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;
161 /* On Linux, it's possible to have different versions of the same
162 shared library linked against different versions of libc. The
163 dynamic linker somehow tags which libc version to use in
164 /etc/ld.so.cache, and, based on the libc that it sees in the
165 executable, chooses which version of the shared library to use.
167 We try to do a similar check here by checking whether this shared
168 library needs any other shared libraries which may conflict with
169 libraries we have already included in the link. If it does, we
170 skip it, and try to find another shared library farther on down the
173 This is called via lang_for_each_input_file.
174 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
175 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
176 a conflicting version. */
179 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
182 struct bfd_link_needed_list *l;
184 if (global_vercheck_failed)
186 if (s->the_bfd == NULL
187 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
190 soname = bfd_elf_get_dt_soname (s->the_bfd);
192 soname = lbasename (bfd_get_filename (s->the_bfd));
194 for (l = global_vercheck_needed; l != NULL; l = l->next)
198 if (strcmp (soname, l->name) == 0)
200 /* Probably can't happen, but it's an easy check. */
204 if (strchr (l->name, '/') != NULL)
207 suffix = strstr (l->name, ".so.");
211 suffix += sizeof ".so." - 1;
213 if (strncmp (soname, l->name, suffix - l->name) == 0)
215 /* Here we know that S is a dynamic object FOO.SO.VER1, and
216 the object we are considering needs a dynamic object
217 FOO.SO.VER2, and VER1 and VER2 are different. This
218 appears to be a version mismatch, so we tell the caller
219 to try a different version of this library. */
220 global_vercheck_failed = TRUE;
227 /* See if an input file matches a DT_NEEDED entry by running stat on
231 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
237 if (global_found != NULL)
239 if (s->the_bfd == NULL)
242 /* If this input file was an as-needed entry, and wasn't found to be
243 needed at the stage it was linked, then don't say we have loaded it. */
244 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
247 if (bfd_stat (s->the_bfd, &st) != 0)
249 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
253 /* Some operating systems, e.g. Windows, do not provide a meaningful
254 st_ino; they always set it to zero. (Windows does provide a
255 meaningful st_dev.) Do not indicate a duplicate library in that
256 case. While there is no guarantee that a system that provides
257 meaningful inode numbers will never set st_ino to zero, this is
258 merely an optimization, so we do not need to worry about false
260 if (st.st_dev == global_stat.st_dev
261 && st.st_ino == global_stat.st_ino
268 /* We issue a warning if it looks like we are including two
269 different versions of the same shared library. For example,
270 there may be a problem if -lc picks up libc.so.6 but some other
271 shared library has a DT_NEEDED entry of libc.so.5. This is a
272 heuristic test, and it will only work if the name looks like
273 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
274 If we really want to issue warnings about mixing version numbers
275 of shared libraries, we need to find a better way. */
277 if (strchr (global_needed->name, '/') != NULL)
279 suffix = strstr (global_needed->name, ".so.");
282 suffix += sizeof ".so." - 1;
284 soname = bfd_elf_get_dt_soname (s->the_bfd);
286 soname = lbasename (s->filename);
288 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
289 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
290 global_needed->name, global_needed->by, soname);
299 /* This function is called for each possible name for a dynamic object
300 named by a DT_NEEDED entry. The FORCE parameter indicates whether
301 to skip the check for a conflicting version. */
304 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
308 const char *name = needed->name;
312 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
315 if (! bfd_check_format (abfd, bfd_object))
320 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
326 /* For DT_NEEDED, they have to match. */
327 if (abfd->xvec != link_info.output_bfd->xvec)
333 /* Check whether this object would include any conflicting library
334 versions. If FORCE is set, then we skip this check; we use this
335 the second time around, if we couldn't find any compatible
336 instance of the shared library. */
340 struct bfd_link_needed_list *needed;
342 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
343 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
347 global_vercheck_needed = needed;
348 global_vercheck_failed = FALSE;
349 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
350 if (global_vercheck_failed)
353 /* Return FALSE to force the caller to move on to try
354 another file on the search path. */
358 /* But wait! It gets much worse. On Linux, if a shared
359 library does not use libc at all, we are supposed to skip
360 it the first time around in case we encounter a shared
361 library later on with the same name which does use the
362 version of libc that we want. This is much too horrible
363 to use on any system other than Linux. */
367 *-*-linux-* | *-*-k*bsd*-*)
370 struct bfd_link_needed_list *l;
372 for (l = needed; l != NULL; l = l->next)
373 if (CONST_STRNEQ (l->name, "libc.so"))
389 /* We've found a dynamic object matching the DT_NEEDED entry. */
391 /* We have already checked that there is no other input file of the
392 same name. We must now check again that we are not including the
393 same file twice. We need to do this because on many systems
394 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
395 reference libc.so.1. If we have already included libc.so, we
396 don't want to include libc.so.1 if they are the same file, and we
397 can only check that using stat. */
399 if (bfd_stat (abfd, &global_stat) != 0)
400 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
402 /* First strip off everything before the last '/'. */
403 soname = lbasename (abfd->filename);
405 if (trace_file_tries)
406 info_msg (_("found %s at %s\n"), soname, name);
409 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
410 if (global_found != NULL)
412 /* Return TRUE to indicate that we found the file, even though
413 we aren't going to do anything with it. */
417 /* Specify the soname to use. */
418 bfd_elf_set_dt_needed_name (abfd, soname);
420 /* Tell the ELF linker that we don't want the output file to have a
421 DT_NEEDED entry for this file, unless it is used to resolve
422 references in a regular object. */
423 link_class = DYN_DT_NEEDED;
425 /* Tell the ELF linker that we don't want the output file to have a
426 DT_NEEDED entry for this file at all if the entry is from a file
427 with DYN_NO_ADD_NEEDED. */
428 if (needed->by != NULL
429 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
430 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
432 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
434 /* Add this file into the symbol table. */
435 if (! bfd_link_add_symbols (abfd, &link_info))
436 einfo ("%F%B: could not read symbols: %E\n", abfd);
442 /* Search for a needed file in a path. */
445 gld${EMULATION_NAME}_search_needed (const char *path,
446 struct dt_needed *n, int force)
449 const char *name = n->name;
451 struct dt_needed needed;
454 return gld${EMULATION_NAME}_try_needed (n, force);
456 if (path == NULL || *path == '\0')
460 needed.name = n->name;
465 char *filename, *sset;
467 s = strchr (path, config.rpath_separator);
469 s = path + strlen (path);
471 filename = (char *) xmalloc (s - path + len + 2);
476 memcpy (filename, path, s - path);
477 filename[s - path] = '/';
478 sset = filename + (s - path) + 1;
482 needed.name = filename;
483 if (gld${EMULATION_NAME}_try_needed (&needed, force))
497 if [ "x${USE_LIBPATH}" = xyes ] ; then
500 /* Add the sysroot to every entry in a path separated by
501 config.rpath_separator. */
504 gld${EMULATION_NAME}_add_sysroot (const char *path)
513 if (path[i++] == config.rpath_separator)
519 len = len + (colons + 1) * strlen (ld_sysroot);
520 ret = xmalloc (len + 1);
521 strcpy (ret, ld_sysroot);
522 p = ret + strlen (ret);
525 if (path[i] == config.rpath_separator)
528 strcpy (p, ld_sysroot);
540 *-*-freebsd* | *-*-dragonfly*)
542 /* Read the system search path the FreeBSD way rather than the Linux way. */
543 #ifdef HAVE_ELF_HINTS_H
544 #include <elf-hints.h>
546 #include "elf-hints-local.h"
550 gld${EMULATION_NAME}_check_ld_elf_hints (const char *name, int force)
552 static bfd_boolean initialized;
553 static char *ld_elf_hints;
554 struct dt_needed needed;
561 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
562 f = fopen (tmppath, FOPEN_RB);
566 struct elfhints_hdr hdr;
568 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
569 && hdr.magic == ELFHINTS_MAGIC
572 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
576 b = xmalloc (hdr.dirlistlen + 1);
577 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
579 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
590 if (ld_elf_hints == NULL)
595 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, & needed,
602 *-*-linux-* | *-*-k*bsd*-*)
604 /* For a native linker, check the file /etc/ld.so.conf for directories
605 in which we may find shared libraries. /etc/ld.so.conf is really
606 only meaningful on Linux. */
608 struct gld${EMULATION_NAME}_ld_so_conf
615 gld${EMULATION_NAME}_parse_ld_so_conf
616 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
619 gld${EMULATION_NAME}_parse_ld_so_conf_include
620 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
628 if (pattern[0] != '/')
630 char *p = strrchr (filename, '/');
631 size_t patlen = strlen (pattern) + 1;
633 newp = xmalloc (p - filename + 1 + patlen);
634 memcpy (newp, filename, p - filename + 1);
635 memcpy (newp + (p - filename + 1), pattern, patlen);
640 if (glob (pattern, 0, NULL, &gl) == 0)
644 for (i = 0; i < gl.gl_pathc; ++i)
645 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
649 /* If we do not have glob, treat the pattern as a literal filename. */
650 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
658 gld${EMULATION_NAME}_parse_ld_so_conf
659 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
661 FILE *f = fopen (filename, FOPEN_RT);
669 line = xmalloc (linelen);
674 /* Normally this would use getline(3), but we need to be portable. */
675 while ((q = fgets (p, linelen - (p - line), f)) != NULL
676 && strlen (q) == linelen - (p - line) - 1
677 && line[linelen - 2] != '\n')
679 line = xrealloc (line, 2 * linelen);
680 p = line + linelen - 1;
684 if (q == NULL && p == line)
687 p = strchr (line, '\n');
691 /* Because the file format does not know any form of quoting we
692 can search forward for the next '#' character and if found
693 make it terminating the line. */
694 p = strchr (line, '#');
698 /* Remove leading whitespace. NUL is no whitespace character. */
700 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
703 /* If the line is blank it is ignored. */
707 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
713 while (*p == ' ' || *p == '\t')
721 while (*p != ' ' && *p != '\t' && *p)
727 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
735 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
736 && *p != '\r' && *p != '\v')
739 while (p != dir && p[-1] == '/')
741 if (info->path == NULL)
743 info->alloc = p - dir + 1 + 256;
744 info->path = xmalloc (info->alloc);
749 if (info->len + 1 + (p - dir) >= info->alloc)
751 info->alloc += p - dir + 256;
752 info->path = xrealloc (info->path, info->alloc);
754 info->path[info->len++] = config.rpath_separator;
756 memcpy (info->path + info->len, dir, p - dir);
757 info->len += p - dir;
758 info->path[info->len] = '\0';
768 gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force)
770 static bfd_boolean initialized;
771 static char *ld_so_conf;
772 struct dt_needed needed;
777 struct gld${EMULATION_NAME}_ld_so_conf info;
780 info.len = info.alloc = 0;
781 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
782 (const char *) NULL);
783 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
786 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
787 (const char *) NULL);
788 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
794 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
801 if (ld_so_conf == NULL)
807 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
817 /* See if an input file matches a DT_NEEDED entry by name. */
820 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
824 /* Stop looking if we've found a loaded lib. */
825 if (global_found != NULL
826 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
827 & DYN_AS_NEEDED) == 0)
830 if (s->filename == NULL || s->the_bfd == NULL)
833 /* Don't look for a second non-loaded as-needed lib. */
834 if (global_found != NULL
835 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
838 if (strcmp (s->filename, global_needed->name) == 0)
844 if (s->search_dirs_flag)
846 const char *f = strrchr (s->filename, '/');
848 && strcmp (f + 1, global_needed->name) == 0)
855 soname = bfd_elf_get_dt_soname (s->the_bfd);
857 && strcmp (soname, global_needed->name) == 0)
866 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
870 gld${EMULATION_NAME}_id_note_section_size (bfd *abfd,
871 struct bfd_link_info *link_info)
873 const char *style = link_info->emit_note_gnu_build_id;
878 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
879 size = (size + 3) & -(bfd_size_type) 4;
881 if (!strcmp (style, "md5") || !strcmp (style, "uuid"))
883 else if (!strcmp (style, "sha1"))
885 else if (!strncmp (style, "0x", 2))
887 /* ID is in string form (hex). Convert to bits. */
888 const char *id = style + 2;
891 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
896 else if (*id == '-' || *id == ':')
903 } while (*id != '\0');
912 read_hex (const char xdigit)
914 if (ISDIGIT (xdigit))
916 if (ISUPPER (xdigit))
917 return xdigit - 'A' + 0xa;
918 if (ISLOWER (xdigit))
919 return xdigit - 'a' + 0xa;
931 gld${EMULATION_NAME}_write_build_id_section (bfd *abfd)
933 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
934 struct build_id_info *info = (struct build_id_info *)
935 elf_tdata (abfd)->after_write_object_contents_info;
937 Elf_Internal_Shdr *i_shdr;
938 unsigned char *contents, *id_bits;
940 Elf_External_Note *e_note;
943 if (bfd_is_abs_section (asec->output_section))
945 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
946 " --build-id ignored.\n"));
949 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
951 if (i_shdr->contents == NULL)
953 if (asec->contents == NULL)
954 asec->contents = (unsigned char *) xmalloc (asec->size);
955 contents = asec->contents;
958 contents = i_shdr->contents + asec->output_offset;
960 e_note = (Elf_External_Note *) contents;
961 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
962 size = (size + 3) & -(bfd_size_type) 4;
963 id_bits = contents + size;
964 size = asec->size - size;
966 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
967 bfd_h_put_32 (abfd, size, &e_note->descsz);
968 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
969 memcpy (e_note->name, "GNU", sizeof "GNU");
971 if (!strcmp (info->style, "md5"))
975 if (bed->s->checksum_contents (abfd,
976 (void (*) (const void *, size_t, void *))
979 md5_finish_ctx (&ctx, id_bits);
983 else if (!strcmp (info->style, "sha1"))
986 sha1_init_ctx (&ctx);
987 if (bed->s->checksum_contents (abfd,
988 (void (*) (const void *, size_t, void *))
991 sha1_finish_ctx (&ctx, id_bits);
995 else if (!strcmp (info->style, "uuid"))
998 int fd = open ("/dev/urandom", O_RDONLY);
1001 n = read (fd, id_bits, size);
1006 else if (!strncmp (info->style, "0x", 2))
1008 /* ID is in string form (hex). Convert to bits. */
1009 const char *id = info->style + 2;
1013 if (ISXDIGIT (id[0]) && ISXDIGIT (id[1]))
1015 id_bits[n] = read_hex (*id++) << 4;
1016 id_bits[n++] |= read_hex (*id++);
1018 else if (*id == '-' || *id == ':')
1021 abort (); /* Should have been validated earlier. */
1022 } while (*id != '\0');
1025 abort (); /* Should have been validated earlier. */
1028 return (bfd_seek (abfd,
1029 i_shdr->sh_offset + asec->output_offset, SEEK_SET) == 0
1030 && bfd_bwrite (contents, size, abfd) == size);
1034 /* This is called after all the input files have been opened. */
1037 gld${EMULATION_NAME}_after_open (void)
1039 struct bfd_link_needed_list *needed, *l;
1040 struct elf_link_hash_table *htab;
1042 htab = elf_hash_table (&link_info);
1043 if (!is_elf_hash_table (htab))
1046 if (link_info.emit_note_gnu_build_id)
1052 abfd = link_info.input_bfds;
1056 /* PR 10555: If there are no input files do not
1057 try to create a .note.gnu-build-id section. */
1058 free (link_info.emit_note_gnu_build_id);
1059 link_info.emit_note_gnu_build_id = NULL;
1063 size = gld${EMULATION_NAME}_id_note_section_size (abfd, &link_info);
1066 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1067 free (link_info.emit_note_gnu_build_id);
1068 link_info.emit_note_gnu_build_id = NULL;
1072 s = bfd_make_section_with_flags (abfd, ".note.gnu.build-id",
1073 SEC_ALLOC | SEC_LOAD
1074 | SEC_IN_MEMORY | SEC_LINKER_CREATED
1075 | SEC_READONLY | SEC_DATA);
1076 if (s != NULL && bfd_set_section_alignment (abfd, s, 2))
1078 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1079 struct build_id_info *b =
1080 (struct build_id_info *) xmalloc (sizeof *b);
1082 b->style = link_info.emit_note_gnu_build_id;
1084 elf_section_type (s) = SHT_NOTE;
1086 t->after_write_object_contents
1087 = &gld${EMULATION_NAME}_write_build_id_section;
1088 t->after_write_object_contents_info = b;
1092 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1093 " --build-id ignored.\n");
1094 free (link_info.emit_note_gnu_build_id);
1095 link_info.emit_note_gnu_build_id = NULL;
1101 if (link_info.relocatable)
1104 if (link_info.eh_frame_hdr
1105 && !link_info.traditional_format)
1110 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link_next)
1112 s = bfd_get_section_by_name (abfd, ".eh_frame");
1113 if (s && s->size > 8 && !bfd_is_abs_section (s->output_section))
1118 const struct elf_backend_data *bed;
1120 bed = get_elf_backend_data (abfd);
1121 s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
1122 bed->dynamic_sec_flags
1125 && bfd_set_section_alignment (abfd, s, 2))
1126 htab->eh_info.hdr_sec = s;
1128 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1129 " --eh-frame-hdr ignored.\n");
1133 /* Get the list of files which appear in DT_NEEDED entries in
1134 dynamic objects included in the link (often there will be none).
1135 For each such file, we want to track down the corresponding
1136 library, and include the symbol table in the link. This is what
1137 the runtime dynamic linker will do. Tracking the files down here
1138 permits one dynamic object to include another without requiring
1139 special action by the person doing the link. Note that the
1140 needed list can actually grow while we are stepping through this
1142 if (!link_info.executable)
1144 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1145 for (l = needed; l != NULL; l = l->next)
1147 struct bfd_link_needed_list *ll;
1148 struct dt_needed n, nn;
1151 /* If the lib that needs this one was --as-needed and wasn't
1152 found to be needed, then this lib isn't needed either. */
1154 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1157 /* If we've already seen this file, skip it. */
1158 for (ll = needed; ll != l; ll = ll->next)
1160 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1161 && strcmp (ll->name, l->name) == 0)
1166 /* See if this file was included in the link explicitly. */
1168 global_found = NULL;
1169 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1170 if (global_found != NULL
1171 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1172 & DYN_AS_NEEDED) == 0)
1178 if (trace_file_tries)
1179 info_msg (_("%s needed by %B\n"), l->name, l->by);
1181 /* As-needed libs specified on the command line (or linker script)
1182 take priority over libs found in search dirs. */
1183 if (global_found != NULL)
1185 nn.name = global_found->filename;
1186 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1190 /* We need to find this file and include the symbol table. We
1191 want to search for the file in the same way that the dynamic
1192 linker will search. That means that we want to use
1193 rpath_link, rpath, then the environment variable
1194 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1195 entries (native only), then the linker script LIB_SEARCH_DIRS.
1196 We do not search using the -L arguments.
1198 We search twice. The first time, we skip objects which may
1199 introduce version mismatches. The second time, we force
1200 their use. See gld${EMULATION_NAME}_vercheck comment. */
1201 for (force = 0; force < 2; force++)
1204 search_dirs_type *search;
1206 if [ "x${NATIVE}" = xyes ] ; then
1208 const char *lib_path;
1211 if [ "x${USE_LIBPATH}" = xyes ] ; then
1213 struct bfd_link_needed_list *rp;
1219 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1223 if [ "x${USE_LIBPATH}" = xyes ] ; then
1225 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
1230 if [ "x${NATIVE}" = xyes ] ; then
1232 if (command_line.rpath_link == NULL
1233 && command_line.rpath == NULL)
1235 lib_path = (const char *) getenv ("LD_RUN_PATH");
1236 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
1240 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
1241 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
1245 if [ "x${USE_LIBPATH}" = xyes ] ; then
1248 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1249 for (; !found && rp != NULL; rp = rp->next)
1251 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
1252 found = (rp->by == l->by
1253 && gld${EMULATION_NAME}_search_needed (tmpname,
1263 if [ "x${USE_LIBPATH}" = xyes ] ; then
1265 *-*-freebsd* | *-*-dragonfly*)
1267 if (gld${EMULATION_NAME}_check_ld_elf_hints (l->name, force))
1273 *-*-linux-* | *-*-k*bsd*-*)
1276 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
1284 len = strlen (l->name);
1285 for (search = search_head; search != NULL; search = search->next)
1289 if (search->cmdline)
1291 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1292 sprintf (filename, "%s/%s", search->name, l->name);
1294 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1307 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1317 /* Look through an expression for an assignment statement. */
1320 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1322 bfd_boolean provide = FALSE;
1324 switch (exp->type.node_class)
1330 /* We call record_link_assignment even if the symbol is defined.
1331 This is because if it is defined by a dynamic object, we
1332 actually want to use the value defined by the linker script,
1333 not the value from the dynamic object (because we are setting
1334 symbols like etext). If the symbol is defined by a regular
1335 object, then, as it happens, calling record_link_assignment
1337 if (strcmp (exp->assign.dst, ".") != 0)
1339 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1341 exp->assign.dst, provide,
1342 exp->assign.hidden))
1343 einfo ("%P%F: failed to record assignment to %s: %E\n",
1346 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1350 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1351 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1355 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1356 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1357 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1361 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1370 /* This is called by the before_allocation routine via
1371 lang_for_each_statement. It locates any assignment statements, and
1372 tells the ELF backend about them, in case they are assignments to
1373 symbols which are referred to by dynamic objects. */
1376 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1378 if (s->header.type == lang_assignment_statement_enum)
1379 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1384 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1385 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1386 ELF_INTERPRETER_SET_DEFAULT="
1387 if (sinterp != NULL)
1389 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1390 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1395 ELF_INTERPRETER_SET_DEFAULT=
1399 /* This is called after the sections have been attached to output
1400 sections, but before any sizes or addresses have been set. */
1403 gld${EMULATION_NAME}_before_allocation (void)
1408 if (link_info.hash->type == bfd_link_elf_hash_table)
1409 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1411 /* If we are going to make any variable assignments, we need to let
1412 the ELF backend know about them in case the variables are
1413 referred to by dynamic objects. */
1414 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1416 /* Let the ELF backend work out the sizes of any sections required
1417 by dynamic linking. */
1418 rpath = command_line.rpath;
1420 rpath = (const char *) getenv ("LD_RUN_PATH");
1421 if (! (bfd_elf_size_dynamic_sections
1422 (link_info.output_bfd, command_line.soname, rpath,
1423 command_line.filter_shlib,
1424 (const char * const *) command_line.auxiliary_filters,
1425 &link_info, &sinterp, lang_elf_version_info)))
1426 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1428 ${ELF_INTERPRETER_SET_DEFAULT}
1429 /* Let the user override the dynamic linker we are using. */
1430 if (command_line.interpreter != NULL
1433 sinterp->contents = (bfd_byte *) command_line.interpreter;
1434 sinterp->size = strlen (command_line.interpreter) + 1;
1437 /* Look for any sections named .gnu.warning. As a GNU extensions,
1438 we treat such sections as containing warning messages. We print
1439 out the warning message, and then zero out the section size so
1440 that it does not get copied into the output file. */
1443 LANG_FOR_EACH_INPUT_STATEMENT (is)
1450 if (is->just_syms_flag)
1453 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1458 msg = (char *) xmalloc ((size_t) (sz + 1));
1459 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1461 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1464 ret = link_info.callbacks->warning (&link_info, msg,
1465 (const char *) NULL,
1466 is->the_bfd, (asection *) NULL,
1471 /* Clobber the section size, so that we don't waste space
1472 copying the warning into the output file. If we've already
1473 sized the output section, adjust its size. The adjustment
1474 is on rawsize because targets that size sections early will
1475 have called lang_reset_memory_regions after sizing. */
1476 if (s->output_section != NULL
1477 && s->output_section->rawsize >= s->size)
1478 s->output_section->rawsize -= s->size;
1482 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1483 warning section don't get copied to the output. */
1484 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1488 before_allocation_default ();
1490 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1491 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1497 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1500 /* Try to open a dynamic archive. This is where we know that ELF
1501 dynamic libraries have an extension of .so (or .sl on oddball systems
1505 gld${EMULATION_NAME}_open_dynamic_archive
1506 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1508 const char *filename;
1511 if (! entry->is_archive)
1514 filename = entry->filename;
1516 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
1517 is defined, but it does not seem worth the headache to optimize
1518 away those two bytes of space. */
1519 string = (char *) xmalloc (strlen (search->name)
1522 #ifdef EXTRA_SHLIB_EXTENSION
1523 + strlen (EXTRA_SHLIB_EXTENSION)
1525 + sizeof "/lib.so");
1527 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1529 #ifdef EXTRA_SHLIB_EXTENSION
1530 /* Try the .so extension first. If that fails build a new filename
1531 using EXTRA_SHLIB_EXTENSION. */
1532 if (! ldfile_try_open_bfd (string, entry))
1534 sprintf (string, "%s/lib%s%s%s", search->name,
1535 filename, arch, EXTRA_SHLIB_EXTENSION);
1538 if (! ldfile_try_open_bfd (string, entry))
1543 #ifdef EXTRA_SHLIB_EXTENSION
1547 entry->filename = string;
1549 /* We have found a dynamic object to include in the link. The ELF
1550 backend linker will create a DT_NEEDED entry in the .dynamic
1551 section naming this file. If this file includes a DT_SONAME
1552 entry, it will be used. Otherwise, the ELF linker will just use
1553 the name of the file. For an archive found by searching, like
1554 this one, the DT_NEEDED entry should consist of just the name of
1555 the file, without the path information used to find it. Note
1556 that we only need to do this if we have a dynamic object; an
1557 archive will never be referenced by a DT_NEEDED entry.
1559 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1560 very pretty. I haven't been able to think of anything that is
1562 if (bfd_check_format (entry->the_bfd, bfd_object)
1563 && (entry->the_bfd->flags & DYNAMIC) != 0)
1565 ASSERT (entry->is_archive && entry->search_dirs_flag);
1567 /* Rather than duplicating the logic above. Just use the
1568 filename we recorded earlier. */
1570 filename = lbasename (entry->filename);
1571 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1580 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1583 /* A variant of lang_output_section_find used by place_orphan. */
1585 static lang_output_section_statement_type *
1586 output_rel_find (asection *sec, int isdyn)
1588 lang_output_section_statement_type *lookup;
1589 lang_output_section_statement_type *last = NULL;
1590 lang_output_section_statement_type *last_alloc = NULL;
1591 lang_output_section_statement_type *last_ro_alloc = NULL;
1592 lang_output_section_statement_type *last_rel = NULL;
1593 lang_output_section_statement_type *last_rel_alloc = NULL;
1594 int rela = sec->name[4] == 'a';
1596 for (lookup = &lang_output_section_statement.head->output_section_statement;
1598 lookup = lookup->next)
1600 if (lookup->constraint >= 0
1601 && CONST_STRNEQ (lookup->name, ".rel"))
1603 int lookrela = lookup->name[4] == 'a';
1605 /* .rel.dyn must come before all other reloc sections, to suit
1610 /* Don't place after .rel.plt as doing so results in wrong
1612 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1615 if (rela == lookrela || last_rel == NULL)
1617 if ((rela == lookrela || last_rel_alloc == NULL)
1618 && lookup->bfd_section != NULL
1619 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1620 last_rel_alloc = lookup;
1624 if (lookup->bfd_section != NULL
1625 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1627 last_alloc = lookup;
1628 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1629 last_ro_alloc = lookup;
1634 return last_rel_alloc;
1640 return last_ro_alloc;
1648 /* Place an orphan section. We use this to put random SHF_ALLOC
1649 sections in the right segment. */
1651 static lang_output_section_statement_type *
1652 gld${EMULATION_NAME}_place_orphan (asection *s,
1653 const char *secname,
1656 static struct orphan_save hold[] =
1659 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1662 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1665 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1671 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1674 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1677 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1683 enum orphan_save_index
1694 static int orphan_init_done = 0;
1695 struct orphan_save *place;
1696 lang_output_section_statement_type *after;
1697 lang_output_section_statement_type *os;
1699 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
1700 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
1702 if (! link_info.relocatable
1703 && link_info.combreloc
1704 && (s->flags & SEC_ALLOC))
1710 secname = ".rela.dyn";
1714 secname = ".rel.dyn";
1720 else if (CONST_STRNEQ (secname, ".rel"))
1722 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
1727 /* Look through the script to see where to place this section. */
1728 if (constraint == 0)
1729 for (os = lang_output_section_find (secname);
1731 os = next_matching_output_section_statement (os, 0))
1733 /* If we don't match an existing output section, tell
1734 lang_insert_orphan to create a new output section. */
1735 constraint = SPECIAL;
1737 if (os->bfd_section != NULL
1738 && (os->bfd_section->flags == 0
1739 || (_bfd_elf_match_sections_by_type (link_info.output_bfd,
1742 && ((s->flags ^ os->bfd_section->flags)
1743 & (SEC_LOAD | SEC_ALLOC)) == 0)))
1745 /* We already have an output section statement with this
1746 name, and its bfd section has compatible flags.
1747 If the section already exists but does not have any flags
1748 set, then it has been created by the linker, probably as a
1749 result of a --section-start command line switch. */
1750 lang_add_section (&os->children, s, os);
1755 if (!orphan_init_done)
1757 lang_output_section_statement_type *lookup;
1758 struct orphan_save *ho;
1760 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1761 if (ho->name != NULL)
1763 ho->os = lang_output_section_find (ho->name);
1764 if (ho->os != NULL && ho->os->flags == 0)
1765 ho->os->flags = ho->flags;
1767 lookup = hold[orphan_bss].os;
1769 lookup = &lang_output_section_statement.head->output_section_statement;
1770 for (; lookup != NULL; lookup = lookup->next)
1771 if ((lookup->bfd_section != NULL
1772 && (lookup->bfd_section->flags & SEC_DEBUGGING) != 0)
1773 || strcmp (lookup->name, ".comment") == 0)
1775 hold[orphan_nonalloc].os = lookup ? lookup->prev : NULL;
1776 hold[orphan_nonalloc].name = ".comment";
1777 orphan_init_done = 1;
1780 /* If this is a final link, then always put .gnu.warning.SYMBOL
1781 sections into the .text section to get them out of the way. */
1782 if (link_info.executable
1783 && ! link_info.relocatable
1784 && CONST_STRNEQ (s->name, ".gnu.warning.")
1785 && hold[orphan_text].os != NULL)
1787 os = hold[orphan_text].os;
1788 lang_add_section (&os->children, s, os);
1792 /* Decide which segment the section should go in based on the
1793 section name and section flags. We put loadable .note sections
1794 right after the .interp section, so that the PT_NOTE segment is
1795 stored right after the program headers where the OS can read it
1796 in the first page. */
1799 if ((s->flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
1800 place = &hold[orphan_nonalloc];
1801 else if ((s->flags & SEC_ALLOC) == 0)
1803 else if ((s->flags & SEC_LOAD) != 0
1804 && ((iself && sh_type == SHT_NOTE)
1805 || (!iself && CONST_STRNEQ (secname, ".note"))))
1806 place = &hold[orphan_interp];
1807 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1808 place = &hold[orphan_bss];
1809 else if ((s->flags & SEC_SMALL_DATA) != 0)
1810 place = &hold[orphan_sdata];
1811 else if ((s->flags & SEC_READONLY) == 0)
1812 place = &hold[orphan_data];
1813 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
1814 || (!iself && CONST_STRNEQ (secname, ".rel")))
1815 && (s->flags & SEC_LOAD) != 0)
1816 place = &hold[orphan_rel];
1817 else if ((s->flags & SEC_CODE) == 0)
1818 place = &hold[orphan_rodata];
1820 place = &hold[orphan_text];
1825 if (place->os == NULL)
1827 if (place->name != NULL)
1828 place->os = lang_output_section_find (place->name);
1830 place->os = output_rel_find (s, isdyn);
1834 after = lang_output_section_find_by_flags
1835 (s, &place->os, _bfd_elf_match_sections_by_type);
1837 /* *ABS* is always the first output section statement. */
1838 after = &lang_output_section_statement.head->output_section_statement;
1841 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
1846 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
1850 gld${EMULATION_NAME}_after_allocation (void)
1852 bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
1854 gld${EMULATION_NAME}_map_segments (need_layout);
1859 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
1863 gld${EMULATION_NAME}_get_script (int *isfile)
1866 if test -n "$COMPILE_IN"
1868 # Scripts compiled in.
1870 # sed commands to quote an ld script as a C string.
1871 sc="-f stringify.sed"
1877 if (link_info.relocatable && config.build_constructors)
1880 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1881 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1882 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1883 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1884 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1885 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
1886 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1887 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1889 if test -n "$GENERATE_PIE_SCRIPT" ; then
1890 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1891 echo ' ; else if (link_info.pie && link_info.combreloc' >> e${EMULATION_NAME}.c
1892 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1893 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1894 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
1895 echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1896 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
1898 echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c
1899 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
1901 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1902 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1903 echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c
1904 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1905 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1906 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
1907 echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1908 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
1910 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1911 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1913 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1914 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
1915 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1916 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
1917 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
1918 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
1920 echo ' ; else return' >> e${EMULATION_NAME}.c
1921 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1922 echo '; }' >> e${EMULATION_NAME}.c
1925 # Scripts read from the filesystem.
1931 if (link_info.relocatable && config.build_constructors)
1932 return "ldscripts/${EMULATION_NAME}.xu";
1933 else if (link_info.relocatable)
1934 return "ldscripts/${EMULATION_NAME}.xr";
1935 else if (!config.text_read_only)
1936 return "ldscripts/${EMULATION_NAME}.xbn";
1938 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
1941 else if (!config.magic_demand_paged)
1942 return "ldscripts/${EMULATION_NAME}.xn";
1945 if test -n "$GENERATE_PIE_SCRIPT" ; then
1946 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1948 else if (link_info.pie && link_info.combreloc
1949 && link_info.relro && (link_info.flags & DF_BIND_NOW))
1950 return "ldscripts/${EMULATION_NAME}.xdw";
1951 else if (link_info.pie && link_info.combreloc)
1952 return "ldscripts/${EMULATION_NAME}.xdc";
1956 else if (link_info.pie)
1957 return "ldscripts/${EMULATION_NAME}.xd";
1960 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1961 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1963 else if (link_info.shared && link_info.combreloc
1964 && link_info.relro && (link_info.flags & DF_BIND_NOW))
1965 return "ldscripts/${EMULATION_NAME}.xsw";
1966 else if (link_info.shared && link_info.combreloc)
1967 return "ldscripts/${EMULATION_NAME}.xsc";
1971 else if (link_info.shared)
1972 return "ldscripts/${EMULATION_NAME}.xs";
1975 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1977 else if (link_info.combreloc && link_info.relro
1978 && (link_info.flags & DF_BIND_NOW))
1979 return "ldscripts/${EMULATION_NAME}.xw";
1980 else if (link_info.combreloc)
1981 return "ldscripts/${EMULATION_NAME}.xc";
1986 return "ldscripts/${EMULATION_NAME}.x";
1993 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1995 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
1997 $PARSE_AND_LIST_PROLOGUE
2003 #define OPTION_DISABLE_NEW_DTAGS (400)
2004 #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
2005 #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
2006 #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
2007 #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
2008 #define OPTION_HASH_STYLE (OPTION_EXCLUDE_LIBS + 1)
2009 #define OPTION_BUILD_ID (OPTION_HASH_STYLE + 1)
2012 gld${EMULATION_NAME}_add_options
2013 (int ns, char **shortopts, int nl, struct option **longopts,
2014 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2016 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2017 static const struct option xtra_long[] = {
2018 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2021 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2023 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2024 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2025 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2026 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2027 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2028 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2032 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2034 $PARSE_AND_LIST_LONGOPTS
2039 {NULL, no_argument, NULL, 0}
2042 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2043 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2044 *longopts = (struct option *)
2045 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2046 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2049 #define DEFAULT_BUILD_ID_STYLE "sha1"
2052 gld${EMULATION_NAME}_handle_option (int optc)
2059 case OPTION_BUILD_ID:
2060 if (link_info.emit_note_gnu_build_id != NULL)
2062 free (link_info.emit_note_gnu_build_id);
2063 link_info.emit_note_gnu_build_id = NULL;
2066 optarg = DEFAULT_BUILD_ID_STYLE;
2067 if (strcmp (optarg, "none"))
2068 link_info.emit_note_gnu_build_id = xstrdup (optarg);
2073 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2075 case OPTION_DISABLE_NEW_DTAGS:
2076 link_info.new_dtags = FALSE;
2079 case OPTION_ENABLE_NEW_DTAGS:
2080 link_info.new_dtags = TRUE;
2083 case OPTION_EH_FRAME_HDR:
2084 link_info.eh_frame_hdr = TRUE;
2088 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2089 /* Groups must be self-contained. */
2090 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2091 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2094 case OPTION_EXCLUDE_LIBS:
2095 add_excluded_libs (optarg);
2098 case OPTION_HASH_STYLE:
2099 link_info.emit_hash = FALSE;
2100 link_info.emit_gnu_hash = FALSE;
2101 if (strcmp (optarg, "sysv") == 0)
2102 link_info.emit_hash = TRUE;
2103 else if (strcmp (optarg, "gnu") == 0)
2104 link_info.emit_gnu_hash = TRUE;
2105 else if (strcmp (optarg, "both") == 0)
2107 link_info.emit_hash = TRUE;
2108 link_info.emit_gnu_hash = TRUE;
2111 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2115 if (strcmp (optarg, "initfirst") == 0)
2116 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2117 else if (strcmp (optarg, "interpose") == 0)
2118 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2119 else if (strcmp (optarg, "loadfltr") == 0)
2120 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2121 else if (strcmp (optarg, "nodefaultlib") == 0)
2122 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2123 else if (strcmp (optarg, "nodelete") == 0)
2124 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2125 else if (strcmp (optarg, "nodlopen") == 0)
2126 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2127 else if (strcmp (optarg, "nodump") == 0)
2128 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2129 else if (strcmp (optarg, "now") == 0)
2131 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2132 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2134 else if (strcmp (optarg, "lazy") == 0)
2136 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2137 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2139 else if (strcmp (optarg, "origin") == 0)
2141 link_info.flags |= (bfd_vma) DF_ORIGIN;
2142 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2144 else if (strcmp (optarg, "defs") == 0)
2145 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2146 else if (strcmp (optarg, "muldefs") == 0)
2147 link_info.allow_multiple_definition = TRUE;
2148 else if (strcmp (optarg, "combreloc") == 0)
2149 link_info.combreloc = TRUE;
2150 else if (strcmp (optarg, "nocombreloc") == 0)
2151 link_info.combreloc = FALSE;
2152 else if (strcmp (optarg, "nocopyreloc") == 0)
2153 link_info.nocopyreloc = TRUE;
2154 else if (strcmp (optarg, "execstack") == 0)
2156 link_info.execstack = TRUE;
2157 link_info.noexecstack = FALSE;
2159 else if (strcmp (optarg, "noexecstack") == 0)
2161 link_info.noexecstack = TRUE;
2162 link_info.execstack = FALSE;
2166 if test -n "$COMMONPAGESIZE"; then
2168 else if (strcmp (optarg, "relro") == 0)
2169 link_info.relro = TRUE;
2170 else if (strcmp (optarg, "norelro") == 0)
2171 link_info.relro = FALSE;
2176 else if (CONST_STRNEQ (optarg, "max-page-size="))
2180 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2181 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2182 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2185 else if (CONST_STRNEQ (optarg, "common-page-size="))
2188 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2190 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2191 einfo (_("%P%F: invalid common page size \`%s'\n"),
2194 /* What about the other Solaris -z options? FIXME. */
2199 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2201 $PARSE_AND_LIST_ARGS_CASES
2213 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2217 gld${EMULATION_NAME}_list_options (FILE * file)
2220 --build-id[=STYLE] Generate build ID note\n"));
2223 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2226 -Bgroup Selects group name lookup rules for DSO\n"));
2228 --disable-new-dtags Disable new dynamic tags\n"));
2230 --enable-new-dtags Enable new dynamic tags\n"));
2232 --eh-frame-hdr Create .eh_frame_hdr section\n"));
2234 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
2236 -z combreloc Merge dynamic relocs into one section and sort\n"));
2238 -z defs Report unresolved symbols in object files.\n"));
2240 -z execstack Mark executable as requiring executable stack\n"));
2242 -z initfirst Mark DSO to be initialized first at runtime\n"));
2244 -z interpose Mark object to interpose all DSOs but executable\n"));
2246 -z lazy Mark object lazy runtime binding (default)\n"));
2248 -z loadfltr Mark object requiring immediate process\n"));
2250 -z muldefs Allow multiple definitions\n"));
2252 -z nocombreloc Don't merge dynamic relocs into one section\n"));
2254 -z nocopyreloc Don't create copy relocs\n"));
2256 -z nodefaultlib Mark object not to use default search paths\n"));
2258 -z nodelete Mark DSO non-deletable at runtime\n"));
2260 -z nodlopen Mark DSO not available to dlopen\n"));
2262 -z nodump Mark DSO not available to dldump\n"));
2264 -z noexecstack Mark executable as not requiring executable stack\n"));
2267 if test -n "$COMMONPAGESIZE"; then
2270 -z norelro Don't create RELRO program header\n"));
2276 -z now Mark object non-lazy runtime binding\n"));
2278 -z origin Mark object requiring immediate \$ORIGIN\n\
2279 processing at runtime\n"));
2282 if test -n "$COMMONPAGESIZE"; then
2285 -z relro Create RELRO program header\n"));
2291 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
2293 -z common-page-size=SIZE Set common page size to SIZE\n"));
2295 -z KEYWORD Ignored for Solaris compatibility\n"));
2299 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2301 $PARSE_AND_LIST_OPTIONS
2309 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2311 $PARSE_AND_LIST_EPILOGUE
2317 #define gld${EMULATION_NAME}_add_options NULL
2318 #define gld${EMULATION_NAME}_handle_option NULL
2320 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2322 #define gld${EMULATION_NAME}_list_options NULL
2329 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2331 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2332 ${LDEMUL_SYSLIB-syslib_default},
2333 ${LDEMUL_HLL-hll_default},
2334 ${LDEMUL_AFTER_PARSE-after_parse_default},
2335 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2336 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2337 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2338 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2339 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2340 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2341 "${EMULATION_NAME}",
2343 ${LDEMUL_FINISH-finish_default},
2344 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2345 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2346 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2347 ${LDEMUL_SET_SYMBOLS-NULL},
2348 ${LDEMUL_PARSE_ARGS-NULL},
2349 gld${EMULATION_NAME}_add_options,
2350 gld${EMULATION_NAME}_handle_option,
2351 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2352 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
2353 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2354 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2355 ${LDEMUL_NEW_VERS_PATTERN-NULL}