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, 2002, 2003, 2004
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}_read_file (const char *, bfd_boolean);
60 static void gld${EMULATION_NAME}_free (void *);
61 static void gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *);
62 static void gld${EMULATION_NAME}_find_exp_assignment (etree_type *);
65 /* The file alignment required for each section. */
66 static unsigned long file_align;
68 /* The maximum size the stack is permitted to grow. This is stored in
70 static unsigned long maxstack;
72 /* The maximum data size. This is stored in the a.out header. */
73 static unsigned long maxdata;
75 /* Whether to perform garbage collection. */
78 /* The module type to use. */
79 static unsigned short modtype = ('1' << 8) | 'L';
81 /* Whether the .text section must be read-only (i.e., no relocs
85 /* Whether to implement Unix like linker semantics. */
88 /* Structure used to hold import file list. */
92 struct filelist *next;
96 /* List of import files. */
97 static struct filelist *import_files;
99 /* List of export symbols read from the export files. */
101 struct export_symbol_list
103 struct export_symbol_list *next;
107 static struct export_symbol_list *export_symbols;
109 /* Maintains the 32 or 64 bit mode state of import file */
110 static unsigned int symbol_mode = 0x04;
112 /* Which symbol modes are valid */
113 static unsigned int symbol_mode_mask = 0x0d;
115 /* Whether this is a 64 bit link */
116 static int is_64bit = 0;
118 /* Which syscalls from import file are valid */
119 static unsigned int syscall_mask = 0x77;
121 /* fake file for -binitfini support */
122 static lang_input_statement_type *initfini_file;
124 /* Whether to do run time linking
125 -brtl enables, -bnortl and -bnortllib disable. */
128 /* Explicit command line library path, -blibpath */
129 static char *command_line_blibpath = NULL;
131 /* This routine is called before anything else is done. */
134 gld${EMULATION_NAME}_before_parse (void)
136 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
138 config.has_shared = TRUE;
140 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
141 Override them here so we can use the link_info.init_function as a
142 state flag that lets the backend know that -binitfini has been done. */
144 link_info.init_function = NULL;
145 link_info.fini_function = NULL;
148 /* Handle AIX specific options. */
176 gld${EMULATION_NAME}_add_options
177 (int ns, char **shortopts, int nl, struct option **longopts,
178 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
180 static const char xtra_short[] = "D:H:KT:z";
181 static const struct option xtra_long[] = {
182 /* -binitfini has special handling in the linker backend. The native linker
183 uses the arguemnts to generate a table of init and fini functions for
184 the executable. The important use for this option is to support aix 4.2+
185 c++ constructors and destructors. This is tied into gcc via collect2.c.
187 The function table is accessed by the runtime linker/loader by checking if
188 the first symbol in the loader symbol table is __rtinit. The gnu linker
189 generates this symbol and makes it the first loader symbol. */
191 {"basis", no_argument, NULL, OPTION_IGNORE},
192 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
193 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
194 {"bcrld", no_argument, NULL, OPTION_IGNORE},
195 {"bcror31", no_argument, NULL, OPTION_IGNORE},
196 {"bD", required_argument, NULL, OPTION_MAXDATA},
197 {"bE", required_argument, NULL, OPTION_EXPORT},
198 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
199 {"berok", no_argument, NULL, OPTION_EROK},
200 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
201 {"bexport", required_argument, NULL, OPTION_EXPORT},
202 {"bf", no_argument, NULL, OPTION_ERNOTOK},
203 {"bgc", no_argument, &gc, 1},
204 {"bh", required_argument, NULL, OPTION_IGNORE},
205 {"bhalt", required_argument, NULL, OPTION_IGNORE},
206 {"bI", required_argument, NULL, OPTION_IMPORT},
207 {"bimport", required_argument, NULL, OPTION_IMPORT},
208 {"binitfini", required_argument, NULL, OPTION_INITFINI},
209 {"bl", required_argument, NULL, OPTION_LOADMAP},
210 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
211 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
212 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
213 {"bM", required_argument, NULL, OPTION_MODTYPE},
214 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
215 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
216 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
217 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
218 {"bnogc", no_argument, &gc, 0},
219 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
220 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
221 {"bnotextro", no_argument, &textro, 0},
222 {"bnro", no_argument, &textro, 0},
223 {"bpD", required_argument, NULL, OPTION_PD},
224 {"bpT", required_argument, NULL, OPTION_PT},
225 {"bro", no_argument, &textro, 1},
226 {"brtl", no_argument, &rtld, 1},
227 {"bnortl", no_argument, &rtld, 0},
228 {"bnortllib", no_argument, &rtld, 0},
229 {"bS", required_argument, NULL, OPTION_MAXSTACK},
230 {"bso", no_argument, NULL, OPTION_AUTOIMP},
231 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
232 {"btextro", no_argument, &textro, 1},
233 {"b32", no_argument, NULL, OPTION_32},
234 {"b64", no_argument, NULL, OPTION_64},
235 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
236 {"unix", no_argument, NULL, OPTION_UNIX},
237 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
238 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
239 {NULL, no_argument, NULL, 0}
242 /* Options supported by the AIX linker which we do not support: -f,
243 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
244 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
245 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
246 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
247 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
248 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
251 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
252 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
253 *longopts = xrealloc (*longopts,
254 nl * sizeof (struct option) + sizeof (xtra_long));
255 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
259 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
263 /* If the current option starts with -b, change the first : to an =.
264 The AIX linker uses : to separate the option from the argument;
265 changing it to = lets us treat it as a getopt option. */
270 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
274 for (s = argv[indx]; *s != '\0'; s++)
287 gld${EMULATION_NAME}_handle_option (int optc)
298 /* Long option which just sets a flag. */
302 val = bfd_scan_vma (optarg, &end, 0);
304 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
306 lang_section_start (".data", exp_intop (val));
310 val = bfd_scan_vma (optarg, &end, 0);
311 if (*end != '\0' || (val & (val - 1)) != 0)
312 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
319 /* FIXME: This should use the page size for the target system. */
324 /* On AIX this is the same as GNU ld -Ttext. When we see -T
325 number, we assume the AIX option is intended. Otherwise, we
326 assume the usual GNU ld -T option is intended. We can't just
327 ignore the AIX option, because gcc passes it to the linker. */
328 val = bfd_scan_vma (optarg, &end, 0);
331 lang_section_start (".text", exp_intop (val));
337 case OPTION_INITFINI:
340 * The aix linker init fini has the format :
342 * -binitfini:[ Initial][:Termination][:Priority]
344 * it allows the Termination and Priority to be optional.
346 * Since we support only one init/fini pair, we ignore the Priority.
348 * Define the special symbol __rtinit.
350 * strtok does not correctly handle the case of -binitfini::fini: so
356 while (*t && ':' != *t)
362 link_info.init_function = i;
365 while (*t && ':' != *t)
370 link_info.fini_function = f;
375 link_info.static_link = FALSE;
379 force_make_executable = FALSE;
383 force_make_executable = TRUE;
387 gld${EMULATION_NAME}_read_file (optarg, FALSE);
393 struct filelist **flpp;
395 n = (struct filelist *) xmalloc (sizeof (struct filelist));
398 flpp = &import_files;
399 while (*flpp != NULL)
400 flpp = &(*flpp)->next;
406 config.map_filename = optarg;
410 val = bfd_scan_vma (optarg, &end, 0);
412 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
417 case OPTION_MAXSTACK:
418 val = bfd_scan_vma (optarg, &end, 0);
420 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
429 link_info.shared = TRUE;
432 if (*optarg == '\0' || optarg[1] == '\0')
433 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
435 modtype = (*optarg << 8) | optarg[1];
438 case OPTION_NOAUTOIMP:
439 link_info.static_link = TRUE;
442 case OPTION_NOSTRCMPCT:
443 link_info.traditional_format = TRUE;
447 /* This sets the page that the .data section is supposed to
448 start on. The offset within the page should still be the
449 offset within the file, so we need to build an appropriate
451 val = bfd_scan_vma (optarg, &end, 0);
453 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
461 exp_nameop (NAME, "."),
464 exp_binop ('+', t, exp_intop (31)),
465 exp_intop (~(bfd_vma) 31));
466 lang_section_start (".data", t);
471 /* This set the page that the .text section is supposed to start
472 on. The offset within the page should still be the offset
474 val = bfd_scan_vma (optarg, &end, 0);
476 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
483 exp_nameop (SIZEOF_HEADERS, NULL));
485 exp_binop ('+', t, exp_intop (31)),
486 exp_intop (~(bfd_vma) 31));
487 lang_section_start (".text", t);
491 case OPTION_STRCMPCT:
492 link_info.traditional_format = FALSE;
502 symbol_mode_mask = 0x0d;
508 symbol_mode_mask = 0x0e;
512 command_line_blibpath = optarg;
515 case OPTION_NOLIBPATH:
516 command_line_blibpath = NULL;
524 /* This is called when an input file can not be recognized as a BFD
525 object or an archive. If the file starts with #!, we must treat it
526 as an import file. This is for AIX compatibility. */
529 gld${EMULATION_NAME}_unrecognized_file (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 (void)
570 /* Call ldctor_build_sets, after pretending that this is a
571 relocatable 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.relocatable;
576 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
577 link_info.relocatable = TRUE;
578 ldctor_build_sets ();
579 link_info.relocatable = 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 (void)
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 /* Precedence of LIBPATH
639 -blibpath: native support always first
640 -rpath: gnu extension
641 -L build from command line -L's */
642 if (command_line_blibpath != NULL)
643 libpath = command_line_blibpath;
644 else if (command_line.rpath != NULL)
645 libpath = command_line.rpath;
646 else if (search_head == NULL)
647 libpath = (char *) "";
651 search_dirs_type *search;
653 len = strlen (search_head->name);
654 libpath = xmalloc (len + 1);
655 strcpy (libpath, search_head->name);
656 for (search = search_head->next; search != NULL; search = search->next)
660 nlen = strlen (search->name);
661 libpath = xrealloc (libpath, len + nlen + 2);
663 strcpy (libpath + len + 1, search->name);
668 /* Let the XCOFF backend set up the .loader section. */
669 if (!bfd_xcoff_size_dynamic_sections
670 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
671 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
672 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
673 rtld ? TRUE : FALSE))
674 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
676 /* Look through the special sections, and put them in the right
677 place in the link ordering. This is especially magic. */
678 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
681 lang_output_section_statement_type *os;
682 lang_statement_union_type **pls;
683 lang_input_section_type *is;
687 sec = special_sections[i];
691 /* Remove this section from the list of the output section.
692 This assumes we know what the script looks like. */
694 os = lang_output_section_find (sec->output_section->name);
696 einfo ("%P%F: can't find output section %s\n",
697 sec->output_section->name);
699 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
701 if ((*pls)->header.type == lang_input_section_enum
702 && (*pls)->input_section.section == sec)
704 is = (lang_input_section_type *) * pls;
705 *pls = (*pls)->header.next;
709 if ((*pls)->header.type == lang_wild_statement_enum)
711 lang_statement_union_type **pwls;
713 for (pwls = &(*pls)->wild_statement.children.head;
714 *pwls != NULL; pwls = &(*pwls)->header.next)
717 if ((*pwls)->header.type == lang_input_section_enum
718 && (*pwls)->input_section.section == sec)
720 is = (lang_input_section_type *) * pwls;
721 *pwls = (*pwls)->header.next;
733 einfo ("%P%F: can't find %s in output section\n",
734 bfd_get_section_name (sec->owner, sec));
737 /* Now figure out where the section should go. */
741 default: /* to avoid warnings */
742 case XCOFF_SPECIAL_SECTION_TEXT:
748 case XCOFF_SPECIAL_SECTION_ETEXT:
754 case XCOFF_SPECIAL_SECTION_DATA:
760 case XCOFF_SPECIAL_SECTION_EDATA:
766 case XCOFF_SPECIAL_SECTION_END:
767 case XCOFF_SPECIAL_SECTION_END2:
774 os = lang_output_section_find (oname);
778 is->header.next = os->children.head;
779 os->children.head = (lang_statement_union_type *) is;
783 is->header.next = NULL;
784 lang_statement_append (&os->children,
785 (lang_statement_union_type *) is,
792 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
795 static char *from_outside;
796 static char *from_inside;
797 static char *argv_to_target[][2] = {
798 {NULL, "${OUTPUT_FORMAT}"},
799 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
800 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
805 from_outside = getenv (TARGET_ENVIRON);
806 if (from_outside != (char *) NULL)
809 /* Set to default. */
810 from_inside = argv_to_target[0][1];
811 for (i = 1; i < argc; i++)
813 for (j = 1; j < jmax; j++)
815 if (0 == strcmp (argv[i], argv_to_target[j][0]))
816 from_inside = argv_to_target[j][1];
827 change_symbol_mode (char *input)
829 char *symbol_mode_string[] = {
840 for (bit = 0;; bit++)
842 string = symbol_mode_string[bit];
846 if (0 == strcmp (input, string))
848 symbol_mode = (1 << bit);
852 /* should not be here */
859 -1 : error, try something else */
861 is_syscall (char *input, unsigned int *flag)
867 char *syscall_string;
870 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
871 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
872 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
873 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
874 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
875 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
876 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
877 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
883 for (bit = 0;; bit++)
885 string = s[bit].syscall_string;
889 if (0 == strcmp (input, string))
891 if (1 << bit & syscall_mask)
902 /* should not be here */
906 /* Read an import or export file. For an import file, this is called
907 by the before_allocation emulation routine. For an export file,
908 this is called by the handle_option emulation routine. */
911 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
920 const char *impmember;
922 o = (struct obstack *) xmalloc (sizeof (struct obstack));
923 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
925 f = fopen (filename, FOPEN_RT);
928 bfd_set_error (bfd_error_system_call);
929 einfo ("%F%s: %E\n", filename);
940 /* Default to 32 and 64 bit mode
941 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
942 are not repeated, assume 64 bit routines also want to use them.
943 See the routine change_symbol_mode for more information. */
947 while ((c = getc (f)) != EOF)
951 unsigned int syscall_flag = 0;
953 struct bfd_link_hash_entry *h;
957 obstack_1grow (o, c);
961 obstack_1grow (o, '\0');
964 s = (char *) obstack_base (o);
969 || change_symbol_mode (s)
970 || (*s == '#' && s[1] == ' ')
971 || (!import && *s == '#' && s[1] == '!'))
973 obstack_free (o, obstack_base (o));
977 if (*s == '#' && s[1] == '!')
987 obstack_free (o, obstack_base (o));
990 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
997 (void) obstack_finish (o);
1001 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1011 if (imppath == file - 1)
1021 while (ISSPACE (cs))
1030 einfo ("%s:%d: warning: syntax error in import file\n",
1037 while (*s != ')' && *s != '\0')
1042 einfo ("%s:%d: warning: syntax error in import file\n",
1050 if (symbol_mode & symbol_mode_mask)
1052 /* This is a symbol to be imported or exported. */
1055 address = (bfd_vma) -1;
1057 while (!ISSPACE (*s) && *s != '\0')
1065 while (ISSPACE (*s))
1069 while (!ISSPACE (*se) && *se != '\0')
1074 while (ISSPACE (*se))
1077 einfo ("%s%d: warning: syntax error in import/export file\n",
1086 status = is_syscall (s, &syscall_flag);
1090 /* not a system call, check for address */
1091 address = bfd_scan_vma (s, &end, 0);
1094 einfo ("%s:%d: warning: syntax error in import/export file\n",
1104 struct export_symbol_list *n;
1106 ldlang_add_undef (symname);
1107 n = ((struct export_symbol_list *)
1108 xmalloc (sizeof (struct export_symbol_list)));
1109 n->next = export_symbols;
1110 n->name = xstrdup (symname);
1115 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1117 if (h == NULL || h->type == bfd_link_hash_new)
1119 /* We can just ignore attempts to import an unreferenced
1124 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1125 address, imppath, impfile,
1126 impmember, syscall_flag))
1127 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1128 filename, lineno, symname);
1132 obstack_free (o, obstack_base (o));
1135 if (obstack_object_size (o) > 0)
1137 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1139 obstack_free (o, obstack_base (o));
1144 obstack_free (o, NULL);
1149 /* This routine saves us from worrying about declaring free. */
1152 gld${EMULATION_NAME}_free (void *p)
1157 /* This is called by the before_allocation routine via
1158 lang_for_each_statement. It looks for relocations and assignments
1162 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1164 if (s->header.type == lang_reloc_statement_enum)
1166 lang_reloc_statement_type *rs;
1168 rs = &s->reloc_statement;
1169 if (rs->name == NULL)
1170 einfo ("%F%P: only relocations against symbols are permitted\n");
1171 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1172 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1175 if (s->header.type == lang_assignment_statement_enum)
1176 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1179 /* Look through an expression for an assignment statement. */
1182 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1184 struct bfd_link_hash_entry *h;
1186 switch (exp->type.node_class)
1189 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1190 FALSE, FALSE, FALSE);
1195 if (strcmp (exp->assign.dst, ".") != 0)
1197 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1199 einfo ("%P%F: failed to record assignment to %s: %E\n",
1202 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1206 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1207 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1211 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1212 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1213 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1217 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1226 gld${EMULATION_NAME}_get_script (int *isfile)
1229 if test -n "$COMPILE_IN"
1231 # Scripts compiled in.
1233 # sed commands to quote an ld script as a C string.
1234 sc="-f ${srcdir}/emultempl/ostring.sed"
1236 cat >>e${EMULATION_NAME}.c <<EOF
1240 if (link_info.relocatable && config.build_constructors)
1243 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1244 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1245 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1246 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1247 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1248 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1249 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1250 echo ' ; else return' >> e${EMULATION_NAME}.c
1251 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1252 echo '; }' >> e${EMULATION_NAME}.c
1255 # Scripts read from the filesystem.
1257 cat >>e${EMULATION_NAME}.c <<EOF
1261 if (link_info.relocatable && config.build_constructors)
1262 return "ldscripts/${EMULATION_NAME}.xu";
1263 else if (link_info.relocatable)
1264 return "ldscripts/${EMULATION_NAME}.xr";
1265 else if (!config.text_read_only)
1266 return "ldscripts/${EMULATION_NAME}.xbn";
1267 else if (!config.magic_demand_paged)
1268 return "ldscripts/${EMULATION_NAME}.xn";
1270 return "ldscripts/${EMULATION_NAME}.x";
1276 cat >>e${EMULATION_NAME}.c <<EOF
1279 gld${EMULATION_NAME}_create_output_section_statements (void)
1282 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1283 && (link_info.init_function != NULL
1284 || link_info.fini_function != NULL
1287 initfini_file = lang_add_input_file ("initfini",
1288 lang_input_file_is_file_enum,
1291 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1292 if (initfini_file->the_bfd == NULL
1293 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1294 bfd_get_arch (output_bfd),
1295 bfd_get_mach (output_bfd)))
1297 einfo ("%X%P: can not create BFD %E\n");
1301 /* Call backend to fill in the rest */
1302 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1303 link_info.init_function,
1304 link_info.fini_function,
1307 einfo ("%X%P: can not create BFD %E\n");
1311 /* __rtld defined in /lib/librtl.a */
1313 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1318 gld${EMULATION_NAME}_set_output_arch (void)
1320 bfd_set_arch_mach (output_bfd,
1321 bfd_xcoff_architecture (output_bfd),
1322 bfd_xcoff_machine (output_bfd));
1324 ldfile_output_architecture = bfd_get_arch (output_bfd);
1325 ldfile_output_machine = bfd_get_mach (output_bfd);
1326 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1329 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1330 gld${EMULATION_NAME}_before_parse,
1333 after_parse_default,
1334 gld${EMULATION_NAME}_after_open,
1335 after_allocation_default,
1336 gld${EMULATION_NAME}_set_output_arch,
1337 gld${EMULATION_NAME}_choose_target,
1338 gld${EMULATION_NAME}_before_allocation,
1339 gld${EMULATION_NAME}_get_script,
1340 "${EMULATION_NAME}",
1343 gld${EMULATION_NAME}_create_output_section_statements,
1344 0, /* open_dynamic_archive */
1345 0, /* place_orphan */
1346 0, /* set_symbols */
1347 gld${EMULATION_NAME}_parse_args,
1348 gld${EMULATION_NAME}_add_options,
1349 gld${EMULATION_NAME}_handle_option,
1350 gld${EMULATION_NAME}_unrecognized_file,
1351 NULL, /* list_options */
1352 NULL, /* recognized_file */
1353 NULL, /* find potential_libraries */
1354 NULL /* new_vers_pattern */