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 void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
61 static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));
62 static void gld${EMULATION_NAME}_free PARAMS ((PTR));
63 static void gld${EMULATION_NAME}_find_relocs
64 PARAMS ((lang_statement_union_type *));
65 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
66 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
67 static boolean gld${EMULATION_NAME}_unrecognized_file
68 PARAMS ((lang_input_statement_type *));
70 /* The file alignment required for each section. */
71 static unsigned long file_align;
73 /* The maximum size the stack is permitted to grow. This is stored in
75 static unsigned long maxstack;
77 /* The maximum data size. This is stored in the a.out header. */
78 static unsigned long maxdata;
80 /* Whether to perform garbage collection. */
83 /* The module type to use. */
84 static unsigned short modtype = ('1' << 8) | 'L';
86 /* Whether the .text section must be read-only (i.e., no relocs
90 /* Whether to implement Unix like linker semantics. */
93 /* Structure used to hold import file list. */
97 struct filelist *next;
101 /* List of import files. */
102 static struct filelist *import_files;
104 /* List of export symbols read from the export files. */
106 struct export_symbol_list
108 struct export_symbol_list *next;
112 static struct export_symbol_list *export_symbols;
114 /* Maintains the 32 or 64 bit mode state of import file */
115 static unsigned int symbol_mode = 0x04;
117 /* This routine is called before anything else is done. */
120 gld${EMULATION_NAME}_before_parse ()
122 #ifndef TARGET_ /* I.e., if not generic. */
123 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
126 ldfile_output_architecture = arch->arch;
127 ldfile_output_machine = arch->mach;
128 ldfile_output_machine_name = arch->printable_name;
131 ldfile_output_architecture = bfd_arch_${ARCH};
132 #endif /* not TARGET_ */
133 config.has_shared = true;
136 * The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
137 * Override them here so we can use the link_info.init_function as a
138 * state flag that lets the backend know that -binitfini has been done.
140 link_info.init_function = NULL;
141 link_info.fini_function = NULL;
145 /* Handle AIX specific options. */
148 gld${EMULATION_NAME}_parse_args (argc, argv)
152 int prevoptind = optind;
153 int prevopterr = opterr;
181 b64 is an empty option. The native linker uses -b64 for xcoff64 support
182 Our linker uses -m aixppc64 for xcoff64 support. The choice for the
183 correct emulation is done in collect2.c via the environmental varible
186 binitfini has special handling in the linker backend. The native linker
187 uses the arguemnts to generate a table of init and fini functions for
188 the executable. The important use for this option is to support aix 4.2+
189 c++ constructors and destructors. This is tied into gcc via collect2.c.
190 The function table is accessed by the runtime linker/loader by checking if
191 the first symbol in the loader symbol table is "__rtinit". The native
192 linker generates this table and the loader symbol. The gnu linker looks
193 for the symbol "__rtinit" and makes it the first loader symbol. It is the
194 responsiblity of the user to define the __rtinit symbol. The format for
195 __rtinit is given by the aix system file /usr/include/rtinit.h. You can
196 look at collect2.c to see an example of how this is done for 32 and 64 bit.
197 Below is an exmaple of a 32 bit assembly file that defines __rtinit.
203 .extern init_function
204 .extern fini_function
212 f1i: .long init_function
218 f1f: .long fini_function
225 s1i: .string "init_function"
227 s1f: .string "fini_function"
231 static const struct option longopts[] = {
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 {"bS", required_argument, NULL, OPTION_MAXSTACK},
268 {"bso", no_argument, NULL, OPTION_AUTOIMP},
269 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
270 {"btextro", no_argument, &textro, 1},
271 {"b64", no_argument, NULL, 0},
272 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
273 {"unix", no_argument, NULL, OPTION_UNIX},
274 {NULL, no_argument, NULL, 0}
277 /* Options supported by the AIX linker which we do not support: -f,
278 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
279 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
280 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
281 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
282 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
283 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
286 /* If the current option starts with -b, change the first : to an =.
287 The AIX linker uses : to separate the option from the argument;
288 changing it to = lets us treat it as a getopt option. */
295 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
299 for (s = argv[indx]; *s != '\0'; s++)
310 /* We add s and u so to the short options list so that -s and -u on
311 the command line do not match -static and -unix. */
314 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
326 /* Long option which just sets a flag. */
330 val = strtoll (optarg, &end, 0);
332 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
334 lang_section_start (".data", exp_intop (val));
338 val = strtoul (optarg, &end, 0);
340 || (val & (val - 1)) != 0)
341 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
348 /* FIXME: This should use the page size for the target system. */
353 /* On AIX this is the same as GNU ld -Ttext. When we see -T
354 number, we assume the AIX option is intended. Otherwise, we
355 assume the usual GNU ld -T option is intended. We can't just
356 ignore the AIX option, because gcc passes it to the linker. */
357 val = strtoull (optarg, &end, 0);
363 lang_section_start (".text", exp_intop (val));
369 case OPTION_INITFINI:
372 * The aix linker init fini has the format :
374 * -binitfini:[ Initial][:Termination][:Priority]
376 * it allows the Termination and Priority to be optional.
378 * Since we support only one init/fini pair, we ignore the Priority.
380 * Define the special symbol __rtinit.
382 * strtok does not correctly handle the case of -binitfini::fini: so
388 while (*t && ':' != *t)
395 link_info.init_function = i;
399 while (*t && ':' != *t)
405 link_info.fini_function = f;
411 link_info.static_link = false;
415 force_make_executable = false;
419 force_make_executable = true;
423 gld${EMULATION_NAME}_read_file (optarg, false);
429 struct filelist **flpp;
431 n = (struct filelist *) xmalloc (sizeof (struct filelist));
434 flpp = &import_files;
435 while (*flpp != NULL)
436 flpp = &(*flpp)->next;
442 config.map_filename = optarg;
446 val = strtoull (optarg, &end, 0);
448 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
453 case OPTION_MAXSTACK:
454 val = strtoull (optarg, &end, 0);
456 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n", optarg);
464 link_info.shared = true;
467 if (*optarg == '\0' || optarg[1] == '\0')
468 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
470 modtype = (*optarg << 8) | optarg[1];
473 case OPTION_NOAUTOIMP:
474 link_info.static_link = true;
477 case OPTION_NOSTRCMPCT:
478 link_info.traditional_format = true;
482 /* This sets the page that the .data section is supposed to
483 start on. The offset within the page should still be the
484 offset within the file, so we need to build an appropriate
486 val = strtoull (optarg, &end, 0);
488 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
496 exp_nameop (NAME, "."),
499 exp_binop ('+', t, exp_intop (31)),
500 exp_intop (~ (bfd_vma) 31));
501 lang_section_start (".data", t);
506 /* This set the page that the .text section is supposed to start
507 on. The offset within the page should still be the offset
509 val = strtoull (optarg, &end, 0);
511 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
518 exp_nameop (SIZEOF_HEADERS, NULL));
520 exp_binop ('+', t, exp_intop (31)),
521 exp_intop (~ (bfd_vma) 31));
522 lang_section_start (".text", t);
526 case OPTION_STRCMPCT:
527 link_info.traditional_format = false;
538 /* This is called when an input file can not be recognized as a BFD
539 object or an archive. If the file starts with #!, we must treat it
540 as an import file. This is for AIX compatibility. */
543 gld${EMULATION_NAME}_unrecognized_file (entry)
544 lang_input_statement_type *entry;
549 e = fopen (entry->filename, FOPEN_RT);
555 if (getc (e) == '#' && getc (e) == '!')
558 struct filelist **flpp;
560 n = (struct filelist *) xmalloc (sizeof (struct filelist));
562 n->name = entry->filename;
563 flpp = &import_files;
564 while (*flpp != NULL)
565 flpp = &(*flpp)->next;
569 entry->loaded = true;
577 /* This is called after the input files have been opened. */
580 gld${EMULATION_NAME}_after_open ()
585 /* Call ldctor_build_sets, after pretending that this is a
586 relocateable link. We do this because AIX requires relocation
587 entries for all references to symbols, even in a final
588 executable. Of course, we only want to do this if we are
589 producing an XCOFF output file. */
590 r = link_info.relocateable;
591 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
592 link_info.relocateable = true;
593 ldctor_build_sets ();
594 link_info.relocateable = r;
596 /* For each set, record the size, so that the XCOFF backend can
597 output the correct csect length. */
598 for (p = sets; p != (struct set_info *) NULL; p = p->next)
602 /* If the symbol is defined, we may have been invoked from
603 collect, and the sets may already have been built, so we do
605 if (p->h->type == bfd_link_hash_defined
606 || p->h->type == bfd_link_hash_defweak)
609 if (p->reloc != BFD_RELOC_CTOR)
611 /* Handle this if we need to. */
615 size = (p->count + 2) * 4;
616 if (! bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
617 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
621 /* This is called after the sections have been attached to output
622 sections, but before any sizes or addresses have been set. */
625 gld${EMULATION_NAME}_before_allocation ()
628 struct export_symbol_list *el;
630 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
633 /* Handle the import and export files, if any. */
634 for (fl = import_files; fl != NULL; fl = fl->next)
635 gld${EMULATION_NAME}_read_file (fl->name, true);
636 for (el = export_symbols; el != NULL; el = el->next)
638 struct bfd_link_hash_entry *h;
640 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
642 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
643 if (! bfd_xcoff_export_symbol (output_bfd, &link_info, h))
644 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
647 /* Track down all relocations called for by the linker script (these
648 are typically constructor/destructor entries created by
649 CONSTRUCTORS) and let the backend know it will need to create
650 .loader relocs for them. */
651 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
653 /* We need to build LIBPATH from the -L arguments. If any -rpath
654 arguments were used, though, we use -rpath instead, as a GNU
656 if (command_line.rpath != NULL)
657 libpath = command_line.rpath;
658 else if (search_head == NULL)
659 libpath = (char *) "";
663 search_dirs_type *search;
665 len = strlen (search_head->name);
666 libpath = xmalloc (len + 1);
667 strcpy (libpath, search_head->name);
668 for (search = search_head->next; search != NULL; search = search->next)
672 nlen = strlen (search->name);
673 libpath = xrealloc (libpath, len + nlen + 2);
675 strcpy (libpath + len + 1, search->name);
680 /* Let the XCOFF backend set up the .loader section. */
681 if (! bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath,
682 entry_symbol, file_align,
684 gc && ! unix_ld ? true : false,
686 textro ? true : false,
689 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
691 /* Look through the special sections, and put them in the right
692 place in the link ordering. This is especially magic. */
693 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
696 lang_output_section_statement_type *os;
697 lang_statement_union_type **pls;
698 lang_input_section_type *is;
702 sec = special_sections[i];
706 /* Remove this section from the list of the output section.
707 This assumes we know what the script looks like. */
709 os = lang_output_section_find (sec->output_section->name);
711 einfo ("%P%F: can't find output section %s\n",
712 sec->output_section->name);
715 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;
732 pwls = &(*pwls)->header.next)
735 if ((*pwls)->header.type == lang_input_section_enum &&
736 (*pwls)->input_section.section == sec)
739 is = (lang_input_section_type *) *pwls;
740 *pwls = (*pwls)->header.next;
752 einfo ("%P%F: can't find %s in output section\n",
753 bfd_get_section_name (sec->owner, sec));
756 /* Now figure out where the section should go. */
760 default: /* to avoid warnings */
761 case XCOFF_SPECIAL_SECTION_TEXT:
767 case XCOFF_SPECIAL_SECTION_ETEXT:
773 case XCOFF_SPECIAL_SECTION_DATA:
779 case XCOFF_SPECIAL_SECTION_EDATA:
785 case XCOFF_SPECIAL_SECTION_END:
786 case XCOFF_SPECIAL_SECTION_END2:
793 os = lang_output_section_find (oname);
797 is->header.next = os->children.head;
798 os->children.head = (lang_statement_union_type *) is;
802 is->header.next = NULL;
803 lang_statement_append (&os->children,
804 (lang_statement_union_type *) is,
810 static int change_symbol_mode (char *input)
817 char *symbol_mode_string[] = {
827 for (bit = 0; ; bit++)
829 string = symbol_mode_string[bit];
833 if (0 == strcmp (input, string))
835 symbol_mode = (1 << bit);
839 /* should not be here */
843 static int is_syscall(char *input, unsigned int *flag)
848 * -1 : error, try something else
854 char *syscall_string;
857 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
858 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
859 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
860 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
861 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
862 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
863 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
864 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
870 for (bit = 0; ;bit++) {
872 string = s[bit].syscall_string;
873 if (NULL == string) {
877 if (0 == strcmp(input, string)) {
878 if (1 << bit & ${SYSCALL_MASK}) {
886 /* should not be here */
890 /* Read an import or export file. For an import file, this is called
891 by the before_allocation emulation routine. For an export file,
892 this is called by the parse_args emulation routine. */
895 gld${EMULATION_NAME}_read_file (filename, import)
896 const char *filename;
906 const char *impmember;
908 o = (struct obstack *) xmalloc (sizeof (struct obstack));
909 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
911 f = fopen (filename, FOPEN_RT);
914 bfd_set_error (bfd_error_system_call);
915 einfo ("%F%s: %E\n", filename);
927 * default to 32 and 64 bit mode
928 * symbols at top of /lib/syscalls.exp do not have a mode modifier and they
929 * are not repeated, assume 64 bit routines also want to use them.
930 * See the routine change_symbol_mode for more information.
934 while ((c = getc (f)) != EOF)
938 unsigned int syscall_flag = 0;
940 struct bfd_link_hash_entry *h;
944 obstack_1grow (o, c);
948 obstack_1grow (o, '\0');
951 s = (char *) obstack_base (o);
956 || change_symbol_mode (s)
957 || (*s == '#' && s[1] == ' ')
958 || (! import && *s == '#' && s[1] == '!'))
960 obstack_free (o, obstack_base (o));
964 if (*s == '#' && s[1] == '!')
974 obstack_free (o, obstack_base (o));
977 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
984 (void) obstack_finish (o);
988 while (! ISSPACE (*s)
989 && *s != '(' && *s != '\0')
999 if (imppath == file - 1)
1009 while (ISSPACE (cs))
1018 einfo ("%s:%d: warning: syntax error in import file\n",
1025 while (*s != ')' && *s != '\0')
1030 einfo ("%s:%d: warning: syntax error in import file\n",
1038 if (symbol_mode & ${SYMBOL_MODE_MASK})
1040 /* This is a symbol to be imported or exported. */
1043 address = (bfd_vma) -1;
1045 while (! ISSPACE (*s) && *s != '\0')
1053 while (ISSPACE (*s))
1057 while (! ISSPACE (*se) && *se != '\0')
1062 while (ISSPACE (*se))
1065 einfo ("%s%d: warning: syntax error in import/export file\n",
1074 status = is_syscall(s, &syscall_flag);
1077 /* not a system call, check for address */
1078 address = strtoul (s, &end, 0);
1080 /* not a system call, check for address */
1081 address = strtoul (s, &end, 0);
1084 einfo ("%s:%d: warning: syntax error in import/export file\n",
1094 struct export_symbol_list *n;
1096 ldlang_add_undef (symname);
1097 n = ((struct export_symbol_list *)
1098 xmalloc (sizeof (struct export_symbol_list)));
1099 n->next = export_symbols;
1100 n->name = xstrdup (symname);
1105 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1107 if (h == NULL || h->type == bfd_link_hash_new)
1109 /* We can just ignore attempts to import an unreferenced
1114 if (! bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1115 address, imppath, impfile,
1116 impmember, syscall_flag))
1117 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1118 filename, lineno, symname);
1122 obstack_free (o, obstack_base (o));
1125 if (obstack_object_size (o) > 0)
1127 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1129 obstack_free (o, obstack_base (o));
1134 obstack_free (o, NULL);
1139 /* This routine saves us from worrying about declaring free. */
1142 gld${EMULATION_NAME}_free (p)
1148 /* This is called by the before_allocation routine via
1149 lang_for_each_statement. It looks for relocations and assignments
1153 gld${EMULATION_NAME}_find_relocs (s)
1154 lang_statement_union_type *s;
1156 if (s->header.type == lang_reloc_statement_enum)
1158 lang_reloc_statement_type *rs;
1160 rs = &s->reloc_statement;
1161 if (rs->name == NULL)
1162 einfo ("%F%P: only relocations against symbols are permitted\n");
1163 if (! bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1164 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1167 if (s->header.type == lang_assignment_statement_enum)
1168 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1171 /* Look through an expression for an assignment statement. */
1174 gld${EMULATION_NAME}_find_exp_assignment (exp)
1177 struct bfd_link_hash_entry *h;
1179 switch (exp->type.node_class)
1182 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1183 false, false, false);
1188 if (strcmp (exp->assign.dst, ".") != 0)
1190 if (! bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1192 einfo ("%P%F: failed to record assignment to %s: %E\n",
1195 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1199 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1200 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1204 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1205 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1206 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1210 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1219 gld${EMULATION_NAME}_get_script (isfile)
1223 if test -n "$COMPILE_IN"
1225 # Scripts compiled in.
1227 # sed commands to quote an ld script as a C string.
1228 sc="-f ${srcdir}/emultempl/ostring.sed"
1230 cat >>e${EMULATION_NAME}.c <<EOF
1234 if (link_info.relocateable == true && config.build_constructors == true)
1237 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1238 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1239 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1240 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1241 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1242 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1243 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1244 echo ' ; else return' >> e${EMULATION_NAME}.c
1245 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1246 echo '; }' >> e${EMULATION_NAME}.c
1249 # Scripts read from the filesystem.
1251 cat >>e${EMULATION_NAME}.c <<EOF
1255 if (link_info.relocateable == true && config.build_constructors == true)
1256 return "ldscripts/${EMULATION_NAME}.xu";
1257 else if (link_info.relocateable == true)
1258 return "ldscripts/${EMULATION_NAME}.xr";
1259 else if (!config.text_read_only)
1260 return "ldscripts/${EMULATION_NAME}.xbn";
1261 else if (!config.magic_demand_paged)
1262 return "ldscripts/${EMULATION_NAME}.xn";
1264 return "ldscripts/${EMULATION_NAME}.x";
1270 cat >>e${EMULATION_NAME}.c <<EOF
1272 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1274 gld${EMULATION_NAME}_before_parse,
1277 after_parse_default,
1278 gld${EMULATION_NAME}_after_open,
1279 after_allocation_default,
1280 set_output_arch_default,
1281 ldemul_default_target,
1282 gld${EMULATION_NAME}_before_allocation,
1283 gld${EMULATION_NAME}_get_script,
1284 "${EMULATION_NAME}",
1287 0, /* create_output_section_statements */
1288 0, /* open_dynamic_archive */
1289 0, /* place_orphan */
1290 0, /* set_symbols */
1291 gld${EMULATION_NAME}_parse_args,
1292 gld${EMULATION_NAME}_unrecognized_file,
1293 NULL, /* list_options */
1294 NULL, /* recognized_file */
1295 NULL, /* find potential_libraries */