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