1# Copyright (C) 2014-2024 Free Software Foundation, Inc.
2#
3# Copying and distribution of this file, with or without modification,
4# are permitted in any medium without royalty provided the copyright
5# notice and this notice are preserved.
6
7cat << EOF
8/* Copyright (C) 2014-2024 Free Software Foundation, Inc.
9
10   Copying and distribution of this script, with or without modification,
11   are permitted in any medium without royalty provided the copyright
12   notice and this notice are preserved.  */
13
14OUTPUT_FORMAT("elf32-v850-rh850", "elf32-v850-rh850",
15                "elf32-v850-rh850")
16OUTPUT_ARCH(v850:rh850)
17${RELOCATING+ENTRY(_start)}
18SEARCH_DIR(.);
19${RELOCATING+EXTERN(__ctbp __ep __gp)};
20SECTIONS
21{
22  /* This saves a little space in the ELF file, since the zda starts
23     at a higher location that the ELF headers take up.  */
24
25  .zdata ${ZDATA_START_ADDR} :
26  {
27          *(.zdata)
28          ${RELOCATING+*(.zdata23)
29          *(.zbss)
30          *(.zbss23)
31          *(reszdata)
32          *(.zcommon)}
33  }
34
35  /* This is the read only part of the zero data area.
36     Having it as a separate section prevents its
37     attributes from being inherited by the zdata
38     section.  Specifically it prevents the zdata
39     section from being marked READONLY.  */
40
41  .rozdata ${ROZDATA_START_ADDR} :
42  {
43          *(.rozdata)
44          ${RELOCATING+*(romzdata)
45          *(romzbss)
46          *(.zconst)
47          *(.zconst23)}
48  }
49
50  /* Read-only sections, merged into text segment.  */
51  . = ${TEXT_START_ADDR};
52  .interp : { *(.interp) }
53  .hash             : { *(.hash) }
54  .dynsym : { *(.dynsym) }
55  .dynstr : { *(.dynstr) }
56  .rel.text         : { *(.rel.text) }
57  .rela.text        : { *(.rela.text) }
58  .rel.data         : { *(.rel.data) }
59  .rela.data        : { *(.rela.data) }
60  .rel.rodata       : { *(.rel.rodata) }
61  .rela.rodata      : { *(.rela.rodata) }
62  .rel.gcc_except_table : { *(.rel.gcc_except_table) }
63  .rela.gcc_except_table : { *(.rela.gcc_except_table) }
64  .rel.got          : { *(.rel.got) }
65  .rela.got         : { *(.rela.got) }
66  .rel.ctors        : { *(.rel.ctors) }
67  .rela.ctors       : { *(.rela.ctors) }
68  .rel.dtors        : { *(.rel.dtors) }
69  .rela.dtors       : { *(.rela.dtors) }
70  .rel.init         : { *(.rel.init) }
71  .rela.init        : { *(.rela.init) }
72  .rel.fini         : { *(.rel.fini) }
73  .rela.fini        : { *(.rela.fini) }
74  .rel.bss          : { *(.rel.bss) }
75  .rela.bss         : { *(.rela.bss) }
76  .rel.plt          : { *(.rel.plt) }
77  .rela.plt         : { *(.rela.plt) }
78  .init             : { KEEP (*(SORT_NONE(.init))) } =0
79  .plt              : { *(.plt) }
80
81  .text             :
82  {
83    *(.text)
84    ${RELOCATING+*(.text.*)}
85
86    /* .gnu.warning sections are handled specially by elf.em.  */
87    *(.gnu.warning)
88    ${RELOCATING+*(.gnu.linkonce.t*)}
89  } =0
90
91  ${RELOCATING+_etext = .;}
92  ${RELOCATING+PROVIDE (etext = .);}
93
94   /* This is special code area at the end of the normal text section.
95      It contains a small lookup table at the start followed by the
96      code pointed to by entries in the lookup table.  */
97
98  .call_table_data ${CALL_TABLE_START_ADDR} :
99  {
100    ${RELOCATING+PROVIDE(__ctbp = .);}
101    *(.call_table_data)
102  } = 0xff   /* Fill gaps with 0xff.  */
103
104  .call_table_text :
105  {
106    *(.call_table_text)
107  }
108
109  .fini             : { KEEP (*(SORT_NONE(.fini))) } =0
110  .rodata :
111  {
112          *(.rodata)
113          ${RELOCATING+*(.rodata.*)
114          *(.gnu.linkonce.r*)
115          *(.const)}
116  }
117  .rodata1          : { *(.rodata1) }
118
119  .data             :
120  {
121    *(.data)
122    ${RELOCATING+*(.data.*)
123    *(.gnu.linkonce.d*)}
124    ${CONSTRUCTING+CONSTRUCTORS}
125  }
126  .data1  : { *(.data1) }
127  .ctors  :
128  {
129    ${CONSTRUCTING+___ctors = .;}
130    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
131    ${RELOCATING+KEEP (*(SORT(.ctors.*)))}
132    KEEP (*crtend(.ctors))
133    ${CONSTRUCTING+___ctors_end = .;}
134  }
135  .dtors  :
136  {
137    ${CONSTRUCTING+___dtors = .;}
138    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
139    ${RELOCATING+KEEP (*(SORT(.dtors.*)))}
140    KEEP (*crtend.o(.dtors))
141    ${CONSTRUCTING+___dtors_end = .;}
142  }
143  .jcr              :
144  {
145    KEEP (*(.jcr))
146  }
147
148  .gcc_except_table : { *(.gcc_except_table) }
149
150  .got              : {${RELOCATING+ *(.got.plt)} *(.got) }
151  .dynamic          : { *(.dynamic) }
152
153  .tdata ${TDATA_START_ADDR} :
154  {
155          ${RELOCATING+PROVIDE (__ep = .);
156          *(.edata)
157          *(.edata23)
158          *(.tbyte)
159          *(.tcommon_byte)}
160          *(.tdata)
161          ${RELOCATING+*(.tdata*)
162          *(.ebss)
163          *(.ebss23)
164          *(.tbss)
165          *(.tbss*)
166          *(.tcommon)}
167  }
168
169  /* We want the small data sections together, so single-instruction offsets
170     can access them all, and initialized data all before uninitialized, so
171     we can shorten the on-disk segment size.  */
172
173  .sdata ${SDATA_START_ADDR} :
174  {
175          ${RELOCATING+PROVIDE (__gp = . + 0x8000);}
176          *(.sdata)
177          ${RELOCATING+*(.sdata23)}
178   }
179
180  /* See comment about .rozdata. */
181  .rosdata ${ROSDATA_START_ADDR} :
182  {
183          *(.rosdata)
184          ${RELOCATING+*(.sconst)
185          *(.sconst23)}
186  }
187
188  /* We place the .sbss data section AFTER the .rosdata section, so that
189     it can directly precede the .bss section.  This allows runtime startup
190     code to initialise all the zero-data sections by simply taking the
191     value of '_edata' and zeroing until it reaches '_end'.  */
192
193  .sbss :
194  {
195          ${RELOCATING+__sbss_start = .;}
196          *(.sbss)
197          ${RELOCATING+*(.sbss23)
198          *(.scommon)}
199  }
200
201  ${RELOCATING+_edata  = DEFINED (__sbss_start) ? __sbss_start : . ;}
202  ${RELOCATING+PROVIDE (edata = _edata);}
203
204  .bss       :
205  {
206          ${RELOCATING+__bss_start = DEFINED (__sbss_start) ? __sbss_start : . ;}
207          ${RELOCATING+__real_bss_start = . ;}
208          ${RELOCATING+*(.dynbss)}
209          *(.bss)
210          ${RELOCATING+*(COMMON)}
211  }
212
213  ${RELOCATING+_end = . ;}
214  ${RELOCATING+PROVIDE (end = .);}
215  ${RELOCATING+PROVIDE (_heap_start = .);}
216
217  .note.renesas 0 : { KEEP(*(.note.renesas)) }
218
219EOF
220
221source_sh $srcdir/scripttempl/misc-sections.sc
222source_sh $srcdir/scripttempl/DWARF.sc
223
224cat <<EOF
225  /* User stack.  */
226  .stack 0x200000   :
227  {
228          ${RELOCATING+__stack = .;}
229          *(.stack)
230  }
231}
232EOF
233