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, 2003
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 bfd_boolean gld${EMULATION_NAME}_parse_args
62 PARAMS ((int, char **));
63 static void gld${EMULATION_NAME}_add_options
64 PARAMS ((int, char **, int, struct option **, int, struct option **));
65 static bfd_boolean gld${EMULATION_NAME}_handle_option
67 static void gld${EMULATION_NAME}_after_open
69 static char *gld${EMULATION_NAME}_choose_target
70 PARAMS ((int, char **));
71 static void gld${EMULATION_NAME}_before_allocation
73 static void gld${EMULATION_NAME}_read_file
74 PARAMS ((const char *, bfd_boolean));
75 static void gld${EMULATION_NAME}_free
77 static void gld${EMULATION_NAME}_find_relocs
78 PARAMS ((lang_statement_union_type *));
79 static void gld${EMULATION_NAME}_find_exp_assignment
80 PARAMS ((etree_type *));
81 static char *gld${EMULATION_NAME}_get_script
82 PARAMS ((int *isfile));
83 static bfd_boolean gld${EMULATION_NAME}_unrecognized_file
84 PARAMS ((lang_input_statement_type *));
85 static void gld${EMULATION_NAME}_create_output_section_statements
87 static void gld${EMULATION_NAME}_set_output_arch
90 PARAMS ((char *, unsigned int *));
91 static int change_symbol_mode
94 /* The file alignment required for each section. */
95 static unsigned long file_align;
97 /* The maximum size the stack is permitted to grow. This is stored in
99 static unsigned long maxstack;
101 /* The maximum data size. This is stored in the a.out header. */
102 static unsigned long maxdata;
104 /* Whether to perform garbage collection. */
107 /* The module type to use. */
108 static unsigned short modtype = ('1' << 8) | 'L';
110 /* Whether the .text section must be read-only (i.e., no relocs
114 /* Whether to implement Unix like linker semantics. */
117 /* Structure used to hold import file list. */
121 struct filelist *next;
125 /* List of import files. */
126 static struct filelist *import_files;
128 /* List of export symbols read from the export files. */
130 struct export_symbol_list
132 struct export_symbol_list *next;
136 static struct export_symbol_list *export_symbols;
138 /* Maintains the 32 or 64 bit mode state of import file */
139 static unsigned int symbol_mode = 0x04;
141 /* Which symbol modes are valid */
142 static unsigned int symbol_mode_mask = 0x0d;
144 /* Whether this is a 64 bit link */
145 static int is_64bit = 0;
147 /* Which syscalls from import file are valid */
148 static unsigned int syscall_mask = 0x77;
150 /* fake file for -binitfini support */
151 static lang_input_statement_type *initfini_file;
153 /* Whether to do run time linking
154 -brtl enables, -bnortl and -bnortllib disable. */
157 /* Explicit command line library path, -blibpath */
158 static char *command_line_blibpath = NULL;
160 /* This routine is called before anything else is done. */
163 gld${EMULATION_NAME}_before_parse ()
165 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
168 ldfile_output_architecture = arch->arch;
169 ldfile_output_machine = arch->mach;
170 ldfile_output_machine_name = arch->printable_name;
173 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`;
175 config.has_shared = TRUE;
177 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
178 Override them here so we can use the link_info.init_function as a
179 state flag that lets the backend know that -binitfini has been done. */
181 link_info.init_function = NULL;
182 link_info.fini_function = NULL;
185 /* Handle AIX specific options. */
213 gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
217 struct option **longopts;
218 int nrl ATTRIBUTE_UNUSED;
219 struct option **really_longopts ATTRIBUTE_UNUSED;
221 static const char xtra_short[] = "D:H:KT:z";
222 static const struct option xtra_long[] = {
223 /* -binitfini has special handling in the linker backend. The native linker
224 uses the arguemnts to generate a table of init and fini functions for
225 the executable. The important use for this option is to support aix 4.2+
226 c++ constructors and destructors. This is tied into gcc via collect2.c.
228 The function table is accessed by the runtime linker/loader by checking if
229 the first symbol in the loader symbol table is __rtinit. The gnu linker
230 generates this symbol and makes it the first loader symbol. */
232 {"basis", no_argument, NULL, OPTION_IGNORE},
233 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
234 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
235 {"bcrld", no_argument, NULL, OPTION_IGNORE},
236 {"bcror31", no_argument, NULL, OPTION_IGNORE},
237 {"bD", required_argument, NULL, OPTION_MAXDATA},
238 {"bE", required_argument, NULL, OPTION_EXPORT},
239 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
240 {"berok", no_argument, NULL, OPTION_EROK},
241 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
242 {"bexport", required_argument, NULL, OPTION_EXPORT},
243 {"bf", no_argument, NULL, OPTION_ERNOTOK},
244 {"bgc", no_argument, &gc, 1},
245 {"bh", required_argument, NULL, OPTION_IGNORE},
246 {"bhalt", required_argument, NULL, OPTION_IGNORE},
247 {"bI", required_argument, NULL, OPTION_IMPORT},
248 {"bimport", required_argument, NULL, OPTION_IMPORT},
249 {"binitfini", required_argument, NULL, OPTION_INITFINI},
250 {"bl", required_argument, NULL, OPTION_LOADMAP},
251 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
252 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
253 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
254 {"bM", required_argument, NULL, OPTION_MODTYPE},
255 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
256 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
257 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
258 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
259 {"bnogc", no_argument, &gc, 0},
260 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
261 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
262 {"bnotextro", no_argument, &textro, 0},
263 {"bnro", no_argument, &textro, 0},
264 {"bpD", required_argument, NULL, OPTION_PD},
265 {"bpT", required_argument, NULL, OPTION_PT},
266 {"bro", no_argument, &textro, 1},
267 {"brtl", no_argument, &rtld, 1},
268 {"bnortl", no_argument, &rtld, 0},
269 {"bnortllib", no_argument, &rtld, 0},
270 {"bS", required_argument, NULL, OPTION_MAXSTACK},
271 {"bso", no_argument, NULL, OPTION_AUTOIMP},
272 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
273 {"btextro", no_argument, &textro, 1},
274 {"b32", no_argument, NULL, OPTION_32},
275 {"b64", no_argument, NULL, OPTION_64},
276 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
277 {"unix", no_argument, NULL, OPTION_UNIX},
278 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
279 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
280 {NULL, no_argument, NULL, 0}
283 /* Options supported by the AIX linker which we do not support: -f,
284 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
285 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
286 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
287 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
288 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
289 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
292 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
293 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
294 *longopts = (struct option *)
295 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
296 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
300 gld${EMULATION_NAME}_parse_args (argc, argv)
306 /* If the current option starts with -b, change the first : to an =.
307 The AIX linker uses : to separate the option from the argument;
308 changing it to = lets us treat it as a getopt option. */
313 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
317 for (s = argv[indx]; *s != '\0'; s++)
330 gld${EMULATION_NAME}_handle_option (optc)
342 /* Long option which just sets a flag. */
346 val = bfd_scan_vma (optarg, &end, 0);
348 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
350 lang_section_start (".data", exp_intop (val));
354 val = bfd_scan_vma (optarg, &end, 0);
355 if (*end != '\0' || (val & (val - 1)) != 0)
356 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
363 /* FIXME: This should use the page size for the target system. */
368 /* On AIX this is the same as GNU ld -Ttext. When we see -T
369 number, we assume the AIX option is intended. Otherwise, we
370 assume the usual GNU ld -T option is intended. We can't just
371 ignore the AIX option, because gcc passes it to the linker. */
372 val = bfd_scan_vma (optarg, &end, 0);
375 lang_section_start (".text", exp_intop (val));
381 case OPTION_INITFINI:
384 * The aix linker init fini has the format :
386 * -binitfini:[ Initial][:Termination][:Priority]
388 * it allows the Termination and Priority to be optional.
390 * Since we support only one init/fini pair, we ignore the Priority.
392 * Define the special symbol __rtinit.
394 * strtok does not correctly handle the case of -binitfini::fini: so
400 while (*t && ':' != *t)
406 link_info.init_function = i;
409 while (*t && ':' != *t)
414 link_info.fini_function = f;
419 link_info.static_link = FALSE;
423 force_make_executable = FALSE;
427 force_make_executable = TRUE;
431 gld${EMULATION_NAME}_read_file (optarg, FALSE);
437 struct filelist **flpp;
439 n = (struct filelist *) xmalloc (sizeof (struct filelist));
442 flpp = &import_files;
443 while (*flpp != NULL)
444 flpp = &(*flpp)->next;
450 config.map_filename = optarg;
454 val = bfd_scan_vma (optarg, &end, 0);
456 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
461 case OPTION_MAXSTACK:
462 val = bfd_scan_vma (optarg, &end, 0);
464 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
473 link_info.shared = TRUE;
476 if (*optarg == '\0' || optarg[1] == '\0')
477 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
479 modtype = (*optarg << 8) | optarg[1];
482 case OPTION_NOAUTOIMP:
483 link_info.static_link = TRUE;
486 case OPTION_NOSTRCMPCT:
487 link_info.traditional_format = TRUE;
491 /* This sets the page that the .data section is supposed to
492 start on. The offset within the page should still be the
493 offset within the file, so we need to build an appropriate
495 val = bfd_scan_vma (optarg, &end, 0);
497 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
505 exp_nameop (NAME, "."),
508 exp_binop ('+', t, exp_intop (31)),
509 exp_intop (~(bfd_vma) 31));
510 lang_section_start (".data", t);
515 /* This set the page that the .text section is supposed to start
516 on. The offset within the page should still be the offset
518 val = bfd_scan_vma (optarg, &end, 0);
520 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
527 exp_nameop (SIZEOF_HEADERS, NULL));
529 exp_binop ('+', t, exp_intop (31)),
530 exp_intop (~(bfd_vma) 31));
531 lang_section_start (".text", t);
535 case OPTION_STRCMPCT:
536 link_info.traditional_format = FALSE;
546 symbol_mode_mask = 0x0d;
552 symbol_mode_mask = 0x0e;
556 command_line_blibpath = optarg;
559 case OPTION_NOLIBPATH:
560 command_line_blibpath = NULL;
568 /* This is called when an input file can not be recognized as a BFD
569 object or an archive. If the file starts with #!, we must treat it
570 as an import file. This is for AIX compatibility. */
573 gld${EMULATION_NAME}_unrecognized_file (entry)
574 lang_input_statement_type *entry;
579 e = fopen (entry->filename, FOPEN_RT);
585 if (getc (e) == '#' && getc (e) == '!')
588 struct filelist **flpp;
590 n = (struct filelist *) xmalloc (sizeof (struct filelist));
592 n->name = entry->filename;
593 flpp = &import_files;
594 while (*flpp != NULL)
595 flpp = &(*flpp)->next;
599 entry->loaded = TRUE;
607 /* This is called after the input files have been opened. */
610 gld${EMULATION_NAME}_after_open ()
615 /* Call ldctor_build_sets, after pretending that this is a
616 relocatable link. We do this because AIX requires relocation
617 entries for all references to symbols, even in a final
618 executable. Of course, we only want to do this if we are
619 producing an XCOFF output file. */
620 r = link_info.relocatable;
621 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
622 link_info.relocatable = TRUE;
623 ldctor_build_sets ();
624 link_info.relocatable = r;
626 /* For each set, record the size, so that the XCOFF backend can
627 output the correct csect length. */
628 for (p = sets; p != (struct set_info *) NULL; p = p->next)
632 /* If the symbol is defined, we may have been invoked from
633 collect, and the sets may already have been built, so we do
635 if (p->h->type == bfd_link_hash_defined
636 || p->h->type == bfd_link_hash_defweak)
639 if (p->reloc != BFD_RELOC_CTOR)
641 /* Handle this if we need to. */
645 size = (p->count + 2) * 4;
646 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
647 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
651 /* This is called after the sections have been attached to output
652 sections, but before any sizes or addresses have been set. */
655 gld${EMULATION_NAME}_before_allocation ()
658 struct export_symbol_list *el;
660 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
663 /* Handle the import and export files, if any. */
664 for (fl = import_files; fl != NULL; fl = fl->next)
665 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
666 for (el = export_symbols; el != NULL; el = el->next)
668 struct bfd_link_hash_entry *h;
670 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
672 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
673 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
674 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
677 /* Track down all relocations called for by the linker script (these
678 are typically constructor/destructor entries created by
679 CONSTRUCTORS) and let the backend know it will need to create
680 .loader relocs for them. */
681 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
683 /* Precedence of LIBPATH
684 -blibpath: native support always first
685 -rpath: gnu extension
686 -L build from command line -L's */
687 if (command_line_blibpath != NULL)
688 libpath = command_line_blibpath;
689 else if (command_line.rpath != NULL)
690 libpath = command_line.rpath;
691 else if (search_head == NULL)
692 libpath = (char *) "";
696 search_dirs_type *search;
698 len = strlen (search_head->name);
699 libpath = xmalloc (len + 1);
700 strcpy (libpath, search_head->name);
701 for (search = search_head->next; search != NULL; search = search->next)
705 nlen = strlen (search->name);
706 libpath = xrealloc (libpath, len + nlen + 2);
708 strcpy (libpath + len + 1, search->name);
713 /* Let the XCOFF backend set up the .loader section. */
714 if (!bfd_xcoff_size_dynamic_sections
715 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
716 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
717 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
718 rtld ? TRUE : FALSE))
719 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
721 /* Look through the special sections, and put them in the right
722 place in the link ordering. This is especially magic. */
723 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
726 lang_output_section_statement_type *os;
727 lang_statement_union_type **pls;
728 lang_input_section_type *is;
732 sec = special_sections[i];
736 /* Remove this section from the list of the output section.
737 This assumes we know what the script looks like. */
739 os = lang_output_section_find (sec->output_section->name);
741 einfo ("%P%F: can't find output section %s\n",
742 sec->output_section->name);
744 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
746 if ((*pls)->header.type == lang_input_section_enum
747 && (*pls)->input_section.section == sec)
749 is = (lang_input_section_type *) * pls;
750 *pls = (*pls)->header.next;
754 if ((*pls)->header.type == lang_wild_statement_enum)
756 lang_statement_union_type **pwls;
758 for (pwls = &(*pls)->wild_statement.children.head;
759 *pwls != NULL; pwls = &(*pwls)->header.next)
762 if ((*pwls)->header.type == lang_input_section_enum
763 && (*pwls)->input_section.section == sec)
765 is = (lang_input_section_type *) * pwls;
766 *pwls = (*pwls)->header.next;
778 einfo ("%P%F: can't find %s in output section\n",
779 bfd_get_section_name (sec->owner, sec));
782 /* Now figure out where the section should go. */
786 default: /* to avoid warnings */
787 case XCOFF_SPECIAL_SECTION_TEXT:
793 case XCOFF_SPECIAL_SECTION_ETEXT:
799 case XCOFF_SPECIAL_SECTION_DATA:
805 case XCOFF_SPECIAL_SECTION_EDATA:
811 case XCOFF_SPECIAL_SECTION_END:
812 case XCOFF_SPECIAL_SECTION_END2:
819 os = lang_output_section_find (oname);
823 is->header.next = os->children.head;
824 os->children.head = (lang_statement_union_type *) is;
828 is->header.next = NULL;
829 lang_statement_append (&os->children,
830 (lang_statement_union_type *) is,
837 gld${EMULATION_NAME}_choose_target (argc, argv)
842 static char *from_outside;
843 static char *from_inside;
844 static char *argv_to_target[][2] = {
845 {NULL, "${OUTPUT_FORMAT}"},
846 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
847 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
852 from_outside = getenv (TARGET_ENVIRON);
853 if (from_outside != (char *) NULL)
856 /* Set to default. */
857 from_inside = argv_to_target[0][1];
858 for (i = 1; i < argc; i++)
860 for (j = 1; j < jmax; j++)
862 if (0 == strcmp (argv[i], argv_to_target[j][0]))
863 from_inside = argv_to_target[j][1];
874 change_symbol_mode (input)
877 char *symbol_mode_string[] = {
888 for (bit = 0;; bit++)
890 string = symbol_mode_string[bit];
894 if (0 == strcmp (input, string))
896 symbol_mode = (1 << bit);
900 /* should not be here */
907 -1 : error, try something else */
909 is_syscall (input, flag)
917 char *syscall_string;
920 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
921 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
922 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
923 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
924 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
925 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
926 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
927 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
933 for (bit = 0;; bit++)
935 string = s[bit].syscall_string;
939 if (0 == strcmp (input, string))
941 if (1 << bit & syscall_mask)
952 /* should not be here */
956 /* Read an import or export file. For an import file, this is called
957 by the before_allocation emulation routine. For an export file,
958 this is called by the handle_option emulation routine. */
961 gld${EMULATION_NAME}_read_file (filename, import)
962 const char *filename;
972 const char *impmember;
974 o = (struct obstack *) xmalloc (sizeof (struct obstack));
975 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
977 f = fopen (filename, FOPEN_RT);
980 bfd_set_error (bfd_error_system_call);
981 einfo ("%F%s: %E\n", filename);
992 /* Default to 32 and 64 bit mode
993 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
994 are not repeated, assume 64 bit routines also want to use them.
995 See the routine change_symbol_mode for more information. */
999 while ((c = getc (f)) != EOF)
1003 unsigned int syscall_flag = 0;
1005 struct bfd_link_hash_entry *h;
1009 obstack_1grow (o, c);
1013 obstack_1grow (o, '\0');
1016 s = (char *) obstack_base (o);
1017 while (ISSPACE (*s))
1021 || change_symbol_mode (s)
1022 || (*s == '#' && s[1] == ' ')
1023 || (!import && *s == '#' && s[1] == '!'))
1025 obstack_free (o, obstack_base (o));
1029 if (*s == '#' && s[1] == '!')
1032 while (ISSPACE (*s))
1039 obstack_free (o, obstack_base (o));
1042 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1049 (void) obstack_finish (o);
1053 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1063 if (imppath == file - 1)
1073 while (ISSPACE (cs))
1082 einfo ("%s:%d: warning: syntax error in import file\n",
1089 while (*s != ')' && *s != '\0')
1094 einfo ("%s:%d: warning: syntax error in import file\n",
1102 if (symbol_mode & symbol_mode_mask)
1104 /* This is a symbol to be imported or exported. */
1107 address = (bfd_vma) -1;
1109 while (!ISSPACE (*s) && *s != '\0')
1117 while (ISSPACE (*s))
1121 while (!ISSPACE (*se) && *se != '\0')
1126 while (ISSPACE (*se))
1129 einfo ("%s%d: warning: syntax error in import/export file\n",
1138 status = is_syscall (s, &syscall_flag);
1142 /* not a system call, check for address */
1143 address = bfd_scan_vma (s, &end, 0);
1146 einfo ("%s:%d: warning: syntax error in import/export file\n",
1156 struct export_symbol_list *n;
1158 ldlang_add_undef (symname);
1159 n = ((struct export_symbol_list *)
1160 xmalloc (sizeof (struct export_symbol_list)));
1161 n->next = export_symbols;
1162 n->name = xstrdup (symname);
1167 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1169 if (h == NULL || h->type == bfd_link_hash_new)
1171 /* We can just ignore attempts to import an unreferenced
1176 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1177 address, imppath, impfile,
1178 impmember, syscall_flag))
1179 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1180 filename, lineno, symname);
1184 obstack_free (o, obstack_base (o));
1187 if (obstack_object_size (o) > 0)
1189 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1191 obstack_free (o, obstack_base (o));
1196 obstack_free (o, NULL);
1201 /* This routine saves us from worrying about declaring free. */
1204 gld${EMULATION_NAME}_free (p)
1210 /* This is called by the before_allocation routine via
1211 lang_for_each_statement. It looks for relocations and assignments
1215 gld${EMULATION_NAME}_find_relocs (s)
1216 lang_statement_union_type *s;
1218 if (s->header.type == lang_reloc_statement_enum)
1220 lang_reloc_statement_type *rs;
1222 rs = &s->reloc_statement;
1223 if (rs->name == NULL)
1224 einfo ("%F%P: only relocations against symbols are permitted\n");
1225 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1226 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1229 if (s->header.type == lang_assignment_statement_enum)
1230 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1233 /* Look through an expression for an assignment statement. */
1236 gld${EMULATION_NAME}_find_exp_assignment (exp)
1239 struct bfd_link_hash_entry *h;
1241 switch (exp->type.node_class)
1244 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1245 FALSE, FALSE, FALSE);
1250 if (strcmp (exp->assign.dst, ".") != 0)
1252 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1254 einfo ("%P%F: failed to record assignment to %s: %E\n",
1257 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1261 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1262 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1266 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1267 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1268 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1272 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1281 gld${EMULATION_NAME}_get_script (isfile)
1285 if test -n "$COMPILE_IN"
1287 # Scripts compiled in.
1289 # sed commands to quote an ld script as a C string.
1290 sc="-f ${srcdir}/emultempl/ostring.sed"
1292 cat >>e${EMULATION_NAME}.c <<EOF
1296 if (link_info.relocatable && config.build_constructors)
1299 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1300 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1301 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1302 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1303 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1304 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1305 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1306 echo ' ; else return' >> e${EMULATION_NAME}.c
1307 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1308 echo '; }' >> e${EMULATION_NAME}.c
1311 # Scripts read from the filesystem.
1313 cat >>e${EMULATION_NAME}.c <<EOF
1317 if (link_info.relocatable && config.build_constructors)
1318 return "ldscripts/${EMULATION_NAME}.xu";
1319 else if (link_info.relocatable)
1320 return "ldscripts/${EMULATION_NAME}.xr";
1321 else if (!config.text_read_only)
1322 return "ldscripts/${EMULATION_NAME}.xbn";
1323 else if (!config.magic_demand_paged)
1324 return "ldscripts/${EMULATION_NAME}.xn";
1326 return "ldscripts/${EMULATION_NAME}.x";
1332 cat >>e${EMULATION_NAME}.c <<EOF
1335 gld${EMULATION_NAME}_create_output_section_statements ()
1338 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1339 && (link_info.init_function != NULL
1340 || link_info.fini_function != NULL
1343 initfini_file = lang_add_input_file ("initfini",
1344 lang_input_file_is_file_enum,
1347 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1348 if (initfini_file->the_bfd == NULL
1349 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1350 bfd_get_arch (output_bfd),
1351 bfd_get_mach (output_bfd)))
1353 einfo ("%X%P: can not create BFD %E\n");
1357 /* Call backend to fill in the rest */
1358 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1359 link_info.init_function,
1360 link_info.fini_function,
1363 einfo ("%X%P: can not create BFD %E\n");
1367 /* __rtld defined in /lib/librtl.a */
1369 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1374 gld${EMULATION_NAME}_set_output_arch ()
1376 bfd_set_arch_mach (output_bfd,
1377 bfd_xcoff_architecture (output_bfd),
1378 bfd_xcoff_machine (output_bfd));
1380 ldfile_output_architecture = bfd_get_arch (output_bfd);
1381 ldfile_output_machine = bfd_get_mach (output_bfd);
1382 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1385 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1386 gld${EMULATION_NAME}_before_parse,
1389 after_parse_default,
1390 gld${EMULATION_NAME}_after_open,
1391 after_allocation_default,
1392 gld${EMULATION_NAME}_set_output_arch,
1393 gld${EMULATION_NAME}_choose_target,
1394 gld${EMULATION_NAME}_before_allocation,
1395 gld${EMULATION_NAME}_get_script,
1396 "${EMULATION_NAME}",
1399 gld${EMULATION_NAME}_create_output_section_statements,
1400 0, /* open_dynamic_archive */
1401 0, /* place_orphan */
1402 0, /* set_symbols */
1403 gld${EMULATION_NAME}_parse_args,
1404 gld${EMULATION_NAME}_add_options,
1405 gld${EMULATION_NAME}_handle_option,
1406 gld${EMULATION_NAME}_unrecognized_file,
1407 NULL, /* list_options */
1408 NULL, /* recognized_file */
1409 NULL, /* find potential_libraries */
1410 NULL /* new_vers_pattern */