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"
59 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
60 static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));
61 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
62 static char *gld${EMULATION_NAME}_choose_target PARAMS ((int, char **));
63 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
64 static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));
65 static void gld${EMULATION_NAME}_free PARAMS ((PTR));
66 static void gld${EMULATION_NAME}_find_relocs
67 PARAMS ((lang_statement_union_type *));
68 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
69 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
70 static boolean gld${EMULATION_NAME}_unrecognized_file
71 PARAMS ((lang_input_statement_type *));
72 static void gld${EMULATION_NAME}_create_output_section_statements
74 static void gld${EMULATION_NAME}_set_output_arch PARAMS ((void));
76 static int is_syscall PARAMS ((char *, unsigned int *));
77 static int change_symbol_mode PARAMS ((char *));
79 /* The file alignment required for each section. */
80 static unsigned long file_align;
82 /* The maximum size the stack is permitted to grow. This is stored in
84 static unsigned long maxstack;
86 /* The maximum data size. This is stored in the a.out header. */
87 static unsigned long maxdata;
89 /* Whether to perform garbage collection. */
92 /* The module type to use. */
93 static unsigned short modtype = ('1' << 8) | 'L';
95 /* Whether the .text section must be read-only (i.e., no relocs
99 /* Whether to implement Unix like linker semantics. */
102 /* Structure used to hold import file list. */
106 struct filelist *next;
110 /* List of import files. */
111 static struct filelist *import_files;
113 /* List of export symbols read from the export files. */
115 struct export_symbol_list
117 struct export_symbol_list *next;
121 static struct export_symbol_list *export_symbols;
123 /* Maintains the 32 or 64 bit mode state of import file */
124 static unsigned int symbol_mode = 0x04;
126 /* Which symbol modes are valid */
127 static unsigned int symbol_mode_mask = 0x0d;
129 /* Whether this is a 64 bit link */
130 static int is_64bit = 0;
132 /* Which syscalls from import file are valid */
133 static unsigned int syscall_mask = 0x77;
135 /* fake file for -binitfini support */
136 static lang_input_statement_type *initfini_file;
138 /* Whether to do run time linking */
141 /* Explicit command line library path, -blibpath */
142 static char *command_line_blibpath = NULL;
144 /* This routine is called before anything else is done. */
147 gld${EMULATION_NAME}_before_parse ()
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;
160 /* Handle AIX specific options. */
163 gld${EMULATION_NAME}_parse_args (argc, argv)
167 int prevoptind = optind;
168 int prevopterr = opterr;
200 /* -binitfini has special handling in the linker backend. The native linker
201 uses the arguemnts to generate a table of init and fini functions for
202 the executable. The important use for this option is to support aix 4.2+
203 c++ constructors and destructors. This is tied into gcc via collect2.c.
205 The function table is accessed by the runtime linker/loader by checking if
206 the first symbol in the loader symbol table is __rtinit. The gnu linker
207 generates this symbol and makes it the first loader symbol. */
209 static const struct option longopts[] = {
210 {"basis", no_argument, NULL, OPTION_IGNORE},
211 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
212 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
213 {"bcrld", no_argument, NULL, OPTION_IGNORE},
214 {"bcror31", no_argument, NULL, OPTION_IGNORE},
215 {"bD", required_argument, NULL, OPTION_MAXDATA},
216 {"bE", required_argument, NULL, OPTION_EXPORT},
217 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
218 {"berok", no_argument, NULL, OPTION_EROK},
219 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
220 {"bexport", required_argument, NULL, OPTION_EXPORT},
221 {"bf", no_argument, NULL, OPTION_ERNOTOK},
222 {"bgc", no_argument, &gc, 1},
223 {"bh", required_argument, NULL, OPTION_IGNORE},
224 {"bhalt", required_argument, NULL, OPTION_IGNORE},
225 {"bI", required_argument, NULL, OPTION_IMPORT},
226 {"bimport", required_argument, NULL, OPTION_IMPORT},
227 {"binitfini", required_argument, NULL, OPTION_INITFINI},
228 {"bl", required_argument, NULL, OPTION_LOADMAP},
229 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
230 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
231 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
232 {"bM", required_argument, NULL, OPTION_MODTYPE},
233 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
234 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
235 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
236 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
237 {"bnogc", no_argument, &gc, 0},
238 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
239 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
240 {"bnotextro", no_argument, &textro, 0},
241 {"bnro", no_argument, &textro, 0},
242 {"bpD", required_argument, NULL, OPTION_PD},
243 {"bpT", required_argument, NULL, OPTION_PT},
244 {"bro", no_argument, &textro, 1},
245 {"brtl", no_argument, &rtld, 1},
246 {"bS", required_argument, NULL, OPTION_MAXSTACK},
247 {"bso", no_argument, NULL, OPTION_AUTOIMP},
248 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
249 {"btextro", no_argument, &textro, 1},
250 {"b32", no_argument, NULL, OPTION_32},
251 {"b64", no_argument, NULL, OPTION_64},
252 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
253 {"unix", no_argument, NULL, OPTION_UNIX},
254 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
255 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
256 {NULL, no_argument, NULL, 0}
259 /* Options supported by the AIX linker which we do not support: -f,
260 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
261 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
262 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
263 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
264 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
265 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
268 /* If the current option starts with -b, change the first : to an =.
269 The AIX linker uses : to separate the option from the argument;
270 changing it to = lets us treat it as a getopt option. */
275 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
279 for (s = argv[indx]; *s != '\0'; s++)
290 /* We add s and u so to the short options list so that -s and -u on
291 the command line do not match -static and -unix. */
294 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
306 /* Long option which just sets a flag. */
310 val = strtoll (optarg, &end, 0);
312 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
314 lang_section_start (".data", exp_intop (val));
318 val = strtoul (optarg, &end, 0);
319 if (*end != '\0' || (val & (val - 1)) != 0)
320 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
327 /* FIXME: This should use the page size for the target system. */
332 /* On AIX this is the same as GNU ld -Ttext. When we see -T
333 number, we assume the AIX option is intended. Otherwise, we
334 assume the usual GNU ld -T option is intended. We can't just
335 ignore the AIX option, because gcc passes it to the linker. */
336 val = strtoull (optarg, &end, 0);
342 lang_section_start (".text", exp_intop (val));
348 case OPTION_INITFINI:
351 * The aix linker init fini has the format :
353 * -binitfini:[ Initial][:Termination][:Priority]
355 * it allows the Termination and Priority to be optional.
357 * Since we support only one init/fini pair, we ignore the Priority.
359 * Define the special symbol __rtinit.
361 * strtok does not correctly handle the case of -binitfini::fini: so
367 while (*t && ':' != *t)
373 link_info.init_function = i;
376 while (*t && ':' != *t)
381 link_info.fini_function = f;
386 link_info.static_link = false;
390 force_make_executable = false;
394 force_make_executable = true;
398 gld${EMULATION_NAME}_read_file (optarg, false);
404 struct filelist **flpp;
406 n = (struct filelist *) xmalloc (sizeof (struct filelist));
409 flpp = &import_files;
410 while (*flpp != NULL)
411 flpp = &(*flpp)->next;
417 config.map_filename = optarg;
421 val = strtoull (optarg, &end, 0);
423 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
428 case OPTION_MAXSTACK:
429 val = strtoull (optarg, &end, 0);
431 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
440 link_info.shared = true;
443 if (*optarg == '\0' || optarg[1] == '\0')
444 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
446 modtype = (*optarg << 8) | optarg[1];
449 case OPTION_NOAUTOIMP:
450 link_info.static_link = true;
453 case OPTION_NOSTRCMPCT:
454 link_info.traditional_format = true;
458 /* This sets the page that the .data section is supposed to
459 start on. The offset within the page should still be the
460 offset within the file, so we need to build an appropriate
462 val = strtoull (optarg, &end, 0);
464 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
472 exp_nameop (NAME, "."),
475 exp_binop ('+', t, exp_intop (31)),
476 exp_intop (~(bfd_vma) 31));
477 lang_section_start (".data", t);
482 /* This set the page that the .text section is supposed to start
483 on. The offset within the page should still be the offset
485 val = strtoull (optarg, &end, 0);
487 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
494 exp_nameop (SIZEOF_HEADERS, NULL));
496 exp_binop ('+', t, exp_intop (31)),
497 exp_intop (~(bfd_vma) 31));
498 lang_section_start (".text", t);
502 case OPTION_STRCMPCT:
503 link_info.traditional_format = false;
513 symbol_mode_mask = 0x0d;
519 symbol_mode_mask = 0x0e;
523 command_line_blibpath = optarg;
526 case OPTION_NOLIBPATH:
527 command_line_blibpath = NULL;
535 /* This is called when an input file can not be recognized as a BFD
536 object or an archive. If the file starts with #!, we must treat it
537 as an import file. This is for AIX compatibility. */
540 gld${EMULATION_NAME}_unrecognized_file (entry)
541 lang_input_statement_type *entry;
546 e = fopen (entry->filename, FOPEN_RT);
552 if (getc (e) == '#' && getc (e) == '!')
555 struct filelist **flpp;
557 n = (struct filelist *) xmalloc (sizeof (struct filelist));
559 n->name = entry->filename;
560 flpp = &import_files;
561 while (*flpp != NULL)
562 flpp = &(*flpp)->next;
566 entry->loaded = true;
574 /* This is called after the input files have been opened. */
577 gld${EMULATION_NAME}_after_open ()
582 /* Call ldctor_build_sets, after pretending that this is a
583 relocateable link. We do this because AIX requires relocation
584 entries for all references to symbols, even in a final
585 executable. Of course, we only want to do this if we are
586 producing an XCOFF output file. */
587 r = link_info.relocateable;
588 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
589 link_info.relocateable = true;
590 ldctor_build_sets ();
591 link_info.relocateable = r;
593 /* For each set, record the size, so that the XCOFF backend can
594 output the correct csect length. */
595 for (p = sets; p != (struct set_info *) NULL; p = p->next)
599 /* If the symbol is defined, we may have been invoked from
600 collect, and the sets may already have been built, so we do
602 if (p->h->type == bfd_link_hash_defined
603 || p->h->type == bfd_link_hash_defweak)
606 if (p->reloc != BFD_RELOC_CTOR)
608 /* Handle this if we need to. */
612 size = (p->count + 2) * 4;
613 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
614 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
618 /* This is called after the sections have been attached to output
619 sections, but before any sizes or addresses have been set. */
622 gld${EMULATION_NAME}_before_allocation ()
625 struct export_symbol_list *el;
627 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
630 /* Handle the import and export files, if any. */
631 for (fl = import_files; fl != NULL; fl = fl->next)
632 gld${EMULATION_NAME}_read_file (fl->name, true);
633 for (el = export_symbols; el != NULL; el = el->next)
635 struct bfd_link_hash_entry *h;
637 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
639 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
640 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
641 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
644 /* Track down all relocations called for by the linker script (these
645 are typically constructor/destructor entries created by
646 CONSTRUCTORS) and let the backend know it will need to create
647 .loader relocs for them. */
648 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
650 /* Precedence of LIBPATH
651 -blibpath: native support always first
652 -rpath: gnu extension
653 -L build from command line -L's */
654 if (command_line_blibpath != NULL)
655 libpath = command_line_blibpath;
656 else 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
682 (output_bfd, &link_info, libpath, entry_symbol, file_align,
683 maxstack, maxdata, gc && !unix_ld ? true : false,
684 modtype, textro ? true : false, unix_ld, special_sections,
685 rtld ? true : false))
686 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
688 /* Look through the special sections, and put them in the right
689 place in the link ordering. This is especially magic. */
690 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
693 lang_output_section_statement_type *os;
694 lang_statement_union_type **pls;
695 lang_input_section_type *is;
699 sec = special_sections[i];
703 /* Remove this section from the list of the output section.
704 This assumes we know what the script looks like. */
706 os = lang_output_section_find (sec->output_section->name);
708 einfo ("%P%F: can't find output section %s\n",
709 sec->output_section->name);
711 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
713 if ((*pls)->header.type == lang_input_section_enum
714 && (*pls)->input_section.section == sec)
716 is = (lang_input_section_type *) * pls;
717 *pls = (*pls)->header.next;
721 if ((*pls)->header.type == lang_wild_statement_enum)
723 lang_statement_union_type **pwls;
725 for (pwls = &(*pls)->wild_statement.children.head;
726 *pwls != NULL; pwls = &(*pwls)->header.next)
729 if ((*pwls)->header.type == lang_input_section_enum
730 && (*pwls)->input_section.section == sec)
732 is = (lang_input_section_type *) * pwls;
733 *pwls = (*pwls)->header.next;
745 einfo ("%P%F: can't find %s in output section\n",
746 bfd_get_section_name (sec->owner, sec));
749 /* Now figure out where the section should go. */
753 default: /* to avoid warnings */
754 case XCOFF_SPECIAL_SECTION_TEXT:
760 case XCOFF_SPECIAL_SECTION_ETEXT:
766 case XCOFF_SPECIAL_SECTION_DATA:
772 case XCOFF_SPECIAL_SECTION_EDATA:
778 case XCOFF_SPECIAL_SECTION_END:
779 case XCOFF_SPECIAL_SECTION_END2:
786 os = lang_output_section_find (oname);
790 is->header.next = os->children.head;
791 os->children.head = (lang_statement_union_type *) is;
795 is->header.next = NULL;
796 lang_statement_append (&os->children,
797 (lang_statement_union_type *) is,
804 gld${EMULATION_NAME}_choose_target (argc, argv)
809 static char *from_outside;
810 static char *from_inside;
811 static char *argv_to_target[][2] = {
812 {NULL, "${OUTPUT_FORMAT}"},
813 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
814 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
819 from_outside = getenv (TARGET_ENVIRON);
820 if (from_outside != (char *) NULL)
823 /* Set to default. */
824 from_inside = argv_to_target[0][1];
825 for (i = 1; i < argc; i++)
827 for (j = 1; j < jmax; j++)
829 if (0 == strcmp (argv[i], argv_to_target[j][0]))
830 from_inside = argv_to_target[j][1];
841 change_symbol_mode (input)
844 char *symbol_mode_string[] = {
855 for (bit = 0;; bit++)
857 string = symbol_mode_string[bit];
861 if (0 == strcmp (input, string))
863 symbol_mode = (1 << bit);
867 /* should not be here */
874 -1 : error, try something else */
876 is_syscall (input, flag)
884 char *syscall_string;
887 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
888 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
889 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
890 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
891 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
892 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
893 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
894 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
900 for (bit = 0;; bit++)
902 string = s[bit].syscall_string;
906 if (0 == strcmp (input, string))
908 if (1 << bit & syscall_mask)
919 /* should not be here */
923 /* Read an import or export file. For an import file, this is called
924 by the before_allocation emulation routine. For an export file,
925 this is called by the parse_args emulation routine. */
928 gld${EMULATION_NAME}_read_file (filename, import)
929 const char *filename;
939 const char *impmember;
941 o = (struct obstack *) xmalloc (sizeof (struct obstack));
942 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
944 f = fopen (filename, FOPEN_RT);
947 bfd_set_error (bfd_error_system_call);
948 einfo ("%F%s: %E\n", filename);
959 /* Default to 32 and 64 bit mode
960 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
961 are not repeated, assume 64 bit routines also want to use them.
962 See the routine change_symbol_mode for more information. */
966 while ((c = getc (f)) != EOF)
970 unsigned int syscall_flag = 0;
972 struct bfd_link_hash_entry *h;
976 obstack_1grow (o, c);
980 obstack_1grow (o, '\0');
983 s = (char *) obstack_base (o);
988 || change_symbol_mode (s)
989 || (*s == '#' && s[1] == ' ')
990 || (!import && *s == '#' && s[1] == '!'))
992 obstack_free (o, obstack_base (o));
996 if (*s == '#' && s[1] == '!')
1006 obstack_free (o, obstack_base (o));
1009 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1016 (void) obstack_finish (o);
1020 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1030 if (imppath == file - 1)
1040 while (ISSPACE (cs))
1049 einfo ("%s:%d: warning: syntax error in import file\n",
1056 while (*s != ')' && *s != '\0')
1061 einfo ("%s:%d: warning: syntax error in import file\n",
1069 if (symbol_mode & symbol_mode_mask)
1071 /* This is a symbol to be imported or exported. */
1074 address = (bfd_vma) -1;
1076 while (!ISSPACE (*s) && *s != '\0')
1084 while (ISSPACE (*s))
1088 while (!ISSPACE (*se) && *se != '\0')
1093 while (ISSPACE (*se))
1096 einfo ("%s%d: warning: syntax error in import/export file\n",
1105 status = is_syscall (s, &syscall_flag);
1109 /* not a system call, check for address */
1110 address = strtoul (s, &end, 0);
1113 einfo ("%s:%d: warning: syntax error in import/export file\n",
1123 struct export_symbol_list *n;
1125 ldlang_add_undef (symname);
1126 n = ((struct export_symbol_list *)
1127 xmalloc (sizeof (struct export_symbol_list)));
1128 n->next = export_symbols;
1129 n->name = xstrdup (symname);
1134 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1136 if (h == NULL || h->type == bfd_link_hash_new)
1138 /* We can just ignore attempts to import an unreferenced
1143 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1144 address, imppath, impfile,
1145 impmember, syscall_flag))
1146 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1147 filename, lineno, symname);
1151 obstack_free (o, obstack_base (o));
1154 if (obstack_object_size (o) > 0)
1156 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1158 obstack_free (o, obstack_base (o));
1163 obstack_free (o, NULL);
1168 /* This routine saves us from worrying about declaring free. */
1171 gld${EMULATION_NAME}_free (p)
1177 /* This is called by the before_allocation routine via
1178 lang_for_each_statement. It looks for relocations and assignments
1182 gld${EMULATION_NAME}_find_relocs (s)
1183 lang_statement_union_type *s;
1185 if (s->header.type == lang_reloc_statement_enum)
1187 lang_reloc_statement_type *rs;
1189 rs = &s->reloc_statement;
1190 if (rs->name == NULL)
1191 einfo ("%F%P: only relocations against symbols are permitted\n");
1192 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1193 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1196 if (s->header.type == lang_assignment_statement_enum)
1197 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1200 /* Look through an expression for an assignment statement. */
1203 gld${EMULATION_NAME}_find_exp_assignment (exp)
1206 struct bfd_link_hash_entry *h;
1208 switch (exp->type.node_class)
1211 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1212 false, false, false);
1217 if (strcmp (exp->assign.dst, ".") != 0)
1219 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1221 einfo ("%P%F: failed to record assignment to %s: %E\n",
1224 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1228 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1229 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1233 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1234 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1235 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1239 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1248 gld${EMULATION_NAME}_get_script (isfile)
1252 if test -n "$COMPILE_IN"
1254 # Scripts compiled in.
1256 # sed commands to quote an ld script as a C string.
1257 sc="-f ${srcdir}/emultempl/ostring.sed"
1259 cat >>e${EMULATION_NAME}.c <<EOF
1263 if (link_info.relocateable == true && config.build_constructors == true)
1266 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1267 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1268 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1269 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1270 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1271 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1272 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1273 echo ' ; else return' >> e${EMULATION_NAME}.c
1274 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1275 echo '; }' >> e${EMULATION_NAME}.c
1278 # Scripts read from the filesystem.
1280 cat >>e${EMULATION_NAME}.c <<EOF
1284 if (link_info.relocateable == true && config.build_constructors == true)
1285 return "ldscripts/${EMULATION_NAME}.xu";
1286 else if (link_info.relocateable == true)
1287 return "ldscripts/${EMULATION_NAME}.xr";
1288 else if (!config.text_read_only)
1289 return "ldscripts/${EMULATION_NAME}.xbn";
1290 else if (!config.magic_demand_paged)
1291 return "ldscripts/${EMULATION_NAME}.xn";
1293 return "ldscripts/${EMULATION_NAME}.x";
1299 cat >>e${EMULATION_NAME}.c <<EOF
1302 gld${EMULATION_NAME}_create_output_section_statements ()
1305 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1306 && (link_info.init_function != NULL
1307 || link_info.fini_function != NULL
1310 initfini_file = lang_add_input_file ("initfini",
1311 lang_input_file_is_file_enum,
1314 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1315 if (initfini_file->the_bfd == NULL
1316 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1317 bfd_get_arch (output_bfd),
1318 bfd_get_mach (output_bfd)))
1320 einfo ("%X%P: can not create BFD %E\n");
1324 /* Call backend to fill in the rest */
1325 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1326 link_info.init_function,
1327 link_info.fini_function,
1330 einfo ("%X%P: can not create BFD %E\n");
1334 /* __rtld defined in /lib/librtl.a */
1336 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1341 gld${EMULATION_NAME}_set_output_arch ()
1343 bfd_set_arch_mach (output_bfd,
1344 bfd_xcoff_architecture (output_bfd),
1345 bfd_xcoff_machine (output_bfd));
1347 ldfile_output_architecture = bfd_get_arch (output_bfd);
1348 ldfile_output_machine = bfd_get_mach (output_bfd);
1349 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1352 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1353 gld${EMULATION_NAME}_before_parse,
1356 after_parse_default,
1357 gld${EMULATION_NAME}_after_open,
1358 after_allocation_default,
1359 gld${EMULATION_NAME}_set_output_arch,
1360 gld${EMULATION_NAME}_choose_target,
1361 gld${EMULATION_NAME}_before_allocation,
1362 gld${EMULATION_NAME}_get_script,
1363 "${EMULATION_NAME}",
1366 gld${EMULATION_NAME}_create_output_section_statements,
1367 0, /* open_dynamic_archive */
1368 0, /* place_orphan */
1369 0, /* set_symbols */
1370 gld${EMULATION_NAME}_parse_args,
1371 gld${EMULATION_NAME}_unrecognized_file,
1372 NULL, /* list_options */
1373 NULL, /* recognized_file */
1374 NULL, /* find potential_libraries */