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