1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
8 cat >e${EMULATION_NAME}.c <<EOF
9 /* This file is is generated by a shell script. DO NOT EDIT! */
11 /* AIX emulation code for ${EMULATION_NAME}
12 Copyright 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2001, 2002
13 Free Software Foundation, Inc.
14 Written by Steve Chamberlain <sac@cygnus.com>
15 AIX support by Ian Lance Taylor <ian@cygnus.com>
16 AIX 64 bit support by Tom Rix <trix@redhat.com>
18 This file is part of GLD, the Gnu Linker.
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version.
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 #define TARGET_IS_${EMULATION_NAME}
38 #include "libiberty.h"
39 #include "safe-ctype.h"
54 #include "coff/internal.h"
55 #include "coff/xcoff.h"
59 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
60 static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));
61 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
62 static char *gld${EMULATION_NAME}_choose_target PARAMS ((int, char **));
63 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
64 static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));
65 static void gld${EMULATION_NAME}_free PARAMS ((PTR));
66 static void gld${EMULATION_NAME}_find_relocs
67 PARAMS ((lang_statement_union_type *));
68 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
69 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
70 static boolean gld${EMULATION_NAME}_unrecognized_file
71 PARAMS ((lang_input_statement_type *));
72 static void gld${EMULATION_NAME}_create_output_section_statements
74 static void gld${EMULATION_NAME}_set_output_arch PARAMS ((void));
76 static int is_syscall PARAMS ((char *, unsigned int *));
77 static int change_symbol_mode PARAMS ((char *));
79 /* The file alignment required for each section. */
80 static unsigned long file_align;
82 /* The maximum size the stack is permitted to grow. This is stored in
84 static unsigned long maxstack;
86 /* The maximum data size. This is stored in the a.out header. */
87 static unsigned long maxdata;
89 /* Whether to perform garbage collection. */
92 /* The module type to use. */
93 static unsigned short modtype = ('1' << 8) | 'L';
95 /* Whether the .text section must be read-only (i.e., no relocs
99 /* Whether to implement Unix like linker semantics. */
102 /* Structure used to hold import file list. */
106 struct filelist *next;
110 /* List of import files. */
111 static struct filelist *import_files;
113 /* List of export symbols read from the export files. */
115 struct export_symbol_list
117 struct export_symbol_list *next;
121 static struct export_symbol_list *export_symbols;
123 /* Maintains the 32 or 64 bit mode state of import file */
124 static unsigned int symbol_mode = 0x04;
126 /* Which symbol modes are valid */
127 static unsigned int symbol_mode_mask = 0x0d;
129 /* Whether this is a 64 bit link */
130 static int is_64bit = 0;
132 /* Which syscalls from import file are valid */
133 static unsigned int syscall_mask = 0x77;
135 /* fake file for -binitfini support */
136 static lang_input_statement_type *initfini_file;
138 /* Whether to do run time linking
139 -brtl enables, -bnortl and -bnortllib disable. */
142 /* Explicit command line library path, -blibpath */
143 static char *command_line_blibpath = NULL;
145 /* This routine is called before anything else is done. */
148 gld${EMULATION_NAME}_before_parse ()
151 config.has_shared = true;
153 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
154 Override them here so we can use the link_info.init_function as a
155 state flag that lets the backend know that -binitfini has been done. */
157 link_info.init_function = NULL;
158 link_info.fini_function = NULL;
161 /* Handle AIX specific options. */
164 gld${EMULATION_NAME}_parse_args (argc, argv)
168 int prevoptind = optind;
169 int prevopterr = opterr;
201 /* -binitfini has special handling in the linker backend. The native linker
202 uses the arguemnts to generate a table of init and fini functions for
203 the executable. The important use for this option is to support aix 4.2+
204 c++ constructors and destructors. This is tied into gcc via collect2.c.
206 The function table is accessed by the runtime linker/loader by checking if
207 the first symbol in the loader symbol table is __rtinit. The gnu linker
208 generates this symbol and makes it the first loader symbol. */
210 static const struct option longopts[] = {
211 {"basis", no_argument, NULL, OPTION_IGNORE},
212 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
213 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
214 {"bcrld", no_argument, NULL, OPTION_IGNORE},
215 {"bcror31", no_argument, NULL, OPTION_IGNORE},
216 {"bD", required_argument, NULL, OPTION_MAXDATA},
217 {"bE", required_argument, NULL, OPTION_EXPORT},
218 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
219 {"berok", no_argument, NULL, OPTION_EROK},
220 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
221 {"bexport", required_argument, NULL, OPTION_EXPORT},
222 {"bf", no_argument, NULL, OPTION_ERNOTOK},
223 {"bgc", no_argument, &gc, 1},
224 {"bh", required_argument, NULL, OPTION_IGNORE},
225 {"bhalt", required_argument, NULL, OPTION_IGNORE},
226 {"bI", required_argument, NULL, OPTION_IMPORT},
227 {"bimport", required_argument, NULL, OPTION_IMPORT},
228 {"binitfini", required_argument, NULL, OPTION_INITFINI},
229 {"bl", required_argument, NULL, OPTION_LOADMAP},
230 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
231 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
232 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
233 {"bM", required_argument, NULL, OPTION_MODTYPE},
234 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
235 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
236 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
237 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
238 {"bnogc", no_argument, &gc, 0},
239 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
240 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
241 {"bnotextro", no_argument, &textro, 0},
242 {"bnro", no_argument, &textro, 0},
243 {"bpD", required_argument, NULL, OPTION_PD},
244 {"bpT", required_argument, NULL, OPTION_PT},
245 {"bro", no_argument, &textro, 1},
246 {"brtl", no_argument, &rtld, 1},
247 {"bnortl", no_argument, &rtld, 0},
248 {"bnortllib", no_argument, &rtld, 0},
249 {"bS", required_argument, NULL, OPTION_MAXSTACK},
250 {"bso", no_argument, NULL, OPTION_AUTOIMP},
251 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
252 {"btextro", no_argument, &textro, 1},
253 {"b32", no_argument, NULL, OPTION_32},
254 {"b64", no_argument, NULL, OPTION_64},
255 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
256 {"unix", no_argument, NULL, OPTION_UNIX},
257 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
258 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
259 {NULL, no_argument, NULL, 0}
262 /* Options supported by the AIX linker which we do not support: -f,
263 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
264 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
265 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
266 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
267 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
268 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
271 /* If the current option starts with -b, change the first : to an =.
272 The AIX linker uses : to separate the option from the argument;
273 changing it to = lets us treat it as a getopt option. */
278 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
282 for (s = argv[indx]; *s != '\0'; s++)
293 /* We add s and u so to the short options list so that -s and -u on
294 the command line do not match -static and -unix. */
297 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
309 /* Long option which just sets a flag. */
313 val = strtoll (optarg, &end, 0);
315 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
317 lang_section_start (".data", exp_intop (val));
321 val = strtoul (optarg, &end, 0);
322 if (*end != '\0' || (val & (val - 1)) != 0)
323 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
330 /* FIXME: This should use the page size for the target system. */
335 /* On AIX this is the same as GNU ld -Ttext. When we see -T
336 number, we assume the AIX option is intended. Otherwise, we
337 assume the usual GNU ld -T option is intended. We can't just
338 ignore the AIX option, because gcc passes it to the linker. */
339 val = strtoull (optarg, &end, 0);
345 lang_section_start (".text", exp_intop (val));
351 case OPTION_INITFINI:
354 * The aix linker init fini has the format :
356 * -binitfini:[ Initial][:Termination][:Priority]
358 * it allows the Termination and Priority to be optional.
360 * Since we support only one init/fini pair, we ignore the Priority.
362 * Define the special symbol __rtinit.
364 * strtok does not correctly handle the case of -binitfini::fini: so
370 while (*t && ':' != *t)
376 link_info.init_function = i;
379 while (*t && ':' != *t)
384 link_info.fini_function = f;
389 link_info.static_link = false;
393 force_make_executable = false;
397 force_make_executable = true;
401 gld${EMULATION_NAME}_read_file (optarg, false);
407 struct filelist **flpp;
409 n = (struct filelist *) xmalloc (sizeof (struct filelist));
412 flpp = &import_files;
413 while (*flpp != NULL)
414 flpp = &(*flpp)->next;
420 config.map_filename = optarg;
424 val = strtoull (optarg, &end, 0);
426 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
431 case OPTION_MAXSTACK:
432 val = strtoull (optarg, &end, 0);
434 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
443 link_info.shared = true;
446 if (*optarg == '\0' || optarg[1] == '\0')
447 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
449 modtype = (*optarg << 8) | optarg[1];
452 case OPTION_NOAUTOIMP:
453 link_info.static_link = true;
456 case OPTION_NOSTRCMPCT:
457 link_info.traditional_format = true;
461 /* This sets the page that the .data section is supposed to
462 start on. The offset within the page should still be the
463 offset within the file, so we need to build an appropriate
465 val = strtoull (optarg, &end, 0);
467 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
475 exp_nameop (NAME, "."),
478 exp_binop ('+', t, exp_intop (31)),
479 exp_intop (~(bfd_vma) 31));
480 lang_section_start (".data", t);
485 /* This set the page that the .text section is supposed to start
486 on. The offset within the page should still be the offset
488 val = strtoull (optarg, &end, 0);
490 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
497 exp_nameop (SIZEOF_HEADERS, NULL));
499 exp_binop ('+', t, exp_intop (31)),
500 exp_intop (~(bfd_vma) 31));
501 lang_section_start (".text", t);
505 case OPTION_STRCMPCT:
506 link_info.traditional_format = false;
516 symbol_mode_mask = 0x0d;
522 symbol_mode_mask = 0x0e;
526 command_line_blibpath = optarg;
529 case OPTION_NOLIBPATH:
530 command_line_blibpath = NULL;
538 /* This is called when an input file can not be recognized as a BFD
539 object or an archive. If the file starts with #!, we must treat it
540 as an import file. This is for AIX compatibility. */
543 gld${EMULATION_NAME}_unrecognized_file (entry)
544 lang_input_statement_type *entry;
549 e = fopen (entry->filename, FOPEN_RT);
555 if (getc (e) == '#' && getc (e) == '!')
558 struct filelist **flpp;
560 n = (struct filelist *) xmalloc (sizeof (struct filelist));
562 n->name = entry->filename;
563 flpp = &import_files;
564 while (*flpp != NULL)
565 flpp = &(*flpp)->next;
569 entry->loaded = true;
577 /* This is called after the input files have been opened. */
580 gld${EMULATION_NAME}_after_open ()
585 /* Call ldctor_build_sets, after pretending that this is a
586 relocateable link. We do this because AIX requires relocation
587 entries for all references to symbols, even in a final
588 executable. Of course, we only want to do this if we are
589 producing an XCOFF output file. */
590 r = link_info.relocateable;
591 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
592 link_info.relocateable = true;
593 ldctor_build_sets ();
594 link_info.relocateable = r;
596 /* For each set, record the size, so that the XCOFF backend can
597 output the correct csect length. */
598 for (p = sets; p != (struct set_info *) NULL; p = p->next)
602 /* If the symbol is defined, we may have been invoked from
603 collect, and the sets may already have been built, so we do
605 if (p->h->type == bfd_link_hash_defined
606 || p->h->type == bfd_link_hash_defweak)
609 if (p->reloc != BFD_RELOC_CTOR)
611 /* Handle this if we need to. */
615 size = (p->count + 2) * 4;
616 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
617 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
621 /* This is called after the sections have been attached to output
622 sections, but before any sizes or addresses have been set. */
625 gld${EMULATION_NAME}_before_allocation ()
628 struct export_symbol_list *el;
630 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
633 /* Handle the import and export files, if any. */
634 for (fl = import_files; fl != NULL; fl = fl->next)
635 gld${EMULATION_NAME}_read_file (fl->name, true);
636 for (el = export_symbols; el != NULL; el = el->next)
638 struct bfd_link_hash_entry *h;
640 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
642 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
643 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
644 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
647 /* Track down all relocations called for by the linker script (these
648 are typically constructor/destructor entries created by
649 CONSTRUCTORS) and let the backend know it will need to create
650 .loader relocs for them. */
651 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
653 /* Precedence of LIBPATH
654 -blibpath: native support always first
655 -rpath: gnu extension
656 -L build from command line -L's */
657 if (command_line_blibpath != NULL)
658 libpath = command_line_blibpath;
659 else if (command_line.rpath != NULL)
660 libpath = command_line.rpath;
661 else if (search_head == NULL)
662 libpath = (char *) "";
666 search_dirs_type *search;
668 len = strlen (search_head->name);
669 libpath = xmalloc (len + 1);
670 strcpy (libpath, search_head->name);
671 for (search = search_head->next; search != NULL; search = search->next)
675 nlen = strlen (search->name);
676 libpath = xrealloc (libpath, len + nlen + 2);
678 strcpy (libpath + len + 1, search->name);
683 /* Let the XCOFF backend set up the .loader section. */
684 if (!bfd_xcoff_size_dynamic_sections
685 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
686 maxstack, maxdata, gc && !unix_ld ? true : false,
687 modtype, textro ? true : false, unix_ld, special_sections,
688 rtld ? true : false))
689 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
691 /* Look through the special sections, and put them in the right
692 place in the link ordering. This is especially magic. */
693 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
696 lang_output_section_statement_type *os;
697 lang_statement_union_type **pls;
698 lang_input_section_type *is;
702 sec = special_sections[i];
706 /* Remove this section from the list of the output section.
707 This assumes we know what the script looks like. */
709 os = lang_output_section_find (sec->output_section->name);
711 einfo ("%P%F: can't find output section %s\n",
712 sec->output_section->name);
714 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
716 if ((*pls)->header.type == lang_input_section_enum
717 && (*pls)->input_section.section == sec)
719 is = (lang_input_section_type *) * pls;
720 *pls = (*pls)->header.next;
724 if ((*pls)->header.type == lang_wild_statement_enum)
726 lang_statement_union_type **pwls;
728 for (pwls = &(*pls)->wild_statement.children.head;
729 *pwls != NULL; pwls = &(*pwls)->header.next)
732 if ((*pwls)->header.type == lang_input_section_enum
733 && (*pwls)->input_section.section == sec)
735 is = (lang_input_section_type *) * pwls;
736 *pwls = (*pwls)->header.next;
748 einfo ("%P%F: can't find %s in output section\n",
749 bfd_get_section_name (sec->owner, sec));
752 /* Now figure out where the section should go. */
756 default: /* to avoid warnings */
757 case XCOFF_SPECIAL_SECTION_TEXT:
763 case XCOFF_SPECIAL_SECTION_ETEXT:
769 case XCOFF_SPECIAL_SECTION_DATA:
775 case XCOFF_SPECIAL_SECTION_EDATA:
781 case XCOFF_SPECIAL_SECTION_END:
782 case XCOFF_SPECIAL_SECTION_END2:
789 os = lang_output_section_find (oname);
793 is->header.next = os->children.head;
794 os->children.head = (lang_statement_union_type *) is;
798 is->header.next = NULL;
799 lang_statement_append (&os->children,
800 (lang_statement_union_type *) is,
807 gld${EMULATION_NAME}_choose_target (argc, argv)
812 static char *from_outside;
813 static char *from_inside;
814 static char *argv_to_target[][2] = {
815 {NULL, "${OUTPUT_FORMAT}"},
816 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
817 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
822 from_outside = getenv (TARGET_ENVIRON);
823 if (from_outside != (char *) NULL)
826 /* Set to default. */
827 from_inside = argv_to_target[0][1];
828 for (i = 1; i < argc; i++)
830 for (j = 1; j < jmax; j++)
832 if (0 == strcmp (argv[i], argv_to_target[j][0]))
833 from_inside = argv_to_target[j][1];
844 change_symbol_mode (input)
847 char *symbol_mode_string[] = {
858 for (bit = 0;; bit++)
860 string = symbol_mode_string[bit];
864 if (0 == strcmp (input, string))
866 symbol_mode = (1 << bit);
870 /* should not be here */
877 -1 : error, try something else */
879 is_syscall (input, flag)
887 char *syscall_string;
890 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
891 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
892 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
893 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
894 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
895 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
896 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
897 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
903 for (bit = 0;; bit++)
905 string = s[bit].syscall_string;
909 if (0 == strcmp (input, string))
911 if (1 << bit & syscall_mask)
922 /* should not be here */
926 /* Read an import or export file. For an import file, this is called
927 by the before_allocation emulation routine. For an export file,
928 this is called by the parse_args emulation routine. */
931 gld${EMULATION_NAME}_read_file (filename, import)
932 const char *filename;
942 const char *impmember;
944 o = (struct obstack *) xmalloc (sizeof (struct obstack));
945 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
947 f = fopen (filename, FOPEN_RT);
950 bfd_set_error (bfd_error_system_call);
951 einfo ("%F%s: %E\n", filename);
962 /* Default to 32 and 64 bit mode
963 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
964 are not repeated, assume 64 bit routines also want to use them.
965 See the routine change_symbol_mode for more information. */
969 while ((c = getc (f)) != EOF)
973 unsigned int syscall_flag = 0;
975 struct bfd_link_hash_entry *h;
979 obstack_1grow (o, c);
983 obstack_1grow (o, '\0');
986 s = (char *) obstack_base (o);
991 || change_symbol_mode (s)
992 || (*s == '#' && s[1] == ' ')
993 || (!import && *s == '#' && s[1] == '!'))
995 obstack_free (o, obstack_base (o));
999 if (*s == '#' && s[1] == '!')
1002 while (ISSPACE (*s))
1009 obstack_free (o, obstack_base (o));
1012 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1019 (void) obstack_finish (o);
1023 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1033 if (imppath == file - 1)
1043 while (ISSPACE (cs))
1052 einfo ("%s:%d: warning: syntax error in import file\n",
1059 while (*s != ')' && *s != '\0')
1064 einfo ("%s:%d: warning: syntax error in import file\n",
1072 if (symbol_mode & symbol_mode_mask)
1074 /* This is a symbol to be imported or exported. */
1077 address = (bfd_vma) -1;
1079 while (!ISSPACE (*s) && *s != '\0')
1087 while (ISSPACE (*s))
1091 while (!ISSPACE (*se) && *se != '\0')
1096 while (ISSPACE (*se))
1099 einfo ("%s%d: warning: syntax error in import/export file\n",
1108 status = is_syscall (s, &syscall_flag);
1112 /* not a system call, check for address */
1113 address = strtoul (s, &end, 0);
1116 einfo ("%s:%d: warning: syntax error in import/export file\n",
1126 struct export_symbol_list *n;
1128 ldlang_add_undef (symname);
1129 n = ((struct export_symbol_list *)
1130 xmalloc (sizeof (struct export_symbol_list)));
1131 n->next = export_symbols;
1132 n->name = xstrdup (symname);
1137 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1139 if (h == NULL || h->type == bfd_link_hash_new)
1141 /* We can just ignore attempts to import an unreferenced
1146 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1147 address, imppath, impfile,
1148 impmember, syscall_flag))
1149 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1150 filename, lineno, symname);
1154 obstack_free (o, obstack_base (o));
1157 if (obstack_object_size (o) > 0)
1159 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1161 obstack_free (o, obstack_base (o));
1166 obstack_free (o, NULL);
1171 /* This routine saves us from worrying about declaring free. */
1174 gld${EMULATION_NAME}_free (p)
1180 /* This is called by the before_allocation routine via
1181 lang_for_each_statement. It looks for relocations and assignments
1185 gld${EMULATION_NAME}_find_relocs (s)
1186 lang_statement_union_type *s;
1188 if (s->header.type == lang_reloc_statement_enum)
1190 lang_reloc_statement_type *rs;
1192 rs = &s->reloc_statement;
1193 if (rs->name == NULL)
1194 einfo ("%F%P: only relocations against symbols are permitted\n");
1195 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1196 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1199 if (s->header.type == lang_assignment_statement_enum)
1200 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1203 /* Look through an expression for an assignment statement. */
1206 gld${EMULATION_NAME}_find_exp_assignment (exp)
1209 struct bfd_link_hash_entry *h;
1211 switch (exp->type.node_class)
1214 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1215 false, false, false);
1220 if (strcmp (exp->assign.dst, ".") != 0)
1222 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1224 einfo ("%P%F: failed to record assignment to %s: %E\n",
1227 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1231 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1232 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1236 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1237 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1238 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1242 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1251 gld${EMULATION_NAME}_get_script (isfile)
1255 if test -n "$COMPILE_IN"
1257 # Scripts compiled in.
1259 # sed commands to quote an ld script as a C string.
1260 sc="-f ${srcdir}/emultempl/ostring.sed"
1262 cat >>e${EMULATION_NAME}.c <<EOF
1266 if (link_info.relocateable == true && config.build_constructors == true)
1269 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1270 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1271 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1272 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1273 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1274 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1275 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1276 echo ' ; else return' >> e${EMULATION_NAME}.c
1277 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1278 echo '; }' >> e${EMULATION_NAME}.c
1281 # Scripts read from the filesystem.
1283 cat >>e${EMULATION_NAME}.c <<EOF
1287 if (link_info.relocateable == true && config.build_constructors == true)
1288 return "ldscripts/${EMULATION_NAME}.xu";
1289 else if (link_info.relocateable == true)
1290 return "ldscripts/${EMULATION_NAME}.xr";
1291 else if (!config.text_read_only)
1292 return "ldscripts/${EMULATION_NAME}.xbn";
1293 else if (!config.magic_demand_paged)
1294 return "ldscripts/${EMULATION_NAME}.xn";
1296 return "ldscripts/${EMULATION_NAME}.x";
1302 cat >>e${EMULATION_NAME}.c <<EOF
1305 gld${EMULATION_NAME}_create_output_section_statements ()
1308 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1309 && (link_info.init_function != NULL
1310 || link_info.fini_function != NULL
1313 initfini_file = lang_add_input_file ("initfini",
1314 lang_input_file_is_file_enum,
1317 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1318 if (initfini_file->the_bfd == NULL
1319 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1320 bfd_get_arch (output_bfd),
1321 bfd_get_mach (output_bfd)))
1323 einfo ("%X%P: can not create BFD %E\n");
1327 /* Call backend to fill in the rest */
1328 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1329 link_info.init_function,
1330 link_info.fini_function,
1333 einfo ("%X%P: can not create BFD %E\n");
1337 /* __rtld defined in /lib/librtl.a */
1339 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1344 gld${EMULATION_NAME}_set_output_arch ()
1346 bfd_set_arch_mach (output_bfd,
1347 bfd_xcoff_architecture (output_bfd),
1348 bfd_xcoff_machine (output_bfd));
1350 ldfile_output_architecture = bfd_get_arch (output_bfd);
1351 ldfile_output_machine = bfd_get_mach (output_bfd);
1352 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1355 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1356 gld${EMULATION_NAME}_before_parse,
1359 after_parse_default,
1360 gld${EMULATION_NAME}_after_open,
1361 after_allocation_default,
1362 gld${EMULATION_NAME}_set_output_arch,
1363 gld${EMULATION_NAME}_choose_target,
1364 gld${EMULATION_NAME}_before_allocation,
1365 gld${EMULATION_NAME}_get_script,
1366 "${EMULATION_NAME}",
1369 gld${EMULATION_NAME}_create_output_section_statements,
1370 0, /* open_dynamic_archive */
1371 0, /* place_orphan */
1372 0, /* set_symbols */
1373 gld${EMULATION_NAME}_parse_args,
1374 gld${EMULATION_NAME}_unrecognized_file,
1375 NULL, /* list_options */
1376 NULL, /* recognized_file */
1377 NULL, /* find potential_libraries */
1378 NULL /* new_vers_pattern */