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