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 void gld${EMULATION_NAME}_create_output_section_statements
72 static int is_syscall PARAMS ((char *, unsigned int *));
73 static int change_symbol_mode PARAMS ((char *));
75 /* The file alignment required for each section. */
76 static unsigned long file_align;
78 /* The maximum size the stack is permitted to grow. This is stored in
80 static unsigned long maxstack;
82 /* The maximum data size. This is stored in the a.out header. */
83 static unsigned long maxdata;
85 /* Whether to perform garbage collection. */
88 /* The module type to use. */
89 static unsigned short modtype = ('1' << 8) | 'L';
91 /* Whether the .text section must be read-only (i.e., no relocs
95 /* Whether to implement Unix like linker semantics. */
98 /* Structure used to hold import file list. */
102 struct filelist *next;
106 /* List of import files. */
107 static struct filelist *import_files;
109 /* List of export symbols read from the export files. */
111 struct export_symbol_list
113 struct export_symbol_list *next;
117 static struct export_symbol_list *export_symbols;
119 /* Maintains the 32 or 64 bit mode state of import file */
120 static unsigned int symbol_mode = 0x04;
122 /* Which symbol modes are valid */
123 static unsigned int symbol_mode_mask = 0x0d;
125 /* Whether this is a 64 bit link */
126 static int is_64bit = 0;
128 /* Which syscalls from import file are valid */
129 static unsigned int syscall_mask = 0x77;
131 /* fake file for -binitfini support */
132 static lang_input_statement_type *initfini_file;
134 /* This routine is called before anything else is done. */
137 gld${EMULATION_NAME}_before_parse ()
139 #ifndef TARGET_ /* I.e., if not generic. */
140 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
143 ldfile_output_architecture = arch->arch;
144 ldfile_output_machine = arch->mach;
145 ldfile_output_machine_name = arch->printable_name;
148 ldfile_output_architecture = bfd_arch_${ARCH};
149 #endif /* not TARGET_ */
150 config.has_shared = true;
152 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
153 Override them here so we can use the link_info.init_function as a
154 state flag that lets the backend know that -binitfini has been done. */
156 link_info.init_function = NULL;
157 link_info.fini_function = NULL;
161 /* Handle AIX specific options. */
164 gld${EMULATION_NAME}_parse_args (argc, argv)
168 int prevoptind = optind;
169 int prevopterr = opterr;
199 /* -binitfini has special handling in the linker backend. The native linker
200 uses the arguemnts to generate a table of init and fini functions for
201 the executable. The important use for this option is to support aix 4.2+
202 c++ constructors and destructors. This is tied into gcc via collect2.c.
204 The function table is accessed by the runtime linker/loader by checking if
205 the first symbol in the loader symbol table is __rtinit. The gnu linker
206 generates this symbol and makes it the first loader symbol. */
208 static const struct option longopts[] = {
209 {"basis", no_argument, NULL, OPTION_IGNORE},
210 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
211 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
212 {"bcrld", no_argument, NULL, OPTION_IGNORE},
213 {"bcror31", no_argument, NULL, OPTION_IGNORE},
214 {"bD", required_argument, NULL, OPTION_MAXDATA},
215 {"bE", required_argument, NULL, OPTION_EXPORT},
216 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
217 {"berok", no_argument, NULL, OPTION_EROK},
218 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
219 {"bexport", required_argument, NULL, OPTION_EXPORT},
220 {"bf", no_argument, NULL, OPTION_ERNOTOK},
221 {"bgc", no_argument, &gc, 1},
222 {"bh", required_argument, NULL, OPTION_IGNORE},
223 {"bhalt", required_argument, NULL, OPTION_IGNORE},
224 {"bI", required_argument, NULL, OPTION_IMPORT},
225 {"bimport", required_argument, NULL, OPTION_IMPORT},
226 {"binitfini", required_argument, NULL, OPTION_INITFINI},
227 {"bl", required_argument, NULL, OPTION_LOADMAP},
228 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
229 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
230 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
231 {"bM", required_argument, NULL, OPTION_MODTYPE},
232 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
233 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
234 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
235 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
236 {"bnogc", no_argument, &gc, 0},
237 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
238 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
239 {"bnotextro", no_argument, &textro, 0},
240 {"bnro", no_argument, &textro, 0},
241 {"bpD", required_argument, NULL, OPTION_PD},
242 {"bpT", required_argument, NULL, OPTION_PT},
243 {"bro", no_argument, &textro, 1},
244 {"bS", required_argument, NULL, OPTION_MAXSTACK},
245 {"bso", no_argument, NULL, OPTION_AUTOIMP},
246 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
247 {"btextro", no_argument, &textro, 1},
248 {"b32", no_argument, NULL, OPTION_32},
249 {"b64", no_argument, NULL, OPTION_64},
250 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
251 {"unix", no_argument, NULL, OPTION_UNIX},
252 {NULL, no_argument, NULL, 0}
255 /* Options supported by the AIX linker which we do not support: -f,
256 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
257 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
258 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
259 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
260 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
261 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
264 /* If the current option starts with -b, change the first : to an =.
265 The AIX linker uses : to separate the option from the argument;
266 changing it to = lets us treat it as a getopt option. */
271 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
275 for (s = argv[indx]; *s != '\0'; s++)
286 /* We add s and u so to the short options list so that -s and -u on
287 the command line do not match -static and -unix. */
290 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
302 /* Long option which just sets a flag. */
306 val = strtoll (optarg, &end, 0);
308 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
310 lang_section_start (".data", exp_intop (val));
314 val = strtoul (optarg, &end, 0);
315 if (*end != '\0' || (val & (val - 1)) != 0)
316 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
323 /* FIXME: This should use the page size for the target system. */
328 /* On AIX this is the same as GNU ld -Ttext. When we see -T
329 number, we assume the AIX option is intended. Otherwise, we
330 assume the usual GNU ld -T option is intended. We can't just
331 ignore the AIX option, because gcc passes it to the linker. */
332 val = strtoull (optarg, &end, 0);
338 lang_section_start (".text", exp_intop (val));
344 case OPTION_INITFINI:
347 * The aix linker init fini has the format :
349 * -binitfini:[ Initial][:Termination][:Priority]
351 * it allows the Termination and Priority to be optional.
353 * Since we support only one init/fini pair, we ignore the Priority.
355 * Define the special symbol __rtinit.
357 * strtok does not correctly handle the case of -binitfini::fini: so
363 while (*t && ':' != *t)
369 link_info.init_function = i;
372 while (*t && ':' != *t)
377 link_info.fini_function = f;
382 link_info.static_link = false;
386 force_make_executable = false;
390 force_make_executable = true;
394 gld${EMULATION_NAME}_read_file (optarg, false);
400 struct filelist **flpp;
402 n = (struct filelist *) xmalloc (sizeof (struct filelist));
405 flpp = &import_files;
406 while (*flpp != NULL)
407 flpp = &(*flpp)->next;
413 config.map_filename = optarg;
417 val = strtoull (optarg, &end, 0);
419 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
424 case OPTION_MAXSTACK:
425 val = strtoull (optarg, &end, 0);
427 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
436 link_info.shared = true;
439 if (*optarg == '\0' || optarg[1] == '\0')
440 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
442 modtype = (*optarg << 8) | optarg[1];
445 case OPTION_NOAUTOIMP:
446 link_info.static_link = true;
449 case OPTION_NOSTRCMPCT:
450 link_info.traditional_format = true;
454 /* This sets the page that the .data section is supposed to
455 start on. The offset within the page should still be the
456 offset within the file, so we need to build an appropriate
458 val = strtoull (optarg, &end, 0);
460 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
468 exp_nameop (NAME, "."),
471 exp_binop ('+', t, exp_intop (31)),
472 exp_intop (~(bfd_vma) 31));
473 lang_section_start (".data", t);
478 /* This set the page that the .text section is supposed to start
479 on. The offset within the page should still be the offset
481 val = strtoull (optarg, &end, 0);
483 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
490 exp_nameop (SIZEOF_HEADERS, NULL));
492 exp_binop ('+', t, exp_intop (31)),
493 exp_intop (~(bfd_vma) 31));
494 lang_section_start (".text", t);
498 case OPTION_STRCMPCT:
499 link_info.traditional_format = false;
509 symbol_mode_mask = 0x0d;
515 symbol_mode_mask = 0x0e;
523 /* This is called when an input file can not be recognized as a BFD
524 object or an archive. If the file starts with #!, we must treat it
525 as an import file. This is for AIX compatibility. */
528 gld${EMULATION_NAME}_unrecognized_file (entry)
529 lang_input_statement_type *entry;
534 e = fopen (entry->filename, FOPEN_RT);
540 if (getc (e) == '#' && getc (e) == '!')
543 struct filelist **flpp;
545 n = (struct filelist *) xmalloc (sizeof (struct filelist));
547 n->name = entry->filename;
548 flpp = &import_files;
549 while (*flpp != NULL)
550 flpp = &(*flpp)->next;
554 entry->loaded = true;
562 /* This is called after the input files have been opened. */
565 gld${EMULATION_NAME}_after_open ()
570 /* Call ldctor_build_sets, after pretending that this is a
571 relocateable link. We do this because AIX requires relocation
572 entries for all references to symbols, even in a final
573 executable. Of course, we only want to do this if we are
574 producing an XCOFF output file. */
575 r = link_info.relocateable;
576 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
577 link_info.relocateable = true;
578 ldctor_build_sets ();
579 link_info.relocateable = r;
581 /* For each set, record the size, so that the XCOFF backend can
582 output the correct csect length. */
583 for (p = sets; p != (struct set_info *) NULL; p = p->next)
587 /* If the symbol is defined, we may have been invoked from
588 collect, and the sets may already have been built, so we do
590 if (p->h->type == bfd_link_hash_defined
591 || p->h->type == bfd_link_hash_defweak)
594 if (p->reloc != BFD_RELOC_CTOR)
596 /* Handle this if we need to. */
600 size = (p->count + 2) * 4;
601 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
602 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
606 /* This is called after the sections have been attached to output
607 sections, but before any sizes or addresses have been set. */
610 gld${EMULATION_NAME}_before_allocation ()
613 struct export_symbol_list *el;
615 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
618 /* Handle the import and export files, if any. */
619 for (fl = import_files; fl != NULL; fl = fl->next)
620 gld${EMULATION_NAME}_read_file (fl->name, true);
621 for (el = export_symbols; el != NULL; el = el->next)
623 struct bfd_link_hash_entry *h;
625 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
627 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
628 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
629 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
632 /* Track down all relocations called for by the linker script (these
633 are typically constructor/destructor entries created by
634 CONSTRUCTORS) and let the backend know it will need to create
635 .loader relocs for them. */
636 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
638 /* We need to build LIBPATH from the -L arguments. If any -rpath
639 arguments were used, though, we use -rpath instead, as a GNU
641 if (command_line.rpath != NULL)
642 libpath = command_line.rpath;
643 else if (search_head == NULL)
644 libpath = (char *) "";
648 search_dirs_type *search;
650 len = strlen (search_head->name);
651 libpath = xmalloc (len + 1);
652 strcpy (libpath, search_head->name);
653 for (search = search_head->next; search != NULL; search = search->next)
657 nlen = strlen (search->name);
658 libpath = xrealloc (libpath, len + nlen + 2);
660 strcpy (libpath + len + 1, search->name);
665 /* Let the XCOFF backend set up the .loader section. */
666 if (!bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath,
667 entry_symbol, file_align,
669 gc && !unix_ld ? true : false,
671 textro ? true : false,
672 unix_ld, special_sections))
673 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
675 /* Look through the special sections, and put them in the right
676 place in the link ordering. This is especially magic. */
677 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
680 lang_output_section_statement_type *os;
681 lang_statement_union_type **pls;
682 lang_input_section_type *is;
686 sec = special_sections[i];
690 /* Remove this section from the list of the output section.
691 This assumes we know what the script looks like. */
693 os = lang_output_section_find (sec->output_section->name);
695 einfo ("%P%F: can't find output section %s\n",
696 sec->output_section->name);
698 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
700 if ((*pls)->header.type == lang_input_section_enum
701 && (*pls)->input_section.section == sec)
703 is = (lang_input_section_type *) * pls;
704 *pls = (*pls)->header.next;
708 if ((*pls)->header.type == lang_wild_statement_enum)
710 lang_statement_union_type **pwls;
712 for (pwls = &(*pls)->wild_statement.children.head;
713 *pwls != NULL; pwls = &(*pwls)->header.next)
716 if ((*pwls)->header.type == lang_input_section_enum
717 && (*pwls)->input_section.section == sec)
719 is = (lang_input_section_type *) * pwls;
720 *pwls = (*pwls)->header.next;
732 einfo ("%P%F: can't find %s in output section\n",
733 bfd_get_section_name (sec->owner, sec));
736 /* Now figure out where the section should go. */
740 default: /* to avoid warnings */
741 case XCOFF_SPECIAL_SECTION_TEXT:
747 case XCOFF_SPECIAL_SECTION_ETEXT:
753 case XCOFF_SPECIAL_SECTION_DATA:
759 case XCOFF_SPECIAL_SECTION_EDATA:
765 case XCOFF_SPECIAL_SECTION_END:
766 case XCOFF_SPECIAL_SECTION_END2:
773 os = lang_output_section_find (oname);
777 is->header.next = os->children.head;
778 os->children.head = (lang_statement_union_type *) is;
782 is->header.next = NULL;
783 lang_statement_append (&os->children,
784 (lang_statement_union_type *) is,
791 choose_target (argc, argv)
796 static char *from_outside;
797 static char *from_inside;
798 static char *argv_to_target[][2] = {
799 {NULL, "${OUTPUT_FORMAT}"},
800 {"-b32", "aixcoff-rs6000"},
801 {"-b64", "aixcoff64-rs6000"},
806 from_outside = getenv (TARGET_ENVIRON);
807 if (from_outside != (char *) NULL)
810 /* Set to default. */
811 from_inside = argv_to_target[0][1];
812 for (i = 1; i < argc; i++)
814 for (j = 1; j < jmax; j++)
816 if (0 == strcmp (argv[i], argv_to_target[j][0]))
817 from_inside = argv_to_target[j][1];
828 change_symbol_mode (input)
831 char *symbol_mode_string[] = {
842 for (bit = 0;; bit++)
844 string = symbol_mode_string[bit];
848 if (0 == strcmp (input, string))
850 symbol_mode = (1 << bit);
854 /* should not be here */
861 -1 : error, try something else */
863 is_syscall (input, flag)
871 char *syscall_string;
874 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
875 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
876 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
877 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
878 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
879 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
880 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
881 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
887 for (bit = 0;; bit++)
889 string = s[bit].syscall_string;
893 if (0 == strcmp (input, string))
895 if (1 << bit & syscall_mask)
906 /* should not be here */
910 /* Read an import or export file. For an import file, this is called
911 by the before_allocation emulation routine. For an export file,
912 this is called by the parse_args emulation routine. */
915 gld${EMULATION_NAME}_read_file (filename, import)
916 const char *filename;
926 const char *impmember;
928 o = (struct obstack *) xmalloc (sizeof (struct obstack));
929 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
931 f = fopen (filename, FOPEN_RT);
934 bfd_set_error (bfd_error_system_call);
935 einfo ("%F%s: %E\n", filename);
947 * default to 32 and 64 bit mode
948 * symbols at top of /lib/syscalls.exp do not have a mode modifier and they
949 * are not repeated, assume 64 bit routines also want to use them.
950 * See the routine change_symbol_mode for more information.
954 while ((c = getc (f)) != EOF)
958 unsigned int syscall_flag = 0;
960 struct bfd_link_hash_entry *h;
964 obstack_1grow (o, c);
968 obstack_1grow (o, '\0');
971 s = (char *) obstack_base (o);
976 || change_symbol_mode (s)
977 || (*s == '#' && s[1] == ' ')
978 || (!import && *s == '#' && s[1] == '!'))
980 obstack_free (o, obstack_base (o));
984 if (*s == '#' && s[1] == '!')
994 obstack_free (o, obstack_base (o));
997 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1004 (void) obstack_finish (o);
1008 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1018 if (imppath == file - 1)
1028 while (ISSPACE (cs))
1037 einfo ("%s:%d: warning: syntax error in import file\n",
1044 while (*s != ')' && *s != '\0')
1049 einfo ("%s:%d: warning: syntax error in import file\n",
1057 if (symbol_mode & symbol_mode_mask)
1059 /* This is a symbol to be imported or exported. */
1062 address = (bfd_vma) -1;
1064 while (!ISSPACE (*s) && *s != '\0')
1072 while (ISSPACE (*s))
1076 while (!ISSPACE (*se) && *se != '\0')
1081 while (ISSPACE (*se))
1084 einfo ("%s%d: warning: syntax error in import/export file\n",
1093 status = is_syscall (s, &syscall_flag);
1097 /* not a system call, check for address */
1098 address = strtoul (s, &end, 0);
1101 einfo ("%s:%d: warning: syntax error in import/export file\n",
1111 struct export_symbol_list *n;
1113 ldlang_add_undef (symname);
1114 n = ((struct export_symbol_list *)
1115 xmalloc (sizeof (struct export_symbol_list)));
1116 n->next = export_symbols;
1117 n->name = xstrdup (symname);
1122 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1124 if (h == NULL || h->type == bfd_link_hash_new)
1126 /* We can just ignore attempts to import an unreferenced
1131 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1132 address, imppath, impfile,
1133 impmember, syscall_flag))
1134 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1135 filename, lineno, symname);
1139 obstack_free (o, obstack_base (o));
1142 if (obstack_object_size (o) > 0)
1144 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1146 obstack_free (o, obstack_base (o));
1151 obstack_free (o, NULL);
1156 /* This routine saves us from worrying about declaring free. */
1159 gld${EMULATION_NAME}_free (p)
1165 /* This is called by the before_allocation routine via
1166 lang_for_each_statement. It looks for relocations and assignments
1170 gld${EMULATION_NAME}_find_relocs (s)
1171 lang_statement_union_type *s;
1173 if (s->header.type == lang_reloc_statement_enum)
1175 lang_reloc_statement_type *rs;
1177 rs = &s->reloc_statement;
1178 if (rs->name == NULL)
1179 einfo ("%F%P: only relocations against symbols are permitted\n");
1180 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1181 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1184 if (s->header.type == lang_assignment_statement_enum)
1185 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1188 /* Look through an expression for an assignment statement. */
1191 gld${EMULATION_NAME}_find_exp_assignment (exp)
1194 struct bfd_link_hash_entry *h;
1196 switch (exp->type.node_class)
1199 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1200 false, false, false);
1205 if (strcmp (exp->assign.dst, ".") != 0)
1207 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1209 einfo ("%P%F: failed to record assignment to %s: %E\n",
1212 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1216 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1217 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1221 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1222 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1223 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1227 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1236 gld${EMULATION_NAME}_get_script (isfile)
1240 if test -n "$COMPILE_IN"
1242 # Scripts compiled in.
1244 # sed commands to quote an ld script as a C string.
1245 sc="-f ${srcdir}/emultempl/ostring.sed"
1247 cat >>e${EMULATION_NAME}.c <<EOF
1251 if (link_info.relocateable == true && config.build_constructors == true)
1254 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1255 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1256 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1257 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1258 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1259 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1260 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1261 echo ' ; else return' >> e${EMULATION_NAME}.c
1262 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1263 echo '; }' >> e${EMULATION_NAME}.c
1266 # Scripts read from the filesystem.
1268 cat >>e${EMULATION_NAME}.c <<EOF
1272 if (link_info.relocateable == true && config.build_constructors == true)
1273 return "ldscripts/${EMULATION_NAME}.xu";
1274 else if (link_info.relocateable == true)
1275 return "ldscripts/${EMULATION_NAME}.xr";
1276 else if (!config.text_read_only)
1277 return "ldscripts/${EMULATION_NAME}.xbn";
1278 else if (!config.magic_demand_paged)
1279 return "ldscripts/${EMULATION_NAME}.xn";
1281 return "ldscripts/${EMULATION_NAME}.x";
1287 cat >>e${EMULATION_NAME}.c <<EOF
1290 gld${EMULATION_NAME}_create_output_section_statements()
1293 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1294 && (link_info.init_function != NULL || link_info.fini_function != NULL))
1297 initfini_file = lang_add_input_file ("initfini",
1298 lang_input_file_is_file_enum,
1301 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1302 if (initfini_file->the_bfd == NULL
1303 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1304 bfd_get_arch (output_bfd),
1305 bfd_get_mach (output_bfd)))
1307 einfo ("%X%P: can not create BFD %E\n");
1311 /* Call backend to fill in the rest */
1312 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1313 link_info.init_function,
1314 link_info.fini_function))
1316 einfo ("%X%P: can not create BFD %E\n");
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 gld${EMULATION_NAME}_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 */