Linker Map
Table of Contents
1. Linker Map
gcc test.c -Wl,-Map=test.map
通过 linker map, 可以看到各个 section 包含了哪些文件的哪些数据以及这些数据的大小,从而清楚的看到 elf 是怎么构成的
Archive member included to satisfy reference by file (symbol) /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o (__libc_csu_init) Merging program properties As-needed library included to satisfy reference by file (symbol) libfoo.so /tmp/ccg09wDv.o (foo) libc.so.6 /tmp/ccg09wDv.o (puts@@GLIBC_2.2.5) Allocating common symbols Common symbol size file xxx 0x190 /tmp/ccg09wDv.o Memory Configuration Name Origin Length Attributes *default* 0x0000000000000000 0xffffffffffffffff [!provide] PROVIDE (__executable_start = SEGMENT_START ("text-segment", 0x0)) 0x0000000000000318 . = (SEGMENT_START ("text-segment", 0x0) + SIZEOF_HEADERS) .interp 0x0000000000000318 0x1c *(.interp) .interp 0x0000000000000318 0x1c /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o .dynsym 0x00000000000003c8 0xd8 *(.dynsym) .dynsym 0x00000000000003c8 0xd8 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o .dynstr 0x00000000000004a0 0x97 *(.dynstr) .dynstr 0x00000000000004a0 0x97 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o .rela.dyn 0x0000000000000570 0xd8 *(.rela.init) *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) .rela.text 0x0000000000000570 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o ... ... .rela.plt 0x0000000000000648 0x48 *(.rela.plt) .rela.plt 0x0000000000000648 0x48 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o *(.rela.iplt) 0x0000000000001000 . = ALIGN (CONSTANT (MAXPAGESIZE)) .init 0x0000000000001000 0x1b *(SORT_NONE(.init)) .init 0x0000000000001000 0x16 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o 0x0000000000001000 _init .init 0x0000000000001016 0x5 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o .plt 0x0000000000001020 0x40 *(.plt) .plt 0x0000000000001020 0x40 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o *(.iplt) .plt.got 0x0000000000001060 0x10 *(.plt.got) .plt.got 0x0000000000001060 0x10 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000001060 __cxa_finalize@@GLIBC_2.2.5 .plt.sec 0x0000000000001070 0x30 *(.plt.sec) .plt.sec 0x0000000000001070 0x30 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000001070 puts@@GLIBC_2.2.5 0x0000000000001080 printf@@GLIBC_2.2.5 0x0000000000001090 foo .text 0x00000000000010a0 0x1a5 *(.text.unlikely .text.*_unlikely .text.unlikely.*) *(.text.exit .text.exit.*) *(.text.startup .text.startup.*) *(.text.hot .text.hot.*) *(SORT_BY_NAME(.text.sorted.*)) *(.text .stub .text.* .gnu.linkonce.t.*) .text 0x00000000000010a0 0x2f /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x00000000000010a0 _start .text 0x00000000000010cf 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o *fill* 0x00000000000010cf 0x1 .text 0x00000000000010d0 0xb9 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o .text 0x0000000000001189 0x42 /tmp/ccg09wDv.o 0x0000000000001189 test 0x00000000000011a0 main *fill* 0x00000000000011cb 0x5 .text 0x00000000000011d0 0x75 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) 0x00000000000011d0 __libc_csu_init 0x0000000000001240 __libc_csu_fini .text 0x0000000000001245 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o .text 0x0000000000001245 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o *(.gnu.warning) .fini 0x0000000000001248 0xd *(SORT_NONE(.fini)) .fini 0x0000000000001248 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o 0x0000000000001248 _fini .fini 0x0000000000001250 0x5 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o [!provide] PROVIDE (__etext = .) [!provide] PROVIDE (_etext = .) [!provide] PROVIDE (etext = .) 0x0000000000002000 . = ALIGN (CONSTANT (MAXPAGESIZE)) 0x0000000000002000 . = SEGMENT_START ("rodata-segment", (ALIGN (CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 0x1)))) .rodata 0x0000000000002000 0x15 *(.rodata .rodata.* .gnu.linkonce.r.*) .rodata.cst4 0x0000000000002000 0x4 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000002000 _IO_stdin_used .rodata 0x0000000000002004 0x11 /tmp/ccg09wDv.o .rodata1 *(.rodata1) .init_array 0x0000000000003d90 0x10 0x0000000000003d90 PROVIDE (__init_array_start = .) *(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)) *(.init_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .ctors) .init_array 0x0000000000003d90 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o .init_array 0x0000000000003d98 0x8 /tmp/ccg09wDv.o 0x0000000000003da0 PROVIDE (__init_array_end = .) .fini_array 0x0000000000003da0 0x8 [!provide] PROVIDE (__fini_array_start = .) *(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)) *(.fini_array EXCLUDE_FILE(*crtend?.o *crtend.o *crtbegin?.o *crtbegin.o) .dtors) .fini_array 0x0000000000003da0 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o [!provide] PROVIDE (__fini_array_end = .) .data.rel.ro 0x0000000000003da8 0x0 *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) .data.rel.ro 0x0000000000003da8 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o .dynamic 0x0000000000003da8 0x200 *(.dynamic) .dynamic 0x0000000000003da8 0x200 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000003da8 _DYNAMIC .got 0x0000000000003fa8 0x58 *(.got.plt) .got.plt 0x0000000000003fa8 0x30 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000003fa8 _GLOBAL_OFFSET_TABLE_ *(.igot.plt) *(.got) .got 0x0000000000003fd8 0x28 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o *(.igot) 0x0000000000004000 . = DATA_SEGMENT_RELRO_END (., 0x0) .data 0x0000000000004000 0x1b0 *(.data .data.* .gnu.linkonce.d.*) .data 0x0000000000004000 0x4 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o 0x0000000000004000 data_start 0x0000000000004000 __data_start .data 0x0000000000004004 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o .data 0x0000000000004004 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o *fill* 0x0000000000004004 0x4 .data.rel.local 0x0000000000004008 0x8 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o 0x0000000000004008 __dso_handle *fill* 0x0000000000004010 0x10 .data 0x0000000000004020 0x190 /tmp/ccg09wDv.o 0x0000000000004020 yyy .data 0x00000000000041b0 0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) .data 0x00000000000041b0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o .data 0x00000000000041b0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o .tm_clone_table 0x00000000000041b0 0x0 .tm_clone_table 0x00000000000041b0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o .tm_clone_table 0x00000000000041b0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o .data1 *(.data1) 0x00000000000041b0 _edata = . [!provide] PROVIDE (edata = .) 0x00000000000041b0 . = . 0x00000000000041b0 __bss_start = . .bss 0x00000000000041c0 0x1b0 *(.dynbss) .dynbss 0x00000000000041c0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o *(.bss .bss.* .gnu.linkonce.b.*) .bss 0x00000000000041c0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o .bss 0x00000000000041c0 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crti.o .bss 0x00000000000041c0 0x1 /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginS.o .bss 0x00000000000041c1 0x0 /tmp/ccg09wDv.o .bss 0x00000000000041c1 0x0 /usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS) .bss 0x00000000000041c1 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/crtendS.o .bss 0x00000000000041c1 0x0 /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crtn.o *(COMMON) *fill* 0x00000000000041c1 0x1f COMMON 0x00000000000041e0 0x190 /tmp/ccg09wDv.o 0x00000000000041e0 xxx 0x0000000000004370 . = ALIGN ((. != 0x0)?0x8:0x1) .lbss *(.dynlbss) *(.lbss .lbss.* .gnu.linkonce.lb.*) *(LARGE_COMMON) 0x0000000000004370 . = ALIGN (0x8) 0x0000000000004370 . = SEGMENT_START ("ldata-segment", .) .lrodata *(.lrodata .lrodata.* .gnu.linkonce.lr.*) .ldata 0x0000000000006370 0x0 *(.ldata .ldata.* .gnu.linkonce.l.*) 0x0000000000006370 . = ALIGN ((. != 0x0)?0x8:0x1) 0x0000000000006370 . = ALIGN (0x8) 0x0000000000004370 _end = . [!provide] PROVIDE (end = .) 0x0000000000006370 . = DATA_SEGMENT_END (.) OUTPUT(a.out elf64-x86-64)
Backlinks
Static Linker (Static Linker > Linker Map): Linker Map