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}
11 cat >e${EMULATION_NAME}.c <<EOF
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 Free Software Foundation, Inc.
17 Written by Steve Chamberlain <sac@cygnus.com>
18 ELF support by Ian Lance Taylor <ian@cygnus.com>
20 This file is part of GLD, the Gnu Linker.
22 This program is free software; you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation; either version 2 of the License, or
25 (at your option) any later version.
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
36 #define TARGET_IS_${EMULATION_NAME}
40 #include "libiberty.h"
41 #include "safe-ctype.h"
54 #include "elf/common.h"
56 /* Declare functions used by various EXTRA_EM_FILEs. */
57 static void gld${EMULATION_NAME}_before_parse (void);
58 static void gld${EMULATION_NAME}_after_open (void);
59 static void gld${EMULATION_NAME}_before_allocation (void);
60 static bfd_boolean gld${EMULATION_NAME}_place_orphan
61 (lang_input_statement_type *file, asection *s);
62 static void gld${EMULATION_NAME}_finish (void);
66 if [ "x${USE_LIBPATH}" = xyes ] ; then
69 cat >>e${EMULATION_NAME}.c <<EOF
76 # Import any needed special functions and/or overrides.
78 if test -n "$EXTRA_EM_FILE" ; then
79 . ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
82 # Functions in this file can be overridden by setting the LDEMUL_* shell
83 # variables. If the name of the overriding function is the same as is
84 # defined in this file, then don't output this file's version.
85 # If a different overriding name is given then output the standard function
86 # as presumably it is called from the overriding function.
88 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
89 cat >>e${EMULATION_NAME}.c <<EOF
92 gld${EMULATION_NAME}_before_parse (void)
94 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
95 config.dynamic_link = ${DYNAMIC_LINK-TRUE};
96 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
102 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
103 cat >>e${EMULATION_NAME}.c <<EOF
104 /* Handle as_needed DT_NEEDED. */
107 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
111 /* Tell the ELF linker that we don't want the output file to have a
112 DT_NEEDED entry for this file, unless it is used to resolve
113 references in a regular object. */
114 if (entry->as_needed)
115 class = DYN_AS_NEEDED;
117 /* Tell the ELF linker that we don't want the output file to have a
118 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
120 if (!entry->add_needed)
121 class |= DYN_NO_ADD_NEEDED;
124 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
127 bfd_elf_set_dyn_lib_class (entry->the_bfd, class);
129 /* Continue on with normal load_symbols processing. */
135 cat >>e${EMULATION_NAME}.c <<EOF
137 /* These variables are required to pass information back and forth
138 between after_open and check_needed and stat_needed and vercheck. */
140 static struct bfd_link_needed_list *global_needed;
141 static struct stat global_stat;
142 static bfd_boolean global_found;
143 static struct bfd_link_needed_list *global_vercheck_needed;
144 static bfd_boolean global_vercheck_failed;
147 /* On Linux, it's possible to have different versions of the same
148 shared library linked against different versions of libc. The
149 dynamic linker somehow tags which libc version to use in
150 /etc/ld.so.cache, and, based on the libc that it sees in the
151 executable, chooses which version of the shared library to use.
153 We try to do a similar check here by checking whether this shared
154 library needs any other shared libraries which may conflict with
155 libraries we have already included in the link. If it does, we
156 skip it, and try to find another shared library farther on down the
159 This is called via lang_for_each_input_file.
160 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
161 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
162 a conflicting version. */
165 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
168 struct bfd_link_needed_list *l;
170 if (global_vercheck_failed)
172 if (s->the_bfd == NULL
173 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
176 soname = bfd_elf_get_dt_soname (s->the_bfd);
178 soname = lbasename (bfd_get_filename (s->the_bfd));
180 for (l = global_vercheck_needed; l != NULL; l = l->next)
184 if (strcmp (soname, l->name) == 0)
186 /* Probably can't happen, but it's an easy check. */
190 if (strchr (l->name, '/') != NULL)
193 suffix = strstr (l->name, ".so.");
197 suffix += sizeof ".so." - 1;
199 if (strncmp (soname, l->name, suffix - l->name) == 0)
201 /* Here we know that S is a dynamic object FOO.SO.VER1, and
202 the object we are considering needs a dynamic object
203 FOO.SO.VER2, and VER1 and VER2 are different. This
204 appears to be a version mismatch, so we tell the caller
205 to try a different version of this library. */
206 global_vercheck_failed = TRUE;
213 /* See if an input file matches a DT_NEEDED entry by running stat on
217 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
225 if (s->the_bfd == NULL)
228 if (bfd_stat (s->the_bfd, &st) != 0)
230 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
234 if (st.st_dev == global_stat.st_dev
235 && st.st_ino == global_stat.st_ino)
241 /* We issue a warning if it looks like we are including two
242 different versions of the same shared library. For example,
243 there may be a problem if -lc picks up libc.so.6 but some other
244 shared library has a DT_NEEDED entry of libc.so.5. This is a
245 heuristic test, and it will only work if the name looks like
246 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
247 If we really want to issue warnings about mixing version numbers
248 of shared libraries, we need to find a better way. */
250 if (strchr (global_needed->name, '/') != NULL)
252 suffix = strstr (global_needed->name, ".so.");
255 suffix += sizeof ".so." - 1;
257 soname = bfd_elf_get_dt_soname (s->the_bfd);
259 soname = lbasename (s->filename);
261 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
262 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
263 global_needed->name, global_needed->by, soname);
272 /* This function is called for each possible name for a dynamic object
273 named by a DT_NEEDED entry. The FORCE parameter indicates whether
274 to skip the check for a conflicting version. */
277 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
281 const char *name = needed->name;
285 abfd = bfd_openr (name, bfd_get_target (output_bfd));
288 if (! bfd_check_format (abfd, bfd_object))
293 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
299 /* For DT_NEEDED, they have to match. */
300 if (abfd->xvec != output_bfd->xvec)
306 /* Check whether this object would include any conflicting library
307 versions. If FORCE is set, then we skip this check; we use this
308 the second time around, if we couldn't find any compatible
309 instance of the shared library. */
313 struct bfd_link_needed_list *needed;
315 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
316 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
320 global_vercheck_needed = needed;
321 global_vercheck_failed = FALSE;
322 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
323 if (global_vercheck_failed)
326 /* Return FALSE to force the caller to move on to try
327 another file on the search path. */
331 /* But wait! It gets much worse. On Linux, if a shared
332 library does not use libc at all, we are supposed to skip
333 it the first time around in case we encounter a shared
334 library later on with the same name which does use the
335 version of libc that we want. This is much too horrible
336 to use on any system other than Linux. */
341 cat >>e${EMULATION_NAME}.c <<EOF
343 struct bfd_link_needed_list *l;
345 for (l = needed; l != NULL; l = l->next)
346 if (strncmp (l->name, "libc.so", 7) == 0)
358 cat >>e${EMULATION_NAME}.c <<EOF
362 /* We've found a dynamic object matching the DT_NEEDED entry. */
364 /* We have already checked that there is no other input file of the
365 same name. We must now check again that we are not including the
366 same file twice. We need to do this because on many systems
367 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
368 reference libc.so.1. If we have already included libc.so, we
369 don't want to include libc.so.1 if they are the same file, and we
370 can only check that using stat. */
372 if (bfd_stat (abfd, &global_stat) != 0)
373 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
375 /* First strip off everything before the last '/'. */
376 soname = lbasename (abfd->filename);
378 if (trace_file_tries)
379 info_msg (_("found %s at %s\n"), soname, name);
381 global_found = FALSE;
382 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
385 /* Return TRUE to indicate that we found the file, even though
386 we aren't going to do anything with it. */
390 /* Specify the soname to use. */
391 bfd_elf_set_dt_needed_name (abfd, soname);
393 /* Tell the ELF linker that we don't want the output file to have a
394 DT_NEEDED entry for this file, unless it is used to resolve
395 references in a regular object. */
396 class = DYN_DT_NEEDED;
398 /* Tell the ELF linker that we don't want the output file to have a
399 DT_NEEDED entry for this file at all if the entry is from a file
400 with DYN_NO_ADD_NEEDED. */
401 if (needed->by != NULL
402 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
403 class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
405 bfd_elf_set_dyn_lib_class (abfd, class);
407 /* Add this file into the symbol table. */
408 if (! bfd_link_add_symbols (abfd, &link_info))
409 einfo ("%F%B: could not read symbols: %E\n", abfd);
415 /* Search for a needed file in a path. */
418 gld${EMULATION_NAME}_search_needed (const char *path,
419 struct dt_needed *n, int force)
422 const char *name = n->name;
424 struct dt_needed needed;
427 return gld${EMULATION_NAME}_try_needed (n, force);
429 if (path == NULL || *path == '\0')
433 needed.name = n->name;
438 char *filename, *sset;
440 s = strchr (path, ':');
442 s = path + strlen (path);
444 filename = (char *) xmalloc (s - path + len + 2);
449 memcpy (filename, path, s - path);
450 filename[s - path] = '/';
451 sset = filename + (s - path) + 1;
455 needed.name = filename;
456 if (gld${EMULATION_NAME}_try_needed (&needed, force))
470 if [ "x${USE_LIBPATH}" = xyes ] ; then
471 cat >>e${EMULATION_NAME}.c <<EOF
473 /* Add the sysroot to every entry in a colon-separated path. */
476 gld${EMULATION_NAME}_add_sysroot (const char *path)
485 if (path[i++] == ':')
491 len = len + (colons + 1) * strlen (ld_sysroot);
492 ret = xmalloc (len + 1);
493 strcpy (ret, ld_sysroot);
494 p = ret + strlen (ret);
500 strcpy (p, ld_sysroot);
513 cat >>e${EMULATION_NAME}.c <<EOF
514 /* For a native linker, check the file /etc/ld.so.conf for directories
515 in which we may find shared libraries. /etc/ld.so.conf is really
516 only meaningful on Linux. */
518 struct gld${EMULATION_NAME}_ld_so_conf
525 gld${EMULATION_NAME}_parse_ld_so_conf
526 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
529 gld${EMULATION_NAME}_parse_ld_so_conf_include
530 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
536 if (pattern[0] != '/')
538 char *p = strrchr (filename, '/');
539 size_t patlen = strlen (pattern) + 1;
541 newp = xmalloc (p - filename + 1 + patlen);
542 memcpy (newp, filename, p - filename + 1);
543 memcpy (newp + (p - filename + 1), pattern, patlen);
547 if (glob (pattern, 0, NULL, &gl) == 0)
551 for (i = 0; i < gl.gl_pathc; ++i)
552 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
561 gld${EMULATION_NAME}_parse_ld_so_conf
562 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
564 FILE *f = fopen (filename, FOPEN_RT);
572 line = xmalloc (linelen);
577 /* Normally this would use getline(3), but we need to be portable. */
578 while ((q = fgets (p, linelen - (p - line), f)) != NULL
579 && strlen (q) == linelen - (p - line) - 1
580 && line[linelen - 2] != '\n')
582 line = xrealloc (line, 2 * linelen);
583 p = line + linelen - 1;
587 if (q == NULL && p == line)
590 p = strchr (line, '\n');
594 /* Because the file format does not know any form of quoting we
595 can search forward for the next '#' character and if found
596 make it terminating the line. */
597 p = strchr (line, '#');
601 /* Remove leading whitespace. NUL is no whitespace character. */
603 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
606 /* If the line is blank it is ignored. */
610 if (!strncmp (p, "include", 7) && (p[7] == ' ' || p[7] == '\t'))
616 while (*p == ' ' || *p == '\t')
624 while (*p != ' ' && *p != '\t' && *p)
630 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
638 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
639 && *p != '\r' && *p != '\v')
642 while (p != dir && p[-1] == '/')
644 if (info->path == NULL)
646 info->alloc = p - dir + 1 + 256;
647 info->path = xmalloc (info->alloc);
652 if (info->len + 1 + (p - dir) >= info->alloc)
654 info->alloc += p - dir + 256;
655 info->path = xrealloc (info->path, info->alloc);
657 info->path[info->len++] = ':';
659 memcpy (info->path + info->len, dir, p - dir);
660 info->len += p - dir;
661 info->path[info->len] = '\0';
670 gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force)
672 static bfd_boolean initialized;
673 static char *ld_so_conf;
674 struct dt_needed needed;
679 struct gld${EMULATION_NAME}_ld_so_conf info;
681 tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL);
683 info.len = info.alloc = 0;
684 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
688 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
695 if (ld_so_conf == NULL)
701 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
709 cat >>e${EMULATION_NAME}.c <<EOF
711 /* See if an input file matches a DT_NEEDED entry by name. */
714 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
719 if (s->filename != NULL)
723 if (strcmp (s->filename, global_needed->name) == 0)
729 if (s->search_dirs_flag)
731 f = strrchr (s->filename, '/');
733 && strcmp (f + 1, global_needed->name) == 0)
741 if (s->the_bfd != NULL)
745 soname = bfd_elf_get_dt_soname (s->the_bfd);
747 && strcmp (soname, global_needed->name) == 0)
757 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
758 cat >>e${EMULATION_NAME}.c <<EOF
760 /* This is called after all the input files have been opened. */
763 gld${EMULATION_NAME}_after_open (void)
765 struct bfd_link_needed_list *needed, *l;
767 /* We only need to worry about this when doing a final link. */
768 if (link_info.relocatable || !link_info.executable)
771 /* Get the list of files which appear in DT_NEEDED entries in
772 dynamic objects included in the link (often there will be none).
773 For each such file, we want to track down the corresponding
774 library, and include the symbol table in the link. This is what
775 the runtime dynamic linker will do. Tracking the files down here
776 permits one dynamic object to include another without requiring
777 special action by the person doing the link. Note that the
778 needed list can actually grow while we are stepping through this
780 needed = bfd_elf_get_needed_list (output_bfd, &link_info);
781 for (l = needed; l != NULL; l = l->next)
783 struct bfd_link_needed_list *ll;
784 struct dt_needed n, nn;
787 /* If the lib that needs this one was --as-needed and wasn't
788 found to be needed, then this lib isn't needed either. */
790 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
793 /* If we've already seen this file, skip it. */
794 for (ll = needed; ll != l; ll = ll->next)
796 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
797 && strcmp (ll->name, l->name) == 0)
802 /* See if this file was included in the link explicitly. */
804 global_found = FALSE;
805 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
812 if (trace_file_tries)
813 info_msg (_("%s needed by %B\n"), l->name, l->by);
815 /* We need to find this file and include the symbol table. We
816 want to search for the file in the same way that the dynamic
817 linker will search. That means that we want to use
818 rpath_link, rpath, then the environment variable
819 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
820 entries (native only), then the linker script LIB_SEARCH_DIRS.
821 We do not search using the -L arguments.
823 We search twice. The first time, we skip objects which may
824 introduce version mismatches. The second time, we force
825 their use. See gld${EMULATION_NAME}_vercheck comment. */
826 for (force = 0; force < 2; force++)
829 search_dirs_type *search;
831 if [ "x${USE_LIBPATH}" = xyes ] ; then
832 cat >>e${EMULATION_NAME}.c <<EOF
833 const char *lib_path;
834 struct bfd_link_needed_list *rp;
838 cat >>e${EMULATION_NAME}.c <<EOF
840 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
844 if [ "x${USE_LIBPATH}" = xyes ] ; then
845 cat >>e${EMULATION_NAME}.c <<EOF
846 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
851 if [ "x${NATIVE}" = xyes ] ; then
852 cat >>e${EMULATION_NAME}.c <<EOF
853 if (command_line.rpath_link == NULL
854 && command_line.rpath == NULL)
856 lib_path = (const char *) getenv ("LD_RUN_PATH");
857 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
861 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
862 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
866 if [ "x${USE_LIBPATH}" = xyes ] ; then
867 cat >>e${EMULATION_NAME}.c <<EOF
869 rp = bfd_elf_get_runpath_list (output_bfd, &link_info);
870 for (; !found && rp != NULL; rp = rp->next)
872 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
873 found = (rp->by == l->by
874 && gld${EMULATION_NAME}_search_needed (tmpname,
884 cat >>e${EMULATION_NAME}.c <<EOF
885 len = strlen (l->name);
886 for (search = search_head; search != NULL; search = search->next)
892 filename = (char *) xmalloc (strlen (search->name) + len + 2);
893 sprintf (filename, "%s/%s", search->name, l->name);
895 if (gld${EMULATION_NAME}_try_needed (&nn, force))
902 if [ "x${USE_LIBPATH}" = xyes ] ; then
905 cat >>e${EMULATION_NAME}.c <<EOF
906 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
913 cat >>e${EMULATION_NAME}.c <<EOF
919 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
927 cat >>e${EMULATION_NAME}.c <<EOF
929 /* Look through an expression for an assignment statement. */
932 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
934 struct bfd_link_hash_entry *h;
936 switch (exp->type.node_class)
939 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
940 FALSE, FALSE, FALSE);
944 /* We call record_link_assignment even if the symbol is defined.
945 This is because if it is defined by a dynamic object, we
946 actually want to use the value defined by the linker script,
947 not the value from the dynamic object (because we are setting
948 symbols like etext). If the symbol is defined by a regular
949 object, then, as it happens, calling record_link_assignment
954 if (strcmp (exp->assign.dst, ".") != 0)
956 if (! (bfd_elf_record_link_assignment
957 (output_bfd, &link_info, exp->assign.dst,
958 exp->type.node_class == etree_provide ? TRUE : FALSE)))
959 einfo ("%P%F: failed to record assignment to %s: %E\n",
962 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
966 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
967 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
971 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
972 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
973 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
977 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
986 /* This is called by the before_allocation routine via
987 lang_for_each_statement. It locates any assignment statements, and
988 tells the ELF backend about them, in case they are assignments to
989 symbols which are referred to by dynamic objects. */
992 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
994 if (s->header.type == lang_assignment_statement_enum)
995 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1000 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1001 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1002 ELF_INTERPRETER_SET_DEFAULT="
1003 if (sinterp != NULL)
1005 sinterp->contents = ${ELF_INTERPRETER_NAME};
1006 sinterp->size = strlen (sinterp->contents) + 1;
1011 ELF_INTERPRETER_SET_DEFAULT=
1013 cat >>e${EMULATION_NAME}.c <<EOF
1015 /* This is called after the sections have been attached to output
1016 sections, but before any sizes or addresses have been set. */
1019 gld${EMULATION_NAME}_before_allocation (void)
1024 if (link_info.hash->type == bfd_link_elf_hash_table)
1025 _bfd_elf_tls_setup (output_bfd, &link_info);
1027 /* If we are going to make any variable assignments, we need to let
1028 the ELF backend know about them in case the variables are
1029 referred to by dynamic objects. */
1030 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1032 /* Let the ELF backend work out the sizes of any sections required
1033 by dynamic linking. */
1034 rpath = command_line.rpath;
1036 rpath = (const char *) getenv ("LD_RUN_PATH");
1037 if (! (bfd_elf_size_dynamic_sections
1038 (output_bfd, command_line.soname, rpath,
1039 command_line.filter_shlib,
1040 (const char * const *) command_line.auxiliary_filters,
1041 &link_info, &sinterp, lang_elf_version_info)))
1042 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1043 ${ELF_INTERPRETER_SET_DEFAULT}
1044 /* Let the user override the dynamic linker we are using. */
1045 if (command_line.interpreter != NULL
1048 sinterp->contents = (bfd_byte *) command_line.interpreter;
1049 sinterp->size = strlen (command_line.interpreter) + 1;
1052 /* Look for any sections named .gnu.warning. As a GNU extensions,
1053 we treat such sections as containing warning messages. We print
1054 out the warning message, and then zero out the section size so
1055 that it does not get copied into the output file. */
1058 LANG_FOR_EACH_INPUT_STATEMENT (is)
1062 bfd_size_type prefix_len;
1065 const char * gnu_warning_prefix = _("warning: ");
1067 if (is->just_syms_flag)
1070 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1075 prefix_len = strlen (gnu_warning_prefix);
1076 msg = xmalloc ((size_t) (prefix_len + sz + 1));
1077 strcpy (msg, gnu_warning_prefix);
1078 if (! bfd_get_section_contents (is->the_bfd, s, msg + prefix_len,
1080 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1082 msg[prefix_len + sz] = '\0';
1083 ret = link_info.callbacks->warning (&link_info, msg,
1084 (const char *) NULL,
1085 is->the_bfd, (asection *) NULL,
1090 /* Clobber the section size, so that we don't waste copying the
1091 warning into the output file. */
1100 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1101 cat >>e${EMULATION_NAME}.c <<EOF
1103 /* Try to open a dynamic archive. This is where we know that ELF
1104 dynamic libraries have an extension of .so (or .sl on oddball systems
1108 gld${EMULATION_NAME}_open_dynamic_archive
1109 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1111 const char *filename;
1114 if (! entry->is_archive)
1117 filename = entry->filename;
1119 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
1120 is defined, but it does not seem worth the headache to optimize
1121 away those two bytes of space. */
1122 string = (char *) xmalloc (strlen (search->name)
1125 #ifdef EXTRA_SHLIB_EXTENSION
1126 + strlen (EXTRA_SHLIB_EXTENSION)
1128 + sizeof "/lib.so");
1130 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1132 #ifdef EXTRA_SHLIB_EXTENSION
1133 /* Try the .so extension first. If that fails build a new filename
1134 using EXTRA_SHLIB_EXTENSION. */
1135 if (! ldfile_try_open_bfd (string, entry))
1136 sprintf (string, "%s/lib%s%s%s", search->name,
1137 filename, arch, EXTRA_SHLIB_EXTENSION);
1140 if (! ldfile_try_open_bfd (string, entry))
1146 entry->filename = string;
1148 /* We have found a dynamic object to include in the link. The ELF
1149 backend linker will create a DT_NEEDED entry in the .dynamic
1150 section naming this file. If this file includes a DT_SONAME
1151 entry, it will be used. Otherwise, the ELF linker will just use
1152 the name of the file. For an archive found by searching, like
1153 this one, the DT_NEEDED entry should consist of just the name of
1154 the file, without the path information used to find it. Note
1155 that we only need to do this if we have a dynamic object; an
1156 archive will never be referenced by a DT_NEEDED entry.
1158 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1159 very pretty. I haven't been able to think of anything that is
1161 if (bfd_check_format (entry->the_bfd, bfd_object)
1162 && (entry->the_bfd->flags & DYNAMIC) != 0)
1164 ASSERT (entry->is_archive && entry->search_dirs_flag);
1166 /* Rather than duplicating the logic above. Just use the
1167 filename we recorded earlier. */
1169 filename = lbasename (entry->filename);
1170 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1179 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1180 cat >>e${EMULATION_NAME}.c <<EOF
1182 /* A variant of lang_output_section_find used by place_orphan. */
1184 static lang_output_section_statement_type *
1185 output_rel_find (asection *sec, int isdyn)
1187 lang_output_section_statement_type *lookup;
1188 lang_output_section_statement_type *last = NULL;
1189 lang_output_section_statement_type *last_alloc = NULL;
1190 lang_output_section_statement_type *last_rel = NULL;
1191 lang_output_section_statement_type *last_rel_alloc = NULL;
1192 int rela = sec->name[4] == 'a';
1194 for (lookup = &lang_output_section_statement.head->output_section_statement;
1196 lookup = lookup->next)
1198 if (lookup->constraint != -1
1199 && strncmp (".rel", lookup->name, 4) == 0)
1201 int lookrela = lookup->name[4] == 'a';
1203 /* .rel.dyn must come before all other reloc sections, to suit
1208 /* Don't place after .rel.plt as doing so results in wrong
1210 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1213 if (rela == lookrela || last_rel == NULL)
1215 if ((rela == lookrela || last_rel_alloc == NULL)
1216 && lookup->bfd_section != NULL
1217 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1218 last_rel_alloc = lookup;
1222 if (lookup->bfd_section != NULL
1223 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1224 last_alloc = lookup;
1228 return last_rel_alloc;
1239 /* Place an orphan section. We use this to put random SHF_ALLOC
1240 sections in the right segment. */
1243 gld${EMULATION_NAME}_place_orphan (lang_input_statement_type *file, asection *s)
1245 static struct orphan_save hold[] =
1248 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1251 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1254 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1260 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1263 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1266 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1269 enum orphan_save_index
1279 static int orphan_init_done = 0;
1280 struct orphan_save *place;
1281 const char *secname;
1282 lang_output_section_statement_type *after;
1283 lang_output_section_statement_type *os;
1286 secname = bfd_get_section_name (s->owner, s);
1288 if (! link_info.relocatable
1289 && link_info.combreloc
1290 && (s->flags & SEC_ALLOC)
1291 && strncmp (secname, ".rel", 4) == 0)
1293 if (secname[4] == 'a')
1294 secname = ".rela.dyn";
1296 secname = ".rel.dyn";
1300 if (isdyn || (!config.unique_orphan_sections && !unique_section_p (s)))
1302 /* Look through the script to see where to place this section. */
1303 os = lang_output_section_find (secname);
1306 && (os->bfd_section == NULL
1307 || os->bfd_section->flags == 0
1308 || ((s->flags ^ os->bfd_section->flags)
1309 & (SEC_LOAD | SEC_ALLOC)) == 0))
1311 /* We already have an output section statement with this
1312 name, and its bfd section, if any, has compatible flags.
1313 If the section already exists but does not have any flags
1314 set, then it has been created by the linker, probably as a
1315 result of a --section-start command line switch. */
1316 lang_add_section (&os->children, s, os, file);
1321 if (!orphan_init_done)
1323 struct orphan_save *ho;
1324 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1325 if (ho->name != NULL)
1327 ho->os = lang_output_section_find (ho->name);
1328 if (ho->os != NULL && ho->os->flags == 0)
1329 ho->os->flags = ho->flags;
1331 orphan_init_done = 1;
1334 /* If this is a final link, then always put .gnu.warning.SYMBOL
1335 sections into the .text section to get them out of the way. */
1336 if (link_info.executable
1337 && ! link_info.relocatable
1338 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0
1339 && hold[orphan_text].os != NULL)
1341 lang_add_section (&hold[orphan_text].os->children, s,
1342 hold[orphan_text].os, file);
1346 /* Decide which segment the section should go in based on the
1347 section name and section flags. We put loadable .note sections
1348 right after the .interp section, so that the PT_NOTE segment is
1349 stored right after the program headers where the OS can read it
1350 in the first page. */
1353 if ((s->flags & SEC_ALLOC) == 0)
1355 else if ((s->flags & SEC_LOAD) != 0
1356 && strncmp (secname, ".note", 5) == 0)
1357 place = &hold[orphan_interp];
1358 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1359 place = &hold[orphan_bss];
1360 else if ((s->flags & SEC_SMALL_DATA) != 0)
1361 place = &hold[orphan_sdata];
1362 else if ((s->flags & SEC_READONLY) == 0)
1363 place = &hold[orphan_data];
1364 else if (strncmp (secname, ".rel", 4) == 0
1365 && (s->flags & SEC_LOAD) != 0)
1366 place = &hold[orphan_rel];
1367 else if ((s->flags & SEC_CODE) == 0)
1368 place = &hold[orphan_rodata];
1370 place = &hold[orphan_text];
1375 if (place->os == NULL)
1377 if (place->name != NULL)
1378 place->os = lang_output_section_find (place->name);
1380 place->os = output_rel_find (s, isdyn);
1384 after = lang_output_section_find_by_flags (s, &place->os);
1386 /* *ABS* is always the first output section statement. */
1387 after = &lang_output_section_statement.head->output_section_statement;
1390 /* Choose a unique name for the section. This will be needed if the
1391 same section name appears in the input file with different
1392 loadable or allocatable characteristics. */
1393 if (bfd_get_section_by_name (output_bfd, secname) != NULL)
1395 static int count = 1;
1396 secname = bfd_get_unique_section_name (output_bfd, secname, &count);
1397 if (secname == NULL)
1398 einfo ("%F%P: place_orphan failed: %E\n");
1401 lang_insert_orphan (file, s, secname, after, place, NULL, NULL);
1408 if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
1409 cat >>e${EMULATION_NAME}.c <<EOF
1412 gld${EMULATION_NAME}_finish (void)
1414 if (bfd_elf_discard_info (output_bfd, &link_info))
1416 lang_reset_memory_regions ();
1418 /* Resize the sections. */
1419 lang_size_sections (stat_ptr->head, abs_output_section,
1420 &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE);
1422 /* Redo special stuff. */
1423 ldemul_after_allocation ();
1425 /* Do the assignments again. */
1426 lang_do_assignments (stat_ptr->head, abs_output_section,
1427 (fill_type *) 0, (bfd_vma) 0);
1433 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
1434 cat >>e${EMULATION_NAME}.c <<EOF
1437 gld${EMULATION_NAME}_get_script (int *isfile)
1440 if test -n "$COMPILE_IN"
1442 # Scripts compiled in.
1444 # sed commands to quote an ld script as a C string.
1445 sc="-f stringify.sed"
1447 cat >>e${EMULATION_NAME}.c <<EOF
1451 if (link_info.relocatable && config.build_constructors)
1454 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1455 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1456 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1457 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1458 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1459 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
1460 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1461 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1463 if test -n "$GENERATE_PIE_SCRIPT" ; then
1464 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1465 echo ' ; else if (link_info.pie && link_info.combreloc' >> e${EMULATION_NAME}.c
1466 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1467 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1468 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
1469 echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1470 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
1472 echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c
1473 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
1475 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1476 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1477 echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c
1478 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1479 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1480 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
1481 echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1482 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
1484 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1485 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1487 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1488 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
1489 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1490 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
1491 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
1492 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
1494 echo ' ; else return' >> e${EMULATION_NAME}.c
1495 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1496 echo '; }' >> e${EMULATION_NAME}.c
1499 # Scripts read from the filesystem.
1501 cat >>e${EMULATION_NAME}.c <<EOF
1505 if (link_info.relocatable && config.build_constructors)
1506 return "ldscripts/${EMULATION_NAME}.xu";
1507 else if (link_info.relocatable)
1508 return "ldscripts/${EMULATION_NAME}.xr";
1509 else if (!config.text_read_only)
1510 return "ldscripts/${EMULATION_NAME}.xbn";
1512 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
1514 cat >>e${EMULATION_NAME}.c <<EOF
1515 else if (!config.magic_demand_paged)
1516 return "ldscripts/${EMULATION_NAME}.xn";
1519 if test -n "$GENERATE_PIE_SCRIPT" ; then
1520 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1521 cat >>e${EMULATION_NAME}.c <<EOF
1522 else if (link_info.pie && link_info.combreloc
1523 && link_info.relro && (link_info.flags & DT_BIND_NOW))
1524 return "ldscripts/${EMULATION_NAME}.xdw";
1525 else if (link_info.pie && link_info.combreloc)
1526 return "ldscripts/${EMULATION_NAME}.xdc";
1529 cat >>e${EMULATION_NAME}.c <<EOF
1530 else if (link_info.pie)
1531 return "ldscripts/${EMULATION_NAME}.xd";
1534 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1535 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1536 cat >>e${EMULATION_NAME}.c <<EOF
1537 else if (link_info.shared && link_info.combreloc
1538 && link_info.relro && (link_info.flags & DT_BIND_NOW))
1539 return "ldscripts/${EMULATION_NAME}.xsw";
1540 else if (link_info.shared && link_info.combreloc)
1541 return "ldscripts/${EMULATION_NAME}.xsc";
1544 cat >>e${EMULATION_NAME}.c <<EOF
1545 else if (link_info.shared)
1546 return "ldscripts/${EMULATION_NAME}.xs";
1549 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1550 cat >>e${EMULATION_NAME}.c <<EOF
1551 else if (link_info.combreloc && link_info.relro
1552 && (link_info.flags & DT_BIND_NOW))
1553 return "ldscripts/${EMULATION_NAME}.xw";
1554 else if (link_info.combreloc)
1555 return "ldscripts/${EMULATION_NAME}.xc";
1558 cat >>e${EMULATION_NAME}.c <<EOF
1560 return "ldscripts/${EMULATION_NAME}.x";
1567 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1569 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
1570 cat >>e${EMULATION_NAME}.c <<EOF
1571 $PARSE_AND_LIST_PROLOGUE
1575 cat >>e${EMULATION_NAME}.c <<EOF
1577 #define OPTION_DISABLE_NEW_DTAGS (400)
1578 #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
1579 #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
1580 #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
1581 #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
1584 gld${EMULATION_NAME}_add_options
1585 (int ns, char **shortopts, int nl, struct option **longopts,
1586 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
1588 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
1589 static const struct option xtra_long[] = {
1592 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1593 cat >>e${EMULATION_NAME}.c <<EOF
1594 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
1595 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
1596 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
1597 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
1598 {"Bgroup", no_argument, NULL, OPTION_GROUP},
1602 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
1603 cat >>e${EMULATION_NAME}.c <<EOF
1604 $PARSE_AND_LIST_LONGOPTS
1608 cat >>e${EMULATION_NAME}.c <<EOF
1609 {NULL, no_argument, NULL, 0}
1612 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
1613 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
1614 *longopts = (struct option *)
1615 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
1616 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
1620 gld${EMULATION_NAME}_handle_option (int optc)
1629 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1630 cat >>e${EMULATION_NAME}.c <<EOF
1631 case OPTION_DISABLE_NEW_DTAGS:
1632 link_info.new_dtags = FALSE;
1635 case OPTION_ENABLE_NEW_DTAGS:
1636 link_info.new_dtags = TRUE;
1639 case OPTION_EH_FRAME_HDR:
1640 link_info.eh_frame_hdr = TRUE;
1644 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
1645 /* Groups must be self-contained. */
1646 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1647 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
1650 case OPTION_EXCLUDE_LIBS:
1651 add_excluded_libs (optarg);
1655 if (strcmp (optarg, "initfirst") == 0)
1656 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
1657 else if (strcmp (optarg, "interpose") == 0)
1658 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
1659 else if (strcmp (optarg, "loadfltr") == 0)
1660 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
1661 else if (strcmp (optarg, "nodefaultlib") == 0)
1662 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
1663 else if (strcmp (optarg, "nodelete") == 0)
1664 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
1665 else if (strcmp (optarg, "nodlopen") == 0)
1666 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
1667 else if (strcmp (optarg, "nodump") == 0)
1668 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
1669 else if (strcmp (optarg, "now") == 0)
1671 link_info.flags |= (bfd_vma) DF_BIND_NOW;
1672 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
1674 else if (strcmp (optarg, "origin") == 0)
1676 link_info.flags |= (bfd_vma) DF_ORIGIN;
1677 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
1679 else if (strcmp (optarg, "defs") == 0)
1680 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1681 else if (strcmp (optarg, "muldefs") == 0)
1682 link_info.allow_multiple_definition = TRUE;
1683 else if (strcmp (optarg, "combreloc") == 0)
1684 link_info.combreloc = TRUE;
1685 else if (strcmp (optarg, "nocombreloc") == 0)
1686 link_info.combreloc = FALSE;
1687 else if (strcmp (optarg, "nocopyreloc") == 0)
1688 link_info.nocopyreloc = TRUE;
1689 else if (strcmp (optarg, "execstack") == 0)
1691 link_info.execstack = TRUE;
1692 link_info.noexecstack = FALSE;
1694 else if (strcmp (optarg, "noexecstack") == 0)
1696 link_info.noexecstack = TRUE;
1697 link_info.execstack = FALSE;
1699 else if (strcmp (optarg, "relro") == 0)
1700 link_info.relro = TRUE;
1701 else if (strcmp (optarg, "norelro") == 0)
1702 link_info.relro = FALSE;
1703 /* What about the other Solaris -z options? FIXME. */
1708 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
1709 cat >>e${EMULATION_NAME}.c <<EOF
1710 $PARSE_AND_LIST_ARGS_CASES
1714 cat >>e${EMULATION_NAME}.c <<EOF
1722 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
1723 cat >>e${EMULATION_NAME}.c <<EOF
1726 gld${EMULATION_NAME}_list_options (FILE * file)
1730 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1731 cat >>e${EMULATION_NAME}.c <<EOF
1732 fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n"));
1733 fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n"));
1734 fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n"));
1735 fprintf (file, _(" --eh-frame-hdr\tCreate .eh_frame_hdr section\n"));
1736 fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n"));
1737 fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n"));
1738 fprintf (file, _(" -z execstack\t\tMark executable as requiring executable stack\n"));
1739 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n"));
1740 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n"));
1741 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n"));
1742 fprintf (file, _(" -z muldefs\t\tAllow multiple definitions\n"));
1743 fprintf (file, _(" -z nocombreloc\tDon't merge dynamic relocs into one section\n"));
1744 fprintf (file, _(" -z nocopyreloc\tDon't create copy relocs\n"));
1745 fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n"));
1746 fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n"));
1747 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n"));
1748 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n"));
1749 fprintf (file, _(" -z noexecstack\tMark executable as not requiring executable stack\n"));
1750 fprintf (file, _(" -z norelro\t\tDon't create RELRO program header\n"));
1751 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n"));
1752 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t at runtime\n"));
1753 fprintf (file, _(" -z relro\t\tCreate RELRO program header\n"));
1754 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n"));
1758 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
1759 cat >>e${EMULATION_NAME}.c <<EOF
1760 $PARSE_AND_LIST_OPTIONS
1764 cat >>e${EMULATION_NAME}.c <<EOF
1768 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
1769 cat >>e${EMULATION_NAME}.c <<EOF
1770 $PARSE_AND_LIST_EPILOGUE
1775 cat >>e${EMULATION_NAME}.c <<EOF
1776 #define gld${EMULATION_NAME}_add_options NULL
1777 #define gld${EMULATION_NAME}_handle_option NULL
1779 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
1780 cat >>e${EMULATION_NAME}.c <<EOF
1781 #define gld${EMULATION_NAME}_list_options NULL
1786 cat >>e${EMULATION_NAME}.c <<EOF
1788 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1790 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
1791 ${LDEMUL_SYSLIB-syslib_default},
1792 ${LDEMUL_HLL-hll_default},
1793 ${LDEMUL_AFTER_PARSE-after_parse_default},
1794 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
1795 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
1796 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
1797 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
1798 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
1799 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
1800 "${EMULATION_NAME}",
1802 ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish},
1803 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
1804 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
1805 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
1806 ${LDEMUL_SET_SYMBOLS-NULL},
1807 ${LDEMUL_PARSE_ARGS-NULL},
1808 gld${EMULATION_NAME}_add_options,
1809 gld${EMULATION_NAME}_handle_option,
1810 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
1811 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
1812 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
1813 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
1814 ${LDEMUL_NEW_VERS_PATTERN-NULL}