LoongArch: Fix linker generate PLT entry for data symbol
[binutils-gdb.git] / ld / emultempl / elf.em
blob0fb6226787f96e0322a014aa0fd9e4fde460ef3e
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
5   OUTPUT_ARCH=${ARCH}
6 else
7   OUTPUT_ARCH=${ARCH}:${MACHINE}
8 fi
9 fragment <<EOF
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-2023 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}
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"
54 /* Declare functions used by various EXTRA_EM_FILEs.  */
55 static void gld${EMULATION_NAME}_before_parse (void);
56 static void gld${EMULATION_NAME}_before_plugin_all_symbols_read
57   (void);
58 static void gld${EMULATION_NAME}_after_open (void);
59 static void gld${EMULATION_NAME}_before_allocation (void);
60 static void gld${EMULATION_NAME}_after_allocation (void);
61 EOF
63 # Import any needed special functions and/or overrides.
65 source_em ${srcdir}/emultempl/elf-generic.em
66 if test -n "$EXTRA_EM_FILE" ; then
67   source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
70 # Functions in this file can be overridden by setting the LDEMUL_* shell
71 # variables.  If the name of the overriding function is the same as is
72 # defined in this file, then don't output this file's version.
73 # If a different overriding name is given then output the standard function
74 # as presumably it is called from the overriding function.
76 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
77 fragment <<EOF
79 static void
80 gld${EMULATION_NAME}_before_parse (void)
82   ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
83   input_flags.dynamic = ${DYNAMIC_LINK-true};
84   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
85   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo true ; else echo false ; fi`;
86   link_info.check_relocs_after_open_input = true;
87 EOF
88 if test -n "$COMMONPAGESIZE"; then
89 fragment <<EOF
90   link_info.relro = DEFAULT_LD_Z_RELRO;
91 EOF
93 fragment <<EOF
94   link_info.separate_code = DEFAULT_LD_Z_SEPARATE_CODE;
95   link_info.warn_execstack = DEFAULT_LD_WARN_EXECSTACK;
96   link_info.no_warn_rwx_segments = ! DEFAULT_LD_WARN_RWX_SEGMENTS;
97   link_info.default_execstack = DEFAULT_LD_EXECSTACK;
98   link_info.error_execstack = DEFAULT_LD_ERROR_EXECSTACK;
99   link_info.warn_is_error_for_rwx_segments = DEFAULT_LD_ERROR_RWX_SEGMENTS;
105 fragment <<EOF
107 /* These variables are used to implement target options */
109 static char *audit; /* colon (typically) separated list of libs */
110 static char *depaudit; /* colon (typically) separated list of libs */
114 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
116   IS_LINUX_TARGET=false
117   IS_FREEBSD_TARGET=false
118   case ${target} in
119     *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
120       IS_LINUX_TARGET=true ;;
121     *-*-freebsd* | *-*-dragonfly*)
122       IS_FREEBSD_TARGET=true ;;
123   esac
124   IS_LIBPATH=false
125   if test "x${USE_LIBPATH}" = xyes; then
126     IS_LIBPATH=true
127   fi
128   IS_NATIVE=false
129   if test "x${NATIVE}" = xyes; then
130     IS_NATIVE=true
131   fi
133 fragment <<EOF
135 /* This is called before calling plugin 'all symbols read' hook.  */
137 static void
138 gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
140   ldelf_before_plugin_all_symbols_read ($IS_LIBPATH, $IS_NATIVE,
141                                         $IS_LINUX_TARGET,
142                                         $IS_FREEBSD_TARGET,
143                                         $ELFSIZE, "$prefix");
146 /* This is called after all the input files have been opened.  */
148 static void
149 gld${EMULATION_NAME}_after_open (void)
151   ldelf_after_open ($IS_LIBPATH, $IS_NATIVE,
152                     $IS_LINUX_TARGET, $IS_FREEBSD_TARGET, $ELFSIZE, "$prefix");
158 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
159   if test x"${ELF_INTERPRETER_NAME}" = x; then
160     ELF_INTERPRETER_NAME=NULL
161   fi
162 fragment <<EOF
164 /* This is called after the sections have been attached to output
165    sections, but before any sizes or addresses have been set.  */
167 static void
168 gld${EMULATION_NAME}_before_allocation (void)
170   ldelf_before_allocation (audit, depaudit, ${ELF_INTERPRETER_NAME});
176 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
177 fragment <<EOF
179 static void
180 gld${EMULATION_NAME}_after_allocation (void)
182   int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
184   if (need_layout < 0)
185     einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
186   else
187     ldelf_map_segments (need_layout);
192 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
193 fragment <<EOF
195 static char *
196 gld${EMULATION_NAME}_get_script (int *isfile)
199 if test x"$COMPILE_IN" = xyes
200 then
201 # Scripts compiled in.
203 # sed commands to quote an ld script as a C string.
204 sc="-f ${srcdir}/emultempl/stringify.sed"
206 fragment <<EOF
208   *isfile = 0;
210   if (bfd_link_relocatable (&link_info) && config.build_constructors)
211     return
213 sed $sc ldscripts/${EMULATION_NAME}.xu                  >> e${EMULATION_NAME}.c
214 echo '  ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
215 sed $sc ldscripts/${EMULATION_NAME}.xr                  >> e${EMULATION_NAME}.c
216 echo '  ; else if (!config.text_read_only) return'      >> e${EMULATION_NAME}.c
217 sed $sc ldscripts/${EMULATION_NAME}.xbn                 >> e${EMULATION_NAME}.c
218 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
219 echo '  ; else if (!config.magic_demand_paged) return'  >> e${EMULATION_NAME}.c
220 sed $sc ldscripts/${EMULATION_NAME}.xn                  >> e${EMULATION_NAME}.c
222 if test -n "$GENERATE_PIE_SCRIPT" ; then
223 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
224 echo '  ; else if (bfd_link_pie (&link_info)'           >> e${EMULATION_NAME}.c
225 echo '             && link_info.combreloc'              >> e${EMULATION_NAME}.c
226 echo '             && link_info.separate_code'          >> e${EMULATION_NAME}.c
227 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
228 sed $sc ldscripts/${EMULATION_NAME}.xdwe                >> e${EMULATION_NAME}.c
229 echo '  ; else if (bfd_link_pie (&link_info)'           >> e${EMULATION_NAME}.c
230 echo '             && link_info.combreloc'              >> e${EMULATION_NAME}.c
231 echo '             && link_info.relro'                  >> e${EMULATION_NAME}.c
232 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
233 sed $sc ldscripts/${EMULATION_NAME}.xdw                 >> e${EMULATION_NAME}.c
234 if test -n "$GENERATE_RELRO_SCRIPT" ; then
235 echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
236 echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
237 echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
238 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
239 sed $sc ldscripts/${EMULATION_NAME}.xdceo              >> e${EMULATION_NAME}.c
241 echo '  ; else if (bfd_link_pie (&link_info)'           >> e${EMULATION_NAME}.c
242 echo '             && link_info.separate_code'          >> e${EMULATION_NAME}.c
243 echo '             && link_info.combreloc) return'      >> e${EMULATION_NAME}.c
244 sed $sc ldscripts/${EMULATION_NAME}.xdce                >> e${EMULATION_NAME}.c
245 if test -n "$GENERATE_RELRO_SCRIPT" ; then
246 echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
247 echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
248 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
249 sed $sc ldscripts/${EMULATION_NAME}.xdco               >> e${EMULATION_NAME}.c
251 echo '  ; else if (bfd_link_pie (&link_info)'           >> e${EMULATION_NAME}.c
252 echo '             && link_info.combreloc) return'      >> e${EMULATION_NAME}.c
253 sed $sc ldscripts/${EMULATION_NAME}.xdc                 >> e${EMULATION_NAME}.c
254 if test -n "$GENERATE_RELRO_SCRIPT" ; then
255 echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
256 echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
257 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
258 sed $sc ldscripts/${EMULATION_NAME}.xdeo               >> e${EMULATION_NAME}.c
261 echo '  ; else if (bfd_link_pie (&link_info)'           >> e${EMULATION_NAME}.c
262 echo '             && link_info.separate_code) return'  >> e${EMULATION_NAME}.c
263 sed $sc ldscripts/${EMULATION_NAME}.xde                 >> e${EMULATION_NAME}.c
264 if test -n "$GENERATE_RELRO_SCRIPT" ; then
265 echo '  ; else if (bfd_link_pie (&link_info)'          >> e${EMULATION_NAME}.c
266 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
267 sed $sc ldscripts/${EMULATION_NAME}.xdo                >> e${EMULATION_NAME}.c
269 echo '  ; else if (bfd_link_pie (&link_info)) return'   >> e${EMULATION_NAME}.c
270 sed $sc ldscripts/${EMULATION_NAME}.xd                  >> e${EMULATION_NAME}.c
272 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
273 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
274 echo '  ; else if (bfd_link_dll (&link_info)'           >> e${EMULATION_NAME}.c
275 echo '             && link_info.combreloc'              >> e${EMULATION_NAME}.c
276 echo '             && link_info.separate_code'          >> e${EMULATION_NAME}.c
277 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
278 sed $sc ldscripts/${EMULATION_NAME}.xswe                >> e${EMULATION_NAME}.c
279 echo '  ; else if (bfd_link_dll (&link_info)'           >> e${EMULATION_NAME}.c
280 echo '             && link_info.combreloc'              >> e${EMULATION_NAME}.c
281 echo '             && link_info.relro'                  >> e${EMULATION_NAME}.c
282 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
283 sed $sc ldscripts/${EMULATION_NAME}.xsw                 >> e${EMULATION_NAME}.c
284 if test -n "$GENERATE_RELRO_SCRIPT" ; then
285 echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
286 echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
287 echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
288 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
289 sed $sc ldscripts/${EMULATION_NAME}.xsceo              >> e${EMULATION_NAME}.c
291 echo '  ; else if (bfd_link_dll (&link_info)'           >> e${EMULATION_NAME}.c
292 echo '             && link_info.combreloc'              >> e${EMULATION_NAME}.c
293 echo '             && link_info.separate_code) return'  >> e${EMULATION_NAME}.c
294 sed $sc ldscripts/${EMULATION_NAME}.xsce                        >> e${EMULATION_NAME}.c
295 if test -n "$GENERATE_RELRO_SCRIPT" ; then
296 echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
297 echo '             && link_info.combreloc'             >> e${EMULATION_NAME}.c
298 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
299 sed $sc ldscripts/${EMULATION_NAME}.xsco               >> e${EMULATION_NAME}.c
301 echo '  ; else if (bfd_link_dll (&link_info)'           >> e${EMULATION_NAME}.c
302 echo '             && link_info.combreloc) return'      >> e${EMULATION_NAME}.c
303 sed $sc ldscripts/${EMULATION_NAME}.xsc                 >> e${EMULATION_NAME}.c
304 if test -n "$GENERATE_RELRO_SCRIPT" ; then
305 echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
306 echo '             && link_info.separate_code'         >> e${EMULATION_NAME}.c
307 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
308 sed $sc ldscripts/${EMULATION_NAME}.xseo               >> e${EMULATION_NAME}.c
311 echo '  ; else if (bfd_link_dll (&link_info)'           >> e${EMULATION_NAME}.c
312 echo '             && link_info.separate_code) return'  >> e${EMULATION_NAME}.c
313 sed $sc ldscripts/${EMULATION_NAME}.xse                 >> e${EMULATION_NAME}.c
314 if test -n "$GENERATE_RELRO_SCRIPT" ; then
315 echo '  ; else if (bfd_link_dll (&link_info)'          >> e${EMULATION_NAME}.c
316 echo '             && link_info.relro) return'         >> e${EMULATION_NAME}.c
317 sed $sc ldscripts/${EMULATION_NAME}.xso               >> e${EMULATION_NAME}.c
319 echo '  ; else if (bfd_link_dll (&link_info)) return'   >> e${EMULATION_NAME}.c
320 sed $sc ldscripts/${EMULATION_NAME}.xs                  >> e${EMULATION_NAME}.c
322 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
323 echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
324 echo '             && link_info.separate_code'          >> e${EMULATION_NAME}.c
325 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
326 sed $sc ldscripts/${EMULATION_NAME}.xwe                 >> e${EMULATION_NAME}.c
327 echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
328 echo '             && link_info.relro'                  >> e${EMULATION_NAME}.c
329 echo '             && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
330 sed $sc ldscripts/${EMULATION_NAME}.xw                  >> e${EMULATION_NAME}.c
331 if test -n "$GENERATE_RELRO_SCRIPT" ; then
332 echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
333 echo '             && link_info.separate_code'          >> e${EMULATION_NAME}.c
334 echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
335 sed $sc ldscripts/${EMULATION_NAME}.xceo                >> e${EMULATION_NAME}.c
337 echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
338 echo '             && link_info.separate_code) return'  >> e${EMULATION_NAME}.c
339 sed $sc ldscripts/${EMULATION_NAME}.xce                 >> e${EMULATION_NAME}.c
340 if test -n "$GENERATE_RELRO_SCRIPT" ; then
341 echo '  ; else if (link_info.combreloc'                 >> e${EMULATION_NAME}.c
342 echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
343 sed $sc ldscripts/${EMULATION_NAME}.xco                 >> e${EMULATION_NAME}.c
345 echo '  ; else if (link_info.combreloc) return'         >> e${EMULATION_NAME}.c
346 sed $sc ldscripts/${EMULATION_NAME}.xc                  >> e${EMULATION_NAME}.c
348 if test -n "$GENERATE_RELRO_SCRIPT" ; then
349 echo '  ; else if (link_info.separate_code'             >> e${EMULATION_NAME}.c
350 echo '             && link_info.relro) return'          >> e${EMULATION_NAME}.c
351 sed $sc ldscripts/${EMULATION_NAME}.xeo                 >> e${EMULATION_NAME}.c
353 echo '  ; else if (link_info.separate_code) return'     >> e${EMULATION_NAME}.c
354 sed $sc ldscripts/${EMULATION_NAME}.xe                  >> e${EMULATION_NAME}.c
355 if test -n "$GENERATE_RELRO_SCRIPT" ; then
356 echo '  ; else if (link_info.relro) return'             >> e${EMULATION_NAME}.c
357 sed $sc ldscripts/${EMULATION_NAME}.xo                  >> e${EMULATION_NAME}.c
359 echo '  ; else return'                                  >> e${EMULATION_NAME}.c
360 sed $sc ldscripts/${EMULATION_NAME}.x                   >> e${EMULATION_NAME}.c
361 echo '; }'                                              >> e${EMULATION_NAME}.c
363 else
364 # Scripts read from the filesystem.
366 fragment <<EOF
368   *isfile = 1;
370   if (bfd_link_relocatable (&link_info) && config.build_constructors)
371     return "ldscripts/${EMULATION_NAME}.xu";
372   else if (bfd_link_relocatable (&link_info))
373     return "ldscripts/${EMULATION_NAME}.xr";
374   else if (!config.text_read_only)
375     return "ldscripts/${EMULATION_NAME}.xbn";
377 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
378 else
379 fragment <<EOF
380   else if (!config.magic_demand_paged)
381     return "ldscripts/${EMULATION_NAME}.xn";
384 if test -n "$GENERATE_PIE_SCRIPT" ; then
385 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
386 fragment <<EOF
387   else if (bfd_link_pie (&link_info)
388            && link_info.combreloc
389            && link_info.relro
390            && (link_info.flags & DF_BIND_NOW))
391     {
392       if (link_info.separate_code)
393         return "ldscripts/${EMULATION_NAME}.xdwe";
394       else
395         return "ldscripts/${EMULATION_NAME}.xdw";
396     }
398 if test -n "$GENERATE_RELRO_SCRIPT" ; then
399 fragment <<EOF
400   else if (bfd_link_pie (&link_info)
401            && link_info.combreloc
402            && link_info.relro)
403     {
404       if (link_info.separate_code)
405         return "ldscripts/${EMULATION_NAME}.xdceo";
406       else
407         return "ldscripts/${EMULATION_NAME}.xdco";
408     }
411 fragment <<EOF
412   else if (bfd_link_pie (&link_info)
413            && link_info.combreloc)
414     {
415       if (link_info.separate_code)
416         return "ldscripts/${EMULATION_NAME}.xdce";
417       else
418         return "ldscripts/${EMULATION_NAME}.xdc";
419     }
422 if test -n "$GENERATE_RELRO_SCRIPT" ; then
423 fragment <<EOF
424   else if (bfd_link_pie (&link_info)
425            && link_info.relro)
426     {
427       if (link_info.separate_code)
428         return "ldscripts/${EMULATION_NAME}.xdeo";
429       else
430         return "ldscripts/${EMULATION_NAME}.xdo";
431     }
434 fragment <<EOF
435   else if (bfd_link_pie (&link_info))
436     {
437       if (link_info.separate_code)
438         return "ldscripts/${EMULATION_NAME}.xde";
439       else
440         return "ldscripts/${EMULATION_NAME}.xd";
441     }
444 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
445 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
446 fragment <<EOF
447   else if (bfd_link_dll (&link_info) && link_info.combreloc
448            && link_info.relro && (link_info.flags & DF_BIND_NOW))
449     {
450       if (link_info.separate_code)
451         return "ldscripts/${EMULATION_NAME}.xswe";
452       else
453         return "ldscripts/${EMULATION_NAME}.xsw";
454     }
456 if test -n "$GENERATE_RELRO_SCRIPT" ; then
457 fragment <<EOF
458   else if (bfd_link_dll (&link_info)
459            && link_info.combreloc
460            && link_info.relro)
461     {
462       if (link_info.separate_code)
463         return "ldscripts/${EMULATION_NAME}.xsceo";
464       else
465         return "ldscripts/${EMULATION_NAME}.xsco";
466     }
469 fragment <<EOF
470   else if (bfd_link_dll (&link_info) && link_info.combreloc)
471     {
472       if (link_info.separate_code)
473         return "ldscripts/${EMULATION_NAME}.xsce";
474       else
475         return "ldscripts/${EMULATION_NAME}.xsc";
476     }
479 if test -n "$GENERATE_RELRO_SCRIPT" ; then
480 fragment <<EOF
481   else if (bfd_link_dll (&link_info)
482            && link_info.relro)
483     {
484       if (link_info.separate_code)
485         return "ldscripts/${EMULATION_NAME}.xseo";
486       else
487         return "ldscripts/${EMULATION_NAME}.xso";
488     }
491 fragment <<EOF
492   else if (bfd_link_dll (&link_info))
493     {
494       if (link_info.separate_code)
495         return "ldscripts/${EMULATION_NAME}.xse";
496       else
497         return "ldscripts/${EMULATION_NAME}.xs";
498     }
501 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
502 fragment <<EOF
503   else if (link_info.combreloc && link_info.relro
504            && (link_info.flags & DF_BIND_NOW))
505     {
506       if (link_info.separate_code)
507         return "ldscripts/${EMULATION_NAME}.xwe";
508       else
509         return "ldscripts/${EMULATION_NAME}.xw";
510     }
512 if test -n "$GENERATE_RELRO_SCRIPT" ; then
513 fragment <<EOF
514   else if (link_info.combreloc
515            && link_info.relro)
516     {
517       if (link_info.separate_code)
518         return "ldscripts/${EMULATION_NAME}.xceo";
519       else
520         return "ldscripts/${EMULATION_NAME}.xco";
521     }
524 fragment <<EOF
525   else if (link_info.combreloc)
526     {
527       if (link_info.separate_code)
528         return "ldscripts/${EMULATION_NAME}.xce";
529       else
530         return "ldscripts/${EMULATION_NAME}.xc";
531     }
534 if test -n "$GENERATE_RELRO_SCRIPT" ; then
535 fragment <<EOF
536   else if (link_info.relro)
537     {
538       if (link_info.separate_code)
539         return "ldscripts/${EMULATION_NAME}.xeo";
540       else
541         return "ldscripts/${EMULATION_NAME}.xo";
542     }
545 fragment <<EOF
546   else
547     {
548       if (link_info.separate_code)
549         return "ldscripts/${EMULATION_NAME}.xe";
550       else
551         return "ldscripts/${EMULATION_NAME}.x";
552     }
559 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
560 fragment <<EOF
561  $PARSE_AND_LIST_PROLOGUE
565 fragment <<EOF
567 enum elf_options
569   OPTION_DISABLE_NEW_DTAGS = 400,
570   OPTION_ENABLE_NEW_DTAGS,
571   OPTION_GROUP,
572   OPTION_EH_FRAME_HDR,
573   OPTION_NO_EH_FRAME_HDR,
574   OPTION_EXCLUDE_LIBS,
575   OPTION_HASH_STYLE,
576   OPTION_BUILD_ID,
577   OPTION_PACKAGE_METADATA,
578   OPTION_AUDIT,
579   OPTION_COMPRESS_DEBUG
582 static void
583 gld${EMULATION_NAME}_add_options
584   (int ns, char **shortopts, int nl, struct option **longopts,
585    int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
588 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
589 fragment <<EOF
590   static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
592 else
593 fragment <<EOF
594   static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
597 fragment <<EOF
598   static const struct option xtra_long[] = {
600 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
601 fragment <<EOF
602     {"audit", required_argument, NULL, OPTION_AUDIT},
603     {"Bgroup", no_argument, NULL, OPTION_GROUP},
606 fragment <<EOF
607     {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
608     {"package-metadata", optional_argument, NULL, OPTION_PACKAGE_METADATA},
609     {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
611 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
612 fragment <<EOF
613     {"depaudit", required_argument, NULL, 'P'},
614     {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
615     {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
616     {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
617     {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
618     {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
619     {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
622 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
623 fragment <<EOF
624     $PARSE_AND_LIST_LONGOPTS
627 fragment <<EOF
628     {NULL, no_argument, NULL, 0}
629   };
631   *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
632   memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
633   *longopts = (struct option *)
634     xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
635   memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
638 #define DEFAULT_BUILD_ID_STYLE  "sha1"
640 static bool
641 gld${EMULATION_NAME}_handle_option (int optc)
643   switch (optc)
644     {
645     default:
646       return false;
648     case OPTION_BUILD_ID:
649       free ((char *) ldelf_emit_note_gnu_build_id);
650       ldelf_emit_note_gnu_build_id = NULL;
651       if (optarg == NULL)
652         optarg = DEFAULT_BUILD_ID_STYLE;
653       if (strcmp (optarg, "none"))
654         ldelf_emit_note_gnu_build_id = xstrdup (optarg);
655       break;
657     case OPTION_PACKAGE_METADATA:
658       free ((char *) ldelf_emit_note_fdo_package_metadata);
659       ldelf_emit_note_fdo_package_metadata = NULL;
660       if (optarg != NULL && strlen(optarg) > 0)
661         ldelf_emit_note_fdo_package_metadata = xstrdup (optarg);
662       break;
664     case OPTION_COMPRESS_DEBUG:
665       config.compress_debug = bfd_get_compression_algorithm (optarg);
666       if (strcasecmp (optarg, "zstd") == 0)
667         {
668 #ifndef HAVE_ZSTD
669           if (config.compress_debug == COMPRESS_DEBUG_ZSTD)
670             einfo (_ ("%F%P: --compress-debug-sections=zstd: ld is not built "
671                   "with zstd support\n"));
672 #endif
673         }
674       if (config.compress_debug == COMPRESS_UNKNOWN)
675         einfo (_("%F%P: invalid --compress-debug-sections option: \`%s'\n"),
676                optarg);
677       break;
680 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
681 fragment <<EOF
682     case OPTION_AUDIT:
683         ldelf_append_to_separated_string (&audit, optarg);
684         break;
686     case 'P':
687         ldelf_append_to_separated_string (&depaudit, optarg);
688         break;
690     case OPTION_DISABLE_NEW_DTAGS:
691       link_info.new_dtags = false;
692       break;
694     case OPTION_ENABLE_NEW_DTAGS:
695       link_info.new_dtags = true;
696       break;
698     case OPTION_EH_FRAME_HDR:
699       link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
700       break;
702     case OPTION_NO_EH_FRAME_HDR:
703       link_info.eh_frame_hdr_type = 0;
704       break;
706     case OPTION_GROUP:
707       link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
708       /* Groups must be self-contained.  */
709       link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
710       link_info.unresolved_syms_in_shared_libs = RM_DIAGNOSE;
711       break;
713     case OPTION_EXCLUDE_LIBS:
714       add_excluded_libs (optarg);
715       break;
717     case OPTION_HASH_STYLE:
718       link_info.emit_hash = false;
719       link_info.emit_gnu_hash = false;
720       if (strcmp (optarg, "sysv") == 0)
721         link_info.emit_hash = true;
722       else if (strcmp (optarg, "gnu") == 0)
723         link_info.emit_gnu_hash = true;
724       else if (strcmp (optarg, "both") == 0)
725         {
726           link_info.emit_hash = true;
727           link_info.emit_gnu_hash = true;
728         }
729       else
730         einfo (_("%F%P: invalid hash style \`%s'\n"), optarg);
731       break;
735 fragment <<EOF
736     case 'z':
737       if (strcmp (optarg, "defs") == 0)
738         link_info.unresolved_syms_in_objects = RM_DIAGNOSE;
739       else if (strcmp (optarg, "undefs") == 0)
740         link_info.unresolved_syms_in_objects = RM_IGNORE;
741       else if (strcmp (optarg, "muldefs") == 0)
742         link_info.allow_multiple_definition = true;
743       else if (startswith (optarg, "max-page-size="))
744         {
745           char *end;
747           link_info.maxpagesize = strtoul (optarg + 14, &end, 0);
748           if (*end
749               || (link_info.maxpagesize & (link_info.maxpagesize - 1)) != 0)
750             einfo (_("%F%P: invalid maximum page size \`%s'\n"),
751                    optarg + 14);
752           link_info.maxpagesize_is_set = true;
753         }
754       else if (startswith (optarg, "common-page-size="))
755         {
756           char *end;
757           link_info.commonpagesize = strtoul (optarg + 17, &end, 0);
758           if (*end
759               || (link_info.commonpagesize & (link_info.commonpagesize - 1)) != 0)
760             einfo (_("%F%P: invalid common page size \`%s'\n"),
761                    optarg + 17);
762           link_info.commonpagesize_is_set = true;
763         }
764       else if (startswith (optarg, "stack-size="))
765         {
766           char *end;
767           link_info.stacksize = strtoul (optarg + 11, &end, 0);
768           if (*end || link_info.stacksize < 0)
769             einfo (_("%F%P: invalid stack size \`%s'\n"), optarg + 11);
770           if (!link_info.stacksize)
771             /* Use -1 for explicit no-stack, because zero means
772                'default'.   */
773             link_info.stacksize = -1;
774         }
775       else if (strcmp (optarg, "execstack") == 0)
776         {
777           link_info.execstack = true;
778           link_info.noexecstack = false;
779         }
780       else if (strcmp (optarg, "noexecstack") == 0)
781         {
782           link_info.noexecstack = true;
783           link_info.execstack = false;
784         }
785       else if (strcmp (optarg, "unique-symbol") == 0)
786         link_info.unique_symbol = true;
787       else if (strcmp (optarg, "nounique-symbol") == 0)
788         link_info.unique_symbol = false;
789       else if (strcmp (optarg, "globalaudit") == 0)
790         {
791           link_info.flags_1 |= DF_1_GLOBAUDIT;
792         }
793       else if (startswith (optarg, "start-stop-gc"))
794         link_info.start_stop_gc = true;
795       else if (startswith (optarg, "nostart-stop-gc"))
796         link_info.start_stop_gc = false;
797       else if (startswith (optarg, "start-stop-visibility="))
798         {
799           if (strcmp (optarg, "start-stop-visibility=default") == 0)
800             link_info.start_stop_visibility = STV_DEFAULT;
801           else if (strcmp (optarg, "start-stop-visibility=internal") == 0)
802             link_info.start_stop_visibility = STV_INTERNAL;
803           else if (strcmp (optarg, "start-stop-visibility=hidden") == 0)
804             link_info.start_stop_visibility = STV_HIDDEN;
805           else if (strcmp (optarg, "start-stop-visibility=protected") == 0)
806             link_info.start_stop_visibility = STV_PROTECTED;
807           else
808             einfo (_("%F%P: invalid visibility in \`-z %s'; "
809                      "must be default, internal, hidden, or protected"),
810                    optarg);
811         }
812       else if (strcmp (optarg, "sectionheader") == 0)
813         config.no_section_header = false;
814       else if (strcmp (optarg, "nosectionheader") == 0)
815         config.no_section_header = true;
818 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
819 fragment <<EOF
820       else if (strcmp (optarg, "global") == 0)
821         link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
822       else if (strcmp (optarg, "initfirst") == 0)
823         link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
824       else if (strcmp (optarg, "interpose") == 0)
825         link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
826       else if (strcmp (optarg, "loadfltr") == 0)
827         link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
828       else if (strcmp (optarg, "nodefaultlib") == 0)
829         link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
830       else if (strcmp (optarg, "nodelete") == 0)
831         link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
832       else if (strcmp (optarg, "nodlopen") == 0)
833         link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
834       else if (strcmp (optarg, "nodump") == 0)
835         link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
836       else if (strcmp (optarg, "now") == 0)
837         {
838           link_info.flags |= (bfd_vma) DF_BIND_NOW;
839           link_info.flags_1 |= (bfd_vma) DF_1_NOW;
840         }
841       else if (strcmp (optarg, "lazy") == 0)
842         {
843           link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
844           link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
845         }
846       else if (strcmp (optarg, "origin") == 0)
847         {
848           link_info.flags |= (bfd_vma) DF_ORIGIN;
849           link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
850         }
851       else if (strcmp (optarg, "unique") == 0)
852         link_info.gnu_flags_1 |= (bfd_vma) DF_GNU_1_UNIQUE;
853       else if (strcmp (optarg, "nounique") == 0)
854         link_info.gnu_flags_1 &= ~(bfd_vma) DF_GNU_1_UNIQUE;
855       else if (strcmp (optarg, "combreloc") == 0)
856         link_info.combreloc = true;
857       else if (strcmp (optarg, "nocombreloc") == 0)
858         link_info.combreloc = false;
859       else if (strcmp (optarg, "nocopyreloc") == 0)
860         link_info.nocopyreloc = true;
862 if test -n "$COMMONPAGESIZE"; then
863 fragment <<EOF
864       else if (strcmp (optarg, "relro") == 0)
865         link_info.relro = true;
866       else if (strcmp (optarg, "norelro") == 0)
867         link_info.relro = false;
870 fragment <<EOF
871       else if (strcmp (optarg, "separate-code") == 0)
872         link_info.separate_code = true;
873       else if (strcmp (optarg, "noseparate-code") == 0)
874         link_info.separate_code = false;
875       else if (strcmp (optarg, "common") == 0)
876         link_info.elf_stt_common = elf_stt_common;
877       else if (strcmp (optarg, "nocommon") == 0)
878         link_info.elf_stt_common = no_elf_stt_common;
879       else if (strcmp (optarg, "text") == 0)
880         link_info.textrel_check = textrel_check_error;
881       else if (strcmp (optarg, "notext") == 0)
882         link_info.textrel_check = textrel_check_none;
883       else if (strcmp (optarg, "textoff") == 0)
884         link_info.textrel_check = textrel_check_none;
888 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
889 fragment <<EOF
890  $PARSE_AND_LIST_ARGS_CASE_Z
894 fragment <<EOF
895       else
896         einfo (_("%P: warning: -z %s ignored\n"), optarg);
897       break;
900 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
901 fragment <<EOF
902  $PARSE_AND_LIST_ARGS_CASES
906 fragment <<EOF
907     }
909   return true;
914 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
915 gld_list_options="gld${EMULATION_NAME}_list_options"
916 if test -n "$PARSE_AND_LIST_OPTIONS"; then
917 fragment <<EOF
919 static void
920 gld${EMULATION_NAME}_list_options (FILE * file)
924 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
925 fragment <<EOF
926  $PARSE_AND_LIST_OPTIONS
930 fragment <<EOF
933 else
934   gld_list_options="NULL"
937 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
938 fragment <<EOF
939  $PARSE_AND_LIST_EPILOGUE
944 LDEMUL_AFTER_PARSE=${LDEMUL_AFTER_PARSE-ldelf_after_parse}
945 LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=${LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ-gld${EMULATION_NAME}_before_plugin_all_symbols_read}
946 LDEMUL_AFTER_OPEN=${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}
947 LDEMUL_BEFORE_PLACE_ORPHANS=${LDEMUL_BEFORE_PLACE_ORPHANS-ldelf_before_place_orphans}
948 LDEMUL_AFTER_ALLOCATION=${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation}
949 LDEMUL_SET_OUTPUT_ARCH=${LDEMUL_SET_OUTPUT_ARCH-ldelf_set_output_arch}
950 LDEMUL_BEFORE_ALLOCATION=${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}
951 LDEMUL_OPEN_DYNAMIC_ARCHIVE=${LDEMUL_OPEN_DYNAMIC_ARCHIVE-ldelf_open_dynamic_archive}
952 LDEMUL_PLACE_ORPHAN=${LDEMUL_PLACE_ORPHAN-ldelf_place_orphan}
953 LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
954 LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
955 LDEMUL_LIST_OPTIONS=${LDEMUL_LIST_OPTIONS-${gld_list_options}}
956 LDEMUL_RECOGNIZED_FILE=${LDEMUL_RECOGNIZED_FILE-ldelf_load_symbols}
958 source_em ${srcdir}/emultempl/emulation.em