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