From 9eb52e51dff703062afc369fecb10e7966d7719a Mon Sep 17 00:00:00 2001 From: Mark Seaborn Date: Thu, 28 Jan 2010 22:08:46 +0000 Subject: [PATCH] Override elf_nacl.xr linker script so that libc_pic.os links correctly Add linker script for the "ld --relocatable" case. Ensures that .text.compat is padded correctly with NOPs instead of zeroes. This replaces a binutils hack to default to padding with 0x90. --- ld/ldscripts/elf_nacl.xr | 160 +++++++++++++++++++++++++++++++++++++++++++++++ link-libcso.sh | 1 + 2 files changed, 161 insertions(+) create mode 100644 ld/ldscripts/elf_nacl.xr diff --git a/ld/ldscripts/elf_nacl.xr b/ld/ldscripts/elf_nacl.xr new file mode 100644 index 0000000000..e8b0a713bf --- /dev/null +++ b/ld/ldscripts/elf_nacl.xr @@ -0,0 +1,160 @@ +/* Script for ld -r: link without relocation */ +OUTPUT_FORMAT("elf32-nacl", "elf32-nacl", + "elf32-nacl") +OUTPUT_ARCH(i386) + /* For some reason, the Solaris linker makes bad executables + if gld -r is used and the intermediate file has sections starting + at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld + bug. But for now assigning the zero vmas works. */ +PHDRS +{ + headers PT_PHDR FILEHDR PHDRS ; /* put the headers in a non-loadable seg */ + text PT_LOAD FLAGS(5) ; /* read + execute */ + rodata PT_LOAD FLAGS(4) ; /* read */ + data PT_LOAD FLAGS(6) ; /* read + write */ + /* TODO(sehr): do we need a stack? */ +} +SECTIONS +{ + /* Read-only sections, merged into text segment: */ + .interp 0 : { *(.interp) } + .note.gnu.build-id : { *(.note.gnu.build-id) } + .hash 0 : { *(.hash) } + .gnu.hash 0 : { *(.gnu.hash) } + .dynsym 0 : { *(.dynsym) } + .dynstr 0 : { *(.dynstr) } + .gnu.version 0 : { *(.gnu.version) } + .gnu.version_d 0: { *(.gnu.version_d) } + .gnu.version_r 0: { *(.gnu.version_r) } + .rel.init 0 : { *(.rel.init) } + .rel.text 0 : { *(.rel.text) } + .rel.fini 0 : { *(.rel.fini) } + .rel.rodata 0 : { *(.rel.rodata) } + .rel.data.rel.ro 0 : { *(.rel.data.rel.ro) } + .rel.data 0 : { *(.rel.data) } + .rel.tdata 0 : { *(.rel.tdata) } + .rel.tbss 0 : { *(.rel.tbss) } + .rel.ctors 0 : { *(.rel.ctors) } + .rel.dtors 0 : { *(.rel.dtors) } + .rel.got 0 : { *(.rel.got) } + .rel.bss 0 : { *(.rel.bss) } + .rel.ifunc 0 : { *(.rel.ifunc) } + .rel.plt 0 : + { + *(.rel.plt) + *(.rel.iplt) + } + .init 0 : + { + KEEP (*(.init)) + } :text =0x90909090 + .plt 0 : { *(.plt) *(.iplt)} + .text 0 : + { + *(.text .stub) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + } =0x90909090 + .text.compat 0 : { *(.text.compat) } =0x90909090 + __libc_freeres_fn 0 : { *(__libc_freeres_fn) } =0x90909090 + __libc_thread_freeres_fn 0 : { *(__libc_thread_freeres_fn) } =0x90909090 + .fini 0 : + { + KEEP (*(.fini)) + } =0x90909090 + /* nacl wants page alignment */ + .rodata 0 : { *(.rodata) } :rodata + .rodata1 0 : { *(.rodata1) } + .nacl_rpc_methods : { *(.nacl_rpc_methods) } + .eh_frame_hdr : { *(.eh_frame_hdr) } + .eh_frame 0 : ONLY_IF_RO { KEEP (*(.eh_frame)) } + .gcc_except_table 0 : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } + /* Adjust the address for the data segment. We want to adjust up to + the same address within the page on the next page up. */ + /* Exception handling */ + .eh_frame 0 : ONLY_IF_RW { KEEP (*(.eh_frame)) } + .gcc_except_table 0 : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } + /* Thread Local Storage sections */ + /* The total size of the TLS template area must be a multiple of 0x20, + * but it's size calculation is hardcoded in bfd_elf_final_link function + * so the only thing we can do is align segments here properly */ + .tdata 0 : { + *(.tdata) + } + .tbss 0 : { + *(.tbss) + } + /* . does not advance for tbss because it is not loaded. */ + .preinit_array 0 : + { + KEEP (*(.preinit_array)) + } + .init_array 0 : + { + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + } + .fini_array 0 : + { + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + } + .jcr 0 : { KEEP (*(.jcr)) } + .dynamic 0 : { *(.dynamic) } + .got 0 : { *(.got) *(.igot) } + .got.plt 0 : { *(.got.plt) *(.igot.plt) } + /* nacl wants page alignment */ + .data 0 : + { + *(.data) + } :data + .data1 0 : { *(.data1) } + .bss 0 : + { + *(.dynbss) + *(.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. + FIXME: Why do we need it? When there is no .bss section, we don't + pad the .data section. */ + } + /* 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) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } +} diff --git a/link-libcso.sh b/link-libcso.sh index 60dfb1b924..f825d50925 100755 --- a/link-libcso.sh +++ b/link-libcso.sh @@ -19,6 +19,7 @@ nacl-gcc \ echo - libc_pic.os nacl-gcc \ + -Lld \ -nostdlib -nostartfiles -r -o $BUILD/libc_pic.os \ -Wl,-d -Wl,--whole-archive $BUILD/libc_pic.a \ -Wl,-Map,$BUILD/libc_pic.os.map -- 2.11.4.GIT