1# 2# Unusual variables checked by this code: 3# NOP - four byte opcode for no-op (defaults to 0) 4# NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not 5# empty. 6# DATA_ADDR - if end-of-text-plus-one-page isn't right for data start 7# INITIAL_READONLY_SECTIONS - at start of text segment 8# OTHER_READONLY_SECTIONS - other than .text .init .rodata ... 9# (e.g., .PARISC.milli) 10# OTHER_TEXT_SECTIONS - these get put in .text when relocating 11# OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ... 12# (e.g., .PARISC.global) 13# OTHER_BSS_SECTIONS - other than .bss .sbss ... 14# OTHER_SECTIONS - at the end 15# EXECUTABLE_SYMBOLS - symbols that must be defined for an 16# executable (e.g., _DYNAMIC_LINK) 17# TEXT_START_SYMBOLS - symbols that appear at the start of the 18# .text section. 19# DATA_START_SYMBOLS - symbols that appear at the start of the 20# .data section. 21# OTHER_GOT_SYMBOLS - symbols defined just before .got. 22# OTHER_GOT_SECTIONS - sections just after .got. 23# OTHER_SDATA_SECTIONS - sections just after .sdata. 24# OTHER_BSS_SYMBOLS - symbols that appear at the start of the 25# .bss section besides __bss_start. 26# DATA_PLT - .plt should be in data segment, not text segment. 27# BSS_PLT - .plt should be in bss segment 28# TEXT_DYNAMIC - .dynamic in text segment, not data segment. 29# EMBEDDED - whether this is for an embedded system. 30# SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set 31# start address of shared library. 32# INPUT_FILES - INPUT command of files to always include 33# WRITABLE_RODATA - if set, the .rodata section should be writable 34# INIT_START, INIT_END - statements just before and just after 35# combination of .init sections. 36# FINI_START, FINI_END - statements just before and just after 37# combination of .fini sections. 38# STACK_ADDR - start of a .stack section. 39# OTHER_END_SYMBOLS - symbols to place right at the end of the script. 40# 41# When adding sections, do note that the names of some sections are used 42# when specifying the start address of the next. 43# 44 45# Many sections come in three flavours. There is the 'real' section, 46# like ".data". Then there are the per-procedure or per-variable 47# sections, generated by -ffunction-sections and -fdata-sections in GCC, 48# and useful for --gc-sections, which for a variable "foo" might be 49# ".data.foo". Then there are the linkonce sections, for which the linker 50# eliminates duplicates, which are named like ".gnu.linkonce.d.foo". 51# The exact correspondences are: 52# 53# Section Linkonce section 54# .text .gnu.linkonce.t.foo 55# .rodata .gnu.linkonce.r.foo 56# .data .gnu.linkonce.d.foo 57# .bss .gnu.linkonce.b.foo 58# .sdata .gnu.linkonce.s.foo 59# .sbss .gnu.linkonce.sb.foo 60# .sdata2 .gnu.linkonce.s2.foo 61# .sbss2 .gnu.linkonce.sb2.foo 62# .debug_info .gnu.linkonce.wi.foo 63# .tdata .gnu.linkonce.td.foo 64# .tbss .gnu.linkonce.tb.foo 65# 66# Each of these can also have corresponding .rel.* and .rela.* sections. 67 68test -z "$ENTRY" && ENTRY=_start 69test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT} 70test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} 71if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi 72test -z "${ELFSIZE}" && ELFSIZE=32 73test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8" 74test "$LD_FLAG" = "N" && DATA_ADDR=. 75test -n "$CREATE_SHLIB" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE="" 76test -z "$CREATE_SHLIB" && test -n "$DATA_ADDR" && COMMONPAGESIZE="" 77DATA_SEGMENT_ALIGN="ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))" 78DATA_SEGMENT_END="" 79if test -n "${COMMONPAGESIZE}"; then 80 DATA_SEGMENT_ALIGN="DATA_SEGMENT_ALIGN(${MAXPAGESIZE}, ${COMMONPAGESIZE})" 81 DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);" 82fi 83INTERP=".interp ${RELOCATING-0} : { *(.interp) }" 84PLT=".plt ${RELOCATING-0} : { *(.plt) }" 85DYNAMIC=".dynamic ${RELOCATING-0} : { *(.dynamic) }" 86RODATA=".rodata ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }" 87if test -z "${NO_SMALL_DATA}"; then 88 SBSS=".sbss ${RELOCATING-0} : 89 { 90 ${RELOCATING+PROVIDE (__sbss_start = .);} 91 ${RELOCATING+PROVIDE (___sbss_start = .);} 92 *(.dynsbss) 93 *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*}) 94 *(.scommon) 95 ${RELOCATING+PROVIDE (__sbss_end = .);} 96 ${RELOCATING+PROVIDE (___sbss_end = .);} 97 }" 98 SBSS2=".sbss2 ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }" 99 SDATA="/* We want the small data sections together, so single-instruction offsets 100 can access them all, and initialized data all before uninitialized, so 101 we can shorten the on-disk segment size. */ 102 .sdata ${RELOCATING-0} : 103 { 104 ${RELOCATING+${SDATA_START_SYMBOLS}} 105 *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*}) 106 }" 107 SDATA2=".sdata2 ${RELOCATING-0} : { *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*}) }" 108 REL_SDATA=".rel.sdata ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) } 109 .rela.sdata ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }" 110 REL_SBSS=".rel.sbss ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) } 111 .rela.sbss ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }" 112 REL_SDATA2=".rel.sdata2 ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) } 113 .rela.sdata2 ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }" 114 REL_SBSS2=".rel.sbss2 ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) } 115 .rela.sbss2 ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }" 116fi 117CTOR=".ctors ${CONSTRUCTING-0} : 118 { 119 ${CONSTRUCTING+${CTOR_START}} 120 /* gcc uses crtbegin.o to find the start of 121 the constructors, so we make sure it is 122 first. Because this is a wildcard, it 123 doesn't matter if the user does not 124 actually link against crtbegin.o; the 125 linker won't look for a file to match a 126 wildcard. The wildcard also means that it 127 doesn't matter which directory crtbegin.o 128 is in. */ 129 130 KEEP (*crtbegin.o(.ctors)) 131 132 /* We don't want to include the .ctor section from 133 from the crtend.o file until after the sorted ctors. 134 The .ctor section from the crtend file contains the 135 end of ctors marker and it must be last */ 136 137 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .ctors)) 138 KEEP (*(SORT(.ctors.*))) 139 KEEP (*(.ctors)) 140 ${CONSTRUCTING+${CTOR_END}} 141 }" 142DTOR=".dtors ${CONSTRUCTING-0} : 143 { 144 ${CONSTRUCTING+${DTOR_START}} 145 KEEP (*crtbegin.o(.dtors)) 146 KEEP (*(EXCLUDE_FILE (*crtend.o $OTHER_EXCLUDE_FILES) .dtors)) 147 KEEP (*(SORT(.dtors.*))) 148 KEEP (*(.dtors)) 149 ${CONSTRUCTING+${DTOR_END}} 150 }" 151STACK=" .stack ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} : 152 { 153 ${RELOCATING+_stack = .;} 154 *(.stack) 155 }" 156 157# if this is for an embedded system, don't add SIZEOF_HEADERS. 158if [ -z "$EMBEDDED" ]; then 159 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS" 160else 161 test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}" 162fi 163 164cat <<EOF 165OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", 166 "${LITTLE_OUTPUT_FORMAT}") 167OUTPUT_ARCH(${OUTPUT_ARCH}) 168ENTRY(${ENTRY}) 169 170${RELOCATING+${LIB_SEARCH_DIRS}} 171${RELOCATING+/* Do we need any of these for elf? 172 __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}} */} 173${RELOCATING+${EXECUTABLE_SYMBOLS}} 174${RELOCATING+${INPUT_FILES}} 175${RELOCATING- /* For some reason, the Solaris linker makes bad executables 176 if gld -r is used and the intermediate file has sections starting 177 at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld 178 bug. But for now assigning the zero vmas works. */} 179 180SECTIONS 181{ 182 /* Read-only sections, merged into text segment: */ 183 ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}} 184 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}} 185 ${CREATE_SHLIB-${INTERP}} 186 ${INITIAL_READONLY_SECTIONS} 187 ${TEXT_DYNAMIC+${DYNAMIC}} 188 .hash ${RELOCATING-0} : { *(.hash) } 189 .dynsym ${RELOCATING-0} : { *(.dynsym) } 190 .dynstr ${RELOCATING-0} : { *(.dynstr) } 191 .gnu.version ${RELOCATING-0} : { *(.gnu.version) } 192 .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) } 193 .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) } 194 195EOF 196if [ "x$COMBRELOC" = x ]; then 197 COMBRELOCCAT=cat 198else 199 COMBRELOCCAT="cat > $COMBRELOC" 200fi 201eval $COMBRELOCCAT <<EOF 202 .rel.init ${RELOCATING-0} : { *(.rel.init) } 203 .rela.init ${RELOCATING-0} : { *(.rela.init) } 204 .rel.text ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) } 205 .rela.text ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) } 206 .rel.fini ${RELOCATING-0} : { *(.rel.fini) } 207 .rela.fini ${RELOCATING-0} : { *(.rela.fini) } 208 .rel.rodata ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) } 209 .rela.rodata ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) } 210 ${OTHER_READONLY_RELOC_SECTIONS} 211 .rel.data ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) } 212 .rela.data ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) } 213 .rel.tdata ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) } 214 .rela.tdata ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) } 215 .rel.tbss ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) } 216 .rela.tbss ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) } 217 .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) } 218 .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) } 219 .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) } 220 .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) } 221 .rel.got ${RELOCATING-0} : { *(.rel.got) } 222 .rela.got ${RELOCATING-0} : { *(.rela.got) } 223 ${OTHER_GOT_RELOC_SECTIONS} 224 ${REL_SDATA} 225 ${REL_SBSS} 226 ${REL_SDATA2} 227 ${REL_SBSS2} 228 .rel.bss ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) } 229 .rela.bss ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) } 230EOF 231if [ -n "$COMBRELOC" ]; then 232cat <<EOF 233 .rel.dyn ${RELOCATING-0} : 234 { 235EOF 236sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/ \1/' $COMBRELOC 237cat <<EOF 238 } 239 .rela.dyn ${RELOCATING-0} : 240 { 241EOF 242sed -e '/^[ ]*[{}][ ]*$/d;/:[ ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/ \1/' $COMBRELOC 243cat <<EOF 244 } 245EOF 246fi 247cat <<EOF 248 .rel.plt ${RELOCATING-0} : { *(.rel.plt) } 249 .rela.plt ${RELOCATING-0} : { *(.rela.plt) } 250 ${OTHER_PLT_RELOC_SECTIONS} 251 252 .init ${RELOCATING-0} : 253 { 254 ${RELOCATING+${INIT_START}} 255 KEEP (*(.init)) 256 ${RELOCATING+${INIT_END}} 257 } =${NOP-0} 258 259 ${DATA_PLT-${BSS_PLT-${PLT}}} 260 .text ${RELOCATING-0} : 261 { 262 ${RELOCATING+${TEXT_START_SYMBOLS}} 263 *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*}) 264 /* .gnu.warning sections are handled specially by elf32.em. */ 265 *(.gnu.warning) 266 ${RELOCATING+${OTHER_TEXT_SECTIONS}} 267 } =${NOP-0} 268 .fini ${RELOCATING-0} : 269 { 270 ${RELOCATING+${FINI_START}} 271 KEEP (*(.fini)) 272 ${RELOCATING+${FINI_END}} 273 } =${NOP-0} 274 ${RELOCATING+PROVIDE (__etext = .);} 275 ${RELOCATING+PROVIDE (_etext = .);} 276 ${RELOCATING+PROVIDE (etext = .);} 277 ${WRITABLE_RODATA-${RODATA}} 278 .rodata1 ${RELOCATING-0} : { *(.rodata1) } 279 ${CREATE_SHLIB-${SDATA2}} 280 ${CREATE_SHLIB-${SBSS2}} 281 ${OTHER_READONLY_SECTIONS} 282 .eh_frame_hdr : { *(.eh_frame_hdr) } 283 284 /* Adjust the address for the data segment. We want to adjust up to 285 the same address within the page on the next page up. */ 286 ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}} 287 ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}} 288 289 /* Ensure the __preinit_array_start label is properly aligned. We 290 could instead move the label definition inside the section, but 291 the linker would then create the section even if it turns out to 292 be empty, which isn't pretty. */ 293 ${RELOCATING+. = ALIGN(${ALIGNMENT});} 294 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}} 295 .preinit_array ${RELOCATING-0} : { *(.preinit_array) } 296 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}} 297 298 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}} 299 .init_array ${RELOCATING-0} : { *(.init_array) } 300 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}} 301 302 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}} 303 .fini_array ${RELOCATING-0} : { *(.fini_array) } 304 ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}} 305 306 .data ${RELOCATING-0} : 307 { 308 ${RELOCATING+${DATA_START_SYMBOLS}} 309 *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*}) 310 ${CONSTRUCTING+SORT(CONSTRUCTORS)} 311 } 312 .data1 ${RELOCATING-0} : { *(.data1) } 313 .tdata ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) } 314 .tbss ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} } 315 .eh_frame ${RELOCATING-0} : { KEEP (*(.eh_frame)) } 316 .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) } 317 ${WRITABLE_RODATA+${RODATA}} 318 ${OTHER_READWRITE_SECTIONS} 319 ${TEXT_DYNAMIC-${DYNAMIC}} 320 ${RELOCATING+${CTOR}} 321 ${RELOCATING+${DTOR}} 322 .jcr ${RELOCATING-0} : { KEEP (*(.jcr)) } 323 ${DATA_PLT+${PLT}} 324 ${RELOCATING+${OTHER_GOT_SYMBOLS}} 325 .got ${RELOCATING-0} : { *(.got.plt) *(.got) } 326 ${OTHER_GOT_SECTIONS} 327 ${CREATE_SHLIB+${SDATA2}} 328 ${CREATE_SHLIB+${SBSS2}} 329 ${SDATA} 330 ${OTHER_SDATA_SECTIONS} 331 ${RELOCATING+_edata = .;} 332 ${RELOCATING+PROVIDE (edata = .);} 333 ${RELOCATING+__bss_start = .;} 334 ${RELOCATING+${OTHER_BSS_SYMBOLS}} 335 ${SBSS} 336 ${BSS_PLT+${PLT}} 337 .bss ${RELOCATING-0} : 338 { 339 *(.dynbss) 340 *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*}) 341 *(COMMON) 342 /* Align here to ensure that the .bss section occupies space up to 343 _end. Align after .bss to ensure correct alignment even if the 344 .bss section disappears because there are no input sections. */ 345 ${RELOCATING+. = ALIGN(${ALIGNMENT});} 346 } 347 ${OTHER_BSS_SECTIONS} 348 ${RELOCATING+. = ALIGN(${ALIGNMENT});} 349 ${RELOCATING+_end = .;} 350 ${RELOCATING+${OTHER_BSS_END_SYMBOLS}} 351 ${RELOCATING+PROVIDE (end = .);} 352 ${RELOCATING+${DATA_SEGMENT_END}} 353 354 /* Stabs debugging sections. */ 355 .stab 0 : { *(.stab) } 356 .stabstr 0 : { *(.stabstr) } 357 .stab.excl 0 : { *(.stab.excl) } 358 .stab.exclstr 0 : { *(.stab.exclstr) } 359 .stab.index 0 : { *(.stab.index) } 360 .stab.indexstr 0 : { *(.stab.indexstr) } 361 362 .comment 0 : { *(.comment) } 363 364 /* DWARF debug sections. 365 Symbols in the DWARF debugging sections are relative to the beginning 366 of the section so we begin them at 0. */ 367 368 /* DWARF 1 */ 369 .debug 0 : { *(.debug) } 370 .line 0 : { *(.line) } 371 372 /* GNU DWARF 1 extensions */ 373 .debug_srcinfo 0 : { *(.debug_srcinfo) } 374 .debug_sfnames 0 : { *(.debug_sfnames) } 375 376 /* DWARF 1.1 and DWARF 2 */ 377 .debug_aranges 0 : { *(.debug_aranges) } 378 .debug_pubnames 0 : { *(.debug_pubnames) } 379 380 /* DWARF 2 */ 381 .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } 382 .debug_abbrev 0 : { *(.debug_abbrev) } 383 .debug_line 0 : { *(.debug_line) } 384 .debug_frame 0 : { *(.debug_frame) } 385 .debug_str 0 : { *(.debug_str) } 386 .debug_loc 0 : { *(.debug_loc) } 387 .debug_macinfo 0 : { *(.debug_macinfo) } 388 389 /* SGI/MIPS DWARF 2 extensions */ 390 .debug_weaknames 0 : { *(.debug_weaknames) } 391 .debug_funcnames 0 : { *(.debug_funcnames) } 392 .debug_typenames 0 : { *(.debug_typenames) } 393 .debug_varnames 0 : { *(.debug_varnames) } 394 395 ${STACK_ADDR+${STACK}} 396 ${OTHER_SECTIONS} 397 ${RELOCATING+${OTHER_END_SYMBOLS}} 398} 399EOF 400