1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
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, 1999, 2000, 2001, 2002,
13 2003, 2004, 2005, 2006, 2007, 2008
14 Free Software Foundation, Inc.
15 Written by Steve Chamberlain <sac@cygnus.com>
16 AIX support by Ian Lance Taylor <ian@cygnus.com>
17 AIX 64 bit support by Tom Rix <trix@redhat.com>
19 This file is part of the GNU Binutils.
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 3 of the License, or
24 (at your option) any later version.
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
34 MA 02110-1301, USA. */
36 #define TARGET_IS_${EMULATION_NAME}
40 #include "libiberty.h"
41 #include "safe-ctype.h"
56 #include "coff/internal.h"
57 #include "coff/xcoff.h"
61 static void gld${EMULATION_NAME}_read_file (const char *, bfd_boolean);
62 static void gld${EMULATION_NAME}_free (void *);
63 static void gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *);
64 static void gld${EMULATION_NAME}_find_exp_assignment (etree_type *);
67 /* The file alignment required for each section. */
68 static unsigned long file_align;
70 /* The maximum size the stack is permitted to grow. This is stored in
72 static unsigned long maxstack;
74 /* The maximum data size. This is stored in the a.out header. */
75 static unsigned long maxdata;
77 /* Whether to perform garbage collection. */
80 /* The module type to use. */
81 static unsigned short modtype = ('1' << 8) | 'L';
83 /* Whether the .text section must be read-only (i.e., no relocs
87 /* Whether to implement Unix like linker semantics. */
90 /* Structure used to hold import file list. */
94 struct filelist *next;
98 /* List of import files. */
99 static struct filelist *import_files;
101 /* List of export symbols read from the export files. */
103 struct export_symbol_list
105 struct export_symbol_list *next;
109 static struct export_symbol_list *export_symbols;
111 /* Maintains the 32 or 64 bit mode state of import file */
112 static unsigned int symbol_mode = 0x04;
114 /* Which symbol modes are valid */
115 static unsigned int symbol_mode_mask = 0x0d;
117 /* Whether this is a 64 bit link */
118 static int is_64bit = 0;
120 /* Which syscalls from import file are valid */
121 static unsigned int syscall_mask = 0x77;
123 /* fake file for -binitfini support */
124 static lang_input_statement_type *initfini_file;
126 /* Whether to do run time linking
127 -brtl enables, -bnortl and -bnortllib disable. */
130 /* Explicit command line library path, -blibpath */
131 static char *command_line_blibpath = NULL;
133 /* This routine is called before anything else is done. */
136 gld${EMULATION_NAME}_before_parse (void)
138 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
140 config.dynamic_link = TRUE;
141 config.has_shared = TRUE;
143 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
144 Override them here so we can use the link_info.init_function as a
145 state flag that lets the backend know that -binitfini has been done. */
147 link_info.init_function = NULL;
148 link_info.fini_function = NULL;
151 /* Handle AIX specific options. */
179 gld${EMULATION_NAME}_add_options
180 (int ns, char **shortopts, int nl, struct option **longopts,
181 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
183 static const char xtra_short[] = "D:H:KT:z";
184 static const struct option xtra_long[] = {
185 /* -binitfini has special handling in the linker backend. The native linker
186 uses the arguemnts to generate a table of init and fini functions for
187 the executable. The important use for this option is to support aix 4.2+
188 c++ constructors and destructors. This is tied into gcc via collect2.c.
190 The function table is accessed by the runtime linker/loader by checking if
191 the first symbol in the loader symbol table is __rtinit. The gnu linker
192 generates this symbol and makes it the first loader symbol. */
194 {"basis", no_argument, NULL, OPTION_IGNORE},
195 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
196 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
197 {"bcrld", no_argument, NULL, OPTION_IGNORE},
198 {"bcror31", no_argument, NULL, OPTION_IGNORE},
199 {"bD", required_argument, NULL, OPTION_MAXDATA},
200 {"bE", required_argument, NULL, OPTION_EXPORT},
201 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
202 {"berok", no_argument, NULL, OPTION_EROK},
203 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
204 {"bexport", required_argument, NULL, OPTION_EXPORT},
205 {"bf", no_argument, NULL, OPTION_ERNOTOK},
206 {"bgc", no_argument, &gc, 1},
207 {"bh", required_argument, NULL, OPTION_IGNORE},
208 {"bhalt", required_argument, NULL, OPTION_IGNORE},
209 {"bI", required_argument, NULL, OPTION_IMPORT},
210 {"bimport", required_argument, NULL, OPTION_IMPORT},
211 {"binitfini", required_argument, NULL, OPTION_INITFINI},
212 {"bl", required_argument, NULL, OPTION_LOADMAP},
213 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
214 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
215 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
216 {"bM", required_argument, NULL, OPTION_MODTYPE},
217 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
218 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
219 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
220 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
221 {"bnogc", no_argument, &gc, 0},
222 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
223 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
224 {"bnotextro", no_argument, &textro, 0},
225 {"bnro", no_argument, &textro, 0},
226 {"bpD", required_argument, NULL, OPTION_PD},
227 {"bpT", required_argument, NULL, OPTION_PT},
228 {"bro", no_argument, &textro, 1},
229 {"brtl", no_argument, &rtld, 1},
230 {"bnortl", no_argument, &rtld, 0},
231 {"bnortllib", no_argument, &rtld, 0},
232 {"bS", required_argument, NULL, OPTION_MAXSTACK},
233 {"bso", no_argument, NULL, OPTION_AUTOIMP},
234 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
235 {"btextro", no_argument, &textro, 1},
236 {"b32", no_argument, NULL, OPTION_32},
237 {"b64", no_argument, NULL, OPTION_64},
238 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
239 {"unix", no_argument, NULL, OPTION_UNIX},
240 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
241 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
242 {NULL, no_argument, NULL, 0}
245 /* Options supported by the AIX linker which we do not support: -f,
246 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
247 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
248 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
249 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
250 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
251 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
254 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
255 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
256 *longopts = xrealloc (*longopts,
257 nl * sizeof (struct option) + sizeof (xtra_long));
258 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
262 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
266 /* If the current option starts with -b, change the first : to an =.
267 The AIX linker uses : to separate the option from the argument;
268 changing it to = lets us treat it as a getopt option. */
273 if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
277 for (s = argv[indx]; *s != '\0'; s++)
290 gld${EMULATION_NAME}_handle_option (int optc)
301 /* Long option which just sets a flag. */
305 val = bfd_scan_vma (optarg, &end, 0);
307 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
309 lang_section_start (".data", exp_intop (val), NULL);
313 val = bfd_scan_vma (optarg, &end, 0);
314 if (*end != '\0' || (val & (val - 1)) != 0)
315 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
322 /* FIXME: This should use the page size for the target system. */
327 /* On AIX this is the same as GNU ld -Ttext. When we see -T
328 number, we assume the AIX option is intended. Otherwise, we
329 assume the usual GNU ld -T option is intended. We can't just
330 ignore the AIX option, because gcc passes it to the linker. */
331 val = bfd_scan_vma (optarg, &end, 0);
334 lang_section_start (".text", exp_intop (val), NULL);
340 case OPTION_INITFINI:
343 * The aix linker init fini has the format :
345 * -binitfini:[ Initial][:Termination][:Priority]
347 * it allows the Termination and Priority to be optional.
349 * Since we support only one init/fini pair, we ignore the Priority.
351 * Define the special symbol __rtinit.
353 * strtok does not correctly handle the case of -binitfini::fini: so
359 while (*t && ':' != *t)
365 link_info.init_function = i;
368 while (*t && ':' != *t)
373 link_info.fini_function = f;
378 link_info.static_link = FALSE;
382 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
383 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
387 link_info.unresolved_syms_in_objects = RM_IGNORE;
388 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
392 gld${EMULATION_NAME}_read_file (optarg, FALSE);
398 struct filelist **flpp;
400 n = (struct filelist *) xmalloc (sizeof (struct filelist));
403 flpp = &import_files;
404 while (*flpp != NULL)
405 flpp = &(*flpp)->next;
411 config.map_filename = optarg;
415 val = bfd_scan_vma (optarg, &end, 0);
417 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
422 case OPTION_MAXSTACK:
423 val = bfd_scan_vma (optarg, &end, 0);
425 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
434 link_info.shared = TRUE;
437 if (*optarg == '\0' || optarg[1] == '\0')
438 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
440 modtype = (*optarg << 8) | optarg[1];
443 case OPTION_NOAUTOIMP:
444 link_info.static_link = TRUE;
447 case OPTION_NOSTRCMPCT:
448 link_info.traditional_format = TRUE;
452 /* This sets the page that the .data section is supposed to
453 start on. The offset within the page should still be the
454 offset within the file, so we need to build an appropriate
456 val = bfd_scan_vma (optarg, &end, 0);
458 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
466 exp_nameop (NAME, "."),
469 exp_binop ('+', t, exp_intop (31)),
470 exp_intop (~(bfd_vma) 31));
471 lang_section_start (".data", t, NULL);
476 /* This set the page that the .text section is supposed to start
477 on. The offset within the page should still be the offset
479 val = bfd_scan_vma (optarg, &end, 0);
481 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
488 exp_nameop (SIZEOF_HEADERS, NULL));
490 exp_binop ('+', t, exp_intop (31)),
491 exp_intop (~(bfd_vma) 31));
492 lang_section_start (".text", t, NULL);
496 case OPTION_STRCMPCT:
497 link_info.traditional_format = FALSE;
507 symbol_mode_mask = 0x0d;
513 symbol_mode_mask = 0x0e;
517 command_line_blibpath = optarg;
520 case OPTION_NOLIBPATH:
521 command_line_blibpath = NULL;
529 /* This is called when an input file can not be recognized as a BFD
530 object or an archive. If the file starts with #!, we must treat it
531 as an import file. This is for AIX compatibility. */
534 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry)
539 e = fopen (entry->filename, FOPEN_RT);
545 if (getc (e) == '#' && getc (e) == '!')
548 struct filelist **flpp;
550 n = (struct filelist *) xmalloc (sizeof (struct filelist));
552 n->name = entry->filename;
553 flpp = &import_files;
554 while (*flpp != NULL)
555 flpp = &(*flpp)->next;
559 entry->loaded = TRUE;
567 /* This is called after the input files have been opened. */
570 gld${EMULATION_NAME}_after_open (void)
575 /* Call ldctor_build_sets, after pretending that this is a
576 relocatable link. We do this because AIX requires relocation
577 entries for all references to symbols, even in a final
578 executable. Of course, we only want to do this if we are
579 producing an XCOFF output file. */
580 r = link_info.relocatable;
581 if (strstr (bfd_get_target (link_info.output_bfd), "xcoff") != NULL)
582 link_info.relocatable = TRUE;
583 ldctor_build_sets ();
584 link_info.relocatable = r;
586 /* For each set, record the size, so that the XCOFF backend can
587 output the correct csect length. */
588 for (p = sets; p != (struct set_info *) NULL; p = p->next)
592 /* If the symbol is defined, we may have been invoked from
593 collect, and the sets may already have been built, so we do
595 if (p->h->type == bfd_link_hash_defined
596 || p->h->type == bfd_link_hash_defweak)
599 if (p->reloc != BFD_RELOC_CTOR)
601 /* Handle this if we need to. */
605 size = (p->count + 2) * 4;
606 if (!bfd_xcoff_link_record_set (link_info.output_bfd, &link_info,
608 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
612 /* This is called after the sections have been attached to output
613 sections, but before any sizes or addresses have been set. */
616 gld${EMULATION_NAME}_before_allocation (void)
619 struct export_symbol_list *el;
621 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
622 static const char *const must_keep_sections[] = {
629 /* Handle the import and export files, if any. */
630 for (fl = import_files; fl != NULL; fl = fl->next)
631 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
632 for (el = export_symbols; el != NULL; el = el->next)
634 struct bfd_link_hash_entry *h;
636 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
638 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
639 if (!bfd_xcoff_export_symbol (link_info.output_bfd, &link_info, h))
640 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
643 /* Track down all relocations called for by the linker script (these
644 are typically constructor/destructor entries created by
645 CONSTRUCTORS) and let the backend know it will need to create
646 .loader relocs for them. */
647 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
649 /* Precedence of LIBPATH
650 -blibpath: native support always first
651 -rpath: gnu extension
652 -L build from command line -L's */
653 if (command_line_blibpath != NULL)
654 libpath = command_line_blibpath;
655 else if (command_line.rpath != NULL)
656 libpath = command_line.rpath;
657 else if (search_head == NULL)
658 libpath = (char *) "";
662 search_dirs_type *search;
664 /* PR ld/4023: Strip sysroot prefix from any paths
665 being inserted into the output binary's DT_RPATH. */
666 if (ld_sysroot != NULL
667 && * ld_sysroot != 0)
669 const char * name = search_head->name;
670 size_t ld_sysroot_len = strlen (ld_sysroot);
672 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
673 name += ld_sysroot_len;
676 libpath = xmalloc (len + 1);
677 strcpy (libpath, name);
679 for (search = search_head->next; search != NULL; search = search->next)
684 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
685 name += ld_sysroot_len;
687 nlen = strlen (name);
688 libpath = xrealloc (libpath, len + nlen + 2);
690 strcpy (libpath + len + 1, name);
696 len = strlen (search_head->name);
697 libpath = xmalloc (len + 1);
698 strcpy (libpath, search_head->name);
700 for (search = search_head->next; search != NULL; search = search->next)
704 nlen = strlen (search->name);
705 libpath = xrealloc (libpath, len + nlen + 2);
707 strcpy (libpath + len + 1, search->name);
713 /* Let the XCOFF backend set up the .loader section. */
714 if (!bfd_xcoff_size_dynamic_sections
715 (link_info.output_bfd, &link_info, libpath, entry_symbol.name, file_align,
716 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
717 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
718 rtld ? TRUE : FALSE))
719 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
721 /* Look through the special sections, and put them in the right
722 place in the link ordering. This is especially magic. */
723 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
726 lang_output_section_statement_type *os;
727 lang_statement_union_type **pls;
728 lang_input_section_type *is;
732 sec = special_sections[i];
736 /* Remove this section from the list of the output section.
737 This assumes we know what the script looks like. */
739 os = lang_output_section_find (sec->output_section->name);
741 einfo ("%P%F: can't find output section %s\n",
742 sec->output_section->name);
744 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
746 if ((*pls)->header.type == lang_input_section_enum
747 && (*pls)->input_section.section == sec)
749 is = (lang_input_section_type *) * pls;
750 *pls = (*pls)->header.next;
754 if ((*pls)->header.type == lang_wild_statement_enum)
756 lang_statement_union_type **pwls;
758 for (pwls = &(*pls)->wild_statement.children.head;
759 *pwls != NULL; pwls = &(*pwls)->header.next)
762 if ((*pwls)->header.type == lang_input_section_enum
763 && (*pwls)->input_section.section == sec)
765 is = (lang_input_section_type *) * pwls;
766 *pwls = (*pwls)->header.next;
778 einfo ("%P%F: can't find %s in output section\n",
779 bfd_get_section_name (sec->owner, sec));
782 /* Now figure out where the section should go. */
786 default: /* to avoid warnings */
787 case XCOFF_SPECIAL_SECTION_TEXT:
793 case XCOFF_SPECIAL_SECTION_ETEXT:
799 case XCOFF_SPECIAL_SECTION_DATA:
805 case XCOFF_SPECIAL_SECTION_EDATA:
811 case XCOFF_SPECIAL_SECTION_END:
812 case XCOFF_SPECIAL_SECTION_END2:
819 os = lang_output_section_find (oname);
823 is->header.next = os->children.head;
824 os->children.head = (lang_statement_union_type *) is;
828 is->header.next = NULL;
829 lang_statement_append (&os->children,
830 (lang_statement_union_type *) is,
835 /* Executables and shared objects must always have .text, .data
836 and .bss output sections, so that the header can refer to them.
837 The kernel refuses to load objects that have missing sections. */
838 if (!link_info.relocatable)
839 for (i = 0; i < ARRAY_SIZE (must_keep_sections); i++)
843 sec = bfd_get_section_by_name (link_info.output_bfd,
844 must_keep_sections[i]);
846 einfo ("%P: can't find required output section %s\n", must_keep_sections[i]);
848 sec->flags |= SEC_KEEP;
851 before_allocation_default ();
855 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
858 static char *from_outside;
859 static char *from_inside;
860 static char *argv_to_target[][2] = {
861 {NULL, "${OUTPUT_FORMAT}"},
862 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
863 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
868 from_outside = getenv (TARGET_ENVIRON);
869 if (from_outside != (char *) NULL)
872 /* Set to default. */
873 from_inside = argv_to_target[0][1];
874 for (i = 1; i < argc; i++)
876 for (j = 1; j < jmax; j++)
878 if (0 == strcmp (argv[i], argv_to_target[j][0]))
879 from_inside = argv_to_target[j][1];
890 change_symbol_mode (char *input)
892 char *symbol_mode_string[] = {
903 for (bit = 0;; bit++)
905 string = symbol_mode_string[bit];
909 if (0 == strcmp (input, string))
911 symbol_mode = (1 << bit);
915 /* should not be here */
922 -1 : error, try something else */
924 is_syscall (char *input, unsigned int *flag)
930 char *syscall_string;
933 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
934 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
935 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
936 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
937 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
938 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
939 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
940 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
946 for (bit = 0;; bit++)
948 string = s[bit].syscall_string;
952 if (0 == strcmp (input, string))
954 if (1 << bit & syscall_mask)
965 /* should not be here */
969 /* Read an import or export file. For an import file, this is called
970 by the before_allocation emulation routine. For an export file,
971 this is called by the handle_option emulation routine. */
974 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
983 const char *impmember;
985 o = (struct obstack *) xmalloc (sizeof (struct obstack));
986 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
988 f = fopen (filename, FOPEN_RT);
991 bfd_set_error (bfd_error_system_call);
992 einfo ("%F%s: %E\n", filename);
1003 /* Default to 32 and 64 bit mode
1004 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
1005 are not repeated, assume 64 bit routines also want to use them.
1006 See the routine change_symbol_mode for more information. */
1010 while ((c = getc (f)) != EOF)
1014 unsigned int syscall_flag = 0;
1016 struct bfd_link_hash_entry *h;
1020 obstack_1grow (o, c);
1024 obstack_1grow (o, '\0');
1027 s = (char *) obstack_base (o);
1028 while (ISSPACE (*s))
1032 || change_symbol_mode (s)
1033 || (*s == '#' && s[1] == ' ')
1034 || (!import && *s == '#' && s[1] == '!'))
1036 obstack_free (o, obstack_base (o));
1040 if (*s == '#' && s[1] == '!')
1043 while (ISSPACE (*s))
1050 obstack_free (o, obstack_base (o));
1053 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1060 (void) obstack_finish (o);
1064 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1074 if (imppath == file - 1)
1084 while (ISSPACE (cs))
1093 einfo ("%s:%d: warning: syntax error in import file\n",
1100 while (*s != ')' && *s != '\0')
1105 einfo ("%s:%d: warning: syntax error in import file\n",
1113 if (symbol_mode & symbol_mode_mask)
1115 /* This is a symbol to be imported or exported. */
1118 address = (bfd_vma) -1;
1120 while (!ISSPACE (*s) && *s != '\0')
1128 while (ISSPACE (*s))
1132 while (!ISSPACE (*se) && *se != '\0')
1137 while (ISSPACE (*se))
1140 einfo ("%s%d: warning: syntax error in import/export file\n",
1149 status = is_syscall (s, &syscall_flag);
1153 /* not a system call, check for address */
1154 address = bfd_scan_vma (s, &end, 0);
1157 einfo ("%s:%d: warning: syntax error in import/export file\n",
1167 struct export_symbol_list *n;
1169 ldlang_add_undef (symname);
1170 n = ((struct export_symbol_list *)
1171 xmalloc (sizeof (struct export_symbol_list)));
1172 n->next = export_symbols;
1173 n->name = xstrdup (symname);
1178 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1180 if (h == NULL || h->type == bfd_link_hash_new)
1182 /* We can just ignore attempts to import an unreferenced
1187 if (!bfd_xcoff_import_symbol (link_info.output_bfd,
1189 address, imppath, impfile,
1190 impmember, syscall_flag))
1191 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1192 filename, lineno, symname);
1196 obstack_free (o, obstack_base (o));
1199 if (obstack_object_size (o) > 0)
1201 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1203 obstack_free (o, obstack_base (o));
1208 obstack_free (o, NULL);
1213 /* This routine saves us from worrying about declaring free. */
1216 gld${EMULATION_NAME}_free (void *p)
1221 /* This is called by the before_allocation routine via
1222 lang_for_each_statement. It looks for relocations and assignments
1226 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1228 if (s->header.type == lang_reloc_statement_enum)
1230 lang_reloc_statement_type *rs;
1232 rs = &s->reloc_statement;
1233 if (rs->name == NULL)
1234 einfo ("%F%P: only relocations against symbols are permitted\n");
1235 if (!bfd_xcoff_link_count_reloc (link_info.output_bfd, &link_info,
1237 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1240 if (s->header.type == lang_assignment_statement_enum)
1241 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1244 /* Look through an expression for an assignment statement. */
1247 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1249 struct bfd_link_hash_entry *h;
1251 switch (exp->type.node_class)
1254 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1255 FALSE, FALSE, FALSE);
1260 if (strcmp (exp->assign.dst, ".") != 0)
1262 if (!bfd_xcoff_record_link_assignment (link_info.output_bfd,
1265 einfo ("%P%F: failed to record assignment to %s: %E\n",
1268 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1272 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1273 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1277 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1278 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1279 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1283 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1292 gld${EMULATION_NAME}_get_script (int *isfile)
1295 if test -n "$COMPILE_IN"
1297 # Scripts compiled in.
1299 # sed commands to quote an ld script as a C string.
1300 sc="-f ${srcdir}/emultempl/ostring.sed"
1306 if (link_info.relocatable && config.build_constructors)
1309 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1310 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1311 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1312 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1313 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1314 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1315 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1316 echo ' ; else return' >> e${EMULATION_NAME}.c
1317 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1318 echo '; }' >> e${EMULATION_NAME}.c
1321 # Scripts read from the filesystem.
1327 if (link_info.relocatable && config.build_constructors)
1328 return "ldscripts/${EMULATION_NAME}.xu";
1329 else if (link_info.relocatable)
1330 return "ldscripts/${EMULATION_NAME}.xr";
1331 else if (!config.text_read_only)
1332 return "ldscripts/${EMULATION_NAME}.xbn";
1333 else if (!config.magic_demand_paged)
1334 return "ldscripts/${EMULATION_NAME}.xn";
1336 return "ldscripts/${EMULATION_NAME}.x";
1345 gld${EMULATION_NAME}_create_output_section_statements (void)
1348 if ((bfd_get_flavour (link_info.output_bfd) == bfd_target_xcoff_flavour)
1349 && (link_info.init_function != NULL
1350 || link_info.fini_function != NULL
1353 initfini_file = lang_add_input_file ("initfini",
1354 lang_input_file_is_file_enum,
1357 initfini_file->the_bfd = bfd_create ("initfini", link_info.output_bfd);
1358 if (initfini_file->the_bfd == NULL
1359 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1360 bfd_get_arch (link_info.output_bfd),
1361 bfd_get_mach (link_info.output_bfd)))
1363 einfo ("%X%P: can not create BFD %E\n");
1367 /* Call backend to fill in the rest */
1368 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1369 link_info.init_function,
1370 link_info.fini_function,
1373 einfo ("%X%P: can not create BFD %E\n");
1377 /* __rtld defined in /lib/librtl.a */
1379 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1384 gld${EMULATION_NAME}_set_output_arch (void)
1386 bfd_set_arch_mach (link_info.output_bfd,
1387 bfd_xcoff_architecture (link_info.output_bfd),
1388 bfd_xcoff_machine (link_info.output_bfd));
1390 ldfile_output_architecture = bfd_get_arch (link_info.output_bfd);
1391 ldfile_output_machine = bfd_get_mach (link_info.output_bfd);
1392 ldfile_output_machine_name = bfd_printable_name (link_info.output_bfd);
1395 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1396 gld${EMULATION_NAME}_before_parse,
1399 after_parse_default,
1400 gld${EMULATION_NAME}_after_open,
1401 after_allocation_default,
1402 gld${EMULATION_NAME}_set_output_arch,
1403 gld${EMULATION_NAME}_choose_target,
1404 gld${EMULATION_NAME}_before_allocation,
1405 gld${EMULATION_NAME}_get_script,
1406 "${EMULATION_NAME}",
1409 gld${EMULATION_NAME}_create_output_section_statements,
1410 0, /* open_dynamic_archive */
1411 0, /* place_orphan */
1412 0, /* set_symbols */
1413 gld${EMULATION_NAME}_parse_args,
1414 gld${EMULATION_NAME}_add_options,
1415 gld${EMULATION_NAME}_handle_option,
1416 gld${EMULATION_NAME}_unrecognized_file,
1417 NULL, /* list_options */
1418 NULL, /* recognized_file */
1419 NULL, /* find potential_libraries */
1420 NULL /* new_vers_pattern */