1. 开发运行环境:
Host 环境:ubuntu 10.0.4
目标机: Contex A53+android系统
2. 问题复现:
1. 用编译Linux Kernel的交叉工具链编译用户空间层程序 test.命令如:xxx-gcc main.c -o test
2. 程序在android系统的用户空间运行
3. 出现bash: ***: No such file or directory
3. 分析思路:
1. readelf -l test, 发现如下信息:
Elf file type is EXEC (Executable file)
Entry point 0x82c4
There are 8 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
EXIDX 0x00049c 0x0000849c 0x0000849c 0x00008 0x00008 R 0x4
PHDR 0x000034 0x00008034 0x00008034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x00008134 0x00008134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.3]
LOAD 0x000000 0x00008000 0x00008000 0x004a8 0x004a8 R E 0x8000
LOAD 0x0004a8 0x000104a8 0x000104a8 0x0011c 0x00120 RW 0x8000
DYNAMIC 0x0004b4 0x000104b4 0x000104b4 0x000e8 0x000e8 RW 0x4
NOTE 0x000148 0x00008148 0x00008148 0x00020 0x00020 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
Segment Sections...
00 .ARM.exidx
01
02 .interp
03 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .ARM.exidx .eh_frame
04 .init_array .fini_array .jcr .dynamic .got .data .bss
05 .dynamic
06 .note.ABI-tag
07
2. 换成静态编译:xxx-gcc -static main.c -o test, 使用readelf -l test
1. 换成静态编译:xxx-gcc -static main.c -o test, 使用readelf -l test
Elf file type is EXEC (Executable file)
Entry point 0x8b28
There are 6 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
EXIDX 0x077610 0x0007f610 0x0007f610 0x00768 0x00768 R 0x4
LOAD 0x000000 0x00008000 0x00008000 0x77d7c 0x77d7c R E 0x8000
LOAD 0x077d7c 0x00087d7c 0x00087d7c 0x00c58 0x020dc RW 0x8000
NOTE 0x0000f4 0x000080f4 0x000080f4 0x00020 0x00020 R 0x4
TLS 0x077d7c 0x00087d7c 0x00087d7c 0x00010 0x00028 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
Segment Sections...
00 .ARM.exidx
01 .note.ABI-tag .init .text __libc_freeres_fn __libc_thread_freeres_fn .fini .rodata __libc_subfreeres __libc_atexit __libc_thread_subfreeres .ARM.extab .ARM.exidx .eh_frame
02 .tdata .init_array .fini_array .jcr .data.rel.ro .got .data .bss __libc_freeres_ptrs
03 .note.ABI-tag
04 .tdata .tbss
05 动态编译的程序有INTERP段,它指明了程序在加载过程中需要使用的动态链接加载器,如果指定的这个加载器未找到,那么就会提示“ No such file or directory”,如果,找到动态链接加载器,但未找到需要的库,那会有另外的提示。
猜想:1. 目标板有ld*一类的库,但是库命令不匹配,可以通过软连接解决;2. 目标板没有ld*一类的库
其结果是2. 然后用readelf工具读取了已有的android可执行程序
Elf file type is EXEC (Executable file)
Entry point 0x8b90
There are 8 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x00008034 0x00008034 0x00100 0x00100 R 0x4
INTERP 0x000134 0x00008134 0x00008134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /system/bin/linker]
LOAD 0x000000 0x00008000 0x00008000 0x02110 0x02110 R E 0x1000
LOAD 0x002110 0x0000b110 0x0000b110 0x00160 0x00160 RW 0x1000
DYNAMIC 0x002110 0x0000b110 0x0000b110 0x000e0 0x000e0 RW 0x4
NOTE 0x000148 0x00008148 0x00008148 0x00028 0x00028 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0
EXIDX 0x002048 0x0000a048 0x0000a048 0x000c0 0x000c0 R 0x4
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .dynsym .dynstr .hash .rel.dyn .rel.plt .plt .text .ARM.extab .ARM.exidx .rodata
03 .dynamic .preinit_array .data .init_array .fini_array .ctors .got
04 .dynamic
05 .note.ABI-tag
06
07 .ARM.exidx android可执行程序的 interpreter段 [Requesting program interpreter: /system/bin/linker], 所以应该是工具链使用错误。原来,开始使用的工具链为编译Linux系统所用的工具链,然后换用android的NDK编译工具链编译,解决问题。
参考:http://bbs.csdn.net/topics/390349057?page=1#post-393513107
版权声明:本文为u012895903原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。