天天看点

如何判断Unix系统的一个库文件是32位还是64位的如何判断Unix系统的一个库文件是32位还是64位的

如何判断Unix系统的一个库文件是32位还是64位的如何判断Unix系统的一个库文件是32位还是64位的

某些时候,我们需要知道操作系统的位数,或者配置插件的时候需要知道主程序的位数(例如配置apache插件的时候需要知道apache的位数以便配置相应的插件),最简单的办法就是执行file命令,如:

<a target="_blank"></a>

<code># file libnss1_files-2.2.4.so </code>

<code>libnss1_files-2.2.4.so: elf 32-bit lsb shared object, intel 80386, version 1, not stripped </code>

<code></code>

<code># file libtrsbean.so </code>

<code>libtrsbean.so: elf 64-bit lsb shared object, version 1, not stripped</code>

32位的没有说明

<code>#file /usr/ccs/lib/mcrt0.o </code>

<code>/usr/ccs/lib/mcrt0.o:   executable (risc system/6000) or object module not stripped</code>

<code>#file /usr/ccs/lib/mcrt0_64.o </code>

<code>/usr/ccs/lib/mcrt0_64.o:        64-bit xcoff executable or object module not stripped</code>

<code># file libmp.so </code>

<code>libmp.so:       elf 32-位 msb 动态库 sparc 版本 1,动态链接,没有除去</code>

另外通过二进制查看命令od查看相关的库文件也可以解决此问题,但难度大,也不保险。下面给出在不同系统中的结果,以供参考(由于只在某一版本的操作系统下面做的测试,下面的结果不可能适应所有的所有版本的系统)

32位第4段是0101;64位第4段是0102 。-h 表示按16进制2字节整数查看,整数高低位也调整了(如7f45变成457f); -n 10 表示查看10个字节。

<code>#od -h -n 10 32.so </code>

<code>      0000000 457f 464c 0101 0001 0000</code>

<code>#od -h  -n 10  64.so </code>

<code>      0000000 457f 464c 0102 0001  0000</code>

和linux差不多,只是linux的 -h 参数变成 -x。另外显示结果也不太一样,solaris是按照字节顺序显示的,linux是按照16进制2字节整数查看,会把高低位调整了。

<code>#od -x -n 10  32.so            </code>

<code>     0000000 7f45 4c46 0101 0100 0000</code>

<code>#od -x -n 10  64.so            </code>

<code>     0000000 7f45 4c46 0102 0100 0000</code>

32位是01df ;64位是01f7

<code>#od -n 10 -h crt0_r.o </code>

<code>     0000000  01df 0003 3d65 462a 0000</code>

<code>#od -n 10 -h mcrt0_64.o </code>

<code>      0000000  01f7 0003 3fe2 7fd5 0000</code>

没有实际操作,只是通过ultraedit打开两个文件xxx32.sl和xxx64.sl并比较前面几个字节(hp库文件是.sl结尾不是.so结尾的)。发现64位的文件和linux/solaris的类似。

<code>02 10 01 0e 05 12 40</code>

<code>7f 45 4c 46 02 02 01</code>

原文发布时间:2015-04-17

本文来自云栖合作伙伴“linux中国”

继续阅读