Debian Codegraph @

third_party/rust/goblin/tests/bins/elf/gnu_hash/README.md

raw
1 # How to generate hello.so file
2
3 With 64-bit gcc:
4
5 ```bash
6 % gcc -o hello.so helloworld.c -Wl,--as-needed -shared -fPIC
7 % readelf --dyn-syms hello.so
8
9 Symbol table '.dynsym' contains 13 entries:
10 Num: Value Size Type Bind Vis Ndx Name
11 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
12 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
13 2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.2.5 (2)
14 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
15 4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
16 5: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5 (2)
17 6: 0000000000201030 0 NOTYPE GLOBAL DEFAULT 22 _edata
18 7: 000000000000065a 33 FUNC GLOBAL DEFAULT 12 helloWorld
19 8: 0000000000201038 0 NOTYPE GLOBAL DEFAULT 23 _end
20 9: 0000000000201030 0 NOTYPE GLOBAL DEFAULT 23 __bss_start
21 10: 000000000000067b 43 FUNC GLOBAL DEFAULT 12 main
22 11: 0000000000000520 0 FUNC GLOBAL DEFAULT 9 _init
23 12: 00000000000006a8 0 FUNC GLOBAL DEFAULT 13 _fini
24
25 % readelf --section-headers hello.so
26 There are 26 section headers, starting at offset 0x1140:
27
28 Section Headers:
29 [Nr] Name Type Address Offset
30 Size EntSize Flags Link Info Align
31 [ 0] NULL 0000000000000000 00000000
32 0000000000000000 0000000000000000 0 0 0
33 [ 1] .note.gnu.build-i NOTE 00000000000001c8 000001c8
34 0000000000000024 0000000000000000 A 0 0 4
35 [ 2] .gnu.hash GNU_HASH 00000000000001f0 000001f0
36 0000000000000040 0000000000000000 A 3 0 8
37 [ 3] .dynsym DYNSYM 0000000000000230 00000230
38 0000000000000138 0000000000000018 A 4 1 8
39 [ 4] .dynstr STRTAB 0000000000000368 00000368
40 00000000000000a6 0000000000000000 A 0 0 1
41 [ 5] .gnu.version VERSYM 000000000000040e 0000040e
42 000000000000001a 0000000000000002 A 3 0 2
43 [ 6] .gnu.version_r VERNEED 0000000000000428 00000428
44 0000000000000020 0000000000000000 A 4 1 8
45 [ 7] .rela.dyn RELA 0000000000000448 00000448
46 00000000000000a8 0000000000000018 A 3 0 8
47 [ 8] .rela.plt RELA 00000000000004f0 000004f0
48 0000000000000030 0000000000000018 AI 3 21 8
49 [ 9] .init PROGBITS 0000000000000520 00000520
50 0000000000000017 0000000000000000 AX 0 0 4
51 [10] .plt PROGBITS 0000000000000540 00000540
52 0000000000000030 0000000000000010 AX 0 0 16
53 [11] .plt.got PROGBITS 0000000000000570 00000570
54 0000000000000008 0000000000000008 AX 0 0 8
55 [12] .text PROGBITS 0000000000000580 00000580
56 0000000000000126 0000000000000000 AX 0 0 16
57 [13] .fini PROGBITS 00000000000006a8 000006a8
58 0000000000000009 0000000000000000 AX 0 0 4
59 [14] .rodata PROGBITS 00000000000006b1 000006b1
60 0000000000000010 0000000000000000 A 0 0 1
61 [15] .eh_frame_hdr PROGBITS 00000000000006c4 000006c4
62 000000000000002c 0000000000000000 A 0 0 4
63 [16] .eh_frame PROGBITS 00000000000006f0 000006f0
64 000000000000009c 0000000000000000 A 0 0 8
65 [17] .init_array INIT_ARRAY 0000000000200e10 00000e10
66 0000000000000008 0000000000000008 WA 0 0 8
67 [18] .fini_array FINI_ARRAY 0000000000200e18 00000e18
68 0000000000000008 0000000000000008 WA 0 0 8
69 [19] .dynamic DYNAMIC 0000000000200e20 00000e20
70 00000000000001c0 0000000000000010 WA 4 0 8
71 [20] .got PROGBITS 0000000000200fe0 00000fe0
72 0000000000000020 0000000000000008 WA 0 0 8
73 [21] .got.plt PROGBITS 0000000000201000 00001000
74 0000000000000028 0000000000000008 WA 0 0 8
75 [22] .data PROGBITS 0000000000201028 00001028
76 0000000000000008 0000000000000000 WA 0 0 8
77 [23] .bss NOBITS 0000000000201030 00001030
78 0000000000000008 0000000000000000 WA 0 0 1
79 [24] .comment PROGBITS 0000000000000000 00001030
80 000000000000002a 0000000000000001 MS 0 0 1
81 [25] .shstrtab STRTAB 0000000000000000 0000105a
82 00000000000000e1 0000000000000000 0 0 1
83 Key to Flags:
84 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
85 L (link order), O (extra OS processing required), G (group), T (TLS),
86 C (compressed), x (unknown), o (OS specific), E (exclude),
87 l (large), p (processor specific)
88 ```
89
90 Or in 32-bit mode (one might need to install `gcc-multilib` on Ubuntu):
91
92 ```bash
93 % gcc -o hello.so helloworld.c -Wl,--as-needed -shared -fPIC
94 % readelf --dyn-syms hello32.so
95
96 Symbol table '.dynsym' contains 13 entries:
97 Num: Value Size Type Bind Vis Ndx Name
98 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
99 1: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
100 2: 00000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
101 3: 00000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.1.3 (3)
102 4: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
103 5: 00000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
104 6: 00002018 0 NOTYPE GLOBAL DEFAULT 22 _edata
105 7: 000004ed 49 FUNC GLOBAL DEFAULT 12 helloWorld
106 8: 0000201c 0 NOTYPE GLOBAL DEFAULT 23 _end
107 9: 00002018 0 NOTYPE GLOBAL DEFAULT 23 __bss_start
108 10: 0000051e 66 FUNC GLOBAL DEFAULT 12 main
109 11: 0000038c 0 FUNC GLOBAL DEFAULT 9 _init
110 12: 00000564 0 FUNC GLOBAL DEFAULT 13 _fini
111
112 ```