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
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
139 -brtl enables, -bnortl and -bnortllib disable. */
142 /* Explicit command line library path, -blibpath */
143 static char *command_line_blibpath = NULL;
145 /* This routine is called before anything else is done. */
148 gld${EMULATION_NAME}_before_parse ()
150 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
153 ldfile_output_architecture = arch->arch;
154 ldfile_output_machine = arch->mach;
155 ldfile_output_machine_name = arch->printable_name;
158 ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`;
160 config.has_shared = true;
162 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
163 Override them here so we can use the link_info.init_function as a
164 state flag that lets the backend know that -binitfini has been done. */
166 link_info.init_function = NULL;
167 link_info.fini_function = NULL;
170 /* Handle AIX specific options. */
173 gld${EMULATION_NAME}_parse_args (argc, argv)
177 int prevoptind = optind;
178 int prevopterr = opterr;
210 /* -binitfini has special handling in the linker backend. The native linker
211 uses the arguemnts to generate a table of init and fini functions for
212 the executable. The important use for this option is to support aix 4.2+
213 c++ constructors and destructors. This is tied into gcc via collect2.c.
215 The function table is accessed by the runtime linker/loader by checking if
216 the first symbol in the loader symbol table is __rtinit. The gnu linker
217 generates this symbol and makes it the first loader symbol. */
219 static const struct option longopts[] = {
220 {"basis", no_argument, NULL, OPTION_IGNORE},
221 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
222 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
223 {"bcrld", no_argument, NULL, OPTION_IGNORE},
224 {"bcror31", no_argument, NULL, OPTION_IGNORE},
225 {"bD", required_argument, NULL, OPTION_MAXDATA},
226 {"bE", required_argument, NULL, OPTION_EXPORT},
227 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
228 {"berok", no_argument, NULL, OPTION_EROK},
229 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
230 {"bexport", required_argument, NULL, OPTION_EXPORT},
231 {"bf", no_argument, NULL, OPTION_ERNOTOK},
232 {"bgc", no_argument, &gc, 1},
233 {"bh", required_argument, NULL, OPTION_IGNORE},
234 {"bhalt", required_argument, NULL, OPTION_IGNORE},
235 {"bI", required_argument, NULL, OPTION_IMPORT},
236 {"bimport", required_argument, NULL, OPTION_IMPORT},
237 {"binitfini", required_argument, NULL, OPTION_INITFINI},
238 {"bl", required_argument, NULL, OPTION_LOADMAP},
239 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
240 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
241 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
242 {"bM", required_argument, NULL, OPTION_MODTYPE},
243 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
244 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
245 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
246 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
247 {"bnogc", no_argument, &gc, 0},
248 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
249 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
250 {"bnotextro", no_argument, &textro, 0},
251 {"bnro", no_argument, &textro, 0},
252 {"bpD", required_argument, NULL, OPTION_PD},
253 {"bpT", required_argument, NULL, OPTION_PT},
254 {"bro", no_argument, &textro, 1},
255 {"brtl", no_argument, &rtld, 1},
256 {"bnortl", no_argument, &rtld, 0},
257 {"bnortllib", no_argument, &rtld, 0},
258 {"bS", required_argument, NULL, OPTION_MAXSTACK},
259 {"bso", no_argument, NULL, OPTION_AUTOIMP},
260 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
261 {"btextro", no_argument, &textro, 1},
262 {"b32", no_argument, NULL, OPTION_32},
263 {"b64", no_argument, NULL, OPTION_64},
264 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
265 {"unix", no_argument, NULL, OPTION_UNIX},
266 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
267 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
268 {NULL, no_argument, NULL, 0}
271 /* Options supported by the AIX linker which we do not support: -f,
272 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
273 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
274 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
275 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
276 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
277 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
280 /* If the current option starts with -b, change the first : to an =.
281 The AIX linker uses : to separate the option from the argument;
282 changing it to = lets us treat it as a getopt option. */
287 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
291 for (s = argv[indx]; *s != '\0'; s++)
302 /* We add s and u so to the short options list so that -s and -u on
303 the command line do not match -static and -unix. */
306 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
318 /* Long option which just sets a flag. */
322 val = bfd_scan_vma (optarg, &end, 0);
324 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
326 lang_section_start (".data", exp_intop (val));
330 val = bfd_scan_vma (optarg, &end, 0);
331 if (*end != '\0' || (val & (val - 1)) != 0)
332 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
339 /* FIXME: This should use the page size for the target system. */
344 /* On AIX this is the same as GNU ld -Ttext. When we see -T
345 number, we assume the AIX option is intended. Otherwise, we
346 assume the usual GNU ld -T option is intended. We can't just
347 ignore the AIX option, because gcc passes it to the linker. */
348 val = bfd_scan_vma (optarg, &end, 0);
354 lang_section_start (".text", exp_intop (val));
360 case OPTION_INITFINI:
363 * The aix linker init fini has the format :
365 * -binitfini:[ Initial][:Termination][:Priority]
367 * it allows the Termination and Priority to be optional.
369 * Since we support only one init/fini pair, we ignore the Priority.
371 * Define the special symbol __rtinit.
373 * strtok does not correctly handle the case of -binitfini::fini: so
379 while (*t && ':' != *t)
385 link_info.init_function = i;
388 while (*t && ':' != *t)
393 link_info.fini_function = f;
398 link_info.static_link = false;
402 force_make_executable = false;
406 force_make_executable = true;
410 gld${EMULATION_NAME}_read_file (optarg, false);
416 struct filelist **flpp;
418 n = (struct filelist *) xmalloc (sizeof (struct filelist));
421 flpp = &import_files;
422 while (*flpp != NULL)
423 flpp = &(*flpp)->next;
429 config.map_filename = optarg;
433 val = bfd_scan_vma (optarg, &end, 0);
435 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
440 case OPTION_MAXSTACK:
441 val = bfd_scan_vma (optarg, &end, 0);
443 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
452 link_info.shared = true;
455 if (*optarg == '\0' || optarg[1] == '\0')
456 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
458 modtype = (*optarg << 8) | optarg[1];
461 case OPTION_NOAUTOIMP:
462 link_info.static_link = true;
465 case OPTION_NOSTRCMPCT:
466 link_info.traditional_format = true;
470 /* This sets the page that the .data section is supposed to
471 start on. The offset within the page should still be the
472 offset within the file, so we need to build an appropriate
474 val = bfd_scan_vma (optarg, &end, 0);
476 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
484 exp_nameop (NAME, "."),
487 exp_binop ('+', t, exp_intop (31)),
488 exp_intop (~(bfd_vma) 31));
489 lang_section_start (".data", t);
494 /* This set the page that the .text section is supposed to start
495 on. The offset within the page should still be the offset
497 val = bfd_scan_vma (optarg, &end, 0);
499 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
506 exp_nameop (SIZEOF_HEADERS, NULL));
508 exp_binop ('+', t, exp_intop (31)),
509 exp_intop (~(bfd_vma) 31));
510 lang_section_start (".text", t);
514 case OPTION_STRCMPCT:
515 link_info.traditional_format = false;
525 symbol_mode_mask = 0x0d;
531 symbol_mode_mask = 0x0e;
535 command_line_blibpath = optarg;
538 case OPTION_NOLIBPATH:
539 command_line_blibpath = NULL;
547 /* This is called when an input file can not be recognized as a BFD
548 object or an archive. If the file starts with #!, we must treat it
549 as an import file. This is for AIX compatibility. */
552 gld${EMULATION_NAME}_unrecognized_file (entry)
553 lang_input_statement_type *entry;
558 e = fopen (entry->filename, FOPEN_RT);
564 if (getc (e) == '#' && getc (e) == '!')
567 struct filelist **flpp;
569 n = (struct filelist *) xmalloc (sizeof (struct filelist));
571 n->name = entry->filename;
572 flpp = &import_files;
573 while (*flpp != NULL)
574 flpp = &(*flpp)->next;
578 entry->loaded = true;
586 /* This is called after the input files have been opened. */
589 gld${EMULATION_NAME}_after_open ()
594 /* Call ldctor_build_sets, after pretending that this is a
595 relocateable link. We do this because AIX requires relocation
596 entries for all references to symbols, even in a final
597 executable. Of course, we only want to do this if we are
598 producing an XCOFF output file. */
599 r = link_info.relocateable;
600 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
601 link_info.relocateable = true;
602 ldctor_build_sets ();
603 link_info.relocateable = r;
605 /* For each set, record the size, so that the XCOFF backend can
606 output the correct csect length. */
607 for (p = sets; p != (struct set_info *) NULL; p = p->next)
611 /* If the symbol is defined, we may have been invoked from
612 collect, and the sets may already have been built, so we do
614 if (p->h->type == bfd_link_hash_defined
615 || p->h->type == bfd_link_hash_defweak)
618 if (p->reloc != BFD_RELOC_CTOR)
620 /* Handle this if we need to. */
624 size = (p->count + 2) * 4;
625 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
626 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
630 /* This is called after the sections have been attached to output
631 sections, but before any sizes or addresses have been set. */
634 gld${EMULATION_NAME}_before_allocation ()
637 struct export_symbol_list *el;
639 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
642 /* Handle the import and export files, if any. */
643 for (fl = import_files; fl != NULL; fl = fl->next)
644 gld${EMULATION_NAME}_read_file (fl->name, true);
645 for (el = export_symbols; el != NULL; el = el->next)
647 struct bfd_link_hash_entry *h;
649 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
651 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
652 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
653 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
656 /* Track down all relocations called for by the linker script (these
657 are typically constructor/destructor entries created by
658 CONSTRUCTORS) and let the backend know it will need to create
659 .loader relocs for them. */
660 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
662 /* Precedence of LIBPATH
663 -blibpath: native support always first
664 -rpath: gnu extension
665 -L build from command line -L's */
666 if (command_line_blibpath != NULL)
667 libpath = command_line_blibpath;
668 else if (command_line.rpath != NULL)
669 libpath = command_line.rpath;
670 else if (search_head == NULL)
671 libpath = (char *) "";
675 search_dirs_type *search;
677 len = strlen (search_head->name);
678 libpath = xmalloc (len + 1);
679 strcpy (libpath, search_head->name);
680 for (search = search_head->next; search != NULL; search = search->next)
684 nlen = strlen (search->name);
685 libpath = xrealloc (libpath, len + nlen + 2);
687 strcpy (libpath + len + 1, search->name);
692 /* Let the XCOFF backend set up the .loader section. */
693 if (!bfd_xcoff_size_dynamic_sections
694 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
695 maxstack, maxdata, gc && !unix_ld ? true : false,
696 modtype, textro ? true : false, unix_ld, special_sections,
697 rtld ? true : false))
698 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
700 /* Look through the special sections, and put them in the right
701 place in the link ordering. This is especially magic. */
702 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
705 lang_output_section_statement_type *os;
706 lang_statement_union_type **pls;
707 lang_input_section_type *is;
711 sec = special_sections[i];
715 /* Remove this section from the list of the output section.
716 This assumes we know what the script looks like. */
718 os = lang_output_section_find (sec->output_section->name);
720 einfo ("%P%F: can't find output section %s\n",
721 sec->output_section->name);
723 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
725 if ((*pls)->header.type == lang_input_section_enum
726 && (*pls)->input_section.section == sec)
728 is = (lang_input_section_type *) * pls;
729 *pls = (*pls)->header.next;
733 if ((*pls)->header.type == lang_wild_statement_enum)
735 lang_statement_union_type **pwls;
737 for (pwls = &(*pls)->wild_statement.children.head;
738 *pwls != NULL; pwls = &(*pwls)->header.next)
741 if ((*pwls)->header.type == lang_input_section_enum
742 && (*pwls)->input_section.section == sec)
744 is = (lang_input_section_type *) * pwls;
745 *pwls = (*pwls)->header.next;
757 einfo ("%P%F: can't find %s in output section\n",
758 bfd_get_section_name (sec->owner, sec));
761 /* Now figure out where the section should go. */
765 default: /* to avoid warnings */
766 case XCOFF_SPECIAL_SECTION_TEXT:
772 case XCOFF_SPECIAL_SECTION_ETEXT:
778 case XCOFF_SPECIAL_SECTION_DATA:
784 case XCOFF_SPECIAL_SECTION_EDATA:
790 case XCOFF_SPECIAL_SECTION_END:
791 case XCOFF_SPECIAL_SECTION_END2:
798 os = lang_output_section_find (oname);
802 is->header.next = os->children.head;
803 os->children.head = (lang_statement_union_type *) is;
807 is->header.next = NULL;
808 lang_statement_append (&os->children,
809 (lang_statement_union_type *) is,
816 gld${EMULATION_NAME}_choose_target (argc, argv)
821 static char *from_outside;
822 static char *from_inside;
823 static char *argv_to_target[][2] = {
824 {NULL, "${OUTPUT_FORMAT}"},
825 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
826 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
831 from_outside = getenv (TARGET_ENVIRON);
832 if (from_outside != (char *) NULL)
835 /* Set to default. */
836 from_inside = argv_to_target[0][1];
837 for (i = 1; i < argc; i++)
839 for (j = 1; j < jmax; j++)
841 if (0 == strcmp (argv[i], argv_to_target[j][0]))
842 from_inside = argv_to_target[j][1];
853 change_symbol_mode (input)
856 char *symbol_mode_string[] = {
867 for (bit = 0;; bit++)
869 string = symbol_mode_string[bit];
873 if (0 == strcmp (input, string))
875 symbol_mode = (1 << bit);
879 /* should not be here */
886 -1 : error, try something else */
888 is_syscall (input, flag)
896 char *syscall_string;
899 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
900 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
901 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
902 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
903 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
904 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
905 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
906 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
912 for (bit = 0;; bit++)
914 string = s[bit].syscall_string;
918 if (0 == strcmp (input, string))
920 if (1 << bit & syscall_mask)
931 /* should not be here */
935 /* Read an import or export file. For an import file, this is called
936 by the before_allocation emulation routine. For an export file,
937 this is called by the parse_args emulation routine. */
940 gld${EMULATION_NAME}_read_file (filename, import)
941 const char *filename;
951 const char *impmember;
953 o = (struct obstack *) xmalloc (sizeof (struct obstack));
954 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
956 f = fopen (filename, FOPEN_RT);
959 bfd_set_error (bfd_error_system_call);
960 einfo ("%F%s: %E\n", filename);
971 /* Default to 32 and 64 bit mode
972 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
973 are not repeated, assume 64 bit routines also want to use them.
974 See the routine change_symbol_mode for more information. */
978 while ((c = getc (f)) != EOF)
982 unsigned int syscall_flag = 0;
984 struct bfd_link_hash_entry *h;
988 obstack_1grow (o, c);
992 obstack_1grow (o, '\0');
995 s = (char *) obstack_base (o);
1000 || change_symbol_mode (s)
1001 || (*s == '#' && s[1] == ' ')
1002 || (!import && *s == '#' && s[1] == '!'))
1004 obstack_free (o, obstack_base (o));
1008 if (*s == '#' && s[1] == '!')
1011 while (ISSPACE (*s))
1018 obstack_free (o, obstack_base (o));
1021 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1028 (void) obstack_finish (o);
1032 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1042 if (imppath == file - 1)
1052 while (ISSPACE (cs))
1061 einfo ("%s:%d: warning: syntax error in import file\n",
1068 while (*s != ')' && *s != '\0')
1073 einfo ("%s:%d: warning: syntax error in import file\n",
1081 if (symbol_mode & symbol_mode_mask)
1083 /* This is a symbol to be imported or exported. */
1086 address = (bfd_vma) -1;
1088 while (!ISSPACE (*s) && *s != '\0')
1096 while (ISSPACE (*s))
1100 while (!ISSPACE (*se) && *se != '\0')
1105 while (ISSPACE (*se))
1108 einfo ("%s%d: warning: syntax error in import/export file\n",
1117 status = is_syscall (s, &syscall_flag);
1121 /* not a system call, check for address */
1122 address = bfd_scan_vma (s, &end, 0);
1125 einfo ("%s:%d: warning: syntax error in import/export file\n",
1135 struct export_symbol_list *n;
1137 ldlang_add_undef (symname);
1138 n = ((struct export_symbol_list *)
1139 xmalloc (sizeof (struct export_symbol_list)));
1140 n->next = export_symbols;
1141 n->name = xstrdup (symname);
1146 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1148 if (h == NULL || h->type == bfd_link_hash_new)
1150 /* We can just ignore attempts to import an unreferenced
1155 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1156 address, imppath, impfile,
1157 impmember, syscall_flag))
1158 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1159 filename, lineno, symname);
1163 obstack_free (o, obstack_base (o));
1166 if (obstack_object_size (o) > 0)
1168 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1170 obstack_free (o, obstack_base (o));
1175 obstack_free (o, NULL);
1180 /* This routine saves us from worrying about declaring free. */
1183 gld${EMULATION_NAME}_free (p)
1189 /* This is called by the before_allocation routine via
1190 lang_for_each_statement. It looks for relocations and assignments
1194 gld${EMULATION_NAME}_find_relocs (s)
1195 lang_statement_union_type *s;
1197 if (s->header.type == lang_reloc_statement_enum)
1199 lang_reloc_statement_type *rs;
1201 rs = &s->reloc_statement;
1202 if (rs->name == NULL)
1203 einfo ("%F%P: only relocations against symbols are permitted\n");
1204 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1205 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1208 if (s->header.type == lang_assignment_statement_enum)
1209 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1212 /* Look through an expression for an assignment statement. */
1215 gld${EMULATION_NAME}_find_exp_assignment (exp)
1218 struct bfd_link_hash_entry *h;
1220 switch (exp->type.node_class)
1223 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1224 false, false, false);
1229 if (strcmp (exp->assign.dst, ".") != 0)
1231 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1233 einfo ("%P%F: failed to record assignment to %s: %E\n",
1236 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1240 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1241 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1245 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1246 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1247 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1251 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1260 gld${EMULATION_NAME}_get_script (isfile)
1264 if test -n "$COMPILE_IN"
1266 # Scripts compiled in.
1268 # sed commands to quote an ld script as a C string.
1269 sc="-f ${srcdir}/emultempl/ostring.sed"
1271 cat >>e${EMULATION_NAME}.c <<EOF
1275 if (link_info.relocateable == true && config.build_constructors == true)
1278 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1279 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1280 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1281 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1282 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1283 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1284 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1285 echo ' ; else return' >> e${EMULATION_NAME}.c
1286 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1287 echo '; }' >> e${EMULATION_NAME}.c
1290 # Scripts read from the filesystem.
1292 cat >>e${EMULATION_NAME}.c <<EOF
1296 if (link_info.relocateable == true && config.build_constructors == true)
1297 return "ldscripts/${EMULATION_NAME}.xu";
1298 else if (link_info.relocateable == true)
1299 return "ldscripts/${EMULATION_NAME}.xr";
1300 else if (!config.text_read_only)
1301 return "ldscripts/${EMULATION_NAME}.xbn";
1302 else if (!config.magic_demand_paged)
1303 return "ldscripts/${EMULATION_NAME}.xn";
1305 return "ldscripts/${EMULATION_NAME}.x";
1311 cat >>e${EMULATION_NAME}.c <<EOF
1314 gld${EMULATION_NAME}_create_output_section_statements ()
1317 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1318 && (link_info.init_function != NULL
1319 || link_info.fini_function != NULL
1322 initfini_file = lang_add_input_file ("initfini",
1323 lang_input_file_is_file_enum,
1326 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1327 if (initfini_file->the_bfd == NULL
1328 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1329 bfd_get_arch (output_bfd),
1330 bfd_get_mach (output_bfd)))
1332 einfo ("%X%P: can not create BFD %E\n");
1336 /* Call backend to fill in the rest */
1337 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1338 link_info.init_function,
1339 link_info.fini_function,
1342 einfo ("%X%P: can not create BFD %E\n");
1346 /* __rtld defined in /lib/librtl.a */
1348 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1353 gld${EMULATION_NAME}_set_output_arch ()
1355 bfd_set_arch_mach (output_bfd,
1356 bfd_xcoff_architecture (output_bfd),
1357 bfd_xcoff_machine (output_bfd));
1359 ldfile_output_architecture = bfd_get_arch (output_bfd);
1360 ldfile_output_machine = bfd_get_mach (output_bfd);
1361 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1364 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1365 gld${EMULATION_NAME}_before_parse,
1368 after_parse_default,
1369 gld${EMULATION_NAME}_after_open,
1370 after_allocation_default,
1371 gld${EMULATION_NAME}_set_output_arch,
1372 gld${EMULATION_NAME}_choose_target,
1373 gld${EMULATION_NAME}_before_allocation,
1374 gld${EMULATION_NAME}_get_script,
1375 "${EMULATION_NAME}",
1378 gld${EMULATION_NAME}_create_output_section_statements,
1379 0, /* open_dynamic_archive */
1380 0, /* place_orphan */
1381 0, /* set_symbols */
1382 gld${EMULATION_NAME}_parse_args,
1383 gld${EMULATION_NAME}_unrecognized_file,
1384 NULL, /* list_options */
1385 NULL, /* recognized_file */
1386 NULL, /* find potential_libraries */
1387 NULL /* new_vers_pattern */