分类: LINUX
2010-10-08 16:21:04
First, my apologies for this long message! OK, Now that I have a somewhat working link script, thanks in part to advice from this list (thanks!!!), I have a question. Last night I noticed that sections not specified in my script were showing up in the executable. I also noticed that once I defined my own PHDRS, that if I didn't explicitly put these sections (__libc_atexit, for example) into my script with a :phdr, then I got really strange behavior. So I put all the sections into my script and all is well. The problem I'm having is with the .note.ABI-tag section. The readelf from a standard build of my code (using the default link script) shows this: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .init PROGBITS 100000c0 0000c0 000028 00 AX 0 0 4 [ 2] .text PROGBITS 10000100 000100 0330e4 00 AX 0 0 32 [ 3] .faketext PROGBITS 100331e4 0331e4 00003c 00 AX 0 0 4 [ 4] .fini PROGBITS 10033220 033220 000020 00 AX 0 0 4 [ 5] .rodata PROGBITS 10033240 033240 006cb0 00 A 0 0 16 [ 6] __libc_subinit PROGBITS 10039ef0 039ef0 00000c 00 A 0 0 4 [ 7] __libc_atexit PROGBITS 10039efc 039efc 000004 00 A 0 0 4 [ 8] __libc_subfreeres PROGBITS 10039f00 039f00 000020 00 A 0 0 4 [ 9] .sdata2 PROGBITS 10039f20 039f20 000000 00 A 0 0 4 [10] .data PROGBITS 10049f20 039f20 000f90 00 WA 0 0 8 [11] .eh_frame PROGBITS 1004aeb0 03aeb0 0001f4 00 WA 0 0 4 [12] .ctors PROGBITS 1004b0a4 03b0a4 000008 00 WA 0 0 4 [13] .dtors PROGBITS 1004b0ac 03b0ac 000008 00 WA 0 0 4 [14] .sdata PROGBITS 1004b0b4 03b0b4 000138 00 WA 0 0 4 [15] .sbss NOBITS 1004b1ec 03b1ec 00020c 00 WA 0 0 4 [16] .bss NOBITS 1004b3f8 03b1ec 000c90 00 WA 0 0 4 [17] .comment PROGBITS 00000000 03b1ec 002050 00 0 0 1 [18] .note.ABI-tag NOTE 100000a0 0000a0 000020 00 A 0 0 16 [19] .shstrtab STRTAB 00000000 03d23c 0000bd 00 0 0 1 [20] .symtab SYMTAB 00000000 03d66c 004ad0 10 21 201 4 [21] .strtab STRTAB 00000000 04213c 003807 00 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) o (os specific), p (processor specific) x (unknown) Elf file type is EXEC (Executable file) Entry point 0x10000100 There are 3 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x10000000 0x10000000 0x39f20 0x39f20 R E 0x10000 LOAD 0x039f20 0x10049f20 0x10049f20 0x012cc 0x02168 RW 0x10000 NOTE 0x0000a0 0x100000a0 0x100000a0 0x00020 0x00020 R 0x10 Section to Segment mapping: Segment Sections... 00 .init .text .faketext .fini .rodata __libc_subinit __libc_atexit __libc_subfreeres .note.ABI-tag 01 .data .eh_frame .ctors .dtors .sdata .sbss .bss 02 .note.ABI-tag The .note.ABI-tag section is in the text segment and the note segment. My linker script specifies the .note section like this: .note.ABI-tag : { *(note.ABI-tag) } :note :text My PHDRS are defined as: PHDRS { text PT_LOAD FILEHDR PHDRS; data PT_LOAD; note PT_NOTE; fake PT_LOAD; }; Yet readelf for the build with my ld.script shows it only in the text segment. What am I doing wrong here? Here's the readelf of the new build. I'm attaching my ld.script as well. Any help or insight is greatly appreciated! Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .init PROGBITS 10000300 000300 000028 00 AX 0 0 4 [ 2] .text PROGBITS 10000360 000360 0330e4 00 AX 0 0 32 [ 3] .fini PROGBITS 10033444 033444 000020 00 AX 0 0 4 [ 4] .rodata PROGBITS 10033470 033470 006cb0 00 A 0 0 16 [ 5] .note.ABI-tag NOTE 10000330 000330 000020 00 A 0 0 16 [ 6] __libc_subinit PROGBITS 1003a120 03a120 00000c 00 A 0 0 4 [ 7] __libc_atexit PROGBITS 1003a12c 03a12c 000004 00 A 0 0 4 [ 8] __libc_subfreeres PROGBITS 1003a130 03a130 000020 00 A 0 0 4 [ 9] .sdata2 PROGBITS 1003a150 03a150 000000 00 A 0 0 4 [10] .data PROGBITS 1004a150 04a150 000f90 00 WA 0 0 8 [11] .eh_frame PROGBITS 1004b0e0 04b0e0 0001f4 00 WA 0 0 4 [12] .ctors PROGBITS 1004b2d4 04b2d4 000008 00 WA 0 0 4 [13] .dtors PROGBITS 1004b2dc 04b2dc 000008 00 WA 0 0 4 [14] .sdata PROGBITS 1004b2e4 04b2e4 000138 00 WA 0 0 4 [15] .sbss NOBITS 1004b41c 04b41c 00020c 00 WA 0 0 4 [16] .bss NOBITS 1004b628 04b41c 000c90 00 WA 0 0 4 [17] .faketext PROGBITS 10f00000 050000 00003c 00 AX 0 0 4 [18] .comment PROGBITS 00000000 05003c 002050 00 0 0 1 [19] .shstrtab STRTAB 00000000 05208c 0000bd 00 0 0 1 [20] .symtab SYMTAB 00000000 0524bc 004ac0 10 21 201 4 [21] .strtab STRTAB 00000000 056f7c 0037dd 00 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) o (os specific), p (processor specific) x (unknown) Elf file type is EXEC (Executable file) Entry point 0x10000360 There are 4 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x10000000 0x10000000 0x3a150 0x3a150 R E 0x10000 LOAD 0x03a150 0x1003a150 0x1003a150 0x112cc 0x12168 RW 0x10000 NOTE 0x000000 0x00000000 0x00000000 0x00000 0x00000 0x4 LOAD 0x050000 0x10f00000 0x10f00000 0x0003c 0x0003c R E 0x10000 Section to Segment mapping: Segment Sections... 00 .init .text .fini .rodata .note.ABI-tag __libc_subinit __libc_atexit __libc_subfreeres 01 .data .eh_frame .ctors .dtors .sdata .sbss .bss 02 03 .faketext -- Becky L. Gill PowerPC Core Design Technologies/Architecture & Performance Motorola SPS, Austin (512) 996-4949
OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc") OUTPUT_ARCH(powerpc) ENTRY(_start) SEARCH_DIR(/lib); SEARCH_DIR(/usr/lib); SEARCH_DIR(/usr/local/lib); SEARCH_DIR(/usr/powerpc-linux/lib); PHDRS { text PT_LOAD FILEHDR PHDRS; data PT_LOAD; note PT_NOTE; fake PT_LOAD; }; SECTIONS { /* Read-only sections, merged into text segment: */ /* Pick a start address and add a constant to it that is > SIZEOF_HEADERS. Don't use SIZEOF_HEADERS - black magic ensues and it won't work */ . = 0x10000000 + 0x0300; .init : { KEEP (*(.init)) } :text =0 /* add a .note section. I don't think this exactly belongs here */ .note.ABI-tag : { *(note.ABI-tag) } :note :text .text : { *(.text) *(.text.*) *(.stub) /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) *(.gnu.linkonce.t*) } :text .fini : { KEEP (*(.fini)) } :text =0 PROVIDE (__etext = .); PROVIDE (_etext = .); PROVIDE (etext = .); .rodata : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) } :text .rodata1 : { *(.rodata1) } :text /* Had to add these in to avoid them defaulting to another phdr */ __libc_subinit : {*(__libc_subinit)} :text __libc_atexit : {*(__libc_atexit)} :text __libc_subfreeres : {*(__libc_subfreeres)} :text .sdata2 : { *(.sdata2) } :data .sbss2 : { *(.sbss2) } :data /* Adjust the address for the data segment. We want to adjust up to the same address within the page on the next page up. */ . = ALIGN(0x10000) + (. & (0x10000 - 1)); .data : { *(.data) *(.data.*) *(.gnu.linkonce.d*) SORT(CONSTRUCTORS) } :data .data1 : { *(.data1) } :data .eh_frame : { *(.eh_frame) } :data .gcc_except_table : { *(.gcc_except_table) } :data .got1 : { *(.got1) } :data .got2 : { *(.got2) } :data .ctors : { /* gcc uses crtbegin.o to find the start of the constructors, so we make sure it is first. Because this is a wildcard, it doesn't matter if the user does not actually link against crtbegin.o; the linker won't look for a file to match a wildcard. The wildcard also means that it doesn't matter which directory crtbegin.o is in. */ KEEP (*crtbegin.o(.ctors)) /* We don't want to include the .ctor section from from the crtend.o file until after the sorted ctors. The .ctor section from the crtend file contains the end of ctors marker and it must be last */ KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) } :data .dtors : { KEEP (*crtbegin.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) } :data .got : { *(.got.plt) *(.got) } :data /* We want the small data sections together, so single-instruction offsets can access them all, and initialized data all before uninitialized, so we can shorten the on-disk segment size. */ .sdata : { *(.sdata) *(.sdata.*) *(.gnu.linkonce.s.*) } :data _edata = .; PROVIDE (edata = .); __bss_start = .; .sbss : { PROVIDE (__sbss_start = .); PROVIDE (___sbss_start = .); *(.dynsbss) *(.sbss) *(.sbss.*) *(.scommon) PROVIDE (__sbss_end = .); PROVIDE (___sbss_end = .); } :data .plt : { *(.plt) } :data .bss : { *(.dynbss) *(.bss) *(.bss.*) *(COMMON) /* Align here to ensure that the .bss section occupies space up to _end. Align after .bss to ensure correct alignment even if the .bss section disappears because there are no input sections. */ . = ALIGN(32 / 8); } :data /* The way this currently works, I believe this has to be AFTER everything else in memory */ FAKETEXT = 0x10f00000; .faketext FAKETEXT : AT (FAKETEXT) { *(.faketext) } :fake . = ALIGN(32 / 8); _end = .; PROVIDE (end = .); /* Stabs debugging sections. */ .stab 0 : { *(.stab) } .stabstr 0 : { *(.stabstr) } .stab.excl 0 : { *(.stab.excl) } .stab.exclstr 0 : { *(.stab.exclstr) } .stab.index 0 : { *(.stab.index) } .stab.indexstr 0 : { *(.stab.indexstr) } .comment 0 : { *(.comment) } /* DWARF debug sections. Symbols in the DWARF debugging sections are relative to the beginning of the section so we begin them at 0. */ /* DWARF 1 */ .debug 0 : { *(.debug) } .line 0 : { *(.line) } /* GNU DWARF 1 extensions */ .debug_srcinfo 0 : { *(.debug_srcinfo) } .debug_sfnames 0 : { *(.debug_sfnames) } /* DWARF 1.1 and DWARF 2 */ .debug_aranges 0 : { *(.debug_aranges) } .debug_pubnames 0 : { *(.debug_pubnames) } /* DWARF 2 */ .debug_info 0 : { *(.debug_info) } .debug_abbrev 0 : { *(.debug_abbrev) } .debug_line 0 : { *(.debug_line) } .debug_frame 0 : { *(.debug_frame) } .debug_str 0 : { *(.debug_str) } .debug_loc 0 : { *(.debug_loc) } .debug_macinfo 0 : { *(.debug_macinfo) } /* SGI/MIPS DWARF 2 extensions */ .debug_weaknames 0 : { *(.debug_weaknames) } .debug_funcnames 0 : { *(.debug_funcnames) } .debug_typenames 0 : { *(.debug_typenames) } .debug_varnames 0 : { *(.debug_varnames) } /DISCARD/ : { *(.fixup) } /* These must appear regardless of . */ }