分离出的调试信息debugsymbol还可以链接回可执行文件test中
objcopy --add-gnu-debuglink test.symbol test
然后就可以正常用addr2line等需要读取调试信息的程序了
addr2line -e test 0x401c23
这个段的段名通常叫做 .dynsym(Dynamic Symbol)
动态链接ELF中最重要的结构应该是 .dynamic 段 ,这个段里面保存了动态链接器所需要的基本信息,比如依赖于哪些共享对象、动态链接符号表的位置、动态链接重定位表的位置、共享对象初始化代码的地址等
与“.symtab”类似,动态符号表也需要一些辅助的表,比如用于保存符号名的字符串表。静态链接时叫做符号字符串表“.strtab”(String Table),在这里就是动态符号字符串表 .dynstr
readelf -S test There are 35 section headers, starting at offset 0x7b2fc: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 000080f4 0000f4 000014 00 A 0 0 1 [ 2] .hash HASH 00008108 000108 000658 04 A 3 0 4 [ 3] .dynsym DYNSYM 00008760 000760 000cf0 10 A 4 1 4 [ 4] .dynstr STRTAB 00009450 001450 00137b 00 A 0 0 1 [ 5] .gnu.version VERSYM 0000a7cc 0027cc 00019e 02 A 3 0 2 [ 6] .gnu.version_r VERNEED 0000a96c 00296c 000060 00 A 4 3 4 [ 7] .rel.dyn REL 0000a9cc 0029cc 000070 08 A 3 0 4 [ 8] .rel.plt REL 0000aa3c 002a3c 0005a8 08 A 3 10 4 [ 9] .init PROGBITS 0000afe4 002fe4 000010 00 AX 0 0 4 [10] .plt PROGBITS 0000aff4 002ff4 000890 04 AX 0 0 4 [11] .text PROGBITS 0000b884 003884 00f158 00 AX 0 0 4 [12] .fini PROGBITS 0001a9dc 0129dc 000010 00 AX 0 0 4 [13] .rodata PROGBITS 0001a9ec 0129ec 003838 00 A 0 0 4 [14] .eh_frame PROGBITS 0001e224 016224 000004 00 A 0 0 4 [15] .init_array INIT_ARRAY 00026228 016228 000004 00 WA 0 0 4 [16] .fini_array FINI_ARRAY 0002622c 01622c 000004 00 WA 0 0 4 [17] .jcr PROGBITS 00026230 016230 000004 00 WA 0 0 4 [18] .dynamic DYNAMIC 00026234 016234 000188 08 WA 4 0 4 [19] .got PROGBITS 000263bc 0163bc 0002e0 04 WA 0 0 4 [20] .data PROGBITS 0002669c 01669c 00003c 00 WA 0 0 4 [21] .bss NOBITS 000266d8 0166d8 0074a0 00 WA 0 0 8 [22] .comment PROGBITS 00000000 0166d8 000068 01 MS 0 0 1 [23] .ARM.attributes ARM_ATTRIBUTES 00000000 016740 00002f 00 0 0 1 [24] .debug_aranges PROGBITS 00000000 01676f 000108 00 0 0 1 [25] .debug_info PROGBITS 00000000 016877 0398ba 00 0 0 1 [26] .debug_abbrev PROGBITS 00000000 050131 001e7e 00 0 0 1 [27] .debug_line PROGBITS 00000000 051faf 005827 00 0 0 1 [28] .debug_frame PROGBITS 00000000 0577d8 00162c 00 0 0 4 [29] .debug_str PROGBITS 00000000 058e04 01788b 01 MS 0 0 1 [30] .debug_loc PROGBITS 00000000 07068f 009e6d 00 0 0 1 [31] .debug_ranges PROGBITS 00000000 07a4fc 000cc0 00 0 0 1 [32] .shstrtab STRTAB 00000000 07b1bc 000140 00 0 0 1 [33] .symtab SYMTAB 00000000 07b874 003760 10 34 548 4 [34] .strtab STRTAB 00000000 07efd4 002e81 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), y (noread), p (processor specific) arm-openwrt-linux-strip -s test There are 25 section headers, starting at offset 0x1683c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 000080f4 0000f4 000014 00 A 0 0 1 [ 2] .hash HASH 00008108 000108 000658 04 A 3 0 4 [ 3] .dynsym DYNSYM 00008760 000760 000cf0 10 A 4 1 4 [ 4] .dynstr STRTAB 00009450 001450 00137b 00 A 0 0 1 [ 5] .gnu.version VERSYM 0000a7cc 0027cc 00019e 02 A 3 0 2 [ 6] .gnu.version_r VERNEED 0000a96c 00296c 000060 00 A 4 3 4 [ 7] .rel.dyn REL 0000a9cc 0029cc 000070 08 A 3 0 4 [ 8] .rel.plt REL 0000aa3c 002a3c 0005a8 08 A 3 10 4 [ 9] .init PROGBITS 0000afe4 002fe4 000010 00 AX 0 0 4 [10] .plt PROGBITS 0000aff4 002ff4 000890 04 AX 0 0 4 [11] .text PROGBITS 0000b884 003884 00f158 00 AX 0 0 4 [12] .fini PROGBITS 0001a9dc 0129dc 000010 00 AX 0 0 4 [13] .rodata PROGBITS 0001a9ec 0129ec 003838 00 A 0 0 4 [14] .eh_frame PROGBITS 0001e224 016224 000004 00 A 0 0 4 [15] .init_array INIT_ARRAY 00026228 016228 000004 00 WA 0 0 4 [16] .fini_array FINI_ARRAY 0002622c 01622c 000004 00 WA 0 0 4 [17] .jcr PROGBITS 00026230 016230 000004 00 WA 0 0 4 [18] .dynamic DYNAMIC 00026234 016234 000188 08 WA 4 0 4 [19] .got PROGBITS 000263bc 0163bc 0002e0 04 WA 0 0 4 [20] .data PROGBITS 0002669c 01669c 00003c 00 WA 0 0 4 [21] .bss NOBITS 000266d8 0166d8 0074a0 00 WA 0 0 8 [22] .comment PROGBITS 00000000 0166d8 000068 01 MS 0 0 1 [23] .ARM.attributes ARM_ATTRIBUTES 00000000 016740 00002f 00 0 0 1 [24] .shstrtab STRTAB 00000000 01676f 0000ca 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), y (noread), p (processor specific) //可以发现符号表symtab 消失了
open("/fp/lib/log_plugins/libto_logs.so.debug.symbol", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/fp/lib/log_plugins/.debug/libto_logs.so.debug.symbol", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/debug//fp/lib/log_plugins/libto_logs.so.debug.symbol", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) open("/usr/lib/debug/old_rootfs/fp/lib/log_plugins/libto_logs.so.debug.symbol", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory) write(1, "(no debugging symbols found)...d"..., 37(no debugging symbols found)...done.
原文:https://www.cnblogs.com/codestack/p/12830451.html