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