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 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
16 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
17 Free Software Foundation, Inc.
18 Written by Steve Chamberlain <sac@cygnus.com>
19 ELF support by Ian Lance Taylor <ian@cygnus.com>
21 This file is part of the GNU Binutils.
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 3 of the License, or
26 (at your option) any later version.
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
36 MA 02110-1301, USA. */
38 #define TARGET_IS_${EMULATION_NAME}
42 #include "libiberty.h"
43 #include "safe-ctype.h"
59 #include "elf/common.h"
62 /* Declare functions used by various EXTRA_EM_FILEs. */
63 static void gld${EMULATION_NAME}_before_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*-*)
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 config.dynamic_link = ${DYNAMIC_LINK-TRUE};
104 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
110 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
112 /* Handle as_needed DT_NEEDED. */
115 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
119 /* Tell the ELF linker that we don't want the output file to have a
120 DT_NEEDED entry for this file, unless it is used to resolve
121 references in a regular object. */
122 if (entry->as_needed)
123 link_class = DYN_AS_NEEDED;
125 /* Tell the ELF linker that we don't want the output file to have a
126 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
128 if (!entry->add_needed)
129 link_class |= DYN_NO_ADD_NEEDED;
131 if (entry->just_syms_flag
132 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
133 einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
137 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
140 bfd_elf_set_dyn_lib_class (entry->the_bfd,
141 (enum dynamic_lib_link_class) link_class);
143 /* Continue on with normal load_symbols processing. */
151 /* These variables are required to pass information back and forth
152 between after_open and check_needed and stat_needed and vercheck. */
154 static struct bfd_link_needed_list *global_needed;
155 static struct stat global_stat;
156 static lang_input_statement_type *global_found;
157 static struct bfd_link_needed_list *global_vercheck_needed;
158 static bfd_boolean global_vercheck_failed;
160 /* These variables are used to implement target options */
162 static char *audit; /* colon (typically) separated list of libs */
163 static char *depaudit; /* colon (typically) separated list of libs */
165 /* On Linux, it's possible to have different versions of the same
166 shared library linked against different versions of libc. The
167 dynamic linker somehow tags which libc version to use in
168 /etc/ld.so.cache, and, based on the libc that it sees in the
169 executable, chooses which version of the shared library to use.
171 We try to do a similar check here by checking whether this shared
172 library needs any other shared libraries which may conflict with
173 libraries we have already included in the link. If it does, we
174 skip it, and try to find another shared library farther on down the
177 This is called via lang_for_each_input_file.
178 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
179 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
180 a conflicting version. */
183 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
186 struct bfd_link_needed_list *l;
188 if (global_vercheck_failed)
190 if (s->the_bfd == NULL
191 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
194 soname = bfd_elf_get_dt_soname (s->the_bfd);
196 soname = lbasename (bfd_get_filename (s->the_bfd));
198 for (l = global_vercheck_needed; l != NULL; l = l->next)
202 if (strcmp (soname, l->name) == 0)
204 /* Probably can't happen, but it's an easy check. */
208 if (strchr (l->name, '/') != NULL)
211 suffix = strstr (l->name, ".so.");
215 suffix += sizeof ".so." - 1;
217 if (strncmp (soname, l->name, suffix - l->name) == 0)
219 /* Here we know that S is a dynamic object FOO.SO.VER1, and
220 the object we are considering needs a dynamic object
221 FOO.SO.VER2, and VER1 and VER2 are different. This
222 appears to be a version mismatch, so we tell the caller
223 to try a different version of this library. */
224 global_vercheck_failed = TRUE;
231 /* See if an input file matches a DT_NEEDED entry by running stat on
235 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
241 if (global_found != NULL)
243 if (s->the_bfd == NULL)
246 /* If this input file was an as-needed entry, and wasn't found to be
247 needed at the stage it was linked, then don't say we have loaded it. */
248 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
251 if (bfd_stat (s->the_bfd, &st) != 0)
253 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
257 /* Some operating systems, e.g. Windows, do not provide a meaningful
258 st_ino; they always set it to zero. (Windows does provide a
259 meaningful st_dev.) Do not indicate a duplicate library in that
260 case. While there is no guarantee that a system that provides
261 meaningful inode numbers will never set st_ino to zero, this is
262 merely an optimization, so we do not need to worry about false
264 if (st.st_dev == global_stat.st_dev
265 && st.st_ino == global_stat.st_ino
272 /* We issue a warning if it looks like we are including two
273 different versions of the same shared library. For example,
274 there may be a problem if -lc picks up libc.so.6 but some other
275 shared library has a DT_NEEDED entry of libc.so.5. This is a
276 heuristic test, and it will only work if the name looks like
277 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
278 If we really want to issue warnings about mixing version numbers
279 of shared libraries, we need to find a better way. */
281 if (strchr (global_needed->name, '/') != NULL)
283 suffix = strstr (global_needed->name, ".so.");
286 suffix += sizeof ".so." - 1;
288 soname = bfd_elf_get_dt_soname (s->the_bfd);
290 soname = lbasename (s->filename);
292 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
293 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
294 global_needed->name, global_needed->by, soname);
303 /* This function is called for each possible name for a dynamic object
304 named by a DT_NEEDED entry. The FORCE parameter indicates whether
305 to skip the check for a conflicting version. */
308 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
312 const char *name = needed->name;
316 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
319 if (! bfd_check_format (abfd, bfd_object))
324 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
330 /* For DT_NEEDED, they have to match. */
331 if (abfd->xvec != link_info.output_bfd->xvec)
337 /* Check whether this object would include any conflicting library
338 versions. If FORCE is set, then we skip this check; we use this
339 the second time around, if we couldn't find any compatible
340 instance of the shared library. */
344 struct bfd_link_needed_list *needed;
346 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
347 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
351 global_vercheck_needed = needed;
352 global_vercheck_failed = FALSE;
353 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
354 if (global_vercheck_failed)
357 /* Return FALSE to force the caller to move on to try
358 another file on the search path. */
362 /* But wait! It gets much worse. On Linux, if a shared
363 library does not use libc at all, we are supposed to skip
364 it the first time around in case we encounter a shared
365 library later on with the same name which does use the
366 version of libc that we want. This is much too horrible
367 to use on any system other than Linux. */
371 *-*-linux-* | *-*-k*bsd*-*)
374 struct bfd_link_needed_list *l;
376 for (l = needed; l != NULL; l = l->next)
377 if (CONST_STRNEQ (l->name, "libc.so"))
393 /* We've found a dynamic object matching the DT_NEEDED entry. */
395 /* We have already checked that there is no other input file of the
396 same name. We must now check again that we are not including the
397 same file twice. We need to do this because on many systems
398 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
399 reference libc.so.1. If we have already included libc.so, we
400 don't want to include libc.so.1 if they are the same file, and we
401 can only check that using stat. */
403 if (bfd_stat (abfd, &global_stat) != 0)
404 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
406 /* First strip off everything before the last '/'. */
407 soname = lbasename (abfd->filename);
409 if (trace_file_tries)
410 info_msg (_("found %s at %s\n"), soname, name);
413 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
414 if (global_found != NULL)
416 /* Return TRUE to indicate that we found the file, even though
417 we aren't going to do anything with it. */
421 /* Specify the soname to use. */
422 bfd_elf_set_dt_needed_name (abfd, soname);
424 /* Tell the ELF linker that we don't want the output file to have a
425 DT_NEEDED entry for this file, unless it is used to resolve
426 references in a regular object. */
427 link_class = DYN_DT_NEEDED;
429 /* Tell the ELF linker that we don't want the output file to have a
430 DT_NEEDED entry for this file at all if the entry is from a file
431 with DYN_NO_ADD_NEEDED. */
432 if (needed->by != NULL
433 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
434 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
436 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
438 /* Add this file into the symbol table. */
439 if (! bfd_link_add_symbols (abfd, &link_info))
440 einfo ("%F%B: could not read symbols: %E\n", abfd);
446 /* Search for a needed file in a path. */
449 gld${EMULATION_NAME}_search_needed (const char *path,
450 struct dt_needed *n, int force)
453 const char *name = n->name;
455 struct dt_needed needed;
458 return gld${EMULATION_NAME}_try_needed (n, force);
460 if (path == NULL || *path == '\0')
464 needed.name = n->name;
469 char *filename, *sset;
471 s = strchr (path, config.rpath_separator);
473 s = path + strlen (path);
475 filename = (char *) xmalloc (s - path + len + 2);
480 memcpy (filename, path, s - path);
481 filename[s - path] = '/';
482 sset = filename + (s - path) + 1;
486 needed.name = filename;
487 if (gld${EMULATION_NAME}_try_needed (&needed, force))
501 if [ "x${USE_LIBPATH}" = xyes ] ; then
504 /* Add the sysroot to every entry in a path separated by
505 config.rpath_separator. */
508 gld${EMULATION_NAME}_add_sysroot (const char *path)
517 if (path[i++] == config.rpath_separator)
523 len = len + (colons + 1) * strlen (ld_sysroot);
524 ret = xmalloc (len + 1);
525 strcpy (ret, ld_sysroot);
526 p = ret + strlen (ret);
529 if (path[i] == config.rpath_separator)
532 strcpy (p, ld_sysroot);
544 *-*-freebsd* | *-*-dragonfly*)
546 /* Read the system search path the FreeBSD way rather than the Linux way. */
547 #ifdef HAVE_ELF_HINTS_H
548 #include <elf-hints.h>
550 #include "elf-hints-local.h"
554 gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force)
556 static bfd_boolean initialized;
557 static char *ld_elf_hints;
558 struct dt_needed needed;
565 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
566 f = fopen (tmppath, FOPEN_RB);
570 struct elfhints_hdr hdr;
572 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
573 && hdr.magic == ELFHINTS_MAGIC
576 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
580 b = xmalloc (hdr.dirlistlen + 1);
581 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
583 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
594 if (ld_elf_hints == NULL)
599 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, & needed,
606 *-*-linux-* | *-*-k*bsd*-*)
608 /* For a native linker, check the file /etc/ld.so.conf for directories
609 in which we may find shared libraries. /etc/ld.so.conf is really
610 only meaningful on Linux. */
612 struct gld${EMULATION_NAME}_ld_so_conf
619 gld${EMULATION_NAME}_parse_ld_so_conf
620 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
623 gld${EMULATION_NAME}_parse_ld_so_conf_include
624 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
632 if (pattern[0] != '/')
634 char *p = strrchr (filename, '/');
635 size_t patlen = strlen (pattern) + 1;
637 newp = xmalloc (p - filename + 1 + patlen);
638 memcpy (newp, filename, p - filename + 1);
639 memcpy (newp + (p - filename + 1), pattern, patlen);
644 if (glob (pattern, 0, NULL, &gl) == 0)
648 for (i = 0; i < gl.gl_pathc; ++i)
649 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
653 /* If we do not have glob, treat the pattern as a literal filename. */
654 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
662 gld${EMULATION_NAME}_parse_ld_so_conf
663 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
665 FILE *f = fopen (filename, FOPEN_RT);
673 line = xmalloc (linelen);
678 /* Normally this would use getline(3), but we need to be portable. */
679 while ((q = fgets (p, linelen - (p - line), f)) != NULL
680 && strlen (q) == linelen - (p - line) - 1
681 && line[linelen - 2] != '\n')
683 line = xrealloc (line, 2 * linelen);
684 p = line + linelen - 1;
688 if (q == NULL && p == line)
691 p = strchr (line, '\n');
695 /* Because the file format does not know any form of quoting we
696 can search forward for the next '#' character and if found
697 make it terminating the line. */
698 p = strchr (line, '#');
702 /* Remove leading whitespace. NUL is no whitespace character. */
704 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
707 /* If the line is blank it is ignored. */
711 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
717 while (*p == ' ' || *p == '\t')
725 while (*p != ' ' && *p != '\t' && *p)
731 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
739 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
740 && *p != '\r' && *p != '\v')
743 while (p != dir && p[-1] == '/')
745 if (info->path == NULL)
747 info->alloc = p - dir + 1 + 256;
748 info->path = xmalloc (info->alloc);
753 if (info->len + 1 + (p - dir) >= info->alloc)
755 info->alloc += p - dir + 256;
756 info->path = xrealloc (info->path, info->alloc);
758 info->path[info->len++] = config.rpath_separator;
760 memcpy (info->path + info->len, dir, p - dir);
761 info->len += p - dir;
762 info->path[info->len] = '\0';
772 gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force)
774 static bfd_boolean initialized;
775 static char *ld_so_conf;
776 struct dt_needed needed;
781 struct gld${EMULATION_NAME}_ld_so_conf info;
784 info.len = info.alloc = 0;
785 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
786 (const char *) NULL);
787 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
790 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
791 (const char *) NULL);
792 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
798 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
805 if (ld_so_conf == NULL)
811 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
821 /* See if an input file matches a DT_NEEDED entry by name. */
824 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
828 /* Stop looking if we've found a loaded lib. */
829 if (global_found != NULL
830 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
831 & DYN_AS_NEEDED) == 0)
834 if (s->filename == NULL || s->the_bfd == NULL)
837 /* Don't look for a second non-loaded as-needed lib. */
838 if (global_found != NULL
839 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
842 if (strcmp (s->filename, global_needed->name) == 0)
848 if (s->search_dirs_flag)
850 const char *f = strrchr (s->filename, '/');
852 && strcmp (f + 1, global_needed->name) == 0)
859 soname = bfd_elf_get_dt_soname (s->the_bfd);
861 && strcmp (soname, global_needed->name) == 0)
870 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
874 gld${EMULATION_NAME}_id_note_section_size (bfd *abfd,
875 struct bfd_link_info *link_info)
877 const char *style = link_info->emit_note_gnu_build_id;
882 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
883 size = (size + 3) & -(bfd_size_type) 4;
885 if (!strcmp (style, "md5") || !strcmp (style, "uuid"))
887 else if (!strcmp (style, "sha1"))
889 else if (!strncmp (style, "0x", 2))
891 /* ID is in string form (hex). Convert to bits. */
892 const char *id = style + 2;
895 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
900 else if (*id == '-' || *id == ':')
907 } while (*id != '\0');
916 read_hex (const char xdigit)
918 if (ISDIGIT (xdigit))
920 if (ISUPPER (xdigit))
921 return xdigit - 'A' + 0xa;
922 if (ISLOWER (xdigit))
923 return xdigit - 'a' + 0xa;
935 gld${EMULATION_NAME}_write_build_id_section (bfd *abfd)
937 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
938 struct build_id_info *info = (struct build_id_info *)
939 elf_tdata (abfd)->after_write_object_contents_info;
941 Elf_Internal_Shdr *i_shdr;
942 unsigned char *contents, *id_bits;
944 Elf_External_Note *e_note;
947 if (bfd_is_abs_section (asec->output_section))
949 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
950 " --build-id ignored.\n"));
953 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
955 if (i_shdr->contents == NULL)
957 if (asec->contents == NULL)
958 asec->contents = (unsigned char *) xmalloc (asec->size);
959 contents = asec->contents;
962 contents = i_shdr->contents + asec->output_offset;
964 e_note = (Elf_External_Note *) contents;
965 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
966 size = (size + 3) & -(bfd_size_type) 4;
967 id_bits = contents + size;
968 size = asec->size - size;
970 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
971 bfd_h_put_32 (abfd, size, &e_note->descsz);
972 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
973 memcpy (e_note->name, "GNU", sizeof "GNU");
975 if (!strcmp (info->style, "md5"))
979 if (bed->s->checksum_contents (abfd,
980 (void (*) (const void *, size_t, void *))
983 md5_finish_ctx (&ctx, id_bits);
987 else if (!strcmp (info->style, "sha1"))
990 sha1_init_ctx (&ctx);
991 if (bed->s->checksum_contents (abfd,
992 (void (*) (const void *, size_t, void *))
995 sha1_finish_ctx (&ctx, id_bits);
999 else if (!strcmp (info->style, "uuid"))
1002 int fd = open ("/dev/urandom", O_RDONLY);
1005 n = read (fd, id_bits, size);
1010 else if (!strncmp (info->style, "0x", 2))
1012 /* ID is in string form (hex). Convert to bits. */
1013 const char *id = info->style + 2;
1017 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
1019 id_bits[n] = read_hex (*id++) << 4;
1020 id_bits[n++] |= read_hex (*id++);
1022 else if (*id == '-' || *id == ':')
1025 abort (); /* Should have been validated earlier. */
1026 } while (*id != '\0');
1029 abort (); /* Should have been validated earlier. */
1032 return (bfd_seek (abfd,
1033 i_shdr->sh_offset + asec->output_offset, SEEK_SET) == 0
1034 && bfd_bwrite (contents, size, abfd) == size);
1038 /* This is called after all the input files have been opened. */
1041 gld${EMULATION_NAME}_after_open (void)
1043 struct bfd_link_needed_list *needed, *l;
1044 struct elf_link_hash_table *htab;
1046 htab = elf_hash_table (&link_info);
1047 if (!is_elf_hash_table (htab))
1050 if (link_info.emit_note_gnu_build_id)
1056 abfd = link_info.input_bfds;
1060 /* PR 10555: If there are no input files do not
1061 try to create a .note.gnu-build-id section. */
1062 free (link_info.emit_note_gnu_build_id);
1063 link_info.emit_note_gnu_build_id = NULL;
1067 size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info);
1070 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1071 free (link_info.emit_note_gnu_build_id);
1072 link_info.emit_note_gnu_build_id = NULL;
1076 s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
1077 SEC_ALLOC | SEC_LOAD
1078 | SEC_IN_MEMORY | SEC_LINKER_CREATED
1079 | SEC_READONLY | SEC_DATA);
1080 if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
1082 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1083 struct build_id_info *b =
1084 (struct build_id_info *) xmalloc (sizeof *b);
1086 b->style = link_info.emit_note_gnu_build_id;
1088 elf_section_type (s) = SHT_NOTE;
1090 t->after_write_object_contents
1091 = &gld${EMULATION_NAME}_write_build_id_section;
1092 t->after_write_object_contents_info = b;
1096 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1097 " --build-id ignored.\n");
1098 free (link_info.emit_note_gnu_build_id);
1099 link_info.emit_note_gnu_build_id = NULL;
1105 if (link_info.relocatable)
1108 if (link_info.eh_frame_hdr
1109 && !link_info.traditional_format)
1114 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
1116 s = bfd_get_section_by_name (abfd, ".eh_frame");
1117 if (s && s->size > 8 && !bfd_is_abs_section (s->output_section))
1122 const struct elf_backend_data *bed;
1124 bed = get_elf_backend_data (abfd);
1125 s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
1126 bed->dynamic_sec_flags
1129 && bfd_set_section_alignment (abfd, s, 2))
1130 htab->eh_info.hdr_sec = s;
1132 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1133 " --eh-frame-hdr ignored.\n");
1137 /* Get the list of files which appear in DT_NEEDED entries in
1138 dynamic objects included in the link (often there will be none).
1139 For each such file, we want to track down the corresponding
1140 library, and include the symbol table in the link. This is what
1141 the runtime dynamic linker will do. Tracking the files down here
1142 permits one dynamic object to include another without requiring
1143 special action by the person doing the link. Note that the
1144 needed list can actually grow while we are stepping through this
1146 if (!link_info.executable)
1148 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1149 for (l = needed; l != NULL; l = l->next)
1151 struct bfd_link_needed_list *ll;
1152 struct dt_needed n, nn;
1155 /* If the lib that needs this one was --as-needed and wasn't
1156 found to be needed, then this lib isn't needed either. */
1158 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1161 /* If we've already seen this file, skip it. */
1162 for (ll = needed; ll != l; ll = ll->next)
1164 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1165 && strcmp (ll->name, l->name) == 0)
1170 /* See if this file was included in the link explicitly. */
1172 global_found = NULL;
1173 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1174 if (global_found != NULL
1175 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1176 & DYN_AS_NEEDED) == 0)
1182 if (trace_file_tries)
1183 info_msg (_("%s needed by %B\n"), l->name, l->by);
1185 /* As-needed libs specified on the command line (or linker script)
1186 take priority over libs found in search dirs. */
1187 if (global_found != NULL)
1189 nn.name = global_found->filename;
1190 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1194 /* We need to find this file and include the symbol table. We
1195 want to search for the file in the same way that the dynamic
1196 linker will search. That means that we want to use
1197 rpath_link, rpath, then the environment variable
1198 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1199 entries (native only), then the linker script LIB_SEARCH_DIRS.
1200 We do not search using the -L arguments.
1202 We search twice. The first time, we skip objects which may
1203 introduce version mismatches. The second time, we force
1204 their use. See gld${EMULATION_NAME}_vercheck comment. */
1205 for (force = 0; force < 2; force++)
1208 search_dirs_type *search;
1210 if [ "x${NATIVE}" = xyes ] ; then
1212 const char *lib_path;
1215 if [ "x${USE_LIBPATH}" = xyes ] ; then
1217 struct bfd_link_needed_list *rp;
1223 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1227 if [ "x${USE_LIBPATH}" = xyes ] ; then
1229 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
1234 if [ "x${NATIVE}" = xyes ] ; then
1236 if (command_line.rpath_link == NULL
1237 && command_line.rpath == NULL)
1239 lib_path = (const char *) getenv ("LD_RUN_PATH");
1240 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
1244 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
1245 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
1249 if [ "x${USE_LIBPATH}" = xyes ] ; then
1252 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1253 for (; !found && rp != NULL; rp = rp->next)
1255 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
1256 found = (rp->by == l->by
1257 && gld${EMULATION_NAME}_search_needed (tmpname,
1267 if [ "x${USE_LIBPATH}" = xyes ] ; then
1269 *-*-freebsd* | *-*-dragonfly*)
1271 if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
1277 *-*-linux-* | *-*-k*bsd*-*)
1280 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
1288 len = strlen (l->name);
1289 for (search = search_head; search != NULL; search = search->next)
1293 if (search->cmdline)
1295 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1296 sprintf (filename, "%s/%s", search->name, l->name);
1298 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1311 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1321 /* Look through an expression for an assignment statement. */
1324 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1326 bfd_boolean provide = FALSE;
1328 switch (exp->type.node_class)
1334 /* We call record_link_assignment even if the symbol is defined.
1335 This is because if it is defined by a dynamic object, we
1336 actually want to use the value defined by the linker script,
1337 not the value from the dynamic object (because we are setting
1338 symbols like etext). If the symbol is defined by a regular
1339 object, then, as it happens, calling record_link_assignment
1341 if (strcmp (exp->assign.dst, ".") != 0)
1343 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1345 exp->assign.dst, provide,
1346 exp->assign.hidden))
1347 einfo ("%P%F: failed to record assignment to %s: %E\n",
1350 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1354 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1355 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1359 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1360 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1361 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1365 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1374 /* This is called by the before_allocation routine via
1375 lang_for_each_statement. It locates any assignment statements, and
1376 tells the ELF backend about them, in case they are assignments to
1377 symbols which are referred to by dynamic objects. */
1380 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1382 if (s->header.type == lang_assignment_statement_enum)
1383 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1388 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1389 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1390 ELF_INTERPRETER_SET_DEFAULT="
1391 if (sinterp != NULL)
1393 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1394 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1399 ELF_INTERPRETER_SET_DEFAULT=
1403 /* used by before_allocation and handle_option. */
1405 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *optarg)
1408 *to = xstrdup (optarg);
1411 size_t to_len = strlen (*to);
1412 size_t optarg_len = strlen (optarg);
1416 /* First see whether OPTARG is already in the path. */
1419 if (strncmp (optarg, cp, optarg_len) == 0
1420 && (cp[optarg_len] == 0
1421 || cp[optarg_len] == config.rpath_separator))
1425 /* Not yet found. */
1426 cp = strchr (cp, config.rpath_separator);
1434 buf = xmalloc (to_len + optarg_len + 2);
1435 sprintf (buf, "%s%c%s", *to,
1436 config.rpath_separator, optarg);
1443 /* This is called after the sections have been attached to output
1444 sections, but before any sizes or addresses have been set. */
1447 gld${EMULATION_NAME}_before_allocation (void)
1453 if (link_info.hash->type == bfd_link_elf_hash_table)
1454 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1456 /* If we are going to make any variable assignments, we need to let
1457 the ELF backend know about them in case the variables are
1458 referred to by dynamic objects. */
1459 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1461 /* Let the ELF backend work out the sizes of any sections required
1462 by dynamic linking. */
1463 rpath = command_line.rpath;
1465 rpath = (const char *) getenv ("LD_RUN_PATH");
1467 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
1469 const char *audit_libs = elf_dt_audit (abfd);
1471 /* If the input bfd contains an audit entry, we need to add it as
1472 a dep audit entry. */
1473 if (audit_libs && *audit_libs != '\0')
1475 char *cp = xstrdup (audit_libs);
1479 char *cp2 = strchr (cp, config.rpath_separator);
1487 if (cp != NULL && *cp != '\0')
1488 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1490 cp = more ? ++cp2 : NULL;
1496 if (! (bfd_elf_size_dynamic_sections
1497 (link_info.output_bfd, command_line.soname, rpath,
1498 command_line.filter_shlib, audit, depaudit,
1499 (const char * const *) command_line.auxiliary_filters,
1500 &link_info, &sinterp, lang_elf_version_info)))
1501 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1503 ${ELF_INTERPRETER_SET_DEFAULT}
1504 /* Let the user override the dynamic linker we are using. */
1505 if (command_line.interpreter != NULL
1508 sinterp->contents = (bfd_byte *) command_line.interpreter;
1509 sinterp->size = strlen (command_line.interpreter) + 1;
1512 /* Look for any sections named .gnu.warning. As a GNU extensions,
1513 we treat such sections as containing warning messages. We print
1514 out the warning message, and then zero out the section size so
1515 that it does not get copied into the output file. */
1518 LANG_FOR_EACH_INPUT_STATEMENT (is)
1525 if (is->just_syms_flag)
1528 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1533 msg = (char *) xmalloc ((size_t) (sz + 1));
1534 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1536 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1539 ret = link_info.callbacks->warning (&link_info, msg,
1540 (const char *) NULL,
1541 is->the_bfd, (asection *) NULL,
1546 /* Clobber the section size, so that we don't waste space
1547 copying the warning into the output file. If we've already
1548 sized the output section, adjust its size. The adjustment
1549 is on rawsize because targets that size sections early will
1550 have called lang_reset_memory_regions after sizing. */
1551 if (s->output_section != NULL
1552 && s->output_section->rawsize >= s->size)
1553 s->output_section->rawsize -= s->size;
1557 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1558 warning section don't get copied to the output. */
1559 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1563 before_allocation_default ();
1565 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1566 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1572 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1575 /* Try to open a dynamic archive. This is where we know that ELF
1576 dynamic libraries have an extension of .so (or .sl on oddball systems
1580 gld${EMULATION_NAME}_open_dynamic_archive
1581 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1583 const char *filename;
1586 if (! entry->is_archive)
1589 filename = entry->filename;
1591 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
1592 is defined, but it does not seem worth the headache to optimize
1593 away those two bytes of space. */
1594 string = (char *) xmalloc (strlen (search->name)
1597 #ifdef EXTRA_SHLIB_EXTENSION
1598 + strlen (EXTRA_SHLIB_EXTENSION)
1600 + sizeof "/lib.so");
1602 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1604 #ifdef EXTRA_SHLIB_EXTENSION
1605 /* Try the .so extension first. If that fails build a new filename
1606 using EXTRA_SHLIB_EXTENSION. */
1607 if (! ldfile_try_open_bfd (string, entry))
1609 sprintf (string, "%s/lib%s%s%s", search->name,
1610 filename, arch, EXTRA_SHLIB_EXTENSION);
1613 if (! ldfile_try_open_bfd (string, entry))
1618 #ifdef EXTRA_SHLIB_EXTENSION
1622 entry->filename = string;
1624 /* We have found a dynamic object to include in the link. The ELF
1625 backend linker will create a DT_NEEDED entry in the .dynamic
1626 section naming this file. If this file includes a DT_SONAME
1627 entry, it will be used. Otherwise, the ELF linker will just use
1628 the name of the file. For an archive found by searching, like
1629 this one, the DT_NEEDED entry should consist of just the name of
1630 the file, without the path information used to find it. Note
1631 that we only need to do this if we have a dynamic object; an
1632 archive will never be referenced by a DT_NEEDED entry.
1634 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1635 very pretty. I haven't been able to think of anything that is
1637 if (bfd_check_format (entry->the_bfd, bfd_object)
1638 && (entry->the_bfd->flags & DYNAMIC) != 0)
1640 ASSERT (entry->is_archive && entry->search_dirs_flag);
1642 /* Rather than duplicating the logic above. Just use the
1643 filename we recorded earlier. */
1645 filename = lbasename (entry->filename);
1646 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1655 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1658 /* A variant of lang_output_section_find used by place_orphan. */
1660 static lang_output_section_statement_type *
1661 output_rel_find (asection *sec, int isdyn)
1663 lang_output_section_statement_type *lookup;
1664 lang_output_section_statement_type *last = NULL;
1665 lang_output_section_statement_type *last_alloc = NULL;
1666 lang_output_section_statement_type *last_ro_alloc = NULL;
1667 lang_output_section_statement_type *last_rel = NULL;
1668 lang_output_section_statement_type *last_rel_alloc = NULL;
1669 int rela = sec->name[4] == 'a';
1671 for (lookup = &lang_output_section_statement.head->output_section_statement;
1673 lookup = lookup->next)
1675 if (lookup->constraint >= 0
1676 && CONST_STRNEQ (lookup->name, ".rel"))
1678 int lookrela = lookup->name[4] == 'a';
1680 /* .rel.dyn must come before all other reloc sections, to suit
1685 /* Don't place after .rel.plt as doing so results in wrong
1687 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1690 if (rela == lookrela || last_rel == NULL)
1692 if ((rela == lookrela || last_rel_alloc == NULL)
1693 && lookup->bfd_section != NULL
1694 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1695 last_rel_alloc = lookup;
1699 if (lookup->bfd_section != NULL
1700 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1702 last_alloc = lookup;
1703 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1704 last_ro_alloc = lookup;
1709 return last_rel_alloc;
1715 return last_ro_alloc;
1723 /* Place an orphan section. We use this to put random SHF_ALLOC
1724 sections in the right segment. */
1726 static lang_output_section_statement_type *
1727 gld${EMULATION_NAME}_place_orphan (asection *s,
1728 const char *secname,
1731 static struct orphan_save hold[] =
1734 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1737 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1740 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1746 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1749 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1752 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1758 enum orphan_save_index
1769 static int orphan_init_done = 0;
1770 struct orphan_save *place;
1771 lang_output_section_statement_type *after;
1772 lang_output_section_statement_type *os;
1774 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
1775 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
1777 if (! link_info.relocatable
1778 && link_info.combreloc
1779 && (s->flags & SEC_ALLOC))
1785 secname = ".rela.dyn";
1789 secname = ".rel.dyn";
1795 else if (CONST_STRNEQ (secname, ".rel"))
1797 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
1802 /* Look through the script to see where to place this section. */
1803 if (constraint == 0)
1804 for (os = lang_output_section_find (secname);
1806 os = next_matching_output_section_statement (os, 0))
1808 /* If we don't match an existing output section, tell
1809 lang_insert_orphan to create a new output section. */
1810 constraint = SPECIAL;
1812 if (os->bfd_section != NULL
1813 && (os->bfd_section->flags == 0
1814 || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
1817 && ((s->flags ^ os->bfd_section->flags)
1818 & (SEC_LOAD | SEC_ALLOC)) == 0)))
1820 /* We already have an output section statement with this
1821 name, and its bfd section has compatible flags.
1822 If the section already exists but does not have any flags
1823 set, then it has been created by the linker, probably as a
1824 result of a --section-start command line switch. */
1825 lang_add_section (&os->children, s, os);
1830 if (!orphan_init_done)
1832 lang_output_section_statement_type *lookup;
1833 struct orphan_save *ho;
1835 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1836 if (ho->name != NULL)
1838 ho->os = lang_output_section_find (ho->name);
1839 if (ho->os != NULL && ho->os->flags == 0)
1840 ho->os->flags = ho->flags;
1842 lookup = hold[orphan_bss].os;
1844 lookup = &lang_output_section_statement.head->output_section_statement;
1845 for (; lookup != NULL; lookup = lookup->next)
1846 if ((lookup->bfd_section != NULL
1847 && (lookup->bfd_section->flags & SEC_DEBUGGING) != 0)
1848 || strcmp (lookup->name, ".comment") == 0)
1850 hold[orphan_nonalloc].os = lookup ? lookup->prev : NULL;
1851 hold[orphan_nonalloc].name = ".comment";
1852 orphan_init_done = 1;
1855 /* If this is a final link, then always put .gnu.warning.SYMBOL
1856 sections into the .text section to get them out of the way. */
1857 if (link_info.executable
1858 && ! link_info.relocatable
1859 && CONST_STRNEQ (s->name, ".gnu.warning.")
1860 && hold[orphan_text].os != NULL)
1862 os = hold[orphan_text].os;
1863 lang_add_section (&os->children, s, os);
1867 /* Decide which segment the section should go in based on the
1868 section name and section flags. We put loadable .note sections
1869 right after the .interp section, so that the PT_NOTE segment is
1870 stored right after the program headers where the OS can read it
1871 in the first page. */
1874 if ((s->flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
1875 place = &hold[orphan_nonalloc];
1876 else if ((s->flags & SEC_ALLOC) == 0)
1878 else if ((s->flags & SEC_LOAD) != 0
1879 && ((iself && sh_type == SHT_NOTE)
1880 || (!iself && CONST_STRNEQ (secname, ".note"))))
1881 place = &hold[orphan_interp];
1882 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1883 place = &hold[orphan_bss];
1884 else if ((s->flags & SEC_SMALL_DATA) != 0)
1885 place = &hold[orphan_sdata];
1886 else if ((s->flags & SEC_READONLY) == 0)
1887 place = &hold[orphan_data];
1888 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
1889 || (!iself && CONST_STRNEQ (secname, ".rel")))
1890 && (s->flags & SEC_LOAD) != 0)
1891 place = &hold[orphan_rel];
1892 else if ((s->flags & SEC_CODE) == 0)
1893 place = &hold[orphan_rodata];
1895 place = &hold[orphan_text];
1900 if (place->os == NULL)
1902 if (place->name != NULL)
1903 place->os = lang_output_section_find (place->name);
1905 place->os = output_rel_find (s, isdyn);
1909 after = lang_output_section_find_by_flags
1910 (s, &place->os, _bfd_elf_match_sections_by_type);
1912 /* *ABS* is always the first output section statement. */
1913 after = &lang_output_section_statement.head->output_section_statement;
1916 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
1921 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
1925 gld${EMULATION_NAME}_after_allocation (void)
1927 bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
1929 gld${EMULATION_NAME}_map_segments (need_layout);
1934 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
1938 gld${EMULATION_NAME}_get_script (int *isfile)
1941 if test -n "$COMPILE_IN"
1943 # Scripts compiled in.
1945 # sed commands to quote an ld script as a C string.
1946 sc="-f stringify.sed"
1952 if (link_info.relocatable && config.build_constructors)
1955 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1956 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1957 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1958 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1959 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1960 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
1961 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1962 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1964 if test -n "$GENERATE_PIE_SCRIPT" ; then
1965 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1966 echo ' ; else if (link_info.pie && link_info.combreloc' >> e${EMULATION_NAME}.c
1967 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1968 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1969 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
1970 echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1971 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
1973 echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c
1974 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
1976 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1977 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1978 echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c
1979 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1980 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1981 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
1982 echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1983 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
1985 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1986 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1988 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1989 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
1990 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1991 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
1992 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
1993 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
1995 echo ' ; else return' >> e${EMULATION_NAME}.c
1996 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1997 echo '; }' >> e${EMULATION_NAME}.c
2000 # Scripts read from the filesystem.
2006 if (link_info.relocatable && config.build_constructors)
2007 return "ldscripts/${EMULATION_NAME}.xu";
2008 else if (link_info.relocatable)
2009 return "ldscripts/${EMULATION_NAME}.xr";
2010 else if (!config.text_read_only)
2011 return "ldscripts/${EMULATION_NAME}.xbn";
2013 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2016 else if (!config.magic_demand_paged)
2017 return "ldscripts/${EMULATION_NAME}.xn";
2020 if test -n "$GENERATE_PIE_SCRIPT" ; then
2021 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2023 else if (link_info.pie && link_info.combreloc
2024 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2025 return "ldscripts/${EMULATION_NAME}.xdw";
2026 else if (link_info.pie && link_info.combreloc)
2027 return "ldscripts/${EMULATION_NAME}.xdc";
2031 else if (link_info.pie)
2032 return "ldscripts/${EMULATION_NAME}.xd";
2035 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2036 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2038 else if (link_info.shared && link_info.combreloc
2039 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2040 return "ldscripts/${EMULATION_NAME}.xsw";
2041 else if (link_info.shared && link_info.combreloc)
2042 return "ldscripts/${EMULATION_NAME}.xsc";
2046 else if (link_info.shared)
2047 return "ldscripts/${EMULATION_NAME}.xs";
2050 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2052 else if (link_info.combreloc && link_info.relro
2053 && (link_info.flags & DF_BIND_NOW))
2054 return "ldscripts/${EMULATION_NAME}.xw";
2055 else if (link_info.combreloc)
2056 return "ldscripts/${EMULATION_NAME}.xc";
2061 return "ldscripts/${EMULATION_NAME}.x";
2068 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2070 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2072 $PARSE_AND_LIST_PROLOGUE
2078 #define OPTION_DISABLE_NEW_DTAGS (400)
2079 #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
2080 #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
2081 #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
2082 #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
2083 #define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
2084 #define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
2085 #define OPTION_AUDIT (OPTION_BUILD_ID + 1)
2088 gld${EMULATION_NAME}_add_options
2089 (int ns, char **shortopts, int nl, struct option **longopts,
2090 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2092 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2093 static const struct option xtra_long[] = {
2094 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2095 {"audit", required_argument, NULL, OPTION_AUDIT},
2096 {"depaudit", required_argument, NULL, 'P'},
2099 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2101 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2102 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2103 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2104 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2105 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2106 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2110 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2112 $PARSE_AND_LIST_LONGOPTS
2117 {NULL, no_argument, NULL, 0}
2120 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2121 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2122 *longopts = (struct option *)
2123 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2124 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2127 #define DEFAULT_BUILD_ID_STYLE "sha1"
2130 gld${EMULATION_NAME}_handle_option (int optc)
2137 case OPTION_BUILD_ID:
2138 if (link_info.emit_note_gnu_build_id != NULL)
2140 free (link_info.emit_note_gnu_build_id);
2141 link_info.emit_note_gnu_build_id = NULL;
2144 optarg = DEFAULT_BUILD_ID_STYLE;
2145 if (strcmp (optarg, "none"))
2146 link_info.emit_note_gnu_build_id = xstrdup (optarg);
2149 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2152 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2157 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2159 case OPTION_DISABLE_NEW_DTAGS:
2160 link_info.new_dtags = FALSE;
2163 case OPTION_ENABLE_NEW_DTAGS:
2164 link_info.new_dtags = TRUE;
2167 case OPTION_EH_FRAME_HDR:
2168 link_info.eh_frame_hdr = TRUE;
2172 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2173 /* Groups must be self-contained. */
2174 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2175 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2178 case OPTION_EXCLUDE_LIBS:
2179 add_excluded_libs (optarg);
2182 case OPTION_HASH_STYLE:
2183 link_info.emit_hash = FALSE;
2184 link_info.emit_gnu_hash = FALSE;
2185 if (strcmp (optarg, "sysv") == 0)
2186 link_info.emit_hash = TRUE;
2187 else if (strcmp (optarg, "gnu") == 0)
2188 link_info.emit_gnu_hash = TRUE;
2189 else if (strcmp (optarg, "both") == 0)
2191 link_info.emit_hash = TRUE;
2192 link_info.emit_gnu_hash = TRUE;
2195 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2199 if (strcmp (optarg, "initfirst") == 0)
2200 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2201 else if (strcmp (optarg, "interpose") == 0)
2202 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2203 else if (strcmp (optarg, "loadfltr") == 0)
2204 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2205 else if (strcmp (optarg, "nodefaultlib") == 0)
2206 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2207 else if (strcmp (optarg, "nodelete") == 0)
2208 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2209 else if (strcmp (optarg, "nodlopen") == 0)
2210 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2211 else if (strcmp (optarg, "nodump") == 0)
2212 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2213 else if (strcmp (optarg, "now") == 0)
2215 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2216 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2218 else if (strcmp (optarg, "lazy") == 0)
2220 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2221 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2223 else if (strcmp (optarg, "origin") == 0)
2225 link_info.flags |= (bfd_vma) DF_ORIGIN;
2226 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2228 else if (strcmp (optarg, "defs") == 0)
2229 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2230 else if (strcmp (optarg, "muldefs") == 0)
2231 link_info.allow_multiple_definition = TRUE;
2232 else if (strcmp (optarg, "combreloc") == 0)
2233 link_info.combreloc = TRUE;
2234 else if (strcmp (optarg, "nocombreloc") == 0)
2235 link_info.combreloc = FALSE;
2236 else if (strcmp (optarg, "nocopyreloc") == 0)
2237 link_info.nocopyreloc = TRUE;
2238 else if (strcmp (optarg, "execstack") == 0)
2240 link_info.execstack = TRUE;
2241 link_info.noexecstack = FALSE;
2243 else if (strcmp (optarg, "noexecstack") == 0)
2245 link_info.noexecstack = TRUE;
2246 link_info.execstack = FALSE;
2250 if test -n "$COMMONPAGESIZE"; then
2252 else if (strcmp (optarg, "relro") == 0)
2253 link_info.relro = TRUE;
2254 else if (strcmp (optarg, "norelro") == 0)
2255 link_info.relro = FALSE;
2260 else if (CONST_STRNEQ (optarg, "max-page-size="))
2264 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2265 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2266 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2269 else if (CONST_STRNEQ (optarg, "common-page-size="))
2272 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2274 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2275 einfo (_("%P%F: invalid common page size \`%s'\n"),
2278 /* What about the other Solaris -z options? FIXME. */
2283 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2285 $PARSE_AND_LIST_ARGS_CASES
2297 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2301 gld${EMULATION_NAME}_list_options (FILE * file)
2304 --build-id[=STYLE] Generate build ID note\n"));
2306 --audit=AUDITLIB Specify a library to use for auditing\n"));
2308 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
2309 Specify a library to use for auditing dependencies\n"));
2312 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2315 -Bgroup Selects group name lookup rules for DSO\n"));
2317 --disable-new-dtags Disable new dynamic tags\n"));
2319 --enable-new-dtags Enable new dynamic tags\n"));
2321 --eh-frame-hdr Create .eh_frame_hdr section\n"));
2323 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
2325 -z combreloc Merge dynamic relocs into one section and sort\n"));
2327 -z defs Report unresolved symbols in object files.\n"));
2329 -z execstack Mark executable as requiring executable stack\n"));
2331 -z initfirst Mark DSO to be initialized first at runtime\n"));
2333 -z interpose Mark object to interpose all DSOs but executable\n"));
2335 -z lazy Mark object lazy runtime binding (default)\n"));
2337 -z loadfltr Mark object requiring immediate process\n"));
2339 -z muldefs Allow multiple definitions\n"));
2341 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2343 -z nocopyreloc Don't create copy relocs\n"));
2345 -z nodefaultlib Mark object not to use default search paths\n"));
2347 -z nodelete Mark DSO non-deletable at runtime\n"));
2349 -z nodlopen Mark DSO not available to dlopen\n"));
2351 -z nodump Mark DSO not available to dldump\n"));
2353 -z noexecstack Mark executable as not requiring executable stack\n"));
2356 if test -n "$COMMONPAGESIZE"; then
2359 -z norelro Don't create RELRO program header\n"));
2365 -z now Mark object non-lazy runtime binding\n"));
2367 -z origin Mark object requiring immediate \$ORIGIN\n\
2368 processing at runtime\n"));
2371 if test -n "$COMMONPAGESIZE"; then
2374 -z relro Create RELRO program header\n"));
2380 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2382 -z common-page-size=SIZE Set common page size to SIZE\n"));
2384 -z KEYWORD Ignored for Solaris compatibility\n"));
2388 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2390 $PARSE_AND_LIST_OPTIONS
2398 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2400 $PARSE_AND_LIST_EPILOGUE
2406 #define gld${EMULATION_NAME}_add_options NULL
2407 #define gld${EMULATION_NAME}_handle_option NULL
2409 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2411 #define gld${EMULATION_NAME}_list_options NULL
2418 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2420 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2421 ${LDEMUL_SYSLIB-syslib_default},
2422 ${LDEMUL_HLL-hll_default},
2423 ${LDEMUL_AFTER_PARSE-after_parse_default},
2424 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2425 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2426 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2427 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2428 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2429 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2430 "${EMULATION_NAME}",
2432 ${LDEMUL_FINISH-finish_default},
2433 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2434 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2435 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2436 ${LDEMUL_SET_SYMBOLS-NULL},
2437 ${LDEMUL_PARSE_ARGS-NULL},
2438 gld${EMULATION_NAME}_add_options,
2439 gld${EMULATION_NAME}_handle_option,
2440 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2441 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
2442 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2443 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2444 ${LDEMUL_NEW_VERS_PATTERN-NULL}