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