1 需求
关键参数:
- -h/--file-header Display the ELF file header
- -l/--program-headers/--segments Display the program headers
- -S/--section-headers/--sections Display the sections' header
- -s/--syms/--symbols Display the symbol table
- --dyn-sysm Display the dynamic symbol table
- -d/--dynamic Display the dynamic section (if present)
- -x/--hex-dump=<number|name> Dump the contents of section <number|name> as bytes
- -p/--string-dump=<number|name> Dump the contents of section <number|name> as strings
- -W/--wide Allow output width to exceed 80 characters
2 语法
D:\JetBrains\CLion 2022.2.3\bin\mingw\bin>readelf.exe --help
Usage: readelf <option(s)> elf-file(s)Display information about the contents of ELF format filesOptions are:-a --all Equivalent to: -h -l -S -s -r -d -V -A -I-h --file-header Display the ELF file header-l --program-headers Display the program headers--segments An alias for --program-headers-S --section-headers Display the sections' header--sections An alias for --section-headers-g --section-groups Display the section groups-t --section-details Display the section details-e --headers Equivalent to: -h -l -S-s --syms Display the symbol table--symbols An alias for --syms--dyn-syms Display the dynamic symbol table--lto-syms Display LTO symbol tables--sym-base=[0|8|10|16]Force base for symbol sizes. The options aremixed (the default), octal, decimal, hexadecimal.-C --demangle[=STYLE] Decode low-level symbol names into user-level namesThe STYLE, if specified, can be `auto' (the default),`gnu', `lucid', `arm', `hp', `edg', `gnu-v3', `java'or `gnat'--no-demangle Do not demangle low-level symbol names. (default)--recurse-limit Enable a demangling recursion limit. (default)--no-recurse-limit Disable a demangling recursion limit-n --notes Display the core notes (if present)-r --relocs Display the relocations (if present)-u --unwind Display the unwind info (if present)-d --dynamic Display the dynamic section (if present)-V --version-info Display the version sections (if present)-A --arch-specific Display architecture specific information (if any)-c --archive-index Display the symbol/file index in an archive-D --use-dynamic Use the dynamic section info when displaying symbols-L --lint|--enable-checksDisplay warning messages for possible problems-x --hex-dump=<number|name>Dump the contents of section <number|name> as bytes-p --string-dump=<number|name>Dump the contents of section <number|name> as strings-R --relocated-dump=<number|name>Dump the relocated contents of section <number|name>-z --decompress Decompress section before dumping it-w --debug-dump[a/=abbrev, A/=addr, r/=aranges, c/=cu_index, L/=decodedline,f/=frames, F/=frames-interp, g/=gdb_index, i/=info, o/=loc,m/=macro, p/=pubnames, t/=pubtypes, R/=Ranges, l/=rawline,s/=str, O/=str-offsets, u/=trace_abbrev, T/=trace_aranges,U/=trace_info]Display the contents of DWARF debug sections-wk --debug-dump=links Display the contents of sections that link to separatedebuginfo files-P --process-links Display the contents of non-debug sections in separatedebuginfo files. (Implies -wK)-wK --debug-dump=follow-linksFollow links to separate debug info files (default)-wN --debug-dump=no-follow-linksDo not follow links to separate debug info files--dwarf-depth=N Do not display DIEs at depth N or greater--dwarf-start=N Display DIEs starting at offset N--ctf=<number|name> Display CTF info from section <number|name>--ctf-parent=<number|name>Use section <number|name> as the CTF parent--ctf-symbols=<number|name>Use section <number|name> as the CTF external symtab--ctf-strings=<number|name>Use section <number|name> as the CTF external strtab-I --histogram Display histogram of bucket list lengths-W --wide Allow output width to exceed 80 characters-T --silent-truncation If a symbol name is truncated, do not add [...] suffix@<file> Read options from <file>-H --help Display this information-v --version Display the version number of readelf
Report bugs to <https://www.sourceware.org/bugzilla/>
3 示例
readelf -S --wide goahead

3 示例
readelf -s goahead
readelf -s libgo.so
> readelf -s goaheadSymbol table '.dynsym' contains 47 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websOpen2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND smatch3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab4: 0000000000000000 0 OBJECT GLOBAL DEFAULT UND logLevel5: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sfmt6: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)7: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetServer8: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetBackground9: 0000000000000000 0 FUNC GLOBAL DEFAULT UND error10: 0000000000000000 0 FUNC GLOBAL DEFAULT UND chdir@GLIBC_2.2.5 (2)11: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@GLIBC_2.4 (3)12: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websServiceEvents13: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getcwd@GLIBC_2.2.5 (2)14: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetDocuments15: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websSetBackground16: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websListen17: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)18: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sclone19: 0000000000000000 0 FUNC GLOBAL DEFAULT UND signal@GLIBC_2.2.5 (2)20: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fprintf@GLIBC_2.2.5 (2)21: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__22: 0000000000000000 0 FUNC GLOBAL DEFAULT UND daemon@GLIBC_2.2.5 (2)23: 0000000000000000 0 FUNC GLOBAL DEFAULT UND logmsgProc24: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websClose25: 0000000000000000 0 FUNC GLOBAL DEFAULT UND stok26: 0000000000000000 0 FUNC GLOBAL DEFAULT UND logSetPath27: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@GLIBC_2.2.5 (2)28: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable29: 0000000000000000 0 FUNC GLOBAL DEFAULT UND wfree30: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websLoad31: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2)32: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websSetDebug33: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __ctype_b_loc@GLIBC_2.3 (4)34: 0000000000000000 0 OBJECT GLOBAL DEFAULT UND stderr@GLIBC_2.2.5 (2)35: 0000000000203010 0 NOTYPE GLOBAL DEFAULT 23 _edata36: 0000000000203000 0 NOTYPE GLOBAL DEFAULT 23 __data_start37: 0000000000203018 0 NOTYPE GLOBAL DEFAULT 24 _end38: 0000000000203000 0 NOTYPE WEAK DEFAULT 23 data_start39: 0000000000001910 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used40: 0000000000001890 101 FUNC GLOBAL DEFAULT 14 __libc_csu_init41: 0000000000000f80 43 FUNC GLOBAL DEFAULT 14 _start42: 0000000000203010 0 NOTYPE GLOBAL DEFAULT 24 __bss_start43: 000000000000108a 1396 FUNC GLOBAL DEFAULT 14 main44: 0000000000000d90 0 FUNC GLOBAL DEFAULT 11 _init45: 0000000000001900 2 FUNC GLOBAL DEFAULT 14 __libc_csu_fini46: 0000000000001904 0 FUNC GLOBAL DEFAULT 15 _finiSymbol table '.symtab' contains 101 entries:Num: Value Size Type Bind Vis Ndx Name0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000238 0 SECTION LOCAL DEFAULT 1 2: 0000000000000254 0 SECTION LOCAL DEFAULT 2 3: 0000000000000274 0 SECTION LOCAL DEFAULT 3 4: 0000000000000298 0 SECTION LOCAL DEFAULT 4 5: 00000000000002f8 0 SECTION LOCAL DEFAULT 5 6: 0000000000000760 0 SECTION LOCAL DEFAULT 6 7: 0000000000000976 0 SECTION LOCAL DEFAULT 7 8: 00000000000009d8 0 SECTION LOCAL DEFAULT 8 9: 0000000000000a18 0 SECTION LOCAL DEFAULT 9 10: 0000000000000b08 0 SECTION LOCAL DEFAULT 10 11: 0000000000000d90 0 SECTION LOCAL DEFAULT 11 12: 0000000000000db0 0 SECTION LOCAL DEFAULT 12 13: 0000000000000f70 0 SECTION LOCAL DEFAULT 13 14: 0000000000000f80 0 SECTION LOCAL DEFAULT 14 15: 0000000000001904 0 SECTION LOCAL DEFAULT 15 16: 0000000000001910 0 SECTION LOCAL DEFAULT 16 17: 0000000000001db4 0 SECTION LOCAL DEFAULT 17 18: 0000000000001e10 0 SECTION LOCAL DEFAULT 18 19: 0000000000202cb8 0 SECTION LOCAL DEFAULT 19 20: 0000000000202cc0 0 SECTION LOCAL DEFAULT 20 21: 0000000000202cc8 0 SECTION LOCAL DEFAULT 21 22: 0000000000202ed8 0 SECTION LOCAL DEFAULT 22 23: 0000000000203000 0 SECTION LOCAL DEFAULT 23 24: 0000000000203010 0 SECTION LOCAL DEFAULT 24 25: 0000000000000000 0 SECTION LOCAL DEFAULT 25 26: 0000000000000000 0 SECTION LOCAL DEFAULT 26 27: 0000000000000000 0 SECTION LOCAL DEFAULT 27 28: 0000000000000000 0 SECTION LOCAL DEFAULT 28 29: 0000000000000000 0 SECTION LOCAL DEFAULT 29 30: 0000000000000000 0 SECTION LOCAL DEFAULT 30 31: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c32: 0000000000000fb0 0 FUNC LOCAL DEFAULT 14 deregister_tm_clones33: 0000000000000ff0 0 FUNC LOCAL DEFAULT 14 register_tm_clones34: 0000000000001040 0 FUNC LOCAL DEFAULT 14 __do_global_dtors_aux35: 0000000000203010 1 OBJECT LOCAL DEFAULT 24 completed.769836: 0000000000202cc0 0 OBJECT LOCAL DEFAULT 20 __do_global_dtors_aux_fin37: 0000000000001080 0 FUNC LOCAL DEFAULT 14 frame_dummy38: 0000000000202cb8 0 OBJECT LOCAL DEFAULT 19 __frame_dummy_init_array_39: 0000000000000000 0 FILE LOCAL DEFAULT ABS goahead.c40: 0000000000203014 4 OBJECT LOCAL DEFAULT 24 finished41: 0000000000001813 58 FUNC LOCAL DEFAULT 14 usage42: 000000000000184d 39 FUNC LOCAL DEFAULT 14 initPlatform43: 00000000000015fe 533 FUNC LOCAL DEFAULT 14 logHeader44: 0000000000001874 20 FUNC LOCAL DEFAULT 14 sigHandler45: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c46: 0000000000001f94 0 OBJECT LOCAL DEFAULT 18 __FRAME_END__47: 0000000000000000 0 FILE LOCAL DEFAULT ABS 48: 0000000000202cc0 0 NOTYPE LOCAL DEFAULT 19 __init_array_end49: 0000000000203008 0 OBJECT LOCAL DEFAULT 23 __dso_handle50: 0000000000202cc8 0 OBJECT LOCAL DEFAULT 21 _DYNAMIC51: 0000000000202cb8 0 NOTYPE LOCAL DEFAULT 19 __init_array_start52: 0000000000001db4 0 NOTYPE LOCAL DEFAULT 17 __GNU_EH_FRAME_HDR53: 0000000000203010 0 OBJECT LOCAL DEFAULT 23 __TMC_END__54: 0000000000202ed8 0 OBJECT LOCAL DEFAULT 22 _GLOBAL_OFFSET_TABLE_55: 0000000000001900 2 FUNC GLOBAL DEFAULT 14 __libc_csu_fini56: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websOpen57: 0000000000000000 0 FUNC GLOBAL DEFAULT UND smatch58: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab59: 0000000000203000 0 NOTYPE WEAK DEFAULT 23 data_start60: 0000000000000000 0 OBJECT GLOBAL DEFAULT UND logLevel61: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sfmt62: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.563: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetServer64: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetBackground65: 0000000000203010 0 NOTYPE GLOBAL DEFAULT 23 _edata66: 0000000000000000 0 FUNC GLOBAL DEFAULT UND error67: 0000000000001904 0 FUNC GLOBAL DEFAULT 15 _fini68: 0000000000000000 0 FUNC GLOBAL DEFAULT UND chdir@@GLIBC_2.2.569: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __stack_chk_fail@@GLIBC_270: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websServiceEvents71: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getcwd@@GLIBC_2.2.572: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websGetDocuments73: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websSetBackground74: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websListen75: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_76: 0000000000203000 0 NOTYPE GLOBAL DEFAULT 23 __data_start77: 0000000000000000 0 FUNC GLOBAL DEFAULT UND sclone78: 0000000000000000 0 FUNC GLOBAL DEFAULT UND signal@@GLIBC_2.2.579: 0000000000000000 0 FUNC GLOBAL DEFAULT UND fprintf@@GLIBC_2.2.580: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__81: 0000000000001910 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used82: 0000000000001890 101 FUNC GLOBAL DEFAULT 14 __libc_csu_init83: 0000000000203018 0 NOTYPE GLOBAL DEFAULT 24 _end84: 0000000000000f80 43 FUNC GLOBAL DEFAULT 14 _start85: 0000000000000000 0 FUNC GLOBAL DEFAULT UND daemon@@GLIBC_2.2.586: 0000000000000000 0 FUNC GLOBAL DEFAULT UND logmsgProc87: 0000000000203010 0 NOTYPE GLOBAL DEFAULT 24 __bss_start88: 000000000000108a 1396 FUNC GLOBAL DEFAULT 14 main89: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websClose90: 0000000000000000 0 FUNC GLOBAL DEFAULT UND stok91: 0000000000000000 0 FUNC GLOBAL DEFAULT UND logSetPath92: 0000000000000000 0 FUNC GLOBAL DEFAULT UND exit@@GLIBC_2.2.593: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable94: 0000000000000000 0 FUNC GLOBAL DEFAULT UND wfree95: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websLoad96: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@@GLIBC_2.297: 0000000000000d90 0 FUNC GLOBAL DEFAULT 11 _init98: 0000000000000000 0 FUNC GLOBAL DEFAULT UND websSetDebug99: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __ctype_b_loc@@GLIBC_2.3100: 0000000000000000 0 OBJECT GLOBAL DEFAULT UND stderr@@GLIBC_2.2.5
3 示例:查看依赖库
readelf -d xxx.so | grep NEEDED

4 参考资料
readelf 和 objdump 例子详解及区别 (ELF文件说明)_readelf工具可以进行代码反汇编_Hani_97的博客-CSDN博客
















