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.
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"
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 int is_syscall PARAMS ((char *, unsigned int *));
71 static int change_symbol_mode PARAMS ((char *));
73 /* The file alignment required for each section. */
74 static unsigned long file_align;
76 /* The maximum size the stack is permitted to grow. This is stored in
78 static unsigned long maxstack;
80 /* The maximum data size. This is stored in the a.out header. */
81 static unsigned long maxdata;
83 /* Whether to perform garbage collection. */
86 /* The module type to use. */
87 static unsigned short modtype = ('1' << 8) | 'L';
89 /* Whether the .text section must be read-only (i.e., no relocs
93 /* Whether to implement Unix like linker semantics. */
96 /* Structure used to hold import file list. */
100 struct filelist *next;
104 /* List of import files. */
105 static struct filelist *import_files;
107 /* List of export symbols read from the export files. */
109 struct export_symbol_list
111 struct export_symbol_list *next;
115 static struct export_symbol_list *export_symbols;
117 /* Maintains the 32 or 64 bit mode state of import file */
118 static unsigned int symbol_mode = 0x04;
120 /* Which symbol modes are valid */
121 static unsigned int symbol_mode_mask = 0x0d;
123 /* Whether this is a 64 bit link */
124 static int is_64bit = 0;
126 /* Which syscalls from import file are valid */
127 static unsigned int syscall_mask = 0x77;
129 /* This routine is called before anything else is done. */
132 gld${EMULATION_NAME}_before_parse ()
134 #ifndef TARGET_ /* I.e., if not generic. */
135 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
138 ldfile_output_architecture = arch->arch;
139 ldfile_output_machine = arch->mach;
140 ldfile_output_machine_name = arch->printable_name;
143 ldfile_output_architecture = bfd_arch_${ARCH};
144 #endif /* not TARGET_ */
145 config.has_shared = true;
148 * The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
149 * Override them here so we can use the link_info.init_function as a
150 * state flag that lets the backend know that -binitfini has been done.
152 link_info.init_function = NULL;
153 link_info.fini_function = NULL;
157 /* Handle AIX specific options. */
160 gld${EMULATION_NAME}_parse_args (argc, argv)
164 int prevoptind = optind;
165 int prevopterr = opterr;
196 binitfini has special handling in the linker backend. The native linker
197 uses the arguemnts to generate a table of init and fini functions for
198 the executable. The important use for this option is to support aix 4.2+
199 c++ constructors and destructors. This is tied into gcc via collect2.c.
200 The function table is accessed by the runtime linker/loader by checking if
201 the first symbol in the loader symbol table is "__rtinit". The native
202 linker generates this table and the loader symbol. The gnu linker looks
203 for the symbol "__rtinit" and makes it the first loader symbol. It is the
204 responsiblity of the user to define the __rtinit symbol. The format for
205 __rtinit is given by the aix system file /usr/include/rtinit.h. You can
206 look at collect2.c to see an example of how this is done for 32 and 64 bit.
207 Below is an exmaple of a 32 bit assembly file that defines __rtinit.
213 .extern init_function
214 .extern fini_function
222 f1i: .long init_function
228 f1f: .long fini_function
235 s1i: .string "init_function"
237 s1f: .string "fini_function"
241 static const struct option longopts[] = {
242 {"basis", no_argument, NULL, OPTION_IGNORE},
243 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
244 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
245 {"bcrld", no_argument, NULL, OPTION_IGNORE},
246 {"bcror31", no_argument, NULL, OPTION_IGNORE},
247 {"bD", required_argument, NULL, OPTION_MAXDATA},
248 {"bE", required_argument, NULL, OPTION_EXPORT},
249 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
250 {"berok", no_argument, NULL, OPTION_EROK},
251 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
252 {"bexport", required_argument, NULL, OPTION_EXPORT},
253 {"bf", no_argument, NULL, OPTION_ERNOTOK},
254 {"bgc", no_argument, &gc, 1},
255 {"bh", required_argument, NULL, OPTION_IGNORE},
256 {"bhalt", required_argument, NULL, OPTION_IGNORE},
257 {"bI", required_argument, NULL, OPTION_IMPORT},
258 {"bimport", required_argument, NULL, OPTION_IMPORT},
259 {"binitfini", required_argument, NULL, OPTION_INITFINI},
260 {"bl", required_argument, NULL, OPTION_LOADMAP},
261 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
262 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
263 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
264 {"bM", required_argument, NULL, OPTION_MODTYPE},
265 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
266 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
267 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
268 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
269 {"bnogc", no_argument, &gc, 0},
270 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
271 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
272 {"bnotextro", no_argument, &textro, 0},
273 {"bnro", no_argument, &textro, 0},
274 {"bpD", required_argument, NULL, OPTION_PD},
275 {"bpT", required_argument, NULL, OPTION_PT},
276 {"bro", no_argument, &textro, 1},
277 {"bS", required_argument, NULL, OPTION_MAXSTACK},
278 {"bso", no_argument, NULL, OPTION_AUTOIMP},
279 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
280 {"btextro", no_argument, &textro, 1},
281 {"b32", no_argument, NULL, OPTION_32},
282 {"b64", no_argument, NULL, OPTION_64},
283 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
284 {"unix", no_argument, NULL, OPTION_UNIX},
285 {NULL, no_argument, NULL, 0}
288 /* Options supported by the AIX linker which we do not support: -f,
289 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
290 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
291 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
292 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
293 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
294 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
297 /* If the current option starts with -b, change the first : to an =.
298 The AIX linker uses : to separate the option from the argument;
299 changing it to = lets us treat it as a getopt option. */
304 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
308 for (s = argv[indx]; *s != '\0'; s++)
319 /* We add s and u so to the short options list so that -s and -u on
320 the command line do not match -static and -unix. */
323 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
335 /* Long option which just sets a flag. */
339 val = strtoll (optarg, &end, 0);
341 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
343 lang_section_start (".data", exp_intop (val));
347 val = strtoul (optarg, &end, 0);
348 if (*end != '\0' || (val & (val - 1)) != 0)
349 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
356 /* FIXME: This should use the page size for the target system. */
361 /* On AIX this is the same as GNU ld -Ttext. When we see -T
362 number, we assume the AIX option is intended. Otherwise, we
363 assume the usual GNU ld -T option is intended. We can't just
364 ignore the AIX option, because gcc passes it to the linker. */
365 val = strtoull (optarg, &end, 0);
371 lang_section_start (".text", exp_intop (val));
377 case OPTION_INITFINI:
380 * The aix linker init fini has the format :
382 * -binitfini:[ Initial][:Termination][:Priority]
384 * it allows the Termination and Priority to be optional.
386 * Since we support only one init/fini pair, we ignore the Priority.
388 * Define the special symbol __rtinit.
390 * strtok does not correctly handle the case of -binitfini::fini: so
396 while (*t && ':' != *t)
402 link_info.init_function = i;
405 while (*t && ':' != *t)
410 link_info.fini_function = f;
415 link_info.static_link = false;
419 force_make_executable = false;
423 force_make_executable = true;
427 gld${EMULATION_NAME}_read_file (optarg, false);
433 struct filelist **flpp;
435 n = (struct filelist *) xmalloc (sizeof (struct filelist));
438 flpp = &import_files;
439 while (*flpp != NULL)
440 flpp = &(*flpp)->next;
446 config.map_filename = optarg;
450 val = strtoull (optarg, &end, 0);
452 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
457 case OPTION_MAXSTACK:
458 val = strtoull (optarg, &end, 0);
460 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
469 link_info.shared = true;
472 if (*optarg == '\0' || optarg[1] == '\0')
473 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
475 modtype = (*optarg << 8) | optarg[1];
478 case OPTION_NOAUTOIMP:
479 link_info.static_link = true;
482 case OPTION_NOSTRCMPCT:
483 link_info.traditional_format = true;
487 /* This sets the page that the .data section is supposed to
488 start on. The offset within the page should still be the
489 offset within the file, so we need to build an appropriate
491 val = strtoull (optarg, &end, 0);
493 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
501 exp_nameop (NAME, "."),
504 exp_binop ('+', t, exp_intop (31)),
505 exp_intop (~(bfd_vma) 31));
506 lang_section_start (".data", t);
511 /* This set the page that the .text section is supposed to start
512 on. The offset within the page should still be the offset
514 val = strtoull (optarg, &end, 0);
516 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
523 exp_nameop (SIZEOF_HEADERS, NULL));
525 exp_binop ('+', t, exp_intop (31)),
526 exp_intop (~(bfd_vma) 31));
527 lang_section_start (".text", t);
531 case OPTION_STRCMPCT:
532 link_info.traditional_format = false;
542 symbol_mode_mask = 0x0d;
548 symbol_mode_mask = 0x0e;
556 /* This is called when an input file can not be recognized as a BFD
557 object or an archive. If the file starts with #!, we must treat it
558 as an import file. This is for AIX compatibility. */
561 gld${EMULATION_NAME}_unrecognized_file (entry)
562 lang_input_statement_type *entry;
567 e = fopen (entry->filename, FOPEN_RT);
573 if (getc (e) == '#' && getc (e) == '!')
576 struct filelist **flpp;
578 n = (struct filelist *) xmalloc (sizeof (struct filelist));
580 n->name = entry->filename;
581 flpp = &import_files;
582 while (*flpp != NULL)
583 flpp = &(*flpp)->next;
587 entry->loaded = true;
595 /* This is called after the input files have been opened. */
598 gld${EMULATION_NAME}_after_open ()
603 /* Call ldctor_build_sets, after pretending that this is a
604 relocateable link. We do this because AIX requires relocation
605 entries for all references to symbols, even in a final
606 executable. Of course, we only want to do this if we are
607 producing an XCOFF output file. */
608 r = link_info.relocateable;
609 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
610 link_info.relocateable = true;
611 ldctor_build_sets ();
612 link_info.relocateable = r;
614 /* For each set, record the size, so that the XCOFF backend can
615 output the correct csect length. */
616 for (p = sets; p != (struct set_info *) NULL; p = p->next)
620 /* If the symbol is defined, we may have been invoked from
621 collect, and the sets may already have been built, so we do
623 if (p->h->type == bfd_link_hash_defined
624 || p->h->type == bfd_link_hash_defweak)
627 if (p->reloc != BFD_RELOC_CTOR)
629 /* Handle this if we need to. */
633 size = (p->count + 2) * 4;
634 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
635 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
639 /* This is called after the sections have been attached to output
640 sections, but before any sizes or addresses have been set. */
643 gld${EMULATION_NAME}_before_allocation ()
646 struct export_symbol_list *el;
648 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
651 /* Handle the import and export files, if any. */
652 for (fl = import_files; fl != NULL; fl = fl->next)
653 gld${EMULATION_NAME}_read_file (fl->name, true);
654 for (el = export_symbols; el != NULL; el = el->next)
656 struct bfd_link_hash_entry *h;
658 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
660 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
661 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
662 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
665 /* Track down all relocations called for by the linker script (these
666 are typically constructor/destructor entries created by
667 CONSTRUCTORS) and let the backend know it will need to create
668 .loader relocs for them. */
669 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
671 /* We need to build LIBPATH from the -L arguments. If any -rpath
672 arguments were used, though, we use -rpath instead, as a GNU
674 if (command_line.rpath != NULL)
675 libpath = command_line.rpath;
676 else if (search_head == NULL)
677 libpath = (char *) "";
681 search_dirs_type *search;
683 len = strlen (search_head->name);
684 libpath = xmalloc (len + 1);
685 strcpy (libpath, search_head->name);
686 for (search = search_head->next; search != NULL; search = search->next)
690 nlen = strlen (search->name);
691 libpath = xrealloc (libpath, len + nlen + 2);
693 strcpy (libpath + len + 1, search->name);
698 /* Let the XCOFF backend set up the .loader section. */
699 if (!bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath,
700 entry_symbol, file_align,
702 gc && !unix_ld ? true : false,
704 textro ? true : false,
705 unix_ld, special_sections))
706 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
708 /* Look through the special sections, and put them in the right
709 place in the link ordering. This is especially magic. */
710 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
713 lang_output_section_statement_type *os;
714 lang_statement_union_type **pls;
715 lang_input_section_type *is;
719 sec = special_sections[i];
723 /* Remove this section from the list of the output section.
724 This assumes we know what the script looks like. */
726 os = lang_output_section_find (sec->output_section->name);
728 einfo ("%P%F: can't find output section %s\n",
729 sec->output_section->name);
731 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
733 if ((*pls)->header.type == lang_input_section_enum
734 && (*pls)->input_section.section == sec)
736 is = (lang_input_section_type *) * pls;
737 *pls = (*pls)->header.next;
741 if ((*pls)->header.type == lang_wild_statement_enum)
743 lang_statement_union_type **pwls;
745 for (pwls = &(*pls)->wild_statement.children.head;
746 *pwls != NULL; pwls = &(*pwls)->header.next)
749 if ((*pwls)->header.type == lang_input_section_enum
750 && (*pwls)->input_section.section == sec)
752 is = (lang_input_section_type *) * pwls;
753 *pwls = (*pwls)->header.next;
765 einfo ("%P%F: can't find %s in output section\n",
766 bfd_get_section_name (sec->owner, sec));
769 /* Now figure out where the section should go. */
773 default: /* to avoid warnings */
774 case XCOFF_SPECIAL_SECTION_TEXT:
780 case XCOFF_SPECIAL_SECTION_ETEXT:
786 case XCOFF_SPECIAL_SECTION_DATA:
792 case XCOFF_SPECIAL_SECTION_EDATA:
798 case XCOFF_SPECIAL_SECTION_END:
799 case XCOFF_SPECIAL_SECTION_END2:
806 os = lang_output_section_find (oname);
810 is->header.next = os->children.head;
811 os->children.head = (lang_statement_union_type *) is;
815 is->header.next = NULL;
816 lang_statement_append (&os->children,
817 (lang_statement_union_type *) is,
824 choose_target (argc, argv)
829 static char *from_outside;
830 static char *from_inside;
831 static char *argv_to_target[][2] = {
832 {NULL, "${OUTPUT_FORMAT}"},
833 {"-b32", "aixcoff-rs6000"},
834 {"-b64", "aixcoff64-rs6000"},
839 from_outside = getenv (TARGET_ENVIRON);
840 if (from_outside != (char *) NULL)
843 /* Set to default. */
844 from_inside = argv_to_target[0][1];
845 for (i = 1; i < argc; i++)
847 for (j = 1; j < jmax; j++)
849 if (0 == strcmp (argv[i], argv_to_target[j][0]))
850 from_inside = argv_to_target[j][1];
861 change_symbol_mode (input)
864 char *symbol_mode_string[] = {
875 for (bit = 0;; bit++)
877 string = symbol_mode_string[bit];
881 if (0 == strcmp (input, string))
883 symbol_mode = (1 << bit);
887 /* should not be here */
894 -1 : error, try something else */
896 is_syscall (input, flag)
904 char *syscall_string;
907 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
908 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
909 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
910 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
911 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
912 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
913 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
914 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
920 for (bit = 0;; bit++)
922 string = s[bit].syscall_string;
926 if (0 == strcmp (input, string))
928 if (1 << bit & syscall_mask)
939 /* should not be here */
943 /* Read an import or export file. For an import file, this is called
944 by the before_allocation emulation routine. For an export file,
945 this is called by the parse_args emulation routine. */
948 gld${EMULATION_NAME}_read_file (filename, import)
949 const char *filename;
959 const char *impmember;
961 o = (struct obstack *) xmalloc (sizeof (struct obstack));
962 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
964 f = fopen (filename, FOPEN_RT);
967 bfd_set_error (bfd_error_system_call);
968 einfo ("%F%s: %E\n", filename);
980 * default to 32 and 64 bit mode
981 * symbols at top of /lib/syscalls.exp do not have a mode modifier and they
982 * are not repeated, assume 64 bit routines also want to use them.
983 * See the routine change_symbol_mode for more information.
987 while ((c = getc (f)) != EOF)
991 unsigned int syscall_flag = 0;
993 struct bfd_link_hash_entry *h;
997 obstack_1grow (o, c);
1001 obstack_1grow (o, '\0');
1004 s = (char *) obstack_base (o);
1005 while (ISSPACE (*s))
1009 || change_symbol_mode (s)
1010 || (*s == '#' && s[1] == ' ')
1011 || (!import && *s == '#' && s[1] == '!'))
1013 obstack_free (o, obstack_base (o));
1017 if (*s == '#' && s[1] == '!')
1020 while (ISSPACE (*s))
1027 obstack_free (o, obstack_base (o));
1030 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1037 (void) obstack_finish (o);
1041 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1051 if (imppath == file - 1)
1061 while (ISSPACE (cs))
1070 einfo ("%s:%d: warning: syntax error in import file\n",
1077 while (*s != ')' && *s != '\0')
1082 einfo ("%s:%d: warning: syntax error in import file\n",
1090 if (symbol_mode & symbol_mode_mask)
1092 /* This is a symbol to be imported or exported. */
1095 address = (bfd_vma) -1;
1097 while (!ISSPACE (*s) && *s != '\0')
1105 while (ISSPACE (*s))
1109 while (!ISSPACE (*se) && *se != '\0')
1114 while (ISSPACE (*se))
1117 einfo ("%s%d: warning: syntax error in import/export file\n",
1126 status = is_syscall (s, &syscall_flag);
1130 /* not a system call, check for address */
1131 address = strtoul (s, &end, 0);
1134 einfo ("%s:%d: warning: syntax error in import/export file\n",
1144 struct export_symbol_list *n;
1146 ldlang_add_undef (symname);
1147 n = ((struct export_symbol_list *)
1148 xmalloc (sizeof (struct export_symbol_list)));
1149 n->next = export_symbols;
1150 n->name = xstrdup (symname);
1155 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1157 if (h == NULL || h->type == bfd_link_hash_new)
1159 /* We can just ignore attempts to import an unreferenced
1164 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1165 address, imppath, impfile,
1166 impmember, syscall_flag))
1167 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1168 filename, lineno, symname);
1172 obstack_free (o, obstack_base (o));
1175 if (obstack_object_size (o) > 0)
1177 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1179 obstack_free (o, obstack_base (o));
1184 obstack_free (o, NULL);
1189 /* This routine saves us from worrying about declaring free. */
1192 gld${EMULATION_NAME}_free (p)
1198 /* This is called by the before_allocation routine via
1199 lang_for_each_statement. It looks for relocations and assignments
1203 gld${EMULATION_NAME}_find_relocs (s)
1204 lang_statement_union_type *s;
1206 if (s->header.type == lang_reloc_statement_enum)
1208 lang_reloc_statement_type *rs;
1210 rs = &s->reloc_statement;
1211 if (rs->name == NULL)
1212 einfo ("%F%P: only relocations against symbols are permitted\n");
1213 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1214 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1217 if (s->header.type == lang_assignment_statement_enum)
1218 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1221 /* Look through an expression for an assignment statement. */
1224 gld${EMULATION_NAME}_find_exp_assignment (exp)
1227 struct bfd_link_hash_entry *h;
1229 switch (exp->type.node_class)
1232 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1233 false, false, false);
1238 if (strcmp (exp->assign.dst, ".") != 0)
1240 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1242 einfo ("%P%F: failed to record assignment to %s: %E\n",
1245 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1249 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1250 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1254 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1255 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1256 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1260 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1269 gld${EMULATION_NAME}_get_script (isfile)
1273 if test -n "$COMPILE_IN"
1275 # Scripts compiled in.
1277 # sed commands to quote an ld script as a C string.
1278 sc="-f ${srcdir}/emultempl/ostring.sed"
1280 cat >>e${EMULATION_NAME}.c <<EOF
1284 if (link_info.relocateable == true && config.build_constructors == true)
1287 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1288 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1289 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1290 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1291 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1292 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1293 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1294 echo ' ; else return' >> e${EMULATION_NAME}.c
1295 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1296 echo '; }' >> e${EMULATION_NAME}.c
1299 # Scripts read from the filesystem.
1301 cat >>e${EMULATION_NAME}.c <<EOF
1305 if (link_info.relocateable == true && config.build_constructors == true)
1306 return "ldscripts/${EMULATION_NAME}.xu";
1307 else if (link_info.relocateable == true)
1308 return "ldscripts/${EMULATION_NAME}.xr";
1309 else if (!config.text_read_only)
1310 return "ldscripts/${EMULATION_NAME}.xbn";
1311 else if (!config.magic_demand_paged)
1312 return "ldscripts/${EMULATION_NAME}.xn";
1314 return "ldscripts/${EMULATION_NAME}.x";
1320 cat >>e${EMULATION_NAME}.c <<EOF
1322 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1323 gld${EMULATION_NAME}_before_parse,
1326 after_parse_default,
1327 gld${EMULATION_NAME}_after_open,
1328 after_allocation_default,
1329 set_output_arch_default,
1331 gld${EMULATION_NAME}_before_allocation,
1332 gld${EMULATION_NAME}_get_script,
1333 "${EMULATION_NAME}",
1336 0, /* create_output_section_statements */
1337 0, /* open_dynamic_archive */
1338 0, /* place_orphan */
1339 0, /* set_symbols */
1340 gld${EMULATION_NAME}_parse_args,
1341 gld${EMULATION_NAME}_unrecognized_file,
1342 NULL, /* list_options */
1343 NULL, /* recognized_file */
1344 NULL, /* find potential_libraries */