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);
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;
499 char *filename, *sset;
501 s = strchr (path, config.rpath_separator);
503 s = path + strlen (path);
505 #if HAVE_DOS_BASED_FILE_SYSTEM
506 /* Assume a match on the second char is part of drive specifier. */
507 else if (config.rpath_separator == ':'
511 s = strchr (s + 1, config.rpath_separator);
513 s = path + strlen (path);
516 filename = (char *) xmalloc (s - path + len + 2);
521 memcpy (filename, path, s - path);
522 filename[s - path] = '/';
523 sset = filename + (s - path) + 1;
527 /* PR 20535: Support the same pseudo-environment variables that
528 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
529 Since there can be more than one occurrence of these tokens in
530 the path we loop until no more are found. */
531 while ((var = strchr (filename, '$')) != NULL)
533 /* The ld.so manual page does not say, but I am going to assume that
534 these tokens are terminated by a directory seperator character
535 (/) or the end of the string. There is also an implication that
536 $ORIGIN should only be used at the start of a path, but that is
539 FIXME: The ld.so manual page also states that it allows ${ORIGIN}
540 ${LIB} and ${PLATFORM}. We should support these variants too.
542 FIXME: The code could be a lot cleverer about allocating space
543 for the processed string. */
544 char * end = strchr (var, '/');
545 char * replacement = NULL;
546 char * freeme = NULL;
547 unsigned flen = strlen (filename);
550 /* Temporarily terminate the filename at the end of the token. */
556 if (strcmp (var + 2, "RIGIN") == 0)
558 /* ORIGIN - replace with the full path to the directory
559 containing the program or shared object. */
560 if (needed.by == NULL)
562 replacement = bfd_get_filename (needed.by);
567 if (replacement[0] == '/')
568 freeme = xstrdup (replacement);
571 char * current_dir = getpwd ();
573 freeme = xmalloc (strlen (replacement) + strlen (current_dir));
574 sprintf (freeme, "%s/%s", current_dir, replacement);
577 replacement = freeme;
578 if ((slash = strrchr (replacement, '/')) != NULL)
585 if (strcmp (var + 2, "IB") == 0)
587 /* LIB - replace with "lib" in 32-bit environments
588 and "lib64" in 64-bit environments. */
590 /* Note - we could replace this switch statement by
591 conditional fragments of shell script, but that is messy.
592 Any compiler worth its salt is going to optimize away
593 all but one of these case statements anyway. */
596 case 32: replacement = "lib"; break;
597 case 64: replacement = "lib64"; break;
599 /* $ELFSIZE is not 32 or 64 ... */
606 if (strcmp (var + 2, "LATFORM") == 0)
608 /* Supporting $PLATFORM in a cross-hosted environment is not
609 possible. Supporting it in a native environment involves
610 loading the <sys/auxv.h> header file which loads the
611 system <elf.h> header file, which conflicts with the
612 "include/elf/mips.h" header file. */
623 char * filename2 = xmalloc (flen + strlen (replacement));
626 sprintf (filename2, "%.*s%s/%s",
627 (int)(var - filename), filename,
628 replacement, end + 1);
630 sprintf (filename2, "%.*s%s",
631 (int)(var - filename), filename,
635 filename = filename2;
636 /* There is no need to restore the path separator (when
637 end != NULL) as we have replaced the entire string. */
642 /* We only issue an "unrecognised" message in verbose mode
643 as the $<foo> token might be a legitimate component of
644 a path name in the target's file system. */
645 info_msg (_("unrecognised or unsupported token '%s' in search path\n"), var);
648 /* Restore the path separator. */
655 needed.name = filename;
656 if (gld${EMULATION_NAME}_try_needed (&needed, force))
670 if [ "x${USE_LIBPATH}" = xyes ] ; then
673 /* Add the sysroot to every entry in a path separated by
674 config.rpath_separator. */
677 gld${EMULATION_NAME}_add_sysroot (const char *path)
686 if (path[i++] == config.rpath_separator)
692 len = len + (colons + 1) * strlen (ld_sysroot);
693 ret = xmalloc (len + 1);
694 strcpy (ret, ld_sysroot);
695 p = ret + strlen (ret);
698 if (path[i] == config.rpath_separator)
701 strcpy (p, ld_sysroot);
713 *-*-freebsd* | *-*-dragonfly*)
715 /* Read the system search path the FreeBSD way rather than the Linux way. */
716 #ifdef HAVE_ELF_HINTS_H
717 #include <elf-hints.h>
719 #include "elf-hints-local.h"
723 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
726 static bfd_boolean initialized;
727 static char *ld_elf_hints;
728 struct dt_needed needed;
735 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
736 f = fopen (tmppath, FOPEN_RB);
740 struct elfhints_hdr hdr;
742 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
743 && hdr.magic == ELFHINTS_MAGIC
746 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
750 b = xmalloc (hdr.dirlistlen + 1);
751 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
753 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
764 if (ld_elf_hints == NULL)
768 needed.name = l->name;
769 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
775 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
777 /* For a native linker, check the file /etc/ld.so.conf for directories
778 in which we may find shared libraries. /etc/ld.so.conf is really
779 only meaningful on Linux. */
781 struct gld${EMULATION_NAME}_ld_so_conf
788 gld${EMULATION_NAME}_parse_ld_so_conf
789 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
792 gld${EMULATION_NAME}_parse_ld_so_conf_include
793 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
801 if (pattern[0] != '/')
803 char *p = strrchr (filename, '/');
804 size_t patlen = strlen (pattern) + 1;
806 newp = xmalloc (p - filename + 1 + patlen);
807 memcpy (newp, filename, p - filename + 1);
808 memcpy (newp + (p - filename + 1), pattern, patlen);
813 if (glob (pattern, 0, NULL, &gl) == 0)
817 for (i = 0; i < gl.gl_pathc; ++i)
818 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
822 /* If we do not have glob, treat the pattern as a literal filename. */
823 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
831 gld${EMULATION_NAME}_parse_ld_so_conf
832 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
834 FILE *f = fopen (filename, FOPEN_RT);
842 line = xmalloc (linelen);
847 /* Normally this would use getline(3), but we need to be portable. */
848 while ((q = fgets (p, linelen - (p - line), f)) != NULL
849 && strlen (q) == linelen - (p - line) - 1
850 && line[linelen - 2] != '\n')
852 line = xrealloc (line, 2 * linelen);
853 p = line + linelen - 1;
857 if (q == NULL && p == line)
860 p = strchr (line, '\n');
864 /* Because the file format does not know any form of quoting we
865 can search forward for the next '#' character and if found
866 make it terminating the line. */
867 p = strchr (line, '#');
871 /* Remove leading whitespace. NUL is no whitespace character. */
873 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
876 /* If the line is blank it is ignored. */
880 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
886 while (*p == ' ' || *p == '\t')
894 while (*p != ' ' && *p != '\t' && *p)
900 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
908 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
909 && *p != '\r' && *p != '\v')
912 while (p != dir && p[-1] == '/')
914 if (info->path == NULL)
916 info->alloc = p - dir + 1 + 256;
917 info->path = xmalloc (info->alloc);
922 if (info->len + 1 + (p - dir) >= info->alloc)
924 info->alloc += p - dir + 256;
925 info->path = xrealloc (info->path, info->alloc);
927 info->path[info->len++] = config.rpath_separator;
929 memcpy (info->path + info->len, dir, p - dir);
930 info->len += p - dir;
931 info->path[info->len] = '\0';
941 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
944 static bfd_boolean initialized;
945 static char *ld_so_conf;
946 struct dt_needed needed;
951 struct gld${EMULATION_NAME}_ld_so_conf info;
954 info.len = info.alloc = 0;
955 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
956 (const char *) NULL);
957 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
960 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
961 (const char *) NULL);
962 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
968 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
975 if (ld_so_conf == NULL)
980 needed.name = l->name;
981 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
991 /* See if an input file matches a DT_NEEDED entry by name. */
994 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
998 /* Stop looking if we've found a loaded lib. */
999 if (global_found != NULL
1000 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1001 & DYN_AS_NEEDED) == 0)
1004 if (s->filename == NULL || s->the_bfd == NULL)
1007 /* Don't look for a second non-loaded as-needed lib. */
1008 if (global_found != NULL
1009 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
1012 if (filename_cmp (s->filename, global_needed->name) == 0)
1018 if (s->flags.search_dirs)
1020 const char *f = strrchr (s->filename, '/');
1022 && filename_cmp (f + 1, global_needed->name) == 0)
1029 soname = bfd_elf_get_dt_soname (s->the_bfd);
1031 && filename_cmp (soname, global_needed->name) == 0)
1040 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1043 static bfd_size_type
1044 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1046 const char *style = emit_note_gnu_build_id;
1048 bfd_size_type build_id_size;
1050 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1051 size = (size + 3) & -(bfd_size_type) 4;
1053 build_id_size = compute_build_id_size (style);
1055 size += build_id_size;
1063 write_build_id (bfd *abfd)
1065 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1066 struct elf_obj_tdata *t = elf_tdata (abfd);
1069 Elf_Internal_Shdr *i_shdr;
1070 unsigned char *contents, *id_bits;
1073 Elf_External_Note *e_note;
1075 style = t->o->build_id.style;
1076 asec = t->o->build_id.sec;
1077 if (bfd_is_abs_section (asec->output_section))
1079 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1080 " --build-id ignored.\n"));
1083 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1085 if (i_shdr->contents == NULL)
1087 if (asec->contents == NULL)
1088 asec->contents = (unsigned char *) xmalloc (asec->size);
1089 contents = asec->contents;
1092 contents = i_shdr->contents + asec->output_offset;
1094 e_note = (Elf_External_Note *) contents;
1095 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1096 size = (size + 3) & -(bfd_size_type) 4;
1097 id_bits = contents + size;
1098 size = asec->size - size;
1100 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1101 bfd_h_put_32 (abfd, size, &e_note->descsz);
1102 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1103 memcpy (e_note->name, "GNU", sizeof "GNU");
1105 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1107 position = i_shdr->sh_offset + asec->output_offset;
1109 return (bfd_seek (abfd, position, SEEK_SET) == 0
1110 && bfd_bwrite (contents, size, abfd) == size);
1113 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1116 setup_build_id (bfd *ibfd)
1122 size = id_note_section_size (ibfd);
1125 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1129 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1130 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1131 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1132 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1134 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1135 t->o->build_id.after_write_object_contents = &write_build_id;
1136 t->o->build_id.style = emit_note_gnu_build_id;
1137 t->o->build_id.sec = s;
1138 elf_section_type (s) = SHT_NOTE;
1143 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1144 " --build-id ignored.\n");
1148 /* This is called after all the input files have been opened. */
1151 gld${EMULATION_NAME}_after_open (void)
1153 struct bfd_link_needed_list *needed, *l;
1154 struct elf_link_hash_table *htab;
1156 after_open_default ();
1158 htab = elf_hash_table (&link_info);
1159 if (!is_elf_hash_table (htab))
1162 if (command_line.out_implib_filename)
1164 unlink_if_ordinary (command_line.out_implib_filename);
1165 link_info.out_implib_bfd
1166 = bfd_openw (command_line.out_implib_filename,
1167 bfd_get_target (link_info.output_bfd));
1169 if (link_info.out_implib_bfd == NULL)
1171 einfo ("%F%s: Can't open for writing: %E\n",
1172 command_line.out_implib_filename);
1176 if (emit_note_gnu_build_id != NULL)
1180 /* Find an ELF input. */
1181 for (abfd = link_info.input_bfds;
1182 abfd != (bfd *) NULL; abfd = abfd->link.next)
1183 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1184 && bfd_count_sections (abfd) != 0)
1187 /* PR 10555: If there are no ELF input files do not try to
1188 create a .note.gnu-build-id section. */
1190 || !setup_build_id (abfd))
1192 free ((char *) emit_note_gnu_build_id);
1193 emit_note_gnu_build_id = NULL;
1197 if (bfd_link_relocatable (&link_info))
1199 if (link_info.execstack == ! link_info.noexecstack)
1200 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1201 command line and we are perfoming a relocatable link then no
1202 PT_GNU_STACK segment will be created and so the
1203 linkinfo.[no]execstack values set in _handle_option() will have no
1204 effect. Instead we create a .note.GNU-stack section in much the
1205 same way as the assembler does with its --[no]execstack option. */
1206 (void) bfd_make_section_with_flags (link_info.input_bfds,
1208 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1213 if (!link_info.traditional_format)
1215 bfd *abfd, *elfbfd = NULL;
1216 bfd_boolean warn_eh_frame = FALSE;
1220 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1223 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1225 const char *name = bfd_get_section_name (abfd, s);
1227 if (bfd_is_abs_section (s->output_section))
1229 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1230 type = COMPACT_EH_HDR;
1231 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1232 type = DWARF2_EH_HDR;
1241 else if (seen_type != type)
1243 einfo (_("%P%F: compact frame descriptions incompatible with"
1244 " DWARF2 .eh_frame from %B\n"),
1245 type == DWARF2_EH_HDR ? abfd : elfbfd);
1250 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1252 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1255 warn_eh_frame = TRUE;
1259 if (seen_type == COMPACT_EH_HDR)
1260 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1262 if (bfd_count_sections (abfd) == 0)
1267 const struct elf_backend_data *bed;
1269 bed = get_elf_backend_data (elfbfd);
1270 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1271 bed->dynamic_sec_flags
1274 && bfd_set_section_alignment (elfbfd, s, 2))
1276 htab->eh_info.hdr_sec = s;
1277 warn_eh_frame = FALSE;
1281 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1282 " --eh-frame-hdr ignored.\n");
1285 /* Get the list of files which appear in DT_NEEDED entries in
1286 dynamic objects included in the link (often there will be none).
1287 For each such file, we want to track down the corresponding
1288 library, and include the symbol table in the link. This is what
1289 the runtime dynamic linker will do. Tracking the files down here
1290 permits one dynamic object to include another without requiring
1291 special action by the person doing the link. Note that the
1292 needed list can actually grow while we are stepping through this
1294 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1295 for (l = needed; l != NULL; l = l->next)
1297 struct bfd_link_needed_list *ll;
1298 struct dt_needed n, nn;
1301 /* If the lib that needs this one was --as-needed and wasn't
1302 found to be needed, then this lib isn't needed either. */
1304 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1307 /* Skip the lib if --no-copy-dt-needed-entries and
1308 --allow-shlib-undefined is in effect. */
1310 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1311 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1314 /* If we've already seen this file, skip it. */
1315 for (ll = needed; ll != l; ll = ll->next)
1317 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1318 && strcmp (ll->name, l->name) == 0)
1323 /* See if this file was included in the link explicitly. */
1325 global_found = NULL;
1326 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1327 if (global_found != NULL
1328 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1329 & DYN_AS_NEEDED) == 0)
1336 info_msg (_("%s needed by %B\n"), l->name, l->by);
1338 /* As-needed libs specified on the command line (or linker script)
1339 take priority over libs found in search dirs. */
1340 if (global_found != NULL)
1342 nn.name = global_found->filename;
1343 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1347 /* We need to find this file and include the symbol table. We
1348 want to search for the file in the same way that the dynamic
1349 linker will search. That means that we want to use
1350 rpath_link, rpath, then the environment variable
1351 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1352 entries (native only), then the linker script LIB_SEARCH_DIRS.
1353 We do not search using the -L arguments.
1355 We search twice. The first time, we skip objects which may
1356 introduce version mismatches. The second time, we force
1357 their use. See gld${EMULATION_NAME}_vercheck comment. */
1358 for (force = 0; force < 2; force++)
1361 search_dirs_type *search;
1363 if [ "x${NATIVE}" = xyes ] ; then
1365 const char *lib_path;
1368 if [ "x${USE_LIBPATH}" = xyes ] ; then
1370 struct bfd_link_needed_list *rp;
1376 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1380 if [ "x${USE_LIBPATH}" = xyes ] ; then
1382 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
1387 if [ "x${NATIVE}" = xyes ] ; then
1389 if (command_line.rpath_link == NULL
1390 && command_line.rpath == NULL)
1392 lib_path = (const char *) getenv ("LD_RUN_PATH");
1393 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
1397 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
1398 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
1402 if [ "x${USE_LIBPATH}" = xyes ] ; then
1405 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1406 for (; !found && rp != NULL; rp = rp->next)
1408 const char *tmpname = rp->name;
1410 if (IS_ABSOLUTE_PATH (tmpname))
1411 tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname);
1412 found = (rp->by == l->by
1413 && gld${EMULATION_NAME}_search_needed (tmpname,
1416 if (tmpname != rp->name)
1417 free ((char *) tmpname);
1424 if [ "x${USE_LIBPATH}" = xyes ] ; then
1426 *-*-freebsd* | *-*-dragonfly*)
1428 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1434 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1436 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1445 len = strlen (l->name);
1446 for (search = search_head; search != NULL; search = search->next)
1450 if (search->cmdline)
1452 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1453 sprintf (filename, "%s/%s", search->name, l->name);
1455 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1468 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1472 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1473 if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE)
1474 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
1482 /* Look through an expression for an assignment statement. */
1485 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1487 bfd_boolean provide = FALSE;
1489 switch (exp->type.node_class)
1492 case etree_provided:
1496 /* We call record_link_assignment even if the symbol is defined.
1497 This is because if it is defined by a dynamic object, we
1498 actually want to use the value defined by the linker script,
1499 not the value from the dynamic object (because we are setting
1500 symbols like etext). If the symbol is defined by a regular
1501 object, then, as it happens, calling record_link_assignment
1503 if (strcmp (exp->assign.dst, ".") != 0)
1505 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1507 exp->assign.dst, provide,
1508 exp->assign.hidden))
1509 einfo ("%P%F: failed to record assignment to %s: %E\n",
1512 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1516 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1517 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1521 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1522 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1523 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1527 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1536 /* This is called by the before_allocation routine via
1537 lang_for_each_statement. It locates any assignment statements, and
1538 tells the ELF backend about them, in case they are assignments to
1539 symbols which are referred to by dynamic objects. */
1542 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1544 if (s->header.type == lang_assignment_statement_enum)
1545 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1550 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1551 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1552 ELF_INTERPRETER_SET_DEFAULT="
1553 if (sinterp != NULL)
1555 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1556 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1561 ELF_INTERPRETER_SET_DEFAULT=
1565 /* used by before_allocation and handle_option. */
1567 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1570 *to = xstrdup (op_arg);
1573 size_t to_len = strlen (*to);
1574 size_t op_arg_len = strlen (op_arg);
1578 /* First see whether OPTARG is already in the path. */
1581 if (strncmp (op_arg, cp, op_arg_len) == 0
1582 && (cp[op_arg_len] == 0
1583 || cp[op_arg_len] == config.rpath_separator))
1587 /* Not yet found. */
1588 cp = strchr (cp, config.rpath_separator);
1596 buf = xmalloc (to_len + op_arg_len + 2);
1597 sprintf (buf, "%s%c%s", *to,
1598 config.rpath_separator, op_arg);
1605 #if defined(__GNUC__) && GCC_VERSION < 4006
1606 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1607 static struct bfd_link_hash_entry ehdr_start_empty;
1610 /* This is called after the sections have been attached to output
1611 sections, but before any sizes or addresses have been set. */
1614 gld${EMULATION_NAME}_before_allocation (void)
1619 struct elf_link_hash_entry *ehdr_start = NULL;
1620 #if defined(__GNUC__) && GCC_VERSION < 4006
1621 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1622 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1624 struct bfd_link_hash_entry ehdr_start_save;
1627 if (is_elf_hash_table (link_info.hash))
1629 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1631 /* Make __ehdr_start hidden if it has been referenced, to
1632 prevent the symbol from being dynamic. */
1633 if (!bfd_link_relocatable (&link_info))
1635 struct elf_link_hash_entry *h
1636 = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
1637 FALSE, FALSE, TRUE);
1639 /* Only adjust the export class if the symbol was referenced
1640 and not defined, otherwise leave it alone. */
1642 && (h->root.type == bfd_link_hash_new
1643 || h->root.type == bfd_link_hash_undefined
1644 || h->root.type == bfd_link_hash_undefweak
1645 || h->root.type == bfd_link_hash_common))
1647 _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
1648 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1649 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1650 /* Don't leave the symbol undefined. Undefined hidden
1651 symbols typically won't have dynamic relocations, but
1652 we most likely will need dynamic relocations for
1653 __ehdr_start if we are building a PIE or shared
1656 ehdr_start_save = h->root;
1657 h->root.type = bfd_link_hash_defined;
1658 h->root.u.def.section = bfd_abs_section_ptr;
1659 h->root.u.def.value = 0;
1663 /* If we are going to make any variable assignments, we need to
1664 let the ELF backend know about them in case the variables are
1665 referred to by dynamic objects. */
1666 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1669 /* Let the ELF backend work out the sizes of any sections required
1670 by dynamic linking. */
1671 rpath = command_line.rpath;
1673 rpath = (const char *) getenv ("LD_RUN_PATH");
1675 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1676 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1678 const char *audit_libs = elf_dt_audit (abfd);
1680 /* If the input bfd contains an audit entry, we need to add it as
1681 a dep audit entry. */
1682 if (audit_libs && *audit_libs != '\0')
1684 char *cp = xstrdup (audit_libs);
1688 char *cp2 = strchr (cp, config.rpath_separator);
1696 if (cp != NULL && *cp != '\0')
1697 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1699 cp = more ? ++cp2 : NULL;
1705 if (! (bfd_elf_size_dynamic_sections
1706 (link_info.output_bfd, command_line.soname, rpath,
1707 command_line.filter_shlib, audit, depaudit,
1708 (const char * const *) command_line.auxiliary_filters,
1709 &link_info, &sinterp)))
1710 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1712 ${ELF_INTERPRETER_SET_DEFAULT}
1713 /* Let the user override the dynamic linker we are using. */
1714 if (command_line.interpreter != NULL
1717 sinterp->contents = (bfd_byte *) command_line.interpreter;
1718 sinterp->size = strlen (command_line.interpreter) + 1;
1721 /* Look for any sections named .gnu.warning. As a GNU extensions,
1722 we treat such sections as containing warning messages. We print
1723 out the warning message, and then zero out the section size so
1724 that it does not get copied into the output file. */
1727 LANG_FOR_EACH_INPUT_STATEMENT (is)
1733 if (is->flags.just_syms)
1736 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1741 msg = (char *) xmalloc ((size_t) (sz + 1));
1742 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1744 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1747 (*link_info.callbacks->warning) (&link_info, msg,
1748 (const char *) NULL, is->the_bfd,
1749 (asection *) NULL, (bfd_vma) 0);
1752 /* Clobber the section size, so that we don't waste space
1753 copying the warning into the output file. If we've already
1754 sized the output section, adjust its size. The adjustment
1755 is on rawsize because targets that size sections early will
1756 have called lang_reset_memory_regions after sizing. */
1757 if (s->output_section != NULL
1758 && s->output_section->rawsize >= s->size)
1759 s->output_section->rawsize -= s->size;
1763 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1764 warning section don't get copied to the output. */
1765 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1769 before_allocation_default ();
1771 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1772 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1774 if (ehdr_start != NULL)
1776 /* If we twiddled __ehdr_start to defined earlier, put it back
1778 ehdr_start->root.type = ehdr_start_save.type;
1779 ehdr_start->root.u = ehdr_start_save.u;
1786 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1789 /* Try to open a dynamic archive. This is where we know that ELF
1790 dynamic libraries have an extension of .so (or .sl on oddball systems
1794 gld${EMULATION_NAME}_open_dynamic_archive
1795 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1797 const char *filename;
1800 bfd_boolean opened = FALSE;
1802 if (! entry->flags.maybe_archive)
1805 filename = entry->filename;
1806 len = strlen (search->name) + strlen (filename);
1807 if (entry->flags.full_name_provided)
1810 string = (char *) xmalloc (len);
1811 sprintf (string, "%s/%s", search->name, filename);
1817 len += strlen (arch) + sizeof "/lib.so";
1818 #ifdef EXTRA_SHLIB_EXTENSION
1819 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1820 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1823 string = (char *) xmalloc (len + xlen);
1824 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1825 #ifdef EXTRA_SHLIB_EXTENSION
1826 /* Try the .so extension first. If that fails build a new filename
1827 using EXTRA_SHLIB_EXTENSION. */
1828 opened = ldfile_try_open_bfd (string, entry);
1830 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1834 if (!opened && !ldfile_try_open_bfd (string, entry))
1840 entry->filename = string;
1842 /* We have found a dynamic object to include in the link. The ELF
1843 backend linker will create a DT_NEEDED entry in the .dynamic
1844 section naming this file. If this file includes a DT_SONAME
1845 entry, it will be used. Otherwise, the ELF linker will just use
1846 the name of the file. For an archive found by searching, like
1847 this one, the DT_NEEDED entry should consist of just the name of
1848 the file, without the path information used to find it. Note
1849 that we only need to do this if we have a dynamic object; an
1850 archive will never be referenced by a DT_NEEDED entry.
1852 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1853 very pretty. I haven't been able to think of anything that is
1855 if (bfd_check_format (entry->the_bfd, bfd_object)
1856 && (entry->the_bfd->flags & DYNAMIC) != 0)
1858 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1860 /* Rather than duplicating the logic above. Just use the
1861 filename we recorded earlier. */
1863 if (!entry->flags.full_name_provided)
1864 filename = lbasename (entry->filename);
1865 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1874 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1877 /* A variant of lang_output_section_find used by place_orphan. */
1879 static lang_output_section_statement_type *
1880 output_rel_find (asection *sec, int isdyn)
1882 lang_output_section_statement_type *lookup;
1883 lang_output_section_statement_type *last = NULL;
1884 lang_output_section_statement_type *last_alloc = NULL;
1885 lang_output_section_statement_type *last_ro_alloc = NULL;
1886 lang_output_section_statement_type *last_rel = NULL;
1887 lang_output_section_statement_type *last_rel_alloc = NULL;
1888 int rela = sec->name[4] == 'a';
1890 for (lookup = &lang_output_section_statement.head->output_section_statement;
1892 lookup = lookup->next)
1894 if (lookup->constraint >= 0
1895 && CONST_STRNEQ (lookup->name, ".rel"))
1897 int lookrela = lookup->name[4] == 'a';
1899 /* .rel.dyn must come before all other reloc sections, to suit
1904 /* Don't place after .rel.plt as doing so results in wrong
1906 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1909 if (rela == lookrela || last_rel == NULL)
1911 if ((rela == lookrela || last_rel_alloc == NULL)
1912 && lookup->bfd_section != NULL
1913 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1914 last_rel_alloc = lookup;
1918 if (lookup->bfd_section != NULL
1919 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1921 last_alloc = lookup;
1922 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1923 last_ro_alloc = lookup;
1928 return last_rel_alloc;
1934 return last_ro_alloc;
1942 /* Place an orphan section. We use this to put random SHF_ALLOC
1943 sections in the right segment. */
1945 static lang_output_section_statement_type *
1946 gld${EMULATION_NAME}_place_orphan (asection *s,
1947 const char *secname,
1950 static struct orphan_save hold[] =
1953 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1956 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1959 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
1962 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1968 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1971 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1974 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1980 enum orphan_save_index
1992 static int orphan_init_done = 0;
1993 struct orphan_save *place;
1994 lang_output_section_statement_type *after;
1995 lang_output_section_statement_type *os;
1996 lang_output_section_statement_type *match_by_name = NULL;
1998 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
1999 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
2003 if (!bfd_link_relocatable (&link_info)
2004 && link_info.combreloc
2005 && (s->flags & SEC_ALLOC))
2011 secname = ".rela.dyn";
2015 secname = ".rel.dyn";
2021 else if (CONST_STRNEQ (secname, ".rel"))
2023 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2028 /* Look through the script to see where to place this section. */
2029 if (constraint == 0)
2030 for (os = lang_output_section_find (secname);
2032 os = next_matching_output_section_statement (os, 0))
2034 /* If we don't match an existing output section, tell
2035 lang_insert_orphan to create a new output section. */
2036 constraint = SPECIAL;
2038 /* SEC_EXCLUDE is cleared when doing a relocatable link. But
2039 we can't merge 2 input sections with the same name when only
2040 one of them has SHF_EXCLUDE. */
2041 if (os->bfd_section != NULL
2042 && (os->bfd_section->flags == 0
2043 || ((!bfd_link_relocatable (&link_info)
2044 || (((elf_section_flags (s)
2045 ^ elf_section_flags (os->bfd_section))
2046 & SHF_EXCLUDE) == 0))
2047 && ((s->flags ^ os->bfd_section->flags)
2048 & (SEC_LOAD | SEC_ALLOC)) == 0
2049 && _bfd_elf_match_sections_by_type (link_info.output_bfd,
2053 /* We already have an output section statement with this
2054 name, and its bfd section has compatible flags.
2055 If the section already exists but does not have any flags
2056 set, then it has been created by the linker, probably as a
2057 result of a --section-start command line switch. */
2058 lang_add_section (&os->children, s, NULL, os);
2062 /* Save unused output sections in case we can match them
2063 against orphans later. */
2064 if (os->bfd_section == NULL)
2068 /* If we didn't match an active output section, see if we matched an
2069 unused one and use that. */
2072 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2073 return match_by_name;
2076 if (!orphan_init_done)
2078 struct orphan_save *ho;
2080 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2081 if (ho->name != NULL)
2083 ho->os = lang_output_section_find (ho->name);
2084 if (ho->os != NULL && ho->os->flags == 0)
2085 ho->os->flags = ho->flags;
2087 orphan_init_done = 1;
2090 /* If this is a final link, then always put .gnu.warning.SYMBOL
2091 sections into the .text section to get them out of the way. */
2092 if (bfd_link_executable (&link_info)
2093 && CONST_STRNEQ (s->name, ".gnu.warning.")
2094 && hold[orphan_text].os != NULL)
2096 os = hold[orphan_text].os;
2097 lang_add_section (&os->children, s, NULL, os);
2102 if (!bfd_link_relocatable (&link_info))
2105 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2107 if (nexts->output_section == NULL
2108 && (nexts->flags & SEC_EXCLUDE) == 0
2109 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2110 && (nexts->owner->flags & DYNAMIC) == 0
2111 && nexts->owner->usrdata != NULL
2112 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2114 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2116 flags = (((flags ^ SEC_READONLY)
2117 | (nexts->flags ^ SEC_READONLY))
2121 /* Decide which segment the section should go in based on the
2122 section name and section flags. We put loadable .note sections
2123 right after the .interp section, so that the PT_NOTE segment is
2124 stored right after the program headers where the OS can read it
2125 in the first page. */
2128 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2129 place = &hold[orphan_nonalloc];
2130 else if ((flags & SEC_ALLOC) == 0)
2132 else if ((flags & SEC_LOAD) != 0
2133 && ((iself && sh_type == SHT_NOTE)
2134 || (!iself && CONST_STRNEQ (secname, ".note"))))
2135 place = &hold[orphan_interp];
2136 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2137 place = &hold[orphan_bss];
2138 else if ((flags & SEC_SMALL_DATA) != 0)
2139 place = &hold[orphan_sdata];
2140 else if ((flags & SEC_THREAD_LOCAL) != 0)
2141 place = &hold[orphan_tdata];
2142 else if ((flags & SEC_READONLY) == 0)
2143 place = &hold[orphan_data];
2144 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
2145 || (!iself && CONST_STRNEQ (secname, ".rel")))
2146 && (flags & SEC_LOAD) != 0)
2147 place = &hold[orphan_rel];
2148 else if ((flags & SEC_CODE) == 0)
2149 place = &hold[orphan_rodata];
2151 place = &hold[orphan_text];
2156 if (place->os == NULL)
2158 if (place->name != NULL)
2159 place->os = lang_output_section_find (place->name);
2161 place->os = output_rel_find (s, isdyn);
2166 = lang_output_section_find_by_flags (s, flags, &place->os,
2167 _bfd_elf_match_sections_by_type);
2169 /* *ABS* is always the first output section statement. */
2170 after = &lang_output_section_statement.head->output_section_statement;
2173 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2178 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2182 gld${EMULATION_NAME}_after_allocation (void)
2184 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2186 if (need_layout < 0)
2187 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
2189 gld${EMULATION_NAME}_map_segments (need_layout);
2194 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2198 gld${EMULATION_NAME}_get_script (int *isfile)
2201 if test x"$COMPILE_IN" = xyes
2203 # Scripts compiled in.
2205 # sed commands to quote an ld script as a C string.
2206 sc="-f stringify.sed"
2212 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2215 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2216 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2217 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2218 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2219 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2220 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2221 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2222 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2224 if test -n "$GENERATE_PIE_SCRIPT" ; then
2225 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2226 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2227 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2228 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2229 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2230 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2231 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2232 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2233 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2235 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2236 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2238 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2239 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2240 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
2241 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2242 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2243 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2244 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2245 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2247 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2248 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2250 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2251 echo ' ; else if (link_info.combreloc && 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}.xw >> e${EMULATION_NAME}.c
2254 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2255 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2257 echo ' ; else return' >> e${EMULATION_NAME}.c
2258 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2259 echo '; }' >> e${EMULATION_NAME}.c
2262 # Scripts read from the filesystem.
2268 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2269 return "ldscripts/${EMULATION_NAME}.xu";
2270 else if (bfd_link_relocatable (&link_info))
2271 return "ldscripts/${EMULATION_NAME}.xr";
2272 else if (!config.text_read_only)
2273 return "ldscripts/${EMULATION_NAME}.xbn";
2275 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2278 else if (!config.magic_demand_paged)
2279 return "ldscripts/${EMULATION_NAME}.xn";
2282 if test -n "$GENERATE_PIE_SCRIPT" ; then
2283 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2285 else if (bfd_link_pie (&link_info)
2286 && link_info.combreloc
2288 && (link_info.flags & DF_BIND_NOW))
2289 return "ldscripts/${EMULATION_NAME}.xdw";
2290 else if (bfd_link_pie (&link_info)
2291 && link_info.combreloc)
2292 return "ldscripts/${EMULATION_NAME}.xdc";
2296 else if (bfd_link_pie (&link_info))
2297 return "ldscripts/${EMULATION_NAME}.xd";
2300 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2301 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2303 else if (bfd_link_dll (&link_info) && link_info.combreloc
2304 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2305 return "ldscripts/${EMULATION_NAME}.xsw";
2306 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2307 return "ldscripts/${EMULATION_NAME}.xsc";
2311 else if (bfd_link_dll (&link_info))
2312 return "ldscripts/${EMULATION_NAME}.xs";
2315 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2317 else if (link_info.combreloc && link_info.relro
2318 && (link_info.flags & DF_BIND_NOW))
2319 return "ldscripts/${EMULATION_NAME}.xw";
2320 else if (link_info.combreloc)
2321 return "ldscripts/${EMULATION_NAME}.xc";
2326 return "ldscripts/${EMULATION_NAME}.x";
2333 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2335 $PARSE_AND_LIST_PROLOGUE
2343 OPTION_DISABLE_NEW_DTAGS = 400,
2344 OPTION_ENABLE_NEW_DTAGS,
2346 OPTION_EH_FRAME_HDR,
2347 OPTION_NO_EH_FRAME_HDR,
2348 OPTION_EXCLUDE_LIBS,
2352 OPTION_COMPRESS_DEBUG
2356 gld${EMULATION_NAME}_add_options
2357 (int ns, char **shortopts, int nl, struct option **longopts,
2358 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2361 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2363 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2367 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2371 static const struct option xtra_long[] = {
2373 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2375 {"audit", required_argument, NULL, OPTION_AUDIT},
2376 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2380 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2381 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2383 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2385 {"depaudit", required_argument, NULL, 'P'},
2386 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2387 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2388 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2389 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2390 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2391 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2394 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2396 $PARSE_AND_LIST_LONGOPTS
2400 {NULL, no_argument, NULL, 0}
2403 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2404 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2405 *longopts = (struct option *)
2406 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2407 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2410 #define DEFAULT_BUILD_ID_STYLE "sha1"
2413 gld${EMULATION_NAME}_handle_option (int optc)
2420 case OPTION_BUILD_ID:
2421 if (emit_note_gnu_build_id != NULL)
2423 free ((char *) emit_note_gnu_build_id);
2424 emit_note_gnu_build_id = NULL;
2427 optarg = DEFAULT_BUILD_ID_STYLE;
2428 if (strcmp (optarg, "none"))
2429 emit_note_gnu_build_id = xstrdup (optarg);
2432 case OPTION_COMPRESS_DEBUG:
2433 if (strcasecmp (optarg, "none") == 0)
2434 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2435 else if (strcasecmp (optarg, "zlib") == 0)
2436 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2437 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2438 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2439 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2440 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2442 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2447 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2450 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2454 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2457 case OPTION_DISABLE_NEW_DTAGS:
2458 link_info.new_dtags = FALSE;
2461 case OPTION_ENABLE_NEW_DTAGS:
2462 link_info.new_dtags = TRUE;
2465 case OPTION_EH_FRAME_HDR:
2466 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2469 case OPTION_NO_EH_FRAME_HDR:
2470 link_info.eh_frame_hdr_type = 0;
2474 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2475 /* Groups must be self-contained. */
2476 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2477 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2480 case OPTION_EXCLUDE_LIBS:
2481 add_excluded_libs (optarg);
2484 case OPTION_HASH_STYLE:
2485 link_info.emit_hash = FALSE;
2486 link_info.emit_gnu_hash = FALSE;
2487 if (strcmp (optarg, "sysv") == 0)
2488 link_info.emit_hash = TRUE;
2489 else if (strcmp (optarg, "gnu") == 0)
2490 link_info.emit_gnu_hash = TRUE;
2491 else if (strcmp (optarg, "both") == 0)
2493 link_info.emit_hash = TRUE;
2494 link_info.emit_gnu_hash = TRUE;
2497 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2504 if (strcmp (optarg, "defs") == 0)
2505 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2506 else if (strcmp (optarg, "muldefs") == 0)
2507 link_info.allow_multiple_definition = TRUE;
2508 else if (CONST_STRNEQ (optarg, "max-page-size="))
2512 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2513 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2514 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2517 else if (CONST_STRNEQ (optarg, "common-page-size="))
2520 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2522 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2523 einfo (_("%P%F: invalid common page size \`%s'\n"),
2526 else if (CONST_STRNEQ (optarg, "stack-size="))
2529 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2530 if (*end || link_info.stacksize < 0)
2531 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2532 if (!link_info.stacksize)
2533 /* Use -1 for explicit no-stack, because zero means
2535 link_info.stacksize = -1;
2537 else if (strcmp (optarg, "execstack") == 0)
2539 link_info.execstack = TRUE;
2540 link_info.noexecstack = FALSE;
2542 else if (strcmp (optarg, "noexecstack") == 0)
2544 link_info.noexecstack = TRUE;
2545 link_info.execstack = FALSE;
2549 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2551 else if (strcmp (optarg, "global") == 0)
2552 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2553 else if (strcmp (optarg, "initfirst") == 0)
2554 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2555 else if (strcmp (optarg, "interpose") == 0)
2556 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2557 else if (strcmp (optarg, "loadfltr") == 0)
2558 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2559 else if (strcmp (optarg, "nodefaultlib") == 0)
2560 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2561 else if (strcmp (optarg, "nodelete") == 0)
2562 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2563 else if (strcmp (optarg, "nodlopen") == 0)
2564 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2565 else if (strcmp (optarg, "nodump") == 0)
2566 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2567 else if (strcmp (optarg, "now") == 0)
2569 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2570 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2572 else if (strcmp (optarg, "lazy") == 0)
2574 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2575 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2577 else if (strcmp (optarg, "origin") == 0)
2579 link_info.flags |= (bfd_vma) DF_ORIGIN;
2580 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2582 else if (strcmp (optarg, "combreloc") == 0)
2583 link_info.combreloc = TRUE;
2584 else if (strcmp (optarg, "nocombreloc") == 0)
2585 link_info.combreloc = FALSE;
2586 else if (strcmp (optarg, "nocopyreloc") == 0)
2587 link_info.nocopyreloc = TRUE;
2588 else if (strcmp (optarg, "relro") == 0)
2589 link_info.relro = TRUE;
2590 else if (strcmp (optarg, "norelro") == 0)
2591 link_info.relro = FALSE;
2592 else if (strcmp (optarg, "common") == 0)
2593 link_info.elf_stt_common = elf_stt_common;
2594 else if (strcmp (optarg, "nocommon") == 0)
2595 link_info.elf_stt_common = no_elf_stt_common;
2596 else if (strcmp (optarg, "text") == 0)
2597 link_info.error_textrel = TRUE;
2598 else if (strcmp (optarg, "notext") == 0)
2599 link_info.error_textrel = FALSE;
2600 else if (strcmp (optarg, "textoff") == 0)
2601 link_info.error_textrel = FALSE;
2605 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2607 $PARSE_AND_LIST_ARGS_CASE_Z
2613 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
2617 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2619 $PARSE_AND_LIST_ARGS_CASES
2631 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2632 gld_list_options="gld${EMULATION_NAME}_list_options"
2633 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2637 gld${EMULATION_NAME}_list_options (FILE * file)
2641 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2643 $PARSE_AND_LIST_OPTIONS
2651 gld_list_options="NULL"
2654 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2656 $PARSE_AND_LIST_EPILOGUE
2663 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2665 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2666 ${LDEMUL_SYSLIB-syslib_default},
2667 ${LDEMUL_HLL-hll_default},
2668 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2669 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2670 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2671 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2672 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2673 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2674 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2675 "${EMULATION_NAME}",
2677 ${LDEMUL_FINISH-finish_default},
2678 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2679 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2680 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2681 ${LDEMUL_SET_SYMBOLS-NULL},
2682 ${LDEMUL_PARSE_ARGS-NULL},
2683 gld${EMULATION_NAME}_add_options,
2684 gld${EMULATION_NAME}_handle_option,
2685 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2686 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2687 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2688 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2689 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2690 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}