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, 2009, 2010
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 /* A mask of XCOFF_EXPALL and XCOFF_EXPFULL flags, as set by their
88 associated -b and -bno options. */
89 static unsigned int auto_export_flags;
91 /* A mask of auto_export_flags bits that were explicitly set on the
93 static unsigned int explicit_auto_export_flags;
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
135 -brtl enables, -bnortl and -bnortllib disable. */
138 /* Explicit command line library path, -blibpath */
139 static char *command_line_blibpath = NULL;
141 /* This routine is called before anything else is done. */
144 gld${EMULATION_NAME}_before_parse (void)
146 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
148 config.dynamic_link = TRUE;
149 config.has_shared = TRUE;
151 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
152 Override them here so we can use the link_info.init_function as a
153 state flag that lets the backend know that -binitfini has been done. */
155 link_info.init_function = NULL;
156 link_info.fini_function = NULL;
159 /* Handle AIX specific options. */
191 gld${EMULATION_NAME}_add_options
192 (int ns, char **shortopts, int nl, struct option **longopts,
193 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
195 static const char xtra_short[] = "D:H:KT:z";
196 static const struct option xtra_long[] = {
197 /* -binitfini has special handling in the linker backend. The native linker
198 uses the arguemnts to generate a table of init and fini functions for
199 the executable. The important use for this option is to support aix 4.2+
200 c++ constructors and destructors. This is tied into gcc via collect2.c.
202 The function table is accessed by the runtime linker/loader by checking if
203 the first symbol in the loader symbol table is __rtinit. The gnu linker
204 generates this symbol and makes it the first loader symbol. */
206 {"basis", no_argument, NULL, OPTION_IGNORE},
207 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
208 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
209 {"bcrld", no_argument, NULL, OPTION_IGNORE},
210 {"bcror31", no_argument, NULL, OPTION_IGNORE},
211 {"bD", required_argument, NULL, OPTION_MAXDATA},
212 {"bE", required_argument, NULL, OPTION_EXPORT},
213 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
214 {"berok", no_argument, NULL, OPTION_EROK},
215 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
216 {"bexpall", no_argument, NULL, OPTION_EXPALL},
217 {"bexpfull", no_argument, NULL, OPTION_EXPFULL},
218 {"bexport", required_argument, NULL, OPTION_EXPORT},
219 {"bbigtoc", no_argument, NULL, OPTION_IGNORE},
220 {"bf", no_argument, NULL, OPTION_ERNOTOK},
221 {"bgc", no_argument, &gc, 1},
222 {"bh", required_argument, NULL, OPTION_IGNORE},
223 {"bhalt", required_argument, NULL, OPTION_IGNORE},
224 {"bI", required_argument, NULL, OPTION_IMPORT},
225 {"bimport", required_argument, NULL, OPTION_IMPORT},
226 {"binitfini", required_argument, NULL, OPTION_INITFINI},
227 {"bl", required_argument, NULL, OPTION_LOADMAP},
228 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
229 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
230 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
231 {"bM", required_argument, NULL, OPTION_MODTYPE},
232 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
233 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
234 {"bnoexpall", no_argument, NULL, OPTION_NOEXPALL},
235 {"bnoexpfull", no_argument, NULL, OPTION_NOEXPFULL},
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 {"bnortl", no_argument, &rtld, 0},
248 {"bnortllib", no_argument, &rtld, 0},
249 {"bS", required_argument, NULL, OPTION_MAXSTACK},
250 {"bso", no_argument, NULL, OPTION_AUTOIMP},
251 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
252 {"btextro", no_argument, &textro, 1},
253 {"b32", no_argument, NULL, OPTION_32},
254 {"b64", no_argument, NULL, OPTION_64},
255 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
256 {"unix", no_argument, NULL, OPTION_UNIX},
257 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
258 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
259 {NULL, no_argument, NULL, 0}
262 /* Options supported by the AIX linker which we do not support: -f,
263 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
264 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
265 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
266 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
267 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
268 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
271 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
272 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
273 *longopts = xrealloc (*longopts,
274 nl * sizeof (struct option) + sizeof (xtra_long));
275 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
279 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
283 /* If the current option starts with -b, change the first : to an =.
284 The AIX linker uses : to separate the option from the argument;
285 changing it to = lets us treat it as a getopt option. */
290 if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
294 for (s = argv[indx]; *s != '\0'; s++)
307 gld${EMULATION_NAME}_handle_option (int optc)
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), NULL);
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);
351 lang_section_start (".text", exp_intop (val), NULL);
357 case OPTION_INITFINI:
360 * The aix linker init fini has the format :
362 * -binitfini:[ Initial][:Termination][:Priority]
364 * it allows the Termination and Priority to be optional.
366 * Since we support only one init/fini pair, we ignore the Priority.
368 * Define the special symbol __rtinit.
370 * strtok does not correctly handle the case of -binitfini::fini: so
376 while (*t && ':' != *t)
382 link_info.init_function = i;
385 while (*t && ':' != *t)
390 link_info.fini_function = f;
395 link_info.static_link = FALSE;
399 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
400 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
404 link_info.unresolved_syms_in_objects = RM_IGNORE;
405 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
409 auto_export_flags |= XCOFF_EXPALL;
410 explicit_auto_export_flags |= XCOFF_EXPALL;
414 auto_export_flags |= XCOFF_EXPFULL;
415 explicit_auto_export_flags |= XCOFF_EXPFULL;
419 gld${EMULATION_NAME}_read_file (optarg, FALSE);
425 struct filelist **flpp;
427 n = (struct filelist *) xmalloc (sizeof (struct filelist));
430 flpp = &import_files;
431 while (*flpp != NULL)
432 flpp = &(*flpp)->next;
438 config.map_filename = optarg;
442 val = bfd_scan_vma (optarg, &end, 0);
444 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
449 case OPTION_MAXSTACK:
450 val = bfd_scan_vma (optarg, &end, 0);
452 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
461 link_info.shared = TRUE;
464 if (*optarg == '\0' || optarg[1] == '\0')
465 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
467 modtype = (*optarg << 8) | optarg[1];
470 case OPTION_NOAUTOIMP:
471 link_info.static_link = TRUE;
474 case OPTION_NOEXPALL:
475 auto_export_flags &= ~XCOFF_EXPALL;
476 explicit_auto_export_flags |= XCOFF_EXPALL;
479 case OPTION_NOEXPFULL:
480 auto_export_flags &= ~XCOFF_EXPFULL;
481 explicit_auto_export_flags |= XCOFF_EXPFULL;
484 case OPTION_NOSTRCMPCT:
485 link_info.traditional_format = TRUE;
489 /* This sets the page that the .data section is supposed to
490 start on. The offset within the page should still be the
491 offset within the file, so we need to build an appropriate
493 val = bfd_scan_vma (optarg, &end, 0);
495 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
503 exp_nameop (NAME, "."),
506 exp_binop ('+', t, exp_intop (31)),
507 exp_intop (~(bfd_vma) 31));
508 lang_section_start (".data", t, NULL);
513 /* This set the page that the .text section is supposed to start
514 on. The offset within the page should still be the offset
516 val = bfd_scan_vma (optarg, &end, 0);
518 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
525 exp_nameop (SIZEOF_HEADERS, NULL));
527 exp_binop ('+', t, exp_intop (31)),
528 exp_intop (~(bfd_vma) 31));
529 lang_section_start (".text", t, NULL);
533 case OPTION_STRCMPCT:
534 link_info.traditional_format = FALSE;
544 symbol_mode_mask = 0x0d;
550 symbol_mode_mask = 0x0e;
554 command_line_blibpath = optarg;
557 case OPTION_NOLIBPATH:
558 command_line_blibpath = NULL;
566 /* This is called when an input file can not be recognized as a BFD
567 object or an archive. If the file starts with #!, we must treat it
568 as an import file. This is for AIX compatibility. */
571 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry)
576 e = fopen (entry->filename, FOPEN_RT);
582 if (getc (e) == '#' && getc (e) == '!')
585 struct filelist **flpp;
587 n = (struct filelist *) xmalloc (sizeof (struct filelist));
589 n->name = entry->filename;
590 flpp = &import_files;
591 while (*flpp != NULL)
592 flpp = &(*flpp)->next;
596 entry->loaded = TRUE;
604 /* This is called after the input files have been opened. */
607 gld${EMULATION_NAME}_after_open (void)
612 after_open_default ();
614 /* Call ldctor_build_sets, after pretending that this is a
615 relocatable link. We do this because AIX requires relocation
616 entries for all references to symbols, even in a final
617 executable. Of course, we only want to do this if we are
618 producing an XCOFF output file. */
619 r = link_info.relocatable;
620 if (strstr (bfd_get_target (link_info.output_bfd), "xcoff") != NULL)
621 link_info.relocatable = TRUE;
622 ldctor_build_sets ();
623 link_info.relocatable = r;
625 /* For each set, record the size, so that the XCOFF backend can
626 output the correct csect length. */
627 for (p = sets; p != (struct set_info *) NULL; p = p->next)
631 /* If the symbol is defined, we may have been invoked from
632 collect, and the sets may already have been built, so we do
634 if (p->h->type == bfd_link_hash_defined
635 || p->h->type == bfd_link_hash_defweak)
638 if (p->reloc != BFD_RELOC_CTOR)
640 /* Handle this if we need to. */
644 size = (p->count + 2) * 4;
645 if (!bfd_xcoff_link_record_set (link_info.output_bfd, &link_info,
647 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
651 /* This is called after the sections have been attached to output
652 sections, but before any sizes or addresses have been set. */
655 gld${EMULATION_NAME}_before_allocation (void)
658 struct export_symbol_list *el;
660 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
661 static const char *const must_keep_sections[] = {
666 unsigned int i, flags;
668 /* Handle the import and export files, if any. */
669 for (fl = import_files; fl != NULL; fl = fl->next)
670 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
671 for (el = export_symbols; el != NULL; el = el->next)
673 struct bfd_link_hash_entry *h;
675 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
677 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
678 if (!bfd_xcoff_export_symbol (link_info.output_bfd, &link_info, h))
679 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
682 /* Track down all relocations called for by the linker script (these
683 are typically constructor/destructor entries created by
684 CONSTRUCTORS) and let the backend know it will need to create
685 .loader relocs for them. */
686 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
688 /* Precedence of LIBPATH
689 -blibpath: native support always first
690 -rpath: gnu extension
691 -L build from command line -L's */
692 if (command_line_blibpath != NULL)
693 libpath = command_line_blibpath;
694 else if (command_line.rpath != NULL)
695 libpath = command_line.rpath;
696 else if (search_head == NULL)
697 libpath = (char *) "";
701 search_dirs_type *search;
703 /* PR ld/4023: Strip sysroot prefix from any paths
704 being inserted into the output binary's DT_RPATH. */
705 if (ld_sysroot != NULL
706 && * ld_sysroot != 0)
708 const char * name = search_head->name;
709 size_t ld_sysroot_len = strlen (ld_sysroot);
711 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
712 name += ld_sysroot_len;
715 libpath = xmalloc (len + 1);
716 strcpy (libpath, name);
718 for (search = search_head->next; search != NULL; search = search->next)
723 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
724 name += ld_sysroot_len;
726 nlen = strlen (name);
727 libpath = xrealloc (libpath, len + nlen + 2);
729 strcpy (libpath + len + 1, name);
735 len = strlen (search_head->name);
736 libpath = xmalloc (len + 1);
737 strcpy (libpath, search_head->name);
739 for (search = search_head->next; search != NULL; search = search->next)
743 nlen = strlen (search->name);
744 libpath = xrealloc (libpath, len + nlen + 2);
746 strcpy (libpath + len + 1, search->name);
752 /* Default to -bexpfull for SVR4-like semantics. */
753 flags = (unix_ld ? XCOFF_EXPFULL : 0);
754 flags &= ~explicit_auto_export_flags;
755 flags |= auto_export_flags;
757 /* Let the XCOFF backend set up the .loader section. */
758 if (!bfd_xcoff_size_dynamic_sections
759 (link_info.output_bfd, &link_info, libpath, entry_symbol.name, file_align,
760 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
761 modtype, textro ? TRUE : FALSE, flags, special_sections,
762 rtld ? TRUE : FALSE))
763 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
765 /* Look through the special sections, and put them in the right
766 place in the link ordering. This is especially magic. */
767 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
770 lang_output_section_statement_type *os;
771 lang_statement_union_type **pls;
772 lang_input_section_type *is;
776 sec = special_sections[i];
780 /* Remove this section from the list of the output section.
781 This assumes we know what the script looks like. */
783 os = lang_output_section_find (sec->output_section->name);
785 einfo ("%P%F: can't find output section %s\n",
786 sec->output_section->name);
788 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
790 if ((*pls)->header.type == lang_input_section_enum
791 && (*pls)->input_section.section == sec)
793 is = (lang_input_section_type *) * pls;
794 *pls = (*pls)->header.next;
798 if ((*pls)->header.type == lang_wild_statement_enum)
800 lang_statement_union_type **pwls;
802 for (pwls = &(*pls)->wild_statement.children.head;
803 *pwls != NULL; pwls = &(*pwls)->header.next)
806 if ((*pwls)->header.type == lang_input_section_enum
807 && (*pwls)->input_section.section == sec)
809 is = (lang_input_section_type *) * pwls;
810 *pwls = (*pwls)->header.next;
822 einfo ("%P%F: can't find %s in output section\n",
823 bfd_get_section_name (sec->owner, sec));
826 /* Now figure out where the section should go. */
830 default: /* to avoid warnings */
831 case XCOFF_SPECIAL_SECTION_TEXT:
837 case XCOFF_SPECIAL_SECTION_ETEXT:
843 case XCOFF_SPECIAL_SECTION_DATA:
849 case XCOFF_SPECIAL_SECTION_EDATA:
855 case XCOFF_SPECIAL_SECTION_END:
856 case XCOFF_SPECIAL_SECTION_END2:
863 os = lang_output_section_find (oname);
867 is->header.next = os->children.head;
868 os->children.head = (lang_statement_union_type *) is;
872 is->header.next = NULL;
873 lang_statement_append (&os->children,
874 (lang_statement_union_type *) is,
879 /* Executables and shared objects must always have .text, .data
880 and .bss output sections, so that the header can refer to them.
881 The kernel refuses to load objects that have missing sections. */
882 if (!link_info.relocatable)
883 for (i = 0; i < ARRAY_SIZE (must_keep_sections); i++)
887 sec = bfd_get_section_by_name (link_info.output_bfd,
888 must_keep_sections[i]);
890 einfo ("%P: can't find required output section %s\n", must_keep_sections[i]);
892 sec->flags |= SEC_KEEP;
895 before_allocation_default ();
899 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
902 static char *from_outside;
903 static char *from_inside;
904 static char *argv_to_target[][2] = {
905 {NULL, "${OUTPUT_FORMAT}"},
906 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
907 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
912 from_outside = getenv (TARGET_ENVIRON);
913 if (from_outside != (char *) NULL)
916 /* Set to default. */
917 from_inside = argv_to_target[0][1];
918 for (i = 1; i < argc; i++)
920 for (j = 1; j < jmax; j++)
922 if (0 == strcmp (argv[i], argv_to_target[j][0]))
923 from_inside = argv_to_target[j][1];
934 change_symbol_mode (char *input)
936 char *symbol_mode_string[] = {
947 for (bit = 0;; bit++)
949 string = symbol_mode_string[bit];
953 if (0 == strcmp (input, string))
955 symbol_mode = (1 << bit);
959 /* should not be here */
966 -1 : error, try something else */
968 is_syscall (char *input, unsigned int *flag)
974 char *syscall_string;
977 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
978 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
979 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
980 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
981 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
982 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
983 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
984 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
990 for (bit = 0;; bit++)
992 string = s[bit].syscall_string;
996 if (0 == strcmp (input, string))
998 if (1 << bit & syscall_mask)
1000 *flag = s[bit].flag;
1009 /* should not be here */
1013 /* Read an import or export file. For an import file, this is called
1014 by the before_allocation emulation routine. For an export file,
1015 this is called by the handle_option emulation routine. */
1018 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
1025 const char *imppath;
1026 const char *impfile;
1027 const char *impmember;
1029 o = (struct obstack *) xmalloc (sizeof (struct obstack));
1030 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
1032 f = fopen (filename, FOPEN_RT);
1035 bfd_set_error (bfd_error_system_call);
1036 einfo ("%F%s: %E\n", filename);
1047 /* Default to 32 and 64 bit mode
1048 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
1049 are not repeated, assume 64 bit routines also want to use them.
1050 See the routine change_symbol_mode for more information. */
1054 while ((c = getc (f)) != EOF)
1058 unsigned int syscall_flag = 0;
1060 struct bfd_link_hash_entry *h;
1064 obstack_1grow (o, c);
1068 obstack_1grow (o, '\0');
1071 s = (char *) obstack_base (o);
1072 while (ISSPACE (*s))
1076 || change_symbol_mode (s)
1077 || (*s == '#' && s[1] == ' ')
1078 || (!import && *s == '#' && s[1] == '!'))
1080 obstack_free (o, obstack_base (o));
1084 if (*s == '#' && s[1] == '!')
1087 while (ISSPACE (*s))
1094 obstack_free (o, obstack_base (o));
1097 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1104 (void) obstack_finish (o);
1107 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1111 if (!bfd_xcoff_split_import_path (link_info.output_bfd,
1112 start, &imppath, &impfile))
1113 einfo ("%F%P: Could not parse import path: %E\n");
1114 while (ISSPACE (cs))
1123 einfo ("%s:%d: warning: syntax error in import file\n",
1130 while (*s != ')' && *s != '\0')
1135 einfo ("%s:%d: warning: syntax error in import file\n",
1143 if (symbol_mode & symbol_mode_mask)
1145 /* This is a symbol to be imported or exported. */
1148 address = (bfd_vma) -1;
1150 while (!ISSPACE (*s) && *s != '\0')
1158 while (ISSPACE (*s))
1162 while (!ISSPACE (*se) && *se != '\0')
1167 while (ISSPACE (*se))
1170 einfo ("%s%d: warning: syntax error in import/export file\n",
1179 status = is_syscall (s, &syscall_flag);
1183 /* not a system call, check for address */
1184 address = bfd_scan_vma (s, &end, 0);
1187 einfo ("%s:%d: warning: syntax error in import/export file\n",
1197 struct export_symbol_list *n;
1199 ldlang_add_undef (symname, TRUE);
1200 n = ((struct export_symbol_list *)
1201 xmalloc (sizeof (struct export_symbol_list)));
1202 n->next = export_symbols;
1203 n->name = xstrdup (symname);
1208 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1210 if (h == NULL || h->type == bfd_link_hash_new)
1212 /* We can just ignore attempts to import an unreferenced
1217 if (!bfd_xcoff_import_symbol (link_info.output_bfd,
1219 address, imppath, impfile,
1220 impmember, syscall_flag))
1221 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1222 filename, lineno, symname);
1226 obstack_free (o, obstack_base (o));
1229 if (obstack_object_size (o) > 0)
1231 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1233 obstack_free (o, obstack_base (o));
1238 obstack_free (o, NULL);
1243 /* This routine saves us from worrying about declaring free. */
1246 gld${EMULATION_NAME}_free (void *p)
1251 /* This is called by the before_allocation routine via
1252 lang_for_each_statement. It looks for relocations and assignments
1256 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1258 if (s->header.type == lang_reloc_statement_enum)
1260 lang_reloc_statement_type *rs;
1262 rs = &s->reloc_statement;
1263 if (rs->name == NULL)
1264 einfo ("%F%P: only relocations against symbols are permitted\n");
1265 if (!bfd_xcoff_link_count_reloc (link_info.output_bfd, &link_info,
1267 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1270 if (s->header.type == lang_assignment_statement_enum)
1271 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1274 /* Look through an expression for an assignment statement. */
1277 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1279 struct bfd_link_hash_entry *h;
1281 switch (exp->type.node_class)
1284 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1285 FALSE, FALSE, FALSE);
1290 if (strcmp (exp->assign.dst, ".") != 0)
1292 if (!bfd_xcoff_record_link_assignment (link_info.output_bfd,
1295 einfo ("%P%F: failed to record assignment to %s: %E\n",
1298 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1302 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1303 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1307 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1308 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1309 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1313 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1322 gld${EMULATION_NAME}_get_script (int *isfile)
1325 if test -n "$COMPILE_IN"
1327 # Scripts compiled in.
1329 # sed commands to quote an ld script as a C string.
1330 sc="-f ${srcdir}/emultempl/ostring.sed"
1336 if (link_info.relocatable && config.build_constructors)
1339 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1340 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1341 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1342 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1343 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1344 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1345 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1346 echo ' ; else return' >> e${EMULATION_NAME}.c
1347 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1348 echo '; }' >> e${EMULATION_NAME}.c
1351 # Scripts read from the filesystem.
1357 if (link_info.relocatable && config.build_constructors)
1358 return "ldscripts/${EMULATION_NAME}.xu";
1359 else if (link_info.relocatable)
1360 return "ldscripts/${EMULATION_NAME}.xr";
1361 else if (!config.text_read_only)
1362 return "ldscripts/${EMULATION_NAME}.xbn";
1363 else if (!config.magic_demand_paged)
1364 return "ldscripts/${EMULATION_NAME}.xn";
1366 return "ldscripts/${EMULATION_NAME}.x";
1375 gld${EMULATION_NAME}_create_output_section_statements (void)
1378 if ((bfd_get_flavour (link_info.output_bfd) == bfd_target_xcoff_flavour)
1379 && (link_info.init_function != NULL
1380 || link_info.fini_function != NULL
1383 initfini_file = lang_add_input_file ("initfini",
1384 lang_input_file_is_file_enum,
1387 initfini_file->the_bfd = bfd_create ("initfini", link_info.output_bfd);
1388 if (initfini_file->the_bfd == NULL
1389 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1390 bfd_get_arch (link_info.output_bfd),
1391 bfd_get_mach (link_info.output_bfd)))
1393 einfo ("%X%P: can not create BFD %E\n");
1397 /* Call backend to fill in the rest */
1398 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1399 link_info.init_function,
1400 link_info.fini_function,
1403 einfo ("%X%P: can not create BFD %E\n");
1407 /* __rtld defined in /lib/librtl.a */
1409 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1414 gld${EMULATION_NAME}_set_output_arch (void)
1416 bfd_set_arch_mach (link_info.output_bfd,
1417 bfd_xcoff_architecture (link_info.output_bfd),
1418 bfd_xcoff_machine (link_info.output_bfd));
1420 ldfile_output_architecture = bfd_get_arch (link_info.output_bfd);
1421 ldfile_output_machine = bfd_get_mach (link_info.output_bfd);
1422 ldfile_output_machine_name = bfd_printable_name (link_info.output_bfd);
1426 gld${EMULATION_NAME}_open_dynamic_archive (const char *arch,
1427 search_dirs_type *search,
1428 lang_input_statement_type *entry)
1432 if (!entry->maybe_archive)
1435 path = concat (search->name, "/lib", entry->filename, arch, ".a", NULL);
1436 if (!ldfile_try_open_bfd (path, entry))
1441 /* Don't include the searched directory in the import path. */
1442 bfd_xcoff_set_archive_import_path (&link_info, entry->the_bfd,
1443 path + strlen (search->name) + 1);
1444 entry->filename = path;
1448 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1449 gld${EMULATION_NAME}_before_parse,
1452 after_parse_default,
1453 gld${EMULATION_NAME}_after_open,
1454 after_allocation_default,
1455 gld${EMULATION_NAME}_set_output_arch,
1456 gld${EMULATION_NAME}_choose_target,
1457 gld${EMULATION_NAME}_before_allocation,
1458 gld${EMULATION_NAME}_get_script,
1459 "${EMULATION_NAME}",
1462 gld${EMULATION_NAME}_create_output_section_statements,
1463 gld${EMULATION_NAME}_open_dynamic_archive,
1464 0, /* place_orphan */
1465 0, /* set_symbols */
1466 gld${EMULATION_NAME}_parse_args,
1467 gld${EMULATION_NAME}_add_options,
1468 gld${EMULATION_NAME}_handle_option,
1469 gld${EMULATION_NAME}_unrecognized_file,
1470 NULL, /* list_options */
1471 NULL, /* recognized_file */
1472 NULL, /* find potential_libraries */
1473 NULL /* new_vers_pattern */