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