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