1*d2201f2fSdrahn# 2*d2201f2fSdrahn# Unusual variables checked by this code: 3*d2201f2fSdrahn# NOP - two byte opcode for no-op (defaults to 0) 4*d2201f2fSdrahn# INITIAL_READONLY_SECTIONS - at start of text segment 5*d2201f2fSdrahn# OTHER_READONLY_SECTIONS - other than .text .init .rodata ... 6*d2201f2fSdrahn# (e.g., .PARISC.milli) 7*d2201f2fSdrahn# OTHER_TEXT_SECTIONS - these get put in .text when relocating 8*d2201f2fSdrahn# OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ... 9*d2201f2fSdrahn# (e.g., .PARISC.global) 10*d2201f2fSdrahn# OTHER_BSS_SECTIONS - other than .bss .sbss ... 11*d2201f2fSdrahn# OTHER_SECTIONS - at the end 12*d2201f2fSdrahn# EXECUTABLE_SYMBOLS - symbols that must be defined for an 13*d2201f2fSdrahn# executable (e.g., _DYNAMIC_LINK) 14*d2201f2fSdrahn# TEXT_START_SYMBOLS - symbols that appear at the start of the 15*d2201f2fSdrahn# .text section. 16*d2201f2fSdrahn# DATA_START_SYMBOLS - symbols that appear at the start of the 17*d2201f2fSdrahn# .data section. 18*d2201f2fSdrahn# OTHER_GOT_SYMBOLS - symbols defined just before .got. 19*d2201f2fSdrahn# OTHER_GOT_SECTIONS - sections just after .got and .sdata. 20*d2201f2fSdrahn# OTHER_BSS_SYMBOLS - symbols that appear at the start of the 21*d2201f2fSdrahn# .bss section besides __bss_start. 22*d2201f2fSdrahn# INPUT_FILES - INPUT command of files to always include 23*d2201f2fSdrahn# INIT_START, INIT_END - statements just before and just after 24*d2201f2fSdrahn# combination of .init sections. 25*d2201f2fSdrahn# FINI_START, FINI_END - statements just before and just after 26*d2201f2fSdrahn# combination of .fini sections. 27*d2201f2fSdrahn# 28*d2201f2fSdrahn# When adding sections, do note that the names of some sections are used 29*d2201f2fSdrahn# when specifying the start address of the next. 30*d2201f2fSdrahn# 31*d2201f2fSdrahn 32*d2201f2fSdrahn# Many sections come in three flavours. There is the 'real' section, 33*d2201f2fSdrahn# like ".data". Then there are the per-procedure or per-variable 34*d2201f2fSdrahn# sections, generated by -ffunction-sections and -fdata-sections in GCC, 35*d2201f2fSdrahn# and useful for --gc-sections, which for a variable "foo" might be 36*d2201f2fSdrahn# ".data.foo". Then there are the linkonce sections, for which the linker 37*d2201f2fSdrahn# eliminates duplicates, which are named like ".gnu.linkonce.d.foo". 38*d2201f2fSdrahn# The exact correspondences are: 39*d2201f2fSdrahn# 40*d2201f2fSdrahn# Section Linkonce section 41*d2201f2fSdrahn# .text .gnu.linkonce.t.foo 42*d2201f2fSdrahn# .rodata .gnu.linkonce.r.foo 43*d2201f2fSdrahn# .data .gnu.linkonce.d.foo 44*d2201f2fSdrahn# .bss .gnu.linkonce.b.foo 45*d2201f2fSdrahn# .sdata .gnu.linkonce.s.foo 46*d2201f2fSdrahn# .sbss .gnu.linkonce.sb.foo 47*d2201f2fSdrahn# .sdata2 .gnu.linkonce.s2.foo 48*d2201f2fSdrahn# .sbss2 .gnu.linkonce.sb2.foo 49*d2201f2fSdrahn# 50*d2201f2fSdrahn# Each of these can also have corresponding .rel.* and .rela.* sections. 51*d2201f2fSdrahn 52*d2201f2fSdrahntest -z "$ENTRY" && ENTRY=_start 53*d2201f2fSdrahntest -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT} 54*d2201f2fSdrahntest -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT} 55*d2201f2fSdrahnif [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi 56*d2201f2fSdrahntest -z "${ELFSIZE}" && ELFSIZE=32 57*d2201f2fSdrahntest -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8" 58*d2201f2fSdrahnCTOR=".ctors ${CONSTRUCTING-0} : 59*d2201f2fSdrahn { 60*d2201f2fSdrahn ${CONSTRUCTING+${CTOR_START}} 61*d2201f2fSdrahn /* gcc uses crtbegin.o to find the start of 62*d2201f2fSdrahn the constructors, so we make sure it is 63*d2201f2fSdrahn first. Because this is a wildcard, it 64*d2201f2fSdrahn doesn't matter if the user does not 65*d2201f2fSdrahn actually link against crtbegin.o; the 66*d2201f2fSdrahn linker won't look for a file to match a 67*d2201f2fSdrahn wildcard. The wildcard also means that it 68*d2201f2fSdrahn doesn't matter which directory crtbegin.o 69*d2201f2fSdrahn is in. */ 70*d2201f2fSdrahn 71*d2201f2fSdrahn KEEP (*crtbegin*.o(.ctors)) 72*d2201f2fSdrahn 73*d2201f2fSdrahn /* We don't want to include the .ctor section from 74*d2201f2fSdrahn from the crtend.o file until after the sorted ctors. 75*d2201f2fSdrahn The .ctor section from the crtend file contains the 76*d2201f2fSdrahn end of ctors marker and it must be last */ 77*d2201f2fSdrahn 78*d2201f2fSdrahn KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .ctors)) 79*d2201f2fSdrahn KEEP (*(SORT(.ctors.*))) 80*d2201f2fSdrahn KEEP (*(.ctors)) 81*d2201f2fSdrahn ${CONSTRUCTING+${CTOR_END}} 82*d2201f2fSdrahn } > ROM" 83*d2201f2fSdrahn 84*d2201f2fSdrahnDTOR=" .dtors ${CONSTRUCTING-0} : 85*d2201f2fSdrahn { 86*d2201f2fSdrahn ${CONSTRUCTING+${DTOR_START}} 87*d2201f2fSdrahn KEEP (*crtbegin*.o(.dtors)) 88*d2201f2fSdrahn KEEP (*(EXCLUDE_FILE (*crtend*.o $OTHER_EXCLUDE_FILES) .dtors)) 89*d2201f2fSdrahn KEEP (*(SORT(.dtors.*))) 90*d2201f2fSdrahn KEEP (*(.dtors)) 91*d2201f2fSdrahn ${CONSTRUCTING+${DTOR_END}} 92*d2201f2fSdrahn } > ROM" 93*d2201f2fSdrahn 94*d2201f2fSdrahncat <<EOF 95*d2201f2fSdrahnOUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}", 96*d2201f2fSdrahn "${LITTLE_OUTPUT_FORMAT}") 97*d2201f2fSdrahnOUTPUT_ARCH(${OUTPUT_ARCH}) 98*d2201f2fSdrahnENTRY(${ENTRY}) 99*d2201f2fSdrahn 100*d2201f2fSdrahn${RELOCATING+${LIB_SEARCH_DIRS}} 101*d2201f2fSdrahn${RELOCATING+${EXECUTABLE_SYMBOLS}} 102*d2201f2fSdrahn${RELOCATING+${INPUT_FILES}} 103*d2201f2fSdrahn${RELOCATING- /* For some reason, the Solaris linker makes bad executables 104*d2201f2fSdrahn if gld -r is used and the intermediate file has sections starting 105*d2201f2fSdrahn at non-zero addresses. Could be a Solaris ld bug, could be a GNU ld 106*d2201f2fSdrahn bug. But for now assigning the zero vmas works. */} 107*d2201f2fSdrahn 108*d2201f2fSdrahn/* There are two memory regions we care about, one from 0 through 0x7F00 109*d2201f2fSdrahn that is RAM and one from 0x8000 up which is ROM. */ 110*d2201f2fSdrahnMEMORY 111*d2201f2fSdrahn{ 112*d2201f2fSdrahn RAM (w) : ORIGIN = 0, LENGTH = 0x7F00 113*d2201f2fSdrahn ROM (!w) : ORIGIN = 0x8000, LENGTH = 0xFF8000 114*d2201f2fSdrahn} 115*d2201f2fSdrahn 116*d2201f2fSdrahnSECTIONS 117*d2201f2fSdrahn{ 118*d2201f2fSdrahn .data ${RELOCATING-0} : 119*d2201f2fSdrahn { 120*d2201f2fSdrahn ${RELOCATING+__rdata = .;} 121*d2201f2fSdrahn ${RELOCATING+__data = .;} 122*d2201f2fSdrahn ${RELOCATING+${DATA_START_SYMBOLS}} 123*d2201f2fSdrahn *(.data) 124*d2201f2fSdrahn ${RELOCATING+*(.data.*)} 125*d2201f2fSdrahn ${RELOCATING+*(.gnu.linkonce.d.*)} 126*d2201f2fSdrahn ${CONSTRUCTING+SORT(CONSTRUCTORS)} 127*d2201f2fSdrahn } > RAM 128*d2201f2fSdrahn ${RELOCATING+${OTHER_READWRITE_SECTIONS}} 129*d2201f2fSdrahn ${RELOCATING+${OTHER_GOT_SYMBOLS}} 130*d2201f2fSdrahn ${RELOCATING+${OTHER_GOT_SECTIONS}} 131*d2201f2fSdrahn ${RELOCATING+_edata = .;} 132*d2201f2fSdrahn ${RELOCATING+PROVIDE (edata = .);} 133*d2201f2fSdrahn ${RELOCATING+__bss_start = .;} 134*d2201f2fSdrahn ${RELOCATING+${OTHER_BSS_SYMBOLS}} 135*d2201f2fSdrahn .bss ${RELOCATING-0} : 136*d2201f2fSdrahn { 137*d2201f2fSdrahn *(.dynbss) 138*d2201f2fSdrahn *(.bss) 139*d2201f2fSdrahn ${RELOCATING+*(.bss.*)} 140*d2201f2fSdrahn ${RELOCATING+*(.gnu.linkonce.b.*)} 141*d2201f2fSdrahn *(COMMON) 142*d2201f2fSdrahn /* Align here to ensure that the .bss section occupies space up to 143*d2201f2fSdrahn _end. Align after .bss to ensure correct alignment even if the 144*d2201f2fSdrahn .bss section disappears because there are no input sections. */ 145*d2201f2fSdrahn ${RELOCATING+. = ALIGN(${ALIGNMENT});} 146*d2201f2fSdrahn } > RAM 147*d2201f2fSdrahn ${RELOCATING+${OTHER_BSS_SECTIONS}} 148*d2201f2fSdrahn ${RELOCATING+. = ALIGN(${ALIGNMENT});} 149*d2201f2fSdrahn ${RELOCATING+_end = .;} 150*d2201f2fSdrahn ${RELOCATING+__stack = .;} 151*d2201f2fSdrahn ${RELOCATING+${OTHER_BSS_END_SYMBOLS}} 152*d2201f2fSdrahn ${RELOCATING+PROVIDE (end = .);} 153*d2201f2fSdrahn 154*d2201f2fSdrahn /* Read-only sections in ROM. */ 155*d2201f2fSdrahn .int_vec ${RELOCATING-0} : { *(.int_vec) } > ROM 156*d2201f2fSdrahn 157*d2201f2fSdrahn .rodata ${RELOCATING-0} : { *(.rodata) ${RELOCATING+*(.rodata.*)} ${RELOCATING+*(.gnu.linkonce.r.*)} } > ROM 158*d2201f2fSdrahn ${RELOCATING+${CTOR}} 159*d2201f2fSdrahn ${RELOCATING+${DTOR}} 160*d2201f2fSdrahn .jcr : { KEEP (*(.jcr)) } > ROM 161*d2201f2fSdrahn .eh_frame : { KEEP (*(.eh_frame)) } > ROM 162*d2201f2fSdrahn .gcc_except_table : { *(.gcc_except_table) } > ROM 163*d2201f2fSdrahn .plt : { *(.plt) } > ROM 164*d2201f2fSdrahn 165*d2201f2fSdrahn .text ${RELOCATING-0} : 166*d2201f2fSdrahn { 167*d2201f2fSdrahn ${RELOCATING+${TEXT_START_SYMBOLS}} 168*d2201f2fSdrahn *(.text) 169*d2201f2fSdrahn ${RELOCATING+*(.text.*)} 170*d2201f2fSdrahn *(.stub) 171*d2201f2fSdrahn /* .gnu.warning sections are handled specially by elf32.em. */ 172*d2201f2fSdrahn *(.gnu.warning) 173*d2201f2fSdrahn ${RELOCATING+*(.gnu.linkonce.t.*)} 174*d2201f2fSdrahn ${RELOCATING+${OTHER_TEXT_SECTIONS}} 175*d2201f2fSdrahn } > ROM =${NOP-0} 176*d2201f2fSdrahn .init ${RELOCATING-0} : 177*d2201f2fSdrahn { 178*d2201f2fSdrahn ${RELOCATING+${INIT_START}} 179*d2201f2fSdrahn KEEP (*(.init)) 180*d2201f2fSdrahn ${RELOCATING+${INIT_END}} 181*d2201f2fSdrahn } > ROM =${NOP-0} 182*d2201f2fSdrahn .fini ${RELOCATING-0} : 183*d2201f2fSdrahn { 184*d2201f2fSdrahn ${RELOCATING+${FINI_START}} 185*d2201f2fSdrahn KEEP (*(.fini)) 186*d2201f2fSdrahn ${RELOCATING+${FINI_END}} 187*d2201f2fSdrahn } > ROM =${NOP-0} 188*d2201f2fSdrahn ${RELOCATING+PROVIDE (__etext = .);} 189*d2201f2fSdrahn ${RELOCATING+PROVIDE (_etext = .);} 190*d2201f2fSdrahn ${RELOCATING+PROVIDE (etext = .);} 191*d2201f2fSdrahn ${RELOCATING+${OTHER_READONLY_SECTIONS}} 192*d2201f2fSdrahn 193*d2201f2fSdrahn 194*d2201f2fSdrahn /* Stabs debugging sections. */ 195*d2201f2fSdrahn .stab 0 : { *(.stab) } 196*d2201f2fSdrahn .stabstr 0 : { *(.stabstr) } 197*d2201f2fSdrahn .stab.excl 0 : { *(.stab.excl) } 198*d2201f2fSdrahn .stab.exclstr 0 : { *(.stab.exclstr) } 199*d2201f2fSdrahn .stab.index 0 : { *(.stab.index) } 200*d2201f2fSdrahn .stab.indexstr 0 : { *(.stab.indexstr) } 201*d2201f2fSdrahn 202*d2201f2fSdrahn .comment 0 : { *(.comment) } 203*d2201f2fSdrahn 204*d2201f2fSdrahn /* DWARF debug sections. 205*d2201f2fSdrahn Symbols in the DWARF debugging sections are relative to the beginning 206*d2201f2fSdrahn of the section so we begin them at 0. */ 207*d2201f2fSdrahn 208*d2201f2fSdrahn /* DWARF 1 */ 209*d2201f2fSdrahn .debug 0 : { *(.debug) } 210*d2201f2fSdrahn .line 0 : { *(.line) } 211*d2201f2fSdrahn 212*d2201f2fSdrahn /* GNU DWARF 1 extensions */ 213*d2201f2fSdrahn .debug_srcinfo 0 : { *(.debug_srcinfo) } 214*d2201f2fSdrahn .debug_sfnames 0 : { *(.debug_sfnames) } 215*d2201f2fSdrahn 216*d2201f2fSdrahn /* DWARF 1.1 and DWARF 2 */ 217*d2201f2fSdrahn .debug_aranges 0 : { *(.debug_aranges) } 218*d2201f2fSdrahn .debug_pubnames 0 : { *(.debug_pubnames) } 219*d2201f2fSdrahn 220*d2201f2fSdrahn /* DWARF 2 */ 221*d2201f2fSdrahn .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } 222*d2201f2fSdrahn .debug_abbrev 0 : { *(.debug_abbrev) } 223*d2201f2fSdrahn .debug_line 0 : { *(.debug_line) } 224*d2201f2fSdrahn .debug_frame 0 : { *(.debug_frame) } 225*d2201f2fSdrahn .debug_str 0 : { *(.debug_str) } 226*d2201f2fSdrahn .debug_loc 0 : { *(.debug_loc) } 227*d2201f2fSdrahn .debug_macinfo 0 : { *(.debug_macinfo) } 228*d2201f2fSdrahn 229*d2201f2fSdrahn /* SGI/MIPS DWARF 2 extensions */ 230*d2201f2fSdrahn .debug_weaknames 0 : { *(.debug_weaknames) } 231*d2201f2fSdrahn .debug_funcnames 0 : { *(.debug_funcnames) } 232*d2201f2fSdrahn .debug_typenames 0 : { *(.debug_typenames) } 233*d2201f2fSdrahn .debug_varnames 0 : { *(.debug_varnames) } 234*d2201f2fSdrahn 235*d2201f2fSdrahn ${RELOCATING+${OTHER_RELOCATING_SECTIONS}} 236*d2201f2fSdrahn 237*d2201f2fSdrahn /* These must appear regardless of ${RELOCATING}. */ 238*d2201f2fSdrahn ${OTHER_SECTIONS} 239*d2201f2fSdrahn} 240*d2201f2fSdrahnEOF 241