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-2016 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);
476 if [ "x${NATIVE}" = xyes ] ; then
478 #ifdef HAVE_GETAUXVAL
479 #include <sys/auxv.h>
485 /* Search for a needed file in a path. */
488 gld${EMULATION_NAME}_search_needed (const char *path,
489 struct dt_needed *n, int force)
492 const char *name = n->name;
494 struct dt_needed needed;
497 return gld${EMULATION_NAME}_try_needed (n, force);
499 if (path == NULL || *path == '\0')
503 needed.name = n->name;
509 char *filename, *sset;
511 s = strchr (path, config.rpath_separator);
513 s = path + strlen (path);
515 #if HAVE_DOS_BASED_FILE_SYSTEM
516 /* Assume a match on the second char is part of drive specifier. */
517 else if (config.rpath_separator == ':'
521 s = strchr (s + 1, config.rpath_separator);
523 s = path + strlen (path);
526 filename = (char *) xmalloc (s - path + len + 2);
531 memcpy (filename, path, s - path);
532 filename[s - path] = '/';
533 sset = filename + (s - path) + 1;
537 /* PR 20535: Support the same pseudo-environment variables that
538 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
539 Since there can be more than one occurrence of these tokens in
540 the path we loop until no more are found. */
541 while ((var = strchr (filename, '$')) != NULL)
543 /* The ld.so manual page does not say, but I am going to assume that
544 these tokens are terminated by a directory seperator character
545 (/) or the end of the string. There is also an implication that
546 $ORIGIN should only be used at the start of a path, but that is
549 FIXME: The ld.so manual page also states that it allows ${ORIGIN}
550 ${LIB} and ${PLATFORM}. We should support these variants too.
552 FIXME: The code could be a lot cleverer about allocating space
553 for the processed string. */
554 char * end = strchr (var, '/');
555 char * replacement = NULL;
556 char * freeme = NULL;
557 unsigned flen = strlen (filename);
560 /* Temporarily terminate the filename at the end of the token. */
566 if (strcmp (var + 2, "RIGIN") == 0)
568 /* ORIGIN - replace with the full path to the directory
569 containing the program or shared object. */
570 if (needed.by == NULL)
572 replacement = bfd_get_filename (needed.by);
577 if (replacement[0] == '/')
578 freeme = xstrdup (replacement);
581 char * current_dir = getpwd ();
583 freeme = xmalloc (strlen (replacement) + strlen (current_dir));
584 sprintf (freeme, "%s/%s", current_dir, replacement);
587 replacement = freeme;
588 if ((slash = strrchr (replacement, '/')) != NULL)
595 if (strcmp (var + 2, "IB") == 0)
597 /* LIB - replace with "lib" in 32-bit environments
598 and "lib64" in 64-bit environments. */
600 /* Note - we could replace this switch statement by
601 conditional fragments of shell script, but that is messy.
602 Any compiler worth its salt is going to optimize away
603 all but one of these case statements anyway. */
606 case 32: replacement = "lib"; break;
607 case 64: replacement = "lib64"; break;
609 /* $ELFSIZE is not 32 or 64 ... */
616 if (strcmp (var + 2, "LATFORM") == 0)
618 /* PLATFORM - replace with a string corresponding
619 to the processor type of the host system.
621 FIXME: Supporting this token might be a bad idea,
622 especially for non-native linkers. It has the potential
623 to find incorrect results. Maybe issuing a warning
624 message would be safer. Current policy: wait and see if
625 somebody complains. */
626 replacement = "$OUTPUT_ARCH";
628 # We use getauxval() if it is available, but only for natives.
629 if [ "x${NATIVE}" = xyes ] ; then
631 #ifdef HAVE_GETAUXVAL
632 replacement = (char *) getauxval (AT_PLATFORM);
646 char * filename2 = xmalloc (flen + strlen (replacement));
649 sprintf (filename2, "%.*s%s/%s",
650 (int)(var - filename), filename,
651 replacement, end + 1);
653 sprintf (filename2, "%.*s%s",
654 (int)(var - filename), filename,
658 filename = filename2;
659 /* There is no need to restore the path separator (when
660 end != NULL) as we have replaced the entire string. */
665 /* We only issue an "unrecognised" message in verbose mode
666 as the $<foo> token might be a legitimate component of
667 a path name in the target's file system. */
668 info_msg (_("unrecognised token '%s' in search path\n"), var);
671 /* Restore the path separator. */
678 needed.name = filename;
679 if (gld${EMULATION_NAME}_try_needed (&needed, force))
693 if [ "x${USE_LIBPATH}" = xyes ] ; then
696 /* Add the sysroot to every entry in a path separated by
697 config.rpath_separator. */
700 gld${EMULATION_NAME}_add_sysroot (const char *path)
709 if (path[i++] == config.rpath_separator)
715 len = len + (colons + 1) * strlen (ld_sysroot);
716 ret = xmalloc (len + 1);
717 strcpy (ret, ld_sysroot);
718 p = ret + strlen (ret);
721 if (path[i] == config.rpath_separator)
724 strcpy (p, ld_sysroot);
736 *-*-freebsd* | *-*-dragonfly*)
738 /* Read the system search path the FreeBSD way rather than the Linux way. */
739 #ifdef HAVE_ELF_HINTS_H
740 #include <elf-hints.h>
742 #include "elf-hints-local.h"
746 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
749 static bfd_boolean initialized;
750 static char *ld_elf_hints;
751 struct dt_needed needed;
758 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
759 f = fopen (tmppath, FOPEN_RB);
763 struct elfhints_hdr hdr;
765 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
766 && hdr.magic == ELFHINTS_MAGIC
769 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
773 b = xmalloc (hdr.dirlistlen + 1);
774 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
776 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
787 if (ld_elf_hints == NULL)
791 needed.name = l->name;
792 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
798 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
800 /* For a native linker, check the file /etc/ld.so.conf for directories
801 in which we may find shared libraries. /etc/ld.so.conf is really
802 only meaningful on Linux. */
804 struct gld${EMULATION_NAME}_ld_so_conf
811 gld${EMULATION_NAME}_parse_ld_so_conf
812 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
815 gld${EMULATION_NAME}_parse_ld_so_conf_include
816 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
824 if (pattern[0] != '/')
826 char *p = strrchr (filename, '/');
827 size_t patlen = strlen (pattern) + 1;
829 newp = xmalloc (p - filename + 1 + patlen);
830 memcpy (newp, filename, p - filename + 1);
831 memcpy (newp + (p - filename + 1), pattern, patlen);
836 if (glob (pattern, 0, NULL, &gl) == 0)
840 for (i = 0; i < gl.gl_pathc; ++i)
841 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
845 /* If we do not have glob, treat the pattern as a literal filename. */
846 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
854 gld${EMULATION_NAME}_parse_ld_so_conf
855 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
857 FILE *f = fopen (filename, FOPEN_RT);
865 line = xmalloc (linelen);
870 /* Normally this would use getline(3), but we need to be portable. */
871 while ((q = fgets (p, linelen - (p - line), f)) != NULL
872 && strlen (q) == linelen - (p - line) - 1
873 && line[linelen - 2] != '\n')
875 line = xrealloc (line, 2 * linelen);
876 p = line + linelen - 1;
880 if (q == NULL && p == line)
883 p = strchr (line, '\n');
887 /* Because the file format does not know any form of quoting we
888 can search forward for the next '#' character and if found
889 make it terminating the line. */
890 p = strchr (line, '#');
894 /* Remove leading whitespace. NUL is no whitespace character. */
896 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
899 /* If the line is blank it is ignored. */
903 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
909 while (*p == ' ' || *p == '\t')
917 while (*p != ' ' && *p != '\t' && *p)
923 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
931 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
932 && *p != '\r' && *p != '\v')
935 while (p != dir && p[-1] == '/')
937 if (info->path == NULL)
939 info->alloc = p - dir + 1 + 256;
940 info->path = xmalloc (info->alloc);
945 if (info->len + 1 + (p - dir) >= info->alloc)
947 info->alloc += p - dir + 256;
948 info->path = xrealloc (info->path, info->alloc);
950 info->path[info->len++] = config.rpath_separator;
952 memcpy (info->path + info->len, dir, p - dir);
953 info->len += p - dir;
954 info->path[info->len] = '\0';
964 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
967 static bfd_boolean initialized;
968 static char *ld_so_conf;
969 struct dt_needed needed;
974 struct gld${EMULATION_NAME}_ld_so_conf info;
977 info.len = info.alloc = 0;
978 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
979 (const char *) NULL);
980 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
983 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
984 (const char *) NULL);
985 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
991 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
998 if (ld_so_conf == NULL)
1003 needed.name = l->name;
1004 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
1014 /* See if an input file matches a DT_NEEDED entry by name. */
1017 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
1021 /* Stop looking if we've found a loaded lib. */
1022 if (global_found != NULL
1023 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1024 & DYN_AS_NEEDED) == 0)
1027 if (s->filename == NULL || s->the_bfd == NULL)
1030 /* Don't look for a second non-loaded as-needed lib. */
1031 if (global_found != NULL
1032 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
1035 if (filename_cmp (s->filename, global_needed->name) == 0)
1041 if (s->flags.search_dirs)
1043 const char *f = strrchr (s->filename, '/');
1045 && filename_cmp (f + 1, global_needed->name) == 0)
1052 soname = bfd_elf_get_dt_soname (s->the_bfd);
1054 && filename_cmp (soname, global_needed->name) == 0)
1063 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1066 static bfd_size_type
1067 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1069 const char *style = emit_note_gnu_build_id;
1071 bfd_size_type build_id_size;
1073 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1074 size = (size + 3) & -(bfd_size_type) 4;
1076 build_id_size = compute_build_id_size (style);
1078 size += build_id_size;
1086 write_build_id (bfd *abfd)
1088 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1089 struct elf_obj_tdata *t = elf_tdata (abfd);
1092 Elf_Internal_Shdr *i_shdr;
1093 unsigned char *contents, *id_bits;
1096 Elf_External_Note *e_note;
1098 style = t->o->build_id.style;
1099 asec = t->o->build_id.sec;
1100 if (bfd_is_abs_section (asec->output_section))
1102 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1103 " --build-id ignored.\n"));
1106 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1108 if (i_shdr->contents == NULL)
1110 if (asec->contents == NULL)
1111 asec->contents = (unsigned char *) xmalloc (asec->size);
1112 contents = asec->contents;
1115 contents = i_shdr->contents + asec->output_offset;
1117 e_note = (Elf_External_Note *) contents;
1118 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1119 size = (size + 3) & -(bfd_size_type) 4;
1120 id_bits = contents + size;
1121 size = asec->size - size;
1123 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1124 bfd_h_put_32 (abfd, size, &e_note->descsz);
1125 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1126 memcpy (e_note->name, "GNU", sizeof "GNU");
1128 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1130 position = i_shdr->sh_offset + asec->output_offset;
1132 return (bfd_seek (abfd, position, SEEK_SET) == 0
1133 && bfd_bwrite (contents, size, abfd) == size);
1136 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1139 setup_build_id (bfd *ibfd)
1145 size = id_note_section_size (ibfd);
1148 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1152 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1153 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1154 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1155 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1157 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1158 t->o->build_id.after_write_object_contents = &write_build_id;
1159 t->o->build_id.style = emit_note_gnu_build_id;
1160 t->o->build_id.sec = s;
1161 elf_section_type (s) = SHT_NOTE;
1166 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1167 " --build-id ignored.\n");
1171 /* This is called after all the input files have been opened. */
1174 gld${EMULATION_NAME}_after_open (void)
1176 struct bfd_link_needed_list *needed, *l;
1177 struct elf_link_hash_table *htab;
1179 after_open_default ();
1181 htab = elf_hash_table (&link_info);
1182 if (!is_elf_hash_table (htab))
1185 if (command_line.out_implib_filename)
1187 unlink_if_ordinary (command_line.out_implib_filename);
1188 link_info.out_implib_bfd
1189 = bfd_openw (command_line.out_implib_filename,
1190 bfd_get_target (link_info.output_bfd));
1192 if (link_info.out_implib_bfd == NULL)
1194 einfo ("%F%s: Can't open for writing: %E\n",
1195 command_line.out_implib_filename);
1199 if (emit_note_gnu_build_id != NULL)
1203 /* Find an ELF input. */
1204 for (abfd = link_info.input_bfds;
1205 abfd != (bfd *) NULL; abfd = abfd->link.next)
1206 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1207 && bfd_count_sections (abfd) != 0)
1210 /* PR 10555: If there are no ELF input files do not try to
1211 create a .note.gnu-build-id section. */
1213 || !setup_build_id (abfd))
1215 free ((char *) emit_note_gnu_build_id);
1216 emit_note_gnu_build_id = NULL;
1220 if (bfd_link_relocatable (&link_info))
1222 if (link_info.execstack == ! link_info.noexecstack)
1223 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1224 command line and we are perfoming a relocatable link then no
1225 PT_GNU_STACK segment will be created and so the
1226 linkinfo.[no]execstack values set in _handle_option() will have no
1227 effect. Instead we create a .note.GNU-stack section in much the
1228 same way as the assembler does with its --[no]execstack option. */
1229 (void) bfd_make_section_with_flags (link_info.input_bfds,
1231 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1236 if (!link_info.traditional_format)
1238 bfd *abfd, *elfbfd = NULL;
1239 bfd_boolean warn_eh_frame = FALSE;
1243 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1246 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1248 const char *name = bfd_get_section_name (abfd, s);
1250 if (bfd_is_abs_section (s->output_section))
1252 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1253 type = COMPACT_EH_HDR;
1254 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1255 type = DWARF2_EH_HDR;
1264 else if (seen_type != type)
1266 einfo (_("%P%F: compact frame descriptions incompatible with"
1267 " DWARF2 .eh_frame from %B\n"),
1268 type == DWARF2_EH_HDR ? abfd : elfbfd);
1273 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1275 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1278 warn_eh_frame = TRUE;
1282 if (seen_type == COMPACT_EH_HDR)
1283 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1285 if (bfd_count_sections (abfd) == 0)
1290 const struct elf_backend_data *bed;
1292 bed = get_elf_backend_data (elfbfd);
1293 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1294 bed->dynamic_sec_flags
1297 && bfd_set_section_alignment (elfbfd, s, 2))
1299 htab->eh_info.hdr_sec = s;
1300 warn_eh_frame = FALSE;
1304 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1305 " --eh-frame-hdr ignored.\n");
1308 /* Get the list of files which appear in DT_NEEDED entries in
1309 dynamic objects included in the link (often there will be none).
1310 For each such file, we want to track down the corresponding
1311 library, and include the symbol table in the link. This is what
1312 the runtime dynamic linker will do. Tracking the files down here
1313 permits one dynamic object to include another without requiring
1314 special action by the person doing the link. Note that the
1315 needed list can actually grow while we are stepping through this
1317 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1318 for (l = needed; l != NULL; l = l->next)
1320 struct bfd_link_needed_list *ll;
1321 struct dt_needed n, nn;
1324 /* If the lib that needs this one was --as-needed and wasn't
1325 found to be needed, then this lib isn't needed either. */
1327 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1330 /* Skip the lib if --no-copy-dt-needed-entries and
1331 --allow-shlib-undefined is in effect. */
1333 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1334 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1337 /* If we've already seen this file, skip it. */
1338 for (ll = needed; ll != l; ll = ll->next)
1340 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1341 && strcmp (ll->name, l->name) == 0)
1346 /* See if this file was included in the link explicitly. */
1348 global_found = NULL;
1349 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1350 if (global_found != NULL
1351 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1352 & DYN_AS_NEEDED) == 0)
1359 info_msg (_("%s needed by %B\n"), l->name, l->by);
1361 /* As-needed libs specified on the command line (or linker script)
1362 take priority over libs found in search dirs. */
1363 if (global_found != NULL)
1365 nn.name = global_found->filename;
1366 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1370 /* We need to find this file and include the symbol table. We
1371 want to search for the file in the same way that the dynamic
1372 linker will search. That means that we want to use
1373 rpath_link, rpath, then the environment variable
1374 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1375 entries (native only), then the linker script LIB_SEARCH_DIRS.
1376 We do not search using the -L arguments.
1378 We search twice. The first time, we skip objects which may
1379 introduce version mismatches. The second time, we force
1380 their use. See gld${EMULATION_NAME}_vercheck comment. */
1381 for (force = 0; force < 2; force++)
1384 search_dirs_type *search;
1386 if [ "x${NATIVE}" = xyes ] ; then
1388 const char *lib_path;
1391 if [ "x${USE_LIBPATH}" = xyes ] ; then
1393 struct bfd_link_needed_list *rp;
1399 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1403 if [ "x${USE_LIBPATH}" = xyes ] ; then
1405 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
1410 if [ "x${NATIVE}" = xyes ] ; then
1412 if (command_line.rpath_link == NULL
1413 && command_line.rpath == NULL)
1415 lib_path = (const char *) getenv ("LD_RUN_PATH");
1416 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
1420 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
1421 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
1425 if [ "x${USE_LIBPATH}" = xyes ] ; then
1428 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1429 for (; !found && rp != NULL; rp = rp->next)
1431 const char *tmpname = rp->name;
1433 if (IS_ABSOLUTE_PATH (tmpname))
1434 tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname);
1435 found = (rp->by == l->by
1436 && gld${EMULATION_NAME}_search_needed (tmpname,
1439 if (tmpname != rp->name)
1440 free ((char *) tmpname);
1447 if [ "x${USE_LIBPATH}" = xyes ] ; then
1449 *-*-freebsd* | *-*-dragonfly*)
1451 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1457 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1459 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1468 len = strlen (l->name);
1469 for (search = search_head; search != NULL; search = search->next)
1473 if (search->cmdline)
1475 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1476 sprintf (filename, "%s/%s", search->name, l->name);
1478 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1491 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1495 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1496 if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE)
1497 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
1505 /* Look through an expression for an assignment statement. */
1508 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1510 bfd_boolean provide = FALSE;
1512 switch (exp->type.node_class)
1515 case etree_provided:
1519 /* We call record_link_assignment even if the symbol is defined.
1520 This is because if it is defined by a dynamic object, we
1521 actually want to use the value defined by the linker script,
1522 not the value from the dynamic object (because we are setting
1523 symbols like etext). If the symbol is defined by a regular
1524 object, then, as it happens, calling record_link_assignment
1526 if (strcmp (exp->assign.dst, ".") != 0)
1528 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1530 exp->assign.dst, provide,
1531 exp->assign.hidden))
1532 einfo ("%P%F: failed to record assignment to %s: %E\n",
1535 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1539 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1540 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1544 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1545 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1546 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1550 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1559 /* This is called by the before_allocation routine via
1560 lang_for_each_statement. It locates any assignment statements, and
1561 tells the ELF backend about them, in case they are assignments to
1562 symbols which are referred to by dynamic objects. */
1565 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1567 if (s->header.type == lang_assignment_statement_enum)
1568 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1573 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1574 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1575 ELF_INTERPRETER_SET_DEFAULT="
1576 if (sinterp != NULL)
1578 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1579 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1584 ELF_INTERPRETER_SET_DEFAULT=
1588 /* used by before_allocation and handle_option. */
1590 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1593 *to = xstrdup (op_arg);
1596 size_t to_len = strlen (*to);
1597 size_t op_arg_len = strlen (op_arg);
1601 /* First see whether OPTARG is already in the path. */
1604 if (strncmp (op_arg, cp, op_arg_len) == 0
1605 && (cp[op_arg_len] == 0
1606 || cp[op_arg_len] == config.rpath_separator))
1610 /* Not yet found. */
1611 cp = strchr (cp, config.rpath_separator);
1619 buf = xmalloc (to_len + op_arg_len + 2);
1620 sprintf (buf, "%s%c%s", *to,
1621 config.rpath_separator, op_arg);
1628 #if defined(__GNUC__) && GCC_VERSION < 4006
1629 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1630 static struct bfd_link_hash_entry ehdr_start_empty;
1633 /* This is called after the sections have been attached to output
1634 sections, but before any sizes or addresses have been set. */
1637 gld${EMULATION_NAME}_before_allocation (void)
1642 struct elf_link_hash_entry *ehdr_start = NULL;
1643 #if defined(__GNUC__) && GCC_VERSION < 4006
1644 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1645 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1647 struct bfd_link_hash_entry ehdr_start_save;
1650 if (is_elf_hash_table (link_info.hash))
1652 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1654 /* Make __ehdr_start hidden if it has been referenced, to
1655 prevent the symbol from being dynamic. */
1656 if (!bfd_link_relocatable (&link_info))
1658 struct elf_link_hash_entry *h
1659 = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
1660 FALSE, FALSE, TRUE);
1662 /* Only adjust the export class if the symbol was referenced
1663 and not defined, otherwise leave it alone. */
1665 && (h->root.type == bfd_link_hash_new
1666 || h->root.type == bfd_link_hash_undefined
1667 || h->root.type == bfd_link_hash_undefweak
1668 || h->root.type == bfd_link_hash_common))
1670 _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
1671 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1672 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1673 /* Don't leave the symbol undefined. Undefined hidden
1674 symbols typically won't have dynamic relocations, but
1675 we most likely will need dynamic relocations for
1676 __ehdr_start if we are building a PIE or shared
1679 ehdr_start_save = h->root;
1680 h->root.type = bfd_link_hash_defined;
1681 h->root.u.def.section = bfd_abs_section_ptr;
1682 h->root.u.def.value = 0;
1686 /* If we are going to make any variable assignments, we need to
1687 let the ELF backend know about them in case the variables are
1688 referred to by dynamic objects. */
1689 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1692 /* Let the ELF backend work out the sizes of any sections required
1693 by dynamic linking. */
1694 rpath = command_line.rpath;
1696 rpath = (const char *) getenv ("LD_RUN_PATH");
1698 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1699 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1701 const char *audit_libs = elf_dt_audit (abfd);
1703 /* If the input bfd contains an audit entry, we need to add it as
1704 a dep audit entry. */
1705 if (audit_libs && *audit_libs != '\0')
1707 char *cp = xstrdup (audit_libs);
1711 char *cp2 = strchr (cp, config.rpath_separator);
1719 if (cp != NULL && *cp != '\0')
1720 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1722 cp = more ? ++cp2 : NULL;
1728 if (! (bfd_elf_size_dynamic_sections
1729 (link_info.output_bfd, command_line.soname, rpath,
1730 command_line.filter_shlib, audit, depaudit,
1731 (const char * const *) command_line.auxiliary_filters,
1732 &link_info, &sinterp)))
1733 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1735 ${ELF_INTERPRETER_SET_DEFAULT}
1736 /* Let the user override the dynamic linker we are using. */
1737 if (command_line.interpreter != NULL
1740 sinterp->contents = (bfd_byte *) command_line.interpreter;
1741 sinterp->size = strlen (command_line.interpreter) + 1;
1744 /* Look for any sections named .gnu.warning. As a GNU extensions,
1745 we treat such sections as containing warning messages. We print
1746 out the warning message, and then zero out the section size so
1747 that it does not get copied into the output file. */
1750 LANG_FOR_EACH_INPUT_STATEMENT (is)
1756 if (is->flags.just_syms)
1759 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1764 msg = (char *) xmalloc ((size_t) (sz + 1));
1765 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1767 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1770 (*link_info.callbacks->warning) (&link_info, msg,
1771 (const char *) NULL, is->the_bfd,
1772 (asection *) NULL, (bfd_vma) 0);
1775 /* Clobber the section size, so that we don't waste space
1776 copying the warning into the output file. If we've already
1777 sized the output section, adjust its size. The adjustment
1778 is on rawsize because targets that size sections early will
1779 have called lang_reset_memory_regions after sizing. */
1780 if (s->output_section != NULL
1781 && s->output_section->rawsize >= s->size)
1782 s->output_section->rawsize -= s->size;
1786 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1787 warning section don't get copied to the output. */
1788 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1792 before_allocation_default ();
1794 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1795 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1797 if (ehdr_start != NULL)
1799 /* If we twiddled __ehdr_start to defined earlier, put it back
1801 ehdr_start->root.type = ehdr_start_save.type;
1802 ehdr_start->root.u = ehdr_start_save.u;
1809 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1812 /* Try to open a dynamic archive. This is where we know that ELF
1813 dynamic libraries have an extension of .so (or .sl on oddball systems
1817 gld${EMULATION_NAME}_open_dynamic_archive
1818 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1820 const char *filename;
1823 bfd_boolean opened = FALSE;
1825 if (! entry->flags.maybe_archive)
1828 filename = entry->filename;
1829 len = strlen (search->name) + strlen (filename);
1830 if (entry->flags.full_name_provided)
1833 string = (char *) xmalloc (len);
1834 sprintf (string, "%s/%s", search->name, filename);
1840 len += strlen (arch) + sizeof "/lib.so";
1841 #ifdef EXTRA_SHLIB_EXTENSION
1842 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1843 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1846 string = (char *) xmalloc (len + xlen);
1847 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1848 #ifdef EXTRA_SHLIB_EXTENSION
1849 /* Try the .so extension first. If that fails build a new filename
1850 using EXTRA_SHLIB_EXTENSION. */
1851 opened = ldfile_try_open_bfd (string, entry);
1853 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1857 if (!opened && !ldfile_try_open_bfd (string, entry))
1863 entry->filename = string;
1865 /* We have found a dynamic object to include in the link. The ELF
1866 backend linker will create a DT_NEEDED entry in the .dynamic
1867 section naming this file. If this file includes a DT_SONAME
1868 entry, it will be used. Otherwise, the ELF linker will just use
1869 the name of the file. For an archive found by searching, like
1870 this one, the DT_NEEDED entry should consist of just the name of
1871 the file, without the path information used to find it. Note
1872 that we only need to do this if we have a dynamic object; an
1873 archive will never be referenced by a DT_NEEDED entry.
1875 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1876 very pretty. I haven't been able to think of anything that is
1878 if (bfd_check_format (entry->the_bfd, bfd_object)
1879 && (entry->the_bfd->flags & DYNAMIC) != 0)
1881 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1883 /* Rather than duplicating the logic above. Just use the
1884 filename we recorded earlier. */
1886 if (!entry->flags.full_name_provided)
1887 filename = lbasename (entry->filename);
1888 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1897 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1900 /* A variant of lang_output_section_find used by place_orphan. */
1902 static lang_output_section_statement_type *
1903 output_rel_find (asection *sec, int isdyn)
1905 lang_output_section_statement_type *lookup;
1906 lang_output_section_statement_type *last = NULL;
1907 lang_output_section_statement_type *last_alloc = NULL;
1908 lang_output_section_statement_type *last_ro_alloc = NULL;
1909 lang_output_section_statement_type *last_rel = NULL;
1910 lang_output_section_statement_type *last_rel_alloc = NULL;
1911 int rela = sec->name[4] == 'a';
1913 for (lookup = &lang_output_section_statement.head->output_section_statement;
1915 lookup = lookup->next)
1917 if (lookup->constraint >= 0
1918 && CONST_STRNEQ (lookup->name, ".rel"))
1920 int lookrela = lookup->name[4] == 'a';
1922 /* .rel.dyn must come before all other reloc sections, to suit
1927 /* Don't place after .rel.plt as doing so results in wrong
1929 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1932 if (rela == lookrela || last_rel == NULL)
1934 if ((rela == lookrela || last_rel_alloc == NULL)
1935 && lookup->bfd_section != NULL
1936 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1937 last_rel_alloc = lookup;
1941 if (lookup->bfd_section != NULL
1942 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1944 last_alloc = lookup;
1945 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1946 last_ro_alloc = lookup;
1951 return last_rel_alloc;
1957 return last_ro_alloc;
1965 /* Place an orphan section. We use this to put random SHF_ALLOC
1966 sections in the right segment. */
1968 static lang_output_section_statement_type *
1969 gld${EMULATION_NAME}_place_orphan (asection *s,
1970 const char *secname,
1973 static struct orphan_save hold[] =
1976 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1979 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1982 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
1985 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1991 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1994 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1997 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
2003 enum orphan_save_index
2015 static int orphan_init_done = 0;
2016 struct orphan_save *place;
2017 lang_output_section_statement_type *after;
2018 lang_output_section_statement_type *os;
2019 lang_output_section_statement_type *match_by_name = NULL;
2021 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
2022 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
2026 if (!bfd_link_relocatable (&link_info)
2027 && link_info.combreloc
2028 && (s->flags & SEC_ALLOC))
2034 secname = ".rela.dyn";
2038 secname = ".rel.dyn";
2044 else if (CONST_STRNEQ (secname, ".rel"))
2046 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2051 /* Look through the script to see where to place this section. */
2052 if (constraint == 0)
2053 for (os = lang_output_section_find (secname);
2055 os = next_matching_output_section_statement (os, 0))
2057 /* If we don't match an existing output section, tell
2058 lang_insert_orphan to create a new output section. */
2059 constraint = SPECIAL;
2061 /* SEC_EXCLUDE is cleared when doing a relocatable link. But
2062 we can't merge 2 input sections with the same name when only
2063 one of them has SHF_EXCLUDE. */
2064 if (os->bfd_section != NULL
2065 && (os->bfd_section->flags == 0
2066 || ((!bfd_link_relocatable (&link_info)
2067 || (((elf_section_flags (s)
2068 ^ elf_section_flags (os->bfd_section))
2069 & SHF_EXCLUDE) == 0))
2070 && ((s->flags ^ os->bfd_section->flags)
2071 & (SEC_LOAD | SEC_ALLOC)) == 0
2072 && _bfd_elf_match_sections_by_type (link_info.output_bfd,
2076 /* We already have an output section statement with this
2077 name, and its bfd section has compatible flags.
2078 If the section already exists but does not have any flags
2079 set, then it has been created by the linker, probably as a
2080 result of a --section-start command line switch. */
2081 lang_add_section (&os->children, s, NULL, os);
2085 /* Save unused output sections in case we can match them
2086 against orphans later. */
2087 if (os->bfd_section == NULL)
2091 /* If we didn't match an active output section, see if we matched an
2092 unused one and use that. */
2095 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2096 return match_by_name;
2099 if (!orphan_init_done)
2101 struct orphan_save *ho;
2103 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2104 if (ho->name != NULL)
2106 ho->os = lang_output_section_find (ho->name);
2107 if (ho->os != NULL && ho->os->flags == 0)
2108 ho->os->flags = ho->flags;
2110 orphan_init_done = 1;
2113 /* If this is a final link, then always put .gnu.warning.SYMBOL
2114 sections into the .text section to get them out of the way. */
2115 if (bfd_link_executable (&link_info)
2116 && CONST_STRNEQ (s->name, ".gnu.warning.")
2117 && hold[orphan_text].os != NULL)
2119 os = hold[orphan_text].os;
2120 lang_add_section (&os->children, s, NULL, os);
2125 if (!bfd_link_relocatable (&link_info))
2128 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2130 if (nexts->output_section == NULL
2131 && (nexts->flags & SEC_EXCLUDE) == 0
2132 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2133 && (nexts->owner->flags & DYNAMIC) == 0
2134 && nexts->owner->usrdata != NULL
2135 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2137 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2139 flags = (((flags ^ SEC_READONLY)
2140 | (nexts->flags ^ SEC_READONLY))
2144 /* Decide which segment the section should go in based on the
2145 section name and section flags. We put loadable .note sections
2146 right after the .interp section, so that the PT_NOTE segment is
2147 stored right after the program headers where the OS can read it
2148 in the first page. */
2151 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2152 place = &hold[orphan_nonalloc];
2153 else if ((flags & SEC_ALLOC) == 0)
2155 else if ((flags & SEC_LOAD) != 0
2156 && ((iself && sh_type == SHT_NOTE)
2157 || (!iself && CONST_STRNEQ (secname, ".note"))))
2158 place = &hold[orphan_interp];
2159 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2160 place = &hold[orphan_bss];
2161 else if ((flags & SEC_SMALL_DATA) != 0)
2162 place = &hold[orphan_sdata];
2163 else if ((flags & SEC_THREAD_LOCAL) != 0)
2164 place = &hold[orphan_tdata];
2165 else if ((flags & SEC_READONLY) == 0)
2166 place = &hold[orphan_data];
2167 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
2168 || (!iself && CONST_STRNEQ (secname, ".rel")))
2169 && (flags & SEC_LOAD) != 0)
2170 place = &hold[orphan_rel];
2171 else if ((flags & SEC_CODE) == 0)
2172 place = &hold[orphan_rodata];
2174 place = &hold[orphan_text];
2179 if (place->os == NULL)
2181 if (place->name != NULL)
2182 place->os = lang_output_section_find (place->name);
2184 place->os = output_rel_find (s, isdyn);
2189 = lang_output_section_find_by_flags (s, flags, &place->os,
2190 _bfd_elf_match_sections_by_type);
2192 /* *ABS* is always the first output section statement. */
2193 after = &lang_output_section_statement.head->output_section_statement;
2196 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2201 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2205 gld${EMULATION_NAME}_after_allocation (void)
2207 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2209 if (need_layout < 0)
2210 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
2212 gld${EMULATION_NAME}_map_segments (need_layout);
2217 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2221 gld${EMULATION_NAME}_get_script (int *isfile)
2224 if test x"$COMPILE_IN" = xyes
2226 # Scripts compiled in.
2228 # sed commands to quote an ld script as a C string.
2229 sc="-f stringify.sed"
2235 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2238 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2239 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2240 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2241 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2242 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2243 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2244 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2245 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2247 if test -n "$GENERATE_PIE_SCRIPT" ; then
2248 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2249 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2250 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2251 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2252 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2253 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2254 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2255 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2256 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2258 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2259 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2261 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2262 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2263 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
2264 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2265 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2266 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2267 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2268 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2270 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2271 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2273 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2274 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
2275 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2276 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2277 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2278 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2280 echo ' ; else return' >> e${EMULATION_NAME}.c
2281 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2282 echo '; }' >> e${EMULATION_NAME}.c
2285 # Scripts read from the filesystem.
2291 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2292 return "ldscripts/${EMULATION_NAME}.xu";
2293 else if (bfd_link_relocatable (&link_info))
2294 return "ldscripts/${EMULATION_NAME}.xr";
2295 else if (!config.text_read_only)
2296 return "ldscripts/${EMULATION_NAME}.xbn";
2298 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2301 else if (!config.magic_demand_paged)
2302 return "ldscripts/${EMULATION_NAME}.xn";
2305 if test -n "$GENERATE_PIE_SCRIPT" ; then
2306 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2308 else if (bfd_link_pie (&link_info)
2309 && link_info.combreloc
2311 && (link_info.flags & DF_BIND_NOW))
2312 return "ldscripts/${EMULATION_NAME}.xdw";
2313 else if (bfd_link_pie (&link_info)
2314 && link_info.combreloc)
2315 return "ldscripts/${EMULATION_NAME}.xdc";
2319 else if (bfd_link_pie (&link_info))
2320 return "ldscripts/${EMULATION_NAME}.xd";
2323 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2324 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2326 else if (bfd_link_dll (&link_info) && link_info.combreloc
2327 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2328 return "ldscripts/${EMULATION_NAME}.xsw";
2329 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2330 return "ldscripts/${EMULATION_NAME}.xsc";
2334 else if (bfd_link_dll (&link_info))
2335 return "ldscripts/${EMULATION_NAME}.xs";
2338 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2340 else if (link_info.combreloc && link_info.relro
2341 && (link_info.flags & DF_BIND_NOW))
2342 return "ldscripts/${EMULATION_NAME}.xw";
2343 else if (link_info.combreloc)
2344 return "ldscripts/${EMULATION_NAME}.xc";
2349 return "ldscripts/${EMULATION_NAME}.x";
2356 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2358 $PARSE_AND_LIST_PROLOGUE
2366 OPTION_DISABLE_NEW_DTAGS = 400,
2367 OPTION_ENABLE_NEW_DTAGS,
2369 OPTION_EH_FRAME_HDR,
2370 OPTION_NO_EH_FRAME_HDR,
2371 OPTION_EXCLUDE_LIBS,
2375 OPTION_COMPRESS_DEBUG
2379 gld${EMULATION_NAME}_add_options
2380 (int ns, char **shortopts, int nl, struct option **longopts,
2381 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2384 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2386 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2390 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2394 static const struct option xtra_long[] = {
2396 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2398 {"audit", required_argument, NULL, OPTION_AUDIT},
2399 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2403 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2404 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2406 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2408 {"depaudit", required_argument, NULL, 'P'},
2409 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2410 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2411 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2412 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2413 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2414 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2417 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2419 $PARSE_AND_LIST_LONGOPTS
2423 {NULL, no_argument, NULL, 0}
2426 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2427 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2428 *longopts = (struct option *)
2429 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2430 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2433 #define DEFAULT_BUILD_ID_STYLE "sha1"
2436 gld${EMULATION_NAME}_handle_option (int optc)
2443 case OPTION_BUILD_ID:
2444 if (emit_note_gnu_build_id != NULL)
2446 free ((char *) emit_note_gnu_build_id);
2447 emit_note_gnu_build_id = NULL;
2450 optarg = DEFAULT_BUILD_ID_STYLE;
2451 if (strcmp (optarg, "none"))
2452 emit_note_gnu_build_id = xstrdup (optarg);
2455 case OPTION_COMPRESS_DEBUG:
2456 if (strcasecmp (optarg, "none") == 0)
2457 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2458 else if (strcasecmp (optarg, "zlib") == 0)
2459 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2460 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2461 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2462 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2463 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2465 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2470 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2473 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2477 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2480 case OPTION_DISABLE_NEW_DTAGS:
2481 link_info.new_dtags = FALSE;
2484 case OPTION_ENABLE_NEW_DTAGS:
2485 link_info.new_dtags = TRUE;
2488 case OPTION_EH_FRAME_HDR:
2489 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2492 case OPTION_NO_EH_FRAME_HDR:
2493 link_info.eh_frame_hdr_type = 0;
2497 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2498 /* Groups must be self-contained. */
2499 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2500 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2503 case OPTION_EXCLUDE_LIBS:
2504 add_excluded_libs (optarg);
2507 case OPTION_HASH_STYLE:
2508 link_info.emit_hash = FALSE;
2509 link_info.emit_gnu_hash = FALSE;
2510 if (strcmp (optarg, "sysv") == 0)
2511 link_info.emit_hash = TRUE;
2512 else if (strcmp (optarg, "gnu") == 0)
2513 link_info.emit_gnu_hash = TRUE;
2514 else if (strcmp (optarg, "both") == 0)
2516 link_info.emit_hash = TRUE;
2517 link_info.emit_gnu_hash = TRUE;
2520 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2527 if (strcmp (optarg, "defs") == 0)
2528 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2529 else if (strcmp (optarg, "muldefs") == 0)
2530 link_info.allow_multiple_definition = TRUE;
2531 else if (CONST_STRNEQ (optarg, "max-page-size="))
2535 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2536 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2537 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2540 else if (CONST_STRNEQ (optarg, "common-page-size="))
2543 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2545 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2546 einfo (_("%P%F: invalid common page size \`%s'\n"),
2549 else if (CONST_STRNEQ (optarg, "stack-size="))
2552 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2553 if (*end || link_info.stacksize < 0)
2554 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2555 if (!link_info.stacksize)
2556 /* Use -1 for explicit no-stack, because zero means
2558 link_info.stacksize = -1;
2560 else if (strcmp (optarg, "execstack") == 0)
2562 link_info.execstack = TRUE;
2563 link_info.noexecstack = FALSE;
2565 else if (strcmp (optarg, "noexecstack") == 0)
2567 link_info.noexecstack = TRUE;
2568 link_info.execstack = FALSE;
2572 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2574 else if (strcmp (optarg, "global") == 0)
2575 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2576 else if (strcmp (optarg, "initfirst") == 0)
2577 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2578 else if (strcmp (optarg, "interpose") == 0)
2579 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2580 else if (strcmp (optarg, "loadfltr") == 0)
2581 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2582 else if (strcmp (optarg, "nodefaultlib") == 0)
2583 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2584 else if (strcmp (optarg, "nodelete") == 0)
2585 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2586 else if (strcmp (optarg, "nodlopen") == 0)
2587 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2588 else if (strcmp (optarg, "nodump") == 0)
2589 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2590 else if (strcmp (optarg, "now") == 0)
2592 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2593 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2595 else if (strcmp (optarg, "lazy") == 0)
2597 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2598 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2600 else if (strcmp (optarg, "origin") == 0)
2602 link_info.flags |= (bfd_vma) DF_ORIGIN;
2603 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2605 else if (strcmp (optarg, "combreloc") == 0)
2606 link_info.combreloc = TRUE;
2607 else if (strcmp (optarg, "nocombreloc") == 0)
2608 link_info.combreloc = FALSE;
2609 else if (strcmp (optarg, "nocopyreloc") == 0)
2610 link_info.nocopyreloc = TRUE;
2611 else if (strcmp (optarg, "relro") == 0)
2612 link_info.relro = TRUE;
2613 else if (strcmp (optarg, "norelro") == 0)
2614 link_info.relro = FALSE;
2615 else if (strcmp (optarg, "common") == 0)
2616 link_info.elf_stt_common = elf_stt_common;
2617 else if (strcmp (optarg, "nocommon") == 0)
2618 link_info.elf_stt_common = no_elf_stt_common;
2619 else if (strcmp (optarg, "text") == 0)
2620 link_info.error_textrel = TRUE;
2621 else if (strcmp (optarg, "notext") == 0)
2622 link_info.error_textrel = FALSE;
2623 else if (strcmp (optarg, "textoff") == 0)
2624 link_info.error_textrel = FALSE;
2628 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2630 $PARSE_AND_LIST_ARGS_CASE_Z
2636 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
2640 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2642 $PARSE_AND_LIST_ARGS_CASES
2654 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2655 gld_list_options="gld${EMULATION_NAME}_list_options"
2656 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2660 gld${EMULATION_NAME}_list_options (FILE * file)
2664 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2666 $PARSE_AND_LIST_OPTIONS
2674 gld_list_options="NULL"
2677 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2679 $PARSE_AND_LIST_EPILOGUE
2686 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2688 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2689 ${LDEMUL_SYSLIB-syslib_default},
2690 ${LDEMUL_HLL-hll_default},
2691 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2692 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2693 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2694 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2695 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2696 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2697 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2698 "${EMULATION_NAME}",
2700 ${LDEMUL_FINISH-finish_default},
2701 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2702 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2703 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2704 ${LDEMUL_SET_SYMBOLS-NULL},
2705 ${LDEMUL_PARSE_ARGS-NULL},
2706 gld${EMULATION_NAME}_add_options,
2707 gld${EMULATION_NAME}_handle_option,
2708 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2709 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2710 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2711 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2712 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2713 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}