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 test -z "$ENTRY" && ENTRY=_start
      8 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
      9 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
     10 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
     11 test "$LD_FLAG" = "N" && DATA_ADDR=.
     12 INTERP=".interp   ${RELOCATING-0} : { *(.interp) }"
     13 PLT=".plt    ${RELOCATING-0} : { *(.plt) }"
     14 
     15 
     16 CTOR=".ctors ${CONSTRUCTING-0} :
     17   {
     18     ${CONSTRUCTING+${CTOR_START}}
     19     /* gcc uses crtbegin.o to find the start of
     20        the constructors, so we make sure it is
     21        first.  Because this is a wildcard, it
     22        doesn't matter if the user does not
     23        actually link against crtbegin.o; the
     24        linker won't look for a file to match a
     25        wildcard.  The wildcard also means that it
     26        doesn't matter which directory crtbegin.o
     27        is in.  */
     28 
     29     KEEP (*crtbegin.o(.ctors))
     30     KEEP (*crtbegin?.o(.ctors))
     31 
     32     /* We don't want to include the .ctor section from
     33        the crtend.o file until after the sorted ctors.
     34        The .ctor section from the crtend file contains the
     35        end of ctors marker and it must be last */
     36 
     37     KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o) .ctors))
     38     KEEP (*(SORT(.ctors.*)))
     39     KEEP (*(.ctors))
     40     ${CONSTRUCTING+${CTOR_END}}
     41   }"
     42 
     43 DTOR=" .dtors       ${CONSTRUCTING-0} :
     44   {
     45     ${CONSTRUCTING+${DTOR_START}}
     46     KEEP (*crtbegin.o(.dtors))
     47     KEEP (*crtbegin?.o(.dtors))
     48     KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o) .dtors))
     49     KEEP (*(SORT(.dtors.*)))
     50     KEEP (*(.dtors))
     51     ${CONSTRUCTING+${DTOR_END}}
     52   }"
     53 
     54 STACK=" .stack : { _stack = .; *(.stack) } >STACK "
     55 
     56 # if this is for an embedded system, don't add SIZEOF_HEADERS.
     57 if [ -z "$EMBEDDED" ]; then
     58    test -z "${READONLY_BASE_ADDRESS}" && READONLY_BASE_ADDRESS="${READONLY_START_ADDR} + SIZEOF_HEADERS"
     59 else
     60    test -z "${READONLY_BASE_ADDRESS}" && READONLY_BASE_ADDRESS="${READONLY_START_ADDR}"
     61 fi
     62 
     63 cat <<EOF
     64 /* Copyright (C) 2014-2025 Free Software Foundation, Inc.
     65 
     66    Copying and distribution of this script, with or without modification,
     67    are permitted in any medium without royalty provided the copyright
     68    notice and this notice are preserved.  */
     69 
     70 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
     71 	      "${LITTLE_OUTPUT_FORMAT}")
     72 OUTPUT_ARCH(${OUTPUT_ARCH})
     73 EOF
     74 
     75 test -n "${RELOCATING}" && cat <<EOF
     76 ENTRY(${ENTRY})
     77 
     78 ${LIB_SEARCH_DIRS}
     79 /* Do we need any of these for elf?
     80    __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */
     81 ${EXECUTABLE_SYMBOLS}
     82 
     83 MEMORY
     84 {
     85   /* These are the values for the D10V-TS3 board.
     86      There are other memory regions available on
     87      the TS3 (eg ROM, FLASH, etc) but these are not
     88      used by this script.  */
     89 
     90   INSN       : org = 0x01000000, len = 256K
     91   DATA       : org = 0x02000000, len = 48K
     92 
     93   /* This is a fake memory region at the top of the
     94      on-chip RAM, used as the start of the
     95      (descending) stack.  */
     96 
     97   STACK      : org = 0x0200BFFC, len = 4
     98 }
     99 
    100 EOF
    101 
    102 cat <<EOF
    103 SECTIONS
    104 {
    105   /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
    106      section is typically placed next to the ELF headers.  */
    107   .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) } ${RELOCATING+ >INSN}
    108 
    109   .text ${RELOCATING+${TEXT_START_ADDR}} :
    110   {
    111     ${RELOCATING+${TEXT_START_SYMBOLS}
    112     KEEP (*(SORT_NONE(.init)))
    113     KEEP (*(SORT_NONE(.init.*)))
    114     KEEP (*(SORT_NONE(.fini)))
    115     KEEP (*(SORT_NONE(.fini.*)))}
    116     *(.text)
    117     ${RELOCATING+*(.text.*)}
    118     /* .gnu.warning sections are handled specially by elf.em.  */
    119     *(.gnu.warning)
    120     ${RELOCATING+*(.gnu.linkonce.t*)
    121     _etext = .;
    122     PROVIDE (etext = .);}
    123   } ${RELOCATING+ >INSN} =${NOP-0}
    124 
    125   .rodata ${RELOCATING+${READONLY_START_ADDR}} : {
    126     *(.rodata)
    127     ${RELOCATING+*(.gnu.linkonce.r*)
    128     *(.rodata.*)}
    129   } ${RELOCATING+ >DATA}
    130 
    131   .rodata1 ${RELOCATING-0} : {
    132     *(.rodata1)
    133     ${RELOCATING+*(.rodata1.*)}
    134    } ${RELOCATING+ >DATA}
    135 
    136   .data  ${RELOCATING-0} :
    137   {
    138     ${RELOCATING+${DATA_START_SYMBOLS}}
    139     *(.data)
    140     ${RELOCATING+*(.data.*)
    141     *(.gnu.linkonce.d*)}
    142     ${CONSTRUCTING+CONSTRUCTORS}
    143   } ${RELOCATING+ >DATA}
    144 
    145   .data1 ${RELOCATING-0} : {
    146     *(.data1)
    147     ${RELOCATING+*(.data1.*)}
    148   } ${RELOCATING+ >DATA}
    149 
    150   ${RELOCATING+${CTOR} >DATA}
    151   ${RELOCATING+${DTOR} >DATA}
    152 
    153   /* We want the small data sections together, so single-instruction offsets
    154      can access them all, and initialized data all before uninitialized, so
    155      we can shorten the on-disk segment size.  */
    156   .sdata   ${RELOCATING-0} : {
    157     *(.sdata)
    158     ${RELOCATING+*(.sdata.*)}
    159   } ${RELOCATING+ >DATA}
    160 
    161   ${RELOCATING+_edata = .;}
    162   ${RELOCATING+PROVIDE (edata = .);}
    163   ${RELOCATING+. = ALIGN(ALIGNOF(NEXT_SECTION));}
    164   ${RELOCATING+__bss_start = .;}
    165   .sbss    ${RELOCATING-0} : { *(.sbss)${RELOCATING+ *(.scommon)} } ${RELOCATING+ >DATA}
    166   .bss     ${RELOCATING-0} :
    167   {
    168    ${RELOCATING+*(.dynbss)
    169    *(.dynbss.*)}
    170    *(.bss)
    171    ${RELOCATING+*(.bss.*)
    172    *(COMMON)}
    173   } ${RELOCATING+ >DATA}
    174 
    175   ${RELOCATING+_end = . ;}
    176   ${RELOCATING+PROVIDE (end = .);}
    177 
    178   ${RELOCATING+$STACK}
    179 
    180 EOF
    181 
    182 source_sh $srcdir/scripttempl/misc-sections.sc DATA
    183 source_sh $srcdir/scripttempl/DWARF.sc
    184 
    185 cat <<EOF
    186 }
    187 EOF
    188