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
61 static int gld${EMULATION_NAME}_parse_args
62 PARAMS ((int, char **));
63 static void gld${EMULATION_NAME}_after_open
65 static char *gld${EMULATION_NAME}_choose_target
66 PARAMS ((int, char **));
67 static void gld${EMULATION_NAME}_before_allocation
69 static void gld${EMULATION_NAME}_read_file
70 PARAMS ((const char *, bfd_boolean));
71 static void gld${EMULATION_NAME}_free
73 static void gld${EMULATION_NAME}_find_relocs
74 PARAMS ((lang_statement_union_type *));
75 static void gld${EMULATION_NAME}_find_exp_assignment
76 PARAMS ((etree_type *));
77 static char *gld${EMULATION_NAME}_get_script
78 PARAMS ((int *isfile));
79 static bfd_boolean gld${EMULATION_NAME}_unrecognized_file
80 PARAMS ((lang_input_statement_type *));
81 static void gld${EMULATION_NAME}_create_output_section_statements
83 static void gld${EMULATION_NAME}_set_output_arch
86 PARAMS ((char *, unsigned int *));
87 static int change_symbol_mode
90 /* The file alignment required for each section. */
91 static unsigned long file_align;
93 /* The maximum size the stack is permitted to grow. This is stored in
95 static unsigned long maxstack;
97 /* The maximum data size. This is stored in the a.out header. */
98 static unsigned long maxdata;
100 /* Whether to perform garbage collection. */
103 /* The module type to use. */
104 static unsigned short modtype = ('1' << 8) | 'L';
106 /* Whether the .text section must be read-only (i.e., no relocs
110 /* Whether to implement Unix like linker semantics. */
113 /* Structure used to hold import file list. */
117 struct filelist *next;
121 /* List of import files. */
122 static struct filelist *import_files;
124 /* List of export symbols read from the export files. */
126 struct export_symbol_list
128 struct export_symbol_list *next;
132 static struct export_symbol_list *export_symbols;
134 /* Maintains the 32 or 64 bit mode state of import file */
135 static unsigned int symbol_mode = 0x04;
137 /* Which symbol modes are valid */
138 static unsigned int symbol_mode_mask = 0x0d;
140 /* Whether this is a 64 bit link */
141 static int is_64bit = 0;
143 /* Which syscalls from import file are valid */
144 static unsigned int syscall_mask = 0x77;
146 /* fake file for -binitfini support */
147 static lang_input_statement_type *initfini_file;
149 /* Whether to do run time linking
150 -brtl enables, -bnortl and -bnortllib disable. */
153 /* Explicit command line library path, -blibpath */
154 static char *command_line_blibpath = NULL;
156 /* This routine is called before anything else is done. */
159 gld${EMULATION_NAME}_before_parse ()
161 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
164 ldfile_output_architecture = arch->arch;
165 ldfile_output_machine = arch->mach;
166 ldfile_output_machine_name = arch->printable_name;
169 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`;
171 config.has_shared = TRUE;
173 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
174 Override them here so we can use the link_info.init_function as a
175 state flag that lets the backend know that -binitfini has been done. */
177 link_info.init_function = NULL;
178 link_info.fini_function = NULL;
181 /* Handle AIX specific options. */
184 gld${EMULATION_NAME}_parse_args (argc, argv)
188 int prevoptind = optind;
189 int prevopterr = opterr;
221 /* -binitfini has special handling in the linker backend. The native linker
222 uses the arguemnts to generate a table of init and fini functions for
223 the executable. The important use for this option is to support aix 4.2+
224 c++ constructors and destructors. This is tied into gcc via collect2.c.
226 The function table is accessed by the runtime linker/loader by checking if
227 the first symbol in the loader symbol table is __rtinit. The gnu linker
228 generates this symbol and makes it the first loader symbol. */
230 static const struct option longopts[] = {
231 {"basis", no_argument, NULL, OPTION_IGNORE},
232 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
233 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
234 {"bcrld", no_argument, NULL, OPTION_IGNORE},
235 {"bcror31", no_argument, NULL, OPTION_IGNORE},
236 {"bD", required_argument, NULL, OPTION_MAXDATA},
237 {"bE", required_argument, NULL, OPTION_EXPORT},
238 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
239 {"berok", no_argument, NULL, OPTION_EROK},
240 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
241 {"bexport", required_argument, NULL, OPTION_EXPORT},
242 {"bf", no_argument, NULL, OPTION_ERNOTOK},
243 {"bgc", no_argument, &gc, 1},
244 {"bh", required_argument, NULL, OPTION_IGNORE},
245 {"bhalt", required_argument, NULL, OPTION_IGNORE},
246 {"bI", required_argument, NULL, OPTION_IMPORT},
247 {"bimport", required_argument, NULL, OPTION_IMPORT},
248 {"binitfini", required_argument, NULL, OPTION_INITFINI},
249 {"bl", required_argument, NULL, OPTION_LOADMAP},
250 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
251 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
252 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
253 {"bM", required_argument, NULL, OPTION_MODTYPE},
254 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
255 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
256 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
257 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
258 {"bnogc", no_argument, &gc, 0},
259 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
260 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
261 {"bnotextro", no_argument, &textro, 0},
262 {"bnro", no_argument, &textro, 0},
263 {"bpD", required_argument, NULL, OPTION_PD},
264 {"bpT", required_argument, NULL, OPTION_PT},
265 {"bro", no_argument, &textro, 1},
266 {"brtl", no_argument, &rtld, 1},
267 {"bnortl", no_argument, &rtld, 0},
268 {"bnortllib", no_argument, &rtld, 0},
269 {"bS", required_argument, NULL, OPTION_MAXSTACK},
270 {"bso", no_argument, NULL, OPTION_AUTOIMP},
271 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
272 {"btextro", no_argument, &textro, 1},
273 {"b32", no_argument, NULL, OPTION_32},
274 {"b64", no_argument, NULL, OPTION_64},
275 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
276 {"unix", no_argument, NULL, OPTION_UNIX},
277 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
278 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
279 {NULL, no_argument, NULL, 0}
282 /* Options supported by the AIX linker which we do not support: -f,
283 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
284 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
285 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
286 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
287 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
288 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
291 /* If the current option starts with -b, change the first : to an =.
292 The AIX linker uses : to separate the option from the argument;
293 changing it to = lets us treat it as a getopt option. */
298 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
302 for (s = argv[indx]; *s != '\0'; s++)
313 /* We add s and u so to the short options list so that -s and -u on
314 the command line do not match -static and -unix. */
317 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
329 /* Long option which just sets a flag. */
333 val = bfd_scan_vma (optarg, &end, 0);
335 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
337 lang_section_start (".data", exp_intop (val));
341 val = bfd_scan_vma (optarg, &end, 0);
342 if (*end != '\0' || (val & (val - 1)) != 0)
343 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
350 /* FIXME: This should use the page size for the target system. */
355 /* On AIX this is the same as GNU ld -Ttext. When we see -T
356 number, we assume the AIX option is intended. Otherwise, we
357 assume the usual GNU ld -T option is intended. We can't just
358 ignore the AIX option, because gcc passes it to the linker. */
359 val = bfd_scan_vma (optarg, &end, 0);
365 lang_section_start (".text", exp_intop (val));
371 case OPTION_INITFINI:
374 * The aix linker init fini has the format :
376 * -binitfini:[ Initial][:Termination][:Priority]
378 * it allows the Termination and Priority to be optional.
380 * Since we support only one init/fini pair, we ignore the Priority.
382 * Define the special symbol __rtinit.
384 * strtok does not correctly handle the case of -binitfini::fini: so
390 while (*t && ':' != *t)
396 link_info.init_function = i;
399 while (*t && ':' != *t)
404 link_info.fini_function = f;
409 link_info.static_link = FALSE;
413 force_make_executable = FALSE;
417 force_make_executable = TRUE;
421 gld${EMULATION_NAME}_read_file (optarg, FALSE);
427 struct filelist **flpp;
429 n = (struct filelist *) xmalloc (sizeof (struct filelist));
432 flpp = &import_files;
433 while (*flpp != NULL)
434 flpp = &(*flpp)->next;
440 config.map_filename = optarg;
444 val = bfd_scan_vma (optarg, &end, 0);
446 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
451 case OPTION_MAXSTACK:
452 val = bfd_scan_vma (optarg, &end, 0);
454 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
463 link_info.shared = TRUE;
466 if (*optarg == '\0' || optarg[1] == '\0')
467 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
469 modtype = (*optarg << 8) | optarg[1];
472 case OPTION_NOAUTOIMP:
473 link_info.static_link = TRUE;
476 case OPTION_NOSTRCMPCT:
477 link_info.traditional_format = TRUE;
481 /* This sets the page that the .data section is supposed to
482 start on. The offset within the page should still be the
483 offset within the file, so we need to build an appropriate
485 val = bfd_scan_vma (optarg, &end, 0);
487 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
495 exp_nameop (NAME, "."),
498 exp_binop ('+', t, exp_intop (31)),
499 exp_intop (~(bfd_vma) 31));
500 lang_section_start (".data", t);
505 /* This set the page that the .text section is supposed to start
506 on. The offset within the page should still be the offset
508 val = bfd_scan_vma (optarg, &end, 0);
510 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
517 exp_nameop (SIZEOF_HEADERS, NULL));
519 exp_binop ('+', t, exp_intop (31)),
520 exp_intop (~(bfd_vma) 31));
521 lang_section_start (".text", t);
525 case OPTION_STRCMPCT:
526 link_info.traditional_format = FALSE;
536 symbol_mode_mask = 0x0d;
542 symbol_mode_mask = 0x0e;
546 command_line_blibpath = optarg;
549 case OPTION_NOLIBPATH:
550 command_line_blibpath = NULL;
558 /* This is called when an input file can not be recognized as a BFD
559 object or an archive. If the file starts with #!, we must treat it
560 as an import file. This is for AIX compatibility. */
563 gld${EMULATION_NAME}_unrecognized_file (entry)
564 lang_input_statement_type *entry;
569 e = fopen (entry->filename, FOPEN_RT);
575 if (getc (e) == '#' && getc (e) == '!')
578 struct filelist **flpp;
580 n = (struct filelist *) xmalloc (sizeof (struct filelist));
582 n->name = entry->filename;
583 flpp = &import_files;
584 while (*flpp != NULL)
585 flpp = &(*flpp)->next;
589 entry->loaded = TRUE;
597 /* This is called after the input files have been opened. */
600 gld${EMULATION_NAME}_after_open ()
605 /* Call ldctor_build_sets, after pretending that this is a
606 relocateable link. We do this because AIX requires relocation
607 entries for all references to symbols, even in a final
608 executable. Of course, we only want to do this if we are
609 producing an XCOFF output file. */
610 r = link_info.relocateable;
611 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
612 link_info.relocateable = TRUE;
613 ldctor_build_sets ();
614 link_info.relocateable = r;
616 /* For each set, record the size, so that the XCOFF backend can
617 output the correct csect length. */
618 for (p = sets; p != (struct set_info *) NULL; p = p->next)
622 /* If the symbol is defined, we may have been invoked from
623 collect, and the sets may already have been built, so we do
625 if (p->h->type == bfd_link_hash_defined
626 || p->h->type == bfd_link_hash_defweak)
629 if (p->reloc != BFD_RELOC_CTOR)
631 /* Handle this if we need to. */
635 size = (p->count + 2) * 4;
636 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
637 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
641 /* This is called after the sections have been attached to output
642 sections, but before any sizes or addresses have been set. */
645 gld${EMULATION_NAME}_before_allocation ()
648 struct export_symbol_list *el;
650 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
653 /* Handle the import and export files, if any. */
654 for (fl = import_files; fl != NULL; fl = fl->next)
655 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
656 for (el = export_symbols; el != NULL; el = el->next)
658 struct bfd_link_hash_entry *h;
660 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
662 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
663 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
664 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
667 /* Track down all relocations called for by the linker script (these
668 are typically constructor/destructor entries created by
669 CONSTRUCTORS) and let the backend know it will need to create
670 .loader relocs for them. */
671 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
673 /* Precedence of LIBPATH
674 -blibpath: native support always first
675 -rpath: gnu extension
676 -L build from command line -L's */
677 if (command_line_blibpath != NULL)
678 libpath = command_line_blibpath;
679 else if (command_line.rpath != NULL)
680 libpath = command_line.rpath;
681 else if (search_head == NULL)
682 libpath = (char *) "";
686 search_dirs_type *search;
688 len = strlen (search_head->name);
689 libpath = xmalloc (len + 1);
690 strcpy (libpath, search_head->name);
691 for (search = search_head->next; search != NULL; search = search->next)
695 nlen = strlen (search->name);
696 libpath = xrealloc (libpath, len + nlen + 2);
698 strcpy (libpath + len + 1, search->name);
703 /* Let the XCOFF backend set up the .loader section. */
704 if (!bfd_xcoff_size_dynamic_sections
705 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
706 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
707 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
708 rtld ? TRUE : FALSE))
709 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
711 /* Look through the special sections, and put them in the right
712 place in the link ordering. This is especially magic. */
713 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
716 lang_output_section_statement_type *os;
717 lang_statement_union_type **pls;
718 lang_input_section_type *is;
722 sec = special_sections[i];
726 /* Remove this section from the list of the output section.
727 This assumes we know what the script looks like. */
729 os = lang_output_section_find (sec->output_section->name);
731 einfo ("%P%F: can't find output section %s\n",
732 sec->output_section->name);
734 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
736 if ((*pls)->header.type == lang_input_section_enum
737 && (*pls)->input_section.section == sec)
739 is = (lang_input_section_type *) * pls;
740 *pls = (*pls)->header.next;
744 if ((*pls)->header.type == lang_wild_statement_enum)
746 lang_statement_union_type **pwls;
748 for (pwls = &(*pls)->wild_statement.children.head;
749 *pwls != NULL; pwls = &(*pwls)->header.next)
752 if ((*pwls)->header.type == lang_input_section_enum
753 && (*pwls)->input_section.section == sec)
755 is = (lang_input_section_type *) * pwls;
756 *pwls = (*pwls)->header.next;
768 einfo ("%P%F: can't find %s in output section\n",
769 bfd_get_section_name (sec->owner, sec));
772 /* Now figure out where the section should go. */
776 default: /* to avoid warnings */
777 case XCOFF_SPECIAL_SECTION_TEXT:
783 case XCOFF_SPECIAL_SECTION_ETEXT:
789 case XCOFF_SPECIAL_SECTION_DATA:
795 case XCOFF_SPECIAL_SECTION_EDATA:
801 case XCOFF_SPECIAL_SECTION_END:
802 case XCOFF_SPECIAL_SECTION_END2:
809 os = lang_output_section_find (oname);
813 is->header.next = os->children.head;
814 os->children.head = (lang_statement_union_type *) is;
818 is->header.next = NULL;
819 lang_statement_append (&os->children,
820 (lang_statement_union_type *) is,
827 gld${EMULATION_NAME}_choose_target (argc, argv)
832 static char *from_outside;
833 static char *from_inside;
834 static char *argv_to_target[][2] = {
835 {NULL, "${OUTPUT_FORMAT}"},
836 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
837 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
842 from_outside = getenv (TARGET_ENVIRON);
843 if (from_outside != (char *) NULL)
846 /* Set to default. */
847 from_inside = argv_to_target[0][1];
848 for (i = 1; i < argc; i++)
850 for (j = 1; j < jmax; j++)
852 if (0 == strcmp (argv[i], argv_to_target[j][0]))
853 from_inside = argv_to_target[j][1];
864 change_symbol_mode (input)
867 char *symbol_mode_string[] = {
878 for (bit = 0;; bit++)
880 string = symbol_mode_string[bit];
884 if (0 == strcmp (input, string))
886 symbol_mode = (1 << bit);
890 /* should not be here */
897 -1 : error, try something else */
899 is_syscall (input, flag)
907 char *syscall_string;
910 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
911 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
912 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
913 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
914 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
915 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
916 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
917 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
923 for (bit = 0;; bit++)
925 string = s[bit].syscall_string;
929 if (0 == strcmp (input, string))
931 if (1 << bit & syscall_mask)
942 /* should not be here */
946 /* Read an import or export file. For an import file, this is called
947 by the before_allocation emulation routine. For an export file,
948 this is called by the parse_args emulation routine. */
951 gld${EMULATION_NAME}_read_file (filename, import)
952 const char *filename;
962 const char *impmember;
964 o = (struct obstack *) xmalloc (sizeof (struct obstack));
965 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
967 f = fopen (filename, FOPEN_RT);
970 bfd_set_error (bfd_error_system_call);
971 einfo ("%F%s: %E\n", filename);
982 /* Default to 32 and 64 bit mode
983 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
984 are not repeated, assume 64 bit routines also want to use them.
985 See the routine change_symbol_mode for more information. */
989 while ((c = getc (f)) != EOF)
993 unsigned int syscall_flag = 0;
995 struct bfd_link_hash_entry *h;
999 obstack_1grow (o, c);
1003 obstack_1grow (o, '\0');
1006 s = (char *) obstack_base (o);
1007 while (ISSPACE (*s))
1011 || change_symbol_mode (s)
1012 || (*s == '#' && s[1] == ' ')
1013 || (!import && *s == '#' && s[1] == '!'))
1015 obstack_free (o, obstack_base (o));
1019 if (*s == '#' && s[1] == '!')
1022 while (ISSPACE (*s))
1029 obstack_free (o, obstack_base (o));
1032 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1039 (void) obstack_finish (o);
1043 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1053 if (imppath == file - 1)
1063 while (ISSPACE (cs))
1072 einfo ("%s:%d: warning: syntax error in import file\n",
1079 while (*s != ')' && *s != '\0')
1084 einfo ("%s:%d: warning: syntax error in import file\n",
1092 if (symbol_mode & symbol_mode_mask)
1094 /* This is a symbol to be imported or exported. */
1097 address = (bfd_vma) -1;
1099 while (!ISSPACE (*s) && *s != '\0')
1107 while (ISSPACE (*s))
1111 while (!ISSPACE (*se) && *se != '\0')
1116 while (ISSPACE (*se))
1119 einfo ("%s%d: warning: syntax error in import/export file\n",
1128 status = is_syscall (s, &syscall_flag);
1132 /* not a system call, check for address */
1133 address = bfd_scan_vma (s, &end, 0);
1136 einfo ("%s:%d: warning: syntax error in import/export file\n",
1146 struct export_symbol_list *n;
1148 ldlang_add_undef (symname);
1149 n = ((struct export_symbol_list *)
1150 xmalloc (sizeof (struct export_symbol_list)));
1151 n->next = export_symbols;
1152 n->name = xstrdup (symname);
1157 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1159 if (h == NULL || h->type == bfd_link_hash_new)
1161 /* We can just ignore attempts to import an unreferenced
1166 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1167 address, imppath, impfile,
1168 impmember, syscall_flag))
1169 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1170 filename, lineno, symname);
1174 obstack_free (o, obstack_base (o));
1177 if (obstack_object_size (o) > 0)
1179 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1181 obstack_free (o, obstack_base (o));
1186 obstack_free (o, NULL);
1191 /* This routine saves us from worrying about declaring free. */
1194 gld${EMULATION_NAME}_free (p)
1200 /* This is called by the before_allocation routine via
1201 lang_for_each_statement. It looks for relocations and assignments
1205 gld${EMULATION_NAME}_find_relocs (s)
1206 lang_statement_union_type *s;
1208 if (s->header.type == lang_reloc_statement_enum)
1210 lang_reloc_statement_type *rs;
1212 rs = &s->reloc_statement;
1213 if (rs->name == NULL)
1214 einfo ("%F%P: only relocations against symbols are permitted\n");
1215 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1216 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1219 if (s->header.type == lang_assignment_statement_enum)
1220 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1223 /* Look through an expression for an assignment statement. */
1226 gld${EMULATION_NAME}_find_exp_assignment (exp)
1229 struct bfd_link_hash_entry *h;
1231 switch (exp->type.node_class)
1234 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1235 FALSE, FALSE, FALSE);
1240 if (strcmp (exp->assign.dst, ".") != 0)
1242 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1244 einfo ("%P%F: failed to record assignment to %s: %E\n",
1247 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1251 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1252 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1256 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1257 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1258 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1262 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1271 gld${EMULATION_NAME}_get_script (isfile)
1275 if test -n "$COMPILE_IN"
1277 # Scripts compiled in.
1279 # sed commands to quote an ld script as a C string.
1280 sc="-f ${srcdir}/emultempl/ostring.sed"
1282 cat >>e${EMULATION_NAME}.c <<EOF
1286 if (link_info.relocateable && config.build_constructors)
1289 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1290 echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
1291 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1292 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1293 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1294 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1295 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1296 echo ' ; else return' >> e${EMULATION_NAME}.c
1297 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1298 echo '; }' >> e${EMULATION_NAME}.c
1301 # Scripts read from the filesystem.
1303 cat >>e${EMULATION_NAME}.c <<EOF
1307 if (link_info.relocateable && config.build_constructors)
1308 return "ldscripts/${EMULATION_NAME}.xu";
1309 else if (link_info.relocateable)
1310 return "ldscripts/${EMULATION_NAME}.xr";
1311 else if (!config.text_read_only)
1312 return "ldscripts/${EMULATION_NAME}.xbn";
1313 else if (!config.magic_demand_paged)
1314 return "ldscripts/${EMULATION_NAME}.xn";
1316 return "ldscripts/${EMULATION_NAME}.x";
1322 cat >>e${EMULATION_NAME}.c <<EOF
1325 gld${EMULATION_NAME}_create_output_section_statements ()
1328 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1329 && (link_info.init_function != NULL
1330 || link_info.fini_function != NULL
1333 initfini_file = lang_add_input_file ("initfini",
1334 lang_input_file_is_file_enum,
1337 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1338 if (initfini_file->the_bfd == NULL
1339 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1340 bfd_get_arch (output_bfd),
1341 bfd_get_mach (output_bfd)))
1343 einfo ("%X%P: can not create BFD %E\n");
1347 /* Call backend to fill in the rest */
1348 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1349 link_info.init_function,
1350 link_info.fini_function,
1353 einfo ("%X%P: can not create BFD %E\n");
1357 /* __rtld defined in /lib/librtl.a */
1359 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1364 gld${EMULATION_NAME}_set_output_arch ()
1366 bfd_set_arch_mach (output_bfd,
1367 bfd_xcoff_architecture (output_bfd),
1368 bfd_xcoff_machine (output_bfd));
1370 ldfile_output_architecture = bfd_get_arch (output_bfd);
1371 ldfile_output_machine = bfd_get_mach (output_bfd);
1372 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1375 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1376 gld${EMULATION_NAME}_before_parse,
1379 after_parse_default,
1380 gld${EMULATION_NAME}_after_open,
1381 after_allocation_default,
1382 gld${EMULATION_NAME}_set_output_arch,
1383 gld${EMULATION_NAME}_choose_target,
1384 gld${EMULATION_NAME}_before_allocation,
1385 gld${EMULATION_NAME}_get_script,
1386 "${EMULATION_NAME}",
1389 gld${EMULATION_NAME}_create_output_section_statements,
1390 0, /* open_dynamic_archive */
1391 0, /* place_orphan */
1392 0, /* set_symbols */
1393 gld${EMULATION_NAME}_parse_args,
1394 gld${EMULATION_NAME}_unrecognized_file,
1395 NULL, /* list_options */
1396 NULL, /* recognized_file */
1397 NULL, /* find potential_libraries */
1398 NULL /* new_vers_pattern */