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 cat >e${EMULATION_NAME}.c <<EOF
7 /* This file is is generated by a shell script. DO NOT EDIT! */
9 /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
10 Copyright (C) 1991, 93, 94, 95, 96, 97, 98, 1999
11 Free Software Foundation, Inc.
12 Written by Steve Chamberlain <sac@cygnus.com>
13 ELF support by Ian Lance Taylor <ian@cygnus.com>
15 This file is part of GLD, the Gnu Linker.
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
31 #define TARGET_IS_${EMULATION_NAME}
49 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
50 static boolean gld${EMULATION_NAME}_open_dynamic_archive
51 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
52 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
53 static void gld${EMULATION_NAME}_check_needed
54 PARAMS ((lang_input_statement_type *));
55 static void gld${EMULATION_NAME}_stat_needed
56 PARAMS ((lang_input_statement_type *));
57 static boolean gld${EMULATION_NAME}_search_needed
58 PARAMS ((const char *, const char *, int));
59 static boolean gld${EMULATION_NAME}_try_needed PARAMS ((const char *, int));
60 static void gld${EMULATION_NAME}_vercheck
61 PARAMS ((lang_input_statement_type *));
62 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
63 static void gld${EMULATION_NAME}_find_statement_assignment
64 PARAMS ((lang_statement_union_type *));
65 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
66 static boolean gld${EMULATION_NAME}_place_orphan
67 PARAMS ((lang_input_statement_type *, asection *));
68 static void gld${EMULATION_NAME}_place_section
69 PARAMS ((lang_statement_union_type *));
70 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
73 gld${EMULATION_NAME}_before_parse()
75 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`;
76 config.dynamic_link = ${DYNAMIC_LINK-true};
77 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
80 /* Try to open a dynamic archive. This is where we know that ELF
81 dynamic libraries have an extension of .so (or .sl on oddball systems
85 gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
87 search_dirs_type *search;
88 lang_input_statement_type *entry;
93 if (! entry->is_archive)
96 filename = entry->filename;
98 string = (char *) xmalloc (strlen (search->name)
103 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
105 if (! ldfile_try_open_bfd (string, entry))
107 /* It failed using .so, try again with .sl for oddball systems
108 that use a different naming scheme (ie hpux). */
109 sprintf (string, "%s/lib%s%s.sl", search->name, filename, arch);
111 if (! ldfile_try_open_bfd (string, entry))
118 entry->filename = string;
120 /* We have found a dynamic object to include in the link. The ELF
121 backend linker will create a DT_NEEDED entry in the .dynamic
122 section naming this file. If this file includes a DT_SONAME
123 entry, it will be used. Otherwise, the ELF linker will just use
124 the name of the file. For an archive found by searching, like
125 this one, the DT_NEEDED entry should consist of just the name of
126 the file, without the path information used to find it. Note
127 that we only need to do this if we have a dynamic object; an
128 archive will never be referenced by a DT_NEEDED entry.
130 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
131 very pretty. I haven't been able to think of anything that is
133 if (bfd_check_format (entry->the_bfd, bfd_object)
134 && (entry->the_bfd->flags & DYNAMIC) != 0)
136 char *filname, *needed_name;
138 ASSERT (entry->is_archive && entry->search_dirs_flag);
140 /* Rather than duplicating the logic above. Just use the
141 filename we recorded earlier.o
143 First strip off everything before the last '/'. */
144 filename = strrchr (entry->filename, '/');
147 needed_name = (char *) xmalloc (strlen (filename) + 1);
148 strcpy (needed_name, filename);
149 bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name);
156 if [ "x${host}" = "x${target}" ] ; then
157 case " ${EMULATION_LIBPATH} " in
158 *" ${EMULATION_NAME} "*)
159 cat >>e${EMULATION_NAME}.c <<EOF
161 /* For a native linker, check the file /etc/ld.so.conf for directories
162 in which we may find shared libraries. /etc/ld.so.conf is really
163 only meaningful on Linux, but we check it on other systems anyhow. */
165 static boolean gld${EMULATION_NAME}_check_ld_so_conf
166 PARAMS ((const char *, int));
169 gld${EMULATION_NAME}_check_ld_so_conf (name, force)
173 static boolean initialized;
174 static char *ld_so_conf;
180 f = fopen ("/etc/ld.so.conf", FOPEN_RT);
189 b = (char *) xmalloc (alloc);
191 while ((c = getc (f)) != EOF)
193 if (len + 1 >= alloc)
196 b = (char *) xrealloc (b, alloc);
209 if (len > 0 && b[len - 1] != ':')
217 if (len > 0 && b[len - 1] == ':')
236 if (ld_so_conf == NULL)
239 return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force);
246 cat >>e${EMULATION_NAME}.c <<EOF
248 /* These variables are required to pass information back and forth
249 between after_open and check_needed and stat_needed and vercheck. */
251 static struct bfd_link_needed_list *global_needed;
252 static struct stat global_stat;
253 static boolean global_found;
254 static struct bfd_link_needed_list *global_vercheck_needed;
255 static boolean global_vercheck_failed;
257 /* This is called after all the input files have been opened. */
260 gld${EMULATION_NAME}_after_open ()
262 struct bfd_link_needed_list *needed, *l;
264 /* We only need to worry about this when doing a final link. */
265 if (link_info.relocateable || link_info.shared)
268 /* Get the list of files which appear in DT_NEEDED entries in
269 dynamic objects included in the link (often there will be none).
270 For each such file, we want to track down the corresponding
271 library, and include the symbol table in the link. This is what
272 the runtime dynamic linker will do. Tracking the files down here
273 permits one dynamic object to include another without requiring
274 special action by the person doing the link. Note that the
275 needed list can actually grow while we are stepping through this
277 needed = bfd_elf_get_needed_list (output_bfd, &link_info);
278 for (l = needed; l != NULL; l = l->next)
280 struct bfd_link_needed_list *ll;
283 /* If we've already seen this file, skip it. */
284 for (ll = needed; ll != l; ll = ll->next)
285 if (strcmp (ll->name, l->name) == 0)
290 /* See if this file was included in the link explicitly. */
292 global_found = false;
293 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
297 /* We need to find this file and include the symbol table. We
298 want to search for the file in the same way that the dynamic
299 linker will search. That means that we want to use
300 rpath_link, rpath, then the environment variable
301 LD_LIBRARY_PATH (native only), then the linker script
302 LIB_SEARCH_DIRS. We do not search using the -L arguments.
304 We search twice. The first time, we skip objects which may
305 introduce version mismatches. The second time, we force
306 their use. See gld${EMULATION_NAME}_vercheck comment. */
307 for (force = 0; force < 2; force++)
309 const char *lib_path;
311 search_dirs_type *search;
313 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
316 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
319 if (command_line.rpath_link == NULL
320 && command_line.rpath == NULL)
322 lib_path = (const char *) getenv ("LD_RUN_PATH");
323 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name,
328 if [ "x${host}" = "x${target}" ] ; then
329 case " ${EMULATION_LIBPATH} " in
330 *" ${EMULATION_NAME} "*)
331 cat >>e${EMULATION_NAME}.c <<EOF
332 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
333 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force))
339 cat >>e${EMULATION_NAME}.c <<EOF
340 len = strlen (l->name);
341 for (search = search_head; search != NULL; search = search->next)
347 filename = (char *) xmalloc (strlen (search->name) + len + 2);
348 sprintf (filename, "%s/%s", search->name, l->name);
349 if (gld${EMULATION_NAME}_try_needed (filename, force))
356 if [ "x${host}" = "x${target}" ] ; then
357 case " ${EMULATION_LIBPATH} " in
358 *" ${EMULATION_NAME} "*)
359 cat >>e${EMULATION_NAME}.c <<EOF
360 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
366 cat >>e${EMULATION_NAME}.c <<EOF
372 einfo ("%P: warning: %s, needed by %B, not found (try using --rpath)\n",
377 /* Search for a needed file in a path. */
380 gld${EMULATION_NAME}_search_needed (path, name, force)
388 if (path == NULL || *path == '\0')
393 char *filename, *sset;
395 s = strchr (path, ':');
397 s = path + strlen (path);
399 filename = (char *) xmalloc (s - path + len + 2);
404 memcpy (filename, path, s - path);
405 filename[s - path] = '/';
406 sset = filename + (s - path) + 1;
410 if (gld${EMULATION_NAME}_try_needed (filename, force))
423 /* This function is called for each possible name for a dynamic object
424 named by a DT_NEEDED entry. The FORCE parameter indicates whether
425 to skip the check for a conflicting version. */
428 gld${EMULATION_NAME}_try_needed (name, force)
434 abfd = bfd_openr (name, bfd_get_target (output_bfd));
437 if (! bfd_check_format (abfd, bfd_object))
439 (void) bfd_close (abfd);
442 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
444 (void) bfd_close (abfd);
448 /* Check whether this object would include any conflicting library
449 versions. If FORCE is set, then we skip this check; we use this
450 the second time around, if we couldn't find any compatible
451 instance of the shared library. */
455 struct bfd_link_needed_list *needed;
457 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
458 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
462 global_vercheck_needed = needed;
463 global_vercheck_failed = false;
464 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
465 if (global_vercheck_failed)
467 (void) bfd_close (abfd);
468 /* Return false to force the caller to move on to try
469 another file on the search path. */
473 /* But wait! It gets much worse. On Linux, if a shared
474 library does not use libc at all, we are supposed to skip
475 it the first time around in case we encounter a shared
476 library later on with the same name which does use the
477 version of libc that we want. This is much too horrible
478 to use on any system other than Linux. */
483 cat >>e${EMULATION_NAME}.c <<EOF
485 struct bfd_link_needed_list *l;
487 for (l = needed; l != NULL; l = l->next)
488 if (strncmp (l->name, "libc.so", 7) == 0)
492 (void) bfd_close (abfd);
500 cat >>e${EMULATION_NAME}.c <<EOF
504 /* We've found a dynamic object matching the DT_NEEDED entry. */
506 /* We have already checked that there is no other input file of the
507 same name. We must now check again that we are not including the
508 same file twice. We need to do this because on many systems
509 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
510 reference libc.so.1. If we have already included libc.so, we
511 don't want to include libc.so.1 if they are the same file, and we
512 can only check that using stat. */
514 if (bfd_stat (abfd, &global_stat) != 0)
515 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
516 global_found = false;
517 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
520 /* Return true to indicate that we found the file, even though
521 we aren't going to do anything with it. */
525 /* Tell the ELF backend that don't want the output file to have a
526 DT_NEEDED entry for this file. */
527 bfd_elf_set_dt_needed_name (abfd, "");
529 /* Add this file into the symbol table. */
530 if (! bfd_link_add_symbols (abfd, &link_info))
531 einfo ("%F%B: could not read symbols: %E\n", abfd);
536 /* See if an input file matches a DT_NEEDED entry by name. */
539 gld${EMULATION_NAME}_check_needed (s)
540 lang_input_statement_type *s;
545 if (s->filename != NULL
546 && strcmp (s->filename, global_needed->name) == 0)
552 if (s->the_bfd != NULL)
556 soname = bfd_elf_get_dt_soname (s->the_bfd);
558 && strcmp (soname, global_needed->name) == 0)
565 if (s->search_dirs_flag
566 && s->filename != NULL
567 && strchr (global_needed->name, '/') == NULL)
571 f = strrchr (s->filename, '/');
573 && strcmp (f + 1, global_needed->name) == 0)
581 /* See if an input file matches a DT_NEEDED entry by running stat on
585 gld${EMULATION_NAME}_stat_needed (s)
586 lang_input_statement_type *s;
595 if (s->the_bfd == NULL)
598 if (bfd_stat (s->the_bfd, &st) != 0)
600 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
604 if (st.st_dev == global_stat.st_dev
605 && st.st_ino == global_stat.st_ino)
611 /* We issue a warning if it looks like we are including two
612 different versions of the same shared library. For example,
613 there may be a problem if -lc picks up libc.so.6 but some other
614 shared library has a DT_NEEDED entry of libc.so.5. This is a
615 hueristic test, and it will only work if the name looks like
616 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
617 If we really want to issue warnings about mixing version numbers
618 of shared libraries, we need to find a better way. */
620 if (strchr (global_needed->name, '/') != NULL)
622 suffix = strstr (global_needed->name, ".so.");
625 suffix += sizeof ".so." - 1;
627 soname = bfd_elf_get_dt_soname (s->the_bfd);
629 soname = s->filename;
631 f = strrchr (soname, '/');
637 if (strncmp (f, global_needed->name, suffix - global_needed->name) == 0)
638 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
639 global_needed->name, global_needed->by, f);
642 /* On Linux, it's possible to have different versions of the same
643 shared library linked against different versions of libc. The
644 dynamic linker somehow tags which libc version to use in
645 /etc/ld.so.cache, and, based on the libc that it sees in the
646 executable, chooses which version of the shared library to use.
648 We try to do a similar check here by checking whether this shared
649 library needs any other shared libraries which may conflict with
650 libraries we have already included in the link. If it does, we
651 skip it, and try to find another shared library farther on down the
654 This is called via lang_for_each_input_file.
655 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
656 which we ar checking. This sets GLOBAL_VERCHECK_FAILED if we find
657 a conflicting version. */
660 gld${EMULATION_NAME}_vercheck (s)
661 lang_input_statement_type *s;
663 const char *soname, *f;
664 struct bfd_link_needed_list *l;
666 if (global_vercheck_failed)
668 if (s->the_bfd == NULL
669 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
672 soname = bfd_elf_get_dt_soname (s->the_bfd);
674 soname = bfd_get_filename (s->the_bfd);
676 f = strrchr (soname, '/');
682 for (l = global_vercheck_needed; l != NULL; l = l->next)
686 if (strcmp (f, l->name) == 0)
688 /* Probably can't happen, but it's an easy check. */
692 if (strchr (l->name, '/') != NULL)
695 suffix = strstr (l->name, ".so.");
699 suffix += sizeof ".so." - 1;
701 if (strncmp (f, l->name, suffix - l->name) == 0)
703 /* Here we know that S is a dynamic object FOO.SO.VER1, and
704 the object we are considering needs a dynamic object
705 FOO.SO.VER2, and VER1 and VER2 are different. This
706 appears to be a version mismatch, so we tell the caller
707 to try a different version of this library. */
708 global_vercheck_failed = true;
714 /* This is called after the sections have been attached to output
715 sections, but before any sizes or addresses have been set. */
718 gld${EMULATION_NAME}_before_allocation ()
723 /* If we are going to make any variable assignments, we need to let
724 the ELF backend know about them in case the variables are
725 referred to by dynamic objects. */
726 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
728 /* Let the ELF backend work out the sizes of any sections required
729 by dynamic linking. */
730 rpath = command_line.rpath;
732 rpath = (const char *) getenv ("LD_RUN_PATH");
733 if (! (bfd_elf${ELFSIZE}_size_dynamic_sections
734 (output_bfd, command_line.soname, rpath,
735 command_line.export_dynamic, command_line.filter_shlib,
736 (const char * const *) command_line.auxiliary_filters,
737 &link_info, &sinterp, lang_elf_version_info)))
738 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
740 /* Let the user override the dynamic linker we are using. */
741 if (command_line.interpreter != NULL
744 sinterp->contents = (bfd_byte *) command_line.interpreter;
745 sinterp->_raw_size = strlen (command_line.interpreter) + 1;
748 /* Look for any sections named .gnu.warning. As a GNU extensions,
749 we treat such sections as containing warning messages. We print
750 out the warning message, and then zero out the section size so
751 that it does not get copied into the output file. */
754 LANG_FOR_EACH_INPUT_STATEMENT (is)
761 if (is->just_syms_flag)
764 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
768 sz = bfd_section_size (is->the_bfd, s);
769 msg = xmalloc ((size_t) sz + 1);
770 if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz))
771 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
774 ret = link_info.callbacks->warning (&link_info, msg,
776 is->the_bfd, (asection *) NULL,
781 /* Clobber the section size, so that we don't waste copying the
782 warning into the output file. */
788 /* This is called by the before_allocation routine via
789 lang_for_each_statement. It locates any assignment statements, and
790 tells the ELF backend about them, in case they are assignments to
791 symbols which are referred to by dynamic objects. */
794 gld${EMULATION_NAME}_find_statement_assignment (s)
795 lang_statement_union_type *s;
797 if (s->header.type == lang_assignment_statement_enum)
798 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
801 /* Look through an expression for an assignment statement. */
804 gld${EMULATION_NAME}_find_exp_assignment (exp)
807 struct bfd_link_hash_entry *h;
809 switch (exp->type.node_class)
812 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
813 false, false, false);
817 /* We call record_link_assignment even if the symbol is defined.
818 This is because if it is defined by a dynamic object, we
819 actually want to use the value defined by the linker script,
820 not the value from the dynamic object (because we are setting
821 symbols like etext). If the symbol is defined by a regular
822 object, then, as it happens, calling record_link_assignment
827 if (strcmp (exp->assign.dst, ".") != 0)
829 if (! (bfd_elf${ELFSIZE}_record_link_assignment
830 (output_bfd, &link_info, exp->assign.dst,
831 exp->type.node_class == etree_provide ? true : false)))
832 einfo ("%P%F: failed to record assignment to %s: %E\n",
835 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
839 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
840 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
844 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
845 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
846 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
850 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
858 /* Place an orphan section. We use this to put random SHF_ALLOC
859 sections in the right segment. */
861 static asection *hold_section;
862 static lang_output_section_statement_type *hold_use;
863 static lang_output_section_statement_type *hold_text;
864 static lang_output_section_statement_type *hold_rodata;
865 static lang_output_section_statement_type *hold_data;
866 static lang_output_section_statement_type *hold_bss;
867 static lang_output_section_statement_type *hold_rel;
868 static lang_output_section_statement_type *hold_interp;
872 gld${EMULATION_NAME}_place_orphan (file, s)
873 lang_input_statement_type *file;
876 lang_output_section_statement_type *place;
877 asection *snew, **pps;
878 lang_statement_list_type *old;
879 lang_statement_list_type add;
881 const char *secname, *ps;
882 const char *outsecname;
883 lang_output_section_statement_type *os;
885 if ((s->flags & SEC_ALLOC) == 0)
888 /* Look through the script to see where to place this section. */
891 lang_for_each_statement (gld${EMULATION_NAME}_place_section);
893 if (hold_use != NULL)
895 /* We have already placed a section with this name. */
896 wild_doit (&hold_use->children, s, hold_use, file);
900 secname = bfd_get_section_name (s->owner, s);
902 /* If this is a final link, then always put .gnu.warning.SYMBOL
903 sections into the .text section to get them out of the way. */
904 if (! link_info.shared
905 && ! link_info.relocateable
906 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0
907 && hold_text != NULL)
909 wild_doit (&hold_text->children, s, hold_text, file);
913 /* Decide which segment the section should go in based on the
914 section name and section flags. We put loadable .note sections
915 right after the .interp section, so that the PT_NOTE segment is
916 stored right after the program headers where the OS can read it
917 in the first page. */
919 if (s->flags & SEC_EXCLUDE)
921 else if ((s->flags & SEC_LOAD) != 0
922 && strncmp (secname, ".note", 4) == 0
923 && hold_interp != NULL)
925 else if ((s->flags & SEC_HAS_CONTENTS) == 0
928 else if ((s->flags & SEC_READONLY) == 0
929 && hold_data != NULL)
931 else if (strncmp (secname, ".rel", 4) == 0
934 else if ((s->flags & SEC_CODE) == 0
935 && (s->flags & SEC_READONLY) != 0
936 && hold_rodata != NULL)
938 else if ((s->flags & SEC_READONLY) != 0
939 && hold_text != NULL)
944 /* Choose a unique name for the section. This will be needed if the
945 same section name appears in the input file with different
946 loadable or allocateable characteristics. */
947 outsecname = secname;
948 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
954 len = strlen (outsecname);
955 newname = xmalloc (len + 5);
956 strcpy (newname, outsecname);
960 sprintf (newname + len, "%d", i);
963 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
965 outsecname = newname;
968 /* Create the section in the output file, and put it in the right
969 place. This shuffling is to make the output file look neater. */
970 snew = bfd_make_section (output_bfd, outsecname);
972 einfo ("%P%F: output format %s cannot represent section called %s\n",
973 output_bfd->xvec->name, outsecname);
974 if (place->bfd_section != NULL)
976 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
979 snew->next = place->bfd_section->next;
980 place->bfd_section->next = snew;
983 /* Start building a list of statements for this section. */
986 lang_list_init (stat_ptr);
988 /* If the name of the section is representable in C, then create
989 symbols to mark the start and the end of the section. */
990 for (ps = outsecname; *ps != '\0'; ps++)
991 if (! isalnum ((unsigned char) *ps) && *ps != '_')
993 if (*ps == '\0' && config.build_constructors)
997 symname = (char *) xmalloc (ps - outsecname + sizeof "__start_");
998 sprintf (symname, "__start_%s", outsecname);
999 lang_add_assignment (exp_assop ('=', symname,
1001 exp_intop ((bfd_vma) 1
1002 << s->alignment_power))));
1005 if (! link_info.relocateable)
1008 address = exp_intop ((bfd_vma) 0);
1010 lang_enter_output_section_statement (outsecname, address, 0,
1012 (etree_type *) NULL,
1013 (etree_type *) NULL,
1014 (etree_type *) NULL);
1016 os = lang_output_section_statement_lookup (outsecname);
1017 wild_doit (&os->children, s, os, file);
1019 lang_leave_output_section_statement
1020 ((bfd_vma) 0, "*default*", (struct lang_output_section_phdr_list *) NULL);
1023 if (*ps == '\0' && config.build_constructors)
1027 symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_");
1028 sprintf (symname, "__stop_%s", outsecname);
1029 lang_add_assignment (exp_assop ('=', symname,
1030 exp_nameop (NAME, ".")));
1033 /* Now stick the new statement list right after PLACE. */
1034 *add.tail = place->header.next;
1035 place->header.next = add.head;
1043 gld${EMULATION_NAME}_place_section (s)
1044 lang_statement_union_type *s;
1046 lang_output_section_statement_type *os;
1048 if (s->header.type != lang_output_section_statement_enum)
1051 os = &s->output_section_statement;
1053 if (strcmp (os->name, hold_section->name) == 0
1054 && os->bfd_section != NULL
1055 && ((hold_section->flags & (SEC_LOAD | SEC_ALLOC))
1056 == (os->bfd_section->flags & (SEC_LOAD | SEC_ALLOC))))
1059 if (strcmp (os->name, ".text") == 0)
1061 else if (strcmp (os->name, ".rodata") == 0)
1063 else if (strcmp (os->name, ".data") == 0)
1065 else if (strcmp (os->name, ".bss") == 0)
1067 else if (hold_rel == NULL
1068 && os->bfd_section != NULL
1069 && (os->bfd_section->flags & SEC_ALLOC) != 0
1070 && strncmp (os->name, ".rel", 4) == 0)
1072 else if (strcmp (os->name, ".interp") == 0)
1077 gld${EMULATION_NAME}_get_script(isfile)
1081 if test -n "$COMPILE_IN"
1083 # Scripts compiled in.
1085 # sed commands to quote an ld script as a C string.
1086 sc="-f stringify.sed"
1088 cat >>e${EMULATION_NAME}.c <<EOF
1092 if (link_info.relocateable == true && config.build_constructors == true)
1095 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1096 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1097 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1098 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1099 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1100 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1101 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1103 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1104 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1105 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1108 echo ' ; else return' >> e${EMULATION_NAME}.c
1109 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1110 echo '; }' >> e${EMULATION_NAME}.c
1113 # Scripts read from the filesystem.
1115 cat >>e${EMULATION_NAME}.c <<EOF
1119 if (link_info.relocateable == true && config.build_constructors == true)
1120 return "ldscripts/${EMULATION_NAME}.xu";
1121 else if (link_info.relocateable == true)
1122 return "ldscripts/${EMULATION_NAME}.xr";
1123 else if (!config.text_read_only)
1124 return "ldscripts/${EMULATION_NAME}.xbn";
1125 else if (!config.magic_demand_paged)
1126 return "ldscripts/${EMULATION_NAME}.xn";
1127 else if (link_info.shared)
1128 return "ldscripts/${EMULATION_NAME}.xs";
1130 return "ldscripts/${EMULATION_NAME}.x";
1136 if test -n "$PARSE_AND_LIST_ARGS" ; then
1137 cat >>e${EMULATION_NAME}.c <<EOF
1138 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
1139 static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE * file));
1141 $PARSE_AND_LIST_ARGS
1145 cat >>e${EMULATION_NAME}.c <<EOF
1146 #define gld_${EMULATION_NAME}_parse_args NULL
1147 #define gld_${EMULATION_NAME}_list_options NULL
1152 cat >>e${EMULATION_NAME}.c <<EOF
1154 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1156 gld${EMULATION_NAME}_before_parse,
1159 after_parse_default,
1160 gld${EMULATION_NAME}_after_open,
1161 after_allocation_default,
1162 set_output_arch_default,
1163 ldemul_default_target,
1164 gld${EMULATION_NAME}_before_allocation,
1165 gld${EMULATION_NAME}_get_script,
1166 "${EMULATION_NAME}",
1169 NULL, /* create output section statements */
1170 gld${EMULATION_NAME}_open_dynamic_archive,
1171 gld${EMULATION_NAME}_place_orphan,
1172 NULL, /* set_symbols */
1173 gld_${EMULATION_NAME}_parse_args,
1174 NULL, /* unrecognized_file */
1175 gld_${EMULATION_NAME}_list_options,
1176 NULL /* recognized_file */