Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / ld / scripttempl / pep.sc
blobdf1f4116ca473967141ca44e96a5b3c661447f79
1 # Linker script for PE.
3 # Copyright (C) 2014-2023 Free Software Foundation, Inc.
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved.
9 if test -z "${RELOCATEABLE_OUTPUT_FORMAT}"; then
10   RELOCATEABLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
13 # We can't easily and portably get an unquoted $ in a shell
14 # substitution, so we do this instead.
15 # Sorting of the .foo$* sections is required by the definition of
16 # grouped sections in PE.
17 # Sorting of the file names in R_IDATA is required by the
18 # current implementation of dlltool (this could probably be changed to
19 # use grouped sections instead).
20 if test "${RELOCATING}"; then
21   R_TEXT='*(SORT(.text$*))'
22   if test "x$LD_FLAG" = "xauto_import" ; then
23     R_DATA='*(SORT(.data$*))
24             *(.rdata)
25             *(SORT(.rdata$*))'
26     R_RDATA=''
27   else
28     R_DATA='*(SORT(.data$*))'
29     R_RDATA='*(.rdata)
30              *(SORT(.rdata$*))'
31   fi
32   R_IDATA234='
33     KEEP (SORT(*)(.idata$2))
34     KEEP (SORT(*)(.idata$3))
35     /* These zeroes mark the end of the import list.  */
36     LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
37     . = ALIGN(8);
38     KEEP (SORT(*)(.idata$4))'
39   R_IDATA5='SORT(*)(.idata$5)'
40   R_IDATA67='
41     KEEP (SORT(*)(.idata$6))
42     KEEP (SORT(*)(.idata$7))'
43   R_CRT_XC='KEEP (*(SORT(.CRT$XC*)))  /* C initialization */'
44   R_CRT_XI='KEEP (*(SORT(.CRT$XI*)))  /* C++ initialization */'
45   R_CRT_XL='KEEP (*(SORT(.CRT$XL*)))  /* TLS callbacks */'
46   R_CRT_XP='KEEP (*(SORT(.CRT$XP*)))  /* Pre-termination */'
47   R_CRT_XT='KEEP (*(SORT(.CRT$XT*)))  /* Termination */'
48   R_TLS='
49     KEEP (*(.tls$AAA))
50     KEEP (*(.tls))
51     KEEP (*(.tls$))
52     KEEP (*(SORT(.tls$*)))
53     KEEP (*(.tls$ZZZ))'
54   R_RSRC='
55     KEEP (*(.rsrc))
56     KEEP (*(.rsrc$*))'
57 else
58   R_TEXT=
59   R_DATA=
60   R_RDATA='*(.rdata)'
61   R_IDATA234=
62   R_IDATA5=
63   R_IDATA67=
64   R_CRT_XC=
65   R_CRT_XI=
66   R_CRT_XL=
67   R_CRT_XP=
68   R_CRT_XT=
69   R_TLS='*(.tls)'
70   R_RSRC='*(.rsrc)'
73 cat <<EOF
74 /* Copyright (C) 2014-2023 Free Software Foundation, Inc.
76    Copying and distribution of this script, with or without modification,
77    are permitted in any medium without royalty provided the copyright
78    notice and this notice are preserved.  */
80 ${RELOCATING+OUTPUT_FORMAT(${OUTPUT_FORMAT})}
81 ${RELOCATING-OUTPUT_FORMAT(${RELOCATEABLE_OUTPUT_FORMAT})}
82 ${OUTPUT_ARCH+OUTPUT_ARCH(${OUTPUT_ARCH})}
84 ${LIB_SEARCH_DIRS}
86 SECTIONS
88   ${RELOCATING+/* Make the virtual address and file offset synced if the alignment is}
89   ${RELOCATING+   lower than the target page size. */}
90   ${RELOCATING+. = SIZEOF_HEADERS;}
91   ${RELOCATING+. = ALIGN(__section_alignment__);}
92   .text ${RELOCATING+ __image_base__ + ( __section_alignment__ < ${TARGET_PAGE_SIZE} ? . : __section_alignment__ )} :
93   {
94     ${RELOCATING+KEEP (*(SORT_NONE(.init)))}
95     *(.text)
96     ${R_TEXT}
97     ${RELOCATING+ *(.text.*)}
98     ${RELOCATING+ *(.gnu.linkonce.t.*)}
99     ${RELOCATING+*(.glue_7t)}
100     ${RELOCATING+*(.glue_7)}
101     ${CONSTRUCTING+. = ALIGN(8);}
102     ${CONSTRUCTING+
103        /* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
104           we do not PROVIDE them.  This is because the ctors.o startup
105           code in libgcc defines them as common symbols, with the 
106           expectation that they will be overridden by the definitions
107           here.  If we PROVIDE the symbols then they will not be
108           overridden and global constructors will not be run.
109           See PR 22762 for more details.
110           
111           This does mean that it is not possible for a user to define
112           their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
113           the content from those variables are included but the symbols
114           defined here silently take precedence.  If they truly need to
115           be redefined, a custom linker script will have to be used.
116           (The custom script can just be a copy of this script with the
117           PROVIDE() qualifiers added).
119           In particular this means that ld -Ur does not work, because
120           the proper __CTOR_LIST__ set by ld -Ur is overridden by a
121           bogus __CTOR_LIST__ set by the final link.  See PR 46.  */
122        ___CTOR_LIST__ = .;
123        __CTOR_LIST__ = .;
124        LONG (-1); LONG (-1);
125        KEEP (*(.ctors));
126        KEEP (*(.ctor));
127        KEEP (*(SORT_BY_NAME(.ctors.*)));
128        LONG (0); LONG (0);
129      }
130     ${CONSTRUCTING+
131        /* See comment about __CTOR_LIST__ above.  The same reasoning
132           applies here too.  */
133        ___DTOR_LIST__ = .;
134        __DTOR_LIST__ = .;
135        LONG (-1); LONG (-1);
136        KEEP (*(.dtors));
137        KEEP (*(.dtor));
138        KEEP (*(SORT_BY_NAME(.dtors.*)));
139        LONG (0); LONG (0);
140      }
141     ${RELOCATING+KEEP (*(SORT_NONE(.fini)))}
142     ${RELOCATING+/* ??? Why is .gcc_exc here?  */}
143     ${RELOCATING+ *(.gcc_exc)}
144     ${RELOCATING+PROVIDE (etext = .);}
145     ${RELOCATING+ KEEP (*(.gcc_except_table))}
146   }
148   /* The Cygwin32 library uses a section to avoid copying certain data
149      on fork.  This used to be named ".data$nocopy".  The linker used
150      to include this between __data_start__ and __data_end__, but that
151      breaks building the cygwin32 dll.  Instead, we name the section
152      ".data_cygwin_nocopy" and explicitly include it after __data_end__. */
154   .data ${RELOCATING+BLOCK(__section_alignment__)} :
155   {
156     ${RELOCATING+__data_start__ = . ;}
157     *(.data)
158     ${RELOCATING+*(.data2)}
159     ${R_DATA}
160     KEEP(*(.jcr))
161     ${RELOCATING+__data_end__ = . ;}
162     ${RELOCATING+*(.data_cygwin_nocopy)}
163   }
165   .rdata ${RELOCATING+BLOCK(__section_alignment__)} :
166   {
167     ${R_RDATA}
168     . = ALIGN(4);
169     ${RELOCATING+__rt_psrelocs_start = .;}
170     ${RELOCATING+KEEP(*(.rdata_runtime_pseudo_reloc))}
171     ${RELOCATING+__rt_psrelocs_end = .;}
172   }
173   ${RELOCATING+__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;}
174   ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
175   ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;}
176   ${RELOCATING+___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
177   ${RELOCATING+__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;}
179   .eh_frame ${RELOCATING+BLOCK(__section_alignment__)} :
180   {
181     KEEP (*(.eh_frame${RELOCATING+*}))
182   }
184   .pdata ${RELOCATING+BLOCK(__section_alignment__)} :
185   {
186     KEEP(*(.pdata${RELOCATING+*}))
187   }
189   .xdata ${RELOCATING+BLOCK(__section_alignment__)} :
190   {
191     KEEP(*(.xdata${RELOCATING+*}))
192   }
194   .bss ${RELOCATING+BLOCK(__section_alignment__)} :
195   {
196     ${RELOCATING+__bss_start__ = . ;}
197     *(.bss)
198     *(COMMON)
199     ${RELOCATING+__bss_end__ = . ;}
200   }
202   .edata ${RELOCATING+BLOCK(__section_alignment__)} :
203   {
204     *(.edata)
205   }
207   /DISCARD/ :
208   {
209     *(.debug\$S)
210     *(.debug\$T)
211     *(.debug\$F)
212     ${RELOCATING+ *(.drectve)}
213     ${RELOCATING+ *(.note.GNU-stack)}
214     ${RELOCATING+ *(.gnu.lto_*)}
215   }
217   .idata ${RELOCATING+BLOCK(__section_alignment__)} :
218   {
219     /* This cannot currently be handled with grouped sections.
220         See pep.em:sort_sections.  */
221     ${R_IDATA234}
222     ${RELOCATING+__IAT_start__ = .;}
223     ${R_IDATA5}
224     ${RELOCATING+__IAT_end__ = .;}
225     ${R_IDATA67}
226   }
227   .CRT ${RELOCATING+BLOCK(__section_alignment__)} :
228   {
229     ${RELOCATING+___crt_xc_start__ = . ;}
230     ${R_CRT_XC}
231     ${RELOCATING+___crt_xc_end__ = . ;}
232     ${RELOCATING+___crt_xi_start__ = . ;}
233     ${R_CRT_XI}
234     ${RELOCATING+___crt_xi_end__ = . ;}
235     ${RELOCATING+___crt_xl_start__ = . ;}
236     ${R_CRT_XL}
237     /* ___crt_xl_end__ is defined in the TLS Directory support code */
238     ${RELOCATING+___crt_xp_start__ = . ;}
239     ${R_CRT_XP}
240     ${RELOCATING+___crt_xp_end__ = . ;}
241     ${RELOCATING+___crt_xt_start__ = . ;}
242     ${R_CRT_XT}
243     ${RELOCATING+___crt_xt_end__ = . ;}
244   }
246   /* Windows TLS expects .tls\$AAA to be at the start and .tls\$ZZZ to be
247      at the end of the .tls section.  This is important because _tls_start MUST
248      be at the beginning of the section to enable SECREL32 relocations with TLS
249      data.  */
250   .tls ${RELOCATING+BLOCK(__section_alignment__)} :
251   {
252     ${RELOCATING+___tls_start__ = . ;}
253     ${R_TLS}
254     ${RELOCATING+___tls_end__ = . ;}
255   }
257   .endjunk ${RELOCATING+BLOCK(__section_alignment__)} :
258   {
259     /* end is deprecated, don't use it */
260     ${RELOCATING+PROVIDE (end = .);}
261     ${RELOCATING+PROVIDE ( _end = .);}
262     ${RELOCATING+ __end__ = .;}
263   }
265   .rsrc ${RELOCATING+BLOCK(__section_alignment__)} : SUBALIGN(4)
266   {
267     ${R_RSRC}
268   }
270   .reloc ${RELOCATING+BLOCK(__section_alignment__)} :
271   {
272     *(.reloc)
273   }
275   .stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
276   {
277     *(.stab)
278   }
280   .stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
281   {
282     *(.stabstr)
283   }
285   /* DWARF debug sections.
286      Symbols in the DWARF debugging sections are relative to the beginning
287      of the section.  Unlike other targets that fake this by putting the
288      section VMA at 0, the PE format will not allow it.  */
290   /* DWARF 1.1 and DWARF 2.  */
291   .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
292   {
293     *(.debug_aranges)
294   }
295   .zdebug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
296   {
297     *(.zdebug_aranges)
298   }
300   .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
301   {
302     *(.debug_pubnames)
303   }
304   .zdebug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
305   {
306     *(.zdebug_pubnames)
307   }
309   /* DWARF 2.  */
310   .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
311   {
312     *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})
313   }
314   .zdebug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
315   {
316     *(.zdebug_info${RELOCATING+ .zdebug.gnu.linkonce.wi.*})
317   }
319   .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
320   {
321     *(.debug_abbrev)
322   }
323   .zdebug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
324   {
325     *(.zdebug_abbrev)
326   }
328   .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
329   {
330     *(.debug_line)
331   }
332   .zdebug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
333   {
334     *(.zdebug_line)
335   }
337   .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
338   {
339     *(.debug_frame*)
340   }
341   .zdebug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
342   {
343     *(.zdebug_frame*)
344   }
346   .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
347   {
348     *(.debug_str)
349   }
350   .zdebug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
351   {
352     *(.zdebug_str)
353   }
355   .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
356   {
357     *(.debug_loc)
358   }
359   .zdebug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
360   {
361     *(.zdebug_loc)
362   }
364   .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
365   {
366     *(.debug_macinfo)
367   }
368   .zdebug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
369   {
370     *(.zdebug_macinfo)
371   }
373   /* SGI/MIPS DWARF 2 extensions.  */
374   .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
375   {
376     *(.debug_weaknames)
377   }
378   .zdebug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
379   {
380     *(.zdebug_weaknames)
381   }
383   .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
384   {
385     *(.debug_funcnames)
386   }
387   .zdebug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
388   {
389     *(.zdebug_funcnames)
390   }
392   .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
393   {
394     *(.debug_typenames)
395   }
396   .zdebug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
397   {
398     *(.zdebug_typenames)
399   }
401   .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
402   {
403     *(.debug_varnames)
404   }
405   .zdebug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
406   {
407     *(.zdebug_varnames)
408   }
410   /* DWARF 3.  */
411   .debug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
412   {
413     *(.debug_pubtypes)
414   }
415   .zdebug_pubtypes ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
416   {
417     *(.zdebug_pubtypes)
418   }
420   .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
421   {
422     *(.debug_ranges)
423   }
424   .zdebug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
425   {
426     *(.zdebug_ranges)
427   }
429   /* DWARF 4.  */
430   .debug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
431   {
432     *(.debug_types${RELOCATING+ .gnu.linkonce.wt.*})
433   }
434   .zdebug_types ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
435   {
436     *(.zdebug_types${RELOCATING+ .gnu.linkonce.wt.*})
437   }
439   /* DWARF 5.  */
440   .debug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
441   {
442     *(.debug_addr)
443   }
444   .zdebug_addr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
445   {
446     *(.zdebug_addr)
447   }
448   .debug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
449   {
450     *(.debug_line_str)
451   }
452   .zdebug_line_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
453   {
454     *(.zdebug_line_str)
455   }
456   .debug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
457   {
458     *(.debug_loclists)
459   }
460   .zdebug_loclists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
461   {
462     *(.zdebug_loclists)
463   }
464   .debug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
465   {
466     *(.debug_macro)
467   }
468   .zdebug_macro ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
469   {
470     *(.zdebug_macro)
471   }
472   .debug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
473   {
474     *(.debug_names)
475   }
476   .zdebug_names ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
477   {
478     *(.zdebug_names)
479   }
480   .debug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
481   {
482     *(.debug_rnglists)
483   }
484   .zdebug_rnglists ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
485   {
486     *(.zdebug_rnglists)
487   }
488   .debug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
489   {
490     *(.debug_str_offsets)
491   }
492   .zdebug_str_offsets ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
493   {
494     *(.zdebug_str_offsets)
495   }
496   .debug_sup ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
497   {
498     *(.debug_sup)
499   }
501   /* For Go and Rust.  */
502   .debug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
503   {
504     *(.debug_gdb_scripts)
505   }
506   .zdebug_gdb_scripts ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
507   {
508     *(.zdebug_gdb_scripts)
509   }