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