有没有办法在不执行代码的情况下检查库是否是为小端或大端架构构建的?
比方说,我有一个库 X,但是,我不知道它是为小端还是大端构建的,是否有任何命令或有没有办法通过构建输出找出库是否已构建小端还是大端?或者是否可以将这些信息放在图书馆中?
最佳答案
如果您正在运行 linux/unix,最简单的方法是使用 file 命令。
$ file /lib64/libc-2.15.so
/lib64/libc-2.15.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), BuildID[sha1]=0x2dc710cc03932ca6fb7f223e2c0f67e21adebb4f, for GNU/Linux 2.6.32, not stripped
所以信息肯定是内置在库头中的。您可以使用 readelf 命令进行检查。
$ readelf -h /lib64/libc-2.15.so
ELF Header:
Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - GNU
ABI Version: 0
Type: DYN (Shared object file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x3fc4c21840
Start of program headers: 64 (bytes into file)
Start of section headers: 2062800 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 10
Size of section headers: 64 (bytes)
Number of section headers: 43
Section header string table index: 42
在 Windows 中,我不知道如何检查,但应该在 dll 的标题中。
关于c - 有没有办法在不执行代码的情况下检查库是否是为小端或大端架构构建的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14597044/