本文共 18282 字,大约阅读时间需要 60 分钟。
[a@b ~]$ mkdir compile_test [a@b ~]$ cd compile_test/ [a@b compile_test]$ ls [a@b compile_test]$ vi foo1.c int foo1 = 10; void foo1_func() { int ret = foo1; }~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "foo1.c" [New] 6L, 54C written [a@b compile_test]$ vi foo2.cint foo2 = 20;
void foo2_func(int x) { int ret = foo2; } ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "foo2.c" [New] 5L, 58C written [a@b compile_test]$ vi hello.c#include <stdio.h>
extern int foo2; int main(int argc, char *argv[]) { foo2 = 5; foo2_func(50); return 0; } ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "hello.c" [New] 8L, 111C written [a@b compile_test]$ gcc -S foo2.c [a@b compile_test]$ ls foo1.c foo2.c foo2.s hello.c [a@b compile_test]$ cat foo2.s .file "foo2.c" .globl foo2 .data .align 4 .type foo2, @object .size foo2, 4 foo2: .long 20 .text .globl foo2_func .type foo2_func, @function foo2_func: pushl %ebp movl %esp, %ebp subl $16, %esp movl foo2, %eax movl %eax, -4(%ebp) leave ret .size foo2_func, .-foo2_func .ident "GCC: (GNU) 4.4.6 20120305 (Red Hat 4.4.6-4)" .section .note.GNU-stack,"",@progbits [a@b compile_test]$ cat foo2.c int foo2 = 20; void foo2_func(int x) { int ret = foo2; } [a@b compile_test]$ gcc -c foo2.c foo1.c hello.c [a@b compile_test]$ ls foo1.c foo1.o foo2.c foo2.o foo2.s hello.c hello.o [a@b compile_test]$ objdump -d foo2.ofoo2.o: file format elf32-i386
Disassembly of section .text:00000000 <foo2_func>:
0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp 6: a1 00 00 00 00 mov 0x0,%eax b: 89 45 fc mov %eax,-0x4(%ebp) e: c9 leave f: c3 ret [a@b compile_test]$ [a@b compile_test]$ [a@b compile_test]$ objdump -d -s foo2.ofoo2.o: file format elf32-i386
Contents of section .text:
0000 5589e583 ec10a100 00000089 45fcc9c3 U...........E... Contents of section .data: 0000 14000000 .... Contents of section .comment: 0000 00474343 3a202847 4e552920 342e342e .GCC: (GNU) 4.4. 0010 36203230 31323033 30352028 52656420 6 20120305 (Red 0020 48617420 342e342e 362d3429 00 Hat 4.4.6-4).Disassembly of section .text:
00000000 <foo2_func>:
0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 10 sub $0x10,%esp 6: a1 00 00 00 00 mov 0x0,%eax b: 89 45 fc mov %eax,-0x4(%ebp) e: c9 leave f: c3 ret [a@b compile_test]$ readelf -r hello.oRelocation section '.rel.text' at offset 0x324 contains 2 entries:
Offset Info Type Sym.Value Sym. Name 0000000b 00000801 R_386_32 00000000 foo2 0000001b 00000902 R_386_PC32 00000000 foo2_func [a@b compile_test]$ [a@b compile_test]$ [a@b compile_test]$ objdump -d hello.ohello.o: file format elf32-i386
Disassembly of section .text:00000000 <main>:
0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp 6: 83 ec 10 sub $0x10,%esp 9: c7 05 00 00 00 00 05 movl $0x5,0x0 10: 00 00 00 13: c7 04 24 32 00 00 00 movl $0x32,(%esp) 1a: e8 fc ff ff ff call 1b <main+0x1b> 1f: b8 00 00 00 00 mov $0x0,%eax 24: c9 leave 25: c3 ret [a@b compile_test]$ readelf -s foo2.oSymbol table '.symtab' contains 9 entries:
Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FILE LOCAL DEFAULT ABS foo2.c 2: 00000000 0 SECTION LOCAL DEFAULT 1 3: 00000000 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 SECTION LOCAL DEFAULT 4 5: 00000000 0 SECTION LOCAL DEFAULT 6 6: 00000000 0 SECTION LOCAL DEFAULT 5 7: 00000000 4 OBJECT GLOBAL DEFAULT 3 foo2 8: 00000000 16 FUNC GLOBAL DEFAULT 1 foo2_func [a@b compile_test]$ readelf -s hello.oSymbol table '.symtab' contains 10 entries:
Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FILE LOCAL DEFAULT ABS hello.c 2: 00000000 0 SECTION LOCAL DEFAULT 1 3: 00000000 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 SECTION LOCAL DEFAULT 4 5: 00000000 0 SECTION LOCAL DEFAULT 6 6: 00000000 0 SECTION LOCAL DEFAULT 5 7: 00000000 38 FUNC GLOBAL DEFAULT 1 main 8: 00000000 0 NOTYPE GLOBAL DEFAULT UND foo2 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND foo2_func [a@b compile_test]$ gcc foo1.o foo2.o hello.o -o hello [a@b compile_test]$ readelf -s helloSymbol table '.dynsym' contains 4 entries:
Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 2: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2) 3: 0804849c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_usedSymbol table '.symtab' contains 70 entries:
Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 08048134 0 SECTION LOCAL DEFAULT 1 2: 08048148 0 SECTION LOCAL DEFAULT 2 3: 08048168 0 SECTION LOCAL DEFAULT 3 4: 0804818c 0 SECTION LOCAL DEFAULT 4 5: 080481ac 0 SECTION LOCAL DEFAULT 5 6: 080481ec 0 SECTION LOCAL DEFAULT 6 7: 08048232 0 SECTION LOCAL DEFAULT 7 8: 0804823c 0 SECTION LOCAL DEFAULT 8 9: 0804825c 0 SECTION LOCAL DEFAULT 9 10: 08048264 0 SECTION LOCAL DEFAULT 10 11: 08048274 0 SECTION LOCAL DEFAULT 11 12: 080482a4 0 SECTION LOCAL DEFAULT 12 13: 080482e0 0 SECTION LOCAL DEFAULT 13 14: 0804847c 0 SECTION LOCAL DEFAULT 14 15: 08048498 0 SECTION LOCAL DEFAULT 15 16: 080484a4 0 SECTION LOCAL DEFAULT 16 17: 080484c8 0 SECTION LOCAL DEFAULT 17 18: 08049544 0 SECTION LOCAL DEFAULT 18 19: 0804954c 0 SECTION LOCAL DEFAULT 19 20: 08049554 0 SECTION LOCAL DEFAULT 20 21: 08049558 0 SECTION LOCAL DEFAULT 21 22: 08049620 0 SECTION LOCAL DEFAULT 22 23: 08049624 0 SECTION LOCAL DEFAULT 23 24: 08049638 0 SECTION LOCAL DEFAULT 24 25: 08049644 0 SECTION LOCAL DEFAULT 25 26: 00000000 0 SECTION LOCAL DEFAULT 26 27: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 28: 08049544 0 OBJECT LOCAL DEFAULT 18 __CTOR_LIST__ 29: 0804954c 0 OBJECT LOCAL DEFAULT 19 __DTOR_LIST__ 30: 08049554 0 OBJECT LOCAL DEFAULT 20 __JCR_LIST__ 31: 08048310 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux 32: 08049644 1 OBJECT LOCAL DEFAULT 25 completed.5972 33: 08049648 4 OBJECT LOCAL DEFAULT 25 dtor_idx.5974 34: 08048370 0 FUNC LOCAL DEFAULT 13 frame_dummy 35: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c 36: 08049548 0 OBJECT LOCAL DEFAULT 18 __CTOR_END__ 37: 08048540 0 OBJECT LOCAL DEFAULT 17 __FRAME_END__ 38: 08049554 0 OBJECT LOCAL DEFAULT 20 __JCR_END__ 39: 08048450 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux 40: 00000000 0 FILE LOCAL DEFAULT ABS foo1.c 41: 00000000 0 FILE LOCAL DEFAULT ABS foo2.c 42: 00000000 0 FILE LOCAL DEFAULT ABS hello.c 43: 08049624 0 OBJECT LOCAL DEFAULT 23 _GLOBAL_OFFSET_TABLE_ 44: 08049544 0 NOTYPE LOCAL DEFAULT 18 __init_array_end 45: 08049544 0 NOTYPE LOCAL DEFAULT 18 __init_array_start 46: 08049558 0 OBJECT LOCAL DEFAULT 21 _DYNAMIC 47: 08049638 0 NOTYPE WEAK DEFAULT 24 data_start 48: 080483e0 5 FUNC GLOBAL DEFAULT 13 __libc_csu_fini 49: 080482e0 0 FUNC GLOBAL DEFAULT 13 _start 50: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 51: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 52: 08048498 4 OBJECT GLOBAL DEFAULT 15 _fp_hw 53: 0804847c 0 FUNC GLOBAL DEFAULT 14 _fini 54: 08049640 4 OBJECT GLOBAL DEFAULT 24 foo2 55: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ 56: 0804849c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used 57: 08049638 0 NOTYPE GLOBAL DEFAULT 24 __data_start 58: 080484a0 0 OBJECT GLOBAL HIDDEN 15 __dso_handle 59: 08049550 0 OBJECT GLOBAL HIDDEN 19 __DTOR_END__ 60: 080483f0 90 FUNC GLOBAL DEFAULT 13 __libc_csu_init 61: 08049644 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 62: 080483a4 16 FUNC GLOBAL DEFAULT 13 foo2_func 63: 0804964c 0 NOTYPE GLOBAL DEFAULT ABS _end 64: 08049644 0 NOTYPE GLOBAL DEFAULT ABS _edata 65: 0804963c 4 OBJECT GLOBAL DEFAULT 24 foo1 66: 0804844a 0 FUNC GLOBAL HIDDEN 13 __i686.get_pc_thunk.bx 67: 080483b4 38 FUNC GLOBAL DEFAULT 13 main 68: 08048274 0 FUNC GLOBAL DEFAULT 11 _init 69: 08048394 16 FUNC GLOBAL DEFAULT 13 foo1_func [a@b compile_test]$ [a@b compile_test]$ readelf -S hello There are 30 section headers, starting at offset 0x798: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 08048134 000134 000013 00 A 0 0 1 [ 2] .note.ABI-tag NOTE 08048148 000148 000020 00 A 0 0 4 [ 3] .note.gnu.build-i NOTE 08048168 000168 000024 00 A 0 0 4 [ 4] .gnu.hash GNU_HASH 0804818c 00018c 000020 04 A 5 0 4 [ 5] .dynsym DYNSYM 080481ac 0001ac 000040 10 A 6 1 4 [ 6] .dynstr STRTAB 080481ec 0001ec 000045 00 A 0 0 1 [ 7] .gnu.version VERSYM 08048232 000232 000008 02 A 5 0 2 [ 8] .gnu.version_r VERNEED 0804823c 00023c 000020 00 A 6 1 4 [ 9] .rel.dyn REL 0804825c 00025c 000008 08 A 5 0 4 [10] .rel.plt REL 08048264 000264 000010 08 A 5 12 4 [11] .init PROGBITS 08048274 000274 000030 00 AX 0 0 4 [12] .plt PROGBITS 080482a4 0002a4 000030 04 AX 0 0 4 [13] .text PROGBITS 080482e0 0002e0 00019c 00 AX 0 0 16 [14] .fini PROGBITS 0804847c 00047c 00001c 00 AX 0 0 4 [15] .rodata PROGBITS 08048498 000498 00000c 00 A 0 0 4 [16] .eh_frame_hdr PROGBITS 080484a4 0004a4 000024 00 A 0 0 4 [17] .eh_frame PROGBITS 080484c8 0004c8 00007c 00 A 0 0 4 [18] .ctors PROGBITS 08049544 000544 000008 00 WA 0 0 4 [19] .dtors PROGBITS 0804954c 00054c 000008 00 WA 0 0 4 [20] .jcr PROGBITS 08049554 000554 000004 00 WA 0 0 4 [21] .dynamic DYNAMIC 08049558 000558 0000c8 08 WA 6 0 4 [22] .got PROGBITS 08049620 000620 000004 04 WA 0 0 4 [23] .got.plt PROGBITS 08049624 000624 000014 04 WA 0 0 4 [24] .data PROGBITS 08049638 000638 00000c 00 WA 0 0 4 [25] .bss NOBITS 08049644 000644 000008 00 WA 0 0 4 [26] .comment PROGBITS 00000000 000644 000058 01 MS 0 0 1 [27] .shstrtab STRTAB 00000000 00069c 0000fc 00 0 0 1 [28] .symtab SYMTAB 00000000 000c48 000460 10 29 47 4 [29] .strtab STRTAB 00000000 0010a8 000217 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) [a@b compile_test]$ readelf -s hello | grep foo2 41: 00000000 0 FILE LOCAL DEFAULT ABS foo2.c 54: 08049640 4 OBJECT GLOBAL DEFAULT 24 foo2 62: 080483a4 16 FUNC GLOBAL DEFAULT 13 foo2_func [a@b compile_test]$ readelf -d helloDynamic section at offset 0x558 contains 20 entries:
Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000c (INIT) 0x8048274 0x0000000d (FINI) 0x804847c 0x6ffffef5 (GNU_HASH) 0x804818c 0x00000005 (STRTAB) 0x80481ec 0x00000006 (SYMTAB) 0x80481ac 0x0000000a (STRSZ) 69 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x8049624 0x00000002 (PLTRELSZ) 16 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0x8048264 0x00000011 (REL) 0x804825c 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0x804823c 0x6fffffff (VERNEEDNUM) 1 0x6ffffff0 (VERSYM) 0x8048232 0x00000000 (NULL) 0x0 [a@b compile_test]$ objdump -d hellohello: file format elf32-i386
Disassembly of section .init:08048274 <_init>:
8048274: 55 push %ebp 8048275: 89 e5 mov %esp,%ebp 8048277: 53 push %ebx 8048278: 83 ec 04 sub $0x4,%esp 804827b: e8 00 00 00 00 call 8048280 <_init+0xc> 8048280: 5b pop %ebx 8048281: 81 c3 a4 13 00 00 add $0x13a4,%ebx 8048287: 8b 93 fc ff ff ff mov -0x4(%ebx),%edx 804828d: 85 d2 test %edx,%edx 804828f: 74 05 je 8048296 <_init+0x22> 8048291: e8 1e 00 00 00 call 80482b4 <__gmon_start__@plt> 8048296: e8 d5 00 00 00 call 8048370 <frame_dummy> 804829b: e8 b0 01 00 00 call 8048450 <__do_global_ctors_aux> 80482a0: 58 pop %eax 80482a1: 5b pop %ebx 80482a2: c9 leave 80482a3: c3 retDisassembly of section .plt:
080482a4 <__gmon_start__@plt-0x10>:
80482a4: ff 35 28 96 04 08 pushl 0x8049628 80482aa: ff 25 2c 96 04 08 jmp *0x804962c 80482b0: 00 00 add %al,(%eax) ...080482b4 <__gmon_start__@plt>:
80482b4: ff 25 30 96 04 08 jmp *0x8049630 80482ba: 68 00 00 00 00 push $0x0 80482bf: e9 e0 ff ff ff jmp 80482a4 <_init+0x30>080482c4 <__libc_start_main@plt>:
80482c4: ff 25 34 96 04 08 jmp *0x8049634 80482ca: 68 08 00 00 00 push $0x8 80482cf: e9 d0 ff ff ff jmp 80482a4 <_init+0x30>Disassembly of section .text:
080482e0 <_start>:
80482e0: 31 ed xor %ebp,%ebp 80482e2: 5e pop %esi 80482e3: 89 e1 mov %esp,%ecx 80482e5: 83 e4 f0 and $0xfffffff0,%esp 80482e8: 50 push %eax 80482e9: 54 push %esp 80482ea: 52 push %edx 80482eb: 68 e0 83 04 08 push $0x80483e0 80482f0: 68 f0 83 04 08 push $0x80483f0 80482f5: 51 push %ecx 80482f6: 56 push %esi 80482f7: 68 b4 83 04 08 push $0x80483b4 80482fc: e8 c3 ff ff ff call 80482c4 <__libc_start_main@plt> 8048301: f4 hlt 8048302: 90 nop 8048303: 90 nop 8048304: 90 nop 8048305: 90 nop 8048306: 90 nop 8048307: 90 nop 8048308: 90 nop 8048309: 90 nop 804830a: 90 nop 804830b: 90 nop 804830c: 90 nop 804830d: 90 nop 804830e: 90 nop 804830f: 90 nop08048310 <__do_global_dtors_aux>:
8048310: 55 push %ebp 8048311: 89 e5 mov %esp,%ebp 8048313: 53 push %ebx 8048314: 8d 64 24 fc lea -0x4(%esp),%esp 8048318: 80 3d 44 96 04 08 00 cmpb $0x0,0x8049644 804831f: 75 3e jne 804835f <__do_global_dtors_aux+0x4f> 8048321: bb 50 95 04 08 mov $0x8049550,%ebx 8048326: a1 48 96 04 08 mov 0x8049648,%eax 804832b: 81 eb 4c 95 04 08 sub $0x804954c,%ebx 8048331: c1 fb 02 sar $0x2,%ebx 8048334: 83 eb 01 sub $0x1,%ebx 8048337: 39 d8 cmp %ebx,%eax 8048339: 73 1d jae 8048358 <__do_global_dtors_aux+0x48> 804833b: 90 nop 804833c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 8048340: 83 c0 01 add $0x1,%eax 8048343: a3 48 96 04 08 mov %eax,0x8049648 8048348: ff 14 85 4c 95 04 08 call *0x804954c(,%eax,4) 804834f: a1 48 96 04 08 mov 0x8049648,%eax 8048354: 39 d8 cmp %ebx,%eax 8048356: 72 e8 jb 8048340 <__do_global_dtors_aux+0x30> 8048358: c6 05 44 96 04 08 01 movb $0x1,0x8049644 804835f: 8d 64 24 04 lea 0x4(%esp),%esp 8048363: 5b pop %ebx 8048364: 5d pop %ebp 8048365: c3 ret 8048366: 8d 76 00 lea 0x0(%esi),%esi 8048369: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi08048370 <frame_dummy>:
8048370: 55 push %ebp 8048371: 89 e5 mov %esp,%ebp 8048373: 8d 64 24 e8 lea -0x18(%esp),%esp 8048377: a1 54 95 04 08 mov 0x8049554,%eax 804837c: 85 c0 test %eax,%eax 804837e: 74 12 je 8048392 <frame_dummy+0x22> 8048380: b8 00 00 00 00 mov $0x0,%eax 8048385: 85 c0 test %eax,%eax 8048387: 74 09 je 8048392 <frame_dummy+0x22> 8048389: c7 04 24 54 95 04 08 movl $0x8049554,(%esp) 8048390: ff d0 call *%eax 8048392: c9 leave 8048393: c3 ret08048394 <foo1_func>:
8048394: 55 push %ebp 8048395: 89 e5 mov %esp,%ebp 8048397: 83 ec 10 sub $0x10,%esp 804839a: a1 3c 96 04 08 mov 0x804963c,%eax 804839f: 89 45 fc mov %eax,-0x4(%ebp) 80483a2: c9 leave 80483a3: c3 ret080483a4 <foo2_func>:
80483a4: 55 push %ebp 80483a5: 89 e5 mov %esp,%ebp 80483a7: 83 ec 10 sub $0x10,%esp 80483aa: a1 40 96 04 08 mov 0x8049640,%eax 80483af: 89 45 fc mov %eax,-0x4(%ebp) 80483b2: c9 leave 80483b3: c3 ret080483b4 <main>:
80483b4: 55 push %ebp 80483b5: 89 e5 mov %esp,%ebp 80483b7: 83 e4 f0 and $0xfffffff0,%esp 80483ba: 83 ec 10 sub $0x10,%esp 80483bd: c7 05 40 96 04 08 05 movl $0x5,0x8049640 80483c4: 00 00 00 80483c7: c7 04 24 32 00 00 00 movl $0x32,(%esp) 80483ce: e8 d1 ff ff ff call 80483a4 <foo2_func> 80483d3: b8 00 00 00 00 mov $0x0,%eax 80483d8: c9 leave 80483d9: c3 ret 80483da: 90 nop 80483db: 90 nop 80483dc: 90 nop 80483dd: 90 nop 80483de: 90 nop 80483df: 90 nop080483e0 <__libc_csu_fini>:
80483e0: 55 push %ebp 80483e1: 89 e5 mov %esp,%ebp 80483e3: 5d pop %ebp 80483e4: c3 ret 80483e5: 66 66 2e 0f 1f 84 00 data32 nopw %cs:0x0(%eax,%eax,1) 80483ec: 00 00 00 00080483f0 <__libc_csu_init>:
80483f0: 55 push %ebp 80483f1: 89 e5 mov %esp,%ebp 80483f3: 57 push %edi 80483f4: 56 push %esi 80483f5: 53 push %ebx 80483f6: e8 4f 00 00 00 call 804844a <__i686.get_pc_thunk.bx> 80483fb: 81 c3 29 12 00 00 add $0x1229,%ebx 8048401: 83 ec 1c sub $0x1c,%esp 8048404: e8 6b fe ff ff call 8048274 <_init> 8048409: 8d bb 20 ff ff ff lea -0xe0(%ebx),%edi 804840f: 8d 83 20 ff ff ff lea -0xe0(%ebx),%eax 8048415: 29 c7 sub %eax,%edi 8048417: c1 ff 02 sar $0x2,%edi 804841a: 85 ff test %edi,%edi 804841c: 74 24 je 8048442 <__libc_csu_init+0x52> 804841e: 31 f6 xor %esi,%esi 8048420: 8b 45 10 mov 0x10(%ebp),%eax 8048423: 89 44 24 08 mov %eax,0x8(%esp) 8048427: 8b 45 0c mov 0xc(%ebp),%eax 804842a: 89 44 24 04 mov %eax,0x4(%esp) 804842e: 8b 45 08 mov 0x8(%ebp),%eax 8048431: 89 04 24 mov %eax,(%esp) 8048434: ff 94 b3 20 ff ff ff call *-0xe0(%ebx,%esi,4) 804843b: 83 c6 01 add $0x1,%esi 804843e: 39 fe cmp %edi,%esi 8048440: 72 de jb 8048420 <__libc_csu_init+0x30> 8048442: 83 c4 1c add $0x1c,%esp 8048445: 5b pop %ebx 8048446: 5e pop %esi 8048447: 5f pop %edi 8048448: 5d pop %ebp 8048449: c3 ret0804844a <__i686.get_pc_thunk.bx>:
804844a: 8b 1c 24 mov (%esp),%ebx 804844d: c3 ret 804844e: 90 nop 804844f: 90 nop08048450 <__do_global_ctors_aux>:
8048450: 55 push %ebp 8048451: 89 e5 mov %esp,%ebp 8048453: 53 push %ebx 8048454: 8d 64 24 fc lea -0x4(%esp),%esp 8048458: a1 44 95 04 08 mov 0x8049544,%eax 804845d: 83 f8 ff cmp $0xffffffff,%eax 8048460: 74 12 je 8048474 <__do_global_ctors_aux+0x24> 8048462: bb 44 95 04 08 mov $0x8049544,%ebx 8048467: 90 nop 8048468: 8d 5b fc lea -0x4(%ebx),%ebx 804846b: ff d0 call *%eax 804846d: 8b 03 mov (%ebx),%eax 804846f: 83 f8 ff cmp $0xffffffff,%eax 8048472: 75 f4 jne 8048468 <__do_global_ctors_aux+0x18> 8048474: 8d 64 24 04 lea 0x4(%esp),%esp 8048478: 5b pop %ebx 8048479: 5d pop %ebp 804847a: c3 ret 804847b: 90 nopDisassembly of section .fini:
0804847c <_fini>:
804847c: 55 push %ebp 804847d: 89 e5 mov %esp,%ebp 804847f: 53 push %ebx 8048480: 83 ec 04 sub $0x4,%esp 8048483: e8 00 00 00 00 call 8048488 <_fini+0xc> 8048488: 5b pop %ebx 8048489: 81 c3 9c 11 00 00 add $0x119c,%ebx 804848f: e8 7c fe ff ff call 8048310 <__do_global_dtors_aux> 8048494: 59 pop %ecx 8048495: 5b pop %ebx 8048496: c9 leave 8048497: c3 ret [a@b compile_test]$ gcc -shared -fPIC foo1.c foo2.c -o libfoo.so [a@b compile_test]$ gcc hello.c -o hello -L./ -lfoo [a@b compile_test]$ readelf -d hello | grep Shared 0x00000001 (NEEDED) Shared library: [libfoo.so] 0x00000001 (NEEDED) Shared library: [libc.so.6] [a@b compile_test]$ readelf -r helloRelocation section '.rel.dyn' at offset 0x35c contains 2 entries:
Offset Info Type Sym.Value Sym. Name 08049728 00000106 R_386_GLOB_DAT 00000000 __gmon_start__ 08049748 00000705 R_386_COPY 08049748 foo2Relocation section '.rel.plt' at offset 0x36c contains 3 entries:
Offset Info Type Sym.Value Sym. Name 08049738 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__ 0804973c 00000307 R_386_JUMP_SLOT 00000000 __libc_start_main 08049740 00000407 R_386_JUMP_SLOT 00000000 foo2_func [a@b compile_test]$
深入理解 Linux 位置无关代码 PIC
https://blog.csdn.net/feelabclihu/article/details/108289461