Stop the v850 linker from converting to other output formats whilst linking.
[deliverable/binutils-gdb.git] / ld / emultempl / elf32.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3# This file is now misnamed, because it supports both 32 bit and 64 bit
4# ELF emulations.
5test -z "${ELFSIZE}" && ELFSIZE=32
86af25fe
L
6if [ -z "$MACHINE" ]; then
7 OUTPUT_ARCH=${ARCH}
8else
9 OUTPUT_ARCH=${ARCH}:${MACHINE}
10fi
92b93329 11fragment <<EOF
252b5132
RH
12/* This file is is generated by a shell script. DO NOT EDIT! */
13
14/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
2571583a 15 Copyright (C) 1991-2017 Free Software Foundation, Inc.
252b5132
RH
16 Written by Steve Chamberlain <sac@cygnus.com>
17 ELF support by Ian Lance Taylor <ian@cygnus.com>
18
f96b4a7b
NC
19 This file is part of the GNU Binutils.
20
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 3 of the License, or
24 (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
34 MA 02110-1301, USA. */
252b5132
RH
35
36#define TARGET_IS_${EMULATION_NAME}
37
252b5132 38#include "sysdep.h"
3db64b00 39#include "bfd.h"
1c9acd94 40#include "libiberty.h"
8056826a 41#include "safe-ctype.h"
42627821 42#include "filenames.h"
fcf65871 43#include "getopt.h"
24382dca 44#include <fcntl.h>
252b5132
RH
45
46#include "bfdlink.h"
47
48#include "ld.h"
49#include "ldmain.h"
252b5132
RH
50#include "ldmisc.h"
51#include "ldexp.h"
52#include "ldlang.h"
b71e2778
AM
53#include "ldfile.h"
54#include "ldemul.h"
61e2488c 55#include "ldbuildid.h"
df2a7313 56#include <ldgram.h>
e0ee487b 57#include "elf/common.h"
ecca9871 58#include "elf-bfd.h"
07f1e47a 59#include "filenames.h"
252b5132 60
0c7a8e5a
AM
61/* Declare functions used by various EXTRA_EM_FILEs. */
62static void gld${EMULATION_NAME}_before_parse (void);
5fe2850d 63static void gld${EMULATION_NAME}_after_parse (void);
0c7a8e5a
AM
64static void gld${EMULATION_NAME}_after_open (void);
65static void gld${EMULATION_NAME}_before_allocation (void);
eaeb0a9d 66static void gld${EMULATION_NAME}_after_allocation (void);
c2edb4b8 67static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
8a99a385 68 (asection *, const char *, int);
41392f03
AM
69EOF
70
d3989512
JJ
71if [ "x${USE_LIBPATH}" = xyes ] ; then
72 case ${target} in
a5244b7e 73 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
92b93329 74 fragment <<EOF
0b48acfe 75#ifdef HAVE_GLOB
d3989512 76#include <glob.h>
0b48acfe 77#endif
d3989512
JJ
78EOF
79 ;;
80 esac
81fi
82
41392f03
AM
83# Import any needed special functions and/or overrides.
84#
92b93329 85source_em ${srcdir}/emultempl/elf-generic.em
41392f03 86if test -n "$EXTRA_EM_FILE" ; then
92b93329 87 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
41392f03
AM
88fi
89
f813923c 90# Functions in this file can be overridden by setting the LDEMUL_* shell
41392f03
AM
91# variables. If the name of the overriding function is the same as is
92# defined in this file, then don't output this file's version.
93# If a different overriding name is given then output the standard function
94# as presumably it is called from the overriding function.
95#
96if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
92b93329 97fragment <<EOF
41392f03 98
252b5132 99static void
0c7a8e5a 100gld${EMULATION_NAME}_before_parse (void)
252b5132 101{
5e2f1575 102 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
66be1055 103 input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
b34976b6 104 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
4724d37e 105 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
caa65211 106 `if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`;
5c3261b0 107 link_info.check_relocs_after_open_input = TRUE;
647e4d46 108 link_info.relro = DEFAULT_LD_Z_RELRO;
663fa543
L
109}
110
822b8bf4 111EOF
663fa543 112fi
822b8bf4 113
5fe2850d
L
114if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
115fragment <<EOF
116
117static void
118gld${EMULATION_NAME}_after_parse (void)
119{
120 if (bfd_link_pie (&link_info))
121 link_info.flags_1 |= (bfd_vma) DF_1_PIE;
122
22b1ee18
AM
123 if (bfd_link_executable (&link_info)
124 && link_info.nointerp)
125 {
126 if (link_info.dynamic_undefined_weak > 0)
127 einfo (_("%P: warning: -z dynamic-undefined-weak ignored\n"));
128 link_info.dynamic_undefined_weak = 0;
129 }
5fe2850d
L
130 after_parse_default ();
131}
132
133EOF
134fi
135
4a43e768 136if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
92b93329 137fragment <<EOF
ddbb8a31 138/* Handle the generation of DT_NEEDED tags. */
4a43e768
AM
139
140static bfd_boolean
141gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
142{
96d56e9f 143 int link_class = 0;
4a43e768
AM
144
145 /* Tell the ELF linker that we don't want the output file to have a
146 DT_NEEDED entry for this file, unless it is used to resolve
147 references in a regular object. */
66be1055 148 if (entry->flags.add_DT_NEEDED_for_regular)
96d56e9f 149 link_class = DYN_AS_NEEDED;
e56f61be
L
150
151 /* Tell the ELF linker that we don't want the output file to have a
152 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
153 this file at all. */
66be1055 154 if (!entry->flags.add_DT_NEEDED_for_dynamic)
96d56e9f 155 link_class |= DYN_NO_ADD_NEEDED;
e56f61be 156
66be1055 157 if (entry->flags.just_syms
12b9ff6c
L
158 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
159 einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
160 entry->the_bfd);
161
ddbb8a31 162 if (link_class == 0
e56f61be
L
163 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
164 return FALSE;
165
1e9cc1c2 166 bfd_elf_set_dyn_lib_class (entry->the_bfd,
4724d37e 167 (enum dynamic_lib_link_class) link_class);
4a43e768
AM
168
169 /* Continue on with normal load_symbols processing. */
170 return FALSE;
171}
172EOF
173fi
174
92b93329 175fragment <<EOF
252b5132
RH
176
177/* These variables are required to pass information back and forth
178 between after_open and check_needed and stat_needed and vercheck. */
179
180static struct bfd_link_needed_list *global_needed;
181static struct stat global_stat;
e13629bc 182static lang_input_statement_type *global_found;
252b5132 183static struct bfd_link_needed_list *global_vercheck_needed;
b34976b6 184static bfd_boolean global_vercheck_failed;
252b5132 185
7ee314fa
AM
186/* These variables are used to implement target options */
187
188static char *audit; /* colon (typically) separated list of libs */
189static char *depaudit; /* colon (typically) separated list of libs */
252b5132 190
30e8ee25
AM
191/* Style of .note.gnu.build-id section. */
192static const char *emit_note_gnu_build_id;
193
04925e1e
AM
194/* On Linux, it's possible to have different versions of the same
195 shared library linked against different versions of libc. The
196 dynamic linker somehow tags which libc version to use in
197 /etc/ld.so.cache, and, based on the libc that it sees in the
198 executable, chooses which version of the shared library to use.
252b5132 199
04925e1e
AM
200 We try to do a similar check here by checking whether this shared
201 library needs any other shared libraries which may conflict with
202 libraries we have already included in the link. If it does, we
203 skip it, and try to find another shared library farther on down the
204 link path.
252b5132 205
04925e1e
AM
206 This is called via lang_for_each_input_file.
207 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
f813923c 208 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
04925e1e 209 a conflicting version. */
252b5132 210
04925e1e 211static void
0c7a8e5a 212gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
04925e1e 213{
1c9acd94 214 const char *soname;
04925e1e 215 struct bfd_link_needed_list *l;
252b5132 216
04925e1e
AM
217 if (global_vercheck_failed)
218 return;
219 if (s->the_bfd == NULL
220 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
221 return;
252b5132 222
04925e1e
AM
223 soname = bfd_elf_get_dt_soname (s->the_bfd);
224 if (soname == NULL)
fed2999d 225 soname = lbasename (bfd_get_filename (s->the_bfd));
04925e1e
AM
226
227 for (l = global_vercheck_needed; l != NULL; l = l->next)
228 {
229 const char *suffix;
230
42627821 231 if (filename_cmp (soname, l->name) == 0)
04925e1e
AM
232 {
233 /* Probably can't happen, but it's an easy check. */
234 continue;
252b5132
RH
235 }
236
04925e1e 237 if (strchr (l->name, '/') != NULL)
252b5132
RH
238 continue;
239
04925e1e
AM
240 suffix = strstr (l->name, ".so.");
241 if (suffix == NULL)
242 continue;
243
244 suffix += sizeof ".so." - 1;
245
42627821 246 if (filename_ncmp (soname, l->name, suffix - l->name) == 0)
04925e1e
AM
247 {
248 /* Here we know that S is a dynamic object FOO.SO.VER1, and
0c7a8e5a
AM
249 the object we are considering needs a dynamic object
250 FOO.SO.VER2, and VER1 and VER2 are different. This
251 appears to be a version mismatch, so we tell the caller
252 to try a different version of this library. */
b34976b6 253 global_vercheck_failed = TRUE;
04925e1e
AM
254 return;
255 }
252b5132
RH
256 }
257}
258
252b5132 259
04925e1e
AM
260/* See if an input file matches a DT_NEEDED entry by running stat on
261 the file. */
262
263static void
0c7a8e5a 264gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
252b5132 265{
04925e1e
AM
266 struct stat st;
267 const char *suffix;
268 const char *soname;
252b5132 269
e13629bc 270 if (global_found != NULL)
04925e1e
AM
271 return;
272 if (s->the_bfd == NULL)
273 return;
e13629bc
AM
274
275 /* If this input file was an as-needed entry, and wasn't found to be
276 needed at the stage it was linked, then don't say we have loaded it. */
277 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
7cedef86 278 return;
04925e1e
AM
279
280 if (bfd_stat (s->the_bfd, &st) != 0)
252b5132 281 {
d003af55 282 einfo (_("%P:%B: bfd_stat failed: %E\n"), s->the_bfd);
04925e1e
AM
283 return;
284 }
252b5132 285
9eabd475
ZW
286 /* Some operating systems, e.g. Windows, do not provide a meaningful
287 st_ino; they always set it to zero. (Windows does provide a
288 meaningful st_dev.) Do not indicate a duplicate library in that
289 case. While there is no guarantee that a system that provides
290 meaningful inode numbers will never set st_ino to zero, this is
291 merely an optimization, so we do not need to worry about false
292 negatives. */
04925e1e 293 if (st.st_dev == global_stat.st_dev
9eabd475
ZW
294 && st.st_ino == global_stat.st_ino
295 && st.st_ino != 0)
04925e1e 296 {
e13629bc 297 global_found = s;
04925e1e
AM
298 return;
299 }
252b5132 300
04925e1e
AM
301 /* We issue a warning if it looks like we are including two
302 different versions of the same shared library. For example,
303 there may be a problem if -lc picks up libc.so.6 but some other
304 shared library has a DT_NEEDED entry of libc.so.5. This is a
f813923c 305 heuristic test, and it will only work if the name looks like
04925e1e
AM
306 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
307 If we really want to issue warnings about mixing version numbers
308 of shared libraries, we need to find a better way. */
252b5132 309
04925e1e
AM
310 if (strchr (global_needed->name, '/') != NULL)
311 return;
312 suffix = strstr (global_needed->name, ".so.");
313 if (suffix == NULL)
314 return;
315 suffix += sizeof ".so." - 1;
252b5132 316
04925e1e
AM
317 soname = bfd_elf_get_dt_soname (s->the_bfd);
318 if (soname == NULL)
fed2999d 319 soname = lbasename (s->filename);
252b5132 320
42627821 321 if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
d003af55 322 einfo (_("%P: warning: %s, needed by %B, may conflict with %s\n"),
1c9acd94 323 global_needed->name, global_needed->by, soname);
252b5132
RH
324}
325
e56f61be
L
326struct dt_needed
327{
328 bfd *by;
329 const char *name;
330};
04925e1e 331
252b5132
RH
332/* This function is called for each possible name for a dynamic object
333 named by a DT_NEEDED entry. The FORCE parameter indicates whether
334 to skip the check for a conflicting version. */
335
b34976b6 336static bfd_boolean
e56f61be
L
337gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
338 int force)
252b5132
RH
339{
340 bfd *abfd;
e56f61be 341 const char *name = needed->name;
ec4eb78a 342 const char *soname;
96d56e9f 343 int link_class;
252b5132 344
f13a99db 345 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
252b5132 346 if (abfd == NULL)
0ec22c2c
NC
347 {
348 if (verbose)
349 info_msg (_("attempt to open %s failed\n"), name);
350 return FALSE;
351 }
4a114e3e
L
352
353 /* Linker needs to decompress sections. */
354 abfd->flags |= BFD_DECOMPRESS;
355
252b5132
RH
356 if (! bfd_check_format (abfd, bfd_object))
357 {
cde43e70 358 bfd_close (abfd);
b34976b6 359 return FALSE;
252b5132
RH
360 }
361 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
362 {
cde43e70 363 bfd_close (abfd);
b34976b6 364 return FALSE;
252b5132
RH
365 }
366
c4bb8067 367 /* For DT_NEEDED, they have to match. */
f13a99db 368 if (abfd->xvec != link_info.output_bfd->xvec)
c4bb8067
L
369 {
370 bfd_close (abfd);
b34976b6 371 return FALSE;
c4bb8067
L
372 }
373
252b5132
RH
374 /* Check whether this object would include any conflicting library
375 versions. If FORCE is set, then we skip this check; we use this
376 the second time around, if we couldn't find any compatible
377 instance of the shared library. */
378
379 if (! force)
380 {
91d6fa6a 381 struct bfd_link_needed_list *needs;
252b5132 382
91d6fa6a 383 if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
d003af55 384 einfo (_("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n"), abfd);
252b5132 385
91d6fa6a 386 if (needs != NULL)
252b5132 387 {
91d6fa6a 388 global_vercheck_needed = needs;
b34976b6 389 global_vercheck_failed = FALSE;
252b5132
RH
390 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
391 if (global_vercheck_failed)
392 {
cde43e70 393 bfd_close (abfd);
b34976b6 394 /* Return FALSE to force the caller to move on to try
0c7a8e5a 395 another file on the search path. */
b34976b6 396 return FALSE;
252b5132
RH
397 }
398
399 /* But wait! It gets much worse. On Linux, if a shared
0c7a8e5a
AM
400 library does not use libc at all, we are supposed to skip
401 it the first time around in case we encounter a shared
402 library later on with the same name which does use the
403 version of libc that we want. This is much too horrible
404 to use on any system other than Linux. */
252b5132
RH
405
406EOF
407case ${target} in
a5244b7e 408 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
92b93329 409 fragment <<EOF
252b5132
RH
410 {
411 struct bfd_link_needed_list *l;
412
91d6fa6a 413 for (l = needs; l != NULL; l = l->next)
0112cd26 414 if (CONST_STRNEQ (l->name, "libc.so"))
252b5132
RH
415 break;
416 if (l == NULL)
417 {
cde43e70 418 bfd_close (abfd);
b34976b6 419 return FALSE;
252b5132
RH
420 }
421 }
422
423EOF
424 ;;
425esac
92b93329 426fragment <<EOF
252b5132
RH
427 }
428 }
429
430 /* We've found a dynamic object matching the DT_NEEDED entry. */
431
04925e1e
AM
432 /* We have already checked that there is no other input file of the
433 same name. We must now check again that we are not including the
434 same file twice. We need to do this because on many systems
435 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
436 reference libc.so.1. If we have already included libc.so, we
437 don't want to include libc.so.1 if they are the same file, and we
438 can only check that using stat. */
439
440 if (bfd_stat (abfd, &global_stat) != 0)
d003af55 441 einfo (_("%F%P:%B: bfd_stat failed: %E\n"), abfd);
ec4eb78a
L
442
443 /* First strip off everything before the last '/'. */
fed2999d 444 soname = lbasename (abfd->filename);
ec4eb78a 445
cd6f1cf3 446 if (verbose)
ec4eb78a
L
447 info_msg (_("found %s at %s\n"), soname, name);
448
e13629bc 449 global_found = NULL;
04925e1e 450 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
e13629bc 451 if (global_found != NULL)
04925e1e 452 {
b34976b6 453 /* Return TRUE to indicate that we found the file, even though
0c7a8e5a 454 we aren't going to do anything with it. */
b34976b6 455 return TRUE;
04925e1e
AM
456 }
457
4a43e768
AM
458 /* Specify the soname to use. */
459 bfd_elf_set_dt_needed_name (abfd, soname);
04925e1e 460
4a43e768
AM
461 /* Tell the ELF linker that we don't want the output file to have a
462 DT_NEEDED entry for this file, unless it is used to resolve
463 references in a regular object. */
96d56e9f 464 link_class = DYN_DT_NEEDED;
e56f61be
L
465
466 /* Tell the ELF linker that we don't want the output file to have a
467 DT_NEEDED entry for this file at all if the entry is from a file
468 with DYN_NO_ADD_NEEDED. */
7e9f0867
AM
469 if (needed->by != NULL
470 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
96d56e9f 471 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
e56f61be 472
1e9cc1c2 473 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
04925e1e
AM
474
475 /* Add this file into the symbol table. */
476 if (! bfd_link_add_symbols (abfd, &link_info))
d003af55 477 einfo (_("%F%B: error adding symbols: %E\n"), abfd);
04925e1e 478
b34976b6 479 return TRUE;
04925e1e
AM
480}
481
04925e1e
AM
482/* Search for a needed file in a path. */
483
b34976b6 484static bfd_boolean
e56f61be
L
485gld${EMULATION_NAME}_search_needed (const char *path,
486 struct dt_needed *n, int force)
04925e1e
AM
487{
488 const char *s;
e56f61be 489 const char *name = n->name;
04925e1e 490 size_t len;
e56f61be 491 struct dt_needed needed;
04925e1e 492
cc5ce052 493 if (name[0] == '/')
e56f61be 494 return gld${EMULATION_NAME}_try_needed (n, force);
cc5ce052 495
04925e1e 496 if (path == NULL || *path == '\0')
b34976b6 497 return FALSE;
e56f61be
L
498
499 needed.by = n->by;
500 needed.name = n->name;
501
04925e1e
AM
502 len = strlen (name);
503 while (1)
504 {
e680a6b6 505 unsigned offset = 0;
199fa1b7 506 char * var;
04925e1e
AM
507 char *filename, *sset;
508
c76308d2 509 s = strchr (path, config.rpath_separator);
04925e1e
AM
510 if (s == NULL)
511 s = path + strlen (path);
512
07f1e47a
AM
513#if HAVE_DOS_BASED_FILE_SYSTEM
514 /* Assume a match on the second char is part of drive specifier. */
515 else if (config.rpath_separator == ':'
516 && s == path + 1
517 && ISALPHA (*path))
518 {
519 s = strchr (s + 1, config.rpath_separator);
520 if (s == NULL)
521 s = path + strlen (path);
522 }
523#endif
04925e1e
AM
524 filename = (char *) xmalloc (s - path + len + 2);
525 if (s == path)
526 sset = filename;
527 else
528 {
529 memcpy (filename, path, s - path);
530 filename[s - path] = '/';
531 sset = filename + (s - path) + 1;
532 }
533 strcpy (sset, name);
534
199fa1b7
NC
535 /* PR 20535: Support the same pseudo-environment variables that
536 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
559192d8 537 Since there can be more than one occurrence of these tokens in
e680a6b6
NC
538 the path we loop until no more are found. Since we might not
539 be able to substitute some of the tokens we maintain an offset
540 into the filename for where we should begin our scan. */
541 while ((var = strchr (filename + offset, '$')) != NULL)
199fa1b7
NC
542 {
543 /* The ld.so manual page does not say, but I am going to assume that
839b0b3f 544 these tokens are terminated by a directory separator character
199fa1b7
NC
545 (/) or the end of the string. There is also an implication that
546 $ORIGIN should only be used at the start of a path, but that is
547 not enforced here.
548
e680a6b6
NC
549 The ld.so manual page also states that it allows ${ORIGIN},
550 ${LIB} and ${PLATFORM}, so these are supported as well.
199fa1b7
NC
551
552 FIXME: The code could be a lot cleverer about allocating space
553 for the processed string. */
554 char * end = strchr (var, '/');
555 char * replacement = NULL;
e680a6b6 556 char * v = var + 1;
199fa1b7
NC
557 char * freeme = NULL;
558 unsigned flen = strlen (filename);
559
560 if (end != NULL)
561 /* Temporarily terminate the filename at the end of the token. */
562 * end = 0;
563
e680a6b6
NC
564 if (*v == '{')
565 ++ v;
566 switch (*v++)
199fa1b7
NC
567 {
568 case 'O':
e680a6b6 569 if (strcmp (v, "RIGIN") == 0 || strcmp (v, "RIGIN}") == 0)
199fa1b7
NC
570 {
571 /* ORIGIN - replace with the full path to the directory
572 containing the program or shared object. */
573 if (needed.by == NULL)
e680a6b6
NC
574 {
575 if (link_info.output_bfd == NULL)
576 {
577 break;
578 }
579 else
580 replacement = bfd_get_filename (link_info.output_bfd);
581 }
582 else
583 replacement = bfd_get_filename (needed.by);
584
199fa1b7
NC
585 if (replacement)
586 {
587 char * slash;
588
589 if (replacement[0] == '/')
590 freeme = xstrdup (replacement);
591 else
592 {
593 char * current_dir = getpwd ();
594
51750acd 595 freeme = xmalloc (strlen (replacement) + strlen (current_dir) + 2);
199fa1b7
NC
596 sprintf (freeme, "%s/%s", current_dir, replacement);
597 }
598
599 replacement = freeme;
600 if ((slash = strrchr (replacement, '/')) != NULL)
601 * slash = 0;
602 }
603 }
604 break;
605
606 case 'L':
e680a6b6 607 if (strcmp (v, "IB") == 0 || strcmp (v, "IB}") == 0)
199fa1b7
NC
608 {
609 /* LIB - replace with "lib" in 32-bit environments
610 and "lib64" in 64-bit environments. */
611
612 /* Note - we could replace this switch statement by
613 conditional fragments of shell script, but that is messy.
614 Any compiler worth its salt is going to optimize away
615 all but one of these case statements anyway. */
616 switch ($ELFSIZE)
617 {
618 case 32: replacement = "lib"; break;
619 case 64: replacement = "lib64"; break;
620 default:
621 /* $ELFSIZE is not 32 or 64 ... */
622 abort ();
623 }
624 }
625 break;
626
627 case 'P':
e680a6b6
NC
628 /* Supporting $PLATFORM in a cross-hosted environment is not
629 possible. Supporting it in a native environment involves
630 loading the <sys/auxv.h> header file which loads the
631 system <elf.h> header file, which conflicts with the
632 "include/elf/mips.h" header file. */
633 /* Fall through. */
199fa1b7
NC
634 default:
635 break;
636 }
637
638 if (replacement)
639 {
640 char * filename2 = xmalloc (flen + strlen (replacement));
641
642 if (end)
e680a6b6
NC
643 {
644 sprintf (filename2, "%.*s%s/%s",
645 (int)(var - filename), filename,
646 replacement, end + 1);
647 offset = (var - filename) + 1 + strlen (replacement);
648 }
199fa1b7 649 else
e680a6b6
NC
650 {
651 sprintf (filename2, "%.*s%s",
652 (int)(var - filename), filename,
653 replacement);
654 offset = var - filename + strlen (replacement);
655 }
656
199fa1b7
NC
657 free (filename);
658 filename = filename2;
659 /* There is no need to restore the path separator (when
660 end != NULL) as we have replaced the entire string. */
661 }
662 else
663 {
664 if (verbose)
665 /* We only issue an "unrecognised" message in verbose mode
666 as the $<foo> token might be a legitimate component of
667 a path name in the target's file system. */
88ba72a2 668 info_msg (_("unrecognised or unsupported token '%s' in search path\n"), var);
199fa1b7
NC
669
670 if (end)
671 /* Restore the path separator. */
672 * end = '/';
e680a6b6 673
559192d8
AM
674 /* PR 20784: Make sure that we resume the scan *after*
675 the token that we could not replace. */
e680a6b6 676 offset = (var + 1) - filename;
199fa1b7
NC
677 }
678
679 free (freeme);
680 }
681
e56f61be 682 needed.name = filename;
e680a6b6 683
e56f61be 684 if (gld${EMULATION_NAME}_try_needed (&needed, force))
b34976b6 685 return TRUE;
04925e1e
AM
686
687 free (filename);
688
689 if (*s == '\0')
690 break;
691 path = s + 1;
692 }
693
b34976b6 694 return FALSE;
04925e1e
AM
695}
696
697EOF
9c8ebd6a 698if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 699 fragment <<EOF
9c8ebd6a 700
316a1245
AM
701/* Prefix the sysroot to absolute paths in PATH, a string containing
702 paths separated by config.rpath_separator. If running on a DOS
703 file system, paths containing a drive spec won't have the sysroot
704 prefix added, unless the sysroot also specifies the same drive. */
9c8ebd6a 705
316a1245 706static const char *
0c7a8e5a 707gld${EMULATION_NAME}_add_sysroot (const char *path)
9c8ebd6a 708{
316a1245
AM
709 size_t len, extra;
710 const char *p;
711 char *ret, *q;
712 int dos_drive_sysroot = HAS_DRIVE_SPEC (ld_sysroot);
713
714 len = strlen (ld_sysroot);
715 for (extra = 0, p = path; ; )
716 {
717 int dos_drive = HAS_DRIVE_SPEC (p);
718
719 if (dos_drive)
720 p += 2;
721 if (IS_DIR_SEPARATOR (*p)
722 && (!dos_drive
723 || (dos_drive_sysroot
724 && ld_sysroot[0] == p[-2])))
725 {
726 if (dos_drive && dos_drive_sysroot)
727 extra += len - 2;
728 else
729 extra += len;
730 }
731 p = strchr (p, config.rpath_separator);
732 if (!p)
733 break;
734 ++p;
735 }
736
737 ret = xmalloc (strlen (path) + extra + 1);
738
739 for (q = ret, p = path; ; )
740 {
741 const char *end;
742 int dos_drive = HAS_DRIVE_SPEC (p);
743
744 if (dos_drive)
745 {
746 *q++ = *p++;
747 *q++ = *p++;
748 }
749 if (IS_DIR_SEPARATOR (*p)
750 && (!dos_drive
751 || (dos_drive_sysroot
752 && ld_sysroot[0] == p[-2])))
753 {
754 if (dos_drive && dos_drive_sysroot)
755 {
756 strcpy (q, ld_sysroot + 2);
757 q += len - 2;
758 }
759 else
760 {
761 strcpy (q, ld_sysroot);
762 q += len;
763 }
764 }
765 end = strchr (p, config.rpath_separator);
766 if (end)
767 {
768 size_t n = end - p + 1;
769 strncpy (q, p, n);
770 q += n;
771 p += n;
772 }
773 else
774 {
775 strcpy (q, p);
776 break;
777 }
778 }
779
9c8ebd6a
DJ
780 return ret;
781}
04925e1e 782
3dc16cab
DJ
783EOF
784 case ${target} in
ebe1fac1 785 *-*-freebsd* | *-*-dragonfly*)
92b93329 786 fragment <<EOF
ebe1fac1
NC
787/* Read the system search path the FreeBSD way rather than the Linux way. */
788#ifdef HAVE_ELF_HINTS_H
789#include <elf-hints.h>
790#else
791#include "elf-hints-local.h"
792#endif
793
794static bfd_boolean
d5c8b1f8
AM
795gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
796 int force)
ebe1fac1
NC
797{
798 static bfd_boolean initialized;
316a1245 799 static const char *ld_elf_hints;
ebe1fac1
NC
800 struct dt_needed needed;
801
802 if (!initialized)
803 {
804 FILE *f;
805 char *tmppath;
806
ff7a0acf 807 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
ebe1fac1
NC
808 f = fopen (tmppath, FOPEN_RB);
809 free (tmppath);
810 if (f != NULL)
811 {
812 struct elfhints_hdr hdr;
813
814 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
815 && hdr.magic == ELFHINTS_MAGIC
816 && hdr.version == 1)
817 {
818 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
819 {
820 char *b;
821
822 b = xmalloc (hdr.dirlistlen + 1);
823 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
824 hdr.dirlistlen + 1)
825 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
e13629bc 826
ebe1fac1
NC
827 free (b);
828 }
829 }
830 fclose (f);
831 }
832
833 initialized = TRUE;
834 }
835
836 if (ld_elf_hints == NULL)
837 return FALSE;
838
d5c8b1f8
AM
839 needed.by = l->by;
840 needed.name = l->name;
841 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
ebe1fac1
NC
842}
843EOF
844 # FreeBSD
845 ;;
846
a5244b7e 847 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
92b93329 848 fragment <<EOF
04925e1e
AM
849/* For a native linker, check the file /etc/ld.so.conf for directories
850 in which we may find shared libraries. /etc/ld.so.conf is really
482e8b32 851 only meaningful on Linux. */
04925e1e 852
d3989512 853struct gld${EMULATION_NAME}_ld_so_conf
04925e1e 854{
d3989512
JJ
855 char *path;
856 size_t len, alloc;
857};
04925e1e 858
dfcffada 859static bfd_boolean
d3989512
JJ
860gld${EMULATION_NAME}_parse_ld_so_conf
861 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
862
863static void
864gld${EMULATION_NAME}_parse_ld_so_conf_include
865 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
866 const char *pattern)
867{
868 char *newp = NULL;
0b48acfe 869#ifdef HAVE_GLOB
d3989512 870 glob_t gl;
0b48acfe 871#endif
d3989512
JJ
872
873 if (pattern[0] != '/')
04925e1e 874 {
d3989512
JJ
875 char *p = strrchr (filename, '/');
876 size_t patlen = strlen (pattern) + 1;
04925e1e 877
d3989512
JJ
878 newp = xmalloc (p - filename + 1 + patlen);
879 memcpy (newp, filename, p - filename + 1);
880 memcpy (newp + (p - filename + 1), pattern, patlen);
881 pattern = newp;
882 }
04925e1e 883
0b48acfe 884#ifdef HAVE_GLOB
d3989512
JJ
885 if (glob (pattern, 0, NULL, &gl) == 0)
886 {
887 size_t i;
888
889 for (i = 0; i < gl.gl_pathc; ++i)
890 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
891 globfree (&gl);
892 }
0b48acfe
MM
893#else
894 /* If we do not have glob, treat the pattern as a literal filename. */
895 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
896#endif
d3989512
JJ
897
898 if (newp)
899 free (newp);
900}
901
dfcffada 902static bfd_boolean
d3989512
JJ
903gld${EMULATION_NAME}_parse_ld_so_conf
904 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
905{
906 FILE *f = fopen (filename, FOPEN_RT);
563f4125
JJ
907 char *line;
908 size_t linelen;
d3989512
JJ
909
910 if (f == NULL)
dfcffada 911 return FALSE;
d3989512 912
563f4125
JJ
913 linelen = 256;
914 line = xmalloc (linelen);
915 do
d3989512 916 {
563f4125
JJ
917 char *p = line, *q;
918
919 /* Normally this would use getline(3), but we need to be portable. */
920 while ((q = fgets (p, linelen - (p - line), f)) != NULL
921 && strlen (q) == linelen - (p - line) - 1
922 && line[linelen - 2] != '\n')
923 {
924 line = xrealloc (line, 2 * linelen);
925 p = line + linelen - 1;
926 linelen += linelen;
927 }
928
929 if (q == NULL && p == line)
930 break;
d3989512
JJ
931
932 p = strchr (line, '\n');
933 if (p)
934 *p = '\0';
935
936 /* Because the file format does not know any form of quoting we
937 can search forward for the next '#' character and if found
938 make it terminating the line. */
939 p = strchr (line, '#');
940 if (p)
941 *p = '\0';
942
943 /* Remove leading whitespace. NUL is no whitespace character. */
944 p = line;
945 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
946 ++p;
947
948 /* If the line is blank it is ignored. */
949 if (p[0] == '\0')
950 continue;
04925e1e 951
0112cd26 952 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
d3989512
JJ
953 {
954 char *dir, c;
955 p += 8;
956 do
04925e1e 957 {
d3989512
JJ
958 while (*p == ' ' || *p == '\t')
959 ++p;
04925e1e 960
d3989512
JJ
961 if (*p == '\0')
962 break;
252b5132 963
d3989512
JJ
964 dir = p;
965
966 while (*p != ' ' && *p != '\t' && *p)
967 ++p;
968
969 c = *p;
970 *p++ = '\0';
971 if (dir[0] != '\0')
972 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
973 dir);
974 }
975 while (c != '\0');
976 }
977 else
978 {
979 char *dir = p;
980 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
981 && *p != '\r' && *p != '\v')
982 ++p;
983
984 while (p != dir && p[-1] == '/')
985 --p;
986 if (info->path == NULL)
987 {
988 info->alloc = p - dir + 1 + 256;
989 info->path = xmalloc (info->alloc);
990 info->len = 0;
991 }
04925e1e
AM
992 else
993 {
d3989512
JJ
994 if (info->len + 1 + (p - dir) >= info->alloc)
995 {
996 info->alloc += p - dir + 256;
997 info->path = xrealloc (info->path, info->alloc);
998 }
c76308d2 999 info->path[info->len++] = config.rpath_separator;
04925e1e 1000 }
d3989512
JJ
1001 memcpy (info->path + info->len, dir, p - dir);
1002 info->len += p - dir;
1003 info->path[info->len] = '\0';
1004 }
1005 }
563f4125 1006 while (! feof (f));
d3989512
JJ
1007 free (line);
1008 fclose (f);
dfcffada 1009 return TRUE;
d3989512 1010}
252b5132 1011
d3989512 1012static bfd_boolean
d5c8b1f8
AM
1013gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
1014 int force)
d3989512
JJ
1015{
1016 static bfd_boolean initialized;
316a1245 1017 static const char *ld_so_conf;
d3989512 1018 struct dt_needed needed;
252b5132 1019
d3989512
JJ
1020 if (! initialized)
1021 {
1022 char *tmppath;
1023 struct gld${EMULATION_NAME}_ld_so_conf info;
9c8ebd6a 1024
d3989512
JJ
1025 info.path = NULL;
1026 info.len = info.alloc = 0;
ff7a0acf
AM
1027 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
1028 (const char *) NULL);
dfcffada
AM
1029 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
1030 {
1031 free (tmppath);
ff7a0acf
AM
1032 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
1033 (const char *) NULL);
dfcffada
AM
1034 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
1035 }
d3989512 1036 free (tmppath);
dfcffada 1037
d3989512
JJ
1038 if (info.path)
1039 {
316a1245 1040 ld_so_conf = gld${EMULATION_NAME}_add_sysroot (info.path);
d3989512 1041 free (info.path);
04925e1e 1042 }
b34976b6 1043 initialized = TRUE;
04925e1e 1044 }
49e56c49 1045
04925e1e 1046 if (ld_so_conf == NULL)
b34976b6 1047 return FALSE;
252b5132 1048
e56f61be 1049
d5c8b1f8
AM
1050 needed.by = l->by;
1051 needed.name = l->name;
e56f61be 1052 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
252b5132
RH
1053}
1054
04925e1e 1055EOF
9c8ebd6a
DJ
1056 # Linux
1057 ;;
04925e1e
AM
1058 esac
1059fi
92b93329 1060fragment <<EOF
04925e1e 1061
252b5132
RH
1062/* See if an input file matches a DT_NEEDED entry by name. */
1063
1064static void
0c7a8e5a 1065gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
252b5132 1066{
e13629bc
AM
1067 const char *soname;
1068
1069 /* Stop looking if we've found a loaded lib. */
1070 if (global_found != NULL
1071 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1072 & DYN_AS_NEEDED) == 0)
252b5132
RH
1073 return;
1074
e13629bc
AM
1075 if (s->filename == NULL || s->the_bfd == NULL)
1076 return;
1077
1078 /* Don't look for a second non-loaded as-needed lib. */
1079 if (global_found != NULL
1080 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
7cedef86
AM
1081 return;
1082
42627821 1083 if (filename_cmp (s->filename, global_needed->name) == 0)
252b5132 1084 {
e13629bc
AM
1085 global_found = s;
1086 return;
1087 }
577a0623 1088
66be1055 1089 if (s->flags.search_dirs)
e13629bc
AM
1090 {
1091 const char *f = strrchr (s->filename, '/');
1092 if (f != NULL
42627821 1093 && filename_cmp (f + 1, global_needed->name) == 0)
577a0623 1094 {
e13629bc 1095 global_found = s;
577a0623
AM
1096 return;
1097 }
252b5132
RH
1098 }
1099
e13629bc
AM
1100 soname = bfd_elf_get_dt_soname (s->the_bfd);
1101 if (soname != NULL
42627821 1102 && filename_cmp (soname, global_needed->name) == 0)
252b5132 1103 {
e13629bc
AM
1104 global_found = s;
1105 return;
252b5132 1106 }
252b5132
RH
1107}
1108
41392f03
AM
1109EOF
1110
1111if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
92b93329 1112fragment <<EOF
04925e1e 1113
24382dca 1114static bfd_size_type
677e5a92 1115id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
24382dca 1116{
30e8ee25 1117 const char *style = emit_note_gnu_build_id;
24382dca 1118 bfd_size_type size;
61e2488c 1119 bfd_size_type build_id_size;
24382dca 1120
24382dca
RM
1121 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1122 size = (size + 3) & -(bfd_size_type) 4;
1123
61e2488c
JT
1124 build_id_size = compute_build_id_size (style);
1125 if (build_id_size)
1126 size += build_id_size;
24382dca
RM
1127 else
1128 size = 0;
1129
1130 return size;
1131}
1132
24382dca 1133static bfd_boolean
30e8ee25 1134write_build_id (bfd *abfd)
24382dca
RM
1135{
1136 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
30e8ee25
AM
1137 struct elf_obj_tdata *t = elf_tdata (abfd);
1138 const char *style;
24382dca
RM
1139 asection *asec;
1140 Elf_Internal_Shdr *i_shdr;
1141 unsigned char *contents, *id_bits;
1142 bfd_size_type size;
30e8ee25 1143 file_ptr position;
24382dca
RM
1144 Elf_External_Note *e_note;
1145
c0355132
AM
1146 style = t->o->build_id.style;
1147 asec = t->o->build_id.sec;
83e4970b 1148 if (bfd_is_abs_section (asec->output_section))
24382dca 1149 {
83e4970b
AM
1150 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1151 " --build-id ignored.\n"));
1152 return TRUE;
24382dca
RM
1153 }
1154 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1155
1156 if (i_shdr->contents == NULL)
1157 {
b2ff8454 1158 if (asec->contents == NULL)
1e9cc1c2 1159 asec->contents = (unsigned char *) xmalloc (asec->size);
b2ff8454 1160 contents = asec->contents;
24382dca 1161 }
b2ff8454
RM
1162 else
1163 contents = i_shdr->contents + asec->output_offset;
24382dca 1164
1e9cc1c2 1165 e_note = (Elf_External_Note *) contents;
24382dca
RM
1166 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1167 size = (size + 3) & -(bfd_size_type) 4;
1168 id_bits = contents + size;
1169 size = asec->size - size;
1170
1171 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1172 bfd_h_put_32 (abfd, size, &e_note->descsz);
1173 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1174 memcpy (e_note->name, "GNU", sizeof "GNU");
1175
61e2488c 1176 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
24382dca 1177
30e8ee25 1178 position = i_shdr->sh_offset + asec->output_offset;
b2ff8454 1179 size = asec->size;
30e8ee25 1180 return (bfd_seek (abfd, position, SEEK_SET) == 0
b2ff8454 1181 && bfd_bwrite (contents, size, abfd) == size);
24382dca
RM
1182}
1183
30e8ee25
AM
1184/* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1185
1186static bfd_boolean
1187setup_build_id (bfd *ibfd)
1188{
1189 asection *s;
1190 bfd_size_type size;
1191 flagword flags;
1192
1193 size = id_note_section_size (ibfd);
1194 if (size == 0)
1195 {
d003af55 1196 einfo (_("%P: warning: unrecognized --build-id style ignored.\n"));
30e8ee25
AM
1197 return FALSE;
1198 }
1199
1200 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1201 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1202 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1203 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1204 {
1205 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
c0355132
AM
1206 t->o->build_id.after_write_object_contents = &write_build_id;
1207 t->o->build_id.style = emit_note_gnu_build_id;
1208 t->o->build_id.sec = s;
1209 elf_section_type (s) = SHT_NOTE;
1210 s->size = size;
1211 return TRUE;
30e8ee25
AM
1212 }
1213
d003af55
AM
1214 einfo (_("%P: warning: Cannot create .note.gnu.build-id section,"
1215 " --build-id ignored.\n"));
30e8ee25
AM
1216 return FALSE;
1217}
24382dca 1218
04925e1e 1219/* This is called after all the input files have been opened. */
252b5132
RH
1220
1221static void
0c7a8e5a 1222gld${EMULATION_NAME}_after_open (void)
252b5132 1223{
04925e1e 1224 struct bfd_link_needed_list *needed, *l;
d10e7fcc 1225 struct elf_link_hash_table *htab;
cbd0eecf
L
1226 asection *s;
1227 bfd *abfd;
d10e7fcc 1228
5c3049d2
AM
1229 after_open_default ();
1230
d10e7fcc
AM
1231 htab = elf_hash_table (&link_info);
1232 if (!is_elf_hash_table (htab))
1233 return;
252b5132 1234
76359541
TP
1235 if (command_line.out_implib_filename)
1236 {
1237 unlink_if_ordinary (command_line.out_implib_filename);
1238 link_info.out_implib_bfd
1239 = bfd_openw (command_line.out_implib_filename,
1240 bfd_get_target (link_info.output_bfd));
1241
1242 if (link_info.out_implib_bfd == NULL)
1243 {
d003af55 1244 einfo (_("%F%s: Can't open for writing: %E\n"),
76359541
TP
1245 command_line.out_implib_filename);
1246 }
1247 }
1248
30e8ee25 1249 if (emit_note_gnu_build_id != NULL)
c0065db7 1250 {
a654efd6
L
1251 /* Find an ELF input. */
1252 for (abfd = link_info.input_bfds;
c72f2fb2 1253 abfd != (bfd *) NULL; abfd = abfd->link.next)
ca0694ad 1254 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
57963c05
AM
1255 && bfd_count_sections (abfd) != 0
1256 && !((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
a654efd6 1257 break;
c0065db7 1258
30e8ee25
AM
1259 /* PR 10555: If there are no ELF input files do not try to
1260 create a .note.gnu-build-id section. */
1261 if (abfd == NULL
1262 || !setup_build_id (abfd))
c0065db7 1263 {
30e8ee25
AM
1264 free ((char *) emit_note_gnu_build_id);
1265 emit_note_gnu_build_id = NULL;
c0065db7
RM
1266 }
1267 }
1268
46bed679
L
1269 get_elf_backend_data (link_info.output_bfd)->setup_gnu_properties (&link_info);
1270
0e1862bb 1271 if (bfd_link_relocatable (&link_info))
76f0cad6
NC
1272 {
1273 if (link_info.execstack == ! link_info.noexecstack)
1274 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1275 command line and we are perfoming a relocatable link then no
1276 PT_GNU_STACK segment will be created and so the
1277 linkinfo.[no]execstack values set in _handle_option() will have no
1278 effect. Instead we create a .note.GNU-stack section in much the
1279 same way as the assembler does with its --[no]execstack option. */
1280 (void) bfd_make_section_with_flags (link_info.input_bfds,
1281 ".note.GNU-stack",
1282 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1283
1284 return;
1285 }
d10e7fcc 1286
2f0c68f2 1287 if (!link_info.traditional_format)
eb3d5f3b 1288 {
cbd0eecf 1289 bfd *elfbfd = NULL;
a654efd6 1290 bfd_boolean warn_eh_frame = FALSE;
2f0c68f2 1291 int seen_type = 0;
eb3d5f3b 1292
c72f2fb2 1293 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
eb3d5f3b 1294 {
2f0c68f2 1295 int type = 0;
57963c05
AM
1296
1297 if (((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
1298 continue;
1299
2f0c68f2 1300 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
4440bb77 1301 {
2f0c68f2
CM
1302 const char *name = bfd_get_section_name (abfd, s);
1303
1304 if (bfd_is_abs_section (s->output_section))
1305 continue;
1306 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1307 type = COMPACT_EH_HDR;
1308 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1309 type = DWARF2_EH_HDR;
4440bb77 1310 }
2f0c68f2
CM
1311
1312 if (type != 0)
1313 {
1314 if (seen_type == 0)
1315 {
1316 seen_type = type;
1317 }
1318 else if (seen_type != type)
1319 {
1320 einfo (_("%P%F: compact frame descriptions incompatible with"
d003af55 1321 " DWARF2 .eh_frame from %B\n"),
2f0c68f2
CM
1322 type == DWARF2_EH_HDR ? abfd : elfbfd);
1323 break;
1324 }
1325
1326 if (!elfbfd
1327 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1328 {
1329 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1330 elfbfd = abfd;
1331
1332 warn_eh_frame = TRUE;
1333 }
1334 }
1335
1336 if (seen_type == COMPACT_EH_HDR)
1337 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
d10e7fcc 1338 }
a654efd6 1339 if (elfbfd)
d10e7fcc
AM
1340 {
1341 const struct elf_backend_data *bed;
1342
a654efd6
L
1343 bed = get_elf_backend_data (elfbfd);
1344 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1345 bed->dynamic_sec_flags
1346 | SEC_READONLY);
d10e7fcc 1347 if (s != NULL
a654efd6
L
1348 && bfd_set_section_alignment (elfbfd, s, 2))
1349 {
1350 htab->eh_info.hdr_sec = s;
1351 warn_eh_frame = FALSE;
1352 }
eb3d5f3b 1353 }
a654efd6 1354 if (warn_eh_frame)
d003af55
AM
1355 einfo (_("%P: warning: Cannot create .eh_frame_hdr section,"
1356 " --eh-frame-hdr ignored.\n"));
eb3d5f3b
JB
1357 }
1358
04925e1e
AM
1359 /* Get the list of files which appear in DT_NEEDED entries in
1360 dynamic objects included in the link (often there will be none).
1361 For each such file, we want to track down the corresponding
1362 library, and include the symbol table in the link. This is what
1363 the runtime dynamic linker will do. Tracking the files down here
1364 permits one dynamic object to include another without requiring
1365 special action by the person doing the link. Note that the
1366 needed list can actually grow while we are stepping through this
1367 loop. */
f13a99db 1368 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
04925e1e 1369 for (l = needed; l != NULL; l = l->next)
252b5132 1370 {
04925e1e 1371 struct bfd_link_needed_list *ll;
e56f61be 1372 struct dt_needed n, nn;
04925e1e 1373 int force;
252b5132 1374
7e9f0867 1375 /* If the lib that needs this one was --as-needed and wasn't
4706eab9 1376 found to be needed, then this lib isn't needed either. */
7e9f0867 1377 if (l->by != NULL
4706eab9
AM
1378 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1379 continue;
1380
1381 /* Skip the lib if --no-copy-dt-needed-entries and
1382 --allow-shlib-undefined is in effect. */
1383 if (l->by != NULL
1384 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1385 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
7e9f0867
AM
1386 continue;
1387
04925e1e
AM
1388 /* If we've already seen this file, skip it. */
1389 for (ll = needed; ll != l; ll = ll->next)
7e9f0867
AM
1390 if ((ll->by == NULL
1391 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1392 && strcmp (ll->name, l->name) == 0)
04925e1e
AM
1393 break;
1394 if (ll != l)
1395 continue;
252b5132 1396
04925e1e
AM
1397 /* See if this file was included in the link explicitly. */
1398 global_needed = l;
e13629bc 1399 global_found = NULL;
04925e1e 1400 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
e13629bc
AM
1401 if (global_found != NULL
1402 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1403 & DYN_AS_NEEDED) == 0)
04925e1e 1404 continue;
252b5132 1405
e56f61be
L
1406 n.by = l->by;
1407 n.name = l->name;
1408 nn.by = l->by;
cd6f1cf3 1409 if (verbose)
ec4eb78a
L
1410 info_msg (_("%s needed by %B\n"), l->name, l->by);
1411
e13629bc
AM
1412 /* As-needed libs specified on the command line (or linker script)
1413 take priority over libs found in search dirs. */
1414 if (global_found != NULL)
1415 {
1416 nn.name = global_found->filename;
1417 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1418 continue;
1419 }
1420
04925e1e
AM
1421 /* We need to find this file and include the symbol table. We
1422 want to search for the file in the same way that the dynamic
1423 linker will search. That means that we want to use
1424 rpath_link, rpath, then the environment variable
ec4eb78a
L
1425 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1426 entries (native only), then the linker script LIB_SEARCH_DIRS.
1427 We do not search using the -L arguments.
252b5132 1428
04925e1e
AM
1429 We search twice. The first time, we skip objects which may
1430 introduce version mismatches. The second time, we force
1431 their use. See gld${EMULATION_NAME}_vercheck comment. */
1432 for (force = 0; force < 2; force++)
1433 {
04925e1e
AM
1434 size_t len;
1435 search_dirs_type *search;
6dd8c765 1436EOF
316a1245 1437if [ "x${NATIVE}" = xyes ] || [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1438fragment <<EOF
316a1245 1439 const char *path;
ff925e69
KK
1440EOF
1441fi
1442if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1443fragment <<EOF
6dd8c765
L
1444 struct bfd_link_needed_list *rp;
1445 int found;
1446EOF
6dd8c765 1447fi
92b93329 1448fragment <<EOF
252b5132 1449
04925e1e 1450 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
e56f61be 1451 &n, force))
04925e1e 1452 break;
dcb0bd0e 1453EOF
9c8ebd6a 1454if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1455fragment <<EOF
316a1245
AM
1456 path = command_line.rpath;
1457 if (path)
1458 {
118aa6cf 1459 path = gld${EMULATION_NAME}_add_sysroot (path);
316a1245 1460 found = gld${EMULATION_NAME}_search_needed (path, &n, force);
118aa6cf 1461 free ((char *) path);
316a1245
AM
1462 if (found)
1463 break;
1464 }
9c8ebd6a
DJ
1465EOF
1466fi
1467if [ "x${NATIVE}" = xyes ] ; then
92b93329 1468fragment <<EOF
04925e1e
AM
1469 if (command_line.rpath_link == NULL
1470 && command_line.rpath == NULL)
1471 {
316a1245
AM
1472 path = (const char *) getenv ("LD_RUN_PATH");
1473 if (path
1474 && gld${EMULATION_NAME}_search_needed (path, &n, force))
04925e1e
AM
1475 break;
1476 }
316a1245
AM
1477 path = (const char *) getenv ("LD_LIBRARY_PATH");
1478 if (path
1479 && gld${EMULATION_NAME}_search_needed (path, &n, force))
04925e1e 1480 break;
9c8ebd6a
DJ
1481EOF
1482fi
1483if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1484fragment <<EOF
ec4eb78a 1485 found = 0;
f13a99db 1486 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
6dd8c765 1487 for (; !found && rp != NULL; rp = rp->next)
ec4eb78a 1488 {
316a1245 1489 path = gld${EMULATION_NAME}_add_sysroot (rp->name);
ec4eb78a 1490 found = (rp->by == l->by
316a1245 1491 && gld${EMULATION_NAME}_search_needed (path, &n,
ec4eb78a 1492 force));
316a1245 1493 free ((char *) path);
ec4eb78a
L
1494 }
1495 if (found)
1496 break;
1497
04925e1e 1498EOF
04925e1e 1499fi
c1446dba
L
1500if [ "x${USE_LIBPATH}" = xyes ] ; then
1501 case ${target} in
ebe1fac1 1502 *-*-freebsd* | *-*-dragonfly*)
92b93329 1503 fragment <<EOF
d5c8b1f8 1504 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
ebe1fac1
NC
1505 break;
1506EOF
1507 # FreeBSD
1508 ;;
1509
a5244b7e 1510 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
92b93329 1511 fragment <<EOF
d5c8b1f8 1512 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
c1446dba
L
1513 break;
1514
1515EOF
eeaa4577 1516 # Linux
c1446dba
L
1517 ;;
1518 esac
1519fi
92b93329 1520fragment <<EOF
04925e1e
AM
1521 len = strlen (l->name);
1522 for (search = search_head; search != NULL; search = search->next)
1523 {
1524 char *filename;
252b5132 1525
04925e1e
AM
1526 if (search->cmdline)
1527 continue;
1528 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1529 sprintf (filename, "%s/%s", search->name, l->name);
e56f61be
L
1530 nn.name = filename;
1531 if (gld${EMULATION_NAME}_try_needed (&nn, force))
04925e1e
AM
1532 break;
1533 free (filename);
1534 }
1535 if (search != NULL)
1536 break;
1537EOF
92b93329 1538fragment <<EOF
04925e1e 1539 }
252b5132 1540
04925e1e
AM
1541 if (force < 2)
1542 continue;
252b5132 1543
d003af55
AM
1544 einfo (_("%P: warning: %s, needed by %B, not found "
1545 "(try using -rpath or -rpath-link)\n"),
04925e1e
AM
1546 l->name, l->by);
1547 }
2f0c68f2
CM
1548
1549 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
535b785f 1550 if (!bfd_elf_parse_eh_frame_entries (NULL, &link_info))
2f0c68f2 1551 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
04925e1e 1552}
252b5132 1553
41392f03
AM
1554EOF
1555fi
1556
92b93329 1557fragment <<EOF
252b5132 1558
04925e1e 1559/* Look through an expression for an assignment statement. */
252b5132 1560
04925e1e 1561static void
0c7a8e5a 1562gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
04925e1e 1563{
4ea42fb7 1564 bfd_boolean provide = FALSE;
04925e1e
AM
1565
1566 switch (exp->type.node_class)
252b5132 1567 {
04925e1e 1568 case etree_provide:
bded3693 1569 case etree_provided:
4ea42fb7 1570 provide = TRUE;
839b0b3f 1571 /* Fallthru */
4ea42fb7 1572 case etree_assign:
04925e1e
AM
1573 /* We call record_link_assignment even if the symbol is defined.
1574 This is because if it is defined by a dynamic object, we
1575 actually want to use the value defined by the linker script,
1576 not the value from the dynamic object (because we are setting
1577 symbols like etext). If the symbol is defined by a regular
1578 object, then, as it happens, calling record_link_assignment
1579 will do no harm. */
04925e1e 1580 if (strcmp (exp->assign.dst, ".") != 0)
252b5132 1581 {
f13a99db
AM
1582 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1583 &link_info,
fe21a8fc
L
1584 exp->assign.dst, provide,
1585 exp->assign.hidden))
d003af55 1586 einfo (_("%P%F: failed to record assignment to %s: %E\n"),
04925e1e 1587 exp->assign.dst);
252b5132 1588 }
04925e1e
AM
1589 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1590 break;
252b5132 1591
04925e1e
AM
1592 case etree_binary:
1593 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1594 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1595 break;
252b5132 1596
04925e1e
AM
1597 case etree_trinary:
1598 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1599 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1600 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1601 break;
252b5132 1602
04925e1e
AM
1603 case etree_unary:
1604 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1605 break;
252b5132 1606
04925e1e
AM
1607 default:
1608 break;
252b5132
RH
1609 }
1610}
1611
04925e1e
AM
1612
1613/* This is called by the before_allocation routine via
1614 lang_for_each_statement. It locates any assignment statements, and
1615 tells the ELF backend about them, in case they are assignments to
1616 symbols which are referred to by dynamic objects. */
1617
1618static void
0c7a8e5a 1619gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
04925e1e
AM
1620{
1621 if (s->header.type == lang_assignment_statement_enum)
1622 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1623}
1624
41392f03
AM
1625EOF
1626
1627if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
57e6abd2
AO
1628 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1629 ELF_INTERPRETER_SET_DEFAULT="
1630 if (sinterp != NULL)
1631 {
5718918d
AM
1632 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1633 sinterp->size = strlen ((char *) sinterp->contents) + 1;
57e6abd2
AO
1634 }
1635
1636"
1637 else
1638 ELF_INTERPRETER_SET_DEFAULT=
1639 fi
92b93329 1640fragment <<EOF
04925e1e 1641
7ee314fa 1642/* used by before_allocation and handle_option. */
4724d37e 1643static void
91d6fa6a 1644gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
7ee314fa
AM
1645{
1646 if (*to == NULL)
91d6fa6a 1647 *to = xstrdup (op_arg);
7ee314fa
AM
1648 else
1649 {
1650 size_t to_len = strlen (*to);
91d6fa6a 1651 size_t op_arg_len = strlen (op_arg);
7ee314fa
AM
1652 char *buf;
1653 char *cp = *to;
1654
1655 /* First see whether OPTARG is already in the path. */
1656 do
1657 {
91d6fa6a
NC
1658 if (strncmp (op_arg, cp, op_arg_len) == 0
1659 && (cp[op_arg_len] == 0
1660 || cp[op_arg_len] == config.rpath_separator))
7ee314fa
AM
1661 /* We found it. */
1662 break;
1663
1664 /* Not yet found. */
1665 cp = strchr (cp, config.rpath_separator);
1666 if (cp != NULL)
1667 ++cp;
1668 }
1669 while (cp != NULL);
1670
1671 if (cp == NULL)
1672 {
91d6fa6a 1673 buf = xmalloc (to_len + op_arg_len + 2);
7ee314fa 1674 sprintf (buf, "%s%c%s", *to,
91d6fa6a 1675 config.rpath_separator, op_arg);
7ee314fa
AM
1676 free (*to);
1677 *to = buf;
1678 }
1679 }
1680}
1681
b6518b38
NC
1682#if defined(__GNUC__) && GCC_VERSION < 4006
1683 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1684static struct bfd_link_hash_entry ehdr_start_empty;
1685#endif
1686
252b5132
RH
1687/* This is called after the sections have been attached to output
1688 sections, but before any sizes or addresses have been set. */
1689
1690static void
0c7a8e5a 1691gld${EMULATION_NAME}_before_allocation (void)
252b5132
RH
1692{
1693 const char *rpath;
1694 asection *sinterp;
7ee314fa 1695 bfd *abfd;
4199e3b8 1696 struct elf_link_hash_entry *ehdr_start = NULL;
a0bde398
L
1697#if defined(__GNUC__) && GCC_VERSION < 4006
1698 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
b6518b38 1699 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
a0bde398 1700#else
4a0bc59e 1701 struct bfd_link_hash_entry ehdr_start_save;
a0bde398 1702#endif
252b5132 1703
b4d040b1 1704 if (is_elf_hash_table (link_info.hash))
a5382c42
MR
1705 {
1706 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
e1918d23 1707
cde7cb01
MR
1708 /* Make __ehdr_start hidden if it has been referenced, to
1709 prevent the symbol from being dynamic. */
0e1862bb 1710 if (!bfd_link_relocatable (&link_info))
559192d8
AM
1711 {
1712 struct elf_link_hash_table *htab = elf_hash_table (&link_info);
1713 struct elf_link_hash_entry *h
1714 = elf_link_hash_lookup (htab, "__ehdr_start", FALSE, FALSE, TRUE);
1715
1716 /* Only adjust the export class if the symbol was referenced
1717 and not defined, otherwise leave it alone. */
1718 if (h != NULL
1719 && (h->root.type == bfd_link_hash_new
1720 || h->root.type == bfd_link_hash_undefined
1721 || h->root.type == bfd_link_hash_undefweak
1722 || h->root.type == bfd_link_hash_common))
1723 {
1724 const struct elf_backend_data *bed;
1725 bed = get_elf_backend_data (link_info.output_bfd);
1726 (*bed->elf_backend_hide_symbol) (&link_info, h, TRUE);
1727 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1728 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1729 /* Don't leave the symbol undefined. Undefined hidden
1730 symbols typically won't have dynamic relocations, but
1731 we most likely will need dynamic relocations for
1732 __ehdr_start if we are building a PIE or shared
1733 library. */
1734 ehdr_start = h;
1735 ehdr_start_save = h->root;
1736 h->root.type = bfd_link_hash_defined;
1737 h->root.u.def.section = bfd_abs_section_ptr;
1738 h->root.u.def.value = 0;
1739 }
1740 }
cde7cb01 1741
a5382c42
MR
1742 /* If we are going to make any variable assignments, we need to
1743 let the ELF backend know about them in case the variables are
1744 referred to by dynamic objects. */
1745 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1746 }
252b5132
RH
1747
1748 /* Let the ELF backend work out the sizes of any sections required
1749 by dynamic linking. */
1750 rpath = command_line.rpath;
1751 if (rpath == NULL)
1752 rpath = (const char *) getenv ("LD_RUN_PATH");
7ee314fa 1753
c72f2fb2 1754 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
8dd881b6
L
1755 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1756 {
1757 const char *audit_libs = elf_dt_audit (abfd);
7ee314fa 1758
4724d37e 1759 /* If the input bfd contains an audit entry, we need to add it as
8dd881b6
L
1760 a dep audit entry. */
1761 if (audit_libs && *audit_libs != '\0')
1762 {
1763 char *cp = xstrdup (audit_libs);
1764 do
1765 {
1766 int more = 0;
1767 char *cp2 = strchr (cp, config.rpath_separator);
7ee314fa 1768
8dd881b6
L
1769 if (cp2)
1770 {
1771 *cp2 = '\0';
1772 more = 1;
1773 }
7ee314fa 1774
8dd881b6
L
1775 if (cp != NULL && *cp != '\0')
1776 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1777
1778 cp = more ? ++cp2 : NULL;
1779 }
1780 while (cp != NULL);
1781 }
1782 }
7ee314fa 1783
5a580b3a 1784 if (! (bfd_elf_size_dynamic_sections
f13a99db 1785 (link_info.output_bfd, command_line.soname, rpath,
7ee314fa 1786 command_line.filter_shlib, audit, depaudit,
252b5132 1787 (const char * const *) command_line.auxiliary_filters,
fd91d419 1788 &link_info, &sinterp)))
d003af55 1789 einfo (_("%P%F: failed to set dynamic section sizes: %E\n"));
8423293d 1790
57e6abd2 1791${ELF_INTERPRETER_SET_DEFAULT}
252b5132
RH
1792 /* Let the user override the dynamic linker we are using. */
1793 if (command_line.interpreter != NULL
1794 && sinterp != NULL)
1795 {
1796 sinterp->contents = (bfd_byte *) command_line.interpreter;
eea6121a 1797 sinterp->size = strlen (command_line.interpreter) + 1;
252b5132
RH
1798 }
1799
1800 /* Look for any sections named .gnu.warning. As a GNU extensions,
1801 we treat such sections as containing warning messages. We print
1802 out the warning message, and then zero out the section size so
1803 that it does not get copied into the output file. */
1804
1805 {
1806 LANG_FOR_EACH_INPUT_STATEMENT (is)
1807 {
1808 asection *s;
1809 bfd_size_type sz;
1810 char *msg;
252b5132 1811
66be1055 1812 if (is->flags.just_syms)
252b5132
RH
1813 continue;
1814
1815 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1816 if (s == NULL)
1817 continue;
1818
eea6121a 1819 sz = s->size;
1e9cc1c2 1820 msg = (char *) xmalloc ((size_t) (sz + 1));
bc251d50 1821 if (! bfd_get_section_contents (is->the_bfd, s, msg,
8c675694 1822 (file_ptr) 0, sz))
d003af55 1823 einfo (_("%F%B: Can't read contents of section .gnu.warning: %E\n"),
252b5132 1824 is->the_bfd);
bc251d50 1825 msg[sz] = '\0';
1a72702b
AM
1826 (*link_info.callbacks->warning) (&link_info, msg,
1827 (const char *) NULL, is->the_bfd,
1828 (asection *) NULL, (bfd_vma) 0);
252b5132
RH
1829 free (msg);
1830
9e3be61d
AM
1831 /* Clobber the section size, so that we don't waste space
1832 copying the warning into the output file. If we've already
1833 sized the output section, adjust its size. The adjustment
1834 is on rawsize because targets that size sections early will
1835 have called lang_reset_memory_regions after sizing. */
1836 if (s->output_section != NULL
1837 && s->output_section->rawsize >= s->size)
1838 s->output_section->rawsize -= s->size;
1839
eea6121a 1840 s->size = 0;
11d2f718 1841
9e3be61d
AM
1842 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1843 warning section don't get copied to the output. */
a14a5de3 1844 s->flags |= SEC_EXCLUDE | SEC_KEEP;
252b5132
RH
1845 }
1846 }
8423293d 1847
1e035701 1848 before_allocation_default ();
8423293d 1849
f13a99db 1850 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
d003af55 1851 einfo (_("%P%F: failed to set dynamic section sizes: %E\n"));
4199e3b8
AM
1852
1853 if (ehdr_start != NULL)
1854 {
1855 /* If we twiddled __ehdr_start to defined earlier, put it back
1856 as it was. */
1857 ehdr_start->root.type = ehdr_start_save.type;
1858 ehdr_start->root.u = ehdr_start_save.u;
1859 }
252b5132
RH
1860}
1861
41392f03
AM
1862EOF
1863fi
1864
1865if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
92b93329 1866fragment <<EOF
252b5132 1867
04925e1e
AM
1868/* Try to open a dynamic archive. This is where we know that ELF
1869 dynamic libraries have an extension of .so (or .sl on oddball systems
1870 like hpux). */
1871
b34976b6 1872static bfd_boolean
0c7a8e5a
AM
1873gld${EMULATION_NAME}_open_dynamic_archive
1874 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
252b5132 1875{
04925e1e
AM
1876 const char *filename;
1877 char *string;
d4ae5fb0
AM
1878 size_t len;
1879 bfd_boolean opened = FALSE;
252b5132 1880
66be1055 1881 if (! entry->flags.maybe_archive)
b34976b6 1882 return FALSE;
252b5132 1883
04925e1e 1884 filename = entry->filename;
d4ae5fb0
AM
1885 len = strlen (search->name) + strlen (filename);
1886 if (entry->flags.full_name_provided)
1887 {
1888 len += sizeof "/";
1889 string = (char *) xmalloc (len);
1890 sprintf (string, "%s/%s", search->name, filename);
1891 }
1892 else
1893 {
1894 size_t xlen = 0;
252b5132 1895
d4ae5fb0 1896 len += strlen (arch) + sizeof "/lib.so";
04925e1e 1897#ifdef EXTRA_SHLIB_EXTENSION
d4ae5fb0
AM
1898 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1899 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1900 : 0);
04925e1e 1901#endif
d4ae5fb0
AM
1902 string = (char *) xmalloc (len + xlen);
1903 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
04925e1e 1904#ifdef EXTRA_SHLIB_EXTENSION
d4ae5fb0
AM
1905 /* Try the .so extension first. If that fails build a new filename
1906 using EXTRA_SHLIB_EXTENSION. */
1907 opened = ldfile_try_open_bfd (string, entry);
1908 if (!opened)
1909 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
04925e1e 1910#endif
d4ae5fb0 1911 }
04925e1e 1912
d4ae5fb0 1913 if (!opened && !ldfile_try_open_bfd (string, entry))
252b5132 1914 {
04925e1e 1915 free (string);
b34976b6 1916 return FALSE;
04925e1e 1917 }
252b5132 1918
04925e1e 1919 entry->filename = string;
252b5132 1920
04925e1e
AM
1921 /* We have found a dynamic object to include in the link. The ELF
1922 backend linker will create a DT_NEEDED entry in the .dynamic
1923 section naming this file. If this file includes a DT_SONAME
1924 entry, it will be used. Otherwise, the ELF linker will just use
1925 the name of the file. For an archive found by searching, like
1926 this one, the DT_NEEDED entry should consist of just the name of
1927 the file, without the path information used to find it. Note
1928 that we only need to do this if we have a dynamic object; an
1929 archive will never be referenced by a DT_NEEDED entry.
252b5132 1930
04925e1e
AM
1931 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1932 very pretty. I haven't been able to think of anything that is
1933 pretty, though. */
1934 if (bfd_check_format (entry->the_bfd, bfd_object)
1935 && (entry->the_bfd->flags & DYNAMIC) != 0)
1936 {
66be1055 1937 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
252b5132 1938
04925e1e 1939 /* Rather than duplicating the logic above. Just use the
1c9acd94 1940 filename we recorded earlier. */
04925e1e 1941
d4ae5fb0 1942 if (!entry->flags.full_name_provided)
559192d8 1943 filename = lbasename (entry->filename);
1c9acd94 1944 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
04925e1e
AM
1945 }
1946
b34976b6 1947 return TRUE;
04925e1e
AM
1948}
1949
41392f03
AM
1950EOF
1951fi
cde43e70
AM
1952
1953if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
92b93329 1954fragment <<EOF
41392f03 1955
afd7a018 1956/* A variant of lang_output_section_find used by place_orphan. */
04925e1e 1957
04925e1e 1958static lang_output_section_statement_type *
2a36a117 1959output_rel_find (asection *sec, int isdyn)
04925e1e 1960{
04925e1e 1961 lang_output_section_statement_type *lookup;
ba493122 1962 lang_output_section_statement_type *last = NULL;
2a36a117 1963 lang_output_section_statement_type *last_alloc = NULL;
48f2ff54 1964 lang_output_section_statement_type *last_ro_alloc = NULL;
ba493122
AM
1965 lang_output_section_statement_type *last_rel = NULL;
1966 lang_output_section_statement_type *last_rel_alloc = NULL;
24cdb50a 1967 int rela = sec->name[4] == 'a';
04925e1e 1968
afd7a018
AM
1969 for (lookup = &lang_output_section_statement.head->output_section_statement;
1970 lookup != NULL;
1971 lookup = lookup->next)
04925e1e 1972 {
66c103b7 1973 if (lookup->constraint >= 0
0112cd26 1974 && CONST_STRNEQ (lookup->name, ".rel"))
04925e1e 1975 {
24cdb50a 1976 int lookrela = lookup->name[4] == 'a';
ba493122 1977
2a36a117
AM
1978 /* .rel.dyn must come before all other reloc sections, to suit
1979 GNU ld.so. */
1980 if (isdyn)
1981 break;
1982
1983 /* Don't place after .rel.plt as doing so results in wrong
1984 dynamic tags. */
1985 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
ba493122 1986 break;
2a36a117
AM
1987
1988 if (rela == lookrela || last_rel == NULL)
24cdb50a 1989 last_rel = lookup;
2a36a117
AM
1990 if ((rela == lookrela || last_rel_alloc == NULL)
1991 && lookup->bfd_section != NULL
ba493122
AM
1992 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1993 last_rel_alloc = lookup;
04925e1e 1994 }
2a36a117
AM
1995
1996 last = lookup;
1997 if (lookup->bfd_section != NULL
1998 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
48f2ff54
AM
1999 {
2000 last_alloc = lookup;
2001 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
2002 last_ro_alloc = lookup;
2003 }
252b5132 2004 }
ba493122
AM
2005
2006 if (last_rel_alloc)
2007 return last_rel_alloc;
2008
2009 if (last_rel)
2010 return last_rel;
2011
48f2ff54
AM
2012 if (last_ro_alloc)
2013 return last_ro_alloc;
2014
2a36a117
AM
2015 if (last_alloc)
2016 return last_alloc;
2017
ba493122 2018 return last;
252b5132
RH
2019}
2020
2e9246e0
AM
2021/* Return whether IN is suitable to be part of OUT. */
2022
2023static bfd_boolean
2024elf_orphan_compatible (asection *in, asection *out)
2025{
2026 /* Non-zero sh_info implies a section with SHF_INFO_LINK with
2027 unknown semantics for the generic linker, or a SHT_REL/SHT_RELA
2028 section where sh_info specifies a symbol table. (We won't see
2029 SHT_GROUP, SHT_SYMTAB or SHT_DYNSYM sections here.) We clearly
2030 can't merge SHT_REL/SHT_RELA using differing symbol tables, and
2031 shouldn't merge sections with differing unknown semantics. */
2032 if (elf_section_data (out)->this_hdr.sh_info
2033 != elf_section_data (in)->this_hdr.sh_info)
2034 return FALSE;
2035 /* We can't merge two sections with differing SHF_EXCLUDE when doing
2036 a relocatable link. */
2037 if (bfd_link_relocatable (&link_info)
2038 && ((elf_section_flags (out) ^ elf_section_flags (in)) & SHF_EXCLUDE) != 0)
2039 return FALSE;
2040 return _bfd_elf_match_sections_by_type (link_info.output_bfd, out,
2041 in->owner, in);
2042}
2043
252b5132
RH
2044/* Place an orphan section. We use this to put random SHF_ALLOC
2045 sections in the right segment. */
2046
c2edb4b8 2047static lang_output_section_statement_type *
8a99a385
AM
2048gld${EMULATION_NAME}_place_orphan (asection *s,
2049 const char *secname,
2050 int constraint)
252b5132 2051{
afd7a018
AM
2052 static struct orphan_save hold[] =
2053 {
2054 { ".text",
2055 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2056 0, 0, 0, 0 },
2057 { ".rodata",
2058 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2059 0, 0, 0, 0 },
d85e71fe
L
2060 { ".tdata",
2061 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
2062 0, 0, 0, 0 },
afd7a018
AM
2063 { ".data",
2064 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2065 0, 0, 0, 0 },
2066 { ".bss",
2067 SEC_ALLOC,
2068 0, 0, 0, 0 },
2069 { 0,
2070 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2071 0, 0, 0, 0 },
2072 { ".interp",
2073 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2074 0, 0, 0, 0 },
2075 { ".sdata",
2076 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
07890c07 2077 0, 0, 0, 0 },
175b7cd4 2078 { ".comment",
07890c07
AM
2079 SEC_HAS_CONTENTS,
2080 0, 0, 0, 0 },
afd7a018
AM
2081 };
2082 enum orphan_save_index
2083 {
2084 orphan_text = 0,
2085 orphan_rodata,
d85e71fe 2086 orphan_tdata,
afd7a018
AM
2087 orphan_data,
2088 orphan_bss,
2089 orphan_rel,
2090 orphan_interp,
07890c07
AM
2091 orphan_sdata,
2092 orphan_nonalloc
afd7a018
AM
2093 };
2094 static int orphan_init_done = 0;
6a345e87 2095 struct orphan_save *place;
afd7a018 2096 lang_output_section_statement_type *after;
252b5132 2097 lang_output_section_statement_type *os;
b5f14a6d 2098 lang_output_section_statement_type *match_by_name = NULL;
24cdb50a 2099 int isdyn = 0;
2e9246e0
AM
2100 int elfinput = s->owner->xvec->flavour == bfd_target_elf_flavour;
2101 int elfoutput = link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour;
2102 unsigned int sh_type = elfinput ? elf_section_type (s) : SHT_NULL;
199af150
AM
2103 flagword flags;
2104 asection *nexts;
252b5132 2105
0e1862bb 2106 if (!bfd_link_relocatable (&link_info)
24cdb50a 2107 && link_info.combreloc
ecca9871 2108 && (s->flags & SEC_ALLOC))
24cdb50a 2109 {
2e9246e0 2110 if (elfinput)
ecca9871
L
2111 switch (sh_type)
2112 {
2113 case SHT_RELA:
2114 secname = ".rela.dyn";
2115 isdyn = 1;
2116 break;
2117 case SHT_REL:
2118 secname = ".rel.dyn";
2119 isdyn = 1;
2120 break;
2121 default:
2122 break;
2123 }
0112cd26 2124 else if (CONST_STRNEQ (secname, ".rel"))
ecca9871
L
2125 {
2126 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2127 isdyn = 1;
2128 }
24cdb50a 2129 }
aea4bd9d 2130
a91e1603 2131 if (!bfd_link_relocatable (&link_info)
2e9246e0
AM
2132 && elfinput
2133 && elfoutput
a91e1603
L
2134 && (s->flags & SEC_ALLOC) != 0
2135 && (elf_section_flags (s) & SHF_GNU_MBIND) != 0)
2136 {
2137 /* Find the output mbind section with the same type, attributes
2138 and sh_info field. */
2139 for (os = &lang_output_section_statement.head->output_section_statement;
2140 os != NULL;
2141 os = os->next)
2142 if (os->bfd_section != NULL
2143 && !bfd_is_abs_section (os->bfd_section)
2144 && (elf_section_flags (os->bfd_section) & SHF_GNU_MBIND) != 0
2145 && ((s->flags & (SEC_ALLOC
2146 | SEC_LOAD
2147 | SEC_HAS_CONTENTS
2148 | SEC_READONLY
2149 | SEC_CODE))
2150 == (os->bfd_section->flags & (SEC_ALLOC
2151 | SEC_LOAD
2152 | SEC_HAS_CONTENTS
2153 | SEC_READONLY
2154 | SEC_CODE)))
2155 && (elf_section_data (os->bfd_section)->this_hdr.sh_info
2156 == elf_section_data (s)->this_hdr.sh_info))
2157 {
2158 lang_add_section (&os->children, s, NULL, os);
2159 return os;
2160 }
2161
2162 /* Create the output mbind section with the ".mbind." prefix
2163 in section name. */
2164 if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2165 secname = ".mbind.bss";
2166 else if ((s->flags & SEC_READONLY) == 0)
2167 secname = ".mbind.data";
2168 else if ((s->flags & SEC_CODE) == 0)
2169 secname = ".mbind.rodata";
2170 else
2171 secname = ".mbind.text";
2172 }
2173
2e9246e0
AM
2174 /* Look through the script to see where to place this section. The
2175 script includes entries added by previous lang_insert_orphan
2176 calls, so this loop puts multiple compatible orphans of the same
2177 name into a single output section. */
2178 if (constraint == 0)
d127ecce
AM
2179 for (os = lang_output_section_find (secname);
2180 os != NULL;
2181 os = next_matching_output_section_statement (os, 0))
2182 {
2183 /* If we don't match an existing output section, tell
2184 lang_insert_orphan to create a new output section. */
2185 constraint = SPECIAL;
2186
2e9246e0
AM
2187 /* Check to see if we already have an output section statement
2188 with this name, and its bfd section has compatible flags.
2189 If the section already exists but does not have any flags
2190 set, then it has been created by the linker, possibly as a
2191 result of a --section-start command line switch. */
d127ecce
AM
2192 if (os->bfd_section != NULL
2193 && (os->bfd_section->flags == 0
2e9246e0 2194 || (((s->flags ^ os->bfd_section->flags)
199af150 2195 & (SEC_LOAD | SEC_ALLOC)) == 0
2e9246e0
AM
2196 && (!elfinput
2197 || !elfoutput
2198 || elf_orphan_compatible (s, os->bfd_section)))))
d127ecce 2199 {
b9c361e0 2200 lang_add_section (&os->children, s, NULL, os);
d127ecce
AM
2201 return os;
2202 }
b5f14a6d
DD
2203
2204 /* Save unused output sections in case we can match them
2205 against orphans later. */
2206 if (os->bfd_section == NULL)
2207 match_by_name = os;
d127ecce 2208 }
252b5132 2209
b5f14a6d
DD
2210 /* If we didn't match an active output section, see if we matched an
2211 unused one and use that. */
2212 if (match_by_name)
2213 {
b9c361e0 2214 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
b5f14a6d
DD
2215 return match_by_name;
2216 }
2217
afd7a018
AM
2218 if (!orphan_init_done)
2219 {
2220 struct orphan_save *ho;
07890c07 2221
afd7a018
AM
2222 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2223 if (ho->name != NULL)
2224 {
2225 ho->os = lang_output_section_find (ho->name);
2226 if (ho->os != NULL && ho->os->flags == 0)
2227 ho->os->flags = ho->flags;
2228 }
2229 orphan_init_done = 1;
2230 }
252b5132
RH
2231
2232 /* If this is a final link, then always put .gnu.warning.SYMBOL
2233 sections into the .text section to get them out of the way. */
0e1862bb 2234 if (bfd_link_executable (&link_info)
bcacc0f5 2235 && CONST_STRNEQ (s->name, ".gnu.warning.")
afd7a018 2236 && hold[orphan_text].os != NULL)
252b5132 2237 {
c2edb4b8 2238 os = hold[orphan_text].os;
b9c361e0 2239 lang_add_section (&os->children, s, NULL, os);
c2edb4b8 2240 return os;
252b5132
RH
2241 }
2242
077fcd6a
L
2243 flags = s->flags;
2244 if (!bfd_link_relocatable (&link_info))
2245 {
2246 nexts = s;
2247 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2248 != NULL)
2249 if (nexts->output_section == NULL
2250 && (nexts->flags & SEC_EXCLUDE) == 0
2251 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2252 && (nexts->owner->flags & DYNAMIC) == 0
2253 && nexts->owner->usrdata != NULL
2254 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2255 ->flags.just_syms)
2256 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2257 s->owner, s))
2258 flags = (((flags ^ SEC_READONLY)
2259 | (nexts->flags ^ SEC_READONLY))
2260 ^ SEC_READONLY);
2261 }
2262
252b5132
RH
2263 /* Decide which segment the section should go in based on the
2264 section name and section flags. We put loadable .note sections
2265 right after the .interp section, so that the PT_NOTE segment is
2266 stored right after the program headers where the OS can read it
2267 in the first page. */
aea4bd9d 2268
71bfc0ae 2269 place = NULL;
199af150 2270 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
07890c07 2271 place = &hold[orphan_nonalloc];
199af150 2272 else if ((flags & SEC_ALLOC) == 0)
71bfc0ae 2273 ;
199af150 2274 else if ((flags & SEC_LOAD) != 0
2e9246e0
AM
2275 && ((elfinput && sh_type == SHT_NOTE)
2276 || (!elfinput && CONST_STRNEQ (secname, ".note"))))
afd7a018 2277 place = &hold[orphan_interp];
199af150 2278 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
afd7a018 2279 place = &hold[orphan_bss];
199af150 2280 else if ((flags & SEC_SMALL_DATA) != 0)
afd7a018 2281 place = &hold[orphan_sdata];
199af150 2282 else if ((flags & SEC_THREAD_LOCAL) != 0)
d85e71fe 2283 place = &hold[orphan_tdata];
199af150 2284 else if ((flags & SEC_READONLY) == 0)
afd7a018 2285 place = &hold[orphan_data];
2e9246e0
AM
2286 else if (((elfinput && (sh_type == SHT_RELA || sh_type == SHT_REL))
2287 || (!elfinput && CONST_STRNEQ (secname, ".rel")))
199af150 2288 && (flags & SEC_LOAD) != 0)
afd7a018 2289 place = &hold[orphan_rel];
199af150 2290 else if ((flags & SEC_CODE) == 0)
afd7a018
AM
2291 place = &hold[orphan_rodata];
2292 else
2293 place = &hold[orphan_text];
71bfc0ae 2294
afd7a018 2295 after = NULL;
5ba47421 2296 if (place != NULL)
252b5132 2297 {
afd7a018 2298 if (place->os == NULL)
5ba47421 2299 {
afd7a018
AM
2300 if (place->name != NULL)
2301 place->os = lang_output_section_find (place->name);
2302 else
2303 place->os = output_rel_find (s, isdyn);
5ba47421 2304 }
afd7a018
AM
2305 after = place->os;
2306 if (after == NULL)
93638471
AM
2307 after
2308 = lang_output_section_find_by_flags (s, flags, &place->os,
2309 _bfd_elf_match_sections_by_type);
afd7a018
AM
2310 if (after == NULL)
2311 /* *ABS* is always the first output section statement. */
2312 after = &lang_output_section_statement.head->output_section_statement;
252b5132
RH
2313 }
2314
c2edb4b8 2315 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
252b5132 2316}
c56feb2b
AM
2317EOF
2318fi
2319
eaeb0a9d 2320if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
92b93329 2321fragment <<EOF
252b5132 2322
deb04cdb 2323static void
eaeb0a9d 2324gld${EMULATION_NAME}_after_allocation (void)
deb04cdb 2325{
75938853
AM
2326 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2327
2328 if (need_layout < 0)
d003af55 2329 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
75938853
AM
2330 else
2331 gld${EMULATION_NAME}_map_segments (need_layout);
73d074b4 2332}
41392f03
AM
2333EOF
2334fi
2335
2336if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
92b93329 2337fragment <<EOF
252b5132
RH
2338
2339static char *
0c7a8e5a 2340gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
2341EOF
2342
7225345d 2343if test x"$COMPILE_IN" = xyes
252b5132
RH
2344then
2345# Scripts compiled in.
2346
2347# sed commands to quote an ld script as a C string.
597e2591 2348sc="-f stringify.sed"
252b5132 2349
92b93329 2350fragment <<EOF
60bcf0fa 2351{
252b5132
RH
2352 *isfile = 0;
2353
0e1862bb 2354 if (bfd_link_relocatable (&link_info) && config.build_constructors)
597e2591 2355 return
252b5132 2356EOF
afd7a018 2357sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
0e1862bb 2358echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
afd7a018
AM
2359sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2360echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2361sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
61585df2 2362if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
afd7a018
AM
2363echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2364sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
db6751f2 2365fi
36af4a4e
JJ
2366if test -n "$GENERATE_PIE_SCRIPT" ; then
2367if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
0e1862bb
L
2368echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2369echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2370echo ' && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 2371echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018 2372sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
0e1862bb
L
2373echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2374echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
afd7a018 2375sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
36af4a4e 2376fi
0e1862bb 2377echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
afd7a018 2378sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
36af4a4e 2379fi
252b5132 2380if test -n "$GENERATE_SHLIB_SCRIPT" ; then
82434356 2381if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
fb24d531
L
2382echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2383echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2384echo ' && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 2385echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018 2386sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
fb24d531
L
2387echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2388echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
afd7a018 2389sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
82434356 2390fi
0e1862bb 2391echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
afd7a018 2392sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
252b5132 2393fi
82434356 2394if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
fb24d531
L
2395echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
2396echo ' && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 2397echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018
AM
2398sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2399echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2400sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
82434356 2401fi
afd7a018
AM
2402echo ' ; else return' >> e${EMULATION_NAME}.c
2403sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2404echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
2405
2406else
2407# Scripts read from the filesystem.
2408
92b93329 2409fragment <<EOF
60bcf0fa 2410{
252b5132
RH
2411 *isfile = 1;
2412
0e1862bb 2413 if (bfd_link_relocatable (&link_info) && config.build_constructors)
252b5132 2414 return "ldscripts/${EMULATION_NAME}.xu";
0e1862bb 2415 else if (bfd_link_relocatable (&link_info))
252b5132
RH
2416 return "ldscripts/${EMULATION_NAME}.xr";
2417 else if (!config.text_read_only)
2418 return "ldscripts/${EMULATION_NAME}.xbn";
a060b769
AM
2419EOF
2420if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2421else
92b93329 2422fragment <<EOF
252b5132
RH
2423 else if (!config.magic_demand_paged)
2424 return "ldscripts/${EMULATION_NAME}.xn";
a060b769
AM
2425EOF
2426fi
36af4a4e
JJ
2427if test -n "$GENERATE_PIE_SCRIPT" ; then
2428if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2429fragment <<EOF
0e1862bb
L
2430 else if (bfd_link_pie (&link_info)
2431 && link_info.combreloc
2432 && link_info.relro
2433 && (link_info.flags & DF_BIND_NOW))
8c37241b 2434 return "ldscripts/${EMULATION_NAME}.xdw";
0e1862bb
L
2435 else if (bfd_link_pie (&link_info)
2436 && link_info.combreloc)
36af4a4e
JJ
2437 return "ldscripts/${EMULATION_NAME}.xdc";
2438EOF
2439fi
92b93329 2440fragment <<EOF
0e1862bb 2441 else if (bfd_link_pie (&link_info))
36af4a4e
JJ
2442 return "ldscripts/${EMULATION_NAME}.xd";
2443EOF
2444fi
a060b769
AM
2445if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2446if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2447fragment <<EOF
0e1862bb 2448 else if (bfd_link_dll (&link_info) && link_info.combreloc
fbfca19e 2449 && link_info.relro && (link_info.flags & DF_BIND_NOW))
8c37241b 2450 return "ldscripts/${EMULATION_NAME}.xsw";
0e1862bb 2451 else if (bfd_link_dll (&link_info) && link_info.combreloc)
a060b769
AM
2452 return "ldscripts/${EMULATION_NAME}.xsc";
2453EOF
2454fi
92b93329 2455fragment <<EOF
0e1862bb 2456 else if (bfd_link_dll (&link_info))
252b5132 2457 return "ldscripts/${EMULATION_NAME}.xs";
a060b769
AM
2458EOF
2459fi
2460if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2461fragment <<EOF
8c37241b 2462 else if (link_info.combreloc && link_info.relro
fbfca19e 2463 && (link_info.flags & DF_BIND_NOW))
8c37241b 2464 return "ldscripts/${EMULATION_NAME}.xw";
a060b769
AM
2465 else if (link_info.combreloc)
2466 return "ldscripts/${EMULATION_NAME}.xc";
2467EOF
2468fi
92b93329 2469fragment <<EOF
252b5132
RH
2470 else
2471 return "ldscripts/${EMULATION_NAME}.x";
2472}
252b5132 2473
3b108066 2474EOF
41392f03
AM
2475fi
2476fi
3b108066 2477
e0ee487b 2478if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
92b93329 2479fragment <<EOF
e0ee487b
L
2480 $PARSE_AND_LIST_PROLOGUE
2481EOF
2482fi
2483
92b93329 2484fragment <<EOF
e0ee487b 2485
29063f8b
NC
2486enum elf_options
2487{
2488 OPTION_DISABLE_NEW_DTAGS = 400,
2489 OPTION_ENABLE_NEW_DTAGS,
2490 OPTION_GROUP,
2491 OPTION_EH_FRAME_HDR,
2492 OPTION_NO_EH_FRAME_HDR,
2493 OPTION_EXCLUDE_LIBS,
2494 OPTION_HASH_STYLE,
2495 OPTION_BUILD_ID,
2496 OPTION_AUDIT,
2497 OPTION_COMPRESS_DEBUG
2498};
e13629bc 2499
3bcf5557 2500static void
0c7a8e5a
AM
2501gld${EMULATION_NAME}_add_options
2502 (int ns, char **shortopts, int nl, struct option **longopts,
2503 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
e0ee487b 2504{
fb42df5e
AM
2505EOF
2506if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2507fragment <<EOF
7ee314fa 2508 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
fb42df5e
AM
2509EOF
2510else
2511fragment <<EOF
2512 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2513EOF
2514fi
2515fragment <<EOF
3bcf5557 2516 static const struct option xtra_long[] = {
fb42df5e
AM
2517EOF
2518if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2519fragment <<EOF
7ee314fa 2520 {"audit", required_argument, NULL, OPTION_AUDIT},
fb42df5e
AM
2521 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2522EOF
2523fi
2524fragment <<EOF
2525 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
0ce398f1 2526 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
e0ee487b 2527EOF
e0ee487b 2528if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
92b93329 2529fragment <<EOF
fb42df5e 2530 {"depaudit", required_argument, NULL, 'P'},
3bcf5557
AM
2531 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2532 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2533 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
29063f8b 2534 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
b58f81ae 2535 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
fdc90cb4 2536 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
e0ee487b
L
2537EOF
2538fi
e0ee487b 2539if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
92b93329 2540fragment <<EOF
3bcf5557 2541 $PARSE_AND_LIST_LONGOPTS
e0ee487b
L
2542EOF
2543fi
92b93329 2544fragment <<EOF
3bcf5557
AM
2545 {NULL, no_argument, NULL, 0}
2546 };
2547
2548 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2549 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2550 *longopts = (struct option *)
2551 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2552 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2553}
04925e1e 2554
24382dca 2555#define DEFAULT_BUILD_ID_STYLE "sha1"
c0065db7 2556
3bcf5557 2557static bfd_boolean
0c7a8e5a 2558gld${EMULATION_NAME}_handle_option (int optc)
e0ee487b 2559{
e0ee487b
L
2560 switch (optc)
2561 {
2562 default:
3bcf5557 2563 return FALSE;
6c1439be 2564
c0065db7 2565 case OPTION_BUILD_ID:
30e8ee25 2566 if (emit_note_gnu_build_id != NULL)
c0065db7 2567 {
30e8ee25
AM
2568 free ((char *) emit_note_gnu_build_id);
2569 emit_note_gnu_build_id = NULL;
c0065db7
RM
2570 }
2571 if (optarg == NULL)
2572 optarg = DEFAULT_BUILD_ID_STYLE;
2573 if (strcmp (optarg, "none"))
30e8ee25 2574 emit_note_gnu_build_id = xstrdup (optarg);
c0065db7 2575 break;
fb42df5e 2576
0ce398f1
L
2577 case OPTION_COMPRESS_DEBUG:
2578 if (strcasecmp (optarg, "none") == 0)
2579 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2580 else if (strcasecmp (optarg, "zlib") == 0)
19a7fe52 2581 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
0ce398f1
L
2582 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2583 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2584 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2585 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2586 else
2587 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2588 optarg);
2589 break;
fb42df5e
AM
2590EOF
2591
2592if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2593fragment <<EOF
7ee314fa 2594 case OPTION_AUDIT:
4724d37e 2595 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
7ee314fa 2596 break;
fb42df5e 2597
7ee314fa
AM
2598 case 'P':
2599 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2600 break;
c0065db7 2601
6c1439be 2602 case OPTION_DISABLE_NEW_DTAGS:
b34976b6 2603 link_info.new_dtags = FALSE;
6c1439be
L
2604 break;
2605
2606 case OPTION_ENABLE_NEW_DTAGS:
b34976b6 2607 link_info.new_dtags = TRUE;
6c1439be
L
2608 break;
2609
65765700 2610 case OPTION_EH_FRAME_HDR:
2f0c68f2 2611 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
65765700
JJ
2612 break;
2613
29063f8b
NC
2614 case OPTION_NO_EH_FRAME_HDR:
2615 link_info.eh_frame_hdr_type = 0;
2616 break;
2617
a1ab1d2a
UD
2618 case OPTION_GROUP:
2619 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2620 /* Groups must be self-contained. */
560e09e9
NC
2621 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2622 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
a1ab1d2a
UD
2623 break;
2624
b58f81ae
DJ
2625 case OPTION_EXCLUDE_LIBS:
2626 add_excluded_libs (optarg);
2627 break;
2628
fdc90cb4
JJ
2629 case OPTION_HASH_STYLE:
2630 link_info.emit_hash = FALSE;
2631 link_info.emit_gnu_hash = FALSE;
2632 if (strcmp (optarg, "sysv") == 0)
2633 link_info.emit_hash = TRUE;
2634 else if (strcmp (optarg, "gnu") == 0)
2635 link_info.emit_gnu_hash = TRUE;
2636 else if (strcmp (optarg, "both") == 0)
2637 {
2638 link_info.emit_hash = TRUE;
2639 link_info.emit_gnu_hash = TRUE;
2640 }
2641 else
2642 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2643 break;
2644
fb42df5e
AM
2645EOF
2646fi
2647fragment <<EOF
e0ee487b 2648 case 'z':
fb42df5e
AM
2649 if (strcmp (optarg, "defs") == 0)
2650 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2651 else if (strcmp (optarg, "muldefs") == 0)
2652 link_info.allow_multiple_definition = TRUE;
2653 else if (CONST_STRNEQ (optarg, "max-page-size="))
2654 {
2655 char *end;
2656
2657 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2658 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2659 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2660 optarg + 14);
2661 }
2662 else if (CONST_STRNEQ (optarg, "common-page-size="))
2663 {
2664 char *end;
2665 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2666 if (*end
2667 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2668 einfo (_("%P%F: invalid common page size \`%s'\n"),
2669 optarg + 17);
2670 }
04c3a755
NS
2671 else if (CONST_STRNEQ (optarg, "stack-size="))
2672 {
2673 char *end;
2674 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2675 if (*end || link_info.stacksize < 0)
2676 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2677 if (!link_info.stacksize)
2678 /* Use -1 for explicit no-stack, because zero means
2679 'default'. */
2680 link_info.stacksize = -1;
2681 }
fb42df5e
AM
2682 else if (strcmp (optarg, "execstack") == 0)
2683 {
2684 link_info.execstack = TRUE;
2685 link_info.noexecstack = FALSE;
2686 }
2687 else if (strcmp (optarg, "noexecstack") == 0)
2688 {
2689 link_info.noexecstack = TRUE;
2690 link_info.execstack = FALSE;
2691 }
93ab9c0d
NC
2692 else if (strcmp (optarg, "globalaudit") == 0)
2693 {
2694 link_info.flags_1 |= DF_1_GLOBAUDIT;
2695 }
fb42df5e 2696EOF
d258b828 2697
fb42df5e
AM
2698if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2699fragment <<EOF
b039ef04
L
2700 else if (strcmp (optarg, "global") == 0)
2701 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
fb42df5e 2702 else if (strcmp (optarg, "initfirst") == 0)
e0ee487b
L
2703 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2704 else if (strcmp (optarg, "interpose") == 0)
2705 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2706 else if (strcmp (optarg, "loadfltr") == 0)
2707 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2708 else if (strcmp (optarg, "nodefaultlib") == 0)
2709 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2710 else if (strcmp (optarg, "nodelete") == 0)
2711 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2712 else if (strcmp (optarg, "nodlopen") == 0)
2713 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2714 else if (strcmp (optarg, "nodump") == 0)
2715 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2716 else if (strcmp (optarg, "now") == 0)
2717 {
2718 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2719 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2720 }
5fa222e4
AM
2721 else if (strcmp (optarg, "lazy") == 0)
2722 {
2723 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2724 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2725 }
e0ee487b
L
2726 else if (strcmp (optarg, "origin") == 0)
2727 {
2728 link_info.flags |= (bfd_vma) DF_ORIGIN;
2729 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2730 }
db6751f2 2731 else if (strcmp (optarg, "combreloc") == 0)
b34976b6 2732 link_info.combreloc = TRUE;
db6751f2 2733 else if (strcmp (optarg, "nocombreloc") == 0)
b34976b6 2734 link_info.combreloc = FALSE;
8bd621d8 2735 else if (strcmp (optarg, "nocopyreloc") == 0)
0c7a8e5a 2736 link_info.nocopyreloc = TRUE;
8c37241b
JJ
2737 else if (strcmp (optarg, "relro") == 0)
2738 link_info.relro = TRUE;
2739 else if (strcmp (optarg, "norelro") == 0)
2740 link_info.relro = FALSE;
b8871f35
L
2741 else if (strcmp (optarg, "common") == 0)
2742 link_info.elf_stt_common = elf_stt_common;
2743 else if (strcmp (optarg, "nocommon") == 0)
2744 link_info.elf_stt_common = no_elf_stt_common;
c192a133
AM
2745 else if (strcmp (optarg, "text") == 0)
2746 link_info.error_textrel = TRUE;
2747 else if (strcmp (optarg, "notext") == 0)
2748 link_info.error_textrel = FALSE;
2749 else if (strcmp (optarg, "textoff") == 0)
2750 link_info.error_textrel = FALSE;
88b882e9 2751EOF
fb42df5e 2752fi
88b882e9 2753
eba27bd7
L
2754if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2755fragment <<EOF
2756 $PARSE_AND_LIST_ARGS_CASE_Z
2757EOF
2758fi
2759
92b93329 2760fragment <<EOF
fb42df5e
AM
2761 else
2762 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
6c1439be 2763 break;
e0ee487b 2764EOF
e0ee487b
L
2765
2766if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
92b93329 2767fragment <<EOF
e0ee487b
L
2768 $PARSE_AND_LIST_ARGS_CASES
2769EOF
2770fi
2771
92b93329 2772fragment <<EOF
e0ee487b
L
2773 }
2774
3bcf5557 2775 return TRUE;
e0ee487b
L
2776}
2777
41392f03 2778EOF
41392f03 2779
4b209b22 2780if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
c58212ea 2781gld_list_options="gld${EMULATION_NAME}_list_options"
eba27bd7 2782if test -n "$PARSE_AND_LIST_OPTIONS"; then
92b93329 2783fragment <<EOF
41392f03 2784
e0ee487b 2785static void
0c7a8e5a 2786gld${EMULATION_NAME}_list_options (FILE * file)
e0ee487b 2787{
fb42df5e 2788EOF
e0ee487b
L
2789
2790if test -n "$PARSE_AND_LIST_OPTIONS" ; then
92b93329 2791fragment <<EOF
e0ee487b
L
2792 $PARSE_AND_LIST_OPTIONS
2793EOF
2794fi
2795
92b93329 2796fragment <<EOF
e0ee487b
L
2797}
2798EOF
c58212ea
L
2799else
2800 gld_list_options="NULL"
2801fi
e0ee487b
L
2802
2803if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
92b93329 2804fragment <<EOF
e0ee487b
L
2805 $PARSE_AND_LIST_EPILOGUE
2806EOF
2807fi
41392f03 2808fi
e0ee487b 2809
92b93329 2810fragment <<EOF
252b5132 2811
60bcf0fa 2812struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132 2813{
41392f03
AM
2814 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2815 ${LDEMUL_SYSLIB-syslib_default},
2816 ${LDEMUL_HLL-hll_default},
5fe2850d 2817 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
41392f03 2818 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
5c3261b0 2819 ${LDEMUL_AFTER_CHECK_RELOCS-after_check_relocs_default},
eaeb0a9d 2820 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
41392f03
AM
2821 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2822 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2823 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2824 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
252b5132
RH
2825 "${EMULATION_NAME}",
2826 "${OUTPUT_FORMAT}",
eaeb0a9d 2827 ${LDEMUL_FINISH-finish_default},
41392f03
AM
2828 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2829 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2830 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2831 ${LDEMUL_SET_SYMBOLS-NULL},
3bcf5557
AM
2832 ${LDEMUL_PARSE_ARGS-NULL},
2833 gld${EMULATION_NAME}_add_options,
2834 gld${EMULATION_NAME}_handle_option,
41392f03 2835 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
c58212ea 2836 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
4a43e768 2837 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
41392f03 2838 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
7a2f2d82
DD
2839 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2840 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}
252b5132
RH
2841};
2842EOF
This page took 1.036309 seconds and 4 git commands to generate.