1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
4 cat >e${EMULATION_NAME}.c <<EOF
5 /* This file is is generated by a shell script. DO NOT EDIT! */
7 /* emulate the original gld for the given ${EMULATION_NAME}
8 Copyright (C) 1991, 93, 96, 97, 98, 1999 Free Software Foundation, Inc.
9 Written by Steve Chamberlain steve@cygnus.com
11 This file is part of GLD, the Gnu Linker.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define TARGET_IS_${EMULATION_NAME}
44 static boolean gld${EMULATION_NAME}_open_dynamic_archive
45 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
46 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
47 static void gld${EMULATION_NAME}_check_needed
48 PARAMS ((lang_input_statement_type *));
49 static void gld${EMULATION_NAME}_stat_needed
50 PARAMS ((lang_input_statement_type *));
51 static boolean gld${EMULATION_NAME}_search_needed
52 PARAMS ((const char *, const char *, int));
53 static boolean gld${EMULATION_NAME}_try_needed PARAMS ((const char *, int));
54 static void gld${EMULATION_NAME}_vercheck
55 PARAMS ((lang_input_statement_type *));
56 static void gld${EMULATION_NAME}_find_statement_assignment
57 PARAMS ((lang_statement_union_type *));
58 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
59 static boolean gld${EMULATION_NAME}_place_orphan
60 PARAMS ((lang_input_statement_type *, asection *));
61 static void gld${EMULATION_NAME}_place_section
62 PARAMS ((lang_statement_union_type *));
63 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
64 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
65 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
66 static int gld${EMULATION_NAME}_parse_args PARAMS((int, char **));
67 static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
68 static void gld_${EMULATION_NAME}_finish PARAMS ((void));
71 static int no_pipeline_knowledge = 0;
72 static char * thumb_entry_symbol = NULL;
74 #define OPTION_THUMB_ENTRY 301
76 static struct option longopts[] =
78 { "no-pipeline-knowledge", no_argument, NULL, 'p'},
79 { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
80 { NULL, no_argument, NULL, 0 }
84 gld${EMULATION_NAME}_list_options (file)
87 fprintf (file, _(" -p --no-pipeline-knowledge Stop the linker knowing about the pipeline length\n"));
88 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
92 gld${EMULATION_NAME}_parse_args (argc, argv)
98 int prevoptind = optind;
99 int prevopterr = opterr;
101 static int lastoptind = -1;
103 if (lastoptind != optind)
109 optc = getopt_long_only (argc, argv, "-p", longopts, & longind);
121 no_pipeline_knowledge = 1;
124 case OPTION_THUMB_ENTRY:
125 thumb_entry_symbol = optarg;
134 gld${EMULATION_NAME}_before_parse ()
136 #ifndef TARGET_ /* I.e., if not generic. */
137 ldfile_set_output_arch ("`echo ${ARCH}`");
138 #endif /* not TARGET_ */
139 config.dynamic_link = ${DYNAMIC_LINK-true};
140 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`;
143 /* Try to open a dynamic archive. This is where we know that ELF
144 dynamic libraries have an extension of .so. */
147 gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
149 search_dirs_type *search;
150 lang_input_statement_type *entry;
152 const char *filename;
155 if (! entry->is_archive)
158 filename = entry->filename;
160 string = (char *) xmalloc (strlen (search->name)
165 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
167 if (! ldfile_try_open_bfd (string, entry))
173 entry->filename = string;
175 /* We have found a dynamic object to include in the link. The ELF
176 backend linker will create a DT_NEEDED entry in the .dynamic
177 section naming this file. If this file includes a DT_SONAME
178 entry, it will be used. Otherwise, the ELF linker will just use
179 the name of the file. For an archive found by searching, like
180 this one, the DT_NEEDED entry should consist of just the name of
181 the file, without the path information used to find it. Note
182 that we only need to do this if we have a dynamic object; an
183 archive will never be referenced by a DT_NEEDED entry.
185 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
186 very pretty. I haven't been able to think of anything that is
188 if (bfd_check_format (entry->the_bfd, bfd_object)
189 && (entry->the_bfd->flags & DYNAMIC) != 0)
193 ASSERT (entry->is_archive && entry->search_dirs_flag);
194 needed_name = (char *) xmalloc (strlen (filename)
197 sprintf (needed_name, "lib%s%s.so", filename, arch);
198 bfd_elf_set_dt_needed_name (entry->the_bfd, needed_name);
205 if [ "x${host}" = "x${target}" ] ; then
206 case " ${EMULATION_LIBPATH} " in
207 *" ${EMULATION_NAME} "*)
208 cat >>e${EMULATION_NAME}.c <<EOF
210 /* For a native linker, check the file /etc/ld.so.conf for directories
211 in which we may find shared libraries. /etc/ld.so.conf is really
212 only meaningful on Linux, but we check it on other systems anyhow. */
214 static boolean gld${EMULATION_NAME}_check_ld_so_conf
215 PARAMS ((const char *, int));
218 gld${EMULATION_NAME}_check_ld_so_conf (name, force)
222 static boolean initialized;
223 static char *ld_so_conf;
229 f = fopen ("/etc/ld.so.conf", FOPEN_RT);
238 b = (char *) xmalloc (alloc);
240 while ((c = getc (f)) != EOF)
242 if (len + 1 >= alloc)
245 b = (char *) xrealloc (b, alloc);
258 if (len > 0 && b[len - 1] != ':')
266 if (len > 0 && b[len - 1] == ':')
285 if (ld_so_conf == NULL)
288 return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force);
295 cat >>e${EMULATION_NAME}.c <<EOF
297 /* These variables are required to pass information back and forth
298 between after_open and check_needed and stat_needed and vercheck. */
300 static struct bfd_link_needed_list *global_needed;
301 static struct stat global_stat;
302 static boolean global_found;
303 static struct bfd_link_needed_list *global_vercheck_needed;
304 static boolean global_vercheck_failed;
307 gld${EMULATION_NAME}_after_open ()
309 struct bfd_link_needed_list *needed, *l;
311 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
313 /* The arm backend needs special fields in the output hash structure.
314 These will only be created if the output format is an arm format,
315 hence we do not support linking and changing output formats at the
316 same time. Use a link followed by objcopy to change output formats. */
317 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
322 LANG_FOR_EACH_INPUT_STATEMENT (is)
324 /* The interworking bfd must be the last one to be processed */
326 bfd_elf32_arm_get_bfd_for_interworking (is->the_bfd, & link_info);
330 /* We only need to worry about this when doing a final link. */
331 if (link_info.relocateable || link_info.shared)
334 /* Get the list of files which appear in DT_NEEDED entries in
335 dynamic objects included in the link (often there will be none).
336 For each such file, we want to track down the corresponding
337 library, and include the symbol table in the link. This is what
338 the runtime dynamic linker will do. Tracking the files down here
339 permits one dynamic object to include another without requiring
340 special action by the person doing the link. Note that the
341 needed list can actually grow while we are stepping through this
343 needed = bfd_elf_get_needed_list (output_bfd, &link_info);
344 for (l = needed; l != NULL; l = l->next)
346 struct bfd_link_needed_list *ll;
349 /* If we've already seen this file, skip it. */
350 for (ll = needed; ll != l; ll = ll->next)
351 if (strcmp (ll->name, l->name) == 0)
356 /* See if this file was included in the link explicitly. */
358 global_found = false;
359 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
363 /* We need to find this file and include the symbol table. We
364 want to search for the file in the same way that the dynamic
365 linker will search. That means that we want to use
366 rpath_link, rpath, then the environment variable
367 LD_LIBRARY_PATH (native only), then the linker script
368 LIB_SEARCH_DIRS. We do not search using the -L arguments.
370 We search twice. The first time, we skip objects which may
371 introduce version mismatches. The second time, we force
372 their use. See gld${EMULATION_NAME}_vercheck comment. */
373 for (force = 0; force < 2; force++)
375 const char *lib_path;
377 search_dirs_type *search;
379 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
382 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
385 if (command_line.rpath_link == NULL
386 && command_line.rpath == NULL)
388 lib_path = (const char *) getenv ("LD_RUN_PATH");
389 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name,
394 if [ "x${host}" = "x${target}" ] ; then
395 case " ${EMULATION_LIBPATH} " in
396 *" ${EMULATION_NAME} "*)
397 cat >>e${EMULATION_NAME}.c <<EOF
398 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
399 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force))
405 cat >>e${EMULATION_NAME}.c <<EOF
406 len = strlen (l->name);
407 for (search = search_head; search != NULL; search = search->next)
413 filename = (char *) xmalloc (strlen (search->name) + len + 2);
414 sprintf (filename, "%s/%s", search->name, l->name);
415 if (gld${EMULATION_NAME}_try_needed (filename, force))
422 if [ "x${host}" = "x${target}" ] ; then
423 case " ${EMULATION_LIBPATH} " in
424 *" ${EMULATION_NAME} "*)
425 cat >>e${EMULATION_NAME}.c <<EOF
426 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force))
432 cat >>e${EMULATION_NAME}.c <<EOF
438 einfo ("%P: warning: %s, needed by %B, not found (try using --rpath)\n",
443 /* Search for a needed file in a path. */
446 gld${EMULATION_NAME}_search_needed (path, name, force)
454 if (path == NULL || *path == '\0')
459 char *filename, *sset;
461 s = strchr (path, ':');
463 s = path + strlen (path);
465 filename = (char *) xmalloc (s - path + len + 2);
470 memcpy (filename, path, s - path);
471 filename[s - path] = '/';
472 sset = filename + (s - path) + 1;
476 if (gld${EMULATION_NAME}_try_needed (filename, force))
489 /* This function is called for each possible name for a dynamic object
490 named by a DT_NEEDED entry. The FORCE parameter indicates whether
491 to skip the check for a conflicting version. */
494 gld${EMULATION_NAME}_try_needed (name, force)
500 abfd = bfd_openr (name, bfd_get_target (output_bfd));
503 if (! bfd_check_format (abfd, bfd_object))
505 (void) bfd_close (abfd);
508 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
510 (void) bfd_close (abfd);
514 /* Check whether this object would include any conflicting library
515 versions. If FORCE is set, then we skip this check; we use this
516 the second time around, if we couldn't find any compatible
517 instance of the shared library. */
521 struct bfd_link_needed_list *needed;
523 if (! bfd_elf_get_bfd_needed_list (abfd, &needed))
524 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
528 global_vercheck_needed = needed;
529 global_vercheck_failed = false;
530 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
531 if (global_vercheck_failed)
533 (void) bfd_close (abfd);
534 /* Return false to force the caller to move on to try
535 another file on the search path. */
539 /* But wait! It gets much worse. On Linux, if a shared
540 library does not use libc at all, we are supposed to skip
541 it the first time around in case we encounter a shared
542 library later on with the same name which does use the
543 version of libc that we want. This is much too horrible
544 to use on any system other than Linux. */
549 cat >>e${EMULATION_NAME}.c <<EOF
551 struct bfd_link_needed_list *l;
553 for (l = needed; l != NULL; l = l->next)
554 if (strncmp (l->name, "libc.so", 7) == 0)
558 (void) bfd_close (abfd);
566 cat >>e${EMULATION_NAME}.c <<EOF
570 /* We've found a dynamic object matching the DT_NEEDED entry. */
572 /* We have already checked that there is no other input file of the
573 same name. We must now check again that we are not including the
574 same file twice. We need to do this because on many systems
575 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
576 reference libc.so.1. If we have already included libc.so, we
577 don't want to include libc.so.1 if they are the same file, and we
578 can only check that using stat. */
580 if (bfd_stat (abfd, &global_stat) != 0)
581 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
582 global_found = false;
583 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
586 /* Return true to indicate that we found the file, even though
587 we aren't going to do anything with it. */
591 /* Tell the ELF backend that don't want the output file to have a
592 DT_NEEDED entry for this file. */
593 bfd_elf_set_dt_needed_name (abfd, "");
595 /* Add this file into the symbol table. */
596 if (! bfd_link_add_symbols (abfd, &link_info))
597 einfo ("%F%B: could not read symbols: %E\n", abfd);
602 /* See if an input file matches a DT_NEEDED entry by name. */
605 gld${EMULATION_NAME}_check_needed (s)
606 lang_input_statement_type *s;
611 if (s->filename != NULL
612 && strcmp (s->filename, global_needed->name) == 0)
618 if (s->the_bfd != NULL)
622 soname = bfd_elf_get_dt_soname (s->the_bfd);
624 && strcmp (soname, global_needed->name) == 0)
631 if (s->search_dirs_flag
632 && s->filename != NULL
633 && strchr (global_needed->name, '/') == NULL)
637 f = strrchr (s->filename, '/');
639 && strcmp (f + 1, global_needed->name) == 0)
647 /* See if an input file matches a DT_NEEDED entry by running stat on
651 gld${EMULATION_NAME}_stat_needed (s)
652 lang_input_statement_type *s;
661 if (s->the_bfd == NULL)
664 if (bfd_stat (s->the_bfd, &st) != 0)
666 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
670 if (st.st_dev == global_stat.st_dev
671 && st.st_ino == global_stat.st_ino)
677 /* We issue a warning if it looks like we are including two
678 different versions of the same shared library. For example,
679 there may be a problem if -lc picks up libc.so.6 but some other
680 shared library has a DT_NEEDED entry of libc.so.5. This is a
681 hueristic test, and it will only work if the name looks like
682 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
683 If we really want to issue warnings about mixing version numbers
684 of shared libraries, we need to find a better way. */
686 if (strchr (global_needed->name, '/') != NULL)
688 suffix = strstr (global_needed->name, ".so.");
691 suffix += sizeof ".so." - 1;
693 soname = bfd_elf_get_dt_soname (s->the_bfd);
695 soname = s->filename;
697 f = strrchr (soname, '/');
703 if (strncmp (f, global_needed->name, suffix - global_needed->name) == 0)
704 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
705 global_needed->name, global_needed->by, f);
708 /* On Linux, it's possible to have different versions of the same
709 shared library linked against different versions of libc. The
710 dynamic linker somehow tags which libc version to use in
711 /etc/ld.so.cache, and, based on the libc that it sees in the
712 executable, chooses which version of the shared library to use.
714 We try to do a similar check here by checking whether this shared
715 library needs any other shared libraries which may conflict with
716 libraries we have already included in the link. If it does, we
717 skip it, and try to find another shared library farther on down the
720 This is called via lang_for_each_input_file.
721 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
722 which we ar checking. This sets GLOBAL_VERCHECK_FAILED if we find
723 a conflicting version. */
726 gld${EMULATION_NAME}_vercheck (s)
727 lang_input_statement_type *s;
729 const char *soname, *f;
730 struct bfd_link_needed_list *l;
732 if (global_vercheck_failed)
734 if (s->the_bfd == NULL
735 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
738 soname = bfd_elf_get_dt_soname (s->the_bfd);
740 soname = bfd_get_filename (s->the_bfd);
742 f = strrchr (soname, '/');
748 for (l = global_vercheck_needed; l != NULL; l = l->next)
752 if (strcmp (f, l->name) == 0)
754 /* Probably can't happen, but it's an easy check. */
758 if (strchr (l->name, '/') != NULL)
761 suffix = strstr (l->name, ".so.");
765 suffix += sizeof ".so." - 1;
767 if (strncmp (f, l->name, suffix - l->name) == 0)
769 /* Here we know that S is a dynamic object FOO.SO.VER1, and
770 the object we are considering needs a dynamic object
771 FOO.SO.VER2, and VER1 and VER2 are different. This
772 appears to be a version mismatch, so we tell the caller
773 to try a different version of this library. */
774 global_vercheck_failed = true;
780 /* Place an orphan section. We use this to put random SHF_ALLOC
781 sections in the right segment. */
783 static asection *hold_section;
784 static lang_output_section_statement_type *hold_use;
785 static lang_output_section_statement_type *hold_text;
786 static lang_output_section_statement_type *hold_rodata;
787 static lang_output_section_statement_type *hold_data;
788 static lang_output_section_statement_type *hold_bss;
789 static lang_output_section_statement_type *hold_rel;
790 static lang_output_section_statement_type *hold_interp;
794 gld${EMULATION_NAME}_place_orphan (file, s)
795 lang_input_statement_type *file;
798 lang_output_section_statement_type *place;
799 asection *snew, **pps;
800 lang_statement_list_type *old;
801 lang_statement_list_type add;
803 const char *secname, *ps;
804 const char *outsecname;
805 lang_output_section_statement_type *os;
807 if ((s->flags & SEC_ALLOC) == 0)
810 /* Look through the script to see where to place this section. */
813 lang_for_each_statement (gld${EMULATION_NAME}_place_section);
815 if (hold_use != NULL)
817 /* We have already placed a section with this name. */
818 wild_doit (&hold_use->children, s, hold_use, file);
822 secname = bfd_get_section_name (s->owner, s);
824 /* If this is a final link, then always put .gnu.warning.SYMBOL
825 sections into the .text section to get them out of the way. */
826 if (! link_info.shared
827 && ! link_info.relocateable
828 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0
829 && hold_text != NULL)
831 wild_doit (&hold_text->children, s, hold_text, file);
835 /* Decide which segment the section should go in based on the
836 section name and section flags. We put loadable .note sections
837 right after the .interp section, so that the PT_NOTE segment is
838 stored right after the program headers where the OS can read it
839 in the first page. */
841 if (s->flags & SEC_EXCLUDE)
843 else if ((s->flags & SEC_LOAD) != 0
844 && strncmp (secname, ".note", 4) == 0
845 && hold_interp != NULL)
847 else if ((s->flags & SEC_HAS_CONTENTS) == 0
850 else if ((s->flags & SEC_READONLY) == 0
851 && hold_data != NULL)
853 else if (strncmp (secname, ".rel", 4) == 0
856 else if ((s->flags & SEC_CODE) == 0
857 && (s->flags & SEC_READONLY) != 0
858 && hold_rodata != NULL)
860 else if ((s->flags & SEC_READONLY) != 0
861 && hold_text != NULL)
866 /* Choose a unique name for the section. This will be needed if the
867 same section name appears in the input file with different
868 loadable or allocateable characteristics. */
869 outsecname = secname;
870 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
876 len = strlen (outsecname);
877 newname = xmalloc (len + 5);
878 strcpy (newname, outsecname);
882 sprintf (newname + len, "%d", i);
885 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
887 outsecname = newname;
890 /* Create the section in the output file, and put it in the right
891 place. This shuffling is to make the output file look neater. */
892 snew = bfd_make_section (output_bfd, outsecname);
894 einfo ("%P%F: output format %s cannot represent section called %s\n",
895 output_bfd->xvec->name, outsecname);
896 if (place->bfd_section != NULL)
898 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
901 snew->next = place->bfd_section->next;
902 place->bfd_section->next = snew;
905 /* Start building a list of statements for this section. */
908 lang_list_init (stat_ptr);
910 /* If the name of the section is representable in C, then create
911 symbols to mark the start and the end of the section. */
912 for (ps = outsecname; *ps != '\0'; ps++)
913 if (! isalnum ((unsigned char) *ps) && *ps != '_')
915 if (*ps == '\0' && config.build_constructors)
919 symname = (char *) xmalloc (ps - outsecname + sizeof "__start_");
920 sprintf (symname, "__start_%s", outsecname);
921 lang_add_assignment (exp_assop ('=', symname,
923 exp_intop ((bfd_vma) 1
924 << s->alignment_power))));
927 if (! link_info.relocateable)
930 address = exp_intop ((bfd_vma) 0);
932 lang_enter_output_section_statement (outsecname, address, 0,
936 (etree_type *) NULL);
938 os = lang_output_section_statement_lookup (outsecname);
939 wild_doit (&os->children, s, os, file);
941 lang_leave_output_section_statement
942 ((bfd_vma) 0, "*default*", (struct lang_output_section_phdr_list *) NULL);
945 if (*ps == '\0' && config.build_constructors)
949 symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_");
950 sprintf (symname, "__stop_%s", outsecname);
951 lang_add_assignment (exp_assop ('=', symname,
952 exp_nameop (NAME, ".")));
955 /* Now stick the new statement list right after PLACE. */
956 *add.tail = place->header.next;
957 place->header.next = add.head;
965 gld${EMULATION_NAME}_place_section (s)
966 lang_statement_union_type *s;
968 lang_output_section_statement_type *os;
970 if (s->header.type != lang_output_section_statement_enum)
973 os = &s->output_section_statement;
975 if (strcmp (os->name, hold_section->name) == 0
976 && os->bfd_section != NULL
977 && ((hold_section->flags & (SEC_LOAD | SEC_ALLOC))
978 == (os->bfd_section->flags & (SEC_LOAD | SEC_ALLOC))))
981 if (strcmp (os->name, ".text") == 0)
983 else if (strcmp (os->name, ".rodata") == 0)
985 else if (strcmp (os->name, ".data") == 0)
987 else if (strcmp (os->name, ".bss") == 0)
989 else if (hold_rel == NULL
990 && os->bfd_section != NULL
991 && (os->bfd_section->flags & SEC_ALLOC) != 0
992 && strncmp (os->name, ".rel", 4) == 0)
994 else if (strcmp (os->name, ".interp") == 0)
998 /* Look through an expression for an assignment statement. */
1001 gld${EMULATION_NAME}_find_exp_assignment (exp)
1004 struct bfd_link_hash_entry *h;
1006 switch (exp->type.node_class)
1009 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1010 false, false, false);
1014 /* We call record_link_assignment even if the symbol is defined.
1015 This is because if it is defined by a dynamic object, we
1016 actually want to use the value defined by the linker script,
1017 not the value from the dynamic object (because we are setting
1018 symbols like etext). If the symbol is defined by a regular
1019 object, then, as it happens, calling record_link_assignment
1024 if (strcmp (exp->assign.dst, ".") != 0)
1026 if (! (bfd_elf${ELFSIZE}_record_link_assignment
1027 (output_bfd, &link_info, exp->assign.dst,
1028 exp->type.node_class == etree_provide ? true : false)))
1029 einfo ("%P%F: failed to record assignment to %s: %E\n",
1032 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1036 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1037 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1041 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1042 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1043 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1047 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1055 /* This is called by the before_allocation routine via
1056 lang_for_each_statement. It locates any assignment statements, and
1057 tells the ELF backend about them, in case they are assignments to
1058 symbols which are referred to by dynamic objects. */
1061 gld${EMULATION_NAME}_find_statement_assignment (s)
1062 lang_statement_union_type *s;
1064 if (s->header.type == lang_assignment_statement_enum)
1065 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1068 /* This is called after the sections have been attached to output
1069 sections, but before any sizes or addresses have been set. */
1072 gld${EMULATION_NAME}_before_allocation ()
1077 /* If we are going to make any variable assignments, we need to let
1078 the ELF backend know about them in case the variables are
1079 referred to by dynamic objects. */
1080 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1082 /* Let the ELF backend work out the sizes of any sections required
1083 by dynamic linking. */
1084 rpath = command_line.rpath;
1086 rpath = (const char *) getenv ("LD_RUN_PATH");
1087 if (! (bfd_elf${ELFSIZE}_size_dynamic_sections
1088 (output_bfd, command_line.soname, rpath,
1089 command_line.export_dynamic, command_line.filter_shlib,
1090 (const char * const *) command_line.auxiliary_filters,
1091 &link_info, &sinterp, lang_elf_version_info)))
1092 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1094 /* Let the user override the dynamic linker we are using. */
1095 if (command_line.interpreter != NULL
1098 sinterp->contents = (bfd_byte *) command_line.interpreter;
1099 sinterp->_raw_size = strlen (command_line.interpreter) + 1;
1102 /* Look for any sections named .gnu.warning. As a GNU extensions,
1103 we treat such sections as containing warning messages. We print
1104 out the warning message, and then zero out the section size so
1105 that it does not get copied into the output file. */
1108 LANG_FOR_EACH_INPUT_STATEMENT (is)
1115 if (is->just_syms_flag)
1118 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1122 sz = bfd_section_size (is->the_bfd, s);
1123 msg = xmalloc ((size_t) sz + 1);
1124 if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz))
1125 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1128 ret = link_info.callbacks->warning (&link_info, msg,
1129 (const char *) NULL,
1130 is->the_bfd, (asection *) NULL,
1135 /* Clobber the section size, so that we don't waste copying the
1136 warning into the output file. */
1141 /* we should be able to set the size of the interworking stub section */
1143 /* Here we rummage through the found bfds to collect glue information */
1144 /* FIXME: should this be based on a command line option? krk@cygnus.com */
1146 LANG_FOR_EACH_INPUT_STATEMENT (is)
1148 if (!bfd_elf32_arm_process_before_allocation (is->the_bfd, & link_info,
1149 no_pipeline_knowledge))
1151 /* xgettext:c-format */
1152 einfo (_("Errors encountered processing file %s"), is->filename);
1157 /* We have seen it all. Allocate it, and carry on */
1158 bfd_elf32_arm_allocate_interworking_sections (& link_info);
1162 gld${EMULATION_NAME}_finish PARAMS((void))
1164 struct bfd_link_hash_entry * h;
1166 if (thumb_entry_symbol == NULL)
1169 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
1171 if (h != (struct bfd_link_hash_entry *) NULL
1172 && (h->type == bfd_link_hash_defined
1173 || h->type == bfd_link_hash_defweak)
1174 && h->u.def.section->output_section != NULL)
1176 static char buffer[32];
1179 /* Special procesing is required for a Thumb entry symbol. The
1180 bottom bit of its address must be set. */
1181 val = (h->u.def.value
1182 + bfd_get_section_vma (output_bfd,
1183 h->u.def.section->output_section)
1184 + h->u.def.section->output_offset);
1188 /* Now convert this value into a string and store it in entry_symbol
1189 where the lang_finish() function will pick it up. */
1193 sprintf_vma (buffer + 2, val);
1195 if (entry_symbol != NULL && entry_from_cmdline)
1196 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
1197 thumb_entry_symbol, entry_symbol);
1198 entry_symbol = buffer;
1201 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
1205 gld${EMULATION_NAME}_get_script (isfile)
1209 if test -n "$COMPILE_IN"
1211 # Scripts compiled in.
1213 # sed commands to quote an ld script as a C string.
1214 sc="-f ${srcdir}/emultempl/stringify.sed"
1216 cat >>e${EMULATION_NAME}.c <<EOF
1220 if (link_info.relocateable == true && config.build_constructors == true)
1223 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1224 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1225 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1226 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1227 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1228 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1229 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1230 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
1231 echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c
1232 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
1234 echo ' ; else return' >> e${EMULATION_NAME}.c
1235 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1236 echo '; }' >> e${EMULATION_NAME}.c
1239 # Scripts read from the filesystem.
1241 cat >>e${EMULATION_NAME}.c <<EOF
1245 if (link_info.relocateable == true && config.build_constructors == true)
1246 return "ldscripts/${EMULATION_NAME}.xu";
1247 else if (link_info.relocateable == true)
1248 return "ldscripts/${EMULATION_NAME}.xr";
1249 else if (!config.text_read_only)
1250 return "ldscripts/${EMULATION_NAME}.xbn";
1251 else if (!config.magic_demand_paged)
1252 return "ldscripts/${EMULATION_NAME}.xn";
1253 else if (link_info.shared)
1254 return "ldscripts/${EMULATION_NAME}.xs";
1256 return "ldscripts/${EMULATION_NAME}.x";
1262 cat >>e${EMULATION_NAME}.c <<EOF
1264 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1266 gld${EMULATION_NAME}_before_parse,
1269 after_parse_default,
1270 gld${EMULATION_NAME}_after_open,
1271 after_allocation_default,
1272 set_output_arch_default,
1273 ldemul_default_target,
1274 gld${EMULATION_NAME}_before_allocation,
1275 gld${EMULATION_NAME}_get_script,
1276 "${EMULATION_NAME}",
1278 gld${EMULATION_NAME}_finish, /* finish */
1279 NULL, /* create output section statements */
1280 gld${EMULATION_NAME}_open_dynamic_archive,
1281 gld${EMULATION_NAME}_place_orphan,
1282 NULL, /* set_symbols */
1283 gld${EMULATION_NAME}_parse_args,
1284 NULL, /* unrecognised file */
1285 gld${EMULATION_NAME}_list_options,
1286 NULL /* recognized file */