* scripttempl/elf.sc: Handle function names and other
[external/binutils.git] / ld / scripttempl / epiphany_4x4.sc
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 #       SMALL_DATA_CTOR - .ctors contains small data.
7 #       SMALL_DATA_DTOR - .dtors contains small data.
8 #       DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
9 #       INITIAL_READONLY_SECTIONS - at start of text segment
10 #       OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
11 #               (e.g., .PARISC.milli)
12 #       OTHER_TEXT_SECTIONS - these get put in .text when relocating
13 #       OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
14 #               (e.g., .PARISC.global)
15 #       OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
16 #               (e.g. PPC32 .fixup, .got[12])
17 #       OTHER_BSS_SECTIONS - other than .bss .sbss ...
18 #       ATTRS_SECTIONS - at the end
19 #       OTHER_SECTIONS - at the end
20 #       EXECUTABLE_SYMBOLS - symbols that must be defined for an
21 #               executable (e.g., _DYNAMIC_LINK)
22 #       TEXT_START_ADDR - the first byte of the text segment, after any
23 #               headers.
24 #       TEXT_BASE_ADDRESS - the first byte of the text segment.
25 #       TEXT_START_SYMBOLS - symbols that appear at the start of the
26 #               .text section.
27 #       DATA_START_SYMBOLS - symbols that appear at the start of the
28 #               .data section.
29 #       DATA_END_SYMBOLS - symbols that appear at the end of the
30 #               writeable data sections.
31 #       OTHER_GOT_SYMBOLS - symbols defined just before .got.
32 #       OTHER_GOT_SECTIONS - sections just after .got.
33 #       OTHER_SDATA_SECTIONS - sections just after .sdata.
34 #       OTHER_BSS_SYMBOLS - symbols that appear at the start of the
35 #               .bss section besides ___bss_start.
36 #       DATA_PLT - .plt should be in data segment, not text segment.
37 #       PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
38 #       BSS_PLT - .plt should be in bss segment
39 #       NO_REL_RELOCS - Don't include .rel.* sections in script
40 #       NO_RELA_RELOCS - Don't include .rela.* sections in script
41 #       NON_ALLOC_DYN - Place dynamic sections after data segment.
42 #       TEXT_DYNAMIC - .dynamic in text segment, not data segment.
43 #       EMBEDDED - whether this is for an embedded system. 
44 #       SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
45 #               start address of shared library.
46 #       INPUT_FILES - INPUT command of files to always include
47 #       WRITABLE_RODATA - if set, the .rodata section should be writable
48 #       INIT_START, INIT_END -  statements just before and just after
49 #       combination of .init sections.
50 #       FINI_START, FINI_END - statements just before and just after
51 #       combination of .fini sections.
52 #       STACK_ADDR - start of a .stack section.
53 #       OTHER_SYMBOLS - symbols to place right at the end of the script.
54 #       ETEXT_NAME - name of a symbol for the end of the text section,
55 #               normally etext.
56 #       SEPARATE_GOTPLT - if set, .got.plt should be separate output section,
57 #               so that .got can be in the RELRO area.  It should be set to
58 #               the number of bytes in the beginning of .got.plt which can be
59 #               in the RELRO area as well.
60 #       USER_LABEL_PREFIX - prefix to add to user-visible symbols.
61 #
62 # When adding sections, do note that the names of some sections are used
63 # when specifying the start address of the next.
64 #
65
66 #  Many sections come in three flavours.  There is the 'real' section,
67 #  like ".data".  Then there are the per-procedure or per-variable
68 #  sections, generated by -ffunction-sections and -fdata-sections in GCC,
69 #  and useful for --gc-sections, which for a variable "foo" might be
70 #  ".data.foo".  Then there are the linkonce sections, for which the linker
71 #  eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
72 #  The exact correspondences are:
73 #
74 #  Section      Linkonce section
75 #  .text        .gnu.linkonce.t.foo
76 #  .rodata      .gnu.linkonce.r.foo
77 #  .data        .gnu.linkonce.d.foo
78 #  .bss         .gnu.linkonce.b.foo
79 #  .sdata       .gnu.linkonce.s.foo
80 #  .sbss        .gnu.linkonce.sb.foo
81 #  .sdata2      .gnu.linkonce.s2.foo
82 #  .sbss2       .gnu.linkonce.sb2.foo
83 #  .debug_info  .gnu.linkonce.wi.foo
84 #  .tdata       .gnu.linkonce.td.foo
85 #  .tbss        .gnu.linkonce.tb.foo
86 #  .lrodata     .gnu.linkonce.lr.foo
87 #  .ldata       .gnu.linkonce.l.foo
88 #  .lbss        .gnu.linkonce.lb.foo
89 #
90 #  Each of these can also have corresponding .rel.* and .rela.* sections.
91
92
93 test -z "$ENTRY" && ENTRY=_start
94 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
95 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
96 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
97 test -z "${ELFSIZE}" && ELFSIZE=32
98 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
99 test "$LD_FLAG" = "N" && DATA_ADDR=.
100 test -z "${ETEXT_NAME}" && ETEXT_NAME=etext
101 test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
102 test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
103 test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
104 test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
105 DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
106 DATA_SEGMENT_RELRO_END=""
107 DATA_SEGMENT_END=""
108 if test -n "${COMMONPAGESIZE}"; then
109   DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
110   DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
111   DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
112 fi
113 if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
114   INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
115 fi
116 if test -z "$PLT"; then
117   PLT=".plt          ${RELOCATING-0} : { *(.plt) }"
118 fi
119 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=yes
120 if test -z "$GOT"; then
121   if test -z "$SEPARATE_GOTPLT"; then
122     GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) }"
123   else
124     GOT=".got          ${RELOCATING-0} : { *(.got) }"
125     GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt) }"
126   fi
127 fi
128 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
129 RODATA=".rodata ${RELOCATING+ADDR(.data)+SIZEOF(.data)} ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }  /*> INTERNAL_RAM*/"
130 DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }"
131 DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }"
132 if test -z "${NO_SMALL_DATA}"; then
133   SBSS=".sbss         ${RELOCATING-0} :
134   {
135     ${RELOCATING+${SBSS_START_SYMBOLS}}
136     ${CREATE_SHLIB+*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)}
137     *(.dynsbss)
138     *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
139     *(.scommon)
140     ${RELOCATING+${SBSS_END_SYMBOLS}}
141   }"
142   SBSS2=".sbss2        ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
143   SDATA="/* We want the small data sections together, so single-instruction offsets
144      can access them all, and initialized data all before uninitialized, so
145      we can shorten the on-disk segment size.  */
146   .sdata        ${RELOCATING-0} : 
147   {
148     ${RELOCATING+${SDATA_START_SYMBOLS}}
149     ${CREATE_SHLIB+*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)}
150     *(.sdata${RELOCATING+ .sdata.* .gnu.linkonce.s.*})
151   }"
152   SDATA2=".sdata2       ${RELOCATING-0} :
153   {
154     ${RELOCATING+${SDATA2_START_SYMBOLS}}
155     *(.sdata2${RELOCATING+ .sdata2.* .gnu.linkonce.s2.*})
156   }"
157   REL_SDATA=".rel.sdata    ${RELOCATING-0} : { *(.rel.sdata${RELOCATING+ .rel.sdata.* .rel.gnu.linkonce.s.*}) }
158   .rela.sdata   ${RELOCATING-0} : { *(.rela.sdata${RELOCATING+ .rela.sdata.* .rela.gnu.linkonce.s.*}) }"
159   REL_SBSS=".rel.sbss     ${RELOCATING-0} : { *(.rel.sbss${RELOCATING+ .rel.sbss.* .rel.gnu.linkonce.sb.*}) }
160   .rela.sbss    ${RELOCATING-0} : { *(.rela.sbss${RELOCATING+ .rela.sbss.* .rela.gnu.linkonce.sb.*}) }"
161   REL_SDATA2=".rel.sdata2   ${RELOCATING-0} : { *(.rel.sdata2${RELOCATING+ .rel.sdata2.* .rel.gnu.linkonce.s2.*}) }
162   .rela.sdata2  ${RELOCATING-0} : { *(.rela.sdata2${RELOCATING+ .rela.sdata2.* .rela.gnu.linkonce.s2.*}) }"
163   REL_SBSS2=".rel.sbss2    ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
164   .rela.sbss2   ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
165 else
166   NO_SMALL_DATA=" "
167 fi
168 if test -z "${DATA_GOT}"; then
169   if test -n "${NO_SMALL_DATA}"; then
170     DATA_GOT=" "
171   fi
172 fi
173 if test -z "${SDATA_GOT}"; then
174   if test -z "${NO_SMALL_DATA}"; then
175     SDATA_GOT=" "
176   fi
177 fi
178 test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
179 test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
180   .rel.ldata    ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) }
181   .rela.ldata   ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) }
182   .rel.lbss     ${RELOCATING-0} : { *(.rel.lbss${RELOCATING+ .rel.lbss.* .rel.gnu.linkonce.lb.*}) }
183   .rela.lbss    ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) }
184   .rel.lrodata  ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) }
185   .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }"
186 test "${LARGE_SECTIONS}" = "yes" && OTHER_BSS_SECTIONS="
187   ${OTHER_BSS_SECTIONS}
188   .lbss ${RELOCATING-0} :
189   {
190     *(.dynlbss)
191     *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
192     *(LARGE_COMMON)
193   }"
194 test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
195   .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
196   {
197     *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*})
198   }
199   .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
200   {
201     *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
202     ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
203   }"
204 CTOR=".ctors    ADDR(.text) + SIZEOF(.text)      ${CONSTRUCTING-0} : 
205   {
206     ${CONSTRUCTING+${CTOR_START}}
207     /* gcc uses crtbegin.o to find the start of
208        the constructors, so we make sure it is
209        first.  Because this is a wildcard, it
210        doesn't matter if the user does not
211        actually link against crtbegin.o; the
212        linker won't look for a file to match a
213        wildcard.  The wildcard also means that it
214        doesn't matter which directory crtbegin.o
215        is in.  */
216
217     KEEP (*crtbegin.o(.ctors))
218     KEEP (*crtbegin?.o(.ctors))
219
220     /* We don't want to include the .ctor section from
221        the crtend.o file until after the sorted ctors.
222        The .ctor section from the crtend file contains the
223        end of ctors marker and it must be last */
224
225     KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
226     KEEP (*(SORT(.ctors.*)))
227     KEEP (*(.ctors))
228     ${CONSTRUCTING+${CTOR_END}}
229   }  /*> INTERNAL_RAM*/" 
230 DTOR=".dtors     ADDR(.ctors) + SIZEOF(.ctors)    ${CONSTRUCTING-0} :
231   {
232     ${CONSTRUCTING+${DTOR_START}}
233     KEEP (*crtbegin.o(.dtors))
234     KEEP (*crtbegin?.o(.dtors))
235     KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
236     KEEP (*(SORT(.dtors.*)))
237     KEEP (*(.dtors))
238     ${CONSTRUCTING+${DTOR_END}}
239   }   /*> INTERNAL_RAM*/ "
240 STACK="  .stack        ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
241   {
242     ${RELOCATING+___stack = .;}
243     *(.stack)
244   }"
245
246 # if this is for an embedded system, don't add SIZEOF_HEADERS.
247 if [ -z "$EMBEDDED" ]; then
248    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
249 else
250    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
251 fi
252
253 cat <<EOF
254
255 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
256               "${LITTLE_OUTPUT_FORMAT}")
257 OUTPUT_ARCH(${OUTPUT_ARCH})
258 ${RELOCATING+ENTRY(${ENTRY})}
259
260 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
261 ${RELOCATING+${INPUT_FILES}}
262 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
263   if gld -r is used and the intermediate file has sections starting
264   at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
265   bug.  But for now assigning the zero vmas works.  */}
266
267
268
269 /* BSP specific*/
270 __PROG_SIZE_FOR_CORE__ = 1M;
271 __HEAP_SIZE_FOR_CORE__ = 1M;
272
273 __MAX_NUM_CORES_IN_ROWS__ = 4;
274 __MAX_NUM_CORES_IN_COLS__ = 4;
275
276 __FIRST_CORE_ROW_ = 0x20;
277 __FIRST_CORE_COL_ = 0x24;
278
279
280
281 PROVIDE (__CORE_ROW_ = __FIRST_CORE_ROW_);
282 PROVIDE (__CORE_COL_ = __FIRST_CORE_COL_);
283 /* generic don't touch */
284 /* used to calculated the slice address in the external memory*/
285 __CORE_NUM_ =  (__CORE_ROW_ -  __FIRST_CORE_ROW_ )* __MAX_NUM_CORES_IN_COLS__ + (__CORE_COL_ - __FIRST_CORE_COL_ ) ;
286
287
288 MEMORY
289  {
290         EXTERNAL_DRAM_0 (WXAI) :     ORIGIN = 0x80000000,      LENGTH = 0x1000000  /*.text, data, rodata, bss and .stack*/
291     EXTERNAL_DRAM_1 (WXAI) :        ORIGIN = 0x81000000,      LENGTH = 0x1000000 /*.heap */
292     
293     EXTERNAL_SRAM (WXAI) :       ORIGIN = 0x92000000,      LENGTH =   8K /* small external RAM, used for testing*/
294     
295     /* run time lib and crt0*/
296     RESERVED_CRT0_RAM (WXAI) :    ORIGIN = 0,      LENGTH = 0x400
297     
298     /* user program, per bank usage */
299     BANK0_SRAM (WXAI) : ORIGIN = LENGTH(RESERVED_CRT0_RAM),   LENGTH = 8K - LENGTH(RESERVED_CRT0_RAM)
300     BANK1_SRAM (WXAI) : ORIGIN = 0x2000, LENGTH = 8K
301     BANK2_SRAM (WXAI) : ORIGIN = 0x4000, LENGTH = 8K
302     BANK3_SRAM (WXAI) : ORIGIN = 0x6000, LENGTH = 8K
303     
304     /* user program, continious placement */
305     INTERNAL_RAM        (WXAI) :     ORIGIN = LENGTH(RESERVED_CRT0_RAM),  LENGTH = 32K - LENGTH(RESERVED_CRT0_RAM)
306     
307     MMR (WAI)         : ORIGIN = 0xF000, LENGTH = 32K
308        
309     /* multi cores space */   
310         CORE_0x20_0x24_INTERNAL_RAM :      ORIGIN = 0x82400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
311         CORE_0x20_0x25_INTERNAL_RAM :      ORIGIN = 0x82500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
312         CORE_0x20_0x26_INTERNAL_RAM :      ORIGIN = 0x82600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
313         CORE_0x20_0x27_INTERNAL_RAM :      ORIGIN = 0x82700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
314         CORE_0x21_0x24_INTERNAL_RAM :      ORIGIN = 0x86400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
315         CORE_0x21_0x25_INTERNAL_RAM :      ORIGIN = 0x86500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
316         CORE_0x21_0x26_INTERNAL_RAM :      ORIGIN = 0x86600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
317         CORE_0x21_0x27_INTERNAL_RAM :      ORIGIN = 0x86700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
318         CORE_0x22_0x24_INTERNAL_RAM :      ORIGIN = 0x8a400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
319         CORE_0x22_0x25_INTERNAL_RAM :      ORIGIN = 0x8a500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
320         CORE_0x22_0x26_INTERNAL_RAM :      ORIGIN = 0x8a600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
321         CORE_0x22_0x27_INTERNAL_RAM :      ORIGIN = 0x8a700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
322         CORE_0x23_0x24_INTERNAL_RAM :      ORIGIN = 0x8e400000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
323         CORE_0x23_0x25_INTERNAL_RAM :      ORIGIN = 0x8e500000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
324         CORE_0x23_0x26_INTERNAL_RAM :      ORIGIN = 0x8e600000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
325         CORE_0x23_0x27_INTERNAL_RAM :      ORIGIN = 0x8e700000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
326         CORE_0x24_0x24_INTERNAL_RAM :      ORIGIN = 0x82000000+LENGTH(RESERVED_CRT0_RAM),      LENGTH = 32K- LENGTH(RESERVED_CRT0_RAM)
327    
328  }
329
330
331 SECTIONS
332 {
333
334    IVT 0 : {*.o(IVT)  } > RESERVED_CRT0_RAM
335    RESERVED_CRT0 : {*.o(RESERVED_CRT0)  } > RESERVED_CRT0_RAM
336    RESERVED_CRT0 : {*.o(reserved_crt0)  } > RESERVED_CRT0_RAM
337    
338    CORE_RAM_0 :   {*.o(core_ram_0)  }  > BANK0_SRAM
339    CORE_RAM_1 :   {*.o(core_ram_1)  }  > BANK1_SRAM
340    CORE_RAM_2 :   {*.o(core_ram_2)  }  > BANK2_SRAM
341    CORE_RAM_3 :   {*.o(core_ram_3)  }  > BANK3_SRAM
342    
343    SRAM_SOUTH :  {*.o(sram)  }  > EXTERNAL_SRAM
344    DRAM_WEST :  {*.o(dram)  }  > EXTERNAL_DRAM_1
345    
346    CORE_INTERNAL :  {*.o(core_ram_internal)  }    /*> INTERNAL_RAM*/
347    
348    /* the newlib  (libc and libm)  library is maped to the dedicated section */
349    
350    __new_lib_start_external_ =  ( ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ *__CORE_NUM_ );
351    __new_lib_start_ = DEFINED(__USE_INTERNAL_MEM_FOR_NEW_LIB_) ? ORIGIN(BANK1_SRAM) :  __new_lib_start_external_ ;
352    
353    NEW_LIB_RO ${RELOCATING+__new_lib_start_} : { lib_a-*.o(.text  .rodata )  *.o(libgloss_epiphany)  }  /*  > INTERNAL_RAM*/
354    GNU_C_BUILTIN_LIB_RO     ADDR(NEW_LIB_RO) + SIZEOF(NEW_LIB_RO) : {  
355                                                                 *mulsi3.o(.text  .rodata)  *modsi3.o(.text  .rodata)
356                                                                 *divsi3.o(.text  .rodata)       *udivsi3.o(.text  .rodata)
357                                                             *umodsi3.o(.text  .rodata)   _*.o(.text  .rodata) 
358    } 
359                                                                                                         
360    NEW_LIB_WR   ADDR(GNU_C_BUILTIN_LIB_RO) + SIZEOF(GNU_C_BUILTIN_LIB_RO)  : { lib_a-*.o(.data ) }    /* >  INTERNAL_RAM*/ 
361    
362    
363    __init_start = DEFINED(__USE_INTERNAL_MEM_) ? ORIGIN(BANK1_SRAM) :  (ADDR(NEW_LIB_WR) + SIZEOF(NEW_LIB_WR) ) ; 
364    __init_start = DEFINED(__USE_INTERNAL_MEM_FOR_NEW_LIB_) ? ADDR(NEW_LIB_WR) + SIZEOF(NEW_LIB_WR)  : __init_start;
365    
366
367   /* Read-only sections, merged into text segment: */
368   /*${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}*/
369   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
370   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
371   ${INITIAL_READONLY_SECTIONS}
372   .note.gnu.build-id : { *(.note.gnu.build-id) }
373 EOF
374
375 test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
376 test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
377 cat > ldscripts/dyntmp.$$ <<EOF
378   ${TEXT_DYNAMIC+${DYNAMIC}}
379   .hash         ${RELOCATING-0} : { *(.hash) }
380   .gnu.hash     ${RELOCATING-0} : { *(.gnu.hash) }
381   .dynsym       ${RELOCATING-0} : { *(.dynsym) }
382   .dynstr       ${RELOCATING-0} : { *(.dynstr) }
383   .gnu.version  ${RELOCATING-0} : { *(.gnu.version) }
384   .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
385   .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
386 EOF
387
388 if [ "x$COMBRELOC" = x ]; then
389   COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
390 else
391   COMBRELOCCAT="cat > $COMBRELOC"
392 fi
393 eval $COMBRELOCCAT <<EOF
394   .rel.init     ${RELOCATING-0} : { *(.rel.init) }
395   .rela.init    ${RELOCATING-0} : { *(.rela.init) }
396   .rel.text     ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
397   .rela.text    ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
398   .rel.fini     ${RELOCATING-0} : { *(.rel.fini) }
399   .rela.fini    ${RELOCATING-0} : { *(.rela.fini) }
400   .rel.rodata   ${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.rodata.* .rel.gnu.linkonce.r.*}) }
401   .rela.rodata  ${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.rodata.* .rela.gnu.linkonce.r.*}) }
402   ${OTHER_READONLY_RELOC_SECTIONS}
403   .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+* .rel.gnu.linkonce.d.rel.ro.*}) }
404   .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+* .rela.gnu.linkonce.d.rel.ro.*}) }
405   .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
406   .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
407   .rel.tdata    ${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
408   .rela.tdata   ${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
409   .rel.tbss     ${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
410   .rela.tbss    ${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
411   .rel.ctors    ${RELOCATING-0} : { *(.rel.ctors) }
412   .rela.ctors   ${RELOCATING-0} : { *(.rela.ctors) }
413   .rel.dtors    ${RELOCATING-0} : { *(.rel.dtors) }
414   .rela.dtors   ${RELOCATING-0} : { *(.rela.dtors) }
415   .rel.got      ${RELOCATING-0} : { *(.rel.got) }
416   .rela.got     ${RELOCATING-0} : { *(.rela.got) }
417   ${OTHER_GOT_RELOC_SECTIONS}
418   ${REL_SDATA}
419   ${REL_SBSS}
420   ${REL_SDATA2}
421   ${REL_SBSS2}
422   .rel.bss      ${RELOCATING-0} : { *(.rel.bss${RELOCATING+ .rel.bss.* .rel.gnu.linkonce.b.*}) }
423   .rela.bss     ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
424   ${REL_LARGE}
425 EOF
426
427 if [ -n "$COMBRELOC" ]; then
428 cat >> ldscripts/dyntmp.$$ <<EOF
429   .rel.dyn      ${RELOCATING-0} :
430     {
431 EOF
432 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
433 cat >> ldscripts/dyntmp.$$ <<EOF
434     }
435   .rela.dyn     ${RELOCATING-0} :
436     {
437 EOF
438 sed -e '/^[     ]*[{}][         ]*$/d;/:[       ]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
439 cat >> ldscripts/dyntmp.$$ <<EOF
440     }
441 EOF
442 fi
443
444 cat >> ldscripts/dyntmp.$$ <<EOF
445   .rel.plt      ${RELOCATING-0} : { *(.rel.plt) }
446   .rela.plt     ${RELOCATING-0} : { *(.rela.plt) }
447   ${OTHER_PLT_RELOC_SECTIONS}
448 EOF
449
450 if test -z "${NON_ALLOC_DYN}"; then
451   if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
452     cat ldscripts/dyntmp.$$
453   else
454     if test -z "${NO_REL_RELOCS}"; then
455       sed -e '/^[       ]*\.rela\.[^}]*$/,/}/d' -e '/^[         ]*\.rela\./d' ldscripts/dyntmp.$$
456     fi
457     if test -z "${NO_RELA_RELOCS}"; then
458       sed -e '/^[       ]*\.rel\.[^}]*$/,/}/d' -e '/^[  ]*\.rel\./d' ldscripts/dyntmp.$$
459     fi
460   fi
461   rm -f ldscripts/dyntmp.$$
462 fi
463
464 cat <<EOF
465  
466   .init  __init_start  : 
467   {   
468     ${RELOCATING+${INIT_START}}
469     KEEP (*(.init))
470     ${RELOCATING+${INIT_END}}
471   }     /*> INTERNAL_RAM*/ =${NOP-0}
472
473   ${TEXT_PLT+${PLT}}
474   ${TINY_READONLY_SECTION}
475   
476   .fini ${RELOCATING+ADDR(.init)+SIZEOF(.init)} ${RELOCATING-0} :
477   {
478     ${RELOCATING+${FINI_START}}
479     KEEP (*(.fini))
480     ${RELOCATING+${FINI_END}}
481   }    /*> INTERNAL_RAM*/ =${NOP-0}
482   
483   .text ${RELOCATING+ADDR(.fini)+SIZEOF(.fini)} ${RELOCATING-0} :
484   {
485     ${RELOCATING+${TEXT_START_SYMBOLS}}
486     *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
487     /* .gnu.warning sections are handled specially by elf32.em.  */
488     *(.gnu.warning)
489     ${RELOCATING+${OTHER_TEXT_SECTIONS}}
490   }    /*> INTERNAL_RAM */ =${NOP-0}
491
492   ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
493   ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
494   ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
495   ${WRITABLE_RODATA-${RODATA}}
496   .rodata1      ${RELOCATING-0} : { *(.rodata1) } 
497   ${CREATE_SHLIB-${SDATA2}}
498   ${CREATE_SHLIB-${SBSS2}}
499   ${OTHER_READONLY_SECTIONS}
500   .eh_frame_hdr : { *(.eh_frame_hdr) }
501   .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
502   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
503
504   /* Adjust the address for the data segment.  We want to adjust up to
505      the same address within the page on the next page up.  */
506   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
507   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
508   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
509
510   /* Exception handling  */
511   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
512   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
513
514   /* Thread Local Storage sections  */
515   .tdata        ${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
516   .tbss         ${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
517
518   .preinit_array   ${RELOCATING-0} :
519   {
520     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}}
521     KEEP (*(.preinit_array))
522     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}}
523   } 
524   .init_array   ${RELOCATING-0} :
525   {
526      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
527      KEEP (*(SORT(.init_array.*)))
528      KEEP (*(.init_array))
529      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
530   }  
531   .fini_array   ${RELOCATING-0} :
532   {
533     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
534     KEEP (*(.fini_array))
535     KEEP (*(SORT(.fini_array.*)))
536     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
537   } 
538   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
539   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
540   .jcr          ${RELOCATING-0} : { KEEP (*(.jcr)) }
541
542   ${RELOCATING+${DATARELRO}}
543   ${OTHER_RELRO_SECTIONS}
544   ${TEXT_DYNAMIC-${DYNAMIC}}
545   ${DATA_GOT+${RELRO_NOW+${GOT}}}
546   ${DATA_GOT+${RELRO_NOW+${GOTPLT}}}
547   ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT+${GOT}}}}
548   ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
549   ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT-${GOT}}}}
550   ${DATA_GOT+${RELRO_NOW-${GOTPLT}}}
551
552   ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
553
554   .data ${RELOCATING+ADDR(.dtors)+SIZEOF(.dtors)} ${RELOCATING-0} :
555   {
556     ${RELOCATING+${DATA_START_SYMBOLS}}
557     *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
558     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
559   }  /*> INTERNAL_RAM*/
560   .data1        ${RELOCATING-0} : { *(.data1) }  
561   ${WRITABLE_RODATA+${RODATA}}
562   ${OTHER_READWRITE_SECTIONS}
563   ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}
564   ${SMALL_DATA_DTOR+${RELOCATING+${DTOR}}}
565   ${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}
566   ${SDATA_GOT+${RELOCATING+${OTHER_GOT_SYMBOLS}}}
567   ${SDATA_GOT+${GOT}}
568   ${SDATA_GOT+${OTHER_GOT_SECTIONS}}
569   ${SDATA}
570   ${OTHER_SDATA_SECTIONS}
571   ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
572   /* Align ___bss_start and _end to a multiple of 8 so that we can use strd
573      to clear bss.  N.B., without adding any extra alignment, we would have
574      to clear the bss byte by byte.  */
575   ${RELOCATING+. = ALIGN(8);}
576   ${RELOCATING+___bss_start = .;}
577   ${RELOCATING+${OTHER_BSS_SYMBOLS}}
578   ${SBSS}
579   ${BSS_PLT+${PLT}}
580   .bss ${RELOCATING+ADDR(.rodata)+SIZEOF(.rodata)} ${RELOCATING-0} :
581   {
582    *(.dynbss)
583    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
584    *(COMMON)
585    /* Align here to ensure that the .bss section occupies space up to
586       _end.  Align after .bss to ensure correct alignment even if the
587       .bss section disappears because there are no input sections.
588       FIXME: Why do we need it? When there is no .bss section, we don't
589       pad the .data section.  */
590    ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
591   }  /*> INTERNAL_RAM*/
592   ${OTHER_BSS_SECTIONS}
593   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
594   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
595   ${LARGE_SECTIONS}
596   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
597   ${RELOCATING+. = ALIGN(8);}
598   ${RELOCATING+${OTHER_END_SYMBOLS}}
599   ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
600   ${RELOCATING+${DATA_SEGMENT_END}}
601 EOF
602
603 if test -n "${NON_ALLOC_DYN}"; then
604   if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
605     cat ldscripts/dyntmp.$$
606   else
607     if test -z "${NO_REL_RELOCS}"; then
608       sed -e '/^[       ]*\.rela\.[^}]*$/,/}/d' -e '/^[         ]*\.rela\./d' ldscripts/dyntmp.$$
609     fi
610     if test -z "${NO_RELA_RELOCS}"; then
611       sed -e '/^[       ]*\.rel\.[^}]*$/,/}/d' -e '/^[  ]*\.rel\./d' ldscripts/dyntmp.$$
612     fi
613   fi
614   rm -f ldscripts/dyntmp.$$
615 fi
616
617 cat <<EOF
618   /* Stabs debugging sections.  */
619   .stab          0 : { *(.stab) }
620   .stabstr       0 : { *(.stabstr) }
621   .stab.excl     0 : { *(.stab.excl) }
622   .stab.exclstr  0 : { *(.stab.exclstr) }
623   .stab.index    0 : { *(.stab.index) }
624   .stab.indexstr 0 : { *(.stab.indexstr) }
625
626   .comment       0 : { *(.comment) }
627
628 EOF
629
630 . $srcdir/scripttempl/DWARF.sc
631
632 cat <<EOF
633   ${TINY_DATA_SECTION}
634   ${TINY_BSS_SECTION}
635
636   /*${STACK_ADDR+${STACK}}*/
637   
638   PROVIDE ( __stack_start_ = ORIGIN(EXTERNAL_DRAM_0) + __PROG_SIZE_FOR_CORE__ * __CORE_NUM_ + __PROG_SIZE_FOR_CORE__  - 0x10) ;
639   .stack ${RELOCATING+__stack_start_} :  {    ___stack = .;    *(.stack)  }
640
641   PROVIDE (  ___heap_start = ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_ );
642   /*.heap_start      __heap_start_    :  {    _heap_start_ = .;    *(.heap_start)  }*/
643
644   PROVIDE (  ___heap_end =   ORIGIN(EXTERNAL_DRAM_1)  + __HEAP_SIZE_FOR_CORE__ * __CORE_NUM_  + __HEAP_SIZE_FOR_CORE__ - 4 );
645   
646   
647  /* .heap_end      __heap_end_    :  {    _heap_end_ = .;    *(.heap_end)  }*/
648
649
650   ${ATTRS_SECTIONS}
651   ${OTHER_SECTIONS}
652   ${RELOCATING+${OTHER_SYMBOLS}}
653   ${RELOCATING+${DISCARDED}}
654 }
655 EOF