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