在Linux手机上执行./a.out,报告找不到a.out的错..
时间:2009-05-16 来源:xw_max
在使用了ext3/xfs两种格式格式化TF卡后,复制到TF卡上的程序文件竟然不能执行,sh报告找不到文件。
-sh: ./a.out: not found
而把echo从/bin下复制到T卡上,这个程序却是可以执行的,说明T卡没有问题,分区也没有问题。只是可执行文件格式的问题。 使用file以及readelf分别对照可以执行以及不能执行的二进制的header区。 发现他们的ELF Version不一样:
-sh: ./a.out: not found
而把echo从/bin下复制到T卡上,这个程序却是可以执行的,说明T卡没有问题,分区也没有问题。只是可执行文件格式的问题。 使用file以及readelf分别对照可以执行以及不能执行的二进制的header区。 发现他们的ELF Version不一样:
xiewei@xiewei-desktop disk $ file echo.ok echo.ok : ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), stripped
xiewei@xiewei-desktop disk $ file echo.not.ok echo.not.ok: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), stripped
xiewei@xiewei-desktop disk $ readelf -h echo.ok ELF Header: Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: ARM ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0xcdfc Start of program headers: 52 (bytes into file) Start of section headers: 563772 (bytes into file) Flags: 0x6, has entry point, GNU EABI, interworking enabled Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 5 Size of section headers: 40 (bytes) Number of section headers: 23 Section header string table index: 22
xiewei@xiewei-desktop disk $ readelf -h echo.not.ok ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0xf1a0 Start of program headers: 52 (bytes into file) Start of section headers: 546060 (bytes into file) Flags: 0x5000002, has entry point, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 40 (bytes) Number of section headers: 26 Section header string table index: 25后来仔细考虑了一下,肯定是由于kernel/rootfs/echo使用的arm交叉编译工具链不同导致的。在网上查了一下,确认这种分析是正确的。 这个困扰了我有半年之久的问题,终于搞定了。
相关阅读 更多 +