1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 test -z "${ELFSIZE}" && ELFSIZE=32
4 if [ -z "$MACHINE" ]; then
7 OUTPUT_ARCH=${ARCH}:${MACHINE}
10 /* This file is is generated by a shell script. DO NOT EDIT! */
12 /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
13 Copyright (C) 1991-2025 Free Software Foundation, Inc.
14 Written by Steve Chamberlain <sac@cygnus.com>
15 ELF support by Ian Lance Taylor <ian@cygnus.com>
17 This file is part of the GNU Binutils.
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.
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.
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. */
34 #define TARGET_IS_${EMULATION_NAME}
38 #include "libiberty.h"
55 /* Declare functions used by various EXTRA_EM_FILEs. */
56 static void gld${EMULATION_NAME}_before_parse (void);
57 static void gld${EMULATION_NAME}_before_plugin_all_symbols_read
59 static void gld${EMULATION_NAME}_after_open (void);
60 static void gld${EMULATION_NAME}_before_allocation (void);
61 static void gld${EMULATION_NAME}_after_allocation (void);
64 # Import any needed special functions and/or overrides.
66 source_em ${srcdir}/emultempl/elf-generic.em
67 if test -n "$EXTRA_EM_FILE" ; then
68 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
71 # Functions in this file can be overridden by setting the LDEMUL_* shell
72 # variables. If the name of the overriding function is the same as is
73 # defined in this file, then don't output this file's version.
74 # If a different overriding name is given then output the standard function
75 # as presumably it is called from the overriding function.
77 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
81 gld${EMULATION_NAME}_before_parse (void)
83 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
84 input_flags.dynamic = ${DYNAMIC_LINK-true};
85 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
86 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
87 link_info.check_relocs_after_open_input = true;
89 if test -n "$COMMONPAGESIZE"; then
91 link_info.relro = DEFAULT_LD_Z_RELRO;
95 link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
96 link_info.one_rosegment = DEFAULT_LD_ROSEGMENT;
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 link_info.error_execstack = DEFAULT_LD_ERROR_EXECSTACK;
101 link_info.warn_is_error_for_rwx_segments = DEFAULT_LD_ERROR_RWX_SEGMENTS;
109 /* These variables are used to implement target options */
111 static char *audit; /* colon (typically) separated list of libs */
112 static char *depaudit; /* colon (typically) separated list of libs */
116 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
118 IS_LINUX_TARGET=false
119 IS_FREEBSD_TARGET=false
121 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
122 IS_LINUX_TARGET=true ;;
123 *-*-freebsd* | *-*-dragonfly*)
124 IS_FREEBSD_TARGET=true ;;
127 if test "x${USE_LIBPATH}" = xyes; then
131 if test "x${NATIVE}" = xyes; then
137 /* This is called before calling plugin 'all symbols read' hook. */
140 gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
142 ldelf_before_plugin_all_symbols_read ($IS_LIBPATH, $IS_NATIVE,
145 $ELFSIZE, "$prefix");
148 /* This is called after all the input files have been opened. */
151 gld${EMULATION_NAME}_after_open (void)
153 ldelf_after_open ($IS_LIBPATH, $IS_NATIVE,
154 $IS_LINUX_TARGET, $IS_FREEBSD_TARGET, $ELFSIZE, "$prefix");
160 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
161 if test x"${ELF_INTERPRETER_NAME}" = x; then
162 ELF_INTERPRETER_NAME=NULL
166 /* This is called after the sections have been attached to output
167 sections, but before any sizes or addresses have been set. */
170 gld${EMULATION_NAME}_before_allocation (void)
172 ldelf_before_allocation (audit, depaudit, ${ELF_INTERPRETER_NAME});
178 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
182 gld${EMULATION_NAME}_after_allocation (void)
184 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
187 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
189 ldelf_map_segments (need_layout);
194 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
198 gld${EMULATION_NAME}_get_script (int *isfile)
201 if test x"$COMPILE_IN" = xyes
203 # Scripts compiled in.
205 # sed commands to quote an ld script as a C string.
206 sc="-f ${srcdir}/emultempl/stringify.sed"
212 if (bfd_link_relocatable (&link_info) && config.build_constructors)
215 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
217 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
218 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
220 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
221 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
223 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
224 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
225 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
228 if test -n "$GENERATE_PIE_SCRIPT" ; then
229 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
231 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
232 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
233 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
234 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
235 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
236 sed $sc ldscripts/${EMULATION_NAME}.xdwer >> e${EMULATION_NAME}.c
238 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
239 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
240 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
241 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
242 sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c
244 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
245 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
246 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
247 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
248 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
250 if test -n "$GENERATE_RELRO_SCRIPT" ; then
252 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
253 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
254 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
255 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
256 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
257 sed $sc ldscripts/${EMULATION_NAME}.xdceor >> e${EMULATION_NAME}.c
259 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
260 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
261 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
262 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
263 sed $sc ldscripts/${EMULATION_NAME}.xdceo >> e${EMULATION_NAME}.c
267 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
268 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
269 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
270 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
271 sed $sc ldscripts/${EMULATION_NAME}.xdcer >> e${EMULATION_NAME}.c
273 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
274 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
275 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
276 sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c
278 if test -n "$GENERATE_RELRO_SCRIPT" ; then
280 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
281 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
282 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
283 sed $sc ldscripts/${EMULATION_NAME}.xdco >> e${EMULATION_NAME}.c
287 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
288 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
289 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
291 if test -n "$GENERATE_RELRO_SCRIPT" ; then
293 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
294 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
295 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
296 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
297 sed $sc ldscripts/${EMULATION_NAME}.xdeor >> e${EMULATION_NAME}.c
299 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
300 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
301 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
302 sed $sc ldscripts/${EMULATION_NAME}.xdeo >> e${EMULATION_NAME}.c
308 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
309 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
310 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
311 sed $sc ldscripts/${EMULATION_NAME}.xder >> e${EMULATION_NAME}.c
313 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
314 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
315 sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c
317 if test -n "$GENERATE_RELRO_SCRIPT" ; then
319 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
320 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
321 sed $sc ldscripts/${EMULATION_NAME}.xdo >> e${EMULATION_NAME}.c
325 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
326 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
329 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
330 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
332 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
333 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
334 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
335 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
336 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
337 sed $sc ldscripts/${EMULATION_NAME}.xswer >> e${EMULATION_NAME}.c
339 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
340 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
341 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
342 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
343 sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c
345 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
346 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
347 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
348 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
349 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
351 if test -n "$GENERATE_RELRO_SCRIPT" ; then
353 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
354 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
355 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
356 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
357 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
358 sed $sc ldscripts/${EMULATION_NAME}.xsceor >> e${EMULATION_NAME}.c
360 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
361 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
362 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
363 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
364 sed $sc ldscripts/${EMULATION_NAME}.xsceo >> e${EMULATION_NAME}.c
368 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
369 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
370 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
371 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
372 sed $sc ldscripts/${EMULATION_NAME}.xscer >> e${EMULATION_NAME}.c
374 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
375 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
376 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
377 sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c
379 if test -n "$GENERATE_RELRO_SCRIPT" ; then
381 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
382 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
383 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
384 sed $sc ldscripts/${EMULATION_NAME}.xsco >> e${EMULATION_NAME}.c
388 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
389 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
390 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
392 if test -n "$GENERATE_RELRO_SCRIPT" ; then
394 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
395 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
396 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
397 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
398 sed $sc ldscripts/${EMULATION_NAME}.xseor >> e${EMULATION_NAME}.c
400 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
401 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
402 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
403 sed $sc ldscripts/${EMULATION_NAME}.xseo >> e${EMULATION_NAME}.c
409 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
410 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
411 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
412 sed $sc ldscripts/${EMULATION_NAME}.xser >> e${EMULATION_NAME}.c
414 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
415 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
416 sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c
418 if test -n "$GENERATE_RELRO_SCRIPT" ; then
420 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
421 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
422 sed $sc ldscripts/${EMULATION_NAME}.xso >> e${EMULATION_NAME}.c
426 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
427 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
431 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
433 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
434 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
435 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
436 sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c
438 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
439 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
440 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
441 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
442 sed $sc ldscripts/${EMULATION_NAME}.xwer >> e${EMULATION_NAME}.c
444 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
445 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
446 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
447 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
449 if test -n "$GENERATE_RELRO_SCRIPT" ; then
451 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
452 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
453 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
454 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
455 sed $sc ldscripts/${EMULATION_NAME}.xceor >> e${EMULATION_NAME}.c
457 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
458 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
459 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
460 sed $sc ldscripts/${EMULATION_NAME}.xceo >> e${EMULATION_NAME}.c
464 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
465 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
466 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
467 sed $sc ldscripts/${EMULATION_NAME}.xcer >> e${EMULATION_NAME}.c
469 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
470 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
471 sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c
473 if test -n "$GENERATE_RELRO_SCRIPT" ; then
475 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
476 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
477 sed $sc ldscripts/${EMULATION_NAME}.xco >> e${EMULATION_NAME}.c
481 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
482 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
486 if test -n "$GENERATE_RELRO_SCRIPT" ; then
488 echo ' ; else if (link_info.separate_code' >> e${EMULATION_NAME}.c
489 echo ' && link_info.one_rosegment' >> e${EMULATION_NAME}.c
490 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
491 sed $sc ldscripts/${EMULATION_NAME}.xeor >> e${EMULATION_NAME}.c
493 echo ' ; else if (link_info.separate_code' >> e${EMULATION_NAME}.c
494 echo ' && link_info.relro) return' >> e${EMULATION_NAME}.c
495 sed $sc ldscripts/${EMULATION_NAME}.xeo >> e${EMULATION_NAME}.c
499 echo ' ; else if (link_info.separate_code' >> e${EMULATION_NAME}.c
500 echo ' && link_info.one_rosegment) return' >> e${EMULATION_NAME}.c
501 sed $sc ldscripts/${EMULATION_NAME}.xer >> e${EMULATION_NAME}.c
503 echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
504 sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
506 if test -n "$GENERATE_RELRO_SCRIPT" ; then
508 echo ' ; else if (link_info.relro) return' >> e${EMULATION_NAME}.c
509 sed $sc ldscripts/${EMULATION_NAME}.xo >> e${EMULATION_NAME}.c
513 echo ' ; else return' >> e${EMULATION_NAME}.c
514 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
515 echo '; }' >> e${EMULATION_NAME}.c
518 # Scripts read from the filesystem.
524 if (bfd_link_relocatable (&link_info) && config.build_constructors)
525 return "ldscripts/${EMULATION_NAME}.xu";
526 else if (bfd_link_relocatable (&link_info))
527 return "ldscripts/${EMULATION_NAME}.xr";
528 else if (!config.text_read_only)
529 return "ldscripts/${EMULATION_NAME}.xbn";
531 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
534 else if (!config.magic_demand_paged)
535 return "ldscripts/${EMULATION_NAME}.xn";
538 if test -n "$GENERATE_PIE_SCRIPT" ; then
539 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
541 else if (bfd_link_pie (&link_info)
542 && link_info.combreloc
544 && (link_info.flags & DF_BIND_NOW))
546 if (link_info.separate_code)
548 if (link_info.one_rosegment)
549 return "ldscripts/${EMULATION_NAME}.xdwer";
551 return "ldscripts/${EMULATION_NAME}.xdwe";
554 return "ldscripts/${EMULATION_NAME}.xdw";
557 if test -n "$GENERATE_RELRO_SCRIPT" ; then
559 else if (bfd_link_pie (&link_info)
560 && link_info.combreloc
563 if (link_info.separate_code)
565 if (link_info.one_rosegment)
566 return "ldscripts/${EMULATION_NAME}.xdceor";
568 return "ldscripts/${EMULATION_NAME}.xdceo";
571 return "ldscripts/${EMULATION_NAME}.xdco";
576 else if (bfd_link_pie (&link_info)
577 && link_info.combreloc)
579 if (link_info.separate_code)
581 if (link_info.one_rosegment)
582 return "ldscripts/${EMULATION_NAME}.xdcer";
584 return "ldscripts/${EMULATION_NAME}.xdce";
587 return "ldscripts/${EMULATION_NAME}.xdc";
591 if test -n "$GENERATE_RELRO_SCRIPT" ; then
593 else if (bfd_link_pie (&link_info)
596 if (link_info.separate_code)
598 if (link_info.one_rosegment)
599 return "ldscripts/${EMULATION_NAME}.xdeor";
601 return "ldscripts/${EMULATION_NAME}.xdeo";
604 return "ldscripts/${EMULATION_NAME}.xdo";
609 else if (bfd_link_pie (&link_info))
611 if (link_info.separate_code)
613 if (link_info.one_rosegment)
614 return "ldscripts/${EMULATION_NAME}.xder";
616 return "ldscripts/${EMULATION_NAME}.xde";
619 return "ldscripts/${EMULATION_NAME}.xd";
623 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
624 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
626 else if (bfd_link_dll (&link_info) && link_info.combreloc
627 && link_info.relro && (link_info.flags & DF_BIND_NOW))
629 if (link_info.separate_code)
631 if (link_info.one_rosegment)
632 return "ldscripts/${EMULATION_NAME}.xswer";
634 return "ldscripts/${EMULATION_NAME}.xswe";
637 return "ldscripts/${EMULATION_NAME}.xsw";
640 if test -n "$GENERATE_RELRO_SCRIPT" ; then
642 else if (bfd_link_dll (&link_info)
643 && link_info.combreloc
646 if (link_info.separate_code)
648 if (link_info.one_rosegment)
649 return "ldscripts/${EMULATION_NAME}.xsceor";
651 return "ldscripts/${EMULATION_NAME}.xsceo";
654 return "ldscripts/${EMULATION_NAME}.xsco";
659 else if (bfd_link_dll (&link_info) && link_info.combreloc)
661 if (link_info.separate_code)
663 if (link_info.one_rosegment)
664 return "ldscripts/${EMULATION_NAME}.xscer";
666 return "ldscripts/${EMULATION_NAME}.xsce";
669 return "ldscripts/${EMULATION_NAME}.xsc";
673 if test -n "$GENERATE_RELRO_SCRIPT" ; then
675 else if (bfd_link_dll (&link_info)
678 if (link_info.separate_code)
680 if (link_info.one_rosegment)
681 return "ldscripts/${EMULATION_NAME}.xseor";
683 return "ldscripts/${EMULATION_NAME}.xseo";
686 return "ldscripts/${EMULATION_NAME}.xso";
691 else if (bfd_link_dll (&link_info))
693 if (link_info.separate_code)
695 if (link_info.one_rosegment)
696 return "ldscripts/${EMULATION_NAME}.xser";
698 return "ldscripts/${EMULATION_NAME}.xse";
701 return "ldscripts/${EMULATION_NAME}.xs";
705 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
707 else if (link_info.combreloc && link_info.relro
708 && (link_info.flags & DF_BIND_NOW))
710 if (link_info.separate_code)
712 if (link_info.one_rosegment)
713 return "ldscripts/${EMULATION_NAME}.xwer";
715 return "ldscripts/${EMULATION_NAME}.xwe";
718 return "ldscripts/${EMULATION_NAME}.xw";
721 if test -n "$GENERATE_RELRO_SCRIPT" ; then
723 else if (link_info.combreloc
726 if (link_info.separate_code)
728 if (link_info.one_rosegment)
729 return "ldscripts/${EMULATION_NAME}.xceor";
731 return "ldscripts/${EMULATION_NAME}.xceo";
734 return "ldscripts/${EMULATION_NAME}.xco";
739 else if (link_info.combreloc)
741 if (link_info.separate_code)
743 if (link_info.one_rosegment)
744 return "ldscripts/${EMULATION_NAME}.xcer";
746 return "ldscripts/${EMULATION_NAME}.xce";
749 return "ldscripts/${EMULATION_NAME}.xc";
753 if test -n "$GENERATE_RELRO_SCRIPT" ; then
755 else if (link_info.relro)
757 if (link_info.separate_code)
759 if (link_info.one_rosegment)
760 return "ldscripts/${EMULATION_NAME}.xeor";
762 return "ldscripts/${EMULATION_NAME}.xeo";
765 return "ldscripts/${EMULATION_NAME}.xo";
772 if (link_info.separate_code)
774 if (link_info.one_rosegment)
775 return "ldscripts/${EMULATION_NAME}.xer";
777 return "ldscripts/${EMULATION_NAME}.xe";
780 return "ldscripts/${EMULATION_NAME}.x";
791 gld${EMULATION_NAME}_add_options
792 (int ns, char **shortopts, int nl, struct option **longopts,
793 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
796 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
798 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
802 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
806 static const struct option xtra_long[] = {
808 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
810 {"audit", required_argument, NULL, OPTION_AUDIT},
811 {"Bgroup", no_argument, NULL, OPTION_GROUP},
815 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
816 {"package-metadata", optional_argument, NULL, OPTION_PACKAGE_METADATA},
817 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
818 {"rosegment", no_argument, NULL, OPTION_ROSEGMENT},
819 {"no-rosegment", no_argument, NULL, OPTION_NO_ROSEGMENT},
821 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
823 {"depaudit", required_argument, NULL, 'P'},
824 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
825 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
826 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
827 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
828 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
829 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
832 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
834 $PARSE_AND_LIST_LONGOPTS
838 {NULL, no_argument, NULL, 0}
841 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
842 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
843 *longopts = (struct option *)
844 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
845 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
848 #define DEFAULT_BUILD_ID_STYLE "sha1"
851 gld${EMULATION_NAME}_handle_option (int optc)
858 case OPTION_BUILD_ID:
859 free ((char *) ldelf_emit_note_gnu_build_id);
860 ldelf_emit_note_gnu_build_id = NULL;
862 optarg = DEFAULT_BUILD_ID_STYLE;
863 if (strcmp (optarg, "none"))
864 ldelf_emit_note_gnu_build_id = xstrdup (optarg);
867 case OPTION_PACKAGE_METADATA:
868 free ((char *) ldelf_emit_note_fdo_package_metadata);
869 ldelf_emit_note_fdo_package_metadata = NULL;
872 size_t len = strlen (optarg);
875 char *package_metadata = xmalloc (len + 1);
876 percent_decode (optarg, package_metadata);
877 ldelf_emit_note_fdo_package_metadata = package_metadata;
882 case OPTION_COMPRESS_DEBUG:
883 config.compress_debug = bfd_get_compression_algorithm (optarg);
884 if (strcasecmp (optarg, "zstd") == 0)
887 if (config.compress_debug == COMPRESS_DEBUG_ZSTD)
888 einfo (_ ("%F%P: --compress-debug-sections=zstd: ld is not built "
889 "with zstd support\n"));
892 if (config.compress_debug == COMPRESS_UNKNOWN)
893 einfo (_("%F%P: invalid --compress-debug-sections option: \`%s'\n"),
897 case OPTION_ROSEGMENT:
898 link_info.one_rosegment = true;
900 case OPTION_NO_ROSEGMENT:
901 link_info.one_rosegment = false;
905 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
908 ldelf_append_to_separated_string (&audit, optarg);
912 ldelf_append_to_separated_string (&depaudit, optarg);
915 case OPTION_DISABLE_NEW_DTAGS:
916 link_info.new_dtags = false;
919 case OPTION_ENABLE_NEW_DTAGS:
920 link_info.new_dtags = true;
923 case OPTION_EH_FRAME_HDR:
924 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
927 case OPTION_NO_EH_FRAME_HDR:
928 link_info.eh_frame_hdr_type = 0;
932 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
933 /* Groups must be self-contained. */
934 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
935 link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
938 case OPTION_EXCLUDE_LIBS:
939 add_excluded_libs (optarg);
942 case OPTION_HASH_STYLE:
943 link_info.emit_hash = false;
944 link_info.emit_gnu_hash = false;
945 if (strcmp (optarg, "sysv") == 0)
946 link_info.emit_hash = true;
947 else if (strcmp (optarg, "gnu") == 0)
948 link_info.emit_gnu_hash = true;
949 else if (strcmp (optarg, "both") == 0)
951 link_info.emit_hash = true;
952 link_info.emit_gnu_hash = true;
955 einfo (_("%F%P: invalid hash style \`%s'\n"), optarg);
962 if (strcmp (optarg, "defs") == 0)
963 link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
964 else if (strcmp (optarg, "undefs") == 0)
965 link_info.unresolved_syms_in_objects = RM_IGNORE;
966 else if (strcmp (optarg, "muldefs") == 0)
967 link_info.allow_multiple_definition = true;
968 else if (startswith (optarg, "max-page-size="))
972 link_info.maxpagesize = strtoul (optarg + 14, &end, 0);
974 || (link_info.maxpagesize & (link_info.maxpagesize - 1)) != 0)
975 einfo (_("%F%P: invalid maximum page size \`%s'\n"),
977 link_info.maxpagesize_is_set = true;
979 else if (startswith (optarg, "common-page-size="))
982 link_info.commonpagesize = strtoul (optarg + 17, &end, 0);
984 || (link_info.commonpagesize & (link_info.commonpagesize - 1)) != 0)
985 einfo (_("%F%P: invalid common page size \`%s'\n"),
987 link_info.commonpagesize_is_set = true;
989 else if (startswith (optarg, "stack-size="))
992 link_info.stacksize = strtoul (optarg + 11, &end, 0);
993 if (*end || link_info.stacksize < 0)
994 einfo (_("%F%P: invalid stack size \`%s'\n"), optarg + 11);
995 if (!link_info.stacksize)
996 /* Use -1 for explicit no-stack, because zero means
998 link_info.stacksize = -1;
1000 else if (strcmp (optarg, "execstack") == 0)
1002 link_info.execstack = true;
1003 link_info.noexecstack = false;
1005 else if (strcmp (optarg, "noexecstack") == 0)
1007 link_info.noexecstack = true;
1008 link_info.execstack = false;
1010 else if (strcmp (optarg, "unique-symbol") == 0)
1011 link_info.unique_symbol = true;
1012 else if (strcmp (optarg, "nounique-symbol") == 0)
1013 link_info.unique_symbol = false;
1014 else if (strcmp (optarg, "globalaudit") == 0)
1016 link_info.flags_1 |= DF_1_GLOBAUDIT;
1018 else if (startswith (optarg, "start-stop-gc"))
1019 link_info.start_stop_gc = true;
1020 else if (startswith (optarg, "nostart-stop-gc"))
1021 link_info.start_stop_gc = false;
1022 else if (startswith (optarg, "start-stop-visibility="))
1024 if (strcmp (optarg, "start-stop-visibility=default") == 0)
1025 link_info.start_stop_visibility = STV_DEFAULT;
1026 else if (strcmp (optarg, "start-stop-visibility=internal") == 0)
1027 link_info.start_stop_visibility = STV_INTERNAL;
1028 else if (strcmp (optarg, "start-stop-visibility=hidden") == 0)
1029 link_info.start_stop_visibility = STV_HIDDEN;
1030 else if (strcmp (optarg, "start-stop-visibility=protected") == 0)
1031 link_info.start_stop_visibility = STV_PROTECTED;
1033 einfo (_("%F%P: invalid visibility in \`-z %s'; "
1034 "must be default, internal, hidden, or protected"),
1037 else if (strcmp (optarg, "sectionheader") == 0)
1038 config.no_section_header = false;
1039 else if (strcmp (optarg, "nosectionheader") == 0)
1040 config.no_section_header = true;
1043 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1045 else if (strcmp (optarg, "global") == 0)
1046 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
1047 else if (strcmp (optarg, "initfirst") == 0)
1048 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
1049 else if (strcmp (optarg, "interpose") == 0)
1050 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
1051 else if (strcmp (optarg, "loadfltr") == 0)
1052 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
1053 else if (strcmp (optarg, "nodefaultlib") == 0)
1054 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
1055 else if (strcmp (optarg, "nodelete") == 0)
1056 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
1057 else if (strcmp (optarg, "nodlopen") == 0)
1058 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
1059 else if (strcmp (optarg, "nodump") == 0)
1060 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
1061 else if (strcmp (optarg, "now") == 0)
1063 link_info.flags |= (bfd_vma) DF_BIND_NOW;
1064 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
1066 else if (strcmp (optarg, "lazy") == 0)
1068 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
1069 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
1071 else if (strcmp (optarg, "origin") == 0)
1073 link_info.flags |= (bfd_vma) DF_ORIGIN;
1074 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
1076 else if (strcmp (optarg, "unique") == 0)
1077 link_info.gnu_flags_1 |= (bfd_vma) DF_GNU_1_UNIQUE;
1078 else if (strcmp (optarg, "nounique") == 0)
1079 link_info.gnu_flags_1 &= ~(bfd_vma) DF_GNU_1_UNIQUE;
1080 else if (strcmp (optarg, "combreloc") == 0)
1081 link_info.combreloc = true;
1082 else if (strcmp (optarg, "nocombreloc") == 0)
1083 link_info.combreloc = false;
1084 else if (strcmp (optarg, "nocopyreloc") == 0)
1085 link_info.nocopyreloc = true;
1087 if test -n "$COMMONPAGESIZE"; then
1089 else if (strcmp (optarg, "relro") == 0)
1090 link_info.relro = true;
1091 else if (strcmp (optarg, "norelro") == 0)
1092 link_info.relro = false;
1097 else if (strcmp (optarg, "separate-code") == 0)
1098 link_info.separate_code = true;
1099 else if (strcmp (optarg, "noseparate-code") == 0)
1100 link_info.separate_code = false;
1101 else if (strcmp (optarg, "common") == 0)
1102 link_info.elf_stt_common = elf_stt_common;
1103 else if (strcmp (optarg, "nocommon") == 0)
1104 link_info.elf_stt_common = no_elf_stt_common;
1105 else if (strcmp (optarg, "text") == 0)
1106 link_info.textrel_check = textrel_check_error;
1107 else if (strcmp (optarg, "notext") == 0)
1108 link_info.textrel_check = textrel_check_none;
1109 else if (strcmp (optarg, "textoff") == 0)
1110 link_info.textrel_check = textrel_check_none;
1113 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
1115 $PARSE_AND_LIST_ARGS_CASE_Z
1121 queue_unknown_cmdline_warning ("-z %s", optarg);
1125 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
1127 $PARSE_AND_LIST_ARGS_CASES
1139 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
1140 gld_list_options="gld${EMULATION_NAME}_list_options"
1141 if test -n "$PARSE_AND_LIST_OPTIONS"; then
1145 gld${EMULATION_NAME}_list_options (FILE * file)
1149 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
1151 $PARSE_AND_LIST_OPTIONS
1159 gld_list_options="NULL"
1162 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
1164 $PARSE_AND_LIST_EPILOGUE
1169 LDEMUL_AFTER_PARSE=${LDEMUL_AFTER_PARSE-ldelf_after_parse}
1170 LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=${LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ-gld${EMULATION_NAME}_before_plugin_all_symbols_read}
1171 LDEMUL_AFTER_OPEN=${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}
1172 LDEMUL_BEFORE_PLACE_ORPHANS=${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orphans}
1173 LDEMUL_AFTER_ALLOCATION=${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}
1174 LDEMUL_SET_OUTPUT_ARCH=${LDEMUL_SET_OUTPUT_ARCH-ldelf_set_output_arch}
1175 LDEMUL_BEFORE_ALLOCATION=${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}
1176 LDEMUL_OPEN_DYNAMIC_ARCHIVE=${LDEMUL_OPEN_DYNAMIC_ARCHIVE-ldelf_open_dynamic_archive}
1177 LDEMUL_PLACE_ORPHAN=${LDEMUL_PLACE_ORPHAN-ldelf_place_orphan}
1178 LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
1179 LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
1180 LDEMUL_LIST_OPTIONS=${LDEMUL_LIST_OPTIONS-${gld_list_options}}
1181 LDEMUL_RECOGNIZED_FILE=${LDEMUL_RECOGNIZED_FILE-ldelf_load_symbols}
1183 source_em ${srcdir}/emultempl/emulation.em