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.
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 *));
71 /* The file alignment required for each section. */
72 static unsigned long file_align;
74 /* The maximum size the stack is permitted to grow. This is stored in
76 static unsigned long maxstack;
78 /* The maximum data size. This is stored in the a.out header. */
79 static unsigned long maxdata;
81 /* Whether to perform garbage collection. */
84 /* The module type to use. */
85 static unsigned short modtype = ('1' << 8) | 'L';
87 /* Whether the .text section must be read-only (i.e., no relocs
91 /* Whether to implement Unix like linker semantics. */
94 /* Structure used to hold import file list. */
98 struct filelist *next;
102 /* List of import files. */
103 static struct filelist *import_files;
105 /* List of export symbols read from the export files. */
107 struct export_symbol_list
109 struct export_symbol_list *next;
113 static struct export_symbol_list *export_symbols;
115 /* Maintains the 32 or 64 bit mode state of import file */
116 static unsigned int symbol_mode = 0x04;
118 /* Which symbol modes are valid */
119 static unsigned int symbol_mode_mask = 0x0d;
121 /* Whether this is a 64 bit link */
122 static int is_64bit = 0;
124 /* Which syscalls from import file are valid */
125 static unsigned int syscall_mask = 0x77;
127 /* This routine is called before anything else is done. */
130 gld${EMULATION_NAME}_before_parse ()
132 #ifndef TARGET_ /* I.e., if not generic. */
133 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
136 ldfile_output_architecture = arch->arch;
137 ldfile_output_machine = arch->mach;
138 ldfile_output_machine_name = arch->printable_name;
141 ldfile_output_architecture = bfd_arch_${ARCH};
142 #endif /* not TARGET_ */
143 config.has_shared = true;
146 * The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
147 * Override them here so we can use the link_info.init_function as a
148 * state flag that lets the backend know that -binitfini has been done.
150 link_info.init_function = NULL;
151 link_info.fini_function = NULL;
155 /* Handle AIX specific options. */
158 gld${EMULATION_NAME}_parse_args (argc, argv)
162 int prevoptind = optind;
163 int prevopterr = opterr;
193 binitfini has special handling in the linker backend. The native linker
194 uses the arguemnts to generate a table of init and fini functions for
195 the executable. The important use for this option is to support aix 4.2+
196 c++ constructors and destructors. This is tied into gcc via collect2.c.
197 The function table is accessed by the runtime linker/loader by checking if
198 the first symbol in the loader symbol table is "__rtinit". The native
199 linker generates this table and the loader symbol. The gnu linker looks
200 for the symbol "__rtinit" and makes it the first loader symbol. It is the
201 responsiblity of the user to define the __rtinit symbol. The format for
202 __rtinit is given by the aix system file /usr/include/rtinit.h. You can
203 look at collect2.c to see an example of how this is done for 32 and 64 bit.
204 Below is an exmaple of a 32 bit assembly file that defines __rtinit.
210 .extern init_function
211 .extern fini_function
219 f1i: .long init_function
225 f1f: .long fini_function
232 s1i: .string "init_function"
234 s1f: .string "fini_function"
238 static const struct option longopts[] = {
239 {"basis", no_argument, NULL, OPTION_IGNORE},
240 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
241 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
242 {"bcrld", no_argument, NULL, OPTION_IGNORE},
243 {"bcror31", no_argument, NULL, OPTION_IGNORE},
244 {"bD", required_argument, NULL, OPTION_MAXDATA},
245 {"bE", required_argument, NULL, OPTION_EXPORT},
246 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
247 {"berok", no_argument, NULL, OPTION_EROK},
248 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
249 {"bexport", required_argument, NULL, OPTION_EXPORT},
250 {"bf", no_argument, NULL, OPTION_ERNOTOK},
251 {"bgc", no_argument, &gc, 1},
252 {"bh", required_argument, NULL, OPTION_IGNORE},
253 {"bhalt", required_argument, NULL, OPTION_IGNORE},
254 {"bI", required_argument, NULL, OPTION_IMPORT},
255 {"bimport", required_argument, NULL, OPTION_IMPORT},
256 {"binitfini", required_argument, NULL, OPTION_INITFINI},
257 {"bl", required_argument, NULL, OPTION_LOADMAP},
258 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
259 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
260 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
261 {"bM", required_argument, NULL, OPTION_MODTYPE},
262 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
263 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
264 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
265 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
266 {"bnogc", no_argument, &gc, 0},
267 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
268 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
269 {"bnotextro", no_argument, &textro, 0},
270 {"bnro", no_argument, &textro, 0},
271 {"bpD", required_argument, NULL, OPTION_PD},
272 {"bpT", required_argument, NULL, OPTION_PT},
273 {"bro", no_argument, &textro, 1},
274 {"bS", required_argument, NULL, OPTION_MAXSTACK},
275 {"bso", no_argument, NULL, OPTION_AUTOIMP},
276 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
277 {"btextro", no_argument, &textro, 1},
278 {"b32", no_argument, NULL, OPTION_32},
279 {"b64", no_argument, NULL, OPTION_64},
280 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
281 {"unix", no_argument, NULL, OPTION_UNIX},
282 {NULL, no_argument, NULL, 0}
285 /* Options supported by the AIX linker which we do not support: -f,
286 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
287 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
288 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
289 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
290 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
291 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
294 /* If the current option starts with -b, change the first : to an =.
295 The AIX linker uses : to separate the option from the argument;
296 changing it to = lets us treat it as a getopt option. */
303 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
307 for (s = argv[indx]; *s != '\0'; s++)
318 /* We add s and u so to the short options list so that -s and -u on
319 the command line do not match -static and -unix. */
322 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
334 /* Long option which just sets a flag. */
338 val = strtoll (optarg, &end, 0);
340 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
342 lang_section_start (".data", exp_intop (val));
346 val = strtoul (optarg, &end, 0);
348 || (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)
403 link_info.init_function = i;
407 while (*t && ':' != *t)
413 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 = strtoull (optarg, &end, 0);
456 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
461 case OPTION_MAXSTACK:
462 val = strtoull (optarg, &end, 0);
464 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n", optarg);
472 link_info.shared = true;
475 if (*optarg == '\0' || optarg[1] == '\0')
476 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
478 modtype = (*optarg << 8) | optarg[1];
481 case OPTION_NOAUTOIMP:
482 link_info.static_link = true;
485 case OPTION_NOSTRCMPCT:
486 link_info.traditional_format = true;
490 /* This sets the page that the .data section is supposed to
491 start on. The offset within the page should still be the
492 offset within the file, so we need to build an appropriate
494 val = strtoull (optarg, &end, 0);
496 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
504 exp_nameop (NAME, "."),
507 exp_binop ('+', t, exp_intop (31)),
508 exp_intop (~ (bfd_vma) 31));
509 lang_section_start (".data", t);
514 /* This set the page that the .text section is supposed to start
515 on. The offset within the page should still be the offset
517 val = strtoull (optarg, &end, 0);
519 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
526 exp_nameop (SIZEOF_HEADERS, NULL));
528 exp_binop ('+', t, exp_intop (31)),
529 exp_intop (~ (bfd_vma) 31));
530 lang_section_start (".text", t);
534 case OPTION_STRCMPCT:
535 link_info.traditional_format = false;
545 symbol_mode_mask = 0x0d;
551 symbol_mode_mask = 0x0e;
559 /* This is called when an input file can not be recognized as a BFD
560 object or an archive. If the file starts with #!, we must treat it
561 as an import file. This is for AIX compatibility. */
564 gld${EMULATION_NAME}_unrecognized_file (entry)
565 lang_input_statement_type *entry;
570 e = fopen (entry->filename, FOPEN_RT);
576 if (getc (e) == '#' && getc (e) == '!')
579 struct filelist **flpp;
581 n = (struct filelist *) xmalloc (sizeof (struct filelist));
583 n->name = entry->filename;
584 flpp = &import_files;
585 while (*flpp != NULL)
586 flpp = &(*flpp)->next;
590 entry->loaded = true;
598 /* This is called after the input files have been opened. */
601 gld${EMULATION_NAME}_after_open ()
606 /* Call ldctor_build_sets, after pretending that this is a
607 relocateable link. We do this because AIX requires relocation
608 entries for all references to symbols, even in a final
609 executable. Of course, we only want to do this if we are
610 producing an XCOFF output file. */
611 r = link_info.relocateable;
612 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
613 link_info.relocateable = true;
614 ldctor_build_sets ();
615 link_info.relocateable = r;
617 /* For each set, record the size, so that the XCOFF backend can
618 output the correct csect length. */
619 for (p = sets; p != (struct set_info *) NULL; p = p->next)
623 /* If the symbol is defined, we may have been invoked from
624 collect, and the sets may already have been built, so we do
626 if (p->h->type == bfd_link_hash_defined
627 || p->h->type == bfd_link_hash_defweak)
630 if (p->reloc != BFD_RELOC_CTOR)
632 /* Handle this if we need to. */
636 size = (p->count + 2) * 4;
637 if (! bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
638 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
642 /* This is called after the sections have been attached to output
643 sections, but before any sizes or addresses have been set. */
646 gld${EMULATION_NAME}_before_allocation ()
649 struct export_symbol_list *el;
651 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
654 /* Handle the import and export files, if any. */
655 for (fl = import_files; fl != NULL; fl = fl->next)
656 gld${EMULATION_NAME}_read_file (fl->name, true);
657 for (el = export_symbols; el != NULL; el = el->next)
659 struct bfd_link_hash_entry *h;
661 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
663 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
664 if (! bfd_xcoff_export_symbol (output_bfd, &link_info, h))
665 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
668 /* Track down all relocations called for by the linker script (these
669 are typically constructor/destructor entries created by
670 CONSTRUCTORS) and let the backend know it will need to create
671 .loader relocs for them. */
672 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
674 /* We need to build LIBPATH from the -L arguments. If any -rpath
675 arguments were used, though, we use -rpath instead, as a GNU
677 if (command_line.rpath != NULL)
678 libpath = command_line.rpath;
679 else if (search_head == NULL)
680 libpath = (char *) "";
684 search_dirs_type *search;
686 len = strlen (search_head->name);
687 libpath = xmalloc (len + 1);
688 strcpy (libpath, search_head->name);
689 for (search = search_head->next; search != NULL; search = search->next)
693 nlen = strlen (search->name);
694 libpath = xrealloc (libpath, len + nlen + 2);
696 strcpy (libpath + len + 1, search->name);
701 /* Let the XCOFF backend set up the .loader section. */
702 if (! bfd_xcoff_size_dynamic_sections (output_bfd, &link_info, libpath,
703 entry_symbol, file_align,
705 gc && ! unix_ld ? true : false,
707 textro ? true : false,
710 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
712 /* Look through the special sections, and put them in the right
713 place in the link ordering. This is especially magic. */
714 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
717 lang_output_section_statement_type *os;
718 lang_statement_union_type **pls;
719 lang_input_section_type *is;
723 sec = special_sections[i];
727 /* Remove this section from the list of the output section.
728 This assumes we know what the script looks like. */
730 os = lang_output_section_find (sec->output_section->name);
732 einfo ("%P%F: can't find output section %s\n",
733 sec->output_section->name);
736 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
739 if ((*pls)->header.type == lang_input_section_enum &&
740 (*pls)->input_section.section == sec)
742 is = (lang_input_section_type *) *pls;
743 *pls = (*pls)->header.next;
747 if ((*pls)->header.type == lang_wild_statement_enum)
749 lang_statement_union_type **pwls;
751 for (pwls = &(*pls)->wild_statement.children.head;
753 pwls = &(*pwls)->header.next)
756 if ((*pwls)->header.type == lang_input_section_enum &&
757 (*pwls)->input_section.section == sec)
760 is = (lang_input_section_type *) *pwls;
761 *pwls = (*pwls)->header.next;
773 einfo ("%P%F: can't find %s in output section\n",
774 bfd_get_section_name (sec->owner, sec));
777 /* Now figure out where the section should go. */
781 default: /* to avoid warnings */
782 case XCOFF_SPECIAL_SECTION_TEXT:
788 case XCOFF_SPECIAL_SECTION_ETEXT:
794 case XCOFF_SPECIAL_SECTION_DATA:
800 case XCOFF_SPECIAL_SECTION_EDATA:
806 case XCOFF_SPECIAL_SECTION_END:
807 case XCOFF_SPECIAL_SECTION_END2:
814 os = lang_output_section_find (oname);
818 is->header.next = os->children.head;
819 os->children.head = (lang_statement_union_type *) is;
823 is->header.next = NULL;
824 lang_statement_append (&os->children,
825 (lang_statement_union_type *) is,
832 choose_target (argc, argv)
837 static char *from_outside;
838 static char *from_inside;
839 static char *argv_to_target[][2] =
841 NULL, "aixcoff-rs6000",
842 "-b32", "aixcoff-rs6000",
843 "-b64", "aixcoff64-rs6000",
848 from_outside = getenv (TARGET_ENVIRON);
849 if (from_outside != (char *)NULL)
852 /* Set to default. */
853 from_inside = argv_to_target[0][1];
854 for (i = 1; i < argc; i++)
856 for (j = 1; j < jmax; j++)
858 if (0 == strcmp (argv[i], argv_to_target[j][0]))
859 from_inside = argv_to_target[j][1];
867 static int change_symbol_mode (char *input)
874 char *symbol_mode_string[] = {
884 for (bit = 0; ; bit++)
886 string = symbol_mode_string[bit];
890 if (0 == strcmp (input, string))
892 symbol_mode = (1 << bit);
896 /* should not be here */
900 static int is_syscall(char *input, unsigned int *flag)
905 * -1 : error, try something else
911 char *syscall_string;
914 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
915 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
916 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
917 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
918 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
919 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
920 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
921 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
927 for (bit = 0; ;bit++) {
929 string = s[bit].syscall_string;
930 if (NULL == string) {
934 if (0 == strcmp(input, string)) {
935 if (1 << bit & syscall_mask) {
943 /* should not be here */
947 /* Read an import or export file. For an import file, this is called
948 by the before_allocation emulation routine. For an export file,
949 this is called by the parse_args emulation routine. */
952 gld${EMULATION_NAME}_read_file (filename, import)
953 const char *filename;
963 const char *impmember;
965 o = (struct obstack *) xmalloc (sizeof (struct obstack));
966 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
968 f = fopen (filename, FOPEN_RT);
971 bfd_set_error (bfd_error_system_call);
972 einfo ("%F%s: %E\n", filename);
984 * default to 32 and 64 bit mode
985 * symbols at top of /lib/syscalls.exp do not have a mode modifier and they
986 * are not repeated, assume 64 bit routines also want to use them.
987 * See the routine change_symbol_mode for more information.
991 while ((c = getc (f)) != EOF)
995 unsigned int syscall_flag = 0;
997 struct bfd_link_hash_entry *h;
1001 obstack_1grow (o, c);
1005 obstack_1grow (o, '\0');
1008 s = (char *) obstack_base (o);
1009 while (ISSPACE (*s))
1013 || change_symbol_mode (s)
1014 || (*s == '#' && s[1] == ' ')
1015 || (! import && *s == '#' && s[1] == '!'))
1017 obstack_free (o, obstack_base (o));
1021 if (*s == '#' && s[1] == '!')
1024 while (ISSPACE (*s))
1031 obstack_free (o, obstack_base (o));
1034 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1041 (void) obstack_finish (o);
1045 while (! ISSPACE (*s)
1046 && *s != '(' && *s != '\0')
1056 if (imppath == file - 1)
1066 while (ISSPACE (cs))
1075 einfo ("%s:%d: warning: syntax error in import file\n",
1082 while (*s != ')' && *s != '\0')
1087 einfo ("%s:%d: warning: syntax error in import file\n",
1095 if (symbol_mode & symbol_mode_mask)
1097 /* This is a symbol to be imported or exported. */
1100 address = (bfd_vma) -1;
1102 while (! ISSPACE (*s) && *s != '\0')
1110 while (ISSPACE (*s))
1114 while (! ISSPACE (*se) && *se != '\0')
1119 while (ISSPACE (*se))
1122 einfo ("%s%d: warning: syntax error in import/export file\n",
1131 status = is_syscall(s, &syscall_flag);
1134 /* not a system call, check for address */
1135 address = strtoul (s, &end, 0);
1137 /* not a system call, check for address */
1138 address = strtoul (s, &end, 0);
1141 einfo ("%s:%d: warning: syntax error in import/export file\n",
1151 struct export_symbol_list *n;
1153 ldlang_add_undef (symname);
1154 n = ((struct export_symbol_list *)
1155 xmalloc (sizeof (struct export_symbol_list)));
1156 n->next = export_symbols;
1157 n->name = xstrdup (symname);
1162 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1164 if (h == NULL || h->type == bfd_link_hash_new)
1166 /* We can just ignore attempts to import an unreferenced
1171 if (! bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1172 address, imppath, impfile,
1173 impmember, syscall_flag))
1174 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1175 filename, lineno, symname);
1179 obstack_free (o, obstack_base (o));
1182 if (obstack_object_size (o) > 0)
1184 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1186 obstack_free (o, obstack_base (o));
1191 obstack_free (o, NULL);
1196 /* This routine saves us from worrying about declaring free. */
1199 gld${EMULATION_NAME}_free (p)
1205 /* This is called by the before_allocation routine via
1206 lang_for_each_statement. It looks for relocations and assignments
1210 gld${EMULATION_NAME}_find_relocs (s)
1211 lang_statement_union_type *s;
1213 if (s->header.type == lang_reloc_statement_enum)
1215 lang_reloc_statement_type *rs;
1217 rs = &s->reloc_statement;
1218 if (rs->name == NULL)
1219 einfo ("%F%P: only relocations against symbols are permitted\n");
1220 if (! bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1221 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1224 if (s->header.type == lang_assignment_statement_enum)
1225 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1228 /* Look through an expression for an assignment statement. */
1231 gld${EMULATION_NAME}_find_exp_assignment (exp)
1234 struct bfd_link_hash_entry *h;
1236 switch (exp->type.node_class)
1239 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1240 false, false, false);
1245 if (strcmp (exp->assign.dst, ".") != 0)
1247 if (! bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1249 einfo ("%P%F: failed to record assignment to %s: %E\n",
1252 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1256 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1257 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1261 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1262 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1263 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1267 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1276 gld${EMULATION_NAME}_get_script (isfile)
1280 if test -n "$COMPILE_IN"
1282 # Scripts compiled in.
1284 # sed commands to quote an ld script as a C string.
1285 sc="-f ${srcdir}/emultempl/ostring.sed"
1287 cat >>e${EMULATION_NAME}.c <<EOF
1291 if (link_info.relocateable == true && config.build_constructors == true)
1294 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1295 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1296 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1297 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1298 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1299 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1300 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1301 echo ' ; else return' >> e${EMULATION_NAME}.c
1302 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1303 echo '; }' >> e${EMULATION_NAME}.c
1306 # Scripts read from the filesystem.
1308 cat >>e${EMULATION_NAME}.c <<EOF
1312 if (link_info.relocateable == true && config.build_constructors == true)
1313 return "ldscripts/${EMULATION_NAME}.xu";
1314 else if (link_info.relocateable == true)
1315 return "ldscripts/${EMULATION_NAME}.xr";
1316 else if (!config.text_read_only)
1317 return "ldscripts/${EMULATION_NAME}.xbn";
1318 else if (!config.magic_demand_paged)
1319 return "ldscripts/${EMULATION_NAME}.xn";
1321 return "ldscripts/${EMULATION_NAME}.x";
1327 cat >>e${EMULATION_NAME}.c <<EOF
1329 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1331 gld${EMULATION_NAME}_before_parse,
1334 after_parse_default,
1335 gld${EMULATION_NAME}_after_open,
1336 after_allocation_default,
1337 set_output_arch_default,
1339 gld${EMULATION_NAME}_before_allocation,
1340 gld${EMULATION_NAME}_get_script,
1341 "${EMULATION_NAME}",
1344 0, /* create_output_section_statements */
1345 0, /* open_dynamic_archive */
1346 0, /* place_orphan */
1347 0, /* set_symbols */
1348 gld${EMULATION_NAME}_parse_args,
1349 gld${EMULATION_NAME}_unrecognized_file,
1350 NULL, /* list_options */
1351 NULL, /* recognized_file */
1352 NULL, /* find potential_libraries */