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 /* Some operating systems, e.g. Windows, do not provide a meaningful
235 st_ino; they always set it to zero. (Windows does provide a
236 meaningful st_dev.) Do not indicate a duplicate library in that
237 case. While there is no guarantee that a system that provides
238 meaningful inode numbers will never set st_ino to zero, this is
239 merely an optimization, so we do not need to worry about false
241 if (st.st_dev == global_stat.st_dev
242 && st.st_ino == global_stat.st_ino
249 /* We issue a warning if it looks like we are including two
250 different versions of the same shared library. For example,
251 there may be a problem if -lc picks up libc.so.6 but some other
252 shared library has a DT_NEEDED entry of libc.so.5. This is a
253 heuristic test, and it will only work if the name looks like
254 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
255 If we really want to issue warnings about mixing version numbers
256 of shared libraries, we need to find a better way. */
258 if (strchr (global_needed->name, '/') != NULL)
260 suffix = strstr (global_needed->name, ".so.");
263 suffix += sizeof ".so." - 1;
265 soname = bfd_elf_get_dt_soname (s->the_bfd);
267 soname = lbasename (s->filename);
269 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
270 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
271 global_needed->name, global_needed->by, soname);
280 /* This function is called for each possible name for a dynamic object
281 named by a DT_NEEDED entry. The FORCE parameter indicates whether
282 to skip the check for a conflicting version. */
285 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
289 const char *name = needed->name;
293 abfd = bfd_openr (name, bfd_get_target (output_bfd));
296 if (! bfd_check_format (abfd, bfd_object))
301 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
307 /* For DT_NEEDED, they have to match. */
308 if (abfd->xvec != output_bfd->xvec)
314 /* Check whether this object would include any conflicting library
315 versions. If FORCE is set, then we skip this check; we use this
316 the second time around, if we couldn't find any compatible
317 instance of the shared library. */
321 struct bfd_link_needed_list *needed;
323 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
324 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
328 global_vercheck_needed = needed;
329 global_vercheck_failed = FALSE;
330 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
331 if (global_vercheck_failed)
334 /* Return FALSE to force the caller to move on to try
335 another file on the search path. */
339 /* But wait! It gets much worse. On Linux, if a shared
340 library does not use libc at all, we are supposed to skip
341 it the first time around in case we encounter a shared
342 library later on with the same name which does use the
343 version of libc that we want. This is much too horrible
344 to use on any system other than Linux. */
349 cat >>e${EMULATION_NAME}.c <<EOF
351 struct bfd_link_needed_list *l;
353 for (l = needed; l != NULL; l = l->next)
354 if (strncmp (l->name, "libc.so", 7) == 0)
366 cat >>e${EMULATION_NAME}.c <<EOF
370 /* We've found a dynamic object matching the DT_NEEDED entry. */
372 /* We have already checked that there is no other input file of the
373 same name. We must now check again that we are not including the
374 same file twice. We need to do this because on many systems
375 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
376 reference libc.so.1. If we have already included libc.so, we
377 don't want to include libc.so.1 if they are the same file, and we
378 can only check that using stat. */
380 if (bfd_stat (abfd, &global_stat) != 0)
381 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
383 /* First strip off everything before the last '/'. */
384 soname = lbasename (abfd->filename);
386 if (trace_file_tries)
387 info_msg (_("found %s at %s\n"), soname, name);
389 global_found = FALSE;
390 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
393 /* Return TRUE to indicate that we found the file, even though
394 we aren't going to do anything with it. */
398 /* Specify the soname to use. */
399 bfd_elf_set_dt_needed_name (abfd, soname);
401 /* Tell the ELF linker that we don't want the output file to have a
402 DT_NEEDED entry for this file, unless it is used to resolve
403 references in a regular object. */
404 class = DYN_DT_NEEDED;
406 /* Tell the ELF linker that we don't want the output file to have a
407 DT_NEEDED entry for this file at all if the entry is from a file
408 with DYN_NO_ADD_NEEDED. */
409 if (needed->by != NULL
410 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
411 class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
413 bfd_elf_set_dyn_lib_class (abfd, class);
415 /* Add this file into the symbol table. */
416 if (! bfd_link_add_symbols (abfd, &link_info))
417 einfo ("%F%B: could not read symbols: %E\n", abfd);
423 /* Search for a needed file in a path. */
426 gld${EMULATION_NAME}_search_needed (const char *path,
427 struct dt_needed *n, int force)
430 const char *name = n->name;
432 struct dt_needed needed;
435 return gld${EMULATION_NAME}_try_needed (n, force);
437 if (path == NULL || *path == '\0')
441 needed.name = n->name;
446 char *filename, *sset;
448 s = strchr (path, ':');
450 s = path + strlen (path);
452 filename = (char *) xmalloc (s - path + len + 2);
457 memcpy (filename, path, s - path);
458 filename[s - path] = '/';
459 sset = filename + (s - path) + 1;
463 needed.name = filename;
464 if (gld${EMULATION_NAME}_try_needed (&needed, force))
478 if [ "x${USE_LIBPATH}" = xyes ] ; then
479 cat >>e${EMULATION_NAME}.c <<EOF
481 /* Add the sysroot to every entry in a colon-separated path. */
484 gld${EMULATION_NAME}_add_sysroot (const char *path)
493 if (path[i++] == ':')
499 len = len + (colons + 1) * strlen (ld_sysroot);
500 ret = xmalloc (len + 1);
501 strcpy (ret, ld_sysroot);
502 p = ret + strlen (ret);
508 strcpy (p, ld_sysroot);
521 cat >>e${EMULATION_NAME}.c <<EOF
522 /* For a native linker, check the file /etc/ld.so.conf for directories
523 in which we may find shared libraries. /etc/ld.so.conf is really
524 only meaningful on Linux. */
526 struct gld${EMULATION_NAME}_ld_so_conf
533 gld${EMULATION_NAME}_parse_ld_so_conf
534 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
537 gld${EMULATION_NAME}_parse_ld_so_conf_include
538 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
544 if (pattern[0] != '/')
546 char *p = strrchr (filename, '/');
547 size_t patlen = strlen (pattern) + 1;
549 newp = xmalloc (p - filename + 1 + patlen);
550 memcpy (newp, filename, p - filename + 1);
551 memcpy (newp + (p - filename + 1), pattern, patlen);
555 if (glob (pattern, 0, NULL, &gl) == 0)
559 for (i = 0; i < gl.gl_pathc; ++i)
560 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
569 gld${EMULATION_NAME}_parse_ld_so_conf
570 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
572 FILE *f = fopen (filename, FOPEN_RT);
580 line = xmalloc (linelen);
585 /* Normally this would use getline(3), but we need to be portable. */
586 while ((q = fgets (p, linelen - (p - line), f)) != NULL
587 && strlen (q) == linelen - (p - line) - 1
588 && line[linelen - 2] != '\n')
590 line = xrealloc (line, 2 * linelen);
591 p = line + linelen - 1;
595 if (q == NULL && p == line)
598 p = strchr (line, '\n');
602 /* Because the file format does not know any form of quoting we
603 can search forward for the next '#' character and if found
604 make it terminating the line. */
605 p = strchr (line, '#');
609 /* Remove leading whitespace. NUL is no whitespace character. */
611 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
614 /* If the line is blank it is ignored. */
618 if (!strncmp (p, "include", 7) && (p[7] == ' ' || p[7] == '\t'))
624 while (*p == ' ' || *p == '\t')
632 while (*p != ' ' && *p != '\t' && *p)
638 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
646 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
647 && *p != '\r' && *p != '\v')
650 while (p != dir && p[-1] == '/')
652 if (info->path == NULL)
654 info->alloc = p - dir + 1 + 256;
655 info->path = xmalloc (info->alloc);
660 if (info->len + 1 + (p - dir) >= info->alloc)
662 info->alloc += p - dir + 256;
663 info->path = xrealloc (info->path, info->alloc);
665 info->path[info->len++] = ':';
667 memcpy (info->path + info->len, dir, p - dir);
668 info->len += p - dir;
669 info->path[info->len] = '\0';
678 gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force)
680 static bfd_boolean initialized;
681 static char *ld_so_conf;
682 struct dt_needed needed;
687 struct gld${EMULATION_NAME}_ld_so_conf info;
689 tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL);
691 info.len = info.alloc = 0;
692 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
696 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
703 if (ld_so_conf == NULL)
709 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
717 cat >>e${EMULATION_NAME}.c <<EOF
719 /* See if an input file matches a DT_NEEDED entry by name. */
722 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
727 if (s->filename != NULL)
731 if (strcmp (s->filename, global_needed->name) == 0)
737 if (s->search_dirs_flag)
739 f = strrchr (s->filename, '/');
741 && strcmp (f + 1, global_needed->name) == 0)
749 if (s->the_bfd != NULL)
753 soname = bfd_elf_get_dt_soname (s->the_bfd);
755 && strcmp (soname, global_needed->name) == 0)
765 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
766 cat >>e${EMULATION_NAME}.c <<EOF
768 /* This is called after all the input files have been opened. */
771 gld${EMULATION_NAME}_after_open (void)
773 struct bfd_link_needed_list *needed, *l;
775 /* We only need to worry about this when doing a final link. */
776 if (link_info.relocatable || !link_info.executable)
779 /* Get the list of files which appear in DT_NEEDED entries in
780 dynamic objects included in the link (often there will be none).
781 For each such file, we want to track down the corresponding
782 library, and include the symbol table in the link. This is what
783 the runtime dynamic linker will do. Tracking the files down here
784 permits one dynamic object to include another without requiring
785 special action by the person doing the link. Note that the
786 needed list can actually grow while we are stepping through this
788 needed = bfd_elf_get_needed_list (output_bfd, &link_info);
789 for (l = needed; l != NULL; l = l->next)
791 struct bfd_link_needed_list *ll;
792 struct dt_needed n, nn;
795 /* If the lib that needs this one was --as-needed and wasn't
796 found to be needed, then this lib isn't needed either. */
798 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
801 /* If we've already seen this file, skip it. */
802 for (ll = needed; ll != l; ll = ll->next)
804 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
805 && strcmp (ll->name, l->name) == 0)
810 /* See if this file was included in the link explicitly. */
812 global_found = FALSE;
813 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
820 if (trace_file_tries)
821 info_msg (_("%s needed by %B\n"), l->name, l->by);
823 /* We need to find this file and include the symbol table. We
824 want to search for the file in the same way that the dynamic
825 linker will search. That means that we want to use
826 rpath_link, rpath, then the environment variable
827 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
828 entries (native only), then the linker script LIB_SEARCH_DIRS.
829 We do not search using the -L arguments.
831 We search twice. The first time, we skip objects which may
832 introduce version mismatches. The second time, we force
833 their use. See gld${EMULATION_NAME}_vercheck comment. */
834 for (force = 0; force < 2; force++)
837 search_dirs_type *search;
839 if [ "x${NATIVE}" = xyes ] ; then
840 cat >>e${EMULATION_NAME}.c <<EOF
841 const char *lib_path;
844 if [ "x${USE_LIBPATH}" = xyes ] ; then
845 cat >>e${EMULATION_NAME}.c <<EOF
846 struct bfd_link_needed_list *rp;
850 cat >>e${EMULATION_NAME}.c <<EOF
852 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
856 if [ "x${USE_LIBPATH}" = xyes ] ; then
857 cat >>e${EMULATION_NAME}.c <<EOF
858 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
863 if [ "x${NATIVE}" = xyes ] ; then
864 cat >>e${EMULATION_NAME}.c <<EOF
865 if (command_line.rpath_link == NULL
866 && command_line.rpath == NULL)
868 lib_path = (const char *) getenv ("LD_RUN_PATH");
869 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
873 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
874 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
878 if [ "x${USE_LIBPATH}" = xyes ] ; then
879 cat >>e${EMULATION_NAME}.c <<EOF
881 rp = bfd_elf_get_runpath_list (output_bfd, &link_info);
882 for (; !found && rp != NULL; rp = rp->next)
884 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name);
885 found = (rp->by == l->by
886 && gld${EMULATION_NAME}_search_needed (tmpname,
896 cat >>e${EMULATION_NAME}.c <<EOF
897 len = strlen (l->name);
898 for (search = search_head; search != NULL; search = search->next)
904 filename = (char *) xmalloc (strlen (search->name) + len + 2);
905 sprintf (filename, "%s/%s", search->name, l->name);
907 if (gld${EMULATION_NAME}_try_needed (&nn, force))
914 if [ "x${USE_LIBPATH}" = xyes ] ; then
917 cat >>e${EMULATION_NAME}.c <<EOF
918 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
925 cat >>e${EMULATION_NAME}.c <<EOF
931 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
939 cat >>e${EMULATION_NAME}.c <<EOF
941 /* Look through an expression for an assignment statement. */
944 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
946 bfd_boolean provide = FALSE;
948 switch (exp->type.node_class)
954 /* We call record_link_assignment even if the symbol is defined.
955 This is because if it is defined by a dynamic object, we
956 actually want to use the value defined by the linker script,
957 not the value from the dynamic object (because we are setting
958 symbols like etext). If the symbol is defined by a regular
959 object, then, as it happens, calling record_link_assignment
961 if (strcmp (exp->assign.dst, ".") != 0)
963 if (!bfd_elf_record_link_assignment (output_bfd, &link_info,
964 exp->assign.dst, provide))
965 einfo ("%P%F: failed to record assignment to %s: %E\n",
968 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
972 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
973 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
977 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
978 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
979 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
983 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
992 /* This is called by the before_allocation routine via
993 lang_for_each_statement. It locates any assignment statements, and
994 tells the ELF backend about them, in case they are assignments to
995 symbols which are referred to by dynamic objects. */
998 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1000 if (s->header.type == lang_assignment_statement_enum)
1001 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1006 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1007 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1008 ELF_INTERPRETER_SET_DEFAULT="
1009 if (sinterp != NULL)
1011 sinterp->contents = ${ELF_INTERPRETER_NAME};
1012 sinterp->size = strlen (sinterp->contents) + 1;
1017 ELF_INTERPRETER_SET_DEFAULT=
1019 cat >>e${EMULATION_NAME}.c <<EOF
1021 /* This is called after the sections have been attached to output
1022 sections, but before any sizes or addresses have been set. */
1025 gld${EMULATION_NAME}_before_allocation (void)
1030 if (link_info.hash->type == bfd_link_elf_hash_table)
1031 _bfd_elf_tls_setup (output_bfd, &link_info);
1033 /* If we are going to make any variable assignments, we need to let
1034 the ELF backend know about them in case the variables are
1035 referred to by dynamic objects. */
1036 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1038 /* Let the ELF backend work out the sizes of any sections required
1039 by dynamic linking. */
1040 rpath = command_line.rpath;
1042 rpath = (const char *) getenv ("LD_RUN_PATH");
1043 if (! (bfd_elf_size_dynamic_sections
1044 (output_bfd, command_line.soname, rpath,
1045 command_line.filter_shlib,
1046 (const char * const *) command_line.auxiliary_filters,
1047 &link_info, &sinterp, lang_elf_version_info)))
1048 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1049 ${ELF_INTERPRETER_SET_DEFAULT}
1050 /* Let the user override the dynamic linker we are using. */
1051 if (command_line.interpreter != NULL
1054 sinterp->contents = (bfd_byte *) command_line.interpreter;
1055 sinterp->size = strlen (command_line.interpreter) + 1;
1058 /* Look for any sections named .gnu.warning. As a GNU extensions,
1059 we treat such sections as containing warning messages. We print
1060 out the warning message, and then zero out the section size so
1061 that it does not get copied into the output file. */
1064 LANG_FOR_EACH_INPUT_STATEMENT (is)
1068 bfd_size_type prefix_len;
1071 const char * gnu_warning_prefix = _("warning: ");
1073 if (is->just_syms_flag)
1076 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1081 prefix_len = strlen (gnu_warning_prefix);
1082 msg = xmalloc ((size_t) (prefix_len + sz + 1));
1083 strcpy (msg, gnu_warning_prefix);
1084 if (! bfd_get_section_contents (is->the_bfd, s, msg + prefix_len,
1086 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1088 msg[prefix_len + sz] = '\0';
1089 ret = link_info.callbacks->warning (&link_info, msg,
1090 (const char *) NULL,
1091 is->the_bfd, (asection *) NULL,
1096 /* Clobber the section size, so that we don't waste copying the
1097 warning into the output file. */
1106 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1107 cat >>e${EMULATION_NAME}.c <<EOF
1109 /* Try to open a dynamic archive. This is where we know that ELF
1110 dynamic libraries have an extension of .so (or .sl on oddball systems
1114 gld${EMULATION_NAME}_open_dynamic_archive
1115 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1117 const char *filename;
1120 if (! entry->is_archive)
1123 filename = entry->filename;
1125 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION
1126 is defined, but it does not seem worth the headache to optimize
1127 away those two bytes of space. */
1128 string = (char *) xmalloc (strlen (search->name)
1131 #ifdef EXTRA_SHLIB_EXTENSION
1132 + strlen (EXTRA_SHLIB_EXTENSION)
1134 + sizeof "/lib.so");
1136 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1138 #ifdef EXTRA_SHLIB_EXTENSION
1139 /* Try the .so extension first. If that fails build a new filename
1140 using EXTRA_SHLIB_EXTENSION. */
1141 if (! ldfile_try_open_bfd (string, entry))
1142 sprintf (string, "%s/lib%s%s%s", search->name,
1143 filename, arch, EXTRA_SHLIB_EXTENSION);
1146 if (! ldfile_try_open_bfd (string, entry))
1152 entry->filename = string;
1154 /* We have found a dynamic object to include in the link. The ELF
1155 backend linker will create a DT_NEEDED entry in the .dynamic
1156 section naming this file. If this file includes a DT_SONAME
1157 entry, it will be used. Otherwise, the ELF linker will just use
1158 the name of the file. For an archive found by searching, like
1159 this one, the DT_NEEDED entry should consist of just the name of
1160 the file, without the path information used to find it. Note
1161 that we only need to do this if we have a dynamic object; an
1162 archive will never be referenced by a DT_NEEDED entry.
1164 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1165 very pretty. I haven't been able to think of anything that is
1167 if (bfd_check_format (entry->the_bfd, bfd_object)
1168 && (entry->the_bfd->flags & DYNAMIC) != 0)
1170 ASSERT (entry->is_archive && entry->search_dirs_flag);
1172 /* Rather than duplicating the logic above. Just use the
1173 filename we recorded earlier. */
1175 filename = lbasename (entry->filename);
1176 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1185 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1186 cat >>e${EMULATION_NAME}.c <<EOF
1188 /* A variant of lang_output_section_find used by place_orphan. */
1190 static lang_output_section_statement_type *
1191 output_rel_find (asection *sec, int isdyn)
1193 lang_output_section_statement_type *lookup;
1194 lang_output_section_statement_type *last = NULL;
1195 lang_output_section_statement_type *last_alloc = NULL;
1196 lang_output_section_statement_type *last_rel = NULL;
1197 lang_output_section_statement_type *last_rel_alloc = NULL;
1198 int rela = sec->name[4] == 'a';
1200 for (lookup = &lang_output_section_statement.head->output_section_statement;
1202 lookup = lookup->next)
1204 if (lookup->constraint != -1
1205 && strncmp (".rel", lookup->name, 4) == 0)
1207 int lookrela = lookup->name[4] == 'a';
1209 /* .rel.dyn must come before all other reloc sections, to suit
1214 /* Don't place after .rel.plt as doing so results in wrong
1216 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1219 if (rela == lookrela || last_rel == NULL)
1221 if ((rela == lookrela || last_rel_alloc == NULL)
1222 && lookup->bfd_section != NULL
1223 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1224 last_rel_alloc = lookup;
1228 if (lookup->bfd_section != NULL
1229 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1230 last_alloc = lookup;
1234 return last_rel_alloc;
1245 /* Place an orphan section. We use this to put random SHF_ALLOC
1246 sections in the right segment. */
1249 gld${EMULATION_NAME}_place_orphan (lang_input_statement_type *file, asection *s)
1251 static struct orphan_save hold[] =
1254 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1257 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1260 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1266 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1269 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1272 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1275 enum orphan_save_index
1285 static int orphan_init_done = 0;
1286 struct orphan_save *place;
1287 const char *secname;
1288 lang_output_section_statement_type *after;
1289 lang_output_section_statement_type *os;
1292 secname = bfd_get_section_name (s->owner, s);
1294 if (! link_info.relocatable
1295 && link_info.combreloc
1296 && (s->flags & SEC_ALLOC)
1297 && strncmp (secname, ".rel", 4) == 0)
1299 if (secname[4] == 'a')
1300 secname = ".rela.dyn";
1302 secname = ".rel.dyn";
1306 if (isdyn || (!config.unique_orphan_sections && !unique_section_p (s)))
1308 /* Look through the script to see where to place this section. */
1309 os = lang_output_section_find (secname);
1312 && (os->bfd_section == NULL
1313 || os->bfd_section->flags == 0
1314 || ((s->flags ^ os->bfd_section->flags)
1315 & (SEC_LOAD | SEC_ALLOC)) == 0))
1317 /* We already have an output section statement with this
1318 name, and its bfd section, if any, has compatible flags.
1319 If the section already exists but does not have any flags
1320 set, then it has been created by the linker, probably as a
1321 result of a --section-start command line switch. */
1322 lang_add_section (&os->children, s, os, file);
1327 if (!orphan_init_done)
1329 struct orphan_save *ho;
1330 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1331 if (ho->name != NULL)
1333 ho->os = lang_output_section_find (ho->name);
1334 if (ho->os != NULL && ho->os->flags == 0)
1335 ho->os->flags = ho->flags;
1337 orphan_init_done = 1;
1340 /* If this is a final link, then always put .gnu.warning.SYMBOL
1341 sections into the .text section to get them out of the way. */
1342 if (link_info.executable
1343 && ! link_info.relocatable
1344 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0
1345 && hold[orphan_text].os != NULL)
1347 lang_add_section (&hold[orphan_text].os->children, s,
1348 hold[orphan_text].os, file);
1352 /* Decide which segment the section should go in based on the
1353 section name and section flags. We put loadable .note sections
1354 right after the .interp section, so that the PT_NOTE segment is
1355 stored right after the program headers where the OS can read it
1356 in the first page. */
1359 if ((s->flags & SEC_ALLOC) == 0)
1361 else if ((s->flags & SEC_LOAD) != 0
1362 && strncmp (secname, ".note", 5) == 0)
1363 place = &hold[orphan_interp];
1364 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1365 place = &hold[orphan_bss];
1366 else if ((s->flags & SEC_SMALL_DATA) != 0)
1367 place = &hold[orphan_sdata];
1368 else if ((s->flags & SEC_READONLY) == 0)
1369 place = &hold[orphan_data];
1370 else if (strncmp (secname, ".rel", 4) == 0
1371 && (s->flags & SEC_LOAD) != 0)
1372 place = &hold[orphan_rel];
1373 else if ((s->flags & SEC_CODE) == 0)
1374 place = &hold[orphan_rodata];
1376 place = &hold[orphan_text];
1381 if (place->os == NULL)
1383 if (place->name != NULL)
1384 place->os = lang_output_section_find (place->name);
1386 place->os = output_rel_find (s, isdyn);
1390 after = lang_output_section_find_by_flags (s, &place->os);
1392 /* *ABS* is always the first output section statement. */
1393 after = &lang_output_section_statement.head->output_section_statement;
1396 /* Choose a unique name for the section. This will be needed if the
1397 same section name appears in the input file with different
1398 loadable or allocatable characteristics. */
1399 if (bfd_get_section_by_name (output_bfd, secname) != NULL)
1401 static int count = 1;
1402 secname = bfd_get_unique_section_name (output_bfd, secname, &count);
1403 if (secname == NULL)
1404 einfo ("%F%P: place_orphan failed: %E\n");
1407 lang_insert_orphan (file, s, secname, after, place, NULL, NULL);
1414 if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
1415 cat >>e${EMULATION_NAME}.c <<EOF
1418 gld${EMULATION_NAME}_finish (void)
1420 if (bfd_elf_discard_info (output_bfd, &link_info))
1422 lang_reset_memory_regions ();
1424 /* Resize the sections. */
1425 lang_size_sections (stat_ptr->head, abs_output_section,
1426 &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE);
1428 /* Redo special stuff. */
1429 ldemul_after_allocation ();
1431 /* Do the assignments again. */
1432 lang_do_assignments (stat_ptr->head, abs_output_section,
1433 (fill_type *) 0, (bfd_vma) 0);
1439 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
1440 cat >>e${EMULATION_NAME}.c <<EOF
1443 gld${EMULATION_NAME}_get_script (int *isfile)
1446 if test -n "$COMPILE_IN"
1448 # Scripts compiled in.
1450 # sed commands to quote an ld script as a C string.
1451 sc="-f stringify.sed"
1453 cat >>e${EMULATION_NAME}.c <<EOF
1457 if (link_info.relocatable && config.build_constructors)
1460 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1461 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1462 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1463 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1464 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1465 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
1466 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1467 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1469 if test -n "$GENERATE_PIE_SCRIPT" ; then
1470 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1471 echo ' ; else if (link_info.pie && link_info.combreloc' >> e${EMULATION_NAME}.c
1472 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1473 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1474 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
1475 echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1476 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
1478 echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c
1479 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
1481 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1482 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1483 echo ' ; else if (link_info.shared && link_info.combreloc' >> e${EMULATION_NAME}.c
1484 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
1485 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1486 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
1487 echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
1488 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
1490 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1491 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1493 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1494 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
1495 echo ' && (link_info.flags & DT_BIND_NOW)) return' >> e${EMULATION_NAME}.c
1496 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
1497 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
1498 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
1500 echo ' ; else return' >> e${EMULATION_NAME}.c
1501 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1502 echo '; }' >> e${EMULATION_NAME}.c
1505 # Scripts read from the filesystem.
1507 cat >>e${EMULATION_NAME}.c <<EOF
1511 if (link_info.relocatable && config.build_constructors)
1512 return "ldscripts/${EMULATION_NAME}.xu";
1513 else if (link_info.relocatable)
1514 return "ldscripts/${EMULATION_NAME}.xr";
1515 else if (!config.text_read_only)
1516 return "ldscripts/${EMULATION_NAME}.xbn";
1518 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
1520 cat >>e${EMULATION_NAME}.c <<EOF
1521 else if (!config.magic_demand_paged)
1522 return "ldscripts/${EMULATION_NAME}.xn";
1525 if test -n "$GENERATE_PIE_SCRIPT" ; then
1526 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1527 cat >>e${EMULATION_NAME}.c <<EOF
1528 else if (link_info.pie && link_info.combreloc
1529 && link_info.relro && (link_info.flags & DT_BIND_NOW))
1530 return "ldscripts/${EMULATION_NAME}.xdw";
1531 else if (link_info.pie && link_info.combreloc)
1532 return "ldscripts/${EMULATION_NAME}.xdc";
1535 cat >>e${EMULATION_NAME}.c <<EOF
1536 else if (link_info.pie)
1537 return "ldscripts/${EMULATION_NAME}.xd";
1540 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1541 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1542 cat >>e${EMULATION_NAME}.c <<EOF
1543 else if (link_info.shared && link_info.combreloc
1544 && link_info.relro && (link_info.flags & DT_BIND_NOW))
1545 return "ldscripts/${EMULATION_NAME}.xsw";
1546 else if (link_info.shared && link_info.combreloc)
1547 return "ldscripts/${EMULATION_NAME}.xsc";
1550 cat >>e${EMULATION_NAME}.c <<EOF
1551 else if (link_info.shared)
1552 return "ldscripts/${EMULATION_NAME}.xs";
1555 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
1556 cat >>e${EMULATION_NAME}.c <<EOF
1557 else if (link_info.combreloc && link_info.relro
1558 && (link_info.flags & DT_BIND_NOW))
1559 return "ldscripts/${EMULATION_NAME}.xw";
1560 else if (link_info.combreloc)
1561 return "ldscripts/${EMULATION_NAME}.xc";
1564 cat >>e${EMULATION_NAME}.c <<EOF
1566 return "ldscripts/${EMULATION_NAME}.x";
1573 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1575 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
1576 cat >>e${EMULATION_NAME}.c <<EOF
1577 $PARSE_AND_LIST_PROLOGUE
1581 cat >>e${EMULATION_NAME}.c <<EOF
1583 #define OPTION_DISABLE_NEW_DTAGS (400)
1584 #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1)
1585 #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1)
1586 #define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1)
1587 #define OPTION_EXCLUDE_LIBS (OPTION_EH_FRAME_HDR + 1)
1590 gld${EMULATION_NAME}_add_options
1591 (int ns, char **shortopts, int nl, struct option **longopts,
1592 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
1594 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
1595 static const struct option xtra_long[] = {
1598 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1599 cat >>e${EMULATION_NAME}.c <<EOF
1600 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
1601 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
1602 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
1603 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
1604 {"Bgroup", no_argument, NULL, OPTION_GROUP},
1608 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
1609 cat >>e${EMULATION_NAME}.c <<EOF
1610 $PARSE_AND_LIST_LONGOPTS
1614 cat >>e${EMULATION_NAME}.c <<EOF
1615 {NULL, no_argument, NULL, 0}
1618 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
1619 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
1620 *longopts = (struct option *)
1621 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
1622 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
1626 gld${EMULATION_NAME}_handle_option (int optc)
1635 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1636 cat >>e${EMULATION_NAME}.c <<EOF
1637 case OPTION_DISABLE_NEW_DTAGS:
1638 link_info.new_dtags = FALSE;
1641 case OPTION_ENABLE_NEW_DTAGS:
1642 link_info.new_dtags = TRUE;
1645 case OPTION_EH_FRAME_HDR:
1646 link_info.eh_frame_hdr = TRUE;
1650 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
1651 /* Groups must be self-contained. */
1652 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1653 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
1656 case OPTION_EXCLUDE_LIBS:
1657 add_excluded_libs (optarg);
1661 if (strcmp (optarg, "initfirst") == 0)
1662 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
1663 else if (strcmp (optarg, "interpose") == 0)
1664 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
1665 else if (strcmp (optarg, "loadfltr") == 0)
1666 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
1667 else if (strcmp (optarg, "nodefaultlib") == 0)
1668 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
1669 else if (strcmp (optarg, "nodelete") == 0)
1670 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
1671 else if (strcmp (optarg, "nodlopen") == 0)
1672 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
1673 else if (strcmp (optarg, "nodump") == 0)
1674 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
1675 else if (strcmp (optarg, "now") == 0)
1677 link_info.flags |= (bfd_vma) DF_BIND_NOW;
1678 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
1680 else if (strcmp (optarg, "origin") == 0)
1682 link_info.flags |= (bfd_vma) DF_ORIGIN;
1683 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
1685 else if (strcmp (optarg, "defs") == 0)
1686 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
1687 else if (strcmp (optarg, "muldefs") == 0)
1688 link_info.allow_multiple_definition = TRUE;
1689 else if (strcmp (optarg, "combreloc") == 0)
1690 link_info.combreloc = TRUE;
1691 else if (strcmp (optarg, "nocombreloc") == 0)
1692 link_info.combreloc = FALSE;
1693 else if (strcmp (optarg, "nocopyreloc") == 0)
1694 link_info.nocopyreloc = TRUE;
1695 else if (strcmp (optarg, "execstack") == 0)
1697 link_info.execstack = TRUE;
1698 link_info.noexecstack = FALSE;
1700 else if (strcmp (optarg, "noexecstack") == 0)
1702 link_info.noexecstack = TRUE;
1703 link_info.execstack = FALSE;
1705 else if (strcmp (optarg, "relro") == 0)
1706 link_info.relro = TRUE;
1707 else if (strcmp (optarg, "norelro") == 0)
1708 link_info.relro = FALSE;
1709 /* What about the other Solaris -z options? FIXME. */
1714 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
1715 cat >>e${EMULATION_NAME}.c <<EOF
1716 $PARSE_AND_LIST_ARGS_CASES
1720 cat >>e${EMULATION_NAME}.c <<EOF
1728 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
1729 cat >>e${EMULATION_NAME}.c <<EOF
1732 gld${EMULATION_NAME}_list_options (FILE * file)
1736 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
1737 cat >>e${EMULATION_NAME}.c <<EOF
1738 fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n"));
1739 fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n"));
1740 fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n"));
1741 fprintf (file, _(" --eh-frame-hdr\tCreate .eh_frame_hdr section\n"));
1742 fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n"));
1743 fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n"));
1744 fprintf (file, _(" -z execstack\t\tMark executable as requiring executable stack\n"));
1745 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n"));
1746 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n"));
1747 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n"));
1748 fprintf (file, _(" -z muldefs\t\tAllow multiple definitions\n"));
1749 fprintf (file, _(" -z nocombreloc\tDon't merge dynamic relocs into one section\n"));
1750 fprintf (file, _(" -z nocopyreloc\tDon't create copy relocs\n"));
1751 fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n"));
1752 fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n"));
1753 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n"));
1754 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n"));
1755 fprintf (file, _(" -z noexecstack\tMark executable as not requiring executable stack\n"));
1756 fprintf (file, _(" -z norelro\t\tDon't create RELRO program header\n"));
1757 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n"));
1758 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t at runtime\n"));
1759 fprintf (file, _(" -z relro\t\tCreate RELRO program header\n"));
1760 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n"));
1764 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
1765 cat >>e${EMULATION_NAME}.c <<EOF
1766 $PARSE_AND_LIST_OPTIONS
1770 cat >>e${EMULATION_NAME}.c <<EOF
1774 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
1775 cat >>e${EMULATION_NAME}.c <<EOF
1776 $PARSE_AND_LIST_EPILOGUE
1781 cat >>e${EMULATION_NAME}.c <<EOF
1782 #define gld${EMULATION_NAME}_add_options NULL
1783 #define gld${EMULATION_NAME}_handle_option NULL
1785 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
1786 cat >>e${EMULATION_NAME}.c <<EOF
1787 #define gld${EMULATION_NAME}_list_options NULL
1792 cat >>e${EMULATION_NAME}.c <<EOF
1794 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1796 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
1797 ${LDEMUL_SYSLIB-syslib_default},
1798 ${LDEMUL_HLL-hll_default},
1799 ${LDEMUL_AFTER_PARSE-after_parse_default},
1800 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
1801 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
1802 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
1803 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
1804 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
1805 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
1806 "${EMULATION_NAME}",
1808 ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish},
1809 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
1810 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
1811 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
1812 ${LDEMUL_SET_SYMBOLS-NULL},
1813 ${LDEMUL_PARSE_ARGS-NULL},
1814 gld${EMULATION_NAME}_add_options,
1815 gld${EMULATION_NAME}_handle_option,
1816 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
1817 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
1818 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
1819 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
1820 ${LDEMUL_NEW_VERS_PATTERN-NULL}