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"
57 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
58 static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));
59 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
60 static char *choose_target PARAMS ((int, char **));
61 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
62 static void gld${EMULATION_NAME}_read_file PARAMS ((const char *, boolean));
63 static void gld${EMULATION_NAME}_free PARAMS ((PTR));
64 static void gld${EMULATION_NAME}_find_relocs
65 PARAMS ((lang_statement_union_type *));
66 static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *));
67 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
68 static boolean gld${EMULATION_NAME}_unrecognized_file
69 PARAMS ((lang_input_statement_type *));
70 static void gld${EMULATION_NAME}_create_output_section_statements
72 static int is_syscall PARAMS ((char *, unsigned int *));
73 static int change_symbol_mode PARAMS ((char *));
75 /* The file alignment required for each section. */
76 static unsigned long file_align;
78 /* The maximum size the stack is permitted to grow. This is stored in
80 static unsigned long maxstack;
82 /* The maximum data size. This is stored in the a.out header. */
83 static unsigned long maxdata;
85 /* Whether to perform garbage collection. */
88 /* The module type to use. */
89 static unsigned short modtype = ('1' << 8) | 'L';
91 /* Whether the .text section must be read-only (i.e., no relocs
95 /* Whether to implement Unix like linker semantics. */
98 /* Structure used to hold import file list. */
102 struct filelist *next;
106 /* List of import files. */
107 static struct filelist *import_files;
109 /* List of export symbols read from the export files. */
111 struct export_symbol_list
113 struct export_symbol_list *next;
117 static struct export_symbol_list *export_symbols;
119 /* Maintains the 32 or 64 bit mode state of import file */
120 static unsigned int symbol_mode = 0x04;
122 /* Which symbol modes are valid */
123 static unsigned int symbol_mode_mask = 0x0d;
125 /* Whether this is a 64 bit link */
126 static int is_64bit = 0;
128 /* Which syscalls from import file are valid */
129 static unsigned int syscall_mask = 0x77;
131 /* fake file for -binitfini support */
132 static lang_input_statement_type *initfini_file;
134 /* Whether to do run time linking */
137 /* This routine is called before anything else is done. */
140 gld${EMULATION_NAME}_before_parse ()
142 #ifndef TARGET_ /* I.e., if not generic. */
143 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
146 ldfile_output_architecture = arch->arch;
147 ldfile_output_machine = arch->mach;
148 ldfile_output_machine_name = arch->printable_name;
151 ldfile_output_architecture = bfd_arch_${ARCH};
152 #endif /* not TARGET_ */
153 config.has_shared = true;
155 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
156 Override them here so we can use the link_info.init_function as a
157 state flag that lets the backend know that -binitfini has been done. */
159 link_info.init_function = NULL;
160 link_info.fini_function = NULL;
163 /* Handle AIX specific options. */
166 gld${EMULATION_NAME}_parse_args (argc, argv)
170 int prevoptind = optind;
171 int prevopterr = opterr;
201 /* -binitfini has special handling in the linker backend. The native linker
202 uses the arguemnts to generate a table of init and fini functions for
203 the executable. The important use for this option is to support aix 4.2+
204 c++ constructors and destructors. This is tied into gcc via collect2.c.
206 The function table is accessed by the runtime linker/loader by checking if
207 the first symbol in the loader symbol table is __rtinit. The gnu linker
208 generates this symbol and makes it the first loader symbol. */
210 static const struct option longopts[] = {
211 {"basis", no_argument, NULL, OPTION_IGNORE},
212 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
213 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
214 {"bcrld", no_argument, NULL, OPTION_IGNORE},
215 {"bcror31", no_argument, NULL, OPTION_IGNORE},
216 {"bD", required_argument, NULL, OPTION_MAXDATA},
217 {"bE", required_argument, NULL, OPTION_EXPORT},
218 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
219 {"berok", no_argument, NULL, OPTION_EROK},
220 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
221 {"bexport", required_argument, NULL, OPTION_EXPORT},
222 {"bf", no_argument, NULL, OPTION_ERNOTOK},
223 {"bgc", no_argument, &gc, 1},
224 {"bh", required_argument, NULL, OPTION_IGNORE},
225 {"bhalt", required_argument, NULL, OPTION_IGNORE},
226 {"bI", required_argument, NULL, OPTION_IMPORT},
227 {"bimport", required_argument, NULL, OPTION_IMPORT},
228 {"binitfini", required_argument, NULL, OPTION_INITFINI},
229 {"bl", required_argument, NULL, OPTION_LOADMAP},
230 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
231 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
232 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
233 {"bM", required_argument, NULL, OPTION_MODTYPE},
234 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
235 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
236 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
237 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
238 {"bnogc", no_argument, &gc, 0},
239 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
240 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
241 {"bnotextro", no_argument, &textro, 0},
242 {"bnro", no_argument, &textro, 0},
243 {"bpD", required_argument, NULL, OPTION_PD},
244 {"bpT", required_argument, NULL, OPTION_PT},
245 {"bro", no_argument, &textro, 1},
246 {"brtl", no_argument, &rtld, 1},
247 {"bS", required_argument, NULL, OPTION_MAXSTACK},
248 {"bso", no_argument, NULL, OPTION_AUTOIMP},
249 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
250 {"btextro", no_argument, &textro, 1},
251 {"b32", no_argument, NULL, OPTION_32},
252 {"b64", no_argument, NULL, OPTION_64},
253 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
254 {"unix", no_argument, NULL, OPTION_UNIX},
255 {NULL, no_argument, NULL, 0}
258 /* Options supported by the AIX linker which we do not support: -f,
259 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
260 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
261 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
262 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
263 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
264 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
267 /* If the current option starts with -b, change the first : to an =.
268 The AIX linker uses : to separate the option from the argument;
269 changing it to = lets us treat it as a getopt option. */
274 if (indx < argc && strncmp (argv[indx], "-b", 2) == 0)
278 for (s = argv[indx]; *s != '\0'; s++)
289 /* We add s and u so to the short options list so that -s and -u on
290 the command line do not match -static and -unix. */
293 optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
305 /* Long option which just sets a flag. */
309 val = strtoll (optarg, &end, 0);
311 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
313 lang_section_start (".data", exp_intop (val));
317 val = strtoul (optarg, &end, 0);
318 if (*end != '\0' || (val & (val - 1)) != 0)
319 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
326 /* FIXME: This should use the page size for the target system. */
331 /* On AIX this is the same as GNU ld -Ttext. When we see -T
332 number, we assume the AIX option is intended. Otherwise, we
333 assume the usual GNU ld -T option is intended. We can't just
334 ignore the AIX option, because gcc passes it to the linker. */
335 val = strtoull (optarg, &end, 0);
341 lang_section_start (".text", exp_intop (val));
347 case OPTION_INITFINI:
350 * The aix linker init fini has the format :
352 * -binitfini:[ Initial][:Termination][:Priority]
354 * it allows the Termination and Priority to be optional.
356 * Since we support only one init/fini pair, we ignore the Priority.
358 * Define the special symbol __rtinit.
360 * strtok does not correctly handle the case of -binitfini::fini: so
366 while (*t && ':' != *t)
372 link_info.init_function = i;
375 while (*t && ':' != *t)
380 link_info.fini_function = f;
385 link_info.static_link = false;
389 force_make_executable = false;
393 force_make_executable = true;
397 gld${EMULATION_NAME}_read_file (optarg, false);
403 struct filelist **flpp;
405 n = (struct filelist *) xmalloc (sizeof (struct filelist));
408 flpp = &import_files;
409 while (*flpp != NULL)
410 flpp = &(*flpp)->next;
416 config.map_filename = optarg;
420 val = strtoull (optarg, &end, 0);
422 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
427 case OPTION_MAXSTACK:
428 val = strtoull (optarg, &end, 0);
430 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
439 link_info.shared = true;
442 if (*optarg == '\0' || optarg[1] == '\0')
443 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
445 modtype = (*optarg << 8) | optarg[1];
448 case OPTION_NOAUTOIMP:
449 link_info.static_link = true;
452 case OPTION_NOSTRCMPCT:
453 link_info.traditional_format = true;
457 /* This sets the page that the .data section is supposed to
458 start on. The offset within the page should still be the
459 offset within the file, so we need to build an appropriate
461 val = strtoull (optarg, &end, 0);
463 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
471 exp_nameop (NAME, "."),
474 exp_binop ('+', t, exp_intop (31)),
475 exp_intop (~(bfd_vma) 31));
476 lang_section_start (".data", t);
481 /* This set the page that the .text section is supposed to start
482 on. The offset within the page should still be the offset
484 val = strtoull (optarg, &end, 0);
486 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
493 exp_nameop (SIZEOF_HEADERS, NULL));
495 exp_binop ('+', t, exp_intop (31)),
496 exp_intop (~(bfd_vma) 31));
497 lang_section_start (".text", t);
501 case OPTION_STRCMPCT:
502 link_info.traditional_format = false;
512 symbol_mode_mask = 0x0d;
518 symbol_mode_mask = 0x0e;
526 /* This is called when an input file can not be recognized as a BFD
527 object or an archive. If the file starts with #!, we must treat it
528 as an import file. This is for AIX compatibility. */
531 gld${EMULATION_NAME}_unrecognized_file (entry)
532 lang_input_statement_type *entry;
537 e = fopen (entry->filename, FOPEN_RT);
543 if (getc (e) == '#' && getc (e) == '!')
546 struct filelist **flpp;
548 n = (struct filelist *) xmalloc (sizeof (struct filelist));
550 n->name = entry->filename;
551 flpp = &import_files;
552 while (*flpp != NULL)
553 flpp = &(*flpp)->next;
557 entry->loaded = true;
565 /* This is called after the input files have been opened. */
568 gld${EMULATION_NAME}_after_open ()
573 /* Call ldctor_build_sets, after pretending that this is a
574 relocateable link. We do this because AIX requires relocation
575 entries for all references to symbols, even in a final
576 executable. Of course, we only want to do this if we are
577 producing an XCOFF output file. */
578 r = link_info.relocateable;
579 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
580 link_info.relocateable = true;
581 ldctor_build_sets ();
582 link_info.relocateable = r;
584 /* For each set, record the size, so that the XCOFF backend can
585 output the correct csect length. */
586 for (p = sets; p != (struct set_info *) NULL; p = p->next)
590 /* If the symbol is defined, we may have been invoked from
591 collect, and the sets may already have been built, so we do
593 if (p->h->type == bfd_link_hash_defined
594 || p->h->type == bfd_link_hash_defweak)
597 if (p->reloc != BFD_RELOC_CTOR)
599 /* Handle this if we need to. */
603 size = (p->count + 2) * 4;
604 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
605 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
609 /* This is called after the sections have been attached to output
610 sections, but before any sizes or addresses have been set. */
613 gld${EMULATION_NAME}_before_allocation ()
616 struct export_symbol_list *el;
618 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
621 /* Handle the import and export files, if any. */
622 for (fl = import_files; fl != NULL; fl = fl->next)
623 gld${EMULATION_NAME}_read_file (fl->name, true);
624 for (el = export_symbols; el != NULL; el = el->next)
626 struct bfd_link_hash_entry *h;
628 h = bfd_link_hash_lookup (link_info.hash, el->name, false, false, false);
630 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
631 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
632 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
635 /* Track down all relocations called for by the linker script (these
636 are typically constructor/destructor entries created by
637 CONSTRUCTORS) and let the backend know it will need to create
638 .loader relocs for them. */
639 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
641 /* We need to build LIBPATH from the -L arguments. If any -rpath
642 arguments were used, though, we use -rpath instead, as a GNU
644 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, file_align,
671 maxstack, maxdata, gc && !unix_ld ? true : false,
672 modtype, textro ? true : false, unix_ld, special_sections, rtld))
673 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
675 /* Look through the special sections, and put them in the right
676 place in the link ordering. This is especially magic. */
677 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
680 lang_output_section_statement_type *os;
681 lang_statement_union_type **pls;
682 lang_input_section_type *is;
686 sec = special_sections[i];
690 /* Remove this section from the list of the output section.
691 This assumes we know what the script looks like. */
693 os = lang_output_section_find (sec->output_section->name);
695 einfo ("%P%F: can't find output section %s\n",
696 sec->output_section->name);
698 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
700 if ((*pls)->header.type == lang_input_section_enum
701 && (*pls)->input_section.section == sec)
703 is = (lang_input_section_type *) * pls;
704 *pls = (*pls)->header.next;
708 if ((*pls)->header.type == lang_wild_statement_enum)
710 lang_statement_union_type **pwls;
712 for (pwls = &(*pls)->wild_statement.children.head;
713 *pwls != NULL; pwls = &(*pwls)->header.next)
716 if ((*pwls)->header.type == lang_input_section_enum
717 && (*pwls)->input_section.section == sec)
719 is = (lang_input_section_type *) * pwls;
720 *pwls = (*pwls)->header.next;
732 einfo ("%P%F: can't find %s in output section\n",
733 bfd_get_section_name (sec->owner, sec));
736 /* Now figure out where the section should go. */
740 default: /* to avoid warnings */
741 case XCOFF_SPECIAL_SECTION_TEXT:
747 case XCOFF_SPECIAL_SECTION_ETEXT:
753 case XCOFF_SPECIAL_SECTION_DATA:
759 case XCOFF_SPECIAL_SECTION_EDATA:
765 case XCOFF_SPECIAL_SECTION_END:
766 case XCOFF_SPECIAL_SECTION_END2:
773 os = lang_output_section_find (oname);
777 is->header.next = os->children.head;
778 os->children.head = (lang_statement_union_type *) is;
782 is->header.next = NULL;
783 lang_statement_append (&os->children,
784 (lang_statement_union_type *) is,
791 choose_target (argc, argv)
796 static char *from_outside;
797 static char *from_inside;
798 static char *argv_to_target[][2] = {
799 {NULL, "${OUTPUT_FORMAT}"},
800 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
801 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
806 from_outside = getenv (TARGET_ENVIRON);
807 if (from_outside != (char *) NULL)
810 /* Set to default. */
811 from_inside = argv_to_target[0][1];
812 for (i = 1; i < argc; i++)
814 for (j = 1; j < jmax; j++)
816 if (0 == strcmp (argv[i], argv_to_target[j][0]))
817 from_inside = argv_to_target[j][1];
828 change_symbol_mode (input)
831 char *symbol_mode_string[] = {
842 for (bit = 0;; bit++)
844 string = symbol_mode_string[bit];
848 if (0 == strcmp (input, string))
850 symbol_mode = (1 << bit);
854 /* should not be here */
861 -1 : error, try something else */
863 is_syscall (input, flag)
871 char *syscall_string;
874 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
875 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
876 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
877 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
878 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
879 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
880 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
881 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
887 for (bit = 0;; bit++)
889 string = s[bit].syscall_string;
893 if (0 == strcmp (input, string))
895 if (1 << bit & syscall_mask)
906 /* should not be here */
910 /* Read an import or export file. For an import file, this is called
911 by the before_allocation emulation routine. For an export file,
912 this is called by the parse_args emulation routine. */
915 gld${EMULATION_NAME}_read_file (filename, import)
916 const char *filename;
926 const char *impmember;
928 o = (struct obstack *) xmalloc (sizeof (struct obstack));
929 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
931 f = fopen (filename, FOPEN_RT);
934 bfd_set_error (bfd_error_system_call);
935 einfo ("%F%s: %E\n", filename);
946 /* Default to 32 and 64 bit mode
947 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
948 are not repeated, assume 64 bit routines also want to use them.
949 See the routine change_symbol_mode for more information. */
953 while ((c = getc (f)) != EOF)
957 unsigned int syscall_flag = 0;
959 struct bfd_link_hash_entry *h;
963 obstack_1grow (o, c);
967 obstack_1grow (o, '\0');
970 s = (char *) obstack_base (o);
975 || change_symbol_mode (s)
976 || (*s == '#' && s[1] == ' ')
977 || (!import && *s == '#' && s[1] == '!'))
979 obstack_free (o, obstack_base (o));
983 if (*s == '#' && s[1] == '!')
993 obstack_free (o, obstack_base (o));
996 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1003 (void) obstack_finish (o);
1007 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1017 if (imppath == file - 1)
1027 while (ISSPACE (cs))
1036 einfo ("%s:%d: warning: syntax error in import file\n",
1043 while (*s != ')' && *s != '\0')
1048 einfo ("%s:%d: warning: syntax error in import file\n",
1056 if (symbol_mode & symbol_mode_mask)
1058 /* This is a symbol to be imported or exported. */
1061 address = (bfd_vma) -1;
1063 while (!ISSPACE (*s) && *s != '\0')
1071 while (ISSPACE (*s))
1075 while (!ISSPACE (*se) && *se != '\0')
1080 while (ISSPACE (*se))
1083 einfo ("%s%d: warning: syntax error in import/export file\n",
1092 status = is_syscall (s, &syscall_flag);
1096 /* not a system call, check for address */
1097 address = strtoul (s, &end, 0);
1100 einfo ("%s:%d: warning: syntax error in import/export file\n",
1110 struct export_symbol_list *n;
1112 ldlang_add_undef (symname);
1113 n = ((struct export_symbol_list *)
1114 xmalloc (sizeof (struct export_symbol_list)));
1115 n->next = export_symbols;
1116 n->name = xstrdup (symname);
1121 h = bfd_link_hash_lookup (link_info.hash, symname, false, false,
1123 if (h == NULL || h->type == bfd_link_hash_new)
1125 /* We can just ignore attempts to import an unreferenced
1130 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1131 address, imppath, impfile,
1132 impmember, syscall_flag))
1133 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1134 filename, lineno, symname);
1138 obstack_free (o, obstack_base (o));
1141 if (obstack_object_size (o) > 0)
1143 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1145 obstack_free (o, obstack_base (o));
1150 obstack_free (o, NULL);
1155 /* This routine saves us from worrying about declaring free. */
1158 gld${EMULATION_NAME}_free (p)
1164 /* This is called by the before_allocation routine via
1165 lang_for_each_statement. It looks for relocations and assignments
1169 gld${EMULATION_NAME}_find_relocs (s)
1170 lang_statement_union_type *s;
1172 if (s->header.type == lang_reloc_statement_enum)
1174 lang_reloc_statement_type *rs;
1176 rs = &s->reloc_statement;
1177 if (rs->name == NULL)
1178 einfo ("%F%P: only relocations against symbols are permitted\n");
1179 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1180 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1183 if (s->header.type == lang_assignment_statement_enum)
1184 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1187 /* Look through an expression for an assignment statement. */
1190 gld${EMULATION_NAME}_find_exp_assignment (exp)
1193 struct bfd_link_hash_entry *h;
1195 switch (exp->type.node_class)
1198 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1199 false, false, false);
1204 if (strcmp (exp->assign.dst, ".") != 0)
1206 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1208 einfo ("%P%F: failed to record assignment to %s: %E\n",
1211 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1215 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1216 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1220 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1221 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1222 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1226 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1235 gld${EMULATION_NAME}_get_script (isfile)
1239 if test -n "$COMPILE_IN"
1241 # Scripts compiled in.
1243 # sed commands to quote an ld script as a C string.
1244 sc="-f ${srcdir}/emultempl/ostring.sed"
1246 cat >>e${EMULATION_NAME}.c <<EOF
1250 if (link_info.relocateable == true && config.build_constructors == true)
1253 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1254 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1255 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1256 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1257 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1258 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1259 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1260 echo ' ; else return' >> e${EMULATION_NAME}.c
1261 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1262 echo '; }' >> e${EMULATION_NAME}.c
1265 # Scripts read from the filesystem.
1267 cat >>e${EMULATION_NAME}.c <<EOF
1271 if (link_info.relocateable == true && config.build_constructors == true)
1272 return "ldscripts/${EMULATION_NAME}.xu";
1273 else if (link_info.relocateable == true)
1274 return "ldscripts/${EMULATION_NAME}.xr";
1275 else if (!config.text_read_only)
1276 return "ldscripts/${EMULATION_NAME}.xbn";
1277 else if (!config.magic_demand_paged)
1278 return "ldscripts/${EMULATION_NAME}.xn";
1280 return "ldscripts/${EMULATION_NAME}.x";
1286 cat >>e${EMULATION_NAME}.c <<EOF
1289 gld${EMULATION_NAME}_create_output_section_statements()
1292 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1293 && (link_info.init_function != NULL
1294 || link_info.fini_function != NULL
1297 initfini_file = lang_add_input_file ("initfini",
1298 lang_input_file_is_file_enum,
1301 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1302 if (initfini_file->the_bfd == NULL
1303 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1304 bfd_get_arch (output_bfd),
1305 bfd_get_mach (output_bfd)))
1307 einfo ("%X%P: can not create BFD %E\n");
1311 /* Call backend to fill in the rest */
1312 if (false == bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1313 link_info.init_function,
1314 link_info.fini_function,
1317 einfo ("%X%P: can not create BFD %E\n");
1321 /* __rtld defined in /lib/librtl.a */
1323 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1327 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1328 gld${EMULATION_NAME}_before_parse,
1331 after_parse_default,
1332 gld${EMULATION_NAME}_after_open,
1333 after_allocation_default,
1334 set_output_arch_default,
1336 gld${EMULATION_NAME}_before_allocation,
1337 gld${EMULATION_NAME}_get_script,
1338 "${EMULATION_NAME}",
1341 gld${EMULATION_NAME}_create_output_section_statements,
1342 0, /* open_dynamic_archive */
1343 0, /* place_orphan */
1344 0, /* set_symbols */
1345 gld${EMULATION_NAME}_parse_args,
1346 gld${EMULATION_NAME}_unrecognized_file,
1347 NULL, /* list_options */
1348 NULL, /* recognized_file */
1349 NULL, /* find potential_libraries */