示例:main_program elf
# 示例:main_program elf
// main_program.c
#include <stdio.h>
extern int add(int, int); // 声明外部函数
int main() {
int result = add(3, 5); // 调用共享库中的函数
printf("Result: %d\n", result);
return 0;
}
readelf -a main_program
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: 0x640
Start of program headers: 64 (bytes into file)
Start of section headers: 6480 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 29
Section header string table index: 28
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 0000000000000238 00000238
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.ABI-tag NOTE 0000000000000254 00000254
0000000000000020 0000000000000000 A 0 0 4
[ 3] .note.gnu.build-i NOTE 0000000000000274 00000274
0000000000000024 0000000000000000 A 0 0 4
[ 4] .gnu.hash GNU_HASH 0000000000000298 00000298
0000000000000038 0000000000000000 A 5 0 8
[ 5] .dynsym DYNSYM 00000000000002d0 000002d0
0000000000000138 0000000000000018 A 6 1 8
[ 6] .dynstr STRTAB 0000000000000408 00000408
00000000000000b6 0000000000000000 A 0 0 1
[ 7] .gnu.version VERSYM 00000000000004be 000004be
000000000000001a 0000000000000002 A 5 0 2
[ 8] .gnu.version_r VERNEED 00000000000004d8 000004d8
0000000000000020 0000000000000000 A 6 1 8
[ 9] .rela.dyn RELA 00000000000004f8 000004f8
00000000000000c0 0000000000000018 A 5 0 8
[10] .rela.plt RELA 00000000000005b8 000005b8
0000000000000030 0000000000000018 AI 5 22 8
[11] .init PROGBITS 00000000000005e8 000005e8
0000000000000017 0000000000000000 AX 0 0 4
[12] .plt PROGBITS 0000000000000600 00000600
0000000000000030 0000000000000010 AX 0 0 16
[13] .plt.got PROGBITS 0000000000000630 00000630
0000000000000008 0000000000000008 AX 0 0 8
[14] .text PROGBITS 0000000000000640 00000640
00000000000001c2 0000000000000000 AX 0 0 16
[15] .fini PROGBITS 0000000000000804 00000804
0000000000000009 0000000000000000 AX 0 0 4
[16] .rodata PROGBITS 0000000000000810 00000810
0000000000000010 0000000000000000 A 0 0 4
[17] .eh_frame_hdr PROGBITS 0000000000000820 00000820
000000000000003c 0000000000000000 A 0 0 4
[18] .eh_frame PROGBITS 0000000000000860 00000860
0000000000000108 0000000000000000 A 0 0 8
[19] .init_array INIT_ARRAY 0000000000200da0 00000da0
0000000000000008 0000000000000008 WA 0 0 8
[20] .fini_array FINI_ARRAY 0000000000200da8 00000da8
0000000000000008 0000000000000008 WA 0 0 8
[21] .dynamic DYNAMIC 0000000000200db0 00000db0
0000000000000200 0000000000000010 WA 6 0 8
[22] .got PROGBITS 0000000000200fb0 00000fb0
0000000000000050 0000000000000008 WA 0 0 8
[23] .data PROGBITS 0000000000201000 00001000
0000000000000010 0000000000000000 WA 0 0 8
[24] .bss NOBITS 0000000000201010 00001010
0000000000000008 0000000000000000 WA 0 0 1
[25] .comment PROGBITS 0000000000000000 00001010
0000000000000029 0000000000000001 MS 0 0 1
[26] .symtab SYMTAB 0000000000000000 00001040
0000000000000600 0000000000000018 27 43 8
[27] .strtab STRTAB 0000000000000000 00001640
0000000000000210 0000000000000000 0 0 1
[28] .shstrtab STRTAB 0000000000000000 00001850
00000000000000fe 0000000000000000 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),
l (large), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000001f8 0x00000000000001f8 R 0x8
INTERP 0x0000000000000238 0x0000000000000238 0x0000000000000238
0x000000000000001c 0x000000000000001c R 0x1
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000968 0x0000000000000968 R E 0x200000
LOAD 0x0000000000000da0 0x0000000000200da0 0x0000000000200da0
0x0000000000000270 0x0000000000000278 RW 0x200000
DYNAMIC 0x0000000000000db0 0x0000000000200db0 0x0000000000200db0
0x0000000000000200 0x0000000000000200 RW 0x8
NOTE 0x0000000000000254 0x0000000000000254 0x0000000000000254
0x0000000000000044 0x0000000000000044 R 0x4
GNU_EH_FRAME 0x0000000000000820 0x0000000000000820 0x0000000000000820
0x000000000000003c 0x000000000000003c R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10
GNU_RELRO 0x0000000000000da0 0x0000000000200da0 0x0000000000200da0
0x0000000000000260 0x0000000000000260 R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .plt.got .text .fini .rodata .eh_frame_hdr .eh_frame
03 .init_array .fini_array .dynamic .got .data .bss
04 .dynamic
05 .note.ABI-tag .note.gnu.build-id
06 .eh_frame_hdr
07
08 .init_array .fini_array .dynamic .got
Dynamic section at offset 0xdb0 contains 28 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libadd.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x5e8
0x000000000000000d (FINI) 0x804
0x0000000000000019 (INIT_ARRAY) 0x200da0
0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
0x000000000000001a (FINI_ARRAY) 0x200da8
0x000000000000001c (FINI_ARRAYSZ) 8 (bytes)
0x000000006ffffef5 (GNU_HASH) 0x298
0x0000000000000005 (STRTAB) 0x408
0x0000000000000006 (SYMTAB) 0x2d0
0x000000000000000a (STRSZ) 182 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x200fb0
0x0000000000000002 (PLTRELSZ) 48 (bytes)
0x0000000000000014 (PLTREL) RELA
0x0000000000000017 (JMPREL) 0x5b8
0x0000000000000007 (RELA) 0x4f8
0x0000000000000008 (RELASZ) 192 (bytes)
0x0000000000000009 (RELAENT) 24 (bytes)
0x000000000000001e (FLAGS) BIND_NOW
0x000000006ffffffb (FLAGS_1) Flags: NOW PIE
0x000000006ffffffe (VERNEED) 0x4d8
0x000000006fffffff (VERNEEDNUM) 1
0x000000006ffffff0 (VERSYM) 0x4be
0x000000006ffffff9 (RELACOUNT) 3
0x0000000000000000 (NULL) 0x0
Relocation section '.rela.dyn' at offset 0x4f8 contains 8 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000200da0 000000000008 R_X86_64_RELATIVE 740
000000200da8 000000000008 R_X86_64_RELATIVE 700
000000201008 000000000008 R_X86_64_RELATIVE 201008
000000200fd8 000100000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_deregisterTMClone + 0
000000200fe0 000400000006 R_X86_64_GLOB_DAT 0000000000000000 __libc_start_main@GLIBC_2.2.5 + 0
000000200fe8 000500000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
000000200ff0 000600000006 R_X86_64_GLOB_DAT 0000000000000000 _ITM_registerTMCloneTa + 0
000000200ff8 000700000006 R_X86_64_GLOB_DAT 0000000000000000 __cxa_finalize@GLIBC_2.2.5 + 0
Relocation section '.rela.plt' at offset 0x5b8 contains 2 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000200fc8 000200000007 R_X86_64_JUMP_SLO 0000000000000000 add + 0
000000200fd0 000300000007 R_X86_64_JUMP_SLO 0000000000000000 printf@GLIBC_2.2.5 + 0
The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.
Symbol table '.dynsym' contains 13 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND add
3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.2.5 (2)
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
5: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
7: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2)
8: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 23 _edata
9: 0000000000201018 0 NOTYPE GLOBAL DEFAULT 24 _end
10: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 24 __bss_start
11: 00000000000005e8 0 FUNC GLOBAL DEFAULT 11 _init
12: 0000000000000804 0 FUNC GLOBAL DEFAULT 15 _fini
Symbol table '.symtab' contains 64 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 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: 00000000000002d0 0 SECTION LOCAL DEFAULT 5
6: 0000000000000408 0 SECTION LOCAL DEFAULT 6
7: 00000000000004be 0 SECTION LOCAL DEFAULT 7
8: 00000000000004d8 0 SECTION LOCAL DEFAULT 8
9: 00000000000004f8 0 SECTION LOCAL DEFAULT 9
10: 00000000000005b8 0 SECTION LOCAL DEFAULT 10
11: 00000000000005e8 0 SECTION LOCAL DEFAULT 11
12: 0000000000000600 0 SECTION LOCAL DEFAULT 12
13: 0000000000000630 0 SECTION LOCAL DEFAULT 13
14: 0000000000000640 0 SECTION LOCAL DEFAULT 14
15: 0000000000000804 0 SECTION LOCAL DEFAULT 15
16: 0000000000000810 0 SECTION LOCAL DEFAULT 16
17: 0000000000000820 0 SECTION LOCAL DEFAULT 17
18: 0000000000000860 0 SECTION LOCAL DEFAULT 18
19: 0000000000200da0 0 SECTION LOCAL DEFAULT 19
20: 0000000000200da8 0 SECTION LOCAL DEFAULT 20
21: 0000000000200db0 0 SECTION LOCAL DEFAULT 21
22: 0000000000200fb0 0 SECTION LOCAL DEFAULT 22
23: 0000000000201000 0 SECTION LOCAL DEFAULT 23
24: 0000000000201010 0 SECTION LOCAL DEFAULT 24
25: 0000000000000000 0 SECTION LOCAL DEFAULT 25
26: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
27: 0000000000000670 0 FUNC LOCAL DEFAULT 14 deregister_tm_clones
28: 00000000000006b0 0 FUNC LOCAL DEFAULT 14 register_tm_clones
29: 0000000000000700 0 FUNC LOCAL DEFAULT 14 __do_global_dtors_aux
30: 0000000000201010 1 OBJECT LOCAL DEFAULT 24 completed.7698
31: 0000000000200da8 0 OBJECT LOCAL DEFAULT 20 __do_global_dtors_aux_fin
32: 0000000000000740 0 FUNC LOCAL DEFAULT 14 frame_dummy
33: 0000000000200da0 0 OBJECT LOCAL DEFAULT 19 __frame_dummy_init_array_
34: 0000000000000000 0 FILE LOCAL DEFAULT ABS main_program.c
35: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
36: 0000000000000964 0 OBJECT LOCAL DEFAULT 18 __FRAME_END__
37: 0000000000000000 0 FILE LOCAL DEFAULT ABS
38: 0000000000200da8 0 NOTYPE LOCAL DEFAULT 19 __init_array_end
39: 0000000000200db0 0 OBJECT LOCAL DEFAULT 21 _DYNAMIC
40: 0000000000200da0 0 NOTYPE LOCAL DEFAULT 19 __init_array_start
41: 0000000000000820 0 NOTYPE LOCAL DEFAULT 17 __GNU_EH_FRAME_HDR
42: 0000000000200fb0 0 OBJECT LOCAL DEFAULT 22 _GLOBAL_OFFSET_TABLE_
43: 0000000000000800 2 FUNC GLOBAL DEFAULT 14 __libc_csu_fini
44: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
45: 0000000000201000 0 NOTYPE WEAK DEFAULT 23 data_start
46: 0000000000000000 0 FUNC GLOBAL DEFAULT UND add
47: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 23 _edata
48: 0000000000000804 0 FUNC GLOBAL DEFAULT 15 _fini
49: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.2.5
50: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
51: 0000000000201000 0 NOTYPE GLOBAL DEFAULT 23 __data_start
52: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
53: 0000000000201008 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
54: 0000000000000810 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used
55: 0000000000000790 101 FUNC GLOBAL DEFAULT 14 __libc_csu_init
56: 0000000000201018 0 NOTYPE GLOBAL DEFAULT 24 _end
57: 0000000000000640 43 FUNC GLOBAL DEFAULT 14 _start
58: 0000000000201010 0 NOTYPE GLOBAL DEFAULT 24 __bss_start
59: 000000000000074a 55 FUNC GLOBAL DEFAULT 14 main
60: 0000000000201010 0 OBJECT GLOBAL HIDDEN 23 __TMC_END__
61: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
62: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@@GLIBC_2.2
63: 00000000000005e8 0 FUNC GLOBAL DEFAULT 11 _init
Histogram for .gnu.hash' bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 1 ( 33.3%) 20.0%
2 2 ( 66.7%) 100.0%
Version symbols section '.gnu.version' contains 13 entries:
Addr: 00000000000004be Offset: 0x0004be Link: 5 (.dynsym)
000: 0 (*local*) 0 (*local*) 0 (*local*) 2 (GLIBC_2.2.5)
004: 2 (GLIBC_2.2.5) 0 (*local*) 0 (*local*) 2 (GLIBC_2.2.5)
008: 1 (*global*) 1 (*global*) 1 (*global*) 1 (*global*)
00c: 1 (*global*)
Version needs section '.gnu.version_r' contains 1 entry:
Addr: 0x00000000000004d8 Offset: 0x0004d8 Link: 6 (.dynstr)
000000: Version: 1 File: libc.so.6 Cnt: 1
0x0010: Name: GLIBC_2.2.5 Flags: none Version: 2
Displaying notes found in: .note.ABI-tag
Owner Data size Description
GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)
OS: Linux, ABI: 3.2.0
Displaying notes found in: .note.gnu.build-id
Owner Data size Description
GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)
Build ID: 1a98050da8e372ee5ca3d1f359d6171357277bd4