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
13 Free Software Foundation, Inc.
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"
57 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
58 static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));
59 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
60 static char *choose_target PARAMS ((int, char **));
61 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
62 static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));
63 static void gld${EMULATION_NAME}_free PARAMS ((PTR));
64 static void gld${EMULATION_NAME}_find_relocs
65 PARAMS ((lang_statement_union_type *));
66 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
67 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
68 static boolean gld${EMULATION_NAME}_unrecognized_file
69 PARAMS ((lang_input_statement_type *));
70 static void gld${EMULATION_NAME}_create_output_section_statements
72 static int is_syscall PARAMS ((char *, unsigned int *));
73 static int change_symbol_mode PARAMS ((char *));
75 /* The file alignment required for each section. */
76 static unsigned long file_align;
78 /* The maximum size the stack is permitted to grow. This is stored in
80 static unsigned long maxstack;
82 /* The maximum data size. This is stored in the a.out header. */
83 static unsigned long maxdata;
85 /* Whether to perform garbage collection. */
88 /* The module type to use. */
89 static unsigned short modtype = ('1' << 8) | 'L';
91 /* Whether the .text section must be read-only (i.e., no relocs
95 /* Whether to implement Unix like linker semantics. */
98 /* Structure used to hold import file list. */
102 struct filelist *next;
106 /* List of import files. */
107 static struct filelist *import_files;
109 /* List of export symbols read from the export files. */
111 struct export_symbol_list
113 struct export_symbol_list *next;
117 static struct export_symbol_list *export_symbols;
119 /* Maintains the 32 or 64 bit mode state of import file */
120 static unsigned int symbol_mode = 0x04;
122 /* Which symbol modes are valid */
123 static unsigned int symbol_mode_mask = 0x0d;
125 /* Whether this is a 64 bit link */
126 static int is_64bit = 0;
128 /* Which syscalls from import file are valid */
129 static unsigned int syscall_mask = 0x77;
131 /* fake file for -binitfini support */
132 static lang_input_statement_type *initfini_file;
134 /* Whether to do run time linking */
137 /* Explicit command line library path, -blibpath */
138 static char *command_line_blibpath = NULL;
140 /* This routine is called before anything else is done. */
143 gld${EMULATION_NAME}_before_parse ()
145 #ifndef TARGET_ /* I.e., if not generic. */
146 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
149 ldfile_output_architecture = arch->arch;
150 ldfile_output_machine = arch->mach;
151 ldfile_output_machine_name = arch->printable_name;
154 ldfile_output_architecture = bfd_arch_${ARCH};
155 #endif /* not TARGET_ */
156 config.has_shared = true;
158 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
159 Override them here so we can use the link_info.init_function as a
160 state flag that lets the backend know that -binitfini has been done. */
162 link_info.init_function = NULL;
163 link_info.fini_function = NULL;
166 /* Handle AIX specific options. */
169 gld${EMULATION_NAME}_parse_args (argc, argv)
173 int prevoptind = optind;
174 int prevopterr = opterr;
206 /* -binitfini has special handling in the linker backend. The native linker
207 uses the arguemnts to generate a table of init and fini functions for
208 the executable. The important use for this option is to support aix 4.2+
209 c++ constructors and destructors. This is tied into gcc via collect2.c.
211 The function table is accessed by the runtime linker/loader by checking if
212 the first symbol in the loader symbol table is __rtinit. The gnu linker
213 generates this symbol and makes it the first loader symbol. */
215 static const struct option longopts[] = {
216 {"basis", no_argument, NULL, OPTION_IGNORE},
217 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
218 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
219 {"bcrld", no_argument, NULL, OPTION_IGNORE},
220 {"bcror31", no_argument, NULL, OPTION_IGNORE},
221 {"bD", required_argument, NULL, OPTION_MAXDATA},
222 {"bE", required_argument, NULL, OPTION_EXPORT},
223 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
224 {"berok", no_argument, NULL, OPTION_EROK},
225 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
226 {"bexport", required_argument, NULL, OPTION_EXPORT},
227 {"bf", no_argument, NULL, OPTION_ERNOTOK},
228 {"bgc", no_argument, &gc, 1},
229 {"bh", required_argument, NULL, OPTION_IGNORE},
230 {"bhalt", required_argument, NULL, OPTION_IGNORE},
231 {"bI", required_argument, NULL, OPTION_IMPORT},
232 {"bimport", required_argument, NULL, OPTION_IMPORT},
233 {"binitfini", required_argument, NULL, OPTION_INITFINI},
234 {"bl", required_argument, NULL, OPTION_LOADMAP},
235 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
236 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
237 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
238 {"bM", required_argument, NULL, OPTION_MODTYPE},
239 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
240 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
241 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
242 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
243 {"bnogc", no_argument, &gc, 0},
244 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
245 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
246 {"bnotextro", no_argument, &textro, 0},
247 {"bnro", no_argument, &textro, 0},
248 {"bpD", required_argument, NULL, OPTION_PD},
249 {"bpT", required_argument, NULL, OPTION_PT},
250 {"bro", no_argument, &textro, 1},
251 {"brtl", no_argument, &rtld, 1},
252 {"bS", required_argument, NULL, OPTION_MAXSTACK},
253 {"bso", no_argument, NULL, OPTION_AUTOIMP},
254 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
255 {"btextro", no_argument, &textro, 1},
256 {"b32", no_argument, NULL, OPTION_32},
257 {"b64", no_argument, NULL, OPTION_64},
258 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
259 {"unix", no_argument, NULL, OPTION_UNIX},
260 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
261 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
262 {NULL, no_argument, NULL, 0}
265 /* Options supported by the AIX linker which we do not support: -f,
266 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
267 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
268 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
269 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
270 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
271 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
274 /* If the current option starts with -b, change the first : to an =.
275 The AIX linker uses : to separate the option from the argument;
276 changing it to = lets us treat it as a getopt option. */
281 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
285 for (s = argv[indx]; *s != '\0'; s++)
296 /* We add s and u so to the short options list so that -s and -u on
297 the command line do not match -static and -unix. */
300 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
312 /* Long option which just sets a flag. */
316 val = strtoll (optarg, &end, 0);
318 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
320 lang_section_start (".data", exp_intop (val));
324 val = strtoul (optarg, &end, 0);
325 if (*end != '\0' || (val & (val - 1)) != 0)
326 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
333 /* FIXME: This should use the page size for the target system. */
338 /* On AIX this is the same as GNU ld -Ttext. When we see -T
339 number, we assume the AIX option is intended. Otherwise, we
340 assume the usual GNU ld -T option is intended. We can't just
341 ignore the AIX option, because gcc passes it to the linker. */
342 val = strtoull (optarg, &end, 0);
348 lang_section_start (".text", exp_intop (val));
354 case OPTION_INITFINI:
357 * The aix linker init fini has the format :
359 * -binitfini:[ Initial][:Termination][:Priority]
361 * it allows the Termination and Priority to be optional.
363 * Since we support only one init/fini pair, we ignore the Priority.
365 * Define the special symbol __rtinit.
367 * strtok does not correctly handle the case of -binitfini::fini: so
373 while (*t && ':' != *t)
379 link_info.init_function = i;
382 while (*t && ':' != *t)
387 link_info.fini_function = f;
392 link_info.static_link = false;
396 force_make_executable = false;
400 force_make_executable = true;
404 gld${EMULATION_NAME}_read_file (optarg, false);
410 struct filelist **flpp;
412 n = (struct filelist *) xmalloc (sizeof (struct filelist));
415 flpp = &import_files;
416 while (*flpp != NULL)
417 flpp = &(*flpp)->next;
423 config.map_filename = optarg;
427 val = strtoull (optarg, &end, 0);
429 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
434 case OPTION_MAXSTACK:
435 val = strtoull (optarg, &end, 0);
437 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
446 link_info.shared = true;
449 if (*optarg == '\0' || optarg[1] == '\0')
450 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
452 modtype = (*optarg << 8) | optarg[1];
455 case OPTION_NOAUTOIMP:
456 link_info.static_link = true;
459 case OPTION_NOSTRCMPCT:
460 link_info.traditional_format = true;
464 /* This sets the page that the .data section is supposed to
465 start on. The offset within the page should still be the
466 offset within the file, so we need to build an appropriate
468 val = strtoull (optarg, &end, 0);
470 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
478 exp_nameop (NAME, "."),
481 exp_binop ('+', t, exp_intop (31)),
482 exp_intop (~(bfd_vma) 31));
483 lang_section_start (".data", t);
488 /* This set the page that the .text section is supposed to start
489 on. The offset within the page should still be the offset
491 val = strtoull (optarg, &end, 0);
493 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
500 exp_nameop (SIZEOF_HEADERS, NULL));
502 exp_binop ('+', t, exp_intop (31)),
503 exp_intop (~(bfd_vma) 31));
504 lang_section_start (".text", t);
508 case OPTION_STRCMPCT:
509 link_info.traditional_format = false;
519 symbol_mode_mask = 0x0d;
525 symbol_mode_mask = 0x0e;
529 command_line_blibpath=optarg;
532 case OPTION_NOLIBPATH:
533 command_line_blibpath=NULL;
541 /* This is called when an input file can not be recognized as a BFD
542 object or an archive. If the file starts with #!, we must treat it
543 as an import file. This is for AIX compatibility. */
546 gld${EMULATION_NAME}_unrecognized_file (entry)
547 lang_input_statement_type *entry;
552 e = fopen (entry->filename, FOPEN_RT);
558 if (getc (e) == '#' && getc (e) == '!')
561 struct filelist **flpp;
563 n = (struct filelist *) xmalloc (sizeof (struct filelist));
565 n->name = entry->filename;
566 flpp = &import_files;
567 while (*flpp != NULL)
568 flpp = &(*flpp)->next;
572 entry->loaded = true;
580 /* This is called after the input files have been opened. */
583 gld${EMULATION_NAME}_after_open ()
588 /* Call ldctor_build_sets, after pretending that this is a
589 relocateable link. We do this because AIX requires relocation
590 entries for all references to symbols, even in a final
591 executable. Of course, we only want to do this if we are
592 producing an XCOFF output file. */
593 r = link_info.relocateable;
594 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
595 link_info.relocateable = true;
596 ldctor_build_sets ();
597 link_info.relocateable = r;
599 /* For each set, record the size, so that the XCOFF backend can
600 output the correct csect length. */
601 for (p = sets; p != (struct set_info *) NULL; p = p->next)
605 /* If the symbol is defined, we may have been invoked from
606 collect, and the sets may already have been built, so we do
608 if (p->h->type == bfd_link_hash_defined
609 || p->h->type == bfd_link_hash_defweak)
612 if (p->reloc != BFD_RELOC_CTOR)
614 /* Handle this if we need to. */
618 size = (p->count + 2) * 4;
619 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
620 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
624 /* This is called after the sections have been attached to output
625 sections, but before any sizes or addresses have been set. */
628 gld${EMULATION_NAME}_before_allocation ()
631 struct export_symbol_list *el;
633 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
636 /* Handle the import and export files, if any. */
637 for (fl = import_files; fl != NULL; fl = fl->next)
638 gld${EMULATION_NAME}_read_file (fl->name, true);
639 for (el = export_symbols; el != NULL; el = el->next)
641 struct bfd_link_hash_entry *h;
643 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
645 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
646 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
647 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
650 /* Track down all relocations called for by the linker script (these
651 are typically constructor/destructor entries created by
652 CONSTRUCTORS) and let the backend know it will need to create
653 .loader relocs for them. */
654 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
656 /* Precedence of LIBPATH
657 -blibpath: native support always first
658 -rpath: gnu extension
659 -L build from command line -L's */
660 if (command_line_blibpath != NULL)
661 libpath = command_line_blibpath;
662 else if (command_line.rpath != NULL)
663 libpath = command_line.rpath;
664 else if (search_head == NULL)
665 libpath = (char *) "";
669 search_dirs_type *search;
671 len = strlen (search_head->name);
672 libpath = xmalloc (len + 1);
673 strcpy (libpath, search_head->name);
674 for (search = search_head->next; search != NULL; search = search->next)
678 nlen = strlen (search->name);
679 libpath = xrealloc (libpath, len + nlen + 2);
681 strcpy (libpath + len + 1, search->name);
686 /* Let the XCOFF backend set up the .loader section. */
687 if (!bfd_xcoff_size_dynamic_sections
688 (output_bfd, &link_info, libpath, entry_symbol, file_align,
689 maxstack, maxdata, gc && !unix_ld ? true : false,
690 modtype, textro ? true : false, unix_ld, special_sections, rtld))
691 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
693 /* Look through the special sections, and put them in the right
694 place in the link ordering. This is especially magic. */
695 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
698 lang_output_section_statement_type *os;
699 lang_statement_union_type **pls;
700 lang_input_section_type *is;
704 sec = special_sections[i];
708 /* Remove this section from the list of the output section.
709 This assumes we know what the script looks like. */
711 os = lang_output_section_find (sec->output_section->name);
713 einfo ("%P%F: can't find output section %s\n",
714 sec->output_section->name);
716 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
718 if ((*pls)->header.type == lang_input_section_enum
719 && (*pls)->input_section.section == sec)
721 is = (lang_input_section_type *) * pls;
722 *pls = (*pls)->header.next;
726 if ((*pls)->header.type == lang_wild_statement_enum)
728 lang_statement_union_type **pwls;
730 for (pwls = &(*pls)->wild_statement.children.head;
731 *pwls != NULL; pwls = &(*pwls)->header.next)
734 if ((*pwls)->header.type == lang_input_section_enum
735 && (*pwls)->input_section.section == sec)
737 is = (lang_input_section_type *) * pwls;
738 *pwls = (*pwls)->header.next;
750 einfo ("%P%F: can't find %s in output section\n",
751 bfd_get_section_name (sec->owner, sec));
754 /* Now figure out where the section should go. */
758 default: /* to avoid warnings */
759 case XCOFF_SPECIAL_SECTION_TEXT:
765 case XCOFF_SPECIAL_SECTION_ETEXT:
771 case XCOFF_SPECIAL_SECTION_DATA:
777 case XCOFF_SPECIAL_SECTION_EDATA:
783 case XCOFF_SPECIAL_SECTION_END:
784 case XCOFF_SPECIAL_SECTION_END2:
791 os = lang_output_section_find (oname);
795 is->header.next = os->children.head;
796 os->children.head = (lang_statement_union_type *) is;
800 is->header.next = NULL;
801 lang_statement_append (&os->children,
802 (lang_statement_union_type *) is,
809 choose_target (argc, argv)
814 static char *from_outside;
815 static char *from_inside;
816 static char *argv_to_target[][2] = {
817 {NULL, "${OUTPUT_FORMAT}"},
818 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
819 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
824 from_outside = getenv (TARGET_ENVIRON);
825 if (from_outside != (char *) NULL)
828 /* Set to default. */
829 from_inside = argv_to_target[0][1];
830 for (i = 1; i < argc; i++)
832 for (j = 1; j < jmax; j++)
834 if (0 == strcmp (argv[i], argv_to_target[j][0]))
835 from_inside = argv_to_target[j][1];
846 change_symbol_mode (input)
849 char *symbol_mode_string[] = {
860 for (bit = 0;; bit++)
862 string = symbol_mode_string[bit];
866 if (0 == strcmp (input, string))
868 symbol_mode = (1 << bit);
872 /* should not be here */
879 -1 : error, try something else */
881 is_syscall (input, flag)
889 char *syscall_string;
892 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
893 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
894 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
895 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
896 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
897 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
898 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
899 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
905 for (bit = 0;; bit++)
907 string = s[bit].syscall_string;
911 if (0 == strcmp (input, string))
913 if (1 << bit & syscall_mask)
924 /* should not be here */
928 /* Read an import or export file. For an import file, this is called
929 by the before_allocation emulation routine. For an export file,
930 this is called by the parse_args emulation routine. */
933 gld${EMULATION_NAME}_read_file (filename, import)
934 const char *filename;
944 const char *impmember;
946 o = (struct obstack *) xmalloc (sizeof (struct obstack));
947 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
949 f = fopen (filename, FOPEN_RT);
952 bfd_set_error (bfd_error_system_call);
953 einfo ("%F%s: %E\n", filename);
964 /* Default to 32 and 64 bit mode
965 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
966 are not repeated, assume 64 bit routines also want to use them.
967 See the routine change_symbol_mode for more information. */
971 while ((c = getc (f)) != EOF)
975 unsigned int syscall_flag = 0;
977 struct bfd_link_hash_entry *h;
981 obstack_1grow (o, c);
985 obstack_1grow (o, '\0');
988 s = (char *) obstack_base (o);
993 || change_symbol_mode (s)
994 || (*s == '#' && s[1] == ' ')
995 || (!import && *s == '#' && s[1] == '!'))
997 obstack_free (o, obstack_base (o));
1001 if (*s == '#' && s[1] == '!')
1004 while (ISSPACE (*s))
1011 obstack_free (o, obstack_base (o));
1014 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1021 (void) obstack_finish (o);
1025 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1035 if (imppath == file - 1)
1045 while (ISSPACE (cs))
1054 einfo ("%s:%d: warning: syntax error in import file\n",
1061 while (*s != ')' && *s != '\0')
1066 einfo ("%s:%d: warning: syntax error in import file\n",
1074 if (symbol_mode & symbol_mode_mask)
1076 /* This is a symbol to be imported or exported. */
1079 address = (bfd_vma) -1;
1081 while (!ISSPACE (*s) && *s != '\0')
1089 while (ISSPACE (*s))
1093 while (!ISSPACE (*se) && *se != '\0')
1098 while (ISSPACE (*se))
1101 einfo ("%s%d: warning: syntax error in import/export file\n",
1110 status = is_syscall (s, &syscall_flag);
1114 /* not a system call, check for address */
1115 address = strtoul (s, &end, 0);
1118 einfo ("%s:%d: warning: syntax error in import/export file\n",
1128 struct export_symbol_list *n;
1130 ldlang_add_undef (symname);
1131 n = ((struct export_symbol_list *)
1132 xmalloc (sizeof (struct export_symbol_list)));
1133 n->next = export_symbols;
1134 n->name = xstrdup (symname);
1139 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1141 if (h == NULL || h->type == bfd_link_hash_new)
1143 /* We can just ignore attempts to import an unreferenced
1148 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1149 address, imppath, impfile,
1150 impmember, syscall_flag))
1151 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1152 filename, lineno, symname);
1156 obstack_free (o, obstack_base (o));
1159 if (obstack_object_size (o) > 0)
1161 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1163 obstack_free (o, obstack_base (o));
1168 obstack_free (o, NULL);
1173 /* This routine saves us from worrying about declaring free. */
1176 gld${EMULATION_NAME}_free (p)
1182 /* This is called by the before_allocation routine via
1183 lang_for_each_statement. It looks for relocations and assignments
1187 gld${EMULATION_NAME}_find_relocs (s)
1188 lang_statement_union_type *s;
1190 if (s->header.type == lang_reloc_statement_enum)
1192 lang_reloc_statement_type *rs;
1194 rs = &s->reloc_statement;
1195 if (rs->name == NULL)
1196 einfo ("%F%P: only relocations against symbols are permitted\n");
1197 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1198 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1201 if (s->header.type == lang_assignment_statement_enum)
1202 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1205 /* Look through an expression for an assignment statement. */
1208 gld${EMULATION_NAME}_find_exp_assignment (exp)
1211 struct bfd_link_hash_entry *h;
1213 switch (exp->type.node_class)
1216 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1217 false, false, false);
1222 if (strcmp (exp->assign.dst, ".") != 0)
1224 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1226 einfo ("%P%F: failed to record assignment to %s: %E\n",
1229 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1233 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1234 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1238 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1239 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1240 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1244 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1253 gld${EMULATION_NAME}_get_script (isfile)
1257 if test -n "$COMPILE_IN"
1259 # Scripts compiled in.
1261 # sed commands to quote an ld script as a C string.
1262 sc="-f ${srcdir}/emultempl/ostring.sed"
1264 cat >>e${EMULATION_NAME}.c <<EOF
1268 if (link_info.relocateable == true && config.build_constructors == true)
1271 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1272 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1273 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1274 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1275 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1276 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1277 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1278 echo ' ; else return' >> e${EMULATION_NAME}.c
1279 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1280 echo '; }' >> e${EMULATION_NAME}.c
1283 # Scripts read from the filesystem.
1285 cat >>e${EMULATION_NAME}.c <<EOF
1289 if (link_info.relocateable == true && config.build_constructors == true)
1290 return "ldscripts/${EMULATION_NAME}.xu";
1291 else if (link_info.relocateable == true)
1292 return "ldscripts/${EMULATION_NAME}.xr";
1293 else if (!config.text_read_only)
1294 return "ldscripts/${EMULATION_NAME}.xbn";
1295 else if (!config.magic_demand_paged)
1296 return "ldscripts/${EMULATION_NAME}.xn";
1298 return "ldscripts/${EMULATION_NAME}.x";
1304 cat >>e${EMULATION_NAME}.c <<EOF
1307 gld${EMULATION_NAME}_create_output_section_statements()
1310 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1311 && (link_info.init_function != NULL
1312 || link_info.fini_function != NULL
1315 initfini_file = lang_add_input_file ("initfini",
1316 lang_input_file_is_file_enum,
1319 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1320 if (initfini_file->the_bfd == NULL
1321 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1322 bfd_get_arch (output_bfd),
1323 bfd_get_mach (output_bfd)))
1325 einfo ("%X%P: can not create BFD %E\n");
1329 /* Call backend to fill in the rest */
1330 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1331 link_info.init_function,
1332 link_info.fini_function,
1335 einfo ("%X%P: can not create BFD %E\n");
1339 /* __rtld defined in /lib/librtl.a */
1341 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1345 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1346 gld${EMULATION_NAME}_before_parse,
1349 after_parse_default,
1350 gld${EMULATION_NAME}_after_open,
1351 after_allocation_default,
1352 set_output_arch_default,
1354 gld${EMULATION_NAME}_before_allocation,
1355 gld${EMULATION_NAME}_get_script,
1356 "${EMULATION_NAME}",
1359 gld${EMULATION_NAME}_create_output_section_statements,
1360 0, /* open_dynamic_archive */
1361 0, /* place_orphan */
1362 0, /* set_symbols */
1363 gld${EMULATION_NAME}_parse_args,
1364 gld${EMULATION_NAME}_unrecognized_file,
1365 NULL, /* list_options */
1366 NULL, /* recognized_file */
1367 NULL, /* find potential_libraries */