Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 1 | /* Script for ld -pie: link position independent executable */ |
Rong Xu | e1a8a48 | 2015-04-08 12:48:42 -0700 | [diff] [blame] | 2 | /* Copyright (C) 2014 Free Software Foundation, Inc. |
| 3 | Copying and distribution of this script, with or without modification, |
| 4 | are permitted in any medium without royalty provided the copyright |
| 5 | notice and this notice are preserved. */ |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 6 | OUTPUT_FORMAT("elf32-bigarm", "elf32-bigarm", |
| 7 | "elf32-littlearm") |
| 8 | OUTPUT_ARCH(arm) |
| 9 | ENTRY(_start) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 10 | SECTIONS |
| 11 | { |
| 12 | /* Read-only sections, merged into text segment: */ |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 13 | PROVIDE (__executable_start = 0); . = 0 + SIZEOF_HEADERS; |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 14 | .interp : { *(.interp) } |
| 15 | .note.gnu.build-id : { *(.note.gnu.build-id) } |
| 16 | .hash : { *(.hash) } |
| 17 | .gnu.hash : { *(.gnu.hash) } |
| 18 | .dynsym : { *(.dynsym) } |
| 19 | .dynstr : { *(.dynstr) } |
| 20 | .gnu.version : { *(.gnu.version) } |
| 21 | .gnu.version_d : { *(.gnu.version_d) } |
| 22 | .gnu.version_r : { *(.gnu.version_r) } |
| 23 | .rel.init : { *(.rel.init) } |
| 24 | .rela.init : { *(.rela.init) } |
| 25 | .rel.text : { *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*) } |
| 26 | .rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) } |
| 27 | .rel.fini : { *(.rel.fini) } |
| 28 | .rela.fini : { *(.rela.fini) } |
| 29 | .rel.rodata : { *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*) } |
| 30 | .rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) } |
| 31 | .rel.data.rel.ro : { *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*) } |
| 32 | .rela.data.rel.ro : { *(.rela.data.rel.ro .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*) } |
| 33 | .rel.data : { *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*) } |
| 34 | .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } |
| 35 | .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } |
| 36 | .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } |
| 37 | .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } |
| 38 | .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } |
| 39 | .rel.ctors : { *(.rel.ctors) } |
| 40 | .rela.ctors : { *(.rela.ctors) } |
| 41 | .rel.dtors : { *(.rel.dtors) } |
| 42 | .rela.dtors : { *(.rela.dtors) } |
| 43 | .rel.got : { *(.rel.got) } |
| 44 | .rela.got : { *(.rela.got) } |
| 45 | .rel.bss : { *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*) } |
| 46 | .rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) } |
| 47 | .rel.iplt : |
| 48 | { |
| 49 | PROVIDE_HIDDEN (__rel_iplt_start = .); |
| 50 | *(.rel.iplt) |
| 51 | PROVIDE_HIDDEN (__rel_iplt_end = .); |
| 52 | } |
| 53 | .rela.iplt : |
| 54 | { |
| 55 | PROVIDE_HIDDEN (__rela_iplt_start = .); |
| 56 | *(.rela.iplt) |
| 57 | PROVIDE_HIDDEN (__rela_iplt_end = .); |
| 58 | } |
| 59 | .rel.plt : |
| 60 | { |
| 61 | *(.rel.plt) |
| 62 | } |
| 63 | .rela.plt : |
| 64 | { |
| 65 | *(.rela.plt) |
| 66 | } |
| 67 | .init : |
| 68 | { |
| 69 | KEEP (*(SORT_NONE(.init))) |
| 70 | } |
| 71 | .plt : { *(.plt) } |
| 72 | .iplt : { *(.iplt) } |
| 73 | .text : |
| 74 | { |
| 75 | *(.text.unlikely .text.*_unlikely .text.unlikely.*) |
| 76 | *(.text.exit .text.exit.*) |
| 77 | *(.text.startup .text.startup.*) |
| 78 | *(.text.hot .text.hot.*) |
| 79 | *(.text .stub .text.* .gnu.linkonce.t.*) |
| 80 | /* .gnu.warning sections are handled specially by elf32.em. */ |
| 81 | *(.gnu.warning) |
| 82 | *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx) |
| 83 | } |
| 84 | .fini : |
| 85 | { |
| 86 | KEEP (*(SORT_NONE(.fini))) |
| 87 | } |
| 88 | PROVIDE (__etext = .); |
| 89 | PROVIDE (_etext = .); |
| 90 | PROVIDE (etext = .); |
| 91 | .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } |
| 92 | .rodata1 : { *(.rodata1) } |
| 93 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } |
| 94 | PROVIDE_HIDDEN (__exidx_start = .); |
| 95 | .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } |
| 96 | PROVIDE_HIDDEN (__exidx_end = .); |
| 97 | .eh_frame_hdr : { *(.eh_frame_hdr) } |
| 98 | .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } |
| 99 | .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table |
| 100 | .gcc_except_table.*) } |
| 101 | /* These sections are generated by the Sun/Oracle C++ compiler. */ |
| 102 | .exception_ranges : ONLY_IF_RO { *(.exception_ranges |
| 103 | .exception_ranges*) } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 104 | /* Adjust the address for the data segment. For 32 bits we want to align |
| 105 | at exactly a page boundary to make life easier for apriori. */ |
| 106 | . = ALIGN (CONSTANT (MAXPAGESIZE)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE)); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 107 | /* Exception handling */ |
| 108 | .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) } |
| 109 | .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) } |
| 110 | .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) } |
| 111 | /* Thread Local Storage sections */ |
| 112 | .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } |
| 113 | .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 114 | /* Ensure the __preinit_array_start label is properly aligned. We |
| 115 | could instead move the label definition inside the section, but |
| 116 | the linker would then create the section even if it turns out to |
| 117 | be empty, which isn't pretty. */ |
| 118 | . = ALIGN(32 / 8); |
| 119 | PROVIDE_HIDDEN (__preinit_array_start = .); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 120 | .preinit_array : |
| 121 | { |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 122 | KEEP (*(.preinit_array)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 123 | } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 124 | PROVIDE_HIDDEN (__preinit_array_end = .); |
| 125 | PROVIDE_HIDDEN (__init_array_start = .); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 126 | .init_array : |
| 127 | { |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 128 | KEEP (*crtbegin*.o(.init_array)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 129 | KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 130 | KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin*.o *crtend.o *crtend*.o ) .ctors)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 131 | } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 132 | PROVIDE_HIDDEN (__init_array_end = .); |
| 133 | PROVIDE_HIDDEN (__fini_array_start = .); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 134 | .fini_array : |
| 135 | { |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 136 | KEEP (*crtbegin*.o(.fini_array)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 137 | KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 138 | KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin*.o *crtend.o *crtend*.o ) .dtors)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 139 | } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 140 | PROVIDE_HIDDEN (__fini_array_end = .); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 141 | .ctors : |
| 142 | { |
| 143 | /* gcc uses crtbegin.o to find the start of |
| 144 | the constructors, so we make sure it is |
| 145 | first. Because this is a wildcard, it |
| 146 | doesn't matter if the user does not |
| 147 | actually link against crtbegin.o; the |
| 148 | linker won't look for a file to match a |
| 149 | wildcard. The wildcard also means that it |
| 150 | doesn't matter which directory crtbegin.o |
| 151 | is in. */ |
| 152 | KEEP (*crtbegin.o(.ctors)) |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 153 | KEEP (*crtbegin*.o(.ctors)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 154 | /* We don't want to include the .ctor section from |
| 155 | the crtend.o file until after the sorted ctors. |
| 156 | The .ctor section from the crtend file contains the |
| 157 | end of ctors marker and it must be last */ |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 158 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend*.o ) .ctors)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 159 | KEEP (*(SORT(.ctors.*))) |
| 160 | KEEP (*(.ctors)) |
| 161 | } |
| 162 | .dtors : |
| 163 | { |
| 164 | KEEP (*crtbegin.o(.dtors)) |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 165 | KEEP (*crtbegin*.o(.dtors)) |
| 166 | KEEP (*(EXCLUDE_FILE (*crtend.o *crtend*.o ) .dtors)) |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 167 | KEEP (*(SORT(.dtors.*))) |
| 168 | KEEP (*(.dtors)) |
| 169 | } |
| 170 | .jcr : { KEEP (*(.jcr)) } |
| 171 | .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) } |
| 172 | .dynamic : { *(.dynamic) } |
| 173 | . = DATA_SEGMENT_RELRO_END (0, .); |
| 174 | .got : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) } |
| 175 | .data : |
| 176 | { |
| 177 | PROVIDE (__data_start = .); |
| 178 | *(.data .data.* .gnu.linkonce.d.*) |
| 179 | SORT(CONSTRUCTORS) |
| 180 | } |
| 181 | .data1 : { *(.data1) } |
| 182 | _edata = .; PROVIDE (edata = .); |
| 183 | . = .; |
| 184 | __bss_start = .; |
| 185 | __bss_start__ = .; |
| 186 | .bss : |
| 187 | { |
| 188 | *(.dynbss) |
| 189 | *(.bss .bss.* .gnu.linkonce.b.*) |
| 190 | *(COMMON) |
| 191 | /* Align here to ensure that the .bss section occupies space up to |
| 192 | _end. Align after .bss to ensure correct alignment even if the |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 193 | .bss section disappears because there are no input sections. */ |
| 194 | . = ALIGN(32 / 8); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 195 | } |
| 196 | _bss_end__ = . ; __bss_end__ = . ; |
| 197 | . = ALIGN(32 / 8); |
| 198 | . = SEGMENT_START("ldata-segment", .); |
| 199 | . = ALIGN(32 / 8); |
| 200 | __end__ = . ; |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 201 | _end = .; |
| 202 | _bss_end__ = . ; __bss_end__ = . ; __end__ = . ; |
| 203 | PROVIDE (end = .); |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 204 | . = DATA_SEGMENT_END (.); |
| 205 | /* Stabs debugging sections. */ |
| 206 | .stab 0 : { *(.stab) } |
| 207 | .stabstr 0 : { *(.stabstr) } |
| 208 | .stab.excl 0 : { *(.stab.excl) } |
| 209 | .stab.exclstr 0 : { *(.stab.exclstr) } |
| 210 | .stab.index 0 : { *(.stab.index) } |
| 211 | .stab.indexstr 0 : { *(.stab.indexstr) } |
| 212 | .comment 0 : { *(.comment) } |
| 213 | /* DWARF debug sections. |
| 214 | Symbols in the DWARF debugging sections are relative to the beginning |
| 215 | of the section so we begin them at 0. */ |
| 216 | /* DWARF 1 */ |
| 217 | .debug 0 : { *(.debug) } |
| 218 | .line 0 : { *(.line) } |
| 219 | /* GNU DWARF 1 extensions */ |
| 220 | .debug_srcinfo 0 : { *(.debug_srcinfo) } |
| 221 | .debug_sfnames 0 : { *(.debug_sfnames) } |
| 222 | /* DWARF 1.1 and DWARF 2 */ |
| 223 | .debug_aranges 0 : { *(.debug_aranges) } |
| 224 | .debug_pubnames 0 : { *(.debug_pubnames) } |
| 225 | /* DWARF 2 */ |
| 226 | .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } |
| 227 | .debug_abbrev 0 : { *(.debug_abbrev) } |
| 228 | .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) } |
| 229 | .debug_frame 0 : { *(.debug_frame) } |
| 230 | .debug_str 0 : { *(.debug_str) } |
| 231 | .debug_loc 0 : { *(.debug_loc) } |
| 232 | .debug_macinfo 0 : { *(.debug_macinfo) } |
| 233 | /* SGI/MIPS DWARF 2 extensions */ |
| 234 | .debug_weaknames 0 : { *(.debug_weaknames) } |
| 235 | .debug_funcnames 0 : { *(.debug_funcnames) } |
| 236 | .debug_typenames 0 : { *(.debug_typenames) } |
| 237 | .debug_varnames 0 : { *(.debug_varnames) } |
| 238 | /* DWARF 3 */ |
| 239 | .debug_pubtypes 0 : { *(.debug_pubtypes) } |
| 240 | .debug_ranges 0 : { *(.debug_ranges) } |
| 241 | /* DWARF Extension. */ |
| 242 | .debug_macro 0 : { *(.debug_macro) } |
| 243 | .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } |
| 244 | .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) } |
Ben Cheng | 79781f5 | 2014-05-19 10:33:46 -0700 | [diff] [blame] | 245 | /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) *(.mdebug.*) } |
Ben Cheng | 7823f2a | 2014-04-08 14:53:42 -0700 | [diff] [blame] | 246 | } |