1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
9 /* This file is is generated by a shell script. DO NOT EDIT! */
11 /* AIX emulation code for ${EMULATION_NAME}
12 Copyright 1991, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
13 2003, 2004, 2005, 2006, 2007, 2008
14 Free Software Foundation, Inc.
15 Written by Steve Chamberlain <sac@cygnus.com>
16 AIX support by Ian Lance Taylor <ian@cygnus.com>
17 AIX 64 bit support by Tom Rix <trix@redhat.com>
19 This file is part of the GNU Binutils.
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 3 of the License, or
24 (at your option) any later version.
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
34 MA 02110-1301, USA. */
36 #define TARGET_IS_${EMULATION_NAME}
40 #include "libiberty.h"
41 #include "safe-ctype.h"
56 #include "coff/internal.h"
57 #include "coff/xcoff.h"
61 static void gld${EMULATION_NAME}_read_file (const char *, bfd_boolean);
62 static void gld${EMULATION_NAME}_free (void *);
63 static void gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *);
64 static void gld${EMULATION_NAME}_find_exp_assignment (etree_type *);
67 /* The file alignment required for each section. */
68 static unsigned long file_align;
70 /* The maximum size the stack is permitted to grow. This is stored in
72 static unsigned long maxstack;
74 /* The maximum data size. This is stored in the a.out header. */
75 static unsigned long maxdata;
77 /* Whether to perform garbage collection. */
80 /* The module type to use. */
81 static unsigned short modtype = ('1' << 8) | 'L';
83 /* Whether the .text section must be read-only (i.e., no relocs
87 /* Whether to implement Unix like linker semantics. */
90 /* Structure used to hold import file list. */
94 struct filelist *next;
98 /* List of import files. */
99 static struct filelist *import_files;
101 /* List of export symbols read from the export files. */
103 struct export_symbol_list
105 struct export_symbol_list *next;
109 static struct export_symbol_list *export_symbols;
111 /* Maintains the 32 or 64 bit mode state of import file */
112 static unsigned int symbol_mode = 0x04;
114 /* Which symbol modes are valid */
115 static unsigned int symbol_mode_mask = 0x0d;
117 /* Whether this is a 64 bit link */
118 static int is_64bit = 0;
120 /* Which syscalls from import file are valid */
121 static unsigned int syscall_mask = 0x77;
123 /* fake file for -binitfini support */
124 static lang_input_statement_type *initfini_file;
126 /* Whether to do run time linking
127 -brtl enables, -bnortl and -bnortllib disable. */
130 /* Explicit command line library path, -blibpath */
131 static char *command_line_blibpath = NULL;
133 /* This routine is called before anything else is done. */
136 gld${EMULATION_NAME}_before_parse (void)
138 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
140 config.has_shared = TRUE;
142 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
143 Override them here so we can use the link_info.init_function as a
144 state flag that lets the backend know that -binitfini has been done. */
146 link_info.init_function = NULL;
147 link_info.fini_function = NULL;
150 /* Handle AIX specific options. */
178 gld${EMULATION_NAME}_add_options
179 (int ns, char **shortopts, int nl, struct option **longopts,
180 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
182 static const char xtra_short[] = "D:H:KT:z";
183 static const struct option xtra_long[] = {
184 /* -binitfini has special handling in the linker backend. The native linker
185 uses the arguemnts to generate a table of init and fini functions for
186 the executable. The important use for this option is to support aix 4.2+
187 c++ constructors and destructors. This is tied into gcc via collect2.c.
189 The function table is accessed by the runtime linker/loader by checking if
190 the first symbol in the loader symbol table is __rtinit. The gnu linker
191 generates this symbol and makes it the first loader symbol. */
193 {"basis", no_argument, NULL, OPTION_IGNORE},
194 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
195 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
196 {"bcrld", no_argument, NULL, OPTION_IGNORE},
197 {"bcror31", no_argument, NULL, OPTION_IGNORE},
198 {"bD", required_argument, NULL, OPTION_MAXDATA},
199 {"bE", required_argument, NULL, OPTION_EXPORT},
200 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
201 {"berok", no_argument, NULL, OPTION_EROK},
202 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
203 {"bexport", required_argument, NULL, OPTION_EXPORT},
204 {"bf", no_argument, NULL, OPTION_ERNOTOK},
205 {"bgc", no_argument, &gc, 1},
206 {"bh", required_argument, NULL, OPTION_IGNORE},
207 {"bhalt", required_argument, NULL, OPTION_IGNORE},
208 {"bI", required_argument, NULL, OPTION_IMPORT},
209 {"bimport", required_argument, NULL, OPTION_IMPORT},
210 {"binitfini", required_argument, NULL, OPTION_INITFINI},
211 {"bl", required_argument, NULL, OPTION_LOADMAP},
212 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
213 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
214 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
215 {"bM", required_argument, NULL, OPTION_MODTYPE},
216 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
217 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
218 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
219 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
220 {"bnogc", no_argument, &gc, 0},
221 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
222 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
223 {"bnotextro", no_argument, &textro, 0},
224 {"bnro", no_argument, &textro, 0},
225 {"bpD", required_argument, NULL, OPTION_PD},
226 {"bpT", required_argument, NULL, OPTION_PT},
227 {"bro", no_argument, &textro, 1},
228 {"brtl", no_argument, &rtld, 1},
229 {"bnortl", no_argument, &rtld, 0},
230 {"bnortllib", no_argument, &rtld, 0},
231 {"bS", required_argument, NULL, OPTION_MAXSTACK},
232 {"bso", no_argument, NULL, OPTION_AUTOIMP},
233 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
234 {"btextro", no_argument, &textro, 1},
235 {"b32", no_argument, NULL, OPTION_32},
236 {"b64", no_argument, NULL, OPTION_64},
237 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
238 {"unix", no_argument, NULL, OPTION_UNIX},
239 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
240 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
241 {NULL, no_argument, NULL, 0}
244 /* Options supported by the AIX linker which we do not support: -f,
245 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
246 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
247 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
248 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
249 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
250 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
253 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
254 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
255 *longopts = xrealloc (*longopts,
256 nl * sizeof (struct option) + sizeof (xtra_long));
257 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
261 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
265 /* If the current option starts with -b, change the first : to an =.
266 The AIX linker uses : to separate the option from the argument;
267 changing it to = lets us treat it as a getopt option. */
272 if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
276 for (s = argv[indx]; *s != '\0'; s++)
289 gld${EMULATION_NAME}_handle_option (int optc)
300 /* Long option which just sets a flag. */
304 val = bfd_scan_vma (optarg, &end, 0);
306 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
308 lang_section_start (".data", exp_intop (val), NULL);
312 val = bfd_scan_vma (optarg, &end, 0);
313 if (*end != '\0' || (val & (val - 1)) != 0)
314 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
321 /* FIXME: This should use the page size for the target system. */
326 /* On AIX this is the same as GNU ld -Ttext. When we see -T
327 number, we assume the AIX option is intended. Otherwise, we
328 assume the usual GNU ld -T option is intended. We can't just
329 ignore the AIX option, because gcc passes it to the linker. */
330 val = bfd_scan_vma (optarg, &end, 0);
333 lang_section_start (".text", exp_intop (val), NULL);
339 case OPTION_INITFINI:
342 * The aix linker init fini has the format :
344 * -binitfini:[ Initial][:Termination][:Priority]
346 * it allows the Termination and Priority to be optional.
348 * Since we support only one init/fini pair, we ignore the Priority.
350 * Define the special symbol __rtinit.
352 * strtok does not correctly handle the case of -binitfini::fini: so
358 while (*t && ':' != *t)
364 link_info.init_function = i;
367 while (*t && ':' != *t)
372 link_info.fini_function = f;
377 link_info.static_link = FALSE;
381 force_make_executable = FALSE;
385 force_make_executable = TRUE;
389 gld${EMULATION_NAME}_read_file (optarg, FALSE);
395 struct filelist **flpp;
397 n = (struct filelist *) xmalloc (sizeof (struct filelist));
400 flpp = &import_files;
401 while (*flpp != NULL)
402 flpp = &(*flpp)->next;
408 config.map_filename = optarg;
412 val = bfd_scan_vma (optarg, &end, 0);
414 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
419 case OPTION_MAXSTACK:
420 val = bfd_scan_vma (optarg, &end, 0);
422 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
431 link_info.shared = TRUE;
434 if (*optarg == '\0' || optarg[1] == '\0')
435 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
437 modtype = (*optarg << 8) | optarg[1];
440 case OPTION_NOAUTOIMP:
441 link_info.static_link = TRUE;
444 case OPTION_NOSTRCMPCT:
445 link_info.traditional_format = TRUE;
449 /* This sets the page that the .data section is supposed to
450 start on. The offset within the page should still be the
451 offset within the file, so we need to build an appropriate
453 val = bfd_scan_vma (optarg, &end, 0);
455 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
463 exp_nameop (NAME, "."),
466 exp_binop ('+', t, exp_intop (31)),
467 exp_intop (~(bfd_vma) 31));
468 lang_section_start (".data", t, NULL);
473 /* This set the page that the .text section is supposed to start
474 on. The offset within the page should still be the offset
476 val = bfd_scan_vma (optarg, &end, 0);
478 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
485 exp_nameop (SIZEOF_HEADERS, NULL));
487 exp_binop ('+', t, exp_intop (31)),
488 exp_intop (~(bfd_vma) 31));
489 lang_section_start (".text", t, NULL);
493 case OPTION_STRCMPCT:
494 link_info.traditional_format = FALSE;
504 symbol_mode_mask = 0x0d;
510 symbol_mode_mask = 0x0e;
514 command_line_blibpath = optarg;
517 case OPTION_NOLIBPATH:
518 command_line_blibpath = NULL;
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 (lang_input_statement_type *entry)
536 e = fopen (entry->filename, FOPEN_RT);
542 if (getc (e) == '#' && getc (e) == '!')
545 struct filelist **flpp;
547 n = (struct filelist *) xmalloc (sizeof (struct filelist));
549 n->name = entry->filename;
550 flpp = &import_files;
551 while (*flpp != NULL)
552 flpp = &(*flpp)->next;
556 entry->loaded = TRUE;
564 /* This is called after the input files have been opened. */
567 gld${EMULATION_NAME}_after_open (void)
572 /* Call ldctor_build_sets, after pretending that this is a
573 relocatable link. We do this because AIX requires relocation
574 entries for all references to symbols, even in a final
575 executable. Of course, we only want to do this if we are
576 producing an XCOFF output file. */
577 r = link_info.relocatable;
578 if (strstr (bfd_get_target (link_info.output_bfd), "xcoff") != NULL)
579 link_info.relocatable = TRUE;
580 ldctor_build_sets ();
581 link_info.relocatable = r;
583 /* For each set, record the size, so that the XCOFF backend can
584 output the correct csect length. */
585 for (p = sets; p != (struct set_info *) NULL; p = p->next)
589 /* If the symbol is defined, we may have been invoked from
590 collect, and the sets may already have been built, so we do
592 if (p->h->type == bfd_link_hash_defined
593 || p->h->type == bfd_link_hash_defweak)
596 if (p->reloc != BFD_RELOC_CTOR)
598 /* Handle this if we need to. */
602 size = (p->count + 2) * 4;
603 if (!bfd_xcoff_link_record_set (link_info.output_bfd, &link_info,
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 (void)
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 (link_info.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 /* Precedence of LIBPATH
642 -blibpath: native support always first
643 -rpath: gnu extension
644 -L build from command line -L's */
645 if (command_line_blibpath != NULL)
646 libpath = command_line_blibpath;
647 else if (command_line.rpath != NULL)
648 libpath = command_line.rpath;
649 else if (search_head == NULL)
650 libpath = (char *) "";
654 search_dirs_type *search;
656 /* PR ld/4023: Strip sysroot prefix from any paths
657 being inserted into the output binary's DT_RPATH. */
658 if (ld_sysroot != NULL
659 && * ld_sysroot != 0)
661 const char * name = search_head->name;
662 size_t ld_sysroot_len = strlen (ld_sysroot);
664 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
665 name += ld_sysroot_len;
668 libpath = xmalloc (len + 1);
669 strcpy (libpath, name);
671 for (search = search_head->next; search != NULL; search = search->next)
676 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
677 name += ld_sysroot_len;
679 nlen = strlen (name);
680 libpath = xrealloc (libpath, len + nlen + 2);
682 strcpy (libpath + len + 1, name);
688 len = strlen (search_head->name);
689 libpath = xmalloc (len + 1);
690 strcpy (libpath, search_head->name);
692 for (search = search_head->next; search != NULL; search = search->next)
696 nlen = strlen (search->name);
697 libpath = xrealloc (libpath, len + nlen + 2);
699 strcpy (libpath + len + 1, search->name);
705 /* Let the XCOFF backend set up the .loader section. */
706 if (!bfd_xcoff_size_dynamic_sections
707 (link_info.output_bfd, &link_info, libpath, entry_symbol.name, file_align,
708 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
709 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
710 rtld ? TRUE : FALSE))
711 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
713 /* Look through the special sections, and put them in the right
714 place in the link ordering. This is especially magic. */
715 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
718 lang_output_section_statement_type *os;
719 lang_statement_union_type **pls;
720 lang_input_section_type *is;
724 sec = special_sections[i];
728 /* Remove this section from the list of the output section.
729 This assumes we know what the script looks like. */
731 os = lang_output_section_find (sec->output_section->name);
733 einfo ("%P%F: can't find output section %s\n",
734 sec->output_section->name);
736 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
738 if ((*pls)->header.type == lang_input_section_enum
739 && (*pls)->input_section.section == sec)
741 is = (lang_input_section_type *) * pls;
742 *pls = (*pls)->header.next;
746 if ((*pls)->header.type == lang_wild_statement_enum)
748 lang_statement_union_type **pwls;
750 for (pwls = &(*pls)->wild_statement.children.head;
751 *pwls != NULL; pwls = &(*pwls)->header.next)
754 if ((*pwls)->header.type == lang_input_section_enum
755 && (*pwls)->input_section.section == sec)
757 is = (lang_input_section_type *) * pwls;
758 *pwls = (*pwls)->header.next;
770 einfo ("%P%F: can't find %s in output section\n",
771 bfd_get_section_name (sec->owner, sec));
774 /* Now figure out where the section should go. */
778 default: /* to avoid warnings */
779 case XCOFF_SPECIAL_SECTION_TEXT:
785 case XCOFF_SPECIAL_SECTION_ETEXT:
791 case XCOFF_SPECIAL_SECTION_DATA:
797 case XCOFF_SPECIAL_SECTION_EDATA:
803 case XCOFF_SPECIAL_SECTION_END:
804 case XCOFF_SPECIAL_SECTION_END2:
811 os = lang_output_section_find (oname);
815 is->header.next = os->children.head;
816 os->children.head = (lang_statement_union_type *) is;
820 is->header.next = NULL;
821 lang_statement_append (&os->children,
822 (lang_statement_union_type *) is,
827 before_allocation_default ();
831 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
834 static char *from_outside;
835 static char *from_inside;
836 static char *argv_to_target[][2] = {
837 {NULL, "${OUTPUT_FORMAT}"},
838 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
839 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
844 from_outside = getenv (TARGET_ENVIRON);
845 if (from_outside != (char *) NULL)
848 /* Set to default. */
849 from_inside = argv_to_target[0][1];
850 for (i = 1; i < argc; i++)
852 for (j = 1; j < jmax; j++)
854 if (0 == strcmp (argv[i], argv_to_target[j][0]))
855 from_inside = argv_to_target[j][1];
866 change_symbol_mode (char *input)
868 char *symbol_mode_string[] = {
879 for (bit = 0;; bit++)
881 string = symbol_mode_string[bit];
885 if (0 == strcmp (input, string))
887 symbol_mode = (1 << bit);
891 /* should not be here */
898 -1 : error, try something else */
900 is_syscall (char *input, unsigned int *flag)
906 char *syscall_string;
909 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
910 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
911 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
912 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
913 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
914 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
915 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
916 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
922 for (bit = 0;; bit++)
924 string = s[bit].syscall_string;
928 if (0 == strcmp (input, string))
930 if (1 << bit & syscall_mask)
941 /* should not be here */
945 /* Read an import or export file. For an import file, this is called
946 by the before_allocation emulation routine. For an export file,
947 this is called by the handle_option emulation routine. */
950 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
959 const char *impmember;
961 o = (struct obstack *) xmalloc (sizeof (struct obstack));
962 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
964 f = fopen (filename, FOPEN_RT);
967 bfd_set_error (bfd_error_system_call);
968 einfo ("%F%s: %E\n", filename);
979 /* Default to 32 and 64 bit mode
980 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
981 are not repeated, assume 64 bit routines also want to use them.
982 See the routine change_symbol_mode for more information. */
986 while ((c = getc (f)) != EOF)
990 unsigned int syscall_flag = 0;
992 struct bfd_link_hash_entry *h;
996 obstack_1grow (o, c);
1000 obstack_1grow (o, '\0');
1003 s = (char *) obstack_base (o);
1004 while (ISSPACE (*s))
1008 || change_symbol_mode (s)
1009 || (*s == '#' && s[1] == ' ')
1010 || (!import && *s == '#' && s[1] == '!'))
1012 obstack_free (o, obstack_base (o));
1016 if (*s == '#' && s[1] == '!')
1019 while (ISSPACE (*s))
1026 obstack_free (o, obstack_base (o));
1029 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1036 (void) obstack_finish (o);
1040 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1050 if (imppath == file - 1)
1060 while (ISSPACE (cs))
1069 einfo ("%s:%d: warning: syntax error in import file\n",
1076 while (*s != ')' && *s != '\0')
1081 einfo ("%s:%d: warning: syntax error in import file\n",
1089 if (symbol_mode & symbol_mode_mask)
1091 /* This is a symbol to be imported or exported. */
1094 address = (bfd_vma) -1;
1096 while (!ISSPACE (*s) && *s != '\0')
1104 while (ISSPACE (*s))
1108 while (!ISSPACE (*se) && *se != '\0')
1113 while (ISSPACE (*se))
1116 einfo ("%s%d: warning: syntax error in import/export file\n",
1125 status = is_syscall (s, &syscall_flag);
1129 /* not a system call, check for address */
1130 address = bfd_scan_vma (s, &end, 0);
1133 einfo ("%s:%d: warning: syntax error in import/export file\n",
1143 struct export_symbol_list *n;
1145 ldlang_add_undef (symname);
1146 n = ((struct export_symbol_list *)
1147 xmalloc (sizeof (struct export_symbol_list)));
1148 n->next = export_symbols;
1149 n->name = xstrdup (symname);
1154 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1156 if (h == NULL || h->type == bfd_link_hash_new)
1158 /* We can just ignore attempts to import an unreferenced
1163 if (!bfd_xcoff_import_symbol (link_info.output_bfd,
1165 address, imppath, impfile,
1166 impmember, syscall_flag))
1167 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1168 filename, lineno, symname);
1172 obstack_free (o, obstack_base (o));
1175 if (obstack_object_size (o) > 0)
1177 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1179 obstack_free (o, obstack_base (o));
1184 obstack_free (o, NULL);
1189 /* This routine saves us from worrying about declaring free. */
1192 gld${EMULATION_NAME}_free (void *p)
1197 /* This is called by the before_allocation routine via
1198 lang_for_each_statement. It looks for relocations and assignments
1202 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1204 if (s->header.type == lang_reloc_statement_enum)
1206 lang_reloc_statement_type *rs;
1208 rs = &s->reloc_statement;
1209 if (rs->name == NULL)
1210 einfo ("%F%P: only relocations against symbols are permitted\n");
1211 if (!bfd_xcoff_link_count_reloc (link_info.output_bfd, &link_info,
1213 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1216 if (s->header.type == lang_assignment_statement_enum)
1217 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1220 /* Look through an expression for an assignment statement. */
1223 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1225 struct bfd_link_hash_entry *h;
1227 switch (exp->type.node_class)
1230 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1231 FALSE, FALSE, FALSE);
1236 if (strcmp (exp->assign.dst, ".") != 0)
1238 if (!bfd_xcoff_record_link_assignment (link_info.output_bfd,
1241 einfo ("%P%F: failed to record assignment to %s: %E\n",
1244 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1248 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1249 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1253 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1254 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1255 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1259 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1268 gld${EMULATION_NAME}_get_script (int *isfile)
1271 if test -n "$COMPILE_IN"
1273 # Scripts compiled in.
1275 # sed commands to quote an ld script as a C string.
1276 sc="-f ${srcdir}/emultempl/ostring.sed"
1282 if (link_info.relocatable && config.build_constructors)
1285 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1286 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1287 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1288 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1289 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1290 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1291 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1292 echo ' ; else return' >> e${EMULATION_NAME}.c
1293 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1294 echo '; }' >> e${EMULATION_NAME}.c
1297 # Scripts read from the filesystem.
1303 if (link_info.relocatable && config.build_constructors)
1304 return "ldscripts/${EMULATION_NAME}.xu";
1305 else if (link_info.relocatable)
1306 return "ldscripts/${EMULATION_NAME}.xr";
1307 else if (!config.text_read_only)
1308 return "ldscripts/${EMULATION_NAME}.xbn";
1309 else if (!config.magic_demand_paged)
1310 return "ldscripts/${EMULATION_NAME}.xn";
1312 return "ldscripts/${EMULATION_NAME}.x";
1321 gld${EMULATION_NAME}_create_output_section_statements (void)
1324 if ((bfd_get_flavour (link_info.output_bfd) == bfd_target_xcoff_flavour)
1325 && (link_info.init_function != NULL
1326 || link_info.fini_function != NULL
1329 initfini_file = lang_add_input_file ("initfini",
1330 lang_input_file_is_file_enum,
1333 initfini_file->the_bfd = bfd_create ("initfini", link_info.output_bfd);
1334 if (initfini_file->the_bfd == NULL
1335 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1336 bfd_get_arch (link_info.output_bfd),
1337 bfd_get_mach (link_info.output_bfd)))
1339 einfo ("%X%P: can not create BFD %E\n");
1343 /* Call backend to fill in the rest */
1344 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1345 link_info.init_function,
1346 link_info.fini_function,
1349 einfo ("%X%P: can not create BFD %E\n");
1353 /* __rtld defined in /lib/librtl.a */
1355 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1360 gld${EMULATION_NAME}_set_output_arch (void)
1362 bfd_set_arch_mach (link_info.output_bfd,
1363 bfd_xcoff_architecture (link_info.output_bfd),
1364 bfd_xcoff_machine (link_info.output_bfd));
1366 ldfile_output_architecture = bfd_get_arch (link_info.output_bfd);
1367 ldfile_output_machine = bfd_get_mach (link_info.output_bfd);
1368 ldfile_output_machine_name = bfd_printable_name (link_info.output_bfd);
1371 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1372 gld${EMULATION_NAME}_before_parse,
1375 after_parse_default,
1376 gld${EMULATION_NAME}_after_open,
1377 after_allocation_default,
1378 gld${EMULATION_NAME}_set_output_arch,
1379 gld${EMULATION_NAME}_choose_target,
1380 gld${EMULATION_NAME}_before_allocation,
1381 gld${EMULATION_NAME}_get_script,
1382 "${EMULATION_NAME}",
1385 gld${EMULATION_NAME}_create_output_section_statements,
1386 0, /* open_dynamic_archive */
1387 0, /* place_orphan */
1388 0, /* set_symbols */
1389 gld${EMULATION_NAME}_parse_args,
1390 gld${EMULATION_NAME}_add_options,
1391 gld${EMULATION_NAME}_handle_option,
1392 gld${EMULATION_NAME}_unrecognized_file,
1393 NULL, /* list_options */
1394 NULL, /* recognized_file */
1395 NULL, /* find potential_libraries */
1396 NULL /* new_vers_pattern */