musl-libc共享库重构后执行失败的问题排查求助
问题描述
在x64架构的Linux虚拟机上开展musl-libc(版本1.1.15)的共享库重构项目,重构完成后,新生成的musl-libc库无法执行(注:musl-libc本身也是二进制可执行文件)。
运行原版musl-libc命令:
./libc.so
预期输出:
musl libc (x86_64) Version 1.1.15 Dynamic Program Loader Usage: ./libc.so [options] [--] pathname [args]
但运行重构后的版本时,出现错误:
bash: ./libc.so.rewritten: cannot execute binary file: Exec format error
初步分析
目标是诊断导致执行失败的问题。已检查重构后库的readelf -a输出,未发现异常,因此需要对加载流程做进一步分析以定位问题。
了解到二进制可执行文件通常包含.interp段来指定动态加载器路径,但musl-libc没有该段。以下是原版readelf -lW ./libc.so的参考输出:
Elf file type is DYN (Shared object file) Entry point 0x5d9c4 There are 7 program headers, starting at offset 64 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x000188 0x000188 R 0x8 LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x08eda4 0x08eda4 R E 0x1000 LOAD 0x08f980 0x0000000000090980 0x0000000000090980 0x000a70 0x003954 RW 0x1000 DYNAMIC 0x08fe18 0x0000000000090e18 0x0000000000090e18 0x000130 0x000130 RW 0x8 GNU_EH_FRAME 0x08ed80 0x000000000008ed80 0x000000000008ed80 0x000024 0x000024 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0 GNU_RELRO 0x08f980 0x0000000000090980 0x0000000000090980 0x000680 0x000680 RW 0x10 ...
疑问
- 动态加载器问题:该问题是否与动态加载器有关?如果是,加载musl-libc使用的是哪个动态加载器?是glibc动态加载器还是musl-libc自身的动态加载器?
- 操作系统加载机制:操作系统是否通过execve直接加载musl-libc?若是,在负责加载ELF二进制的内核函数中添加日志是否有助于诊断问题?
恳请各位提供建议或指导,感谢帮助!
补充:以下是libc.so.rewritten的readelf -h输出:
ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x191c1 Start of program headers: 64 (bytes into file) Start of section headers: 867576 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 79 Size of section headers: 64 (bytes) Number of section headers: 92 Section header string table index: 91
内容的提问来源于stack exchange,提问作者CowHorse
相关产品推荐
相关产品推荐

