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 (C) 1991-2019 Free Software Foundation, Inc.
13 Written by Steve Chamberlain <sac@cygnus.com>
14 AIX support by Ian Lance Taylor <ian@cygnus.com>
15 AIX 64 bit support by Tom Rix <trix@redhat.com>
17 This file is part of the GNU Binutils.
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 3 of the License, or
22 (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
32 MA 02110-1301, USA. */
34 #define TARGET_IS_${EMULATION_NAME}
38 #include "libiberty.h"
39 #include "safe-ctype.h"
54 #include "coff/internal.h"
55 #include "coff/xcoff.h"
59 static void gld${EMULATION_NAME}_read_file (const char *, bfd_boolean);
60 static void gld${EMULATION_NAME}_free (void *);
61 static void gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *);
62 static void gld${EMULATION_NAME}_find_exp_assignment (etree_type *);
65 /* The file alignment required for each section. */
66 static unsigned long file_align;
68 /* The maximum size the stack is permitted to grow. This is stored in
70 static unsigned long maxstack;
72 /* The maximum data size. This is stored in the a.out header. */
73 static unsigned long maxdata;
75 /* Whether to perform garbage collection. */
78 /* The module type to use. */
79 static unsigned short modtype = ('1' << 8) | 'L';
81 /* Whether the .text section must be read-only (i.e., no relocs
85 /* A mask of XCOFF_EXPALL and XCOFF_EXPFULL flags, as set by their
86 associated -b and -bno options. */
87 static unsigned int auto_export_flags;
89 /* A mask of auto_export_flags bits that were explicitly set on the
91 static unsigned int explicit_auto_export_flags;
93 /* Whether to implement Unix like linker semantics. */
96 /* Structure used to hold import file list. */
100 struct filelist *next;
104 /* List of import files. */
105 static struct filelist *import_files;
107 /* List of export symbols read from the export files. */
109 struct export_symbol_list
111 struct export_symbol_list *next;
115 static struct export_symbol_list *export_symbols;
117 /* Maintains the 32 or 64 bit mode state of import file */
118 static unsigned int symbol_mode = 0x04;
120 /* Which symbol modes are valid */
121 static unsigned int symbol_mode_mask = 0x0d;
123 /* Whether this is a 64 bit link */
124 static int is_64bit = 0;
126 /* Which syscalls from import file are valid */
127 static unsigned int syscall_mask = 0x77;
129 /* fake file for -binitfini support */
130 static lang_input_statement_type *initfini_file;
132 /* Whether to do run time linking
133 -brtl enables, -bnortl and -bnortllib disable. */
136 /* Explicit command line library path, -blibpath */
137 static char *command_line_blibpath = NULL;
139 /* This routine is called before anything else is done. */
142 gld${EMULATION_NAME}_before_parse (void)
144 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
146 input_flags.dynamic = TRUE;
147 config.has_shared = TRUE;
149 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
150 Override them here so we can use the link_info.init_function as a
151 state flag that lets the backend know that -binitfini has been done. */
153 link_info.init_function = NULL;
154 link_info.fini_function = NULL;
157 /* Handle AIX specific options. */
189 gld${EMULATION_NAME}_add_options
190 (int ns, char **shortopts, int nl, struct option **longopts,
191 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
193 static const char xtra_short[] = "D:H:KT:z";
194 static const struct option xtra_long[] = {
195 /* -binitfini has special handling in the linker backend. The native linker
196 uses the arguemnts to generate a table of init and fini functions for
197 the executable. The important use for this option is to support aix 4.2+
198 c++ constructors and destructors. This is tied into gcc via collect2.c.
200 The function table is accessed by the runtime linker/loader by checking if
201 the first symbol in the loader symbol table is __rtinit. The gnu linker
202 generates this symbol and makes it the first loader symbol. */
204 {"basis", no_argument, NULL, OPTION_IGNORE},
205 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
206 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
207 {"bcrld", no_argument, NULL, OPTION_IGNORE},
208 {"bcror31", no_argument, NULL, OPTION_IGNORE},
209 {"bD", required_argument, NULL, OPTION_MAXDATA},
210 {"bE", required_argument, NULL, OPTION_EXPORT},
211 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
212 {"berok", no_argument, NULL, OPTION_EROK},
213 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
214 {"bexpall", no_argument, NULL, OPTION_EXPALL},
215 {"bexpfull", no_argument, NULL, OPTION_EXPFULL},
216 {"bexport", required_argument, NULL, OPTION_EXPORT},
217 {"bbigtoc", no_argument, NULL, OPTION_IGNORE},
218 {"bf", no_argument, NULL, OPTION_ERNOTOK},
219 {"bgc", no_argument, &gc, 1},
220 {"bh", required_argument, NULL, OPTION_IGNORE},
221 {"bhalt", required_argument, NULL, OPTION_IGNORE},
222 {"bI", required_argument, NULL, OPTION_IMPORT},
223 {"bimport", required_argument, NULL, OPTION_IMPORT},
224 {"binitfini", required_argument, NULL, OPTION_INITFINI},
225 {"bl", required_argument, NULL, OPTION_LOADMAP},
226 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
227 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
228 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
229 {"bM", required_argument, NULL, OPTION_MODTYPE},
230 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
231 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
232 {"bnoexpall", no_argument, NULL, OPTION_NOEXPALL},
233 {"bnoexpfull", no_argument, NULL, OPTION_NOEXPFULL},
234 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
235 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
236 {"bnogc", no_argument, &gc, 0},
237 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
238 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
239 {"bnotextro", no_argument, &textro, 0},
240 {"bnro", no_argument, &textro, 0},
241 {"bpD", required_argument, NULL, OPTION_PD},
242 {"bpT", required_argument, NULL, OPTION_PT},
243 {"bro", no_argument, &textro, 1},
244 {"brtl", no_argument, &rtld, 1},
245 {"bnortl", no_argument, &rtld, 0},
246 {"bnortllib", no_argument, &rtld, 0},
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 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
256 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
257 {NULL, no_argument, NULL, 0}
260 /* Options supported by the AIX linker which we do not support:
261 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
262 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
263 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
264 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
265 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
266 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
269 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
270 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
271 *longopts = xrealloc (*longopts,
272 nl * sizeof (struct option) + sizeof (xtra_long));
273 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
277 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
281 /* If the current option starts with -b, change the first : to an =.
282 The AIX linker uses : to separate the option from the argument;
283 changing it to = lets us treat it as a getopt option. */
288 if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
292 for (s = argv[indx]; *s != '\0'; s++)
304 /* Helper for option '-f', which specify a list of input files.
305 Contrary to the native linker, we don't support shell patterns
306 (simply because glob isn't always available). */
309 read_file_list (const char *filename)
312 /* An upper bound on the number of characters in the file. */
314 /* File in memory. */
320 f = fopen (filename, FOPEN_RT);
323 einfo (_("%F%P: cannot open %s\n"), filename);
326 if (fseek (f, 0L, SEEK_END) == -1)
331 if (fseek (f, 0L, SEEK_SET) == -1)
334 buffer = (char *) xmalloc (pos + 1);
335 len = fread (buffer, sizeof (char), pos, f);
336 if (len != (size_t) pos && ferror (f))
338 /* Add a NUL terminator. */
346 /* Skip empty lines. */
347 while (*b == '\n' || *b == '\r')
350 /* Stop if end of buffer. */
351 if (b == buffer + len)
354 /* Eat any byte until end of line. */
355 for (e = b; *e != '\0'; e++)
356 if (*e == '\n' || *e == '\r')
359 /* Replace end of line by nul. */
364 lang_add_input_file (b, lang_input_file_is_search_file_enum, NULL);
370 einfo (_("%F%P: cannot read %s\n"), optarg);
375 gld${EMULATION_NAME}_handle_option (int optc)
386 /* Long option which just sets a flag. */
390 /* This overrides --auxiliary. This option specifies a file containing
391 a list of input files. */
392 read_file_list (optarg);
396 val = bfd_scan_vma (optarg, &end, 0);
398 einfo (_("%P: warning: ignoring invalid -D number %s\n"), optarg);
400 lang_section_start (".data", exp_intop (val), NULL);
404 val = bfd_scan_vma (optarg, &end, 0);
405 if (*end != '\0' || (val & (val - 1)) != 0)
406 einfo (_("%P: warning: ignoring invalid -H number %s\n"), optarg);
413 /* FIXME: This should use the page size for the target system. */
418 /* On AIX this is the same as GNU ld -Ttext. When we see -T
419 number, we assume the AIX option is intended. Otherwise, we
420 assume the usual GNU ld -T option is intended. We can't just
421 ignore the AIX option, because gcc passes it to the linker. */
422 val = bfd_scan_vma (optarg, &end, 0);
425 lang_section_start (".text", exp_intop (val), NULL);
431 case OPTION_INITFINI:
434 * The aix linker init fini has the format :
436 * -binitfini:[ Initial][:Termination][:Priority]
438 * it allows the Termination and Priority to be optional.
440 * Since we support only one init/fini pair, we ignore the Priority.
442 * Define the special symbol __rtinit.
444 * strtok does not correctly handle the case of -binitfini::fini: so
450 while (*t && ':' != *t)
456 link_info.init_function = i;
459 while (*t && ':' != *t)
464 link_info.fini_function = f;
469 link_info.static_link = FALSE;
473 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
474 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
478 link_info.unresolved_syms_in_objects = RM_IGNORE;
479 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
483 auto_export_flags |= XCOFF_EXPALL;
484 explicit_auto_export_flags |= XCOFF_EXPALL;
488 auto_export_flags |= XCOFF_EXPFULL;
489 explicit_auto_export_flags |= XCOFF_EXPFULL;
493 gld${EMULATION_NAME}_read_file (optarg, FALSE);
499 struct filelist **flpp;
501 n = (struct filelist *) xmalloc (sizeof (struct filelist));
504 flpp = &import_files;
505 while (*flpp != NULL)
506 flpp = &(*flpp)->next;
512 config.map_filename = optarg;
516 val = bfd_scan_vma (optarg, &end, 0);
518 einfo (_("%P: warning: ignoring invalid -bmaxdata number %s\n"),
524 case OPTION_MAXSTACK:
525 val = bfd_scan_vma (optarg, &end, 0);
527 einfo (_("%P: warning: ignoring invalid -bmaxstack number %s\n"),
536 link_info.type = type_dll;
539 if (*optarg == '\0' || optarg[1] == '\0')
540 einfo (_("%P: warning: ignoring invalid module type %s\n"), optarg);
542 modtype = (*optarg << 8) | optarg[1];
545 case OPTION_NOAUTOIMP:
546 link_info.static_link = TRUE;
549 case OPTION_NOEXPALL:
550 auto_export_flags &= ~XCOFF_EXPALL;
551 explicit_auto_export_flags |= XCOFF_EXPALL;
554 case OPTION_NOEXPFULL:
555 auto_export_flags &= ~XCOFF_EXPFULL;
556 explicit_auto_export_flags |= XCOFF_EXPFULL;
559 case OPTION_NOSTRCMPCT:
560 link_info.traditional_format = TRUE;
564 /* This sets the page that the .data section is supposed to
565 start on. The offset within the page should still be the
566 offset within the file, so we need to build an appropriate
568 val = bfd_scan_vma (optarg, &end, 0);
570 einfo (_("%P: warning: ignoring invalid -pD number %s\n"), optarg);
578 exp_nameop (NAME, "."),
581 exp_binop ('+', t, exp_intop (31)),
582 exp_intop (~(bfd_vma) 31));
583 lang_section_start (".data", t, NULL);
588 /* This set the page that the .text section is supposed to start
589 on. The offset within the page should still be the offset
591 val = bfd_scan_vma (optarg, &end, 0);
593 einfo (_("%P: warning: ignoring invalid -pT number %s\n"), optarg);
600 exp_nameop (SIZEOF_HEADERS, NULL));
602 exp_binop ('+', t, exp_intop (31)),
603 exp_intop (~(bfd_vma) 31));
604 lang_section_start (".text", t, NULL);
608 case OPTION_STRCMPCT:
609 link_info.traditional_format = FALSE;
619 symbol_mode_mask = 0x0d;
625 symbol_mode_mask = 0x0e;
629 command_line_blibpath = optarg;
632 case OPTION_NOLIBPATH:
633 command_line_blibpath = NULL;
641 /* This is called when an input file can not be recognized as a BFD
642 object or an archive. If the file starts with #!, we must treat it
643 as an import file. This is for AIX compatibility. */
646 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry)
651 e = fopen (entry->filename, FOPEN_RT);
657 if (getc (e) == '#' && getc (e) == '!')
660 struct filelist **flpp;
662 n = (struct filelist *) xmalloc (sizeof (struct filelist));
664 n->name = entry->filename;
665 flpp = &import_files;
666 while (*flpp != NULL)
667 flpp = &(*flpp)->next;
671 entry->flags.loaded = TRUE;
679 /* This is called after the input files have been opened. */
682 gld${EMULATION_NAME}_after_open (void)
687 after_open_default ();
689 /* Call ldctor_build_sets, after pretending that this is a
690 relocatable link. We do this because AIX requires relocation
691 entries for all references to symbols, even in a final
692 executable. Of course, we only want to do this if we are
693 producing an XCOFF output file. */
695 if (strstr (bfd_get_target (link_info.output_bfd), "xcoff") != NULL)
696 link_info.type = type_relocatable;
697 ldctor_build_sets ();
700 /* For each set, record the size, so that the XCOFF backend can
701 output the correct csect length. */
702 for (p = sets; p != (struct set_info *) NULL; p = p->next)
706 /* If the symbol is defined, we may have been invoked from
707 collect, and the sets may already have been built, so we do
709 if (p->h->type == bfd_link_hash_defined
710 || p->h->type == bfd_link_hash_defweak)
713 if (p->reloc != BFD_RELOC_CTOR)
715 /* Handle this if we need to. */
719 size = (p->count + 2) * 4;
720 if (!bfd_xcoff_link_record_set (link_info.output_bfd, &link_info,
722 einfo (_("%F%P: bfd_xcoff_link_record_set failed: %E\n"));
726 /* This is called after the sections have been attached to output
727 sections, but before any sizes or addresses have been set. */
730 gld${EMULATION_NAME}_before_allocation (void)
733 struct export_symbol_list *el;
735 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
736 static const char *const must_keep_sections[] = {
741 unsigned int i, flags;
743 /* Handle the import and export files, if any. */
744 for (fl = import_files; fl != NULL; fl = fl->next)
745 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
746 for (el = export_symbols; el != NULL; el = el->next)
748 struct bfd_link_hash_entry *h;
750 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
752 einfo (_("%F%P: bfd_link_hash_lookup of export symbol failed: %E\n"));
753 if (!bfd_xcoff_export_symbol (link_info.output_bfd, &link_info, h))
754 einfo (_("%F%P: bfd_xcoff_export_symbol failed: %E\n"));
757 /* Track down all relocations called for by the linker script (these
758 are typically constructor/destructor entries created by
759 CONSTRUCTORS) and let the backend know it will need to create
760 .loader relocs for them. */
761 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
763 /* Precedence of LIBPATH
764 -blibpath: native support always first
765 -rpath: gnu extension
766 -L build from command line -L's */
767 if (command_line_blibpath != NULL)
768 libpath = command_line_blibpath;
769 else if (command_line.rpath != NULL)
770 libpath = command_line.rpath;
771 else if (search_head == NULL)
772 libpath = (char *) "";
776 search_dirs_type *search;
778 /* PR ld/4023: Strip sysroot prefix from any paths
779 being inserted into the output binary's DT_RPATH. */
780 if (ld_sysroot != NULL
781 && * ld_sysroot != 0)
783 const char * name = search_head->name;
784 size_t ld_sysroot_len = strlen (ld_sysroot);
786 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
787 name += ld_sysroot_len;
790 libpath = xmalloc (len + 1);
791 strcpy (libpath, name);
793 for (search = search_head->next; search != NULL; search = search->next)
798 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
799 name += ld_sysroot_len;
801 nlen = strlen (name);
802 libpath = xrealloc (libpath, len + nlen + 2);
804 strcpy (libpath + len + 1, name);
810 len = strlen (search_head->name);
811 libpath = xmalloc (len + 1);
812 strcpy (libpath, search_head->name);
814 for (search = search_head->next; search != NULL; search = search->next)
818 nlen = strlen (search->name);
819 libpath = xrealloc (libpath, len + nlen + 2);
821 strcpy (libpath + len + 1, search->name);
827 /* Default to -bexpfull for SVR4-like semantics. */
828 flags = (unix_ld ? XCOFF_EXPFULL : 0);
829 flags &= ~explicit_auto_export_flags;
830 flags |= auto_export_flags;
832 /* Let the XCOFF backend set up the .loader section. */
833 if (!bfd_xcoff_size_dynamic_sections
834 (link_info.output_bfd, &link_info, libpath, entry_symbol.name, file_align,
835 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
836 modtype, textro ? TRUE : FALSE, flags, special_sections,
837 rtld ? TRUE : FALSE))
838 einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
840 /* Look through the special sections, and put them in the right
841 place in the link ordering. This is especially magic. */
842 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
845 lang_output_section_statement_type *os;
846 lang_statement_union_type **pls;
847 lang_input_section_type *is;
851 sec = special_sections[i];
855 /* Remove this section from the list of the output section.
856 This assumes we know what the script looks like. */
858 os = lang_output_section_get (sec->output_section);
860 einfo (_("%F%P: can't find output section %s\n"),
861 sec->output_section->name);
863 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
865 if ((*pls)->header.type == lang_input_section_enum
866 && (*pls)->input_section.section == sec)
868 is = (lang_input_section_type *) * pls;
869 *pls = (*pls)->header.next;
873 if ((*pls)->header.type == lang_wild_statement_enum)
875 lang_statement_union_type **pwls;
877 for (pwls = &(*pls)->wild_statement.children.head;
878 *pwls != NULL; pwls = &(*pwls)->header.next)
881 if ((*pwls)->header.type == lang_input_section_enum
882 && (*pwls)->input_section.section == sec)
884 is = (lang_input_section_type *) * pwls;
885 *pwls = (*pwls)->header.next;
897 einfo (_("%F%P: can't find %s in output section\n"),
898 bfd_get_section_name (sec->owner, sec));
901 /* Now figure out where the section should go. */
905 default: /* to avoid warnings */
906 case XCOFF_SPECIAL_SECTION_TEXT:
912 case XCOFF_SPECIAL_SECTION_ETEXT:
918 case XCOFF_SPECIAL_SECTION_DATA:
924 case XCOFF_SPECIAL_SECTION_EDATA:
930 case XCOFF_SPECIAL_SECTION_END:
931 case XCOFF_SPECIAL_SECTION_END2:
938 os = lang_output_section_find (oname);
942 is->header.next = os->children.head;
943 os->children.head = (lang_statement_union_type *) is;
947 is->header.next = NULL;
948 lang_statement_append (&os->children,
949 (lang_statement_union_type *) is,
954 /* Executables and shared objects must always have .text, .data
955 and .bss output sections, so that the header can refer to them.
956 The kernel refuses to load objects that have missing sections. */
957 if (!bfd_link_relocatable (&link_info))
958 for (i = 0; i < ARRAY_SIZE (must_keep_sections); i++)
962 sec = bfd_get_section_by_name (link_info.output_bfd,
963 must_keep_sections[i]);
965 einfo (_("%P: can't find required output section %s\n"),
966 must_keep_sections[i]);
968 sec->flags |= SEC_KEEP;
971 before_allocation_default ();
975 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
978 static char *from_outside;
979 static char *from_inside;
980 static char *argv_to_target[][2] = {
981 {NULL, "${OUTPUT_FORMAT}"},
982 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
983 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
988 from_outside = getenv (TARGET_ENVIRON);
989 if (from_outside != (char *) NULL)
992 /* Set to default. */
993 from_inside = argv_to_target[0][1];
994 for (i = 1; i < argc; i++)
996 for (j = 1; j < jmax; j++)
998 if (0 == strcmp (argv[i], argv_to_target[j][0]))
999 from_inside = argv_to_target[j][1];
1010 change_symbol_mode (char *input)
1012 char *symbol_mode_string[] = {
1015 "# no32", /* 0x04 */
1016 "# no64", /* 0x08 */
1023 for (bit = 0;; bit++)
1025 string = symbol_mode_string[bit];
1029 if (0 == strcmp (input, string))
1031 symbol_mode = (1 << bit);
1035 /* should not be here */
1042 -1 : error, try something else */
1044 is_syscall (char *input, unsigned int *flag)
1050 char *syscall_string;
1053 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
1054 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
1055 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
1056 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
1057 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
1058 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
1059 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
1060 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
1066 for (bit = 0;; bit++)
1068 string = s[bit].syscall_string;
1072 if (0 == strcmp (input, string))
1074 if (1 << bit & syscall_mask)
1076 *flag = s[bit].flag;
1085 /* should not be here */
1089 /* Read an import or export file. For an import file, this is called
1090 by the before_allocation emulation routine. For an export file,
1091 this is called by the handle_option emulation routine. */
1094 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
1101 const char *imppath;
1102 const char *impfile;
1103 const char *impmember;
1105 o = (struct obstack *) xmalloc (sizeof (struct obstack));
1106 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
1108 f = fopen (filename, FOPEN_RT);
1111 bfd_set_error (bfd_error_system_call);
1112 einfo ("%F%P: %s: %E\n", filename);
1124 /* Default to 32 and 64 bit mode
1125 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
1126 are not repeated, assume 64 bit routines also want to use them.
1127 See the routine change_symbol_mode for more information. */
1131 while ((c = getc (f)) != EOF)
1135 unsigned int syscall_flag = 0;
1137 struct bfd_link_hash_entry *h;
1141 obstack_1grow (o, c);
1145 obstack_1grow (o, '\0');
1148 s = (char *) obstack_base (o);
1149 while (ISSPACE (*s))
1153 || change_symbol_mode (s)
1154 || (*s == '#' && s[1] == ' ')
1155 || (!import && *s == '#' && s[1] == '!'))
1157 obstack_free (o, obstack_base (o));
1161 if (*s == '#' && s[1] == '!')
1164 while (ISSPACE (*s))
1171 obstack_free (o, obstack_base (o));
1174 einfo (_("%F%P:%s:%d: #! ([member]) is not supported "
1175 "in import files\n"),
1182 (void) obstack_finish (o);
1185 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1189 if (!bfd_xcoff_split_import_path (link_info.output_bfd,
1190 start, &imppath, &impfile))
1191 einfo (_("%F%P: could not parse import path: %E\n"));
1192 while (ISSPACE (cs))
1201 einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
1208 while (*s != ')' && *s != '\0')
1213 einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
1221 if (symbol_mode & symbol_mode_mask)
1223 /* This is a symbol to be imported or exported. */
1226 address = (bfd_vma) -1;
1228 while (!ISSPACE (*s) && *s != '\0')
1236 while (ISSPACE (*s))
1240 while (!ISSPACE (*se) && *se != '\0')
1245 while (ISSPACE (*se))
1248 einfo (_("%P:%s%d: warning: syntax error in "
1249 "import/export file\n"),
1258 status = is_syscall (s, &syscall_flag);
1262 /* not a system call, check for address */
1263 address = bfd_scan_vma (s, &end, 0);
1266 einfo (_("%P:%s:%d: warning: syntax error in "
1267 "import/export file\n"),
1277 struct export_symbol_list *n;
1279 ldlang_add_undef (symname, TRUE);
1280 n = ((struct export_symbol_list *)
1281 xmalloc (sizeof (struct export_symbol_list)));
1282 n->next = export_symbols;
1283 n->name = xstrdup (symname);
1288 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1290 if (h == NULL || h->type == bfd_link_hash_new)
1292 /* We can just ignore attempts to import an unreferenced
1297 if (!bfd_xcoff_import_symbol (link_info.output_bfd,
1299 address, imppath, impfile,
1300 impmember, syscall_flag))
1301 einfo (_("%X%P:%s:%d: failed to import symbol %s: %E\n"),
1302 filename, lineno, symname);
1306 obstack_free (o, obstack_base (o));
1309 if (obstack_object_size (o) > 0)
1311 einfo (_("%P:%s:%d: warning: ignoring unterminated last line\n"),
1313 obstack_free (o, obstack_base (o));
1318 obstack_free (o, NULL);
1325 /* This routine saves us from worrying about declaring free. */
1328 gld${EMULATION_NAME}_free (void *p)
1333 /* This is called by the before_allocation routine via
1334 lang_for_each_statement. It looks for relocations and assignments
1338 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1340 if (s->header.type == lang_reloc_statement_enum)
1342 lang_reloc_statement_type *rs;
1344 rs = &s->reloc_statement;
1345 if (rs->name == NULL)
1346 einfo (_("%F%P: only relocations against symbols are permitted\n"));
1347 if (!bfd_xcoff_link_count_reloc (link_info.output_bfd, &link_info,
1349 einfo (_("%F%P: bfd_xcoff_link_count_reloc failed: %E\n"));
1352 if (s->header.type == lang_assignment_statement_enum)
1353 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1356 /* Look through an expression for an assignment statement. */
1359 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1361 struct bfd_link_hash_entry *h;
1363 switch (exp->type.node_class)
1366 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1367 FALSE, FALSE, FALSE);
1372 if (strcmp (exp->assign.dst, ".") != 0)
1374 if (!bfd_xcoff_record_link_assignment (link_info.output_bfd,
1377 einfo (_("%F%P: failed to record assignment to %s: %E\n"),
1380 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1384 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1385 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1389 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1390 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1391 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1395 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1404 gld${EMULATION_NAME}_get_script (int *isfile)
1407 if test x"$COMPILE_IN" = xyes
1409 # Scripts compiled in.
1411 # sed commands to quote an ld script as a C string.
1412 sc="-f ${srcdir}/emultempl/ostring.sed"
1418 if (bfd_link_relocatable (&link_info) && config.build_constructors)
1421 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1422 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
1423 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1424 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1425 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1426 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1427 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1428 echo ' ; else return' >> e${EMULATION_NAME}.c
1429 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1430 echo '; }' >> e${EMULATION_NAME}.c
1433 # Scripts read from the filesystem.
1439 if (bfd_link_relocatable (&link_info) && config.build_constructors)
1440 return "ldscripts/${EMULATION_NAME}.xu";
1441 else if (bfd_link_relocatable (&link_info))
1442 return "ldscripts/${EMULATION_NAME}.xr";
1443 else if (!config.text_read_only)
1444 return "ldscripts/${EMULATION_NAME}.xbn";
1445 else if (!config.magic_demand_paged)
1446 return "ldscripts/${EMULATION_NAME}.xn";
1448 return "ldscripts/${EMULATION_NAME}.x";
1457 gld${EMULATION_NAME}_create_output_section_statements (void)
1460 if ((bfd_get_flavour (link_info.output_bfd) == bfd_target_xcoff_flavour)
1461 && (link_info.init_function != NULL
1462 || link_info.fini_function != NULL
1465 initfini_file = lang_add_input_file ("initfini",
1466 lang_input_file_is_file_enum,
1469 initfini_file->the_bfd = bfd_create ("initfini", link_info.output_bfd);
1470 if (initfini_file->the_bfd == NULL
1471 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1472 bfd_get_arch (link_info.output_bfd),
1473 bfd_get_mach (link_info.output_bfd)))
1475 einfo (_("%F%P: can not create BFD: %E\n"));
1479 /* Call backend to fill in the rest */
1480 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1481 link_info.init_function,
1482 link_info.fini_function,
1485 einfo (_("%F%P: can not create BFD: %E\n"));
1489 /* __rtld defined in /lib/librtl.a */
1491 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1496 gld${EMULATION_NAME}_set_output_arch (void)
1498 bfd_set_arch_mach (link_info.output_bfd,
1499 bfd_xcoff_architecture (link_info.output_bfd),
1500 bfd_xcoff_machine (link_info.output_bfd));
1502 ldfile_output_architecture = bfd_get_arch (link_info.output_bfd);
1503 ldfile_output_machine = bfd_get_mach (link_info.output_bfd);
1504 ldfile_output_machine_name = bfd_printable_name (link_info.output_bfd);
1508 gld${EMULATION_NAME}_open_dynamic_archive (const char *arch,
1509 search_dirs_type *search,
1510 lang_input_statement_type *entry)
1514 if (!entry->flags.maybe_archive)
1517 if (entry->flags.full_name_provided)
1518 path = concat (search->name, "/", entry->filename,
1519 (const char *) NULL);
1521 path = concat (search->name, "/lib", entry->filename, arch, ".a",
1522 (const char *) NULL);
1524 if (!ldfile_try_open_bfd (path, entry))
1529 /* Don't include the searched directory in the import path. */
1530 bfd_xcoff_set_archive_import_path (&link_info, entry->the_bfd,
1531 path + strlen (search->name) + 1);
1532 entry->filename = path;
1536 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1537 gld${EMULATION_NAME}_before_parse,
1540 after_parse_default,
1541 gld${EMULATION_NAME}_after_open,
1542 after_check_relocs_default,
1543 after_allocation_default,
1544 gld${EMULATION_NAME}_set_output_arch,
1545 gld${EMULATION_NAME}_choose_target,
1546 gld${EMULATION_NAME}_before_allocation,
1547 gld${EMULATION_NAME}_get_script,
1548 "${EMULATION_NAME}",
1551 gld${EMULATION_NAME}_create_output_section_statements,
1552 gld${EMULATION_NAME}_open_dynamic_archive,
1553 0, /* place_orphan */
1554 0, /* set_symbols */
1555 gld${EMULATION_NAME}_parse_args,
1556 gld${EMULATION_NAME}_add_options,
1557 gld${EMULATION_NAME}_handle_option,
1558 gld${EMULATION_NAME}_unrecognized_file,
1559 NULL, /* list_options */
1560 NULL, /* recognized_file */
1561 NULL, /* find potential_libraries */
1562 NULL, /* new_vers_pattern */
1563 NULL /* extra_map_file_text */