bfd/
[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}
e3dc8847 15 Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
aa820537
AM
16 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
17 Free Software Foundation, Inc.
252b5132
RH
18 Written by Steve Chamberlain <sac@cygnus.com>
19 ELF support by Ian Lance Taylor <ian@cygnus.com>
20
f96b4a7b
NC
21 This file is part of the GNU Binutils.
22
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 3 of the License, or
26 (at your option) any later version.
27
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
32
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
36 MA 02110-1301, USA. */
252b5132
RH
37
38#define TARGET_IS_${EMULATION_NAME}
39
252b5132 40#include "sysdep.h"
3db64b00 41#include "bfd.h"
1c9acd94 42#include "libiberty.h"
3882b010 43#include "safe-ctype.h"
fcf65871 44#include "getopt.h"
24382dca
RM
45#include "md5.h"
46#include "sha1.h"
47#include <fcntl.h>
252b5132
RH
48
49#include "bfdlink.h"
50
51#include "ld.h"
52#include "ldmain.h"
252b5132
RH
53#include "ldmisc.h"
54#include "ldexp.h"
55#include "ldlang.h"
b71e2778
AM
56#include "ldfile.h"
57#include "ldemul.h"
df2a7313 58#include <ldgram.h>
e0ee487b 59#include "elf/common.h"
ecca9871 60#include "elf-bfd.h"
252b5132 61
0c7a8e5a
AM
62/* Declare functions used by various EXTRA_EM_FILEs. */
63static void gld${EMULATION_NAME}_before_parse (void);
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
711c0baa 73 *-*-linux-* | *-*-k*bsd*-*)
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/:.*//'`);
b34976b6
AM
103 config.dynamic_link = ${DYNAMIC_LINK-TRUE};
104 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
252b5132
RH
105}
106
41392f03
AM
107EOF
108fi
109
4a43e768 110if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
92b93329 111fragment <<EOF
4a43e768
AM
112/* Handle as_needed DT_NEEDED. */
113
114static bfd_boolean
115gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
116{
96d56e9f 117 int link_class = 0;
4a43e768
AM
118
119 /* Tell the ELF linker that we don't want the output file to have a
120 DT_NEEDED entry for this file, unless it is used to resolve
121 references in a regular object. */
e56f61be 122 if (entry->as_needed)
96d56e9f 123 link_class = DYN_AS_NEEDED;
e56f61be
L
124
125 /* Tell the ELF linker that we don't want the output file to have a
126 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
127 this file at all. */
128 if (!entry->add_needed)
96d56e9f 129 link_class |= DYN_NO_ADD_NEEDED;
e56f61be 130
12b9ff6c
L
131 if (entry->just_syms_flag
132 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
133 einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
134 entry->the_bfd);
135
96d56e9f 136 if (!link_class
e56f61be
L
137 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
138 return FALSE;
139
1e9cc1c2
NC
140 bfd_elf_set_dyn_lib_class (entry->the_bfd,
141 (enum dynamic_lib_link_class) link_class);
4a43e768
AM
142
143 /* Continue on with normal load_symbols processing. */
144 return FALSE;
145}
146EOF
147fi
148
92b93329 149fragment <<EOF
252b5132
RH
150
151/* These variables are required to pass information back and forth
152 between after_open and check_needed and stat_needed and vercheck. */
153
154static struct bfd_link_needed_list *global_needed;
155static struct stat global_stat;
e13629bc 156static lang_input_statement_type *global_found;
252b5132 157static struct bfd_link_needed_list *global_vercheck_needed;
b34976b6 158static bfd_boolean global_vercheck_failed;
252b5132 159
7ee314fa
AM
160/* These variables are used to implement target options */
161
162static char *audit; /* colon (typically) separated list of libs */
163static char *depaudit; /* colon (typically) separated list of libs */
252b5132 164
04925e1e
AM
165/* On Linux, it's possible to have different versions of the same
166 shared library linked against different versions of libc. The
167 dynamic linker somehow tags which libc version to use in
168 /etc/ld.so.cache, and, based on the libc that it sees in the
169 executable, chooses which version of the shared library to use.
252b5132 170
04925e1e
AM
171 We try to do a similar check here by checking whether this shared
172 library needs any other shared libraries which may conflict with
173 libraries we have already included in the link. If it does, we
174 skip it, and try to find another shared library farther on down the
175 link path.
252b5132 176
04925e1e
AM
177 This is called via lang_for_each_input_file.
178 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
f813923c 179 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
04925e1e 180 a conflicting version. */
252b5132 181
04925e1e 182static void
0c7a8e5a 183gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
04925e1e 184{
1c9acd94 185 const char *soname;
04925e1e 186 struct bfd_link_needed_list *l;
252b5132 187
04925e1e
AM
188 if (global_vercheck_failed)
189 return;
190 if (s->the_bfd == NULL
191 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
192 return;
252b5132 193
04925e1e
AM
194 soname = bfd_elf_get_dt_soname (s->the_bfd);
195 if (soname == NULL)
fed2999d 196 soname = lbasename (bfd_get_filename (s->the_bfd));
04925e1e
AM
197
198 for (l = global_vercheck_needed; l != NULL; l = l->next)
199 {
200 const char *suffix;
201
1c9acd94 202 if (strcmp (soname, l->name) == 0)
04925e1e
AM
203 {
204 /* Probably can't happen, but it's an easy check. */
205 continue;
252b5132
RH
206 }
207
04925e1e 208 if (strchr (l->name, '/') != NULL)
252b5132
RH
209 continue;
210
04925e1e
AM
211 suffix = strstr (l->name, ".so.");
212 if (suffix == NULL)
213 continue;
214
215 suffix += sizeof ".so." - 1;
216
1c9acd94 217 if (strncmp (soname, l->name, suffix - l->name) == 0)
04925e1e
AM
218 {
219 /* Here we know that S is a dynamic object FOO.SO.VER1, and
0c7a8e5a
AM
220 the object we are considering needs a dynamic object
221 FOO.SO.VER2, and VER1 and VER2 are different. This
222 appears to be a version mismatch, so we tell the caller
223 to try a different version of this library. */
b34976b6 224 global_vercheck_failed = TRUE;
04925e1e
AM
225 return;
226 }
252b5132
RH
227 }
228}
229
252b5132 230
04925e1e
AM
231/* See if an input file matches a DT_NEEDED entry by running stat on
232 the file. */
233
234static void
0c7a8e5a 235gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
252b5132 236{
04925e1e
AM
237 struct stat st;
238 const char *suffix;
239 const char *soname;
252b5132 240
e13629bc 241 if (global_found != NULL)
04925e1e
AM
242 return;
243 if (s->the_bfd == NULL)
244 return;
e13629bc
AM
245
246 /* If this input file was an as-needed entry, and wasn't found to be
247 needed at the stage it was linked, then don't say we have loaded it. */
248 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
7cedef86 249 return;
04925e1e
AM
250
251 if (bfd_stat (s->the_bfd, &st) != 0)
252b5132 252 {
04925e1e
AM
253 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
254 return;
255 }
252b5132 256
9eabd475
ZW
257 /* Some operating systems, e.g. Windows, do not provide a meaningful
258 st_ino; they always set it to zero. (Windows does provide a
259 meaningful st_dev.) Do not indicate a duplicate library in that
260 case. While there is no guarantee that a system that provides
261 meaningful inode numbers will never set st_ino to zero, this is
262 merely an optimization, so we do not need to worry about false
263 negatives. */
04925e1e 264 if (st.st_dev == global_stat.st_dev
9eabd475
ZW
265 && st.st_ino == global_stat.st_ino
266 && st.st_ino != 0)
04925e1e 267 {
e13629bc 268 global_found = s;
04925e1e
AM
269 return;
270 }
252b5132 271
04925e1e
AM
272 /* We issue a warning if it looks like we are including two
273 different versions of the same shared library. For example,
274 there may be a problem if -lc picks up libc.so.6 but some other
275 shared library has a DT_NEEDED entry of libc.so.5. This is a
f813923c 276 heuristic test, and it will only work if the name looks like
04925e1e
AM
277 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
278 If we really want to issue warnings about mixing version numbers
279 of shared libraries, we need to find a better way. */
252b5132 280
04925e1e
AM
281 if (strchr (global_needed->name, '/') != NULL)
282 return;
283 suffix = strstr (global_needed->name, ".so.");
284 if (suffix == NULL)
285 return;
286 suffix += sizeof ".so." - 1;
252b5132 287
04925e1e
AM
288 soname = bfd_elf_get_dt_soname (s->the_bfd);
289 if (soname == NULL)
fed2999d 290 soname = lbasename (s->filename);
252b5132 291
cde43e70 292 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
04925e1e 293 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
1c9acd94 294 global_needed->name, global_needed->by, soname);
252b5132
RH
295}
296
e56f61be
L
297struct dt_needed
298{
299 bfd *by;
300 const char *name;
301};
04925e1e 302
252b5132
RH
303/* This function is called for each possible name for a dynamic object
304 named by a DT_NEEDED entry. The FORCE parameter indicates whether
305 to skip the check for a conflicting version. */
306
b34976b6 307static bfd_boolean
e56f61be
L
308gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
309 int force)
252b5132
RH
310{
311 bfd *abfd;
e56f61be 312 const char *name = needed->name;
ec4eb78a 313 const char *soname;
96d56e9f 314 int link_class;
252b5132 315
f13a99db 316 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
252b5132 317 if (abfd == NULL)
b34976b6 318 return FALSE;
252b5132
RH
319 if (! bfd_check_format (abfd, bfd_object))
320 {
cde43e70 321 bfd_close (abfd);
b34976b6 322 return FALSE;
252b5132
RH
323 }
324 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
325 {
cde43e70 326 bfd_close (abfd);
b34976b6 327 return FALSE;
252b5132
RH
328 }
329
c4bb8067 330 /* For DT_NEEDED, they have to match. */
f13a99db 331 if (abfd->xvec != link_info.output_bfd->xvec)
c4bb8067
L
332 {
333 bfd_close (abfd);
b34976b6 334 return FALSE;
c4bb8067
L
335 }
336
252b5132
RH
337 /* Check whether this object would include any conflicting library
338 versions. If FORCE is set, then we skip this check; we use this
339 the second time around, if we couldn't find any compatible
340 instance of the shared library. */
341
342 if (! force)
343 {
344 struct bfd_link_needed_list *needed;
345
346 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
347 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
348
349 if (needed != NULL)
350 {
351 global_vercheck_needed = needed;
b34976b6 352 global_vercheck_failed = FALSE;
252b5132
RH
353 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
354 if (global_vercheck_failed)
355 {
cde43e70 356 bfd_close (abfd);
b34976b6 357 /* Return FALSE to force the caller to move on to try
0c7a8e5a 358 another file on the search path. */
b34976b6 359 return FALSE;
252b5132
RH
360 }
361
362 /* But wait! It gets much worse. On Linux, if a shared
0c7a8e5a
AM
363 library does not use libc at all, we are supposed to skip
364 it the first time around in case we encounter a shared
365 library later on with the same name which does use the
366 version of libc that we want. This is much too horrible
367 to use on any system other than Linux. */
252b5132
RH
368
369EOF
370case ${target} in
711c0baa 371 *-*-linux-* | *-*-k*bsd*-*)
92b93329 372 fragment <<EOF
252b5132
RH
373 {
374 struct bfd_link_needed_list *l;
375
376 for (l = needed; l != NULL; l = l->next)
0112cd26 377 if (CONST_STRNEQ (l->name, "libc.so"))
252b5132
RH
378 break;
379 if (l == NULL)
380 {
cde43e70 381 bfd_close (abfd);
b34976b6 382 return FALSE;
252b5132
RH
383 }
384 }
385
386EOF
387 ;;
388esac
92b93329 389fragment <<EOF
252b5132
RH
390 }
391 }
392
393 /* We've found a dynamic object matching the DT_NEEDED entry. */
394
04925e1e
AM
395 /* We have already checked that there is no other input file of the
396 same name. We must now check again that we are not including the
397 same file twice. We need to do this because on many systems
398 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
399 reference libc.so.1. If we have already included libc.so, we
400 don't want to include libc.so.1 if they are the same file, and we
401 can only check that using stat. */
402
403 if (bfd_stat (abfd, &global_stat) != 0)
404 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
ec4eb78a
L
405
406 /* First strip off everything before the last '/'. */
fed2999d 407 soname = lbasename (abfd->filename);
ec4eb78a
L
408
409 if (trace_file_tries)
410 info_msg (_("found %s at %s\n"), soname, name);
411
e13629bc 412 global_found = NULL;
04925e1e 413 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
e13629bc 414 if (global_found != NULL)
04925e1e 415 {
b34976b6 416 /* Return TRUE to indicate that we found the file, even though
0c7a8e5a 417 we aren't going to do anything with it. */
b34976b6 418 return TRUE;
04925e1e
AM
419 }
420
4a43e768
AM
421 /* Specify the soname to use. */
422 bfd_elf_set_dt_needed_name (abfd, soname);
04925e1e 423
4a43e768
AM
424 /* Tell the ELF linker that we don't want the output file to have a
425 DT_NEEDED entry for this file, unless it is used to resolve
426 references in a regular object. */
96d56e9f 427 link_class = DYN_DT_NEEDED;
e56f61be
L
428
429 /* Tell the ELF linker that we don't want the output file to have a
430 DT_NEEDED entry for this file at all if the entry is from a file
431 with DYN_NO_ADD_NEEDED. */
7e9f0867
AM
432 if (needed->by != NULL
433 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
96d56e9f 434 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
e56f61be 435
1e9cc1c2 436 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
04925e1e
AM
437
438 /* Add this file into the symbol table. */
439 if (! bfd_link_add_symbols (abfd, &link_info))
440 einfo ("%F%B: could not read symbols: %E\n", abfd);
441
b34976b6 442 return TRUE;
04925e1e
AM
443}
444
445
446/* Search for a needed file in a path. */
447
b34976b6 448static bfd_boolean
e56f61be
L
449gld${EMULATION_NAME}_search_needed (const char *path,
450 struct dt_needed *n, int force)
04925e1e
AM
451{
452 const char *s;
e56f61be 453 const char *name = n->name;
04925e1e 454 size_t len;
e56f61be 455 struct dt_needed needed;
04925e1e 456
cc5ce052 457 if (name[0] == '/')
e56f61be 458 return gld${EMULATION_NAME}_try_needed (n, force);
cc5ce052 459
04925e1e 460 if (path == NULL || *path == '\0')
b34976b6 461 return FALSE;
e56f61be
L
462
463 needed.by = n->by;
464 needed.name = n->name;
465
04925e1e
AM
466 len = strlen (name);
467 while (1)
468 {
469 char *filename, *sset;
470
c76308d2 471 s = strchr (path, config.rpath_separator);
04925e1e
AM
472 if (s == NULL)
473 s = path + strlen (path);
474
475 filename = (char *) xmalloc (s - path + len + 2);
476 if (s == path)
477 sset = filename;
478 else
479 {
480 memcpy (filename, path, s - path);
481 filename[s - path] = '/';
482 sset = filename + (s - path) + 1;
483 }
484 strcpy (sset, name);
485
e56f61be
L
486 needed.name = filename;
487 if (gld${EMULATION_NAME}_try_needed (&needed, force))
b34976b6 488 return TRUE;
04925e1e
AM
489
490 free (filename);
491
492 if (*s == '\0')
493 break;
494 path = s + 1;
495 }
496
b34976b6 497 return FALSE;
04925e1e
AM
498}
499
500EOF
9c8ebd6a 501if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 502 fragment <<EOF
9c8ebd6a 503
c76308d2
RS
504/* Add the sysroot to every entry in a path separated by
505 config.rpath_separator. */
9c8ebd6a
DJ
506
507static char *
0c7a8e5a 508gld${EMULATION_NAME}_add_sysroot (const char *path)
9c8ebd6a
DJ
509{
510 int len, colons, i;
511 char *ret, *p;
512
513 len = strlen (path);
514 colons = 0;
515 i = 0;
516 while (path[i])
c76308d2 517 if (path[i++] == config.rpath_separator)
9c8ebd6a
DJ
518 colons++;
519
520 if (path[i])
521 colons++;
522
42644a89 523 len = len + (colons + 1) * strlen (ld_sysroot);
9c8ebd6a
DJ
524 ret = xmalloc (len + 1);
525 strcpy (ret, ld_sysroot);
526 p = ret + strlen (ret);
527 i = 0;
528 while (path[i])
c76308d2 529 if (path[i] == config.rpath_separator)
9c8ebd6a 530 {
0c7a8e5a 531 *p++ = path[i++];
9c8ebd6a
DJ
532 strcpy (p, ld_sysroot);
533 p = p + strlen (p);
9c8ebd6a
DJ
534 }
535 else
536 *p++ = path[i++];
537
538 *p = 0;
539 return ret;
540}
04925e1e 541
3dc16cab
DJ
542EOF
543 case ${target} in
ebe1fac1 544 *-*-freebsd* | *-*-dragonfly*)
92b93329 545 fragment <<EOF
ebe1fac1
NC
546/* Read the system search path the FreeBSD way rather than the Linux way. */
547#ifdef HAVE_ELF_HINTS_H
548#include <elf-hints.h>
549#else
550#include "elf-hints-local.h"
551#endif
552
553static bfd_boolean
554gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force)
555{
556 static bfd_boolean initialized;
557 static char *ld_elf_hints;
558 struct dt_needed needed;
559
560 if (!initialized)
561 {
562 FILE *f;
563 char *tmppath;
564
ff7a0acf 565 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
ebe1fac1
NC
566 f = fopen (tmppath, FOPEN_RB);
567 free (tmppath);
568 if (f != NULL)
569 {
570 struct elfhints_hdr hdr;
571
572 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
573 && hdr.magic == ELFHINTS_MAGIC
574 && hdr.version == 1)
575 {
576 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
577 {
578 char *b;
579
580 b = xmalloc (hdr.dirlistlen + 1);
581 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
582 hdr.dirlistlen + 1)
583 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
e13629bc 584
ebe1fac1
NC
585 free (b);
586 }
587 }
588 fclose (f);
589 }
590
591 initialized = TRUE;
592 }
593
594 if (ld_elf_hints == NULL)
595 return FALSE;
596
597 needed.by = NULL;
598 needed.name = name;
599 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, & needed,
e13629bc 600 force);
ebe1fac1
NC
601}
602EOF
603 # FreeBSD
604 ;;
605
711c0baa 606 *-*-linux-* | *-*-k*bsd*-*)
92b93329 607 fragment <<EOF
04925e1e
AM
608/* For a native linker, check the file /etc/ld.so.conf for directories
609 in which we may find shared libraries. /etc/ld.so.conf is really
482e8b32 610 only meaningful on Linux. */
04925e1e 611
d3989512 612struct gld${EMULATION_NAME}_ld_so_conf
04925e1e 613{
d3989512
JJ
614 char *path;
615 size_t len, alloc;
616};
04925e1e 617
dfcffada 618static bfd_boolean
d3989512
JJ
619gld${EMULATION_NAME}_parse_ld_so_conf
620 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
621
622static void
623gld${EMULATION_NAME}_parse_ld_so_conf_include
624 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
625 const char *pattern)
626{
627 char *newp = NULL;
0b48acfe 628#ifdef HAVE_GLOB
d3989512 629 glob_t gl;
0b48acfe 630#endif
d3989512
JJ
631
632 if (pattern[0] != '/')
04925e1e 633 {
d3989512
JJ
634 char *p = strrchr (filename, '/');
635 size_t patlen = strlen (pattern) + 1;
04925e1e 636
d3989512
JJ
637 newp = xmalloc (p - filename + 1 + patlen);
638 memcpy (newp, filename, p - filename + 1);
639 memcpy (newp + (p - filename + 1), pattern, patlen);
640 pattern = newp;
641 }
04925e1e 642
0b48acfe 643#ifdef HAVE_GLOB
d3989512
JJ
644 if (glob (pattern, 0, NULL, &gl) == 0)
645 {
646 size_t i;
647
648 for (i = 0; i < gl.gl_pathc; ++i)
649 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
650 globfree (&gl);
651 }
0b48acfe
MM
652#else
653 /* If we do not have glob, treat the pattern as a literal filename. */
654 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
655#endif
d3989512
JJ
656
657 if (newp)
658 free (newp);
659}
660
dfcffada 661static bfd_boolean
d3989512
JJ
662gld${EMULATION_NAME}_parse_ld_so_conf
663 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
664{
665 FILE *f = fopen (filename, FOPEN_RT);
563f4125
JJ
666 char *line;
667 size_t linelen;
d3989512
JJ
668
669 if (f == NULL)
dfcffada 670 return FALSE;
d3989512 671
563f4125
JJ
672 linelen = 256;
673 line = xmalloc (linelen);
674 do
d3989512 675 {
563f4125
JJ
676 char *p = line, *q;
677
678 /* Normally this would use getline(3), but we need to be portable. */
679 while ((q = fgets (p, linelen - (p - line), f)) != NULL
680 && strlen (q) == linelen - (p - line) - 1
681 && line[linelen - 2] != '\n')
682 {
683 line = xrealloc (line, 2 * linelen);
684 p = line + linelen - 1;
685 linelen += linelen;
686 }
687
688 if (q == NULL && p == line)
689 break;
d3989512
JJ
690
691 p = strchr (line, '\n');
692 if (p)
693 *p = '\0';
694
695 /* Because the file format does not know any form of quoting we
696 can search forward for the next '#' character and if found
697 make it terminating the line. */
698 p = strchr (line, '#');
699 if (p)
700 *p = '\0';
701
702 /* Remove leading whitespace. NUL is no whitespace character. */
703 p = line;
704 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
705 ++p;
706
707 /* If the line is blank it is ignored. */
708 if (p[0] == '\0')
709 continue;
04925e1e 710
0112cd26 711 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
d3989512
JJ
712 {
713 char *dir, c;
714 p += 8;
715 do
04925e1e 716 {
d3989512
JJ
717 while (*p == ' ' || *p == '\t')
718 ++p;
04925e1e 719
d3989512
JJ
720 if (*p == '\0')
721 break;
252b5132 722
d3989512
JJ
723 dir = p;
724
725 while (*p != ' ' && *p != '\t' && *p)
726 ++p;
727
728 c = *p;
729 *p++ = '\0';
730 if (dir[0] != '\0')
731 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
732 dir);
733 }
734 while (c != '\0');
735 }
736 else
737 {
738 char *dir = p;
739 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
740 && *p != '\r' && *p != '\v')
741 ++p;
742
743 while (p != dir && p[-1] == '/')
744 --p;
745 if (info->path == NULL)
746 {
747 info->alloc = p - dir + 1 + 256;
748 info->path = xmalloc (info->alloc);
749 info->len = 0;
750 }
04925e1e
AM
751 else
752 {
d3989512
JJ
753 if (info->len + 1 + (p - dir) >= info->alloc)
754 {
755 info->alloc += p - dir + 256;
756 info->path = xrealloc (info->path, info->alloc);
757 }
c76308d2 758 info->path[info->len++] = config.rpath_separator;
04925e1e 759 }
d3989512
JJ
760 memcpy (info->path + info->len, dir, p - dir);
761 info->len += p - dir;
762 info->path[info->len] = '\0';
763 }
764 }
563f4125 765 while (! feof (f));
d3989512
JJ
766 free (line);
767 fclose (f);
dfcffada 768 return TRUE;
d3989512 769}
252b5132 770
d3989512
JJ
771static bfd_boolean
772gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force)
773{
774 static bfd_boolean initialized;
775 static char *ld_so_conf;
776 struct dt_needed needed;
252b5132 777
d3989512
JJ
778 if (! initialized)
779 {
780 char *tmppath;
781 struct gld${EMULATION_NAME}_ld_so_conf info;
9c8ebd6a 782
d3989512
JJ
783 info.path = NULL;
784 info.len = info.alloc = 0;
ff7a0acf
AM
785 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
786 (const char *) NULL);
dfcffada
AM
787 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
788 {
789 free (tmppath);
ff7a0acf
AM
790 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
791 (const char *) NULL);
dfcffada
AM
792 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
793 }
d3989512 794 free (tmppath);
dfcffada 795
d3989512
JJ
796 if (info.path)
797 {
798 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
799 free (info.path);
800 ld_so_conf = d;
04925e1e 801 }
b34976b6 802 initialized = TRUE;
04925e1e 803 }
49e56c49 804
04925e1e 805 if (ld_so_conf == NULL)
b34976b6 806 return FALSE;
252b5132 807
e56f61be
L
808
809 needed.by = NULL;
810 needed.name = name;
811 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
252b5132
RH
812}
813
04925e1e 814EOF
9c8ebd6a
DJ
815 # Linux
816 ;;
04925e1e
AM
817 esac
818fi
92b93329 819fragment <<EOF
04925e1e 820
252b5132
RH
821/* See if an input file matches a DT_NEEDED entry by name. */
822
823static void
0c7a8e5a 824gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
252b5132 825{
e13629bc
AM
826 const char *soname;
827
828 /* Stop looking if we've found a loaded lib. */
829 if (global_found != NULL
830 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
831 & DYN_AS_NEEDED) == 0)
252b5132
RH
832 return;
833
e13629bc
AM
834 if (s->filename == NULL || s->the_bfd == NULL)
835 return;
836
837 /* Don't look for a second non-loaded as-needed lib. */
838 if (global_found != NULL
839 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
7cedef86
AM
840 return;
841
e13629bc 842 if (strcmp (s->filename, global_needed->name) == 0)
252b5132 843 {
e13629bc
AM
844 global_found = s;
845 return;
846 }
577a0623 847
e13629bc
AM
848 if (s->search_dirs_flag)
849 {
850 const char *f = strrchr (s->filename, '/');
851 if (f != NULL
852 && strcmp (f + 1, global_needed->name) == 0)
577a0623 853 {
e13629bc 854 global_found = s;
577a0623
AM
855 return;
856 }
252b5132
RH
857 }
858
e13629bc
AM
859 soname = bfd_elf_get_dt_soname (s->the_bfd);
860 if (soname != NULL
861 && strcmp (soname, global_needed->name) == 0)
252b5132 862 {
e13629bc
AM
863 global_found = s;
864 return;
252b5132 865 }
252b5132
RH
866}
867
41392f03
AM
868EOF
869
870if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
92b93329 871fragment <<EOF
04925e1e 872
24382dca
RM
873static bfd_size_type
874gld${EMULATION_NAME}_id_note_section_size (bfd *abfd,
875 struct bfd_link_info *link_info)
876{
877 const char *style = link_info->emit_note_gnu_build_id;
878 bfd_size_type size;
879
880 abfd = abfd;
881
882 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
883 size = (size + 3) & -(bfd_size_type) 4;
884
885 if (!strcmp (style, "md5") || !strcmp (style, "uuid"))
886 size += 128 / 8;
887 else if (!strcmp (style, "sha1"))
888 size += 160 / 8;
889 else if (!strncmp (style, "0x", 2))
890 {
891 /* ID is in string form (hex). Convert to bits. */
892 const char *id = style + 2;
893 do
894 {
895 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
896 {
897 ++size;
898 id += 2;
899 }
900 else if (*id == '-' || *id == ':')
901 ++id;
902 else
903 {
904 size = 0;
905 break;
906 }
907 } while (*id != '\0');
908 }
909 else
910 size = 0;
911
912 return size;
913}
914
915static unsigned char
916read_hex (const char xdigit)
917{
918 if (ISDIGIT (xdigit))
919 return xdigit - '0';
920 if (ISUPPER (xdigit))
921 return xdigit - 'A' + 0xa;
922 if (ISLOWER (xdigit))
923 return xdigit - 'a' + 0xa;
924 abort ();
925 return 0;
926}
927
928struct build_id_info
929{
930 const char *style;
931 asection *sec;
932};
933
934static bfd_boolean
935gld${EMULATION_NAME}_write_build_id_section (bfd *abfd)
936{
937 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1e9cc1c2 938 struct build_id_info *info = (struct build_id_info *)
24382dca
RM
939 elf_tdata (abfd)->after_write_object_contents_info;
940 asection *asec;
941 Elf_Internal_Shdr *i_shdr;
942 unsigned char *contents, *id_bits;
943 bfd_size_type size;
944 Elf_External_Note *e_note;
945
946 asec = info->sec;
83e4970b 947 if (bfd_is_abs_section (asec->output_section))
24382dca 948 {
83e4970b
AM
949 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
950 " --build-id ignored.\n"));
951 return TRUE;
24382dca
RM
952 }
953 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
954
955 if (i_shdr->contents == NULL)
956 {
b2ff8454 957 if (asec->contents == NULL)
1e9cc1c2 958 asec->contents = (unsigned char *) xmalloc (asec->size);
b2ff8454 959 contents = asec->contents;
24382dca 960 }
b2ff8454
RM
961 else
962 contents = i_shdr->contents + asec->output_offset;
24382dca 963
1e9cc1c2 964 e_note = (Elf_External_Note *) contents;
24382dca
RM
965 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
966 size = (size + 3) & -(bfd_size_type) 4;
967 id_bits = contents + size;
968 size = asec->size - size;
969
970 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
971 bfd_h_put_32 (abfd, size, &e_note->descsz);
972 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
973 memcpy (e_note->name, "GNU", sizeof "GNU");
974
975 if (!strcmp (info->style, "md5"))
976 {
977 struct md5_ctx ctx;
978 md5_init_ctx (&ctx);
979 if (bed->s->checksum_contents (abfd,
980 (void (*) (const void *, size_t, void *))
981 &md5_process_bytes,
982 &ctx))
983 md5_finish_ctx (&ctx, id_bits);
984 else
985 return FALSE;
986 }
987 else if (!strcmp (info->style, "sha1"))
988 {
989 struct sha1_ctx ctx;
990 sha1_init_ctx (&ctx);
991 if (bed->s->checksum_contents (abfd,
992 (void (*) (const void *, size_t, void *))
993 &sha1_process_bytes,
994 &ctx))
995 sha1_finish_ctx (&ctx, id_bits);
996 else
997 return FALSE;
998 }
999 else if (!strcmp (info->style, "uuid"))
1000 {
1001 int n;
1002 int fd = open ("/dev/urandom", O_RDONLY);
1003 if (fd < 0)
1004 return FALSE;
1005 n = read (fd, id_bits, size);
1006 close (fd);
1007 if (n < (int) size)
1008 return FALSE;
1009 }
1010 else if (!strncmp (info->style, "0x", 2))
1011 {
1012 /* ID is in string form (hex). Convert to bits. */
1013 const char *id = info->style + 2;
1014 size_t n = 0;
1015 do
1016 {
1017 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
1018 {
1019 id_bits[n] = read_hex (*id++) << 4;
1020 id_bits[n++] |= read_hex (*id++);
1021 }
1022 else if (*id == '-' || *id == ':')
1023 ++id;
1024 else
1025 abort (); /* Should have been validated earlier. */
1026 } while (*id != '\0');
1027 }
1028 else
1029 abort (); /* Should have been validated earlier. */
1030
b2ff8454
RM
1031 size = asec->size;
1032 return (bfd_seek (abfd,
1033 i_shdr->sh_offset + asec->output_offset, SEEK_SET) == 0
1034 && bfd_bwrite (contents, size, abfd) == size);
24382dca
RM
1035}
1036
1037
04925e1e 1038/* This is called after all the input files have been opened. */
252b5132
RH
1039
1040static void
0c7a8e5a 1041gld${EMULATION_NAME}_after_open (void)
252b5132 1042{
04925e1e 1043 struct bfd_link_needed_list *needed, *l;
d10e7fcc
AM
1044 struct elf_link_hash_table *htab;
1045
1046 htab = elf_hash_table (&link_info);
1047 if (!is_elf_hash_table (htab))
1048 return;
252b5132 1049
c0065db7
RM
1050 if (link_info.emit_note_gnu_build_id)
1051 {
1052 bfd *abfd;
1053 asection *s;
1054 bfd_size_type size;
1055
1056 abfd = link_info.input_bfds;
1057
e9e0a58e 1058 if (abfd == NULL)
c0065db7 1059 {
e9e0a58e
NC
1060 /* PR 10555: If there are no input files do not
1061 try to create a .note.gnu-build-id section. */
c0065db7
RM
1062 free (link_info.emit_note_gnu_build_id);
1063 link_info.emit_note_gnu_build_id = NULL;
1064 }
1065 else
1066 {
e9e0a58e
NC
1067 size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info);
1068 if (size == 0)
c0065db7 1069 {
e9e0a58e
NC
1070 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1071 free (link_info.emit_note_gnu_build_id);
1072 link_info.emit_note_gnu_build_id = NULL;
c0065db7
RM
1073 }
1074 else
1075 {
e9e0a58e
NC
1076 s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
1077 SEC_ALLOC | SEC_LOAD
1078 | SEC_IN_MEMORY | SEC_LINKER_CREATED
1079 | SEC_READONLY | SEC_DATA);
1080 if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
1081 {
1082 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1e9cc1c2
NC
1083 struct build_id_info *b =
1084 (struct build_id_info *) xmalloc (sizeof *b);
e9e0a58e
NC
1085
1086 b->style = link_info.emit_note_gnu_build_id;
1087 b->sec = s;
1088 elf_section_type (s) = SHT_NOTE;
1089 s->size = size;
1090 t->after_write_object_contents
1091 = &gld${EMULATION_NAME}_write_build_id_section;
1092 t->after_write_object_contents_info = b;
1093 }
1094 else
1095 {
1096 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1097 " --build-id ignored.\n");
1098 free (link_info.emit_note_gnu_build_id);
1099 link_info.emit_note_gnu_build_id = NULL;
1100 }
c0065db7
RM
1101 }
1102 }
1103 }
1104
d10e7fcc
AM
1105 if (link_info.relocatable)
1106 return;
1107
eb3d5f3b 1108 if (link_info.eh_frame_hdr
d10e7fcc 1109 && !link_info.traditional_format)
eb3d5f3b 1110 {
d10e7fcc
AM
1111 bfd *abfd;
1112 asection *s;
eb3d5f3b 1113
d10e7fcc 1114 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
eb3d5f3b 1115 {
d10e7fcc
AM
1116 s = bfd_get_section_by_name (abfd, ".eh_frame");
1117 if (s && s->size > 8 && !bfd_is_abs_section (s->output_section))
1118 break;
1119 }
1120 if (abfd)
1121 {
1122 const struct elf_backend_data *bed;
1123
1124 bed = get_elf_backend_data (abfd);
1125 s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
1126 bed->dynamic_sec_flags
1127 | SEC_READONLY);
1128 if (s != NULL
1129 && bfd_set_section_alignment (abfd, s, 2))
1130 htab->eh_info.hdr_sec = s;
1131 else
1132 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1133 " --eh-frame-hdr ignored.\n");
eb3d5f3b
JB
1134 }
1135 }
1136
04925e1e
AM
1137 /* Get the list of files which appear in DT_NEEDED entries in
1138 dynamic objects included in the link (often there will be none).
1139 For each such file, we want to track down the corresponding
1140 library, and include the symbol table in the link. This is what
1141 the runtime dynamic linker will do. Tracking the files down here
1142 permits one dynamic object to include another without requiring
1143 special action by the person doing the link. Note that the
1144 needed list can actually grow while we are stepping through this
1145 loop. */
d10e7fcc
AM
1146 if (!link_info.executable)
1147 return;
f13a99db 1148 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
04925e1e 1149 for (l = needed; l != NULL; l = l->next)
252b5132 1150 {
04925e1e 1151 struct bfd_link_needed_list *ll;
e56f61be 1152 struct dt_needed n, nn;
04925e1e 1153 int force;
252b5132 1154
7e9f0867
AM
1155 /* If the lib that needs this one was --as-needed and wasn't
1156 found to be needed, then this lib isn't needed either. */
1157 if (l->by != NULL
1158 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1159 continue;
1160
04925e1e
AM
1161 /* If we've already seen this file, skip it. */
1162 for (ll = needed; ll != l; ll = ll->next)
7e9f0867
AM
1163 if ((ll->by == NULL
1164 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1165 && strcmp (ll->name, l->name) == 0)
04925e1e
AM
1166 break;
1167 if (ll != l)
1168 continue;
252b5132 1169
04925e1e
AM
1170 /* See if this file was included in the link explicitly. */
1171 global_needed = l;
e13629bc 1172 global_found = NULL;
04925e1e 1173 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
e13629bc
AM
1174 if (global_found != NULL
1175 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1176 & DYN_AS_NEEDED) == 0)
04925e1e 1177 continue;
252b5132 1178
e56f61be
L
1179 n.by = l->by;
1180 n.name = l->name;
1181 nn.by = l->by;
ec4eb78a
L
1182 if (trace_file_tries)
1183 info_msg (_("%s needed by %B\n"), l->name, l->by);
1184
e13629bc
AM
1185 /* As-needed libs specified on the command line (or linker script)
1186 take priority over libs found in search dirs. */
1187 if (global_found != NULL)
1188 {
1189 nn.name = global_found->filename;
1190 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1191 continue;
1192 }
1193
04925e1e
AM
1194 /* We need to find this file and include the symbol table. We
1195 want to search for the file in the same way that the dynamic
1196 linker will search. That means that we want to use
1197 rpath_link, rpath, then the environment variable
ec4eb78a
L
1198 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1199 entries (native only), then the linker script LIB_SEARCH_DIRS.
1200 We do not search using the -L arguments.
252b5132 1201
04925e1e
AM
1202 We search twice. The first time, we skip objects which may
1203 introduce version mismatches. The second time, we force
1204 their use. See gld${EMULATION_NAME}_vercheck comment. */
1205 for (force = 0; force < 2; force++)
1206 {
04925e1e
AM
1207 size_t len;
1208 search_dirs_type *search;
6dd8c765 1209EOF
ff925e69 1210if [ "x${NATIVE}" = xyes ] ; then
92b93329 1211fragment <<EOF
dcb0bd0e 1212 const char *lib_path;
ff925e69
KK
1213EOF
1214fi
1215if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1216fragment <<EOF
6dd8c765
L
1217 struct bfd_link_needed_list *rp;
1218 int found;
1219EOF
6dd8c765 1220fi
92b93329 1221fragment <<EOF
252b5132 1222
04925e1e 1223 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
e56f61be 1224 &n, force))
04925e1e 1225 break;
dcb0bd0e 1226EOF
9c8ebd6a 1227if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1228fragment <<EOF
04925e1e 1229 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
e56f61be 1230 &n, force))
04925e1e 1231 break;
9c8ebd6a
DJ
1232EOF
1233fi
1234if [ "x${NATIVE}" = xyes ] ; then
92b93329 1235fragment <<EOF
04925e1e
AM
1236 if (command_line.rpath_link == NULL
1237 && command_line.rpath == NULL)
1238 {
1239 lib_path = (const char *) getenv ("LD_RUN_PATH");
e56f61be 1240 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
04925e1e
AM
1241 force))
1242 break;
1243 }
04925e1e 1244 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
e56f61be 1245 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
04925e1e 1246 break;
9c8ebd6a
DJ
1247EOF
1248fi
1249if [ "x${USE_LIBPATH}" = xyes ] ; then
92b93329 1250fragment <<EOF
ec4eb78a 1251 found = 0;
f13a99db 1252 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
6dd8c765 1253 for (; !found && rp != NULL; rp = rp->next)
ec4eb78a 1254 {
9c8ebd6a 1255 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
ec4eb78a 1256 found = (rp->by == l->by
9c8ebd6a 1257 && gld${EMULATION_NAME}_search_needed (tmpname,
e56f61be 1258 &n,
ec4eb78a 1259 force));
9c8ebd6a 1260 free (tmpname);
ec4eb78a
L
1261 }
1262 if (found)
1263 break;
1264
04925e1e 1265EOF
04925e1e 1266fi
c1446dba
L
1267if [ "x${USE_LIBPATH}" = xyes ] ; then
1268 case ${target} in
ebe1fac1 1269 *-*-freebsd* | *-*-dragonfly*)
92b93329 1270 fragment <<EOF
ebe1fac1
NC
1271 if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
1272 break;
1273EOF
1274 # FreeBSD
1275 ;;
1276
c1446dba
L
1277 *-*-linux-* | *-*-k*bsd*-*)
1278 # Linux
92b93329 1279 fragment <<EOF
c1446dba
L
1280 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
1281 break;
1282
1283EOF
1284 ;;
1285 esac
1286fi
92b93329 1287fragment <<EOF
04925e1e
AM
1288 len = strlen (l->name);
1289 for (search = search_head; search != NULL; search = search->next)
1290 {
1291 char *filename;
252b5132 1292
04925e1e
AM
1293 if (search->cmdline)
1294 continue;
1295 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1296 sprintf (filename, "%s/%s", search->name, l->name);
e56f61be
L
1297 nn.name = filename;
1298 if (gld${EMULATION_NAME}_try_needed (&nn, force))
04925e1e
AM
1299 break;
1300 free (filename);
1301 }
1302 if (search != NULL)
1303 break;
1304EOF
92b93329 1305fragment <<EOF
04925e1e 1306 }
252b5132 1307
04925e1e
AM
1308 if (force < 2)
1309 continue;
252b5132 1310
e374f1d9 1311 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
04925e1e
AM
1312 l->name, l->by);
1313 }
1314}
252b5132 1315
41392f03
AM
1316EOF
1317fi
1318
92b93329 1319fragment <<EOF
252b5132 1320
04925e1e 1321/* Look through an expression for an assignment statement. */
252b5132 1322
04925e1e 1323static void
0c7a8e5a 1324gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
04925e1e 1325{
4ea42fb7 1326 bfd_boolean provide = FALSE;
04925e1e
AM
1327
1328 switch (exp->type.node_class)
252b5132 1329 {
04925e1e 1330 case etree_provide:
4ea42fb7
AM
1331 provide = TRUE;
1332 /* Fall thru */
1333 case etree_assign:
04925e1e
AM
1334 /* We call record_link_assignment even if the symbol is defined.
1335 This is because if it is defined by a dynamic object, we
1336 actually want to use the value defined by the linker script,
1337 not the value from the dynamic object (because we are setting
1338 symbols like etext). If the symbol is defined by a regular
1339 object, then, as it happens, calling record_link_assignment
1340 will do no harm. */
04925e1e 1341 if (strcmp (exp->assign.dst, ".") != 0)
252b5132 1342 {
f13a99db
AM
1343 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1344 &link_info,
fe21a8fc
L
1345 exp->assign.dst, provide,
1346 exp->assign.hidden))
04925e1e
AM
1347 einfo ("%P%F: failed to record assignment to %s: %E\n",
1348 exp->assign.dst);
252b5132 1349 }
04925e1e
AM
1350 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1351 break;
252b5132 1352
04925e1e
AM
1353 case etree_binary:
1354 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1355 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1356 break;
252b5132 1357
04925e1e
AM
1358 case etree_trinary:
1359 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1360 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1361 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1362 break;
252b5132 1363
04925e1e
AM
1364 case etree_unary:
1365 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1366 break;
252b5132 1367
04925e1e
AM
1368 default:
1369 break;
252b5132
RH
1370 }
1371}
1372
04925e1e
AM
1373
1374/* This is called by the before_allocation routine via
1375 lang_for_each_statement. It locates any assignment statements, and
1376 tells the ELF backend about them, in case they are assignments to
1377 symbols which are referred to by dynamic objects. */
1378
1379static void
0c7a8e5a 1380gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
04925e1e
AM
1381{
1382 if (s->header.type == lang_assignment_statement_enum)
1383 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1384}
1385
41392f03
AM
1386EOF
1387
1388if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
57e6abd2
AO
1389 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1390 ELF_INTERPRETER_SET_DEFAULT="
1391 if (sinterp != NULL)
1392 {
5718918d
AM
1393 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1394 sinterp->size = strlen ((char *) sinterp->contents) + 1;
57e6abd2
AO
1395 }
1396
1397"
1398 else
1399 ELF_INTERPRETER_SET_DEFAULT=
1400 fi
92b93329 1401fragment <<EOF
04925e1e 1402
7ee314fa
AM
1403/* used by before_allocation and handle_option. */
1404static void
1405gld${EMULATION_NAME}_append_to_separated_string (char **to, char *optarg)
1406{
1407 if (*to == NULL)
1408 *to = xstrdup (optarg);
1409 else
1410 {
1411 size_t to_len = strlen (*to);
1412 size_t optarg_len = strlen (optarg);
1413 char *buf;
1414 char *cp = *to;
1415
1416 /* First see whether OPTARG is already in the path. */
1417 do
1418 {
1419 if (strncmp (optarg, cp, optarg_len) == 0
1420 && (cp[optarg_len] == 0
1421 || cp[optarg_len] == config.rpath_separator))
1422 /* We found it. */
1423 break;
1424
1425 /* Not yet found. */
1426 cp = strchr (cp, config.rpath_separator);
1427 if (cp != NULL)
1428 ++cp;
1429 }
1430 while (cp != NULL);
1431
1432 if (cp == NULL)
1433 {
1434 buf = xmalloc (to_len + optarg_len + 2);
1435 sprintf (buf, "%s%c%s", *to,
1436 config.rpath_separator, optarg);
1437 free (*to);
1438 *to = buf;
1439 }
1440 }
1441}
1442
252b5132
RH
1443/* This is called after the sections have been attached to output
1444 sections, but before any sizes or addresses have been set. */
1445
1446static void
0c7a8e5a 1447gld${EMULATION_NAME}_before_allocation (void)
252b5132
RH
1448{
1449 const char *rpath;
1450 asection *sinterp;
7ee314fa 1451 bfd *abfd;
252b5132 1452
fd574c46 1453 if (link_info.hash->type == bfd_link_elf_hash_table)
f13a99db 1454 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
e1918d23 1455
252b5132
RH
1456 /* If we are going to make any variable assignments, we need to let
1457 the ELF backend know about them in case the variables are
1458 referred to by dynamic objects. */
1459 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1460
1461 /* Let the ELF backend work out the sizes of any sections required
1462 by dynamic linking. */
1463 rpath = command_line.rpath;
1464 if (rpath == NULL)
1465 rpath = (const char *) getenv ("LD_RUN_PATH");
7ee314fa
AM
1466
1467 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
1468 {
1469 const char *audit_libs = elf_dt_audit (abfd);
1470
1471 /* If the input bfd contains an audit entry, we need to add it as
1472 a dep audit entry. */
1473 if (audit_libs && *audit_libs != '\0')
1474 {
1475 char *cp = xstrdup (audit_libs);
1476 do
1477 {
1478 int more = 0;
1479 char *cp2 = strchr (cp, config.rpath_separator);
1480
1481 if (cp2)
1482 {
1483 *cp2 = '\0';
1484 more = 1;
1485 }
1486
1487 if (cp != NULL && *cp != '\0')
1488 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1489
1490 cp = more ? ++cp2 : NULL;
1491 }
1492 while (cp != NULL);
1493 }
1494 }
1495
5a580b3a 1496 if (! (bfd_elf_size_dynamic_sections
f13a99db 1497 (link_info.output_bfd, command_line.soname, rpath,
7ee314fa 1498 command_line.filter_shlib, audit, depaudit,
252b5132
RH
1499 (const char * const *) command_line.auxiliary_filters,
1500 &link_info, &sinterp, lang_elf_version_info)))
1501 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
8423293d 1502
57e6abd2 1503${ELF_INTERPRETER_SET_DEFAULT}
252b5132
RH
1504 /* Let the user override the dynamic linker we are using. */
1505 if (command_line.interpreter != NULL
1506 && sinterp != NULL)
1507 {
1508 sinterp->contents = (bfd_byte *) command_line.interpreter;
eea6121a 1509 sinterp->size = strlen (command_line.interpreter) + 1;
252b5132
RH
1510 }
1511
1512 /* Look for any sections named .gnu.warning. As a GNU extensions,
1513 we treat such sections as containing warning messages. We print
1514 out the warning message, and then zero out the section size so
1515 that it does not get copied into the output file. */
1516
1517 {
1518 LANG_FOR_EACH_INPUT_STATEMENT (is)
1519 {
1520 asection *s;
1521 bfd_size_type sz;
1522 char *msg;
b34976b6 1523 bfd_boolean ret;
252b5132
RH
1524
1525 if (is->just_syms_flag)
1526 continue;
1527
1528 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1529 if (s == NULL)
1530 continue;
1531
eea6121a 1532 sz = s->size;
1e9cc1c2 1533 msg = (char *) xmalloc ((size_t) (sz + 1));
bc251d50 1534 if (! bfd_get_section_contents (is->the_bfd, s, msg,
8c675694 1535 (file_ptr) 0, sz))
252b5132
RH
1536 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1537 is->the_bfd);
bc251d50 1538 msg[sz] = '\0';
252b5132
RH
1539 ret = link_info.callbacks->warning (&link_info, msg,
1540 (const char *) NULL,
1541 is->the_bfd, (asection *) NULL,
1542 (bfd_vma) 0);
1543 ASSERT (ret);
1544 free (msg);
1545
9e3be61d
AM
1546 /* Clobber the section size, so that we don't waste space
1547 copying the warning into the output file. If we've already
1548 sized the output section, adjust its size. The adjustment
1549 is on rawsize because targets that size sections early will
1550 have called lang_reset_memory_regions after sizing. */
1551 if (s->output_section != NULL
1552 && s->output_section->rawsize >= s->size)
1553 s->output_section->rawsize -= s->size;
1554
eea6121a 1555 s->size = 0;
11d2f718 1556
9e3be61d
AM
1557 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1558 warning section don't get copied to the output. */
a14a5de3 1559 s->flags |= SEC_EXCLUDE | SEC_KEEP;
252b5132
RH
1560 }
1561 }
8423293d 1562
1e035701 1563 before_allocation_default ();
8423293d 1564
f13a99db 1565 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
8423293d 1566 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
252b5132
RH
1567}
1568
41392f03
AM
1569EOF
1570fi
1571
1572if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
92b93329 1573fragment <<EOF
252b5132 1574
04925e1e
AM
1575/* Try to open a dynamic archive. This is where we know that ELF
1576 dynamic libraries have an extension of .so (or .sl on oddball systems
1577 like hpux). */
1578
b34976b6 1579static bfd_boolean
0c7a8e5a
AM
1580gld${EMULATION_NAME}_open_dynamic_archive
1581 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
252b5132 1582{
04925e1e
AM
1583 const char *filename;
1584 char *string;
252b5132 1585
04925e1e 1586 if (! entry->is_archive)
b34976b6 1587 return FALSE;
252b5132 1588
04925e1e 1589 filename = entry->filename;
252b5132 1590
04925e1e
AM
1591 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
1592 is defined, but it does not seem worth the headache to optimize
1593 away those two bytes of space. */
1594 string = (char *) xmalloc (strlen (search->name)
1595 + strlen (filename)
1596 + strlen (arch)
1597#ifdef EXTRA_SHLIB_EXTENSION
1598 + strlen (EXTRA_SHLIB_EXTENSION)
1599#endif
1600 + sizeof "/lib.so");
1601
1602 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1603
1604#ifdef EXTRA_SHLIB_EXTENSION
1605 /* Try the .so extension first. If that fails build a new filename
1606 using EXTRA_SHLIB_EXTENSION. */
1607 if (! ldfile_try_open_bfd (string, entry))
a26cc967
AM
1608 {
1609 sprintf (string, "%s/lib%s%s%s", search->name,
1610 filename, arch, EXTRA_SHLIB_EXTENSION);
04925e1e
AM
1611#endif
1612
1613 if (! ldfile_try_open_bfd (string, entry))
252b5132 1614 {
04925e1e 1615 free (string);
b34976b6 1616 return FALSE;
04925e1e 1617 }
a26cc967
AM
1618#ifdef EXTRA_SHLIB_EXTENSION
1619 }
1620#endif
252b5132 1621
04925e1e 1622 entry->filename = string;
252b5132 1623
04925e1e
AM
1624 /* We have found a dynamic object to include in the link. The ELF
1625 backend linker will create a DT_NEEDED entry in the .dynamic
1626 section naming this file. If this file includes a DT_SONAME
1627 entry, it will be used. Otherwise, the ELF linker will just use
1628 the name of the file. For an archive found by searching, like
1629 this one, the DT_NEEDED entry should consist of just the name of
1630 the file, without the path information used to find it. Note
1631 that we only need to do this if we have a dynamic object; an
1632 archive will never be referenced by a DT_NEEDED entry.
252b5132 1633
04925e1e
AM
1634 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1635 very pretty. I haven't been able to think of anything that is
1636 pretty, though. */
1637 if (bfd_check_format (entry->the_bfd, bfd_object)
1638 && (entry->the_bfd->flags & DYNAMIC) != 0)
1639 {
04925e1e 1640 ASSERT (entry->is_archive && entry->search_dirs_flag);
252b5132 1641
04925e1e 1642 /* Rather than duplicating the logic above. Just use the
1c9acd94 1643 filename we recorded earlier. */
04925e1e 1644
fed2999d 1645 filename = lbasename (entry->filename);
1c9acd94 1646 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
04925e1e
AM
1647 }
1648
b34976b6 1649 return TRUE;
04925e1e
AM
1650}
1651
41392f03
AM
1652EOF
1653fi
cde43e70
AM
1654
1655if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
92b93329 1656fragment <<EOF
41392f03 1657
afd7a018 1658/* A variant of lang_output_section_find used by place_orphan. */
04925e1e 1659
04925e1e 1660static lang_output_section_statement_type *
2a36a117 1661output_rel_find (asection *sec, int isdyn)
04925e1e 1662{
04925e1e 1663 lang_output_section_statement_type *lookup;
ba493122 1664 lang_output_section_statement_type *last = NULL;
2a36a117 1665 lang_output_section_statement_type *last_alloc = NULL;
48f2ff54 1666 lang_output_section_statement_type *last_ro_alloc = NULL;
ba493122
AM
1667 lang_output_section_statement_type *last_rel = NULL;
1668 lang_output_section_statement_type *last_rel_alloc = NULL;
24cdb50a 1669 int rela = sec->name[4] == 'a';
04925e1e 1670
afd7a018
AM
1671 for (lookup = &lang_output_section_statement.head->output_section_statement;
1672 lookup != NULL;
1673 lookup = lookup->next)
04925e1e 1674 {
66c103b7 1675 if (lookup->constraint >= 0
0112cd26 1676 && CONST_STRNEQ (lookup->name, ".rel"))
04925e1e 1677 {
24cdb50a 1678 int lookrela = lookup->name[4] == 'a';
ba493122 1679
2a36a117
AM
1680 /* .rel.dyn must come before all other reloc sections, to suit
1681 GNU ld.so. */
1682 if (isdyn)
1683 break;
1684
1685 /* Don't place after .rel.plt as doing so results in wrong
1686 dynamic tags. */
1687 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
ba493122 1688 break;
2a36a117
AM
1689
1690 if (rela == lookrela || last_rel == NULL)
24cdb50a 1691 last_rel = lookup;
2a36a117
AM
1692 if ((rela == lookrela || last_rel_alloc == NULL)
1693 && lookup->bfd_section != NULL
ba493122
AM
1694 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1695 last_rel_alloc = lookup;
04925e1e 1696 }
2a36a117
AM
1697
1698 last = lookup;
1699 if (lookup->bfd_section != NULL
1700 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
48f2ff54
AM
1701 {
1702 last_alloc = lookup;
1703 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1704 last_ro_alloc = lookup;
1705 }
252b5132 1706 }
ba493122
AM
1707
1708 if (last_rel_alloc)
1709 return last_rel_alloc;
1710
1711 if (last_rel)
1712 return last_rel;
1713
48f2ff54
AM
1714 if (last_ro_alloc)
1715 return last_ro_alloc;
1716
2a36a117
AM
1717 if (last_alloc)
1718 return last_alloc;
1719
ba493122 1720 return last;
252b5132
RH
1721}
1722
1723/* Place an orphan section. We use this to put random SHF_ALLOC
1724 sections in the right segment. */
1725
c2edb4b8 1726static lang_output_section_statement_type *
8a99a385
AM
1727gld${EMULATION_NAME}_place_orphan (asection *s,
1728 const char *secname,
1729 int constraint)
252b5132 1730{
afd7a018
AM
1731 static struct orphan_save hold[] =
1732 {
1733 { ".text",
1734 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1735 0, 0, 0, 0 },
1736 { ".rodata",
1737 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1738 0, 0, 0, 0 },
1739 { ".data",
1740 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1741 0, 0, 0, 0 },
1742 { ".bss",
1743 SEC_ALLOC,
1744 0, 0, 0, 0 },
1745 { 0,
1746 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1747 0, 0, 0, 0 },
1748 { ".interp",
1749 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1750 0, 0, 0, 0 },
1751 { ".sdata",
1752 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
07890c07
AM
1753 0, 0, 0, 0 },
1754 { 0,
1755 SEC_HAS_CONTENTS,
1756 0, 0, 0, 0 },
afd7a018
AM
1757 };
1758 enum orphan_save_index
1759 {
1760 orphan_text = 0,
1761 orphan_rodata,
1762 orphan_data,
1763 orphan_bss,
1764 orphan_rel,
1765 orphan_interp,
07890c07
AM
1766 orphan_sdata,
1767 orphan_nonalloc
afd7a018
AM
1768 };
1769 static int orphan_init_done = 0;
6a345e87 1770 struct orphan_save *place;
afd7a018 1771 lang_output_section_statement_type *after;
252b5132 1772 lang_output_section_statement_type *os;
24cdb50a 1773 int isdyn = 0;
ecca9871
L
1774 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
1775 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
252b5132 1776
1049f94e 1777 if (! link_info.relocatable
24cdb50a 1778 && link_info.combreloc
ecca9871 1779 && (s->flags & SEC_ALLOC))
24cdb50a 1780 {
ecca9871
L
1781 if (iself)
1782 switch (sh_type)
1783 {
1784 case SHT_RELA:
1785 secname = ".rela.dyn";
1786 isdyn = 1;
1787 break;
1788 case SHT_REL:
1789 secname = ".rel.dyn";
1790 isdyn = 1;
1791 break;
1792 default:
1793 break;
1794 }
0112cd26 1795 else if (CONST_STRNEQ (secname, ".rel"))
ecca9871
L
1796 {
1797 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
1798 isdyn = 1;
1799 }
24cdb50a 1800 }
aea4bd9d 1801
bcacc0f5 1802 /* Look through the script to see where to place this section. */
d127ecce
AM
1803 if (constraint == 0)
1804 for (os = lang_output_section_find (secname);
1805 os != NULL;
1806 os = next_matching_output_section_statement (os, 0))
1807 {
1808 /* If we don't match an existing output section, tell
1809 lang_insert_orphan to create a new output section. */
1810 constraint = SPECIAL;
1811
1812 if (os->bfd_section != NULL
1813 && (os->bfd_section->flags == 0
1814 || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
1815 os->bfd_section,
1816 s->owner, s)
1817 && ((s->flags ^ os->bfd_section->flags)
1818 & (SEC_LOAD | SEC_ALLOC)) == 0)))
1819 {
1820 /* We already have an output section statement with this
1821 name, and its bfd section has compatible flags.
1822 If the section already exists but does not have any flags
1823 set, then it has been created by the linker, probably as a
1824 result of a --section-start command line switch. */
1825 lang_add_section (&os->children, s, os);
1826 return os;
1827 }
1828 }
252b5132 1829
afd7a018
AM
1830 if (!orphan_init_done)
1831 {
07890c07 1832 lang_output_section_statement_type *lookup;
afd7a018 1833 struct orphan_save *ho;
07890c07 1834
afd7a018
AM
1835 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1836 if (ho->name != NULL)
1837 {
1838 ho->os = lang_output_section_find (ho->name);
1839 if (ho->os != NULL && ho->os->flags == 0)
1840 ho->os->flags = ho->flags;
1841 }
07890c07
AM
1842 lookup = hold[orphan_bss].os;
1843 if (lookup == NULL)
1844 lookup = &lang_output_section_statement.head->output_section_statement;
1845 for (; lookup != NULL; lookup = lookup->next)
1846 if ((lookup->bfd_section != NULL
1847 && (lookup->bfd_section->flags & SEC_DEBUGGING) != 0)
1848 || strcmp (lookup->name, ".comment") == 0)
1849 break;
1850 hold[orphan_nonalloc].os = lookup ? lookup->prev : NULL;
1851 hold[orphan_nonalloc].name = ".comment";
afd7a018
AM
1852 orphan_init_done = 1;
1853 }
252b5132
RH
1854
1855 /* If this is a final link, then always put .gnu.warning.SYMBOL
1856 sections into the .text section to get them out of the way. */
36af4a4e 1857 if (link_info.executable
1049f94e 1858 && ! link_info.relocatable
bcacc0f5 1859 && CONST_STRNEQ (s->name, ".gnu.warning.")
afd7a018 1860 && hold[orphan_text].os != NULL)
252b5132 1861 {
c2edb4b8
AM
1862 os = hold[orphan_text].os;
1863 lang_add_section (&os->children, s, os);
1864 return os;
252b5132
RH
1865 }
1866
1867 /* Decide which segment the section should go in based on the
1868 section name and section flags. We put loadable .note sections
1869 right after the .interp section, so that the PT_NOTE segment is
1870 stored right after the program headers where the OS can read it
1871 in the first page. */
aea4bd9d 1872
71bfc0ae 1873 place = NULL;
07890c07
AM
1874 if ((s->flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
1875 place = &hold[orphan_nonalloc];
1876 else if ((s->flags & SEC_ALLOC) == 0)
71bfc0ae 1877 ;
252b5132 1878 else if ((s->flags & SEC_LOAD) != 0
ecca9871 1879 && ((iself && sh_type == SHT_NOTE)
0112cd26 1880 || (!iself && CONST_STRNEQ (secname, ".note"))))
afd7a018
AM
1881 place = &hold[orphan_interp];
1882 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1883 place = &hold[orphan_bss];
1884 else if ((s->flags & SEC_SMALL_DATA) != 0)
1885 place = &hold[orphan_sdata];
1886 else if ((s->flags & SEC_READONLY) == 0)
1887 place = &hold[orphan_data];
ecca9871 1888 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
0112cd26 1889 || (!iself && CONST_STRNEQ (secname, ".rel")))
afd7a018
AM
1890 && (s->flags & SEC_LOAD) != 0)
1891 place = &hold[orphan_rel];
1892 else if ((s->flags & SEC_CODE) == 0)
1893 place = &hold[orphan_rodata];
1894 else
1895 place = &hold[orphan_text];
71bfc0ae 1896
afd7a018 1897 after = NULL;
5ba47421 1898 if (place != NULL)
252b5132 1899 {
afd7a018 1900 if (place->os == NULL)
5ba47421 1901 {
afd7a018
AM
1902 if (place->name != NULL)
1903 place->os = lang_output_section_find (place->name);
1904 else
1905 place->os = output_rel_find (s, isdyn);
5ba47421 1906 }
afd7a018
AM
1907 after = place->os;
1908 if (after == NULL)
390fbbf1
AM
1909 after = lang_output_section_find_by_flags
1910 (s, &place->os, _bfd_elf_match_sections_by_type);
afd7a018
AM
1911 if (after == NULL)
1912 /* *ABS* is always the first output section statement. */
1913 after = &lang_output_section_statement.head->output_section_statement;
252b5132
RH
1914 }
1915
c2edb4b8 1916 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
252b5132 1917}
c56feb2b
AM
1918EOF
1919fi
1920
eaeb0a9d 1921if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
92b93329 1922fragment <<EOF
252b5132 1923
deb04cdb 1924static void
eaeb0a9d 1925gld${EMULATION_NAME}_after_allocation (void)
deb04cdb 1926{
f13a99db
AM
1927 bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
1928 &link_info);
8ded5a0f 1929 gld${EMULATION_NAME}_map_segments (need_layout);
73d074b4 1930}
41392f03
AM
1931EOF
1932fi
1933
1934if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
92b93329 1935fragment <<EOF
252b5132
RH
1936
1937static char *
0c7a8e5a 1938gld${EMULATION_NAME}_get_script (int *isfile)
252b5132
RH
1939EOF
1940
1941if test -n "$COMPILE_IN"
1942then
1943# Scripts compiled in.
1944
1945# sed commands to quote an ld script as a C string.
597e2591 1946sc="-f stringify.sed"
252b5132 1947
92b93329 1948fragment <<EOF
60bcf0fa 1949{
252b5132
RH
1950 *isfile = 0;
1951
1049f94e 1952 if (link_info.relocatable && config.build_constructors)
597e2591 1953 return
252b5132 1954EOF
afd7a018
AM
1955sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1956echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1957sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1958echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1959sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
61585df2 1960if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
afd7a018
AM
1961echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1962sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
db6751f2 1963fi
36af4a4e
JJ
1964if test -n "$GENERATE_PIE_SCRIPT" ; then
1965if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
8c37241b
JJ
1966echo ' ; else if (link_info.pie && link_info.combreloc' >> e${EMULATION_NAME}.c
1967echo ' && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 1968echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018 1969sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
36af4a4e 1970echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
afd7a018 1971sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
36af4a4e 1972fi
afd7a018
AM
1973echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c
1974sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
36af4a4e 1975fi
252b5132 1976if test -n "$GENERATE_SHLIB_SCRIPT" ; then
82434356 1977if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
8c37241b
JJ
1978echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c
1979echo ' && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 1980echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018 1981sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
db6751f2 1982echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
afd7a018 1983sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
82434356 1984fi
afd7a018
AM
1985echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1986sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
252b5132 1987fi
82434356 1988if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
8c37241b 1989echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
fbfca19e 1990echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
afd7a018
AM
1991sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
1992echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
1993sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
82434356 1994fi
afd7a018
AM
1995echo ' ; else return' >> e${EMULATION_NAME}.c
1996sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1997echo '; }' >> e${EMULATION_NAME}.c
252b5132
RH
1998
1999else
2000# Scripts read from the filesystem.
2001
92b93329 2002fragment <<EOF
60bcf0fa 2003{
252b5132
RH
2004 *isfile = 1;
2005
1049f94e 2006 if (link_info.relocatable && config.build_constructors)
252b5132 2007 return "ldscripts/${EMULATION_NAME}.xu";
1049f94e 2008 else if (link_info.relocatable)
252b5132
RH
2009 return "ldscripts/${EMULATION_NAME}.xr";
2010 else if (!config.text_read_only)
2011 return "ldscripts/${EMULATION_NAME}.xbn";
a060b769
AM
2012EOF
2013if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2014else
92b93329 2015fragment <<EOF
252b5132
RH
2016 else if (!config.magic_demand_paged)
2017 return "ldscripts/${EMULATION_NAME}.xn";
a060b769
AM
2018EOF
2019fi
36af4a4e
JJ
2020if test -n "$GENERATE_PIE_SCRIPT" ; then
2021if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2022fragment <<EOF
8c37241b 2023 else if (link_info.pie && link_info.combreloc
fbfca19e 2024 && link_info.relro && (link_info.flags & DF_BIND_NOW))
8c37241b 2025 return "ldscripts/${EMULATION_NAME}.xdw";
36af4a4e
JJ
2026 else if (link_info.pie && link_info.combreloc)
2027 return "ldscripts/${EMULATION_NAME}.xdc";
2028EOF
2029fi
92b93329 2030fragment <<EOF
36af4a4e
JJ
2031 else if (link_info.pie)
2032 return "ldscripts/${EMULATION_NAME}.xd";
2033EOF
2034fi
a060b769
AM
2035if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2036if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2037fragment <<EOF
8c37241b 2038 else if (link_info.shared && link_info.combreloc
fbfca19e 2039 && link_info.relro && (link_info.flags & DF_BIND_NOW))
8c37241b 2040 return "ldscripts/${EMULATION_NAME}.xsw";
a060b769
AM
2041 else if (link_info.shared && link_info.combreloc)
2042 return "ldscripts/${EMULATION_NAME}.xsc";
2043EOF
2044fi
92b93329 2045fragment <<EOF
252b5132
RH
2046 else if (link_info.shared)
2047 return "ldscripts/${EMULATION_NAME}.xs";
a060b769
AM
2048EOF
2049fi
2050if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
92b93329 2051fragment <<EOF
8c37241b 2052 else if (link_info.combreloc && link_info.relro
fbfca19e 2053 && (link_info.flags & DF_BIND_NOW))
8c37241b 2054 return "ldscripts/${EMULATION_NAME}.xw";
a060b769
AM
2055 else if (link_info.combreloc)
2056 return "ldscripts/${EMULATION_NAME}.xc";
2057EOF
2058fi
92b93329 2059fragment <<EOF
252b5132
RH
2060 else
2061 return "ldscripts/${EMULATION_NAME}.x";
2062}
252b5132 2063
3b108066 2064EOF
41392f03
AM
2065fi
2066fi
3b108066 2067
41392f03 2068if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
3b108066 2069
e0ee487b 2070if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
92b93329 2071fragment <<EOF
e0ee487b
L
2072 $PARSE_AND_LIST_PROLOGUE
2073EOF
2074fi
2075
92b93329 2076fragment <<EOF
e0ee487b 2077
6c1439be
L
2078#define OPTION_DISABLE_NEW_DTAGS (400)
2079#define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
a1ab1d2a 2080#define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
65765700 2081#define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
b58f81ae 2082#define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
fdc90cb4 2083#define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
c0065db7 2084#define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
7ee314fa 2085#define OPTION_AUDIT (OPTION_BUILD_ID + 1)
e13629bc 2086
3bcf5557 2087static void
0c7a8e5a
AM
2088gld${EMULATION_NAME}_add_options
2089 (int ns, char **shortopts, int nl, struct option **longopts,
2090 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
e0ee487b 2091{
7ee314fa 2092 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
3bcf5557 2093 static const struct option xtra_long[] = {
c0065db7 2094 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
7ee314fa
AM
2095 {"audit", required_argument, NULL, OPTION_AUDIT},
2096 {"depaudit", required_argument, NULL, 'P'},
e0ee487b 2097EOF
e0ee487b
L
2098
2099if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
92b93329 2100fragment <<EOF
3bcf5557
AM
2101 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2102 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2103 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
b58f81ae 2104 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
fdc90cb4 2105 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
3bcf5557 2106 {"Bgroup", no_argument, NULL, OPTION_GROUP},
e0ee487b
L
2107EOF
2108fi
2109
2110if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
92b93329 2111fragment <<EOF
3bcf5557 2112 $PARSE_AND_LIST_LONGOPTS
e0ee487b
L
2113EOF
2114fi
2115
92b93329 2116fragment <<EOF
3bcf5557
AM
2117 {NULL, no_argument, NULL, 0}
2118 };
2119
2120 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2121 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2122 *longopts = (struct option *)
2123 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2124 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2125}
04925e1e 2126
24382dca 2127#define DEFAULT_BUILD_ID_STYLE "sha1"
c0065db7 2128
3bcf5557 2129static bfd_boolean
0c7a8e5a 2130gld${EMULATION_NAME}_handle_option (int optc)
e0ee487b 2131{
e0ee487b
L
2132 switch (optc)
2133 {
2134 default:
3bcf5557 2135 return FALSE;
6c1439be 2136
c0065db7
RM
2137 case OPTION_BUILD_ID:
2138 if (link_info.emit_note_gnu_build_id != NULL)
2139 {
2140 free (link_info.emit_note_gnu_build_id);
2141 link_info.emit_note_gnu_build_id = NULL;
2142 }
2143 if (optarg == NULL)
2144 optarg = DEFAULT_BUILD_ID_STYLE;
2145 if (strcmp (optarg, "none"))
2146 link_info.emit_note_gnu_build_id = xstrdup (optarg);
2147 break;
7ee314fa
AM
2148 case OPTION_AUDIT:
2149 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2150 break;
2151 case 'P':
2152 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2153 break;
c0065db7 2154
e0ee487b 2155EOF
e0ee487b
L
2156
2157if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
92b93329 2158fragment <<EOF
6c1439be 2159 case OPTION_DISABLE_NEW_DTAGS:
b34976b6 2160 link_info.new_dtags = FALSE;
6c1439be
L
2161 break;
2162
2163 case OPTION_ENABLE_NEW_DTAGS:
b34976b6 2164 link_info.new_dtags = TRUE;
6c1439be
L
2165 break;
2166
65765700 2167 case OPTION_EH_FRAME_HDR:
b34976b6 2168 link_info.eh_frame_hdr = TRUE;
65765700
JJ
2169 break;
2170
a1ab1d2a
UD
2171 case OPTION_GROUP:
2172 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2173 /* Groups must be self-contained. */
560e09e9
NC
2174 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2175 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
a1ab1d2a
UD
2176 break;
2177
b58f81ae
DJ
2178 case OPTION_EXCLUDE_LIBS:
2179 add_excluded_libs (optarg);
2180 break;
2181
fdc90cb4
JJ
2182 case OPTION_HASH_STYLE:
2183 link_info.emit_hash = FALSE;
2184 link_info.emit_gnu_hash = FALSE;
2185 if (strcmp (optarg, "sysv") == 0)
2186 link_info.emit_hash = TRUE;
2187 else if (strcmp (optarg, "gnu") == 0)
2188 link_info.emit_gnu_hash = TRUE;
2189 else if (strcmp (optarg, "both") == 0)
2190 {
2191 link_info.emit_hash = TRUE;
2192 link_info.emit_gnu_hash = TRUE;
2193 }
2194 else
2195 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2196 break;
2197
e0ee487b
L
2198 case 'z':
2199 if (strcmp (optarg, "initfirst") == 0)
2200 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2201 else if (strcmp (optarg, "interpose") == 0)
2202 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2203 else if (strcmp (optarg, "loadfltr") == 0)
2204 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2205 else if (strcmp (optarg, "nodefaultlib") == 0)
2206 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2207 else if (strcmp (optarg, "nodelete") == 0)
2208 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2209 else if (strcmp (optarg, "nodlopen") == 0)
2210 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2211 else if (strcmp (optarg, "nodump") == 0)
2212 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2213 else if (strcmp (optarg, "now") == 0)
2214 {
2215 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2216 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2217 }
5fa222e4
AM
2218 else if (strcmp (optarg, "lazy") == 0)
2219 {
2220 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2221 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2222 }
e0ee487b
L
2223 else if (strcmp (optarg, "origin") == 0)
2224 {
2225 link_info.flags |= (bfd_vma) DF_ORIGIN;
2226 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2227 }
a1ab1d2a 2228 else if (strcmp (optarg, "defs") == 0)
560e09e9 2229 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
aa713662 2230 else if (strcmp (optarg, "muldefs") == 0)
b34976b6 2231 link_info.allow_multiple_definition = TRUE;
db6751f2 2232 else if (strcmp (optarg, "combreloc") == 0)
b34976b6 2233 link_info.combreloc = TRUE;
db6751f2 2234 else if (strcmp (optarg, "nocombreloc") == 0)
b34976b6 2235 link_info.combreloc = FALSE;
8bd621d8 2236 else if (strcmp (optarg, "nocopyreloc") == 0)
0c7a8e5a 2237 link_info.nocopyreloc = TRUE;
9ee5e499
JJ
2238 else if (strcmp (optarg, "execstack") == 0)
2239 {
2240 link_info.execstack = TRUE;
2241 link_info.noexecstack = FALSE;
2242 }
2243 else if (strcmp (optarg, "noexecstack") == 0)
2244 {
2245 link_info.noexecstack = TRUE;
2246 link_info.execstack = FALSE;
2247 }
88b882e9
L
2248EOF
2249
2250 if test -n "$COMMONPAGESIZE"; then
92b93329 2251fragment <<EOF
8c37241b
JJ
2252 else if (strcmp (optarg, "relro") == 0)
2253 link_info.relro = TRUE;
2254 else if (strcmp (optarg, "norelro") == 0)
2255 link_info.relro = FALSE;
88b882e9
L
2256EOF
2257 fi
2258
92b93329 2259fragment <<EOF
0112cd26 2260 else if (CONST_STRNEQ (optarg, "max-page-size="))
24718e3b
L
2261 {
2262 char *end;
0112cd26 2263
24718e3b 2264 config.maxpagesize = strtoul (optarg + 14, &end, 0);
b8142865 2265 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
24718e3b
L
2266 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2267 optarg + 14);
2268 }
0112cd26 2269 else if (CONST_STRNEQ (optarg, "common-page-size="))
24718e3b
L
2270 {
2271 char *end;
2272 config.commonpagesize = strtoul (optarg + 17, &end, 0);
b8142865
L
2273 if (*end
2274 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
24718e3b
L
2275 einfo (_("%P%F: invalid common page size \`%s'\n"),
2276 optarg + 17);
2277 }
e0ee487b 2278 /* What about the other Solaris -z options? FIXME. */
6c1439be 2279 break;
e0ee487b
L
2280EOF
2281fi
2282
2283if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
92b93329 2284fragment <<EOF
e0ee487b
L
2285 $PARSE_AND_LIST_ARGS_CASES
2286EOF
2287fi
2288
92b93329 2289fragment <<EOF
e0ee487b
L
2290 }
2291
3bcf5557 2292 return TRUE;
e0ee487b
L
2293}
2294
41392f03 2295EOF
41392f03 2296
4b209b22 2297if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
92b93329 2298fragment <<EOF
41392f03 2299
e0ee487b 2300static void
0c7a8e5a 2301gld${EMULATION_NAME}_list_options (FILE * file)
e0ee487b 2302{
442996ee
AM
2303 fprintf (file, _("\
2304 --build-id[=STYLE] Generate build ID note\n"));
7ee314fa
AM
2305 fprintf (file, _("\
2306 --audit=AUDITLIB Specify a library to use for auditing\n"));
2307 fprintf (file, _("\
2308 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
2309 Specify a library to use for auditing dependencies\n"));
e0ee487b 2310EOF
e0ee487b
L
2311
2312if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
92b93329 2313fragment <<EOF
442996ee
AM
2314 fprintf (file, _("\
2315 -Bgroup Selects group name lookup rules for DSO\n"));
2316 fprintf (file, _("\
2317 --disable-new-dtags Disable new dynamic tags\n"));
2318 fprintf (file, _("\
2319 --enable-new-dtags Enable new dynamic tags\n"));
2320 fprintf (file, _("\
2321 --eh-frame-hdr Create .eh_frame_hdr section\n"));
2322 fprintf (file, _("\
2323 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
2324 fprintf (file, _("\
2325 -z combreloc Merge dynamic relocs into one section and sort\n"));
2326 fprintf (file, _("\
2327 -z defs Report unresolved symbols in object files.\n"));
2328 fprintf (file, _("\
2329 -z execstack Mark executable as requiring executable stack\n"));
2330 fprintf (file, _("\
2331 -z initfirst Mark DSO to be initialized first at runtime\n"));
2332 fprintf (file, _("\
2333 -z interpose Mark object to interpose all DSOs but executable\n"));
2334 fprintf (file, _("\
2335 -z lazy Mark object lazy runtime binding (default)\n"));
2336 fprintf (file, _("\
2337 -z loadfltr Mark object requiring immediate process\n"));
2338 fprintf (file, _("\
2339 -z muldefs Allow multiple definitions\n"));
2340 fprintf (file, _("\
2341 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2342 fprintf (file, _("\
2343 -z nocopyreloc Don't create copy relocs\n"));
2344 fprintf (file, _("\
2345 -z nodefaultlib Mark object not to use default search paths\n"));
2346 fprintf (file, _("\
2347 -z nodelete Mark DSO non-deletable at runtime\n"));
2348 fprintf (file, _("\
2349 -z nodlopen Mark DSO not available to dlopen\n"));
2350 fprintf (file, _("\
2351 -z nodump Mark DSO not available to dldump\n"));
2352 fprintf (file, _("\
2353 -z noexecstack Mark executable as not requiring executable stack\n"));
88b882e9
L
2354EOF
2355
2356 if test -n "$COMMONPAGESIZE"; then
92b93329 2357fragment <<EOF
442996ee
AM
2358 fprintf (file, _("\
2359 -z norelro Don't create RELRO program header\n"));
88b882e9
L
2360EOF
2361 fi
2362
92b93329 2363fragment <<EOF
442996ee
AM
2364 fprintf (file, _("\
2365 -z now Mark object non-lazy runtime binding\n"));
2366 fprintf (file, _("\
2367 -z origin Mark object requiring immediate \$ORIGIN\n\
2368 processing at runtime\n"));
88b882e9
L
2369EOF
2370
2371 if test -n "$COMMONPAGESIZE"; then
92b93329 2372fragment <<EOF
442996ee
AM
2373 fprintf (file, _("\
2374 -z relro Create RELRO program header\n"));
88b882e9
L
2375EOF
2376 fi
2377
92b93329 2378fragment <<EOF
442996ee
AM
2379 fprintf (file, _("\
2380 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2381 fprintf (file, _("\
2382 -z common-page-size=SIZE Set common page size to SIZE\n"));
2383 fprintf (file, _("\
2384 -z KEYWORD Ignored for Solaris compatibility\n"));
e0ee487b
L
2385EOF
2386fi
2387
2388if test -n "$PARSE_AND_LIST_OPTIONS" ; then
92b93329 2389fragment <<EOF
e0ee487b
L
2390 $PARSE_AND_LIST_OPTIONS
2391EOF
2392fi
2393
92b93329 2394fragment <<EOF
e0ee487b
L
2395}
2396EOF
e0ee487b
L
2397
2398if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
92b93329 2399fragment <<EOF
e0ee487b
L
2400 $PARSE_AND_LIST_EPILOGUE
2401EOF
2402fi
41392f03
AM
2403fi
2404else
92b93329 2405fragment <<EOF
3bcf5557
AM
2406#define gld${EMULATION_NAME}_add_options NULL
2407#define gld${EMULATION_NAME}_handle_option NULL
41392f03 2408EOF
4b209b22 2409if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
92b93329 2410fragment <<EOF
4b209b22 2411#define gld${EMULATION_NAME}_list_options NULL
41392f03
AM
2412EOF
2413fi
2414fi
e0ee487b 2415
92b93329 2416fragment <<EOF
252b5132 2417
60bcf0fa 2418struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132 2419{
41392f03
AM
2420 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2421 ${LDEMUL_SYSLIB-syslib_default},
2422 ${LDEMUL_HLL-hll_default},
2423 ${LDEMUL_AFTER_PARSE-after_parse_default},
2424 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
eaeb0a9d 2425 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
41392f03
AM
2426 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2427 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2428 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2429 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
252b5132
RH
2430 "${EMULATION_NAME}",
2431 "${OUTPUT_FORMAT}",
eaeb0a9d 2432 ${LDEMUL_FINISH-finish_default},
41392f03
AM
2433 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2434 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2435 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2436 ${LDEMUL_SET_SYMBOLS-NULL},
3bcf5557
AM
2437 ${LDEMUL_PARSE_ARGS-NULL},
2438 gld${EMULATION_NAME}_add_options,
2439 gld${EMULATION_NAME}_handle_option,
41392f03 2440 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
4b209b22 2441 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
4a43e768 2442 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
41392f03 2443 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
fac1652d 2444 ${LDEMUL_NEW_VERS_PATTERN-NULL}
252b5132
RH
2445};
2446EOF
This page took 0.578683 seconds and 4 git commands to generate.