]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame_incremental - ld/emultempl/elf.em
Add a linker warning when creating potentially dangerous executable segments. Add...
[thirdparty/binutils-gdb.git] / ld / emultempl / elf.em
... / ...
CommitLineData
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3test -z "${ELFSIZE}" && ELFSIZE=32
4if [ -z "$MACHINE" ]; then
5 OUTPUT_ARCH=${ARCH}
6else
7 OUTPUT_ARCH=${ARCH}:${MACHINE}
8fi
9fragment <<EOF
10/* This file is is generated by a shell script. DO NOT EDIT! */
11
12/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
13 Copyright (C) 1991-2022 Free Software Foundation, Inc.
14 Written by Steve Chamberlain <sac@cygnus.com>
15 ELF support by Ian Lance Taylor <ian@cygnus.com>
16
17 This file is part of the GNU Binutils.
18
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 3 of the License, or
22 (at your option) any later version.
23
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
32 MA 02110-1301, USA. */
33
34#define TARGET_IS_${EMULATION_NAME}
35
36#include "sysdep.h"
37#include "bfd.h"
38#include "libiberty.h"
39#include "getopt.h"
40#include "bfdlink.h"
41#include "ctf-api.h"
42#include "ld.h"
43#include "ldmain.h"
44#include "ldmisc.h"
45#include "ldexp.h"
46#include "ldlang.h"
47#include "ldfile.h"
48#include "ldemul.h"
49#include <ldgram.h>
50#include "elf-bfd.h"
51#include "ldelf.h"
52#include "ldelfgen.h"
53
54/* Declare functions used by various EXTRA_EM_FILEs. */
55static void gld${EMULATION_NAME}_before_parse (void);
56static void gld${EMULATION_NAME}_before_plugin_all_symbols_read
57 (void);
58static void gld${EMULATION_NAME}_after_open (void);
59static void gld${EMULATION_NAME}_before_allocation (void);
60static void gld${EMULATION_NAME}_after_allocation (void);
61EOF
62
63# Import any needed special functions and/or overrides.
64#
65source_em ${srcdir}/emultempl/elf-generic.em
66if test -n "$EXTRA_EM_FILE" ; then
67 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
68fi
69
70# Functions in this file can be overridden by setting the LDEMUL_* shell
71# variables. If the name of the overriding function is the same as is
72# defined in this file, then don't output this file's version.
73# If a different overriding name is given then output the standard function
74# as presumably it is called from the overriding function.
75#
76if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
77fragment <<EOF
78
79static void
80gld${EMULATION_NAME}_before_parse (void)
81{
82 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
83 input_flags.dynamic = ${DYNAMIC_LINK-true};
84 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
85 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
86 link_info.check_relocs_after_open_input = true;
87EOF
88if test -n "$COMMONPAGESIZE"; then
89fragment <<EOF
90 link_info.relro = DEFAULT_LD_Z_RELRO;
91EOF
92fi
93fragment <<EOF
94 link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
95 link_info.warn_execstack = DEFAULT_LD_WARN_EXECSTACK;
96 link_info.no_warn_rwx_segments = ! DEFAULT_LD_WARN_RWX_SEGMENTS;
97 link_info.default_execstack = DEFAULT_LD_EXECSTACK;
98}
99
100EOF
101fi
102
103fragment <<EOF
104
105/* These variables are used to implement target options */
106
107static char *audit; /* colon (typically) separated list of libs */
108static char *depaudit; /* colon (typically) separated list of libs */
109
110EOF
111
112if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
113
114 IS_LINUX_TARGET=false
115 IS_FREEBSD_TARGET=false
116 case ${target} in
117 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
118 IS_LINUX_TARGET=true ;;
119 *-*-freebsd* | *-*-dragonfly*)
120 IS_FREEBSD_TARGET=true ;;
121 esac
122 IS_LIBPATH=false
123 if test "x${USE_LIBPATH}" = xyes; then
124 IS_LIBPATH=true
125 fi
126 IS_NATIVE=false
127 if test "x${NATIVE}" = xyes; then
128 IS_NATIVE=true
129 fi
130
131fragment <<EOF
132
133/* This is called before calling plugin 'all symbols read' hook. */
134
135static void
136gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
137{
138 ldelf_before_plugin_all_symbols_read ($IS_LIBPATH, $IS_NATIVE,
139 $IS_LINUX_TARGET,
140 $IS_FREEBSD_TARGET,
141 $ELFSIZE, "$prefix");
142}
143
144/* This is called after all the input files have been opened. */
145
146static void
147gld${EMULATION_NAME}_after_open (void)
148{
149 ldelf_after_open ($IS_LIBPATH, $IS_NATIVE,
150 $IS_LINUX_TARGET, $IS_FREEBSD_TARGET, $ELFSIZE, "$prefix");
151}
152
153EOF
154fi
155
156if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
157 if test x"${ELF_INTERPRETER_NAME}" = x; then
158 ELF_INTERPRETER_NAME=NULL
159 fi
160fragment <<EOF
161
162/* This is called after the sections have been attached to output
163 sections, but before any sizes or addresses have been set. */
164
165static void
166gld${EMULATION_NAME}_before_allocation (void)
167{
168 ldelf_before_allocation (audit, depaudit, ${ELF_INTERPRETER_NAME});
169}
170
171EOF
172fi
173
174if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
175fragment <<EOF
176
177static void
178gld${EMULATION_NAME}_after_allocation (void)
179{
180 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
181
182 if (need_layout < 0)
183 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
184 else
185 ldelf_map_segments (need_layout);
186}
187EOF
188fi
189
190if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
191fragment <<EOF
192
193static char *
194gld${EMULATION_NAME}_get_script (int *isfile)
195EOF
196
197if test x"$COMPILE_IN" = xyes
198then
199# Scripts compiled in.
200
201# sed commands to quote an ld script as a C string.
202sc="-f stringify.sed"
203
204fragment <<EOF
205{
206 *isfile = 0;
207
208 if (bfd_link_relocatable (&link_info) && config.build_constructors)
209 return
210EOF
211sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
212echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
213sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
214echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
215sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
216if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
217echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
218sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
219fi
220if test -n "$GENERATE_PIE_SCRIPT" ; then
221if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
222echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
223echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
224echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
225echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
226sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c
227echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
228echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
229echo ' && link_info.relro' >> e${EMULATION_NAME}.c
230echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
231sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
232if test -n "$GENERATE_RELRO_SCRIPT" ; then
233echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
234echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
235echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
236echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
237sed $sc ldscripts/${EMULATION_NAME}.xdceo >> e${EMULATION_NAME}.c
238fi
239echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
240echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
241echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
242sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c
243if test -n "$GENERATE_RELRO_SCRIPT" ; then
244echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
245echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
246echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
247sed $sc ldscripts/${EMULATION_NAME}.xdco >> e${EMULATION_NAME}.c
248fi
249echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
250echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
251sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
252if test -n "$GENERATE_RELRO_SCRIPT" ; then
253echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
254echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
255echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
256sed $sc ldscripts/${EMULATION_NAME}.xdeo >> e${EMULATION_NAME}.c
257fi
258fi
259echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
260echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
261sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c
262if test -n "$GENERATE_RELRO_SCRIPT" ; then
263echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
264echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
265sed $sc ldscripts/${EMULATION_NAME}.xdo >> e${EMULATION_NAME}.c
266fi
267echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
268sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
269fi
270if test -n "$GENERATE_SHLIB_SCRIPT" ; then
271if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
272echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
273echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
274echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
275echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
276sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c
277echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
278echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
279echo ' && link_info.relro' >> e${EMULATION_NAME}.c
280echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
281sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
282if test -n "$GENERATE_RELRO_SCRIPT" ; then
283echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
284echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
285echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
286echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
287sed $sc ldscripts/${EMULATION_NAME}.xsceo >> e${EMULATION_NAME}.c
288fi
289echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
290echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
291echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
292sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c
293if test -n "$GENERATE_RELRO_SCRIPT" ; then
294echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
295echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
296echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
297sed $sc ldscripts/${EMULATION_NAME}.xsco >> e${EMULATION_NAME}.c
298fi
299echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
300echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
301sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
302if test -n "$GENERATE_RELRO_SCRIPT" ; then
303echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
304echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
305echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
306sed $sc ldscripts/${EMULATION_NAME}.xseo >> e${EMULATION_NAME}.c
307fi
308fi
309echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
310echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
311sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c
312if test -n "$GENERATE_RELRO_SCRIPT" ; then
313echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
314echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
315sed $sc ldscripts/${EMULATION_NAME}.xso >> e${EMULATION_NAME}.c
316fi
317echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
318sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
319fi
320if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
321echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
322echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
323echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
324sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c
325echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
326echo ' && link_info.relro' >> e${EMULATION_NAME}.c
327echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
328sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
329if test -n "$GENERATE_RELRO_SCRIPT" ; then
330echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
331echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
332echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
333sed $sc ldscripts/${EMULATION_NAME}.xceo >> e${EMULATION_NAME}.c
334fi
335echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
336echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
337sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c
338if test -n "$GENERATE_RELRO_SCRIPT" ; then
339echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
340echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
341sed $sc ldscripts/${EMULATION_NAME}.xco >> e${EMULATION_NAME}.c
342fi
343echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
344sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
345fi
346if test -n "$GENERATE_RELRO_SCRIPT" ; then
347echo ' ; else if (link_info.separate_code' >> e${EMULATION_NAME}.c
348echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
349sed $sc ldscripts/${EMULATION_NAME}.xeo >> e${EMULATION_NAME}.c
350fi
351echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
352sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
353if test -n "$GENERATE_RELRO_SCRIPT" ; then
354echo ' ; else if (link_info.relro) return' >> e${EMULATION_NAME}.c
355sed $sc ldscripts/${EMULATION_NAME}.xo >> e${EMULATION_NAME}.c
356fi
357echo ' ; else return' >> e${EMULATION_NAME}.c
358sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
359echo '; }' >> e${EMULATION_NAME}.c
360
361else
362# Scripts read from the filesystem.
363
364fragment <<EOF
365{
366 *isfile = 1;
367
368 if (bfd_link_relocatable (&link_info) && config.build_constructors)
369 return "ldscripts/${EMULATION_NAME}.xu";
370 else if (bfd_link_relocatable (&link_info))
371 return "ldscripts/${EMULATION_NAME}.xr";
372 else if (!config.text_read_only)
373 return "ldscripts/${EMULATION_NAME}.xbn";
374EOF
375if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
376else
377fragment <<EOF
378 else if (!config.magic_demand_paged)
379 return "ldscripts/${EMULATION_NAME}.xn";
380EOF
381fi
382if test -n "$GENERATE_PIE_SCRIPT" ; then
383if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
384fragment <<EOF
385 else if (bfd_link_pie (&link_info)
386 && link_info.combreloc
387 && link_info.relro
388 && (link_info.flags & DF_BIND_NOW))
389 {
390 if (link_info.separate_code)
391 return "ldscripts/${EMULATION_NAME}.xdwe";
392 else
393 return "ldscripts/${EMULATION_NAME}.xdw";
394 }
395EOF
396if test -n "$GENERATE_RELRO_SCRIPT" ; then
397fragment <<EOF
398 else if (bfd_link_pie (&link_info)
399 && link_info.combreloc
400 && link_info.relro)
401 {
402 if (link_info.separate_code)
403 return "ldscripts/${EMULATION_NAME}.xdceo";
404 else
405 return "ldscripts/${EMULATION_NAME}.xdco";
406 }
407EOF
408fi
409fragment <<EOF
410 else if (bfd_link_pie (&link_info)
411 && link_info.combreloc)
412 {
413 if (link_info.separate_code)
414 return "ldscripts/${EMULATION_NAME}.xdce";
415 else
416 return "ldscripts/${EMULATION_NAME}.xdc";
417 }
418EOF
419fi
420if test -n "$GENERATE_RELRO_SCRIPT" ; then
421fragment <<EOF
422 else if (bfd_link_pie (&link_info)
423 && link_info.relro)
424 {
425 if (link_info.separate_code)
426 return "ldscripts/${EMULATION_NAME}.xdeo";
427 else
428 return "ldscripts/${EMULATION_NAME}.xdo";
429 }
430EOF
431fi
432fragment <<EOF
433 else if (bfd_link_pie (&link_info))
434 {
435 if (link_info.separate_code)
436 return "ldscripts/${EMULATION_NAME}.xde";
437 else
438 return "ldscripts/${EMULATION_NAME}.xd";
439 }
440EOF
441fi
442if test -n "$GENERATE_SHLIB_SCRIPT" ; then
443if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
444fragment <<EOF
445 else if (bfd_link_dll (&link_info) && link_info.combreloc
446 && link_info.relro && (link_info.flags & DF_BIND_NOW))
447 {
448 if (link_info.separate_code)
449 return "ldscripts/${EMULATION_NAME}.xswe";
450 else
451 return "ldscripts/${EMULATION_NAME}.xsw";
452 }
453EOF
454if test -n "$GENERATE_RELRO_SCRIPT" ; then
455fragment <<EOF
456 else if (bfd_link_dll (&link_info)
457 && link_info.combreloc
458 && link_info.relro)
459 {
460 if (link_info.separate_code)
461 return "ldscripts/${EMULATION_NAME}.xsceo";
462 else
463 return "ldscripts/${EMULATION_NAME}.xsco";
464 }
465EOF
466fi
467fragment <<EOF
468 else if (bfd_link_dll (&link_info) && link_info.combreloc)
469 {
470 if (link_info.separate_code)
471 return "ldscripts/${EMULATION_NAME}.xsce";
472 else
473 return "ldscripts/${EMULATION_NAME}.xsc";
474 }
475EOF
476fi
477if test -n "$GENERATE_RELRO_SCRIPT" ; then
478fragment <<EOF
479 else if (bfd_link_dll (&link_info)
480 && link_info.relro)
481 {
482 if (link_info.separate_code)
483 return "ldscripts/${EMULATION_NAME}.xseo";
484 else
485 return "ldscripts/${EMULATION_NAME}.xso";
486 }
487EOF
488fi
489fragment <<EOF
490 else if (bfd_link_dll (&link_info))
491 {
492 if (link_info.separate_code)
493 return "ldscripts/${EMULATION_NAME}.xse";
494 else
495 return "ldscripts/${EMULATION_NAME}.xs";
496 }
497EOF
498fi
499if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
500fragment <<EOF
501 else if (link_info.combreloc && link_info.relro
502 && (link_info.flags & DF_BIND_NOW))
503 {
504 if (link_info.separate_code)
505 return "ldscripts/${EMULATION_NAME}.xwe";
506 else
507 return "ldscripts/${EMULATION_NAME}.xw";
508 }
509EOF
510if test -n "$GENERATE_RELRO_SCRIPT" ; then
511fragment <<EOF
512 else if (link_info.combreloc
513 && link_info.relro)
514 {
515 if (link_info.separate_code)
516 return "ldscripts/${EMULATION_NAME}.xceo";
517 else
518 return "ldscripts/${EMULATION_NAME}.xco";
519 }
520EOF
521fi
522fragment <<EOF
523 else if (link_info.combreloc)
524 {
525 if (link_info.separate_code)
526 return "ldscripts/${EMULATION_NAME}.xce";
527 else
528 return "ldscripts/${EMULATION_NAME}.xc";
529 }
530EOF
531fi
532if test -n "$GENERATE_RELRO_SCRIPT" ; then
533fragment <<EOF
534 else if (link_info.relro)
535 {
536 if (link_info.separate_code)
537 return "ldscripts/${EMULATION_NAME}.xeo";
538 else
539 return "ldscripts/${EMULATION_NAME}.xo";
540 }
541EOF
542fi
543fragment <<EOF
544 else
545 {
546 if (link_info.separate_code)
547 return "ldscripts/${EMULATION_NAME}.xe";
548 else
549 return "ldscripts/${EMULATION_NAME}.x";
550 }
551}
552
553EOF
554fi
555fi
556
557if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
558fragment <<EOF
559 $PARSE_AND_LIST_PROLOGUE
560EOF
561fi
562
563fragment <<EOF
564
565enum elf_options
566{
567 OPTION_DISABLE_NEW_DTAGS = 400,
568 OPTION_ENABLE_NEW_DTAGS,
569 OPTION_GROUP,
570 OPTION_EH_FRAME_HDR,
571 OPTION_NO_EH_FRAME_HDR,
572 OPTION_EXCLUDE_LIBS,
573 OPTION_HASH_STYLE,
574 OPTION_BUILD_ID,
575 OPTION_AUDIT,
576 OPTION_COMPRESS_DEBUG
577};
578
579static void
580gld${EMULATION_NAME}_add_options
581 (int ns, char **shortopts, int nl, struct option **longopts,
582 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
583{
584EOF
585if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
586fragment <<EOF
587 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
588EOF
589else
590fragment <<EOF
591 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
592EOF
593fi
594fragment <<EOF
595 static const struct option xtra_long[] = {
596EOF
597if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
598fragment <<EOF
599 {"audit", required_argument, NULL, OPTION_AUDIT},
600 {"Bgroup", no_argument, NULL, OPTION_GROUP},
601EOF
602fi
603fragment <<EOF
604 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
605 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
606EOF
607if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
608fragment <<EOF
609 {"depaudit", required_argument, NULL, 'P'},
610 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
611 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
612 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
613 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
614 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
615 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
616EOF
617fi
618if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
619fragment <<EOF
620 $PARSE_AND_LIST_LONGOPTS
621EOF
622fi
623fragment <<EOF
624 {NULL, no_argument, NULL, 0}
625 };
626
627 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
628 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
629 *longopts = (struct option *)
630 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
631 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
632}
633
634#define DEFAULT_BUILD_ID_STYLE "sha1"
635
636static bool
637gld${EMULATION_NAME}_handle_option (int optc)
638{
639 switch (optc)
640 {
641 default:
642 return false;
643
644 case OPTION_BUILD_ID:
645 free ((char *) ldelf_emit_note_gnu_build_id);
646 ldelf_emit_note_gnu_build_id = NULL;
647 if (optarg == NULL)
648 optarg = DEFAULT_BUILD_ID_STYLE;
649 if (strcmp (optarg, "none"))
650 ldelf_emit_note_gnu_build_id = xstrdup (optarg);
651 break;
652
653 case OPTION_COMPRESS_DEBUG:
654 if (strcasecmp (optarg, "none") == 0)
655 link_info.compress_debug = COMPRESS_DEBUG_NONE;
656 else if (strcasecmp (optarg, "zlib") == 0)
657 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
658 else if (strcasecmp (optarg, "zlib-gnu") == 0)
659 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
660 else if (strcasecmp (optarg, "zlib-gabi") == 0)
661 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
662 else
663 einfo (_("%F%P: invalid --compress-debug-sections option: \`%s'\n"),
664 optarg);
665 break;
666EOF
667
668if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
669fragment <<EOF
670 case OPTION_AUDIT:
671 ldelf_append_to_separated_string (&audit, optarg);
672 break;
673
674 case 'P':
675 ldelf_append_to_separated_string (&depaudit, optarg);
676 break;
677
678 case OPTION_DISABLE_NEW_DTAGS:
679 link_info.new_dtags = false;
680 break;
681
682 case OPTION_ENABLE_NEW_DTAGS:
683 link_info.new_dtags = true;
684 break;
685
686 case OPTION_EH_FRAME_HDR:
687 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
688 break;
689
690 case OPTION_NO_EH_FRAME_HDR:
691 link_info.eh_frame_hdr_type = 0;
692 break;
693
694 case OPTION_GROUP:
695 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
696 /* Groups must be self-contained. */
697 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
698 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
699 break;
700
701 case OPTION_EXCLUDE_LIBS:
702 add_excluded_libs (optarg);
703 break;
704
705 case OPTION_HASH_STYLE:
706 link_info.emit_hash = false;
707 link_info.emit_gnu_hash = false;
708 if (strcmp (optarg, "sysv") == 0)
709 link_info.emit_hash = true;
710 else if (strcmp (optarg, "gnu") == 0)
711 link_info.emit_gnu_hash = true;
712 else if (strcmp (optarg, "both") == 0)
713 {
714 link_info.emit_hash = true;
715 link_info.emit_gnu_hash = true;
716 }
717 else
718 einfo (_("%F%P: invalid hash style \`%s'\n"), optarg);
719 break;
720
721EOF
722fi
723fragment <<EOF
724 case 'z':
725 if (strcmp (optarg, "defs") == 0)
726 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
727 else if (strcmp (optarg, "undefs") == 0)
728 link_info.unresolved_syms_in_objects = RM_IGNORE;
729 else if (strcmp (optarg, "muldefs") == 0)
730 link_info.allow_multiple_definition = true;
731 else if (startswith (optarg, "max-page-size="))
732 {
733 char *end;
734
735 link_info.maxpagesize = strtoul (optarg + 14, &end, 0);
736 if (*end
737 || (link_info.maxpagesize & (link_info.maxpagesize - 1)) != 0)
738 einfo (_("%F%P: invalid maximum page size \`%s'\n"),
739 optarg + 14);
740 link_info.maxpagesize_is_set = true;
741 }
742 else if (startswith (optarg, "common-page-size="))
743 {
744 char *end;
745 link_info.commonpagesize = strtoul (optarg + 17, &end, 0);
746 if (*end
747 || (link_info.commonpagesize & (link_info.commonpagesize - 1)) != 0)
748 einfo (_("%F%P: invalid common page size \`%s'\n"),
749 optarg + 17);
750 link_info.commonpagesize_is_set = true;
751 }
752 else if (startswith (optarg, "stack-size="))
753 {
754 char *end;
755 link_info.stacksize = strtoul (optarg + 11, &end, 0);
756 if (*end || link_info.stacksize < 0)
757 einfo (_("%F%P: invalid stack size \`%s'\n"), optarg + 11);
758 if (!link_info.stacksize)
759 /* Use -1 for explicit no-stack, because zero means
760 'default'. */
761 link_info.stacksize = -1;
762 }
763 else if (strcmp (optarg, "execstack") == 0)
764 {
765 link_info.execstack = true;
766 link_info.noexecstack = false;
767 }
768 else if (strcmp (optarg, "noexecstack") == 0)
769 {
770 link_info.noexecstack = true;
771 link_info.execstack = false;
772 }
773 else if (strcmp (optarg, "unique-symbol") == 0)
774 link_info.unique_symbol = true;
775 else if (strcmp (optarg, "nounique-symbol") == 0)
776 link_info.unique_symbol = false;
777 else if (strcmp (optarg, "globalaudit") == 0)
778 {
779 link_info.flags_1 |= DF_1_GLOBAUDIT;
780 }
781 else if (startswith (optarg, "start-stop-gc"))
782 link_info.start_stop_gc = true;
783 else if (startswith (optarg, "nostart-stop-gc"))
784 link_info.start_stop_gc = false;
785 else if (startswith (optarg, "start-stop-visibility="))
786 {
787 if (strcmp (optarg, "start-stop-visibility=default") == 0)
788 link_info.start_stop_visibility = STV_DEFAULT;
789 else if (strcmp (optarg, "start-stop-visibility=internal") == 0)
790 link_info.start_stop_visibility = STV_INTERNAL;
791 else if (strcmp (optarg, "start-stop-visibility=hidden") == 0)
792 link_info.start_stop_visibility = STV_HIDDEN;
793 else if (strcmp (optarg, "start-stop-visibility=protected") == 0)
794 link_info.start_stop_visibility = STV_PROTECTED;
795 else
796 einfo (_("%F%P: invalid visibility in \`-z %s'; "
797 "must be default, internal, hidden, or protected"),
798 optarg);
799 }
800EOF
801
802if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
803fragment <<EOF
804 else if (strcmp (optarg, "global") == 0)
805 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
806 else if (strcmp (optarg, "initfirst") == 0)
807 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
808 else if (strcmp (optarg, "interpose") == 0)
809 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
810 else if (strcmp (optarg, "loadfltr") == 0)
811 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
812 else if (strcmp (optarg, "nodefaultlib") == 0)
813 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
814 else if (strcmp (optarg, "nodelete") == 0)
815 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
816 else if (strcmp (optarg, "nodlopen") == 0)
817 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
818 else if (strcmp (optarg, "nodump") == 0)
819 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
820 else if (strcmp (optarg, "now") == 0)
821 {
822 link_info.flags |= (bfd_vma) DF_BIND_NOW;
823 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
824 }
825 else if (strcmp (optarg, "lazy") == 0)
826 {
827 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
828 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
829 }
830 else if (strcmp (optarg, "origin") == 0)
831 {
832 link_info.flags |= (bfd_vma) DF_ORIGIN;
833 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
834 }
835 else if (strcmp (optarg, "unique") == 0)
836 link_info.gnu_flags_1 |= (bfd_vma) DF_GNU_1_UNIQUE;
837 else if (strcmp (optarg, "nounique") == 0)
838 link_info.gnu_flags_1 &= ~(bfd_vma) DF_GNU_1_UNIQUE;
839 else if (strcmp (optarg, "combreloc") == 0)
840 link_info.combreloc = true;
841 else if (strcmp (optarg, "nocombreloc") == 0)
842 link_info.combreloc = false;
843 else if (strcmp (optarg, "nocopyreloc") == 0)
844 link_info.nocopyreloc = true;
845EOF
846if test -n "$COMMONPAGESIZE"; then
847fragment <<EOF
848 else if (strcmp (optarg, "relro") == 0)
849 link_info.relro = true;
850 else if (strcmp (optarg, "norelro") == 0)
851 link_info.relro = false;
852EOF
853fi
854fragment <<EOF
855 else if (strcmp (optarg, "separate-code") == 0)
856 link_info.separate_code = true;
857 else if (strcmp (optarg, "noseparate-code") == 0)
858 link_info.separate_code = false;
859 else if (strcmp (optarg, "common") == 0)
860 link_info.elf_stt_common = elf_stt_common;
861 else if (strcmp (optarg, "nocommon") == 0)
862 link_info.elf_stt_common = no_elf_stt_common;
863 else if (strcmp (optarg, "text") == 0)
864 link_info.textrel_check = textrel_check_error;
865 else if (strcmp (optarg, "notext") == 0)
866 link_info.textrel_check = textrel_check_none;
867 else if (strcmp (optarg, "textoff") == 0)
868 link_info.textrel_check = textrel_check_none;
869EOF
870fi
871
872if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
873fragment <<EOF
874 $PARSE_AND_LIST_ARGS_CASE_Z
875EOF
876fi
877
878fragment <<EOF
879 else
880 einfo (_("%P: warning: -z %s ignored\n"), optarg);
881 break;
882EOF
883
884if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
885fragment <<EOF
886 $PARSE_AND_LIST_ARGS_CASES
887EOF
888fi
889
890fragment <<EOF
891 }
892
893 return true;
894}
895
896EOF
897
898if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
899gld_list_options="gld${EMULATION_NAME}_list_options"
900if test -n "$PARSE_AND_LIST_OPTIONS"; then
901fragment <<EOF
902
903static void
904gld${EMULATION_NAME}_list_options (FILE * file)
905{
906EOF
907
908if test -n "$PARSE_AND_LIST_OPTIONS" ; then
909fragment <<EOF
910 $PARSE_AND_LIST_OPTIONS
911EOF
912fi
913
914fragment <<EOF
915}
916EOF
917else
918 gld_list_options="NULL"
919fi
920
921if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
922fragment <<EOF
923 $PARSE_AND_LIST_EPILOGUE
924EOF
925fi
926fi
927
928LDEMUL_AFTER_PARSE=${LDEMUL_AFTER_PARSE-ldelf_after_parse}
929LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=${LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ-gld${EMULATION_NAME}_before_plugin_all_symbols_read}
930LDEMUL_AFTER_OPEN=${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}
931LDEMUL_BEFORE_PLACE_ORPHANS=${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orphans}
932LDEMUL_AFTER_ALLOCATION=${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}
933LDEMUL_SET_OUTPUT_ARCH=${LDEMUL_SET_OUTPUT_ARCH-ldelf_set_output_arch}
934LDEMUL_BEFORE_ALLOCATION=${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}
935LDEMUL_OPEN_DYNAMIC_ARCHIVE=${LDEMUL_OPEN_DYNAMIC_ARCHIVE-ldelf_open_dynamic_archive}
936LDEMUL_PLACE_ORPHAN=${LDEMUL_PLACE_ORPHAN-ldelf_place_orphan}
937LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
938LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
939LDEMUL_LIST_OPTIONS=${LDEMUL_LIST_OPTIONS-${gld_list_options}}
940LDEMUL_RECOGNIZED_FILE=${LDEMUL_RECOGNIZED_FILE-ldelf_load_symbols}
941
942source_em ${srcdir}/emultempl/emulation.em