在我的笔记本电脑
$cat /etc/issue
Ubuntu 18.04 LTS \n \l
库x86和x86_64有两个不同的文件夹:
~$ls -1 /
bin
lib
lib64
sbin
...
为什么二进制文件只存在一个目录?
附:我也对Android感兴趣,但我希望答案应该是一样的.
解决方法:
首先,为什么有单独的/ lib和/ lib64:
10.1. There may be one or more variants of the /lib directory on systems which support more than one binary format requiring
separate libraries. (…) This is commonly used for 64-bit or 32-bit
support on systems which support multiple binary formats, but require
libraries of the same name. In this case, /lib32 and /lib64 might be
the library directories, and /lib a symlink to one of them.
例如,我的Slackware 14.2有/ lib和/ lib64
尽管如此,分别为32位和64位库的目录
/ lib不像FHS片段建议的那样作为符号链接:
$ls -l /lib/libc.so.6
lrwxrwxrwx 1 root root 12 Aug 11 2016 /lib/libc.so.6 -> libc-2.23.so
$ls -l /lib64/libc.so.6
lrwxrwxrwx 1 root root 12 Aug 11 2016 /lib64/libc.so.6 -> libc-2.23.so
/ lib和/ lib64中有两个libc.so.6库.
每个动态构建
ELF binary
包含解释器的硬编码路径,在这种情况下也是如此
/lib/ld-linux.so.2或/lib64/ld-linux-x86-64.so.2:
$file main
main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, not stripped
$readelf -a main | grep 'Requesting program interpreter'
[Requesting program interpreter: /lib/ld-linux.so.2]
$file ./main64
./main64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped
$readelf -a main64 | grep 'Requesting program interpreter'
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
解释器的工作是加载必要的共享库.您
可以向GNU解释器询问它甚至不会加载哪些库
使用LD_TRACE_LOADED_OBJECTS = 1或ldd包装器运行二进制文件:
$LD_TRACE_LOADED_OBJECTS=1 ./main
linux-gate.so.1 (0xf77a9000)
libc.so.6 => /lib/libc.so.6 (0xf760e000)
/lib/ld-linux.so.2 (0xf77aa000)
$LD_TRACE_LOADED_OBJECTS=1 ./main64
linux-vdso.so.1 (0x00007ffd535b3000)
libc.so.6 => /lib64/libc.so.6 (0x00007f56830b3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f568347c000)
正如您所看到的,给定的解释器确切地知道在哪里寻找
库 – 32位版本在/ lib和64位中查找库
version在/ lib64中查找库.
关于/ bin的FHS标准如下:
/bin contains commands that may be used by both the system
administrator and by users, but which are required when no other
filesystems are mounted (e.g. in single user mode). It may also
contain commands which are used indirectly by scripts.
IMO没有单独的/ bin和/ bin64的原因是,如果我们有
在这两个目录中具有相同名称的文件我们无法调用其中一个
间接因为我们必须首先放入/ bin或/ bin64
$PATH.
但是,请注意以上只是惯例 – Linux
内核并不关心你是否有单独的/ bin和/ bin64.
如果需要,可以创建它们并相应地设置系统.
你还提到了Android – 请注意除了运行修改后的内容
Linux内核它与GNU系统无关
Ubuntu – 没有glibc,没有bash(默认情况下,你当然可以手动编译和部署),而且目录结构也是
完全不同.
标签:android,linux,architecture
来源: https://codeday.me/bug/20190808/1623687.html