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-2018 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 = TRUE;
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 if (bfd_link_executable (&link_info)
124 && link_info.nointerp)
126 if (link_info.dynamic_undefined_weak > 0)
127 einfo (_("%P: warning: -z dynamic-undefined-weak ignored\n"));
128 link_info.dynamic_undefined_weak = 0;
130 after_parse_default ();
136 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
138 /* Handle the generation of DT_NEEDED tags. */
141 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
145 /* Tell the ELF linker that we don't want the output file to have a
146 DT_NEEDED entry for this file, unless it is used to resolve
147 references in a regular object. */
148 if (entry->flags.add_DT_NEEDED_for_regular)
149 link_class = DYN_AS_NEEDED;
151 /* Tell the ELF linker that we don't want the output file to have a
152 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
154 if (!entry->flags.add_DT_NEEDED_for_dynamic)
155 link_class |= DYN_NO_ADD_NEEDED;
157 if (entry->flags.just_syms
158 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
159 einfo (_("%F%P: %pB: --just-symbols may not be used on DSO\n"),
163 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
166 bfd_elf_set_dyn_lib_class (entry->the_bfd,
167 (enum dynamic_lib_link_class) link_class);
169 /* Continue on with normal load_symbols processing. */
177 /* These variables are required to pass information back and forth
178 between after_open and check_needed and stat_needed and vercheck. */
180 static struct bfd_link_needed_list *global_needed;
181 static struct stat global_stat;
182 static lang_input_statement_type *global_found;
183 static struct bfd_link_needed_list *global_vercheck_needed;
184 static bfd_boolean global_vercheck_failed;
186 /* These variables are used to implement target options */
188 static char *audit; /* colon (typically) separated list of libs */
189 static char *depaudit; /* colon (typically) separated list of libs */
191 /* Style of .note.gnu.build-id section. */
192 static const char *emit_note_gnu_build_id;
194 /* On Linux, it's possible to have different versions of the same
195 shared library linked against different versions of libc. The
196 dynamic linker somehow tags which libc version to use in
197 /etc/ld.so.cache, and, based on the libc that it sees in the
198 executable, chooses which version of the shared library to use.
200 We try to do a similar check here by checking whether this shared
201 library needs any other shared libraries which may conflict with
202 libraries we have already included in the link. If it does, we
203 skip it, and try to find another shared library farther on down the
206 This is called via lang_for_each_input_file.
207 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
208 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
209 a conflicting version. */
212 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
215 struct bfd_link_needed_list *l;
217 if (global_vercheck_failed)
219 if (s->the_bfd == NULL
220 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
223 soname = bfd_elf_get_dt_soname (s->the_bfd);
225 soname = lbasename (bfd_get_filename (s->the_bfd));
227 for (l = global_vercheck_needed; l != NULL; l = l->next)
231 if (filename_cmp (soname, l->name) == 0)
233 /* Probably can't happen, but it's an easy check. */
237 if (strchr (l->name, '/') != NULL)
240 suffix = strstr (l->name, ".so.");
244 suffix += sizeof ".so." - 1;
246 if (filename_ncmp (soname, l->name, suffix - l->name) == 0)
248 /* Here we know that S is a dynamic object FOO.SO.VER1, and
249 the object we are considering needs a dynamic object
250 FOO.SO.VER2, and VER1 and VER2 are different. This
251 appears to be a version mismatch, so we tell the caller
252 to try a different version of this library. */
253 global_vercheck_failed = TRUE;
260 /* See if an input file matches a DT_NEEDED entry by running stat on
264 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
270 if (global_found != NULL)
272 if (s->the_bfd == NULL)
275 /* If this input file was an as-needed entry, and wasn't found to be
276 needed at the stage it was linked, then don't say we have loaded it. */
277 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
280 if (bfd_stat (s->the_bfd, &st) != 0)
282 einfo (_("%P: %pB: bfd_stat failed: %E\n"), s->the_bfd);
286 /* Some operating systems, e.g. Windows, do not provide a meaningful
287 st_ino; they always set it to zero. (Windows does provide a
288 meaningful st_dev.) Do not indicate a duplicate library in that
289 case. While there is no guarantee that a system that provides
290 meaningful inode numbers will never set st_ino to zero, this is
291 merely an optimization, so we do not need to worry about false
293 if (st.st_dev == global_stat.st_dev
294 && st.st_ino == global_stat.st_ino
301 /* We issue a warning if it looks like we are including two
302 different versions of the same shared library. For example,
303 there may be a problem if -lc picks up libc.so.6 but some other
304 shared library has a DT_NEEDED entry of libc.so.5. This is a
305 heuristic test, and it will only work if the name looks like
306 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
307 If we really want to issue warnings about mixing version numbers
308 of shared libraries, we need to find a better way. */
310 if (strchr (global_needed->name, '/') != NULL)
312 suffix = strstr (global_needed->name, ".so.");
315 suffix += sizeof ".so." - 1;
317 soname = bfd_elf_get_dt_soname (s->the_bfd);
319 soname = lbasename (s->filename);
321 if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
322 einfo (_("%P: warning: %s, needed by %pB, may conflict with %s\n"),
323 global_needed->name, global_needed->by, soname);
332 /* This function is called for each possible name for a dynamic object
333 named by a DT_NEEDED entry. The FORCE parameter indicates whether
334 to skip the check for a conflicting version. */
337 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
341 const char *name = needed->name;
345 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
349 info_msg (_("attempt to open %s failed\n"), name);
353 /* Linker needs to decompress sections. */
354 abfd->flags |= BFD_DECOMPRESS;
356 if (! bfd_check_format (abfd, bfd_object))
361 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
367 /* For DT_NEEDED, they have to match. */
368 if (abfd->xvec != link_info.output_bfd->xvec)
374 /* Check whether this object would include any conflicting library
375 versions. If FORCE is set, then we skip this check; we use this
376 the second time around, if we couldn't find any compatible
377 instance of the shared library. */
381 struct bfd_link_needed_list *needs;
383 if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
384 einfo (_("%F%P: %pB: bfd_elf_get_bfd_needed_list failed: %E\n"), abfd);
388 global_vercheck_needed = needs;
389 global_vercheck_failed = FALSE;
390 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
391 if (global_vercheck_failed)
394 /* Return FALSE to force the caller to move on to try
395 another file on the search path. */
399 /* But wait! It gets much worse. On Linux, if a shared
400 library does not use libc at all, we are supposed to skip
401 it the first time around in case we encounter a shared
402 library later on with the same name which does use the
403 version of libc that we want. This is much too horrible
404 to use on any system other than Linux. */
408 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
411 struct bfd_link_needed_list *l;
413 for (l = needs; l != NULL; l = l->next)
414 if (CONST_STRNEQ (l->name, "libc.so"))
430 /* We've found a dynamic object matching the DT_NEEDED entry. */
432 /* We have already checked that there is no other input file of the
433 same name. We must now check again that we are not including the
434 same file twice. We need to do this because on many systems
435 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
436 reference libc.so.1. If we have already included libc.so, we
437 don't want to include libc.so.1 if they are the same file, and we
438 can only check that using stat. */
440 if (bfd_stat (abfd, &global_stat) != 0)
441 einfo (_("%F%P: %pB: bfd_stat failed: %E\n"), abfd);
443 /* First strip off everything before the last '/'. */
444 soname = lbasename (abfd->filename);
447 info_msg (_("found %s at %s\n"), soname, name);
450 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
451 if (global_found != NULL)
453 /* Return TRUE to indicate that we found the file, even though
454 we aren't going to do anything with it. */
458 /* Specify the soname to use. */
459 bfd_elf_set_dt_needed_name (abfd, soname);
461 /* Tell the ELF linker that we don't want the output file to have a
462 DT_NEEDED entry for this file, unless it is used to resolve
463 references in a regular object. */
464 link_class = DYN_DT_NEEDED;
466 /* Tell the ELF linker that we don't want the output file to have a
467 DT_NEEDED entry for this file at all if the entry is from a file
468 with DYN_NO_ADD_NEEDED. */
469 if (needed->by != NULL
470 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
471 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
473 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
475 /* Add this file into the symbol table. */
476 if (! bfd_link_add_symbols (abfd, &link_info))
477 einfo (_("%F%P: %pB: error adding symbols: %E\n"), abfd);
482 /* Search for a needed file in a path. */
485 gld${EMULATION_NAME}_search_needed (const char *path,
486 struct dt_needed *n, int force)
489 const char *name = n->name;
491 struct dt_needed needed;
494 return gld${EMULATION_NAME}_try_needed (n, force);
496 if (path == NULL || *path == '\0')
500 needed.name = n->name;
507 char *filename, *sset;
509 s = strchr (path, config.rpath_separator);
511 s = path + strlen (path);
513 #if HAVE_DOS_BASED_FILE_SYSTEM
514 /* Assume a match on the second char is part of drive specifier. */
515 else if (config.rpath_separator == ':'
519 s = strchr (s + 1, config.rpath_separator);
521 s = path + strlen (path);
524 filename = (char *) xmalloc (s - path + len + 2);
529 memcpy (filename, path, s - path);
530 filename[s - path] = '/';
531 sset = filename + (s - path) + 1;
535 /* PR 20535: Support the same pseudo-environment variables that
536 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
537 Since there can be more than one occurrence of these tokens in
538 the path we loop until no more are found. Since we might not
539 be able to substitute some of the tokens we maintain an offset
540 into the filename for where we should begin our scan. */
541 while ((var = strchr (filename + offset, '$')) != 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 separator 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 The ld.so manual page also states that it allows ${ORIGIN},
550 ${LIB} and ${PLATFORM}, so these are supported as well.
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;
557 char * freeme = NULL;
558 unsigned flen = strlen (filename);
561 /* Temporarily terminate the filename at the end of the token. */
569 if (strcmp (v, "RIGIN") == 0 || strcmp (v, "RIGIN}") == 0)
571 /* ORIGIN - replace with the full path to the directory
572 containing the program or shared object. */
573 if (needed.by == NULL)
575 if (link_info.output_bfd == NULL)
580 replacement = bfd_get_filename (link_info.output_bfd);
583 replacement = bfd_get_filename (needed.by);
589 if (replacement[0] == '/')
590 freeme = xstrdup (replacement);
593 char * current_dir = getpwd ();
595 freeme = xmalloc (strlen (replacement) + strlen (current_dir) + 2);
596 sprintf (freeme, "%s/%s", current_dir, replacement);
599 replacement = freeme;
600 if ((slash = strrchr (replacement, '/')) != NULL)
607 if (strcmp (v, "IB") == 0 || strcmp (v, "IB}") == 0)
609 /* LIB - replace with "lib" in 32-bit environments
610 and "lib64" in 64-bit environments. */
612 /* Note - we could replace this switch statement by
613 conditional fragments of shell script, but that is messy.
614 Any compiler worth its salt is going to optimize away
615 all but one of these case statements anyway. */
618 case 32: replacement = "lib"; break;
619 case 64: replacement = "lib64"; break;
621 /* $ELFSIZE is not 32 or 64 ... */
628 /* Supporting $PLATFORM in a cross-hosted environment is not
629 possible. Supporting it in a native environment involves
630 loading the <sys/auxv.h> header file which loads the
631 system <elf.h> header file, which conflicts with the
632 "include/elf/mips.h" header file. */
640 char * filename2 = xmalloc (flen + strlen (replacement));
644 sprintf (filename2, "%.*s%s/%s",
645 (int)(var - filename), filename,
646 replacement, end + 1);
647 offset = (var - filename) + 1 + strlen (replacement);
651 sprintf (filename2, "%.*s%s",
652 (int)(var - filename), filename,
654 offset = var - filename + strlen (replacement);
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 or unsupported token '%s' in search path\n"), var);
671 /* Restore the path separator. */
674 /* PR 20784: Make sure that we resume the scan *after*
675 the token that we could not replace. */
676 offset = (var + 1) - filename;
682 needed.name = filename;
684 if (gld${EMULATION_NAME}_try_needed (&needed, force))
698 if [ "x${USE_LIBPATH}" = xyes ] ; then
701 /* Prefix the sysroot to absolute paths in PATH, a string containing
702 paths separated by config.rpath_separator. If running on a DOS
703 file system, paths containing a drive spec won't have the sysroot
704 prefix added, unless the sysroot also specifies the same drive. */
707 gld${EMULATION_NAME}_add_sysroot (const char *path)
712 int dos_drive_sysroot = HAS_DRIVE_SPEC (ld_sysroot);
714 len = strlen (ld_sysroot);
715 for (extra = 0, p = path; ; )
717 int dos_drive = HAS_DRIVE_SPEC (p);
721 if (IS_DIR_SEPARATOR (*p)
723 || (dos_drive_sysroot
724 && ld_sysroot[0] == p[-2])))
726 if (dos_drive && dos_drive_sysroot)
731 p = strchr (p, config.rpath_separator);
737 ret = xmalloc (strlen (path) + extra + 1);
739 for (q = ret, p = path; ; )
742 int dos_drive = HAS_DRIVE_SPEC (p);
749 if (IS_DIR_SEPARATOR (*p)
751 || (dos_drive_sysroot
752 && ld_sysroot[0] == p[-2])))
754 if (dos_drive && dos_drive_sysroot)
756 strcpy (q, ld_sysroot + 2);
761 strcpy (q, ld_sysroot);
765 end = strchr (p, config.rpath_separator);
768 size_t n = end - p + 1;
785 *-*-freebsd* | *-*-dragonfly*)
787 /* Read the system search path the FreeBSD way rather than the Linux way. */
788 #ifdef HAVE_ELF_HINTS_H
789 #include <elf-hints.h>
791 #include "elf-hints-local.h"
795 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
798 static bfd_boolean initialized;
799 static const char *ld_elf_hints;
800 struct dt_needed needed;
807 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
808 f = fopen (tmppath, FOPEN_RB);
812 struct elfhints_hdr hdr;
814 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
815 && hdr.magic == ELFHINTS_MAGIC
818 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
822 b = xmalloc (hdr.dirlistlen + 1);
823 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
825 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
836 if (ld_elf_hints == NULL)
840 needed.name = l->name;
841 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
847 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
849 /* For a native linker, check the file /etc/ld.so.conf for directories
850 in which we may find shared libraries. /etc/ld.so.conf is really
851 only meaningful on Linux. */
853 struct gld${EMULATION_NAME}_ld_so_conf
860 gld${EMULATION_NAME}_parse_ld_so_conf
861 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
864 gld${EMULATION_NAME}_parse_ld_so_conf_include
865 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
873 if (pattern[0] != '/')
875 char *p = strrchr (filename, '/');
876 size_t patlen = strlen (pattern) + 1;
878 newp = xmalloc (p - filename + 1 + patlen);
879 memcpy (newp, filename, p - filename + 1);
880 memcpy (newp + (p - filename + 1), pattern, patlen);
885 if (glob (pattern, 0, NULL, &gl) == 0)
889 for (i = 0; i < gl.gl_pathc; ++i)
890 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
894 /* If we do not have glob, treat the pattern as a literal filename. */
895 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
903 gld${EMULATION_NAME}_parse_ld_so_conf
904 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
906 FILE *f = fopen (filename, FOPEN_RT);
914 line = xmalloc (linelen);
919 /* Normally this would use getline(3), but we need to be portable. */
920 while ((q = fgets (p, linelen - (p - line), f)) != NULL
921 && strlen (q) == linelen - (p - line) - 1
922 && line[linelen - 2] != '\n')
924 line = xrealloc (line, 2 * linelen);
925 p = line + linelen - 1;
929 if (q == NULL && p == line)
932 p = strchr (line, '\n');
936 /* Because the file format does not know any form of quoting we
937 can search forward for the next '#' character and if found
938 make it terminating the line. */
939 p = strchr (line, '#');
943 /* Remove leading whitespace. NUL is no whitespace character. */
945 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
948 /* If the line is blank it is ignored. */
952 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
958 while (*p == ' ' || *p == '\t')
966 while (*p != ' ' && *p != '\t' && *p)
972 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
980 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
981 && *p != '\r' && *p != '\v')
984 while (p != dir && p[-1] == '/')
986 if (info->path == NULL)
988 info->alloc = p - dir + 1 + 256;
989 info->path = xmalloc (info->alloc);
994 if (info->len + 1 + (p - dir) >= info->alloc)
996 info->alloc += p - dir + 256;
997 info->path = xrealloc (info->path, info->alloc);
999 info->path[info->len++] = config.rpath_separator;
1001 memcpy (info->path + info->len, dir, p - dir);
1002 info->len += p - dir;
1003 info->path[info->len] = '\0';
1013 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
1016 static bfd_boolean initialized;
1017 static const char *ld_so_conf;
1018 struct dt_needed needed;
1023 struct gld${EMULATION_NAME}_ld_so_conf info;
1026 info.len = info.alloc = 0;
1027 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
1028 (const char *) NULL);
1029 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
1032 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
1033 (const char *) NULL);
1034 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
1040 ld_so_conf = gld${EMULATION_NAME}_add_sysroot (info.path);
1046 if (ld_so_conf == NULL)
1051 needed.name = l->name;
1052 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
1062 /* See if an input file matches a DT_NEEDED entry by name. */
1065 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
1069 /* Stop looking if we've found a loaded lib. */
1070 if (global_found != NULL
1071 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1072 & DYN_AS_NEEDED) == 0)
1075 if (s->filename == NULL || s->the_bfd == NULL)
1078 /* Don't look for a second non-loaded as-needed lib. */
1079 if (global_found != NULL
1080 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
1083 if (filename_cmp (s->filename, global_needed->name) == 0)
1089 if (s->flags.search_dirs)
1091 const char *f = strrchr (s->filename, '/');
1093 && filename_cmp (f + 1, global_needed->name) == 0)
1100 soname = bfd_elf_get_dt_soname (s->the_bfd);
1102 && filename_cmp (soname, global_needed->name) == 0)
1111 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1114 static bfd_size_type
1115 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1117 const char *style = emit_note_gnu_build_id;
1119 bfd_size_type build_id_size;
1121 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1122 size = (size + 3) & -(bfd_size_type) 4;
1124 build_id_size = compute_build_id_size (style);
1126 size += build_id_size;
1134 write_build_id (bfd *abfd)
1136 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1137 struct elf_obj_tdata *t = elf_tdata (abfd);
1140 Elf_Internal_Shdr *i_shdr;
1141 unsigned char *contents, *id_bits;
1144 Elf_External_Note *e_note;
1146 style = t->o->build_id.style;
1147 asec = t->o->build_id.sec;
1148 if (bfd_is_abs_section (asec->output_section))
1150 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1151 " --build-id ignored\n"));
1154 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1156 if (i_shdr->contents == NULL)
1158 if (asec->contents == NULL)
1159 asec->contents = (unsigned char *) xmalloc (asec->size);
1160 contents = asec->contents;
1163 contents = i_shdr->contents + asec->output_offset;
1165 e_note = (Elf_External_Note *) contents;
1166 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1167 size = (size + 3) & -(bfd_size_type) 4;
1168 id_bits = contents + size;
1169 size = asec->size - size;
1171 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1172 bfd_h_put_32 (abfd, size, &e_note->descsz);
1173 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1174 memcpy (e_note->name, "GNU", sizeof "GNU");
1176 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1178 position = i_shdr->sh_offset + asec->output_offset;
1180 return (bfd_seek (abfd, position, SEEK_SET) == 0
1181 && bfd_bwrite (contents, size, abfd) == size);
1184 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1187 setup_build_id (bfd *ibfd)
1193 size = id_note_section_size (ibfd);
1196 einfo (_("%P: warning: unrecognized --build-id style ignored\n"));
1200 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1201 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1202 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1203 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1205 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1206 t->o->build_id.after_write_object_contents = &write_build_id;
1207 t->o->build_id.style = emit_note_gnu_build_id;
1208 t->o->build_id.sec = s;
1209 elf_section_type (s) = SHT_NOTE;
1214 einfo (_("%P: warning: cannot create .note.gnu.build-id section,"
1215 " --build-id ignored\n"));
1219 /* This is called after all the input files have been opened. */
1222 gld${EMULATION_NAME}_after_open (void)
1224 struct bfd_link_needed_list *needed, *l;
1225 struct elf_link_hash_table *htab;
1229 after_open_default ();
1231 htab = elf_hash_table (&link_info);
1232 if (!is_elf_hash_table (htab))
1235 if (command_line.out_implib_filename)
1237 unlink_if_ordinary (command_line.out_implib_filename);
1238 link_info.out_implib_bfd
1239 = bfd_openw (command_line.out_implib_filename,
1240 bfd_get_target (link_info.output_bfd));
1242 if (link_info.out_implib_bfd == NULL)
1244 einfo (_("%F%P: %s: can't open for writing: %E\n"),
1245 command_line.out_implib_filename);
1249 if (emit_note_gnu_build_id != NULL)
1251 /* Find an ELF input. */
1252 for (abfd = link_info.input_bfds;
1253 abfd != (bfd *) NULL; abfd = abfd->link.next)
1254 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1255 && bfd_count_sections (abfd) != 0
1256 && !((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
1259 /* PR 10555: If there are no ELF input files do not try to
1260 create a .note.gnu-build-id section. */
1262 || !setup_build_id (abfd))
1264 free ((char *) emit_note_gnu_build_id);
1265 emit_note_gnu_build_id = NULL;
1269 get_elf_backend_data (link_info.output_bfd)->setup_gnu_properties (&link_info);
1271 if (bfd_link_relocatable (&link_info))
1273 if (link_info.execstack == ! link_info.noexecstack)
1274 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1275 command line and we are perfoming a relocatable link then no
1276 PT_GNU_STACK segment will be created and so the
1277 linkinfo.[no]execstack values set in _handle_option() will have no
1278 effect. Instead we create a .note.GNU-stack section in much the
1279 same way as the assembler does with its --[no]execstack option. */
1280 (void) bfd_make_section_with_flags (link_info.input_bfds,
1282 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1287 if (!link_info.traditional_format)
1290 bfd_boolean warn_eh_frame = FALSE;
1293 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1297 if (((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
1300 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1302 const char *name = bfd_get_section_name (abfd, s);
1304 if (bfd_is_abs_section (s->output_section))
1306 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1307 type = COMPACT_EH_HDR;
1308 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1309 type = DWARF2_EH_HDR;
1318 else if (seen_type != type)
1320 einfo (_("%F%P: compact frame descriptions incompatible with"
1321 " DWARF2 .eh_frame from %pB\n"),
1322 type == DWARF2_EH_HDR ? abfd : elfbfd);
1327 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1329 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1332 warn_eh_frame = TRUE;
1336 if (seen_type == COMPACT_EH_HDR)
1337 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1341 const struct elf_backend_data *bed;
1343 bed = get_elf_backend_data (elfbfd);
1344 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1345 bed->dynamic_sec_flags
1348 && bfd_set_section_alignment (elfbfd, s, 2))
1350 htab->eh_info.hdr_sec = s;
1351 warn_eh_frame = FALSE;
1355 einfo (_("%P: warning: cannot create .eh_frame_hdr section,"
1356 " --eh-frame-hdr ignored\n"));
1359 /* Get the list of files which appear in DT_NEEDED entries in
1360 dynamic objects included in the link (often there will be none).
1361 For each such file, we want to track down the corresponding
1362 library, and include the symbol table in the link. This is what
1363 the runtime dynamic linker will do. Tracking the files down here
1364 permits one dynamic object to include another without requiring
1365 special action by the person doing the link. Note that the
1366 needed list can actually grow while we are stepping through this
1368 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1369 for (l = needed; l != NULL; l = l->next)
1371 struct bfd_link_needed_list *ll;
1372 struct dt_needed n, nn;
1375 /* If the lib that needs this one was --as-needed and wasn't
1376 found to be needed, then this lib isn't needed either. */
1378 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1381 /* Skip the lib if --no-copy-dt-needed-entries and
1382 --allow-shlib-undefined is in effect. */
1384 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1385 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1388 /* If we've already seen this file, skip it. */
1389 for (ll = needed; ll != l; ll = ll->next)
1391 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1392 && strcmp (ll->name, l->name) == 0)
1397 /* See if this file was included in the link explicitly. */
1399 global_found = NULL;
1400 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1401 if (global_found != NULL
1402 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1403 & DYN_AS_NEEDED) == 0)
1410 info_msg (_("%s needed by %pB\n"), l->name, l->by);
1412 /* As-needed libs specified on the command line (or linker script)
1413 take priority over libs found in search dirs. */
1414 if (global_found != NULL)
1416 nn.name = global_found->filename;
1417 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1421 /* We need to find this file and include the symbol table. We
1422 want to search for the file in the same way that the dynamic
1423 linker will search. That means that we want to use
1424 rpath_link, rpath, then the environment variable
1425 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1426 entries (native only), then the linker script LIB_SEARCH_DIRS.
1427 We do not search using the -L arguments.
1429 We search twice. The first time, we skip objects which may
1430 introduce version mismatches. The second time, we force
1431 their use. See gld${EMULATION_NAME}_vercheck comment. */
1432 for (force = 0; force < 2; force++)
1435 search_dirs_type *search;
1437 if [ "x${NATIVE}" = xyes ] || [ "x${USE_LIBPATH}" = xyes ] ; then
1442 if [ "x${USE_LIBPATH}" = xyes ] ; then
1444 struct bfd_link_needed_list *rp;
1450 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1454 if [ "x${USE_LIBPATH}" = xyes ] ; then
1456 path = command_line.rpath;
1459 path = gld${EMULATION_NAME}_add_sysroot (path);
1460 found = gld${EMULATION_NAME}_search_needed (path, &n, force);
1461 free ((char *) path);
1467 if [ "x${NATIVE}" = xyes ] ; then
1469 if (command_line.rpath_link == NULL
1470 && command_line.rpath == NULL)
1472 path = (const char *) getenv ("LD_RUN_PATH");
1474 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1477 path = (const char *) getenv ("LD_LIBRARY_PATH");
1479 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1483 if [ "x${USE_LIBPATH}" = xyes ] ; then
1486 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1487 for (; !found && rp != NULL; rp = rp->next)
1489 path = gld${EMULATION_NAME}_add_sysroot (rp->name);
1490 found = (rp->by == l->by
1491 && gld${EMULATION_NAME}_search_needed (path, &n,
1493 free ((char *) path);
1500 if [ "x${USE_LIBPATH}" = xyes ] ; then
1502 *-*-freebsd* | *-*-dragonfly*)
1504 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1510 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1512 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1521 len = strlen (l->name);
1522 for (search = search_head; search != NULL; search = search->next)
1526 if (search->cmdline)
1528 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1529 sprintf (filename, "%s/%s", search->name, l->name);
1531 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1544 einfo (_("%P: warning: %s, needed by %pB, not found "
1545 "(try using -rpath or -rpath-link)\n"),
1549 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1550 if (!bfd_elf_parse_eh_frame_entries (NULL, &link_info))
1551 einfo (_("%F%P: failed to parse EH frame entries\n"));
1559 /* Look through an expression for an assignment statement. */
1562 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1564 bfd_boolean provide = FALSE;
1566 switch (exp->type.node_class)
1569 case etree_provided:
1573 /* We call record_link_assignment even if the symbol is defined.
1574 This is because if it is defined by a dynamic object, we
1575 actually want to use the value defined by the linker script,
1576 not the value from the dynamic object (because we are setting
1577 symbols like etext). If the symbol is defined by a regular
1578 object, then, as it happens, calling record_link_assignment
1580 if (strcmp (exp->assign.dst, ".") != 0)
1582 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1584 exp->assign.dst, provide,
1585 exp->assign.hidden))
1586 einfo (_("%F%P: failed to record assignment to %s: %E\n"),
1589 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1593 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1594 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1598 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1599 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1600 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1604 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1613 /* This is called by the before_allocation routine via
1614 lang_for_each_statement. It locates any assignment statements, and
1615 tells the ELF backend about them, in case they are assignments to
1616 symbols which are referred to by dynamic objects. */
1619 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1621 if (s->header.type == lang_assignment_statement_enum)
1622 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1627 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1628 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1629 ELF_INTERPRETER_SET_DEFAULT="
1630 if (sinterp != NULL)
1632 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1633 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1638 ELF_INTERPRETER_SET_DEFAULT=
1642 /* used by before_allocation and handle_option. */
1644 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1647 *to = xstrdup (op_arg);
1650 size_t to_len = strlen (*to);
1651 size_t op_arg_len = strlen (op_arg);
1655 /* First see whether OPTARG is already in the path. */
1658 if (strncmp (op_arg, cp, op_arg_len) == 0
1659 && (cp[op_arg_len] == 0
1660 || cp[op_arg_len] == config.rpath_separator))
1664 /* Not yet found. */
1665 cp = strchr (cp, config.rpath_separator);
1673 buf = xmalloc (to_len + op_arg_len + 2);
1674 sprintf (buf, "%s%c%s", *to,
1675 config.rpath_separator, op_arg);
1682 #if defined(__GNUC__) && GCC_VERSION < 4006
1683 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1684 static struct bfd_link_hash_entry ehdr_start_empty;
1687 /* This is called after the sections have been attached to output
1688 sections, but before any sizes or addresses have been set. */
1691 gld${EMULATION_NAME}_before_allocation (void)
1696 struct elf_link_hash_entry *ehdr_start = NULL;
1697 #if defined(__GNUC__) && GCC_VERSION < 4006
1698 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1699 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1701 struct bfd_link_hash_entry ehdr_start_save;
1704 if (is_elf_hash_table (link_info.hash))
1706 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1708 /* Make __ehdr_start hidden if it has been referenced, to
1709 prevent the symbol from being dynamic. */
1710 if (!bfd_link_relocatable (&link_info))
1712 struct elf_link_hash_table *htab = elf_hash_table (&link_info);
1713 struct elf_link_hash_entry *h
1714 = elf_link_hash_lookup (htab, "__ehdr_start", FALSE, FALSE, TRUE);
1716 /* Only adjust the export class if the symbol was referenced
1717 and not defined, otherwise leave it alone. */
1719 && (h->root.type == bfd_link_hash_new
1720 || h->root.type == bfd_link_hash_undefined
1721 || h->root.type == bfd_link_hash_undefweak
1722 || h->root.type == bfd_link_hash_common))
1724 const struct elf_backend_data *bed;
1725 bed = get_elf_backend_data (link_info.output_bfd);
1726 (*bed->elf_backend_hide_symbol) (&link_info, h, TRUE);
1727 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1728 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1729 /* Don't leave the symbol undefined. Undefined hidden
1730 symbols typically won't have dynamic relocations, but
1731 we most likely will need dynamic relocations for
1732 __ehdr_start if we are building a PIE or shared
1735 ehdr_start_save = h->root;
1736 h->root.type = bfd_link_hash_defined;
1737 h->root.u.def.section = bfd_abs_section_ptr;
1738 h->root.u.def.value = 0;
1742 /* If we are going to make any variable assignments, we need to
1743 let the ELF backend know about them in case the variables are
1744 referred to by dynamic objects. */
1745 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1748 /* Let the ELF backend work out the sizes of any sections required
1749 by dynamic linking. */
1750 rpath = command_line.rpath;
1752 rpath = (const char *) getenv ("LD_RUN_PATH");
1754 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1755 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1757 const char *audit_libs = elf_dt_audit (abfd);
1759 /* If the input bfd contains an audit entry, we need to add it as
1760 a dep audit entry. */
1761 if (audit_libs && *audit_libs != '\0')
1763 char *cp = xstrdup (audit_libs);
1767 char *cp2 = strchr (cp, config.rpath_separator);
1775 if (cp != NULL && *cp != '\0')
1776 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1778 cp = more ? ++cp2 : NULL;
1784 if (! (bfd_elf_size_dynamic_sections
1785 (link_info.output_bfd, command_line.soname, rpath,
1786 command_line.filter_shlib, audit, depaudit,
1787 (const char * const *) command_line.auxiliary_filters,
1788 &link_info, &sinterp)))
1789 einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
1791 ${ELF_INTERPRETER_SET_DEFAULT}
1792 /* Let the user override the dynamic linker we are using. */
1793 if (command_line.interpreter != NULL
1796 sinterp->contents = (bfd_byte *) command_line.interpreter;
1797 sinterp->size = strlen (command_line.interpreter) + 1;
1800 /* Look for any sections named .gnu.warning. As a GNU extensions,
1801 we treat such sections as containing warning messages. We print
1802 out the warning message, and then zero out the section size so
1803 that it does not get copied into the output file. */
1806 LANG_FOR_EACH_INPUT_STATEMENT (is)
1812 if (is->flags.just_syms)
1815 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1820 msg = (char *) xmalloc ((size_t) (sz + 1));
1821 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1823 einfo (_("%F%P: %pB: can't read contents of section .gnu.warning: %E\n"),
1826 (*link_info.callbacks->warning) (&link_info, msg,
1827 (const char *) NULL, is->the_bfd,
1828 (asection *) NULL, (bfd_vma) 0);
1831 /* Clobber the section size, so that we don't waste space
1832 copying the warning into the output file. If we've already
1833 sized the output section, adjust its size. The adjustment
1834 is on rawsize because targets that size sections early will
1835 have called lang_reset_memory_regions after sizing. */
1836 if (s->output_section != NULL
1837 && s->output_section->rawsize >= s->size)
1838 s->output_section->rawsize -= s->size;
1842 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1843 warning section don't get copied to the output. */
1844 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1848 before_allocation_default ();
1850 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1851 einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
1853 if (ehdr_start != NULL)
1855 /* If we twiddled __ehdr_start to defined earlier, put it back
1857 ehdr_start->root.type = ehdr_start_save.type;
1858 ehdr_start->root.u = ehdr_start_save.u;
1865 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1868 /* Try to open a dynamic archive. This is where we know that ELF
1869 dynamic libraries have an extension of .so (or .sl on oddball systems
1873 gld${EMULATION_NAME}_open_dynamic_archive
1874 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1876 const char *filename;
1879 bfd_boolean opened = FALSE;
1881 if (! entry->flags.maybe_archive)
1884 filename = entry->filename;
1885 len = strlen (search->name) + strlen (filename);
1886 if (entry->flags.full_name_provided)
1889 string = (char *) xmalloc (len);
1890 sprintf (string, "%s/%s", search->name, filename);
1896 len += strlen (arch) + sizeof "/lib.so";
1897 #ifdef EXTRA_SHLIB_EXTENSION
1898 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1899 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1902 string = (char *) xmalloc (len + xlen);
1903 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1904 #ifdef EXTRA_SHLIB_EXTENSION
1905 /* Try the .so extension first. If that fails build a new filename
1906 using EXTRA_SHLIB_EXTENSION. */
1907 opened = ldfile_try_open_bfd (string, entry);
1909 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1913 if (!opened && !ldfile_try_open_bfd (string, entry))
1919 entry->filename = string;
1921 /* We have found a dynamic object to include in the link. The ELF
1922 backend linker will create a DT_NEEDED entry in the .dynamic
1923 section naming this file. If this file includes a DT_SONAME
1924 entry, it will be used. Otherwise, the ELF linker will just use
1925 the name of the file. For an archive found by searching, like
1926 this one, the DT_NEEDED entry should consist of just the name of
1927 the file, without the path information used to find it. Note
1928 that we only need to do this if we have a dynamic object; an
1929 archive will never be referenced by a DT_NEEDED entry.
1931 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1932 very pretty. I haven't been able to think of anything that is
1934 if (bfd_check_format (entry->the_bfd, bfd_object)
1935 && (entry->the_bfd->flags & DYNAMIC) != 0)
1937 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1939 /* Rather than duplicating the logic above. Just use the
1940 filename we recorded earlier. */
1942 if (!entry->flags.full_name_provided)
1943 filename = lbasename (entry->filename);
1944 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1953 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1956 /* A variant of lang_output_section_find used by place_orphan. */
1958 static lang_output_section_statement_type *
1959 output_rel_find (asection *sec, int isdyn)
1961 lang_output_section_statement_type *lookup;
1962 lang_output_section_statement_type *last = NULL;
1963 lang_output_section_statement_type *last_alloc = NULL;
1964 lang_output_section_statement_type *last_ro_alloc = NULL;
1965 lang_output_section_statement_type *last_rel = NULL;
1966 lang_output_section_statement_type *last_rel_alloc = NULL;
1967 int rela = sec->name[4] == 'a';
1969 for (lookup = &lang_output_section_statement.head->output_section_statement;
1971 lookup = lookup->next)
1973 if (lookup->constraint >= 0
1974 && CONST_STRNEQ (lookup->name, ".rel"))
1976 int lookrela = lookup->name[4] == 'a';
1978 /* .rel.dyn must come before all other reloc sections, to suit
1983 /* Don't place after .rel.plt as doing so results in wrong
1985 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1988 if (rela == lookrela || last_rel == NULL)
1990 if ((rela == lookrela || last_rel_alloc == NULL)
1991 && lookup->bfd_section != NULL
1992 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1993 last_rel_alloc = lookup;
1997 if (lookup->bfd_section != NULL
1998 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
2000 last_alloc = lookup;
2001 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
2002 last_ro_alloc = lookup;
2007 return last_rel_alloc;
2013 return last_ro_alloc;
2021 /* Return whether IN is suitable to be part of OUT. */
2024 elf_orphan_compatible (asection *in, asection *out)
2026 /* Non-zero sh_info implies a section with SHF_INFO_LINK with
2027 unknown semantics for the generic linker, or a SHT_REL/SHT_RELA
2028 section where sh_info specifies a symbol table. (We won't see
2029 SHT_GROUP, SHT_SYMTAB or SHT_DYNSYM sections here.) We clearly
2030 can't merge SHT_REL/SHT_RELA using differing symbol tables, and
2031 shouldn't merge sections with differing unknown semantics. */
2032 if (elf_section_data (out)->this_hdr.sh_info
2033 != elf_section_data (in)->this_hdr.sh_info)
2035 /* We can't merge two sections with differing SHF_EXCLUDE when doing
2036 a relocatable link. */
2037 if (bfd_link_relocatable (&link_info)
2038 && ((elf_section_flags (out) ^ elf_section_flags (in)) & SHF_EXCLUDE) != 0)
2040 return _bfd_elf_match_sections_by_type (link_info.output_bfd, out,
2044 /* Place an orphan section. We use this to put random SHF_ALLOC
2045 sections in the right segment. */
2047 static lang_output_section_statement_type *
2048 gld${EMULATION_NAME}_place_orphan (asection *s,
2049 const char *secname,
2052 static struct orphan_save hold[] =
2055 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2058 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2061 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
2064 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2070 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2073 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2076 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
2082 enum orphan_save_index
2094 static int orphan_init_done = 0;
2095 struct orphan_save *place;
2096 lang_output_section_statement_type *after;
2097 lang_output_section_statement_type *os;
2098 lang_output_section_statement_type *match_by_name = NULL;
2100 int elfinput = s->owner->xvec->flavour == bfd_target_elf_flavour;
2101 int elfoutput = link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour;
2102 unsigned int sh_type = elfinput ? elf_section_type (s) : SHT_NULL;
2106 if (!bfd_link_relocatable (&link_info)
2107 && link_info.combreloc
2108 && (s->flags & SEC_ALLOC))
2114 secname = ".rela.dyn";
2118 secname = ".rel.dyn";
2124 else if (CONST_STRNEQ (secname, ".rel"))
2126 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2131 if (!bfd_link_relocatable (&link_info)
2134 && (s->flags & SEC_ALLOC) != 0
2135 && (elf_section_flags (s) & SHF_GNU_MBIND) != 0)
2137 /* Find the output mbind section with the same type, attributes
2138 and sh_info field. */
2139 for (os = &lang_output_section_statement.head->output_section_statement;
2142 if (os->bfd_section != NULL
2143 && !bfd_is_abs_section (os->bfd_section)
2144 && (elf_section_flags (os->bfd_section) & SHF_GNU_MBIND) != 0
2145 && ((s->flags & (SEC_ALLOC
2150 == (os->bfd_section->flags & (SEC_ALLOC
2155 && (elf_section_data (os->bfd_section)->this_hdr.sh_info
2156 == elf_section_data (s)->this_hdr.sh_info))
2158 lang_add_section (&os->children, s, NULL, os);
2162 /* Create the output mbind section with the ".mbind." prefix
2164 if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2165 secname = ".mbind.bss";
2166 else if ((s->flags & SEC_READONLY) == 0)
2167 secname = ".mbind.data";
2168 else if ((s->flags & SEC_CODE) == 0)
2169 secname = ".mbind.rodata";
2171 secname = ".mbind.text";
2174 /* Look through the script to see where to place this section. The
2175 script includes entries added by previous lang_insert_orphan
2176 calls, so this loop puts multiple compatible orphans of the same
2177 name into a single output section. */
2178 if (constraint == 0)
2179 for (os = lang_output_section_find (secname);
2181 os = next_matching_output_section_statement (os, 0))
2183 /* If we don't match an existing output section, tell
2184 lang_insert_orphan to create a new output section. */
2185 constraint = SPECIAL;
2187 /* Check to see if we already have an output section statement
2188 with this name, and its bfd section has compatible flags.
2189 If the section already exists but does not have any flags
2190 set, then it has been created by the linker, possibly as a
2191 result of a --section-start command line switch. */
2192 if (os->bfd_section != NULL
2193 && (os->bfd_section->flags == 0
2194 || (((s->flags ^ os->bfd_section->flags)
2195 & (SEC_LOAD | SEC_ALLOC)) == 0
2198 || elf_orphan_compatible (s, os->bfd_section)))))
2200 lang_add_section (&os->children, s, NULL, os);
2204 /* Save unused output sections in case we can match them
2205 against orphans later. */
2206 if (os->bfd_section == NULL)
2210 /* If we didn't match an active output section, see if we matched an
2211 unused one and use that. */
2214 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2215 return match_by_name;
2218 if (!orphan_init_done)
2220 struct orphan_save *ho;
2222 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2223 if (ho->name != NULL)
2225 ho->os = lang_output_section_find (ho->name);
2226 if (ho->os != NULL && ho->os->flags == 0)
2227 ho->os->flags = ho->flags;
2229 orphan_init_done = 1;
2232 /* If this is a final link, then always put .gnu.warning.SYMBOL
2233 sections into the .text section to get them out of the way. */
2234 if (bfd_link_executable (&link_info)
2235 && CONST_STRNEQ (s->name, ".gnu.warning.")
2236 && hold[orphan_text].os != NULL)
2238 os = hold[orphan_text].os;
2239 lang_add_section (&os->children, s, NULL, os);
2244 if (!bfd_link_relocatable (&link_info))
2247 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2249 if (nexts->output_section == NULL
2250 && (nexts->flags & SEC_EXCLUDE) == 0
2251 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2252 && (nexts->owner->flags & DYNAMIC) == 0
2253 && nexts->owner->usrdata != NULL
2254 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2256 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2258 flags = (((flags ^ SEC_READONLY)
2259 | (nexts->flags ^ SEC_READONLY))
2263 /* Decide which segment the section should go in based on the
2264 section name and section flags. We put loadable .note sections
2265 right after the .interp section, so that the PT_NOTE segment is
2266 stored right after the program headers where the OS can read it
2267 in the first page. */
2270 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2271 place = &hold[orphan_nonalloc];
2272 else if ((flags & SEC_ALLOC) == 0)
2274 else if ((flags & SEC_LOAD) != 0
2275 && ((elfinput && sh_type == SHT_NOTE)
2276 || (!elfinput && CONST_STRNEQ (secname, ".note"))))
2277 place = &hold[orphan_interp];
2278 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2279 place = &hold[orphan_bss];
2280 else if ((flags & SEC_SMALL_DATA) != 0)
2281 place = &hold[orphan_sdata];
2282 else if ((flags & SEC_THREAD_LOCAL) != 0)
2283 place = &hold[orphan_tdata];
2284 else if ((flags & SEC_READONLY) == 0)
2285 place = &hold[orphan_data];
2286 else if (((elfinput && (sh_type == SHT_RELA || sh_type == SHT_REL))
2287 || (!elfinput && CONST_STRNEQ (secname, ".rel")))
2288 && (flags & SEC_LOAD) != 0)
2289 place = &hold[orphan_rel];
2290 else if ((flags & SEC_CODE) == 0)
2291 place = &hold[orphan_rodata];
2293 place = &hold[orphan_text];
2298 if (place->os == NULL)
2300 if (place->name != NULL)
2301 place->os = lang_output_section_find (place->name);
2303 place->os = output_rel_find (s, isdyn);
2308 = lang_output_section_find_by_flags (s, flags, &place->os,
2309 _bfd_elf_match_sections_by_type);
2311 /* *ABS* is always the first output section statement. */
2312 after = &lang_output_section_statement.head->output_section_statement;
2315 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2320 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2324 gld${EMULATION_NAME}_after_allocation (void)
2326 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2328 if (need_layout < 0)
2329 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
2331 gld${EMULATION_NAME}_map_segments (need_layout);
2336 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2340 gld${EMULATION_NAME}_get_script (int *isfile)
2343 if test x"$COMPILE_IN" = xyes
2345 # Scripts compiled in.
2347 # sed commands to quote an ld script as a C string.
2348 sc="-f stringify.sed"
2354 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2357 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2358 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2359 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2360 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2361 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2362 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2363 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2364 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2366 if test -n "$GENERATE_PIE_SCRIPT" ; then
2367 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2368 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2369 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2370 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
2371 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2372 sed $sc ldscripts/${EMULATION_NAME}.xdwe >> e${EMULATION_NAME}.c
2373 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2374 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2375 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2376 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2377 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2378 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2379 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
2380 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2381 sed $sc ldscripts/${EMULATION_NAME}.xdce >> e${EMULATION_NAME}.c
2382 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2383 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2384 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2386 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2387 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
2388 sed $sc ldscripts/${EMULATION_NAME}.xde >> e${EMULATION_NAME}.c
2389 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2390 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2392 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2393 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2394 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2395 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2396 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
2397 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2398 sed $sc ldscripts/${EMULATION_NAME}.xswe >> e${EMULATION_NAME}.c
2399 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2400 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2401 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2402 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2403 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2404 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2405 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2406 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
2407 sed $sc ldscripts/${EMULATION_NAME}.xsce >> e${EMULATION_NAME}.c
2408 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2409 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2410 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2412 echo ' ; else if (bfd_link_dll (&link_info)' >> e${EMULATION_NAME}.c
2413 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
2414 sed $sc ldscripts/${EMULATION_NAME}.xse >> e${EMULATION_NAME}.c
2415 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2416 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2418 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2419 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
2420 echo ' && link_info.separate_code' >> e${EMULATION_NAME}.c
2421 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2422 sed $sc ldscripts/${EMULATION_NAME}.xwe >> e${EMULATION_NAME}.c
2423 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
2424 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2425 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2426 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2427 echo ' ; else if (link_info.combreloc' >> e${EMULATION_NAME}.c
2428 echo ' && link_info.separate_code) return' >> e${EMULATION_NAME}.c
2429 sed $sc ldscripts/${EMULATION_NAME}.xce >> e${EMULATION_NAME}.c
2430 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2431 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2433 echo ' ; else if (link_info.separate_code) return' >> e${EMULATION_NAME}.c
2434 sed $sc ldscripts/${EMULATION_NAME}.xe >> e${EMULATION_NAME}.c
2435 echo ' ; else return' >> e${EMULATION_NAME}.c
2436 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2437 echo '; }' >> e${EMULATION_NAME}.c
2440 # Scripts read from the filesystem.
2446 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2447 return "ldscripts/${EMULATION_NAME}.xu";
2448 else if (bfd_link_relocatable (&link_info))
2449 return "ldscripts/${EMULATION_NAME}.xr";
2450 else if (!config.text_read_only)
2451 return "ldscripts/${EMULATION_NAME}.xbn";
2453 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2456 else if (!config.magic_demand_paged)
2457 return "ldscripts/${EMULATION_NAME}.xn";
2460 if test -n "$GENERATE_PIE_SCRIPT" ; then
2461 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2463 else if (bfd_link_pie (&link_info)
2464 && link_info.combreloc
2466 && (link_info.flags & DF_BIND_NOW))
2468 if (link_info.separate_code)
2469 return "ldscripts/${EMULATION_NAME}.xdwe";
2471 return "ldscripts/${EMULATION_NAME}.xdw";
2473 else if (bfd_link_pie (&link_info)
2474 && link_info.combreloc)
2476 if (link_info.separate_code)
2477 return "ldscripts/${EMULATION_NAME}.xdce";
2479 return "ldscripts/${EMULATION_NAME}.xdc";
2484 else if (bfd_link_pie (&link_info))
2486 if (link_info.separate_code)
2487 return "ldscripts/${EMULATION_NAME}.xde";
2489 return "ldscripts/${EMULATION_NAME}.xd";
2493 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2494 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2496 else if (bfd_link_dll (&link_info) && link_info.combreloc
2497 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2499 if (link_info.separate_code)
2500 return "ldscripts/${EMULATION_NAME}.xswe";
2502 return "ldscripts/${EMULATION_NAME}.xsw";
2504 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2506 if (link_info.separate_code)
2507 return "ldscripts/${EMULATION_NAME}.xsce";
2509 return "ldscripts/${EMULATION_NAME}.xsc";
2514 else if (bfd_link_dll (&link_info))
2516 if (link_info.separate_code)
2517 return "ldscripts/${EMULATION_NAME}.xse";
2519 return "ldscripts/${EMULATION_NAME}.xs";
2523 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2525 else if (link_info.combreloc && link_info.relro
2526 && (link_info.flags & DF_BIND_NOW))
2528 if (link_info.separate_code)
2529 return "ldscripts/${EMULATION_NAME}.xwe";
2531 return "ldscripts/${EMULATION_NAME}.xw";
2533 else if (link_info.combreloc)
2535 if (link_info.separate_code)
2536 return "ldscripts/${EMULATION_NAME}.xce";
2538 return "ldscripts/${EMULATION_NAME}.xc";
2545 if (link_info.separate_code)
2546 return "ldscripts/${EMULATION_NAME}.xe";
2548 return "ldscripts/${EMULATION_NAME}.x";
2556 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2558 $PARSE_AND_LIST_PROLOGUE
2566 OPTION_DISABLE_NEW_DTAGS = 400,
2567 OPTION_ENABLE_NEW_DTAGS,
2569 OPTION_EH_FRAME_HDR,
2570 OPTION_NO_EH_FRAME_HDR,
2571 OPTION_EXCLUDE_LIBS,
2575 OPTION_COMPRESS_DEBUG
2579 gld${EMULATION_NAME}_add_options
2580 (int ns, char **shortopts, int nl, struct option **longopts,
2581 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2584 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2586 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2590 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2594 static const struct option xtra_long[] = {
2596 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2598 {"audit", required_argument, NULL, OPTION_AUDIT},
2599 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2603 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2604 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2606 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2608 {"depaudit", required_argument, NULL, 'P'},
2609 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2610 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2611 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2612 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2613 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2614 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2617 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2619 $PARSE_AND_LIST_LONGOPTS
2623 {NULL, no_argument, NULL, 0}
2626 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2627 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2628 *longopts = (struct option *)
2629 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2630 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2633 #define DEFAULT_BUILD_ID_STYLE "sha1"
2636 gld${EMULATION_NAME}_handle_option (int optc)
2643 case OPTION_BUILD_ID:
2644 if (emit_note_gnu_build_id != NULL)
2646 free ((char *) emit_note_gnu_build_id);
2647 emit_note_gnu_build_id = NULL;
2650 optarg = DEFAULT_BUILD_ID_STYLE;
2651 if (strcmp (optarg, "none"))
2652 emit_note_gnu_build_id = xstrdup (optarg);
2655 case OPTION_COMPRESS_DEBUG:
2656 if (strcasecmp (optarg, "none") == 0)
2657 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2658 else if (strcasecmp (optarg, "zlib") == 0)
2659 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2660 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2661 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2662 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2663 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2665 einfo (_("%F%P: invalid --compress-debug-sections option: \`%s'\n"),
2670 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2673 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2677 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2680 case OPTION_DISABLE_NEW_DTAGS:
2681 link_info.new_dtags = FALSE;
2684 case OPTION_ENABLE_NEW_DTAGS:
2685 link_info.new_dtags = TRUE;
2688 case OPTION_EH_FRAME_HDR:
2689 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2692 case OPTION_NO_EH_FRAME_HDR:
2693 link_info.eh_frame_hdr_type = 0;
2697 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2698 /* Groups must be self-contained. */
2699 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2700 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2703 case OPTION_EXCLUDE_LIBS:
2704 add_excluded_libs (optarg);
2707 case OPTION_HASH_STYLE:
2708 link_info.emit_hash = FALSE;
2709 link_info.emit_gnu_hash = FALSE;
2710 if (strcmp (optarg, "sysv") == 0)
2711 link_info.emit_hash = TRUE;
2712 else if (strcmp (optarg, "gnu") == 0)
2713 link_info.emit_gnu_hash = TRUE;
2714 else if (strcmp (optarg, "both") == 0)
2716 link_info.emit_hash = TRUE;
2717 link_info.emit_gnu_hash = TRUE;
2720 einfo (_("%F%P: invalid hash style \`%s'\n"), optarg);
2727 if (strcmp (optarg, "defs") == 0)
2728 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2729 else if (strcmp (optarg, "undefs") == 0)
2730 link_info.unresolved_syms_in_objects = RM_IGNORE;
2731 else if (strcmp (optarg, "muldefs") == 0)
2732 link_info.allow_multiple_definition = TRUE;
2733 else if (CONST_STRNEQ (optarg, "max-page-size="))
2737 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2738 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2739 einfo (_("%F%P: invalid maxium page size \`%s'\n"),
2742 else if (CONST_STRNEQ (optarg, "common-page-size="))
2745 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2747 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2748 einfo (_("%F%P: invalid common page size \`%s'\n"),
2751 else if (CONST_STRNEQ (optarg, "stack-size="))
2754 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2755 if (*end || link_info.stacksize < 0)
2756 einfo (_("%F%P: invalid stack size \`%s'\n"), optarg + 11);
2757 if (!link_info.stacksize)
2758 /* Use -1 for explicit no-stack, because zero means
2760 link_info.stacksize = -1;
2762 else if (strcmp (optarg, "execstack") == 0)
2764 link_info.execstack = TRUE;
2765 link_info.noexecstack = FALSE;
2767 else if (strcmp (optarg, "noexecstack") == 0)
2769 link_info.noexecstack = TRUE;
2770 link_info.execstack = FALSE;
2772 else if (strcmp (optarg, "globalaudit") == 0)
2774 link_info.flags_1 |= DF_1_GLOBAUDIT;
2778 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2780 else if (strcmp (optarg, "global") == 0)
2781 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2782 else if (strcmp (optarg, "initfirst") == 0)
2783 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2784 else if (strcmp (optarg, "interpose") == 0)
2785 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2786 else if (strcmp (optarg, "loadfltr") == 0)
2787 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2788 else if (strcmp (optarg, "nodefaultlib") == 0)
2789 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2790 else if (strcmp (optarg, "nodelete") == 0)
2791 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2792 else if (strcmp (optarg, "nodlopen") == 0)
2793 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2794 else if (strcmp (optarg, "nodump") == 0)
2795 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2796 else if (strcmp (optarg, "now") == 0)
2798 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2799 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2801 else if (strcmp (optarg, "lazy") == 0)
2803 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2804 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2806 else if (strcmp (optarg, "origin") == 0)
2808 link_info.flags |= (bfd_vma) DF_ORIGIN;
2809 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2811 else if (strcmp (optarg, "combreloc") == 0)
2812 link_info.combreloc = TRUE;
2813 else if (strcmp (optarg, "nocombreloc") == 0)
2814 link_info.combreloc = FALSE;
2815 else if (strcmp (optarg, "nocopyreloc") == 0)
2816 link_info.nocopyreloc = TRUE;
2817 else if (strcmp (optarg, "relro") == 0)
2818 link_info.relro = TRUE;
2819 else if (strcmp (optarg, "norelro") == 0)
2820 link_info.relro = FALSE;
2821 else if (strcmp (optarg, "separate-code") == 0)
2822 link_info.separate_code = TRUE;
2823 else if (strcmp (optarg, "noseparate-code") == 0)
2824 link_info.separate_code = FALSE;
2825 else if (strcmp (optarg, "common") == 0)
2826 link_info.elf_stt_common = elf_stt_common;
2827 else if (strcmp (optarg, "nocommon") == 0)
2828 link_info.elf_stt_common = no_elf_stt_common;
2829 else if (strcmp (optarg, "text") == 0)
2830 link_info.error_textrel = TRUE;
2831 else if (strcmp (optarg, "notext") == 0)
2832 link_info.error_textrel = FALSE;
2833 else if (strcmp (optarg, "textoff") == 0)
2834 link_info.error_textrel = FALSE;
2838 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2840 $PARSE_AND_LIST_ARGS_CASE_Z
2846 einfo (_("%P: warning: -z %s ignored\n"), optarg);
2850 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2852 $PARSE_AND_LIST_ARGS_CASES
2864 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2865 gld_list_options="gld${EMULATION_NAME}_list_options"
2866 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2870 gld${EMULATION_NAME}_list_options (FILE * file)
2874 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2876 $PARSE_AND_LIST_OPTIONS
2884 gld_list_options="NULL"
2887 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2889 $PARSE_AND_LIST_EPILOGUE
2896 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2898 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2899 ${LDEMUL_SYSLIB-syslib_default},
2900 ${LDEMUL_HLL-hll_default},
2901 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2902 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2903 ${LDEMUL_AFTER_CHECK_RELOCS-after_check_relocs_default},
2904 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2905 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2906 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2907 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2908 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2909 "${EMULATION_NAME}",
2911 ${LDEMUL_FINISH-finish_default},
2912 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2913 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2914 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2915 ${LDEMUL_SET_SYMBOLS-NULL},
2916 ${LDEMUL_PARSE_ARGS-NULL},
2917 gld${EMULATION_NAME}_add_options,
2918 gld${EMULATION_NAME}_handle_option,
2919 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2920 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2921 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2922 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2923 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2924 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}