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