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
5 test -z "${ELFSIZE}" && ELFSIZE=32
6 if [ -z "$MACHINE" ]; then
9 OUTPUT_ARCH=${ARCH}:${MACHINE}
12 /* This file is is generated by a shell script. DO NOT EDIT! */
14 /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
15 Copyright (C) 1991-2017 Free Software Foundation, Inc.
16 Written by Steve Chamberlain <sac@cygnus.com>
17 ELF support by Ian Lance Taylor <ian@cygnus.com>
19 This file is part of the GNU Binutils.
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.
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.
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. */
36 #define TARGET_IS_${EMULATION_NAME}
40 #include "libiberty.h"
41 #include "safe-ctype.h"
42 #include "filenames.h"
55 #include "ldbuildid.h"
57 #include "elf/common.h"
59 #include "filenames.h"
61 /* Declare functions used by various EXTRA_EM_FILEs. */
62 static void gld${EMULATION_NAME}_before_parse (void);
63 static void gld${EMULATION_NAME}_after_parse (void);
64 static void gld${EMULATION_NAME}_after_open (void);
65 static void gld${EMULATION_NAME}_before_allocation (void);
66 static void gld${EMULATION_NAME}_after_allocation (void);
67 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
68 (asection *, const char *, int);
71 if [ "x${USE_LIBPATH}" = xyes ] ; then
73 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
83 # Import any needed special functions and/or overrides.
85 source_em ${srcdir}/emultempl/elf-generic.em
86 if test -n "$EXTRA_EM_FILE" ; then
87 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
90 # Functions in this file can be overridden by setting the LDEMUL_* shell
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.
96 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
100 gld${EMULATION_NAME}_before_parse (void)
102 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
103 input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
104 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
105 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
106 `if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`;
107 link_info.check_relocs_after_open_input = `if test "x${CHECK_RELOCS_AFTER_OPEN_INPUT}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
108 link_info.relro = DEFAULT_LD_Z_RELRO;
114 if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
118 gld${EMULATION_NAME}_after_parse (void)
120 if (bfd_link_pie (&link_info))
121 link_info.flags_1 |= (bfd_vma) DF_1_PIE;
123 after_parse_default ();
129 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
131 /* Handle the generation of DT_NEEDED tags. */
134 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
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. */
141 if (entry->flags.add_DT_NEEDED_for_regular)
142 link_class = DYN_AS_NEEDED;
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
147 if (!entry->flags.add_DT_NEEDED_for_dynamic)
148 link_class |= DYN_NO_ADD_NEEDED;
150 if (entry->flags.just_syms
151 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
152 einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
156 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
159 bfd_elf_set_dyn_lib_class (entry->the_bfd,
160 (enum dynamic_lib_link_class) link_class);
162 /* Continue on with normal load_symbols processing. */
170 /* These variables are required to pass information back and forth
171 between after_open and check_needed and stat_needed and vercheck. */
173 static struct bfd_link_needed_list *global_needed;
174 static struct stat global_stat;
175 static lang_input_statement_type *global_found;
176 static struct bfd_link_needed_list *global_vercheck_needed;
177 static bfd_boolean global_vercheck_failed;
179 /* These variables are used to implement target options */
181 static char *audit; /* colon (typically) separated list of libs */
182 static char *depaudit; /* colon (typically) separated list of libs */
184 /* Style of .note.gnu.build-id section. */
185 static const char *emit_note_gnu_build_id;
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.
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
199 This is called via lang_for_each_input_file.
200 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
201 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
202 a conflicting version. */
205 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
208 struct bfd_link_needed_list *l;
210 if (global_vercheck_failed)
212 if (s->the_bfd == NULL
213 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
216 soname = bfd_elf_get_dt_soname (s->the_bfd);
218 soname = lbasename (bfd_get_filename (s->the_bfd));
220 for (l = global_vercheck_needed; l != NULL; l = l->next)
224 if (filename_cmp (soname, l->name) == 0)
226 /* Probably can't happen, but it's an easy check. */
230 if (strchr (l->name, '/') != NULL)
233 suffix = strstr (l->name, ".so.");
237 suffix += sizeof ".so." - 1;
239 if (filename_ncmp (soname, l->name, suffix - l->name) == 0)
241 /* Here we know that S is a dynamic object FOO.SO.VER1, and
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. */
246 global_vercheck_failed = TRUE;
253 /* See if an input file matches a DT_NEEDED entry by running stat on
257 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
263 if (global_found != NULL)
265 if (s->the_bfd == NULL)
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)
273 if (bfd_stat (s->the_bfd, &st) != 0)
275 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
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
286 if (st.st_dev == global_stat.st_dev
287 && st.st_ino == global_stat.st_ino
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
298 heuristic test, and it will only work if the name looks like
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. */
303 if (strchr (global_needed->name, '/') != NULL)
305 suffix = strstr (global_needed->name, ".so.");
308 suffix += sizeof ".so." - 1;
310 soname = bfd_elf_get_dt_soname (s->the_bfd);
312 soname = lbasename (s->filename);
314 if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
315 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
316 global_needed->name, global_needed->by, soname);
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. */
330 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
334 const char *name = needed->name;
338 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
342 info_msg (_("attempt to open %s failed\n"), name);
346 /* Linker needs to decompress sections. */
347 abfd->flags |= BFD_DECOMPRESS;
349 if (! bfd_check_format (abfd, bfd_object))
354 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
360 /* For DT_NEEDED, they have to match. */
361 if (abfd->xvec != link_info.output_bfd->xvec)
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. */
374 struct bfd_link_needed_list *needs;
376 if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
377 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
381 global_vercheck_needed = needs;
382 global_vercheck_failed = FALSE;
383 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
384 if (global_vercheck_failed)
387 /* Return FALSE to force the caller to move on to try
388 another file on the search path. */
392 /* But wait! It gets much worse. On Linux, if a shared
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. */
401 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
404 struct bfd_link_needed_list *l;
406 for (l = needs; l != NULL; l = l->next)
407 if (CONST_STRNEQ (l->name, "libc.so"))
423 /* We've found a dynamic object matching the DT_NEEDED entry. */
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. */
433 if (bfd_stat (abfd, &global_stat) != 0)
434 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
436 /* First strip off everything before the last '/'. */
437 soname = lbasename (abfd->filename);
440 info_msg (_("found %s at %s\n"), soname, name);
443 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
444 if (global_found != NULL)
446 /* Return TRUE to indicate that we found the file, even though
447 we aren't going to do anything with it. */
451 /* Specify the soname to use. */
452 bfd_elf_set_dt_needed_name (abfd, soname);
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. */
457 link_class = DYN_DT_NEEDED;
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. */
462 if (needed->by != NULL
463 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
464 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
466 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
468 /* Add this file into the symbol table. */
469 if (! bfd_link_add_symbols (abfd, &link_info))
470 einfo ("%F%B: error adding symbols: %E\n", abfd);
475 /* Search for a needed file in a path. */
478 gld${EMULATION_NAME}_search_needed (const char *path,
479 struct dt_needed *n, int force)
482 const char *name = n->name;
484 struct dt_needed needed;
487 return gld${EMULATION_NAME}_try_needed (n, force);
489 if (path == NULL || *path == '\0')
493 needed.name = n->name;
500 char *filename, *sset;
502 s = strchr (path, config.rpath_separator);
504 s = path + strlen (path);
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 == ':'
512 s = strchr (s + 1, config.rpath_separator);
514 s = path + strlen (path);
517 filename = (char *) xmalloc (s - path + len + 2);
522 memcpy (filename, path, s - path);
523 filename[s - path] = '/';
524 sset = filename + (s - path) + 1;
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
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)
536 /* The ld.so manual page does not say, but I am going to assume that
537 these tokens are terminated by a directory separator character
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
542 The ld.so manual page also states that it allows ${ORIGIN},
543 ${LIB} and ${PLATFORM}, so these are supported as well.
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;
550 char * freeme = NULL;
551 unsigned flen = strlen (filename);
554 /* Temporarily terminate the filename at the end of the token. */
562 if (strcmp (v, "RIGIN") == 0 || strcmp (v, "RIGIN}") == 0)
564 /* ORIGIN - replace with the full path to the directory
565 containing the program or shared object. */
566 if (needed.by == NULL)
568 if (link_info.output_bfd == NULL)
573 replacement = bfd_get_filename (link_info.output_bfd);
576 replacement = bfd_get_filename (needed.by);
582 if (replacement[0] == '/')
583 freeme = xstrdup (replacement);
586 char * current_dir = getpwd ();
588 freeme = xmalloc (strlen (replacement) + strlen (current_dir) + 2);
589 sprintf (freeme, "%s/%s", current_dir, replacement);
592 replacement = freeme;
593 if ((slash = strrchr (replacement, '/')) != NULL)
600 if (strcmp (v, "IB") == 0 || strcmp (v, "IB}") == 0)
602 /* LIB - replace with "lib" in 32-bit environments
603 and "lib64" in 64-bit environments. */
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. */
611 case 32: replacement = "lib"; break;
612 case 64: replacement = "lib64"; break;
614 /* $ELFSIZE is not 32 or 64 ... */
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. */
633 char * filename2 = xmalloc (flen + strlen (replacement));
637 sprintf (filename2, "%.*s%s/%s",
638 (int)(var - filename), filename,
639 replacement, end + 1);
640 offset = (var - filename) + 1 + strlen (replacement);
644 sprintf (filename2, "%.*s%s",
645 (int)(var - filename), filename,
647 offset = var - filename + strlen (replacement);
651 filename = filename2;
652 /* There is no need to restore the path separator (when
653 end != NULL) as we have replaced the entire string. */
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. */
661 info_msg (_("unrecognised or unsupported token '%s' in search path\n"), var);
664 /* Restore the path separator. */
667 /* PR 20784: Make sure that we resume the scan
668 *after* the token that we could not replace. */
669 offset = (var + 1) - filename;
675 needed.name = filename;
677 if (gld${EMULATION_NAME}_try_needed (&needed, force))
691 if [ "x${USE_LIBPATH}" = xyes ] ; then
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. */
700 gld${EMULATION_NAME}_add_sysroot (const char *path)
705 int dos_drive_sysroot = HAS_DRIVE_SPEC (ld_sysroot);
707 len = strlen (ld_sysroot);
708 for (extra = 0, p = path; ; )
710 int dos_drive = HAS_DRIVE_SPEC (p);
714 if (IS_DIR_SEPARATOR (*p)
716 || (dos_drive_sysroot
717 && ld_sysroot[0] == p[-2])))
719 if (dos_drive && dos_drive_sysroot)
724 p = strchr (p, config.rpath_separator);
730 ret = xmalloc (strlen (path) + extra + 1);
732 for (q = ret, p = path; ; )
735 int dos_drive = HAS_DRIVE_SPEC (p);
742 if (IS_DIR_SEPARATOR (*p)
744 || (dos_drive_sysroot
745 && ld_sysroot[0] == p[-2])))
747 if (dos_drive && dos_drive_sysroot)
749 strcpy (q, ld_sysroot + 2);
754 strcpy (q, ld_sysroot);
758 end = strchr (p, config.rpath_separator);
761 size_t n = end - p + 1;
778 *-*-freebsd* | *-*-dragonfly*)
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>
784 #include "elf-hints-local.h"
788 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
791 static bfd_boolean initialized;
792 static const char *ld_elf_hints;
793 struct dt_needed needed;
800 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
801 f = fopen (tmppath, FOPEN_RB);
805 struct elfhints_hdr hdr;
807 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
808 && hdr.magic == ELFHINTS_MAGIC
811 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
815 b = xmalloc (hdr.dirlistlen + 1);
816 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
818 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
829 if (ld_elf_hints == NULL)
833 needed.name = l->name;
834 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
840 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
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
844 only meaningful on Linux. */
846 struct gld${EMULATION_NAME}_ld_so_conf
853 gld${EMULATION_NAME}_parse_ld_so_conf
854 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
857 gld${EMULATION_NAME}_parse_ld_so_conf_include
858 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
866 if (pattern[0] != '/')
868 char *p = strrchr (filename, '/');
869 size_t patlen = strlen (pattern) + 1;
871 newp = xmalloc (p - filename + 1 + patlen);
872 memcpy (newp, filename, p - filename + 1);
873 memcpy (newp + (p - filename + 1), pattern, patlen);
878 if (glob (pattern, 0, NULL, &gl) == 0)
882 for (i = 0; i < gl.gl_pathc; ++i)
883 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
887 /* If we do not have glob, treat the pattern as a literal filename. */
888 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
896 gld${EMULATION_NAME}_parse_ld_so_conf
897 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
899 FILE *f = fopen (filename, FOPEN_RT);
907 line = xmalloc (linelen);
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')
917 line = xrealloc (line, 2 * linelen);
918 p = line + linelen - 1;
922 if (q == NULL && p == line)
925 p = strchr (line, '\n');
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, '#');
936 /* Remove leading whitespace. NUL is no whitespace character. */
938 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
941 /* If the line is blank it is ignored. */
945 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
951 while (*p == ' ' || *p == '\t')
959 while (*p != ' ' && *p != '\t' && *p)
965 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
973 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
974 && *p != '\r' && *p != '\v')
977 while (p != dir && p[-1] == '/')
979 if (info->path == NULL)
981 info->alloc = p - dir + 1 + 256;
982 info->path = xmalloc (info->alloc);
987 if (info->len + 1 + (p - dir) >= info->alloc)
989 info->alloc += p - dir + 256;
990 info->path = xrealloc (info->path, info->alloc);
992 info->path[info->len++] = config.rpath_separator;
994 memcpy (info->path + info->len, dir, p - dir);
995 info->len += p - dir;
996 info->path[info->len] = '\0';
1006 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
1009 static bfd_boolean initialized;
1010 static const char *ld_so_conf;
1011 struct dt_needed needed;
1016 struct gld${EMULATION_NAME}_ld_so_conf info;
1019 info.len = info.alloc = 0;
1020 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
1021 (const char *) NULL);
1022 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
1025 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
1026 (const char *) NULL);
1027 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
1033 ld_so_conf = gld${EMULATION_NAME}_add_sysroot (info.path);
1039 if (ld_so_conf == NULL)
1044 needed.name = l->name;
1045 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
1055 /* See if an input file matches a DT_NEEDED entry by name. */
1058 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
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)
1068 if (s->filename == NULL || s->the_bfd == NULL)
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)
1076 if (filename_cmp (s->filename, global_needed->name) == 0)
1082 if (s->flags.search_dirs)
1084 const char *f = strrchr (s->filename, '/');
1086 && filename_cmp (f + 1, global_needed->name) == 0)
1093 soname = bfd_elf_get_dt_soname (s->the_bfd);
1095 && filename_cmp (soname, global_needed->name) == 0)
1104 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1107 static bfd_size_type
1108 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1110 const char *style = emit_note_gnu_build_id;
1112 bfd_size_type build_id_size;
1114 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1115 size = (size + 3) & -(bfd_size_type) 4;
1117 build_id_size = compute_build_id_size (style);
1119 size += build_id_size;
1127 write_build_id (bfd *abfd)
1129 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1130 struct elf_obj_tdata *t = elf_tdata (abfd);
1133 Elf_Internal_Shdr *i_shdr;
1134 unsigned char *contents, *id_bits;
1137 Elf_External_Note *e_note;
1139 style = t->o->build_id.style;
1140 asec = t->o->build_id.sec;
1141 if (bfd_is_abs_section (asec->output_section))
1143 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1144 " --build-id ignored.\n"));
1147 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1149 if (i_shdr->contents == NULL)
1151 if (asec->contents == NULL)
1152 asec->contents = (unsigned char *) xmalloc (asec->size);
1153 contents = asec->contents;
1156 contents = i_shdr->contents + asec->output_offset;
1158 e_note = (Elf_External_Note *) contents;
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;
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");
1169 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1171 position = i_shdr->sh_offset + asec->output_offset;
1173 return (bfd_seek (abfd, position, SEEK_SET) == 0
1174 && bfd_bwrite (contents, size, abfd) == size);
1177 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1180 setup_build_id (bfd *ibfd)
1186 size = id_note_section_size (ibfd);
1189 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
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))
1198 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
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;
1207 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1208 " --build-id ignored.\n");
1212 /* This is called after all the input files have been opened. */
1215 gld${EMULATION_NAME}_after_open (void)
1217 struct bfd_link_needed_list *needed, *l;
1218 struct elf_link_hash_table *htab;
1220 after_open_default ();
1222 htab = elf_hash_table (&link_info);
1223 if (!is_elf_hash_table (htab))
1226 if (command_line.out_implib_filename)
1228 unlink_if_ordinary (command_line.out_implib_filename);
1229 link_info.out_implib_bfd
1230 = bfd_openw (command_line.out_implib_filename,
1231 bfd_get_target (link_info.output_bfd));
1233 if (link_info.out_implib_bfd == NULL)
1235 einfo ("%F%s: Can't open for writing: %E\n",
1236 command_line.out_implib_filename);
1240 if (emit_note_gnu_build_id != NULL)
1244 /* Find an ELF input. */
1245 for (abfd = link_info.input_bfds;
1246 abfd != (bfd *) NULL; abfd = abfd->link.next)
1247 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1248 && bfd_count_sections (abfd) != 0)
1251 /* PR 10555: If there are no ELF input files do not try to
1252 create a .note.gnu-build-id section. */
1254 || !setup_build_id (abfd))
1256 free ((char *) emit_note_gnu_build_id);
1257 emit_note_gnu_build_id = NULL;
1261 get_elf_backend_data (link_info.output_bfd)->setup_gnu_properties (&link_info);
1263 if (bfd_link_relocatable (&link_info))
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,
1274 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1279 if (!link_info.traditional_format)
1281 bfd *abfd, *elfbfd = NULL;
1282 bfd_boolean warn_eh_frame = FALSE;
1286 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1289 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1291 const char *name = bfd_get_section_name (abfd, s);
1293 if (bfd_is_abs_section (s->output_section))
1295 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1296 type = COMPACT_EH_HDR;
1297 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1298 type = DWARF2_EH_HDR;
1307 else if (seen_type != type)
1309 einfo (_("%P%F: compact frame descriptions incompatible with"
1310 " DWARF2 .eh_frame from %B\n"),
1311 type == DWARF2_EH_HDR ? abfd : elfbfd);
1316 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1318 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1321 warn_eh_frame = TRUE;
1325 if (seen_type == COMPACT_EH_HDR)
1326 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1328 if (bfd_count_sections (abfd) == 0)
1333 const struct elf_backend_data *bed;
1335 bed = get_elf_backend_data (elfbfd);
1336 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1337 bed->dynamic_sec_flags
1340 && bfd_set_section_alignment (elfbfd, s, 2))
1342 htab->eh_info.hdr_sec = s;
1343 warn_eh_frame = FALSE;
1347 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1348 " --eh-frame-hdr ignored.\n");
1351 /* Get the list of files which appear in DT_NEEDED entries in
1352 dynamic objects included in the link (often there will be none).
1353 For each such file, we want to track down the corresponding
1354 library, and include the symbol table in the link. This is what
1355 the runtime dynamic linker will do. Tracking the files down here
1356 permits one dynamic object to include another without requiring
1357 special action by the person doing the link. Note that the
1358 needed list can actually grow while we are stepping through this
1360 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1361 for (l = needed; l != NULL; l = l->next)
1363 struct bfd_link_needed_list *ll;
1364 struct dt_needed n, nn;
1367 /* If the lib that needs this one was --as-needed and wasn't
1368 found to be needed, then this lib isn't needed either. */
1370 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1373 /* Skip the lib if --no-copy-dt-needed-entries and
1374 --allow-shlib-undefined is in effect. */
1376 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1377 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1380 /* If we've already seen this file, skip it. */
1381 for (ll = needed; ll != l; ll = ll->next)
1383 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1384 && strcmp (ll->name, l->name) == 0)
1389 /* See if this file was included in the link explicitly. */
1391 global_found = NULL;
1392 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1393 if (global_found != NULL
1394 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1395 & DYN_AS_NEEDED) == 0)
1402 info_msg (_("%s needed by %B\n"), l->name, l->by);
1404 /* As-needed libs specified on the command line (or linker script)
1405 take priority over libs found in search dirs. */
1406 if (global_found != NULL)
1408 nn.name = global_found->filename;
1409 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1413 /* We need to find this file and include the symbol table. We
1414 want to search for the file in the same way that the dynamic
1415 linker will search. That means that we want to use
1416 rpath_link, rpath, then the environment variable
1417 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1418 entries (native only), then the linker script LIB_SEARCH_DIRS.
1419 We do not search using the -L arguments.
1421 We search twice. The first time, we skip objects which may
1422 introduce version mismatches. The second time, we force
1423 their use. See gld${EMULATION_NAME}_vercheck comment. */
1424 for (force = 0; force < 2; force++)
1427 search_dirs_type *search;
1429 if [ "x${NATIVE}" = xyes ] || [ "x${USE_LIBPATH}" = xyes ] ; then
1434 if [ "x${USE_LIBPATH}" = xyes ] ; then
1436 struct bfd_link_needed_list *rp;
1442 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1446 if [ "x${USE_LIBPATH}" = xyes ] ; then
1448 path = command_line.rpath;
1451 path = gld${EMULATION_NAME}_add_sysroot (path);
1452 found = gld${EMULATION_NAME}_search_needed (path, &n, force);
1453 free ((char *) path);
1459 if [ "x${NATIVE}" = xyes ] ; then
1461 if (command_line.rpath_link == NULL
1462 && command_line.rpath == NULL)
1464 path = (const char *) getenv ("LD_RUN_PATH");
1466 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1469 path = (const char *) getenv ("LD_LIBRARY_PATH");
1471 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1475 if [ "x${USE_LIBPATH}" = xyes ] ; then
1478 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1479 for (; !found && rp != NULL; rp = rp->next)
1481 path = gld${EMULATION_NAME}_add_sysroot (rp->name);
1482 found = (rp->by == l->by
1483 && gld${EMULATION_NAME}_search_needed (path, &n,
1485 free ((char *) path);
1492 if [ "x${USE_LIBPATH}" = xyes ] ; then
1494 *-*-freebsd* | *-*-dragonfly*)
1496 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1502 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1504 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1513 len = strlen (l->name);
1514 for (search = search_head; search != NULL; search = search->next)
1518 if (search->cmdline)
1520 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1521 sprintf (filename, "%s/%s", search->name, l->name);
1523 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1536 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1540 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1541 if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE)
1542 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
1550 /* Look through an expression for an assignment statement. */
1553 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1555 bfd_boolean provide = FALSE;
1557 switch (exp->type.node_class)
1560 case etree_provided:
1564 /* We call record_link_assignment even if the symbol is defined.
1565 This is because if it is defined by a dynamic object, we
1566 actually want to use the value defined by the linker script,
1567 not the value from the dynamic object (because we are setting
1568 symbols like etext). If the symbol is defined by a regular
1569 object, then, as it happens, calling record_link_assignment
1571 if (strcmp (exp->assign.dst, ".") != 0)
1573 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1575 exp->assign.dst, provide,
1576 exp->assign.hidden))
1577 einfo ("%P%F: failed to record assignment to %s: %E\n",
1580 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1584 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1585 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1589 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1590 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1591 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1595 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1604 /* This is called by the before_allocation routine via
1605 lang_for_each_statement. It locates any assignment statements, and
1606 tells the ELF backend about them, in case they are assignments to
1607 symbols which are referred to by dynamic objects. */
1610 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1612 if (s->header.type == lang_assignment_statement_enum)
1613 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1618 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1619 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1620 ELF_INTERPRETER_SET_DEFAULT="
1621 if (sinterp != NULL)
1623 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1624 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1629 ELF_INTERPRETER_SET_DEFAULT=
1633 /* used by before_allocation and handle_option. */
1635 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1638 *to = xstrdup (op_arg);
1641 size_t to_len = strlen (*to);
1642 size_t op_arg_len = strlen (op_arg);
1646 /* First see whether OPTARG is already in the path. */
1649 if (strncmp (op_arg, cp, op_arg_len) == 0
1650 && (cp[op_arg_len] == 0
1651 || cp[op_arg_len] == config.rpath_separator))
1655 /* Not yet found. */
1656 cp = strchr (cp, config.rpath_separator);
1664 buf = xmalloc (to_len + op_arg_len + 2);
1665 sprintf (buf, "%s%c%s", *to,
1666 config.rpath_separator, op_arg);
1673 #if defined(__GNUC__) && GCC_VERSION < 4006
1674 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1675 static struct bfd_link_hash_entry ehdr_start_empty;
1678 /* This is called after the sections have been attached to output
1679 sections, but before any sizes or addresses have been set. */
1682 gld${EMULATION_NAME}_before_allocation (void)
1687 struct elf_link_hash_entry *ehdr_start = NULL;
1688 #if defined(__GNUC__) && GCC_VERSION < 4006
1689 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1690 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1692 struct bfd_link_hash_entry ehdr_start_save;
1695 if (is_elf_hash_table (link_info.hash))
1697 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1699 /* Make __ehdr_start hidden if it has been referenced, to
1700 prevent the symbol from being dynamic. */
1701 if (!bfd_link_relocatable (&link_info))
1703 struct elf_link_hash_entry *h
1704 = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
1705 FALSE, FALSE, TRUE);
1707 /* Only adjust the export class if the symbol was referenced
1708 and not defined, otherwise leave it alone. */
1710 && (h->root.type == bfd_link_hash_new
1711 || h->root.type == bfd_link_hash_undefined
1712 || h->root.type == bfd_link_hash_undefweak
1713 || h->root.type == bfd_link_hash_common))
1715 _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
1716 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1717 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1718 /* Don't leave the symbol undefined. Undefined hidden
1719 symbols typically won't have dynamic relocations, but
1720 we most likely will need dynamic relocations for
1721 __ehdr_start if we are building a PIE or shared
1724 ehdr_start_save = h->root;
1725 h->root.type = bfd_link_hash_defined;
1726 h->root.u.def.section = bfd_abs_section_ptr;
1727 h->root.u.def.value = 0;
1731 /* If we are going to make any variable assignments, we need to
1732 let the ELF backend know about them in case the variables are
1733 referred to by dynamic objects. */
1734 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1737 /* Let the ELF backend work out the sizes of any sections required
1738 by dynamic linking. */
1739 rpath = command_line.rpath;
1741 rpath = (const char *) getenv ("LD_RUN_PATH");
1743 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1744 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1746 const char *audit_libs = elf_dt_audit (abfd);
1748 /* If the input bfd contains an audit entry, we need to add it as
1749 a dep audit entry. */
1750 if (audit_libs && *audit_libs != '\0')
1752 char *cp = xstrdup (audit_libs);
1756 char *cp2 = strchr (cp, config.rpath_separator);
1764 if (cp != NULL && *cp != '\0')
1765 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1767 cp = more ? ++cp2 : NULL;
1773 if (! (bfd_elf_size_dynamic_sections
1774 (link_info.output_bfd, command_line.soname, rpath,
1775 command_line.filter_shlib, audit, depaudit,
1776 (const char * const *) command_line.auxiliary_filters,
1777 &link_info, &sinterp)))
1778 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1780 ${ELF_INTERPRETER_SET_DEFAULT}
1781 /* Let the user override the dynamic linker we are using. */
1782 if (command_line.interpreter != NULL
1785 sinterp->contents = (bfd_byte *) command_line.interpreter;
1786 sinterp->size = strlen (command_line.interpreter) + 1;
1789 /* Look for any sections named .gnu.warning. As a GNU extensions,
1790 we treat such sections as containing warning messages. We print
1791 out the warning message, and then zero out the section size so
1792 that it does not get copied into the output file. */
1795 LANG_FOR_EACH_INPUT_STATEMENT (is)
1801 if (is->flags.just_syms)
1804 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1809 msg = (char *) xmalloc ((size_t) (sz + 1));
1810 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1812 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1815 (*link_info.callbacks->warning) (&link_info, msg,
1816 (const char *) NULL, is->the_bfd,
1817 (asection *) NULL, (bfd_vma) 0);
1820 /* Clobber the section size, so that we don't waste space
1821 copying the warning into the output file. If we've already
1822 sized the output section, adjust its size. The adjustment
1823 is on rawsize because targets that size sections early will
1824 have called lang_reset_memory_regions after sizing. */
1825 if (s->output_section != NULL
1826 && s->output_section->rawsize >= s->size)
1827 s->output_section->rawsize -= s->size;
1831 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1832 warning section don't get copied to the output. */
1833 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1837 before_allocation_default ();
1839 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1840 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1842 if (ehdr_start != NULL)
1844 /* If we twiddled __ehdr_start to defined earlier, put it back
1846 ehdr_start->root.type = ehdr_start_save.type;
1847 ehdr_start->root.u = ehdr_start_save.u;
1854 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1857 /* Try to open a dynamic archive. This is where we know that ELF
1858 dynamic libraries have an extension of .so (or .sl on oddball systems
1862 gld${EMULATION_NAME}_open_dynamic_archive
1863 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1865 const char *filename;
1868 bfd_boolean opened = FALSE;
1870 if (! entry->flags.maybe_archive)
1873 filename = entry->filename;
1874 len = strlen (search->name) + strlen (filename);
1875 if (entry->flags.full_name_provided)
1878 string = (char *) xmalloc (len);
1879 sprintf (string, "%s/%s", search->name, filename);
1885 len += strlen (arch) + sizeof "/lib.so";
1886 #ifdef EXTRA_SHLIB_EXTENSION
1887 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1888 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1891 string = (char *) xmalloc (len + xlen);
1892 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1893 #ifdef EXTRA_SHLIB_EXTENSION
1894 /* Try the .so extension first. If that fails build a new filename
1895 using EXTRA_SHLIB_EXTENSION. */
1896 opened = ldfile_try_open_bfd (string, entry);
1898 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1902 if (!opened && !ldfile_try_open_bfd (string, entry))
1908 entry->filename = string;
1910 /* We have found a dynamic object to include in the link. The ELF
1911 backend linker will create a DT_NEEDED entry in the .dynamic
1912 section naming this file. If this file includes a DT_SONAME
1913 entry, it will be used. Otherwise, the ELF linker will just use
1914 the name of the file. For an archive found by searching, like
1915 this one, the DT_NEEDED entry should consist of just the name of
1916 the file, without the path information used to find it. Note
1917 that we only need to do this if we have a dynamic object; an
1918 archive will never be referenced by a DT_NEEDED entry.
1920 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1921 very pretty. I haven't been able to think of anything that is
1923 if (bfd_check_format (entry->the_bfd, bfd_object)
1924 && (entry->the_bfd->flags & DYNAMIC) != 0)
1926 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1928 /* Rather than duplicating the logic above. Just use the
1929 filename we recorded earlier. */
1931 if (!entry->flags.full_name_provided)
1932 filename = lbasename (entry->filename);
1933 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1942 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1945 /* A variant of lang_output_section_find used by place_orphan. */
1947 static lang_output_section_statement_type *
1948 output_rel_find (asection *sec, int isdyn)
1950 lang_output_section_statement_type *lookup;
1951 lang_output_section_statement_type *last = NULL;
1952 lang_output_section_statement_type *last_alloc = NULL;
1953 lang_output_section_statement_type *last_ro_alloc = NULL;
1954 lang_output_section_statement_type *last_rel = NULL;
1955 lang_output_section_statement_type *last_rel_alloc = NULL;
1956 int rela = sec->name[4] == 'a';
1958 for (lookup = &lang_output_section_statement.head->output_section_statement;
1960 lookup = lookup->next)
1962 if (lookup->constraint >= 0
1963 && CONST_STRNEQ (lookup->name, ".rel"))
1965 int lookrela = lookup->name[4] == 'a';
1967 /* .rel.dyn must come before all other reloc sections, to suit
1972 /* Don't place after .rel.plt as doing so results in wrong
1974 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1977 if (rela == lookrela || last_rel == NULL)
1979 if ((rela == lookrela || last_rel_alloc == NULL)
1980 && lookup->bfd_section != NULL
1981 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1982 last_rel_alloc = lookup;
1986 if (lookup->bfd_section != NULL
1987 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1989 last_alloc = lookup;
1990 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1991 last_ro_alloc = lookup;
1996 return last_rel_alloc;
2002 return last_ro_alloc;
2010 /* Place an orphan section. We use this to put random SHF_ALLOC
2011 sections in the right segment. */
2013 static lang_output_section_statement_type *
2014 gld${EMULATION_NAME}_place_orphan (asection *s,
2015 const char *secname,
2018 static struct orphan_save hold[] =
2021 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2024 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2027 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
2030 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2036 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2039 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2042 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
2048 enum orphan_save_index
2060 static int orphan_init_done = 0;
2061 struct orphan_save *place;
2062 lang_output_section_statement_type *after;
2063 lang_output_section_statement_type *os;
2064 lang_output_section_statement_type *match_by_name = NULL;
2066 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
2067 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
2071 if (!bfd_link_relocatable (&link_info)
2072 && link_info.combreloc
2073 && (s->flags & SEC_ALLOC))
2079 secname = ".rela.dyn";
2083 secname = ".rel.dyn";
2089 else if (CONST_STRNEQ (secname, ".rel"))
2091 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2096 /* Look through the script to see where to place this section. */
2097 if (constraint == 0)
2098 for (os = lang_output_section_find (secname);
2100 os = next_matching_output_section_statement (os, 0))
2102 /* If we don't match an existing output section, tell
2103 lang_insert_orphan to create a new output section. */
2104 constraint = SPECIAL;
2106 /* SEC_EXCLUDE is cleared when doing a relocatable link. But
2107 we can't merge 2 input sections with the same name when only
2108 one of them has SHF_EXCLUDE. */
2109 if (os->bfd_section != NULL
2110 && (os->bfd_section->flags == 0
2111 || ((!bfd_link_relocatable (&link_info)
2112 || (iself && (((elf_section_flags (s)
2113 ^ elf_section_flags (os->bfd_section))
2114 & SHF_EXCLUDE) == 0)))
2115 && ((s->flags ^ os->bfd_section->flags)
2116 & (SEC_LOAD | SEC_ALLOC)) == 0
2117 && _bfd_elf_match_sections_by_type (link_info.output_bfd,
2121 /* We already have an output section statement with this
2122 name, and its bfd section has compatible flags.
2123 If the section already exists but does not have any flags
2124 set, then it has been created by the linker, probably as a
2125 result of a --section-start command line switch. */
2126 lang_add_section (&os->children, s, NULL, os);
2130 /* Save unused output sections in case we can match them
2131 against orphans later. */
2132 if (os->bfd_section == NULL)
2136 /* If we didn't match an active output section, see if we matched an
2137 unused one and use that. */
2140 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2141 return match_by_name;
2144 if (!orphan_init_done)
2146 struct orphan_save *ho;
2148 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2149 if (ho->name != NULL)
2151 ho->os = lang_output_section_find (ho->name);
2152 if (ho->os != NULL && ho->os->flags == 0)
2153 ho->os->flags = ho->flags;
2155 orphan_init_done = 1;
2158 /* If this is a final link, then always put .gnu.warning.SYMBOL
2159 sections into the .text section to get them out of the way. */
2160 if (bfd_link_executable (&link_info)
2161 && CONST_STRNEQ (s->name, ".gnu.warning.")
2162 && hold[orphan_text].os != NULL)
2164 os = hold[orphan_text].os;
2165 lang_add_section (&os->children, s, NULL, os);
2170 if (!bfd_link_relocatable (&link_info))
2173 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2175 if (nexts->output_section == NULL
2176 && (nexts->flags & SEC_EXCLUDE) == 0
2177 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2178 && (nexts->owner->flags & DYNAMIC) == 0
2179 && nexts->owner->usrdata != NULL
2180 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2182 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2184 flags = (((flags ^ SEC_READONLY)
2185 | (nexts->flags ^ SEC_READONLY))
2189 /* Decide which segment the section should go in based on the
2190 section name and section flags. We put loadable .note sections
2191 right after the .interp section, so that the PT_NOTE segment is
2192 stored right after the program headers where the OS can read it
2193 in the first page. */
2196 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2197 place = &hold[orphan_nonalloc];
2198 else if ((flags & SEC_ALLOC) == 0)
2200 else if ((flags & SEC_LOAD) != 0
2201 && ((iself && sh_type == SHT_NOTE)
2202 || (!iself && CONST_STRNEQ (secname, ".note"))))
2203 place = &hold[orphan_interp];
2204 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2205 place = &hold[orphan_bss];
2206 else if ((flags & SEC_SMALL_DATA) != 0)
2207 place = &hold[orphan_sdata];
2208 else if ((flags & SEC_THREAD_LOCAL) != 0)
2209 place = &hold[orphan_tdata];
2210 else if ((flags & SEC_READONLY) == 0)
2211 place = &hold[orphan_data];
2212 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
2213 || (!iself && CONST_STRNEQ (secname, ".rel")))
2214 && (flags & SEC_LOAD) != 0)
2215 place = &hold[orphan_rel];
2216 else if ((flags & SEC_CODE) == 0)
2217 place = &hold[orphan_rodata];
2219 place = &hold[orphan_text];
2224 if (place->os == NULL)
2226 if (place->name != NULL)
2227 place->os = lang_output_section_find (place->name);
2229 place->os = output_rel_find (s, isdyn);
2234 = lang_output_section_find_by_flags (s, flags, &place->os,
2235 _bfd_elf_match_sections_by_type);
2237 /* *ABS* is always the first output section statement. */
2238 after = &lang_output_section_statement.head->output_section_statement;
2241 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2246 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2250 gld${EMULATION_NAME}_after_allocation (void)
2252 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2254 if (need_layout < 0)
2255 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
2257 gld${EMULATION_NAME}_map_segments (need_layout);
2262 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2266 gld${EMULATION_NAME}_get_script (int *isfile)
2269 if test x"$COMPILE_IN" = xyes
2271 # Scripts compiled in.
2273 # sed commands to quote an ld script as a C string.
2274 sc="-f stringify.sed"
2280 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2283 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2284 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2285 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2286 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2287 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2288 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2289 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2290 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2292 if test -n "$GENERATE_PIE_SCRIPT" ; then
2293 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2294 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2295 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2296 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2297 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2298 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2299 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2300 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2301 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2303 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2304 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2306 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2307 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2308 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
2309 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2310 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2311 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2312 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2313 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2315 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2316 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2318 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2319 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
2320 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2321 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2322 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2323 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2325 echo ' ; else return' >> e${EMULATION_NAME}.c
2326 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2327 echo '; }' >> e${EMULATION_NAME}.c
2330 # Scripts read from the filesystem.
2336 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2337 return "ldscripts/${EMULATION_NAME}.xu";
2338 else if (bfd_link_relocatable (&link_info))
2339 return "ldscripts/${EMULATION_NAME}.xr";
2340 else if (!config.text_read_only)
2341 return "ldscripts/${EMULATION_NAME}.xbn";
2343 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2346 else if (!config.magic_demand_paged)
2347 return "ldscripts/${EMULATION_NAME}.xn";
2350 if test -n "$GENERATE_PIE_SCRIPT" ; then
2351 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2353 else if (bfd_link_pie (&link_info)
2354 && link_info.combreloc
2356 && (link_info.flags & DF_BIND_NOW))
2357 return "ldscripts/${EMULATION_NAME}.xdw";
2358 else if (bfd_link_pie (&link_info)
2359 && link_info.combreloc)
2360 return "ldscripts/${EMULATION_NAME}.xdc";
2364 else if (bfd_link_pie (&link_info))
2365 return "ldscripts/${EMULATION_NAME}.xd";
2368 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2369 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2371 else if (bfd_link_dll (&link_info) && link_info.combreloc
2372 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2373 return "ldscripts/${EMULATION_NAME}.xsw";
2374 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2375 return "ldscripts/${EMULATION_NAME}.xsc";
2379 else if (bfd_link_dll (&link_info))
2380 return "ldscripts/${EMULATION_NAME}.xs";
2383 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2385 else if (link_info.combreloc && link_info.relro
2386 && (link_info.flags & DF_BIND_NOW))
2387 return "ldscripts/${EMULATION_NAME}.xw";
2388 else if (link_info.combreloc)
2389 return "ldscripts/${EMULATION_NAME}.xc";
2394 return "ldscripts/${EMULATION_NAME}.x";
2401 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2403 $PARSE_AND_LIST_PROLOGUE
2411 OPTION_DISABLE_NEW_DTAGS = 400,
2412 OPTION_ENABLE_NEW_DTAGS,
2414 OPTION_EH_FRAME_HDR,
2415 OPTION_NO_EH_FRAME_HDR,
2416 OPTION_EXCLUDE_LIBS,
2420 OPTION_COMPRESS_DEBUG
2424 gld${EMULATION_NAME}_add_options
2425 (int ns, char **shortopts, int nl, struct option **longopts,
2426 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2429 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2431 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2435 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2439 static const struct option xtra_long[] = {
2441 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2443 {"audit", required_argument, NULL, OPTION_AUDIT},
2444 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2448 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2449 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2451 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2453 {"depaudit", required_argument, NULL, 'P'},
2454 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2455 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2456 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2457 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2458 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2459 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2462 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2464 $PARSE_AND_LIST_LONGOPTS
2468 {NULL, no_argument, NULL, 0}
2471 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2472 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2473 *longopts = (struct option *)
2474 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2475 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2478 #define DEFAULT_BUILD_ID_STYLE "sha1"
2481 gld${EMULATION_NAME}_handle_option (int optc)
2488 case OPTION_BUILD_ID:
2489 if (emit_note_gnu_build_id != NULL)
2491 free ((char *) emit_note_gnu_build_id);
2492 emit_note_gnu_build_id = NULL;
2495 optarg = DEFAULT_BUILD_ID_STYLE;
2496 if (strcmp (optarg, "none"))
2497 emit_note_gnu_build_id = xstrdup (optarg);
2500 case OPTION_COMPRESS_DEBUG:
2501 if (strcasecmp (optarg, "none") == 0)
2502 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2503 else if (strcasecmp (optarg, "zlib") == 0)
2504 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2505 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2506 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2507 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2508 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2510 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2515 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2518 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2522 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2525 case OPTION_DISABLE_NEW_DTAGS:
2526 link_info.new_dtags = FALSE;
2529 case OPTION_ENABLE_NEW_DTAGS:
2530 link_info.new_dtags = TRUE;
2533 case OPTION_EH_FRAME_HDR:
2534 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2537 case OPTION_NO_EH_FRAME_HDR:
2538 link_info.eh_frame_hdr_type = 0;
2542 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2543 /* Groups must be self-contained. */
2544 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2545 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2548 case OPTION_EXCLUDE_LIBS:
2549 add_excluded_libs (optarg);
2552 case OPTION_HASH_STYLE:
2553 link_info.emit_hash = FALSE;
2554 link_info.emit_gnu_hash = FALSE;
2555 if (strcmp (optarg, "sysv") == 0)
2556 link_info.emit_hash = TRUE;
2557 else if (strcmp (optarg, "gnu") == 0)
2558 link_info.emit_gnu_hash = TRUE;
2559 else if (strcmp (optarg, "both") == 0)
2561 link_info.emit_hash = TRUE;
2562 link_info.emit_gnu_hash = TRUE;
2565 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2572 if (strcmp (optarg, "defs") == 0)
2573 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2574 else if (strcmp (optarg, "muldefs") == 0)
2575 link_info.allow_multiple_definition = TRUE;
2576 else if (CONST_STRNEQ (optarg, "max-page-size="))
2580 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2581 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2582 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2585 else if (CONST_STRNEQ (optarg, "common-page-size="))
2588 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2590 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2591 einfo (_("%P%F: invalid common page size \`%s'\n"),
2594 else if (CONST_STRNEQ (optarg, "stack-size="))
2597 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2598 if (*end || link_info.stacksize < 0)
2599 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2600 if (!link_info.stacksize)
2601 /* Use -1 for explicit no-stack, because zero means
2603 link_info.stacksize = -1;
2605 else if (strcmp (optarg, "execstack") == 0)
2607 link_info.execstack = TRUE;
2608 link_info.noexecstack = FALSE;
2610 else if (strcmp (optarg, "noexecstack") == 0)
2612 link_info.noexecstack = TRUE;
2613 link_info.execstack = FALSE;
2617 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2619 else if (strcmp (optarg, "global") == 0)
2620 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2621 else if (strcmp (optarg, "initfirst") == 0)
2622 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2623 else if (strcmp (optarg, "interpose") == 0)
2624 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2625 else if (strcmp (optarg, "loadfltr") == 0)
2626 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2627 else if (strcmp (optarg, "nodefaultlib") == 0)
2628 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2629 else if (strcmp (optarg, "nodelete") == 0)
2630 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2631 else if (strcmp (optarg, "nodlopen") == 0)
2632 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2633 else if (strcmp (optarg, "nodump") == 0)
2634 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2635 else if (strcmp (optarg, "now") == 0)
2637 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2638 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2640 else if (strcmp (optarg, "lazy") == 0)
2642 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2643 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2645 else if (strcmp (optarg, "origin") == 0)
2647 link_info.flags |= (bfd_vma) DF_ORIGIN;
2648 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2650 else if (strcmp (optarg, "combreloc") == 0)
2651 link_info.combreloc = TRUE;
2652 else if (strcmp (optarg, "nocombreloc") == 0)
2653 link_info.combreloc = FALSE;
2654 else if (strcmp (optarg, "nocopyreloc") == 0)
2655 link_info.nocopyreloc = TRUE;
2656 else if (strcmp (optarg, "relro") == 0)
2657 link_info.relro = TRUE;
2658 else if (strcmp (optarg, "norelro") == 0)
2659 link_info.relro = FALSE;
2660 else if (strcmp (optarg, "common") == 0)
2661 link_info.elf_stt_common = elf_stt_common;
2662 else if (strcmp (optarg, "nocommon") == 0)
2663 link_info.elf_stt_common = no_elf_stt_common;
2664 else if (strcmp (optarg, "text") == 0)
2665 link_info.error_textrel = TRUE;
2666 else if (strcmp (optarg, "notext") == 0)
2667 link_info.error_textrel = FALSE;
2668 else if (strcmp (optarg, "textoff") == 0)
2669 link_info.error_textrel = FALSE;
2673 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2675 $PARSE_AND_LIST_ARGS_CASE_Z
2681 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
2685 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2687 $PARSE_AND_LIST_ARGS_CASES
2699 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2700 gld_list_options="gld${EMULATION_NAME}_list_options"
2701 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2705 gld${EMULATION_NAME}_list_options (FILE * file)
2709 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2711 $PARSE_AND_LIST_OPTIONS
2719 gld_list_options="NULL"
2722 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2724 $PARSE_AND_LIST_EPILOGUE
2731 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2733 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2734 ${LDEMUL_SYSLIB-syslib_default},
2735 ${LDEMUL_HLL-hll_default},
2736 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2737 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2738 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2739 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2740 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2741 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2742 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2743 "${EMULATION_NAME}",
2745 ${LDEMUL_FINISH-finish_default},
2746 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2747 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2748 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2749 ${LDEMUL_SET_SYMBOLS-NULL},
2750 ${LDEMUL_PARSE_ARGS-NULL},
2751 gld${EMULATION_NAME}_add_options,
2752 gld${EMULATION_NAME}_handle_option,
2753 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2754 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2755 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2756 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2757 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2758 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}