Initial revision
[binutils.git] / ld / scripttempl / elf.sc
blobe1fea97d791a692b267a267a9a70463289eeb998
2 # Unusual variables checked by this code:
3 #       NOP - two byte opcode for no-op (defaults to 0)
4 #       DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
5 #       INITIAL_READONLY_SECTIONS - at start of text segment
6 #       OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
7 #               (e.g., .PARISC.milli)
8 #       OTHER_TEXT_SECTIONS - these get put in .text when relocating
9 #       OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
10 #               (e.g., .PARISC.global)
11 #       OTHER_SECTIONS - at the end
12 #       EXECUTABLE_SYMBOLS - symbols that must be defined for an
13 #               executable (e.g., _DYNAMIC_LINK)
14 #       TEXT_START_SYMBOLS - symbols that appear at the start of the
15 #               .text section.
16 #       DATA_START_SYMBOLS - symbols that appear at the start of the
17 #               .data section.
18 #       OTHER_GOT_SYMBOLS - symbols defined just before .got.
19 #       OTHER_GOT_SECTIONS - sections just after .got and .sdata.
20 #       OTHER_BSS_SYMBOLS - symbols that appear at the start of the
21 #               .bss section besides __bss_start.
22 #       DATA_PLT - .plt should be in data segment, not text segment.
23 #       TEXT_DYNAMIC - .dynamic in text segment, not data segment.
24 #       EMBEDDED - whether this is for an embedded system. 
25 #       SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
26 #               start address of shared library.
27 #       INPUT_FILES - INPUT command of files to always include
29 # When adding sections, do note that the names of some sections are used
30 # when specifying the start address of the next.
33 test -z "$ENTRY" && ENTRY=_start
34 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
35 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
36 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
37 test -z "${ELFSIZE}" && ELFSIZE=32
38 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
39 test "$LD_FLAG" = "N" && DATA_ADDR=.
40 INTERP=".interp   ${RELOCATING-0} : { *(.interp)        }"
41 PLT=".plt    ${RELOCATING-0} : { *(.plt)        }"
42 DYNAMIC=".dynamic     ${RELOCATING-0} : { *(.dynamic) }"
44 CTOR=".ctors ${CONSTRUCTING-0} : 
45   {
46     ${CONSTRUCTING+${CTOR_START}}
47     /* gcc uses crtbegin.o to find the start of
48        the constructors, so we make sure it is
49        first.  Because this is a wildcard, it
50        doesn't matter if the user does not
51        actually link against crtbegin.o; the
52        linker won't look for a file to match a
53        wildcard.  The wildcard also means that it
54        doesn't matter which directory crtbegin.o
55        is in.  */
57     KEEP (*crtbegin.o(.ctors))
59     /* We don't want to include the .ctor section from
60        from the crtend.o file until after the sorted ctors.
61        The .ctor section from the crtend file contains the
62        end of ctors marker and it must be last */
64     KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
65     KEEP (*(SORT(.ctors.*)))
66     KEEP (*(.ctors))
67     ${CONSTRUCTING+${CTOR_END}}
68   }"
70 DTOR=" .dtors       ${CONSTRUCTING-0} :
71   {
72     ${CONSTRUCTING+${DTOR_START}}
73     KEEP (*crtbegin.o(.dtors))
74     KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
75     KEEP (*(SORT(.dtors.*)))
76     KEEP (*(.dtors))
77     ${CONSTRUCTING+${DTOR_END}}
78   }"
80 # if this is for an embedded system, don't add SIZEOF_HEADERS.
81 if [ -z "$EMBEDDED" ]; then
82    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR} + SIZEOF_HEADERS"
83 else
84    test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
87 cat <<EOF
88 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
89               "${LITTLE_OUTPUT_FORMAT}")
90 OUTPUT_ARCH(${OUTPUT_ARCH})
91 ENTRY(${ENTRY})
93 ${RELOCATING+${LIB_SEARCH_DIRS}}
94 ${RELOCATING+/* Do we need any of these for elf?
95    __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */}
96 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
97 ${RELOCATING+${INPUT_FILES}}
98 ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
99   if gld -r is used and the intermediate file has sections starting
100   at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
101   bug.  But for now assigning the zero vmas works.  */}
103 SECTIONS
105   /* Read-only sections, merged into text segment: */
106   ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
107   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
108   ${CREATE_SHLIB-${INTERP}}
109   ${INITIAL_READONLY_SECTIONS}
110   ${TEXT_DYNAMIC+${DYNAMIC}}
111   .hash        ${RELOCATING-0} : { *(.hash)             }
112   .dynsym      ${RELOCATING-0} : { *(.dynsym)           }
113   .dynstr      ${RELOCATING-0} : { *(.dynstr)           }
114   .gnu.version ${RELOCATING-0} : { *(.gnu.version)      }
115   .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)  }
116   .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)  }
117   .rel.text    ${RELOCATING-0} :
118     {
119       *(.rel.text)
120       ${RELOCATING+*(.rel.text.*)}
121       ${RELOCATING+*(.rel.gnu.linkonce.t*)}
122     }
123   .rela.text   ${RELOCATING-0} :
124     {
125       *(.rela.text)
126       ${RELOCATING+*(.rela.text.*)}
127       ${RELOCATING+*(.rela.gnu.linkonce.t*)}
128     }
129   .rel.data    ${RELOCATING-0} :
130     {
131       *(.rel.data)
132       ${RELOCATING+*(.rel.data.*)}
133       ${RELOCATING+*(.rel.gnu.linkonce.d*)}
134     }
135   .rela.data   ${RELOCATING-0} :
136     {
137       *(.rela.data)
138       ${RELOCATING+*(.rela.data.*)}
139       ${RELOCATING+*(.rela.gnu.linkonce.d*)}
140     }
141   .rel.rodata  ${RELOCATING-0} :
142     {
143       *(.rel.rodata)
144       ${RELOCATING+*(.rel.rodata.*)}
145       ${RELOCATING+*(.rel.gnu.linkonce.r*)}
146     }
147   .rela.rodata ${RELOCATING-0} :
148     {
149       *(.rela.rodata)
150       ${RELOCATING+*(.rela.rodata.*)}
151       ${RELOCATING+*(.rela.gnu.linkonce.r*)}
152     }
153   .rel.got     ${RELOCATING-0} : { *(.rel.got)          }
154   .rela.got    ${RELOCATING-0} : { *(.rela.got)         }
155   .rel.ctors   ${RELOCATING-0} : { *(.rel.ctors)        }
156   .rela.ctors  ${RELOCATING-0} : { *(.rela.ctors)       }
157   .rel.dtors   ${RELOCATING-0} : { *(.rel.dtors)        }
158   .rela.dtors  ${RELOCATING-0} : { *(.rela.dtors)       }
159   .rel.init    ${RELOCATING-0} : { *(.rel.init) }
160   .rela.init   ${RELOCATING-0} : { *(.rela.init)        }
161   .rel.fini    ${RELOCATING-0} : { *(.rel.fini) }
162   .rela.fini   ${RELOCATING-0} : { *(.rela.fini)        }
163   .rel.bss     ${RELOCATING-0} : { *(.rel.bss)          }
164   .rela.bss    ${RELOCATING-0} : { *(.rela.bss)         }
165   .rel.plt     ${RELOCATING-0} : { *(.rel.plt)          }
166   .rela.plt    ${RELOCATING-0} : { *(.rela.plt)         }
167   .init        ${RELOCATING-0} : { KEEP (*(.init))      } =${NOP-0}
168   ${DATA_PLT-${PLT}}
169   .text    ${RELOCATING-0} :
170   {
171     ${RELOCATING+${TEXT_START_SYMBOLS}}
172     *(.text)
173     ${RELOCATING+*(.text.*)}
174     *(.stub)
175     /* .gnu.warning sections are handled specially by elf32.em.  */
176     *(.gnu.warning)
177     ${RELOCATING+*(.gnu.linkonce.t*)}
178     ${RELOCATING+${OTHER_TEXT_SECTIONS}}
179   } =${NOP-0}
180   ${RELOCATING+_etext = .;}
181   ${RELOCATING+PROVIDE (etext = .);}
182   .fini    ${RELOCATING-0} : { KEEP (*(.fini))          } =${NOP-0}
183   .rodata  ${RELOCATING-0} :
184   {
185     *(.rodata)
186     ${RELOCATING+*(.rodata.*)}
187     ${RELOCATING+*(.gnu.linkonce.r*)}
188   }
189   .rodata1 ${RELOCATING-0} : { *(.rodata1) }
190   ${RELOCATING+${OTHER_READONLY_SECTIONS}}
192   /* Adjust the address for the data segment.  We want to adjust up to
193      the same address within the page on the next page up.  */
194   ${CREATE_SHLIB-${RELOCATING+. = ${DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
195   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
197   .data  ${RELOCATING-0} :
198   {
199     ${RELOCATING+${DATA_START_SYMBOLS}}
200     *(.data)
201     ${RELOCATING+*(.data.*)}
202     ${RELOCATING+*(.gnu.linkonce.d*)}
203     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
204   }
205   .data1 ${RELOCATING-0} : { *(.data1) }
206   .eh_frame : { *(.eh_frame) }
207   .gcc_except_table : { *(.gcc_except_table) }
208   ${RELOCATING+${OTHER_READWRITE_SECTIONS}}
209   ${RELOCATING+${CTOR}}
210   ${RELOCATING+${DTOR}}
211   ${DATA_PLT+${PLT}}
212   ${RELOCATING+${OTHER_GOT_SYMBOLS}}
213   .got         ${RELOCATING-0} : { *(.got.plt) *(.got) }
214   ${TEXT_DYNAMIC-${DYNAMIC}}
215   /* We want the small data sections together, so single-instruction offsets
216      can access them all, and initialized data all before uninitialized, so
217      we can shorten the on-disk segment size.  */
218   .sdata   ${RELOCATING-0} : { *(.sdata) *(.sdata.*) }
219   ${RELOCATING+${OTHER_GOT_SECTIONS}}
220   ${RELOCATING+_edata  =  .;}
221   ${RELOCATING+PROVIDE (edata = .);}
222   ${RELOCATING+__bss_start = .;}
223   ${RELOCATING+${OTHER_BSS_SYMBOLS}}
224   .sbss    ${RELOCATING-0} : { *(.sbss) *(.scommon) }
225   .bss     ${RELOCATING-0} :
226   {
227    *(.dynbss)
228    *(.bss)
229    *(COMMON)
230    /* Align here to ensure that the .bss section occupies space up to
231       _end.  Align after .bss to ensure correct alignment even if the
232       .bss section disappears because there are no input sections.  */
233    ${RELOCATING+. = ALIGN(${ALIGNMENT});}
234   }
235   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
236   ${RELOCATING+_end = . ;}
237   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
238   ${RELOCATING+PROVIDE (end = .);}
240   /* Stabs debugging sections.  */
241   .stab 0 : { *(.stab) }
242   .stabstr 0 : { *(.stabstr) }
243   .stab.excl 0 : { *(.stab.excl) }
244   .stab.exclstr 0 : { *(.stab.exclstr) }
245   .stab.index 0 : { *(.stab.index) }
246   .stab.indexstr 0 : { *(.stab.indexstr) }
248   .comment 0 : { *(.comment) }
250   /* DWARF debug sections.
251      Symbols in the DWARF debugging sections are relative to the beginning
252      of the section so we begin them at 0.  */
254   /* DWARF 1 */
255   .debug          0 : { *(.debug) }
256   .line           0 : { *(.line) }
258   /* GNU DWARF 1 extensions */
259   .debug_srcinfo  0 : { *(.debug_srcinfo) }
260   .debug_sfnames  0 : { *(.debug_sfnames) }
262   /* DWARF 1.1 and DWARF 2 */
263   .debug_aranges  0 : { *(.debug_aranges) }
264   .debug_pubnames 0 : { *(.debug_pubnames) }
266   /* DWARF 2 */
267   .debug_info     0 : { *(.debug_info) }
268   .debug_abbrev   0 : { *(.debug_abbrev) }
269   .debug_line     0 : { *(.debug_line) }
270   .debug_frame    0 : { *(.debug_frame) }
271   .debug_str      0 : { *(.debug_str) }
272   .debug_loc      0 : { *(.debug_loc) }
273   .debug_macinfo  0 : { *(.debug_macinfo) }
275   /* SGI/MIPS DWARF 2 extensions */
276   .debug_weaknames 0 : { *(.debug_weaknames) }
277   .debug_funcnames 0 : { *(.debug_funcnames) }
278   .debug_typenames 0 : { *(.debug_typenames) }
279   .debug_varnames  0 : { *(.debug_varnames) }
281   ${RELOCATING+${OTHER_RELOCATING_SECTIONS}}
283   /* These must appear regardless of ${RELOCATING}.  */
284   ${OTHER_SECTIONS}