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, 1999, 2000, 2001, 2002,
13 2003, 2004, 2005, 2006
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 GLD, the Gnu Linker.
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 2 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, MA 02110-1301, USA. */
35 #define TARGET_IS_${EMULATION_NAME}
39 #include "libiberty.h"
40 #include "safe-ctype.h"
55 #include "coff/internal.h"
56 #include "coff/xcoff.h"
60 static void gld${EMULATION_NAME}_read_file (const char *, bfd_boolean);
61 static void gld${EMULATION_NAME}_free (void *);
62 static void gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *);
63 static void gld${EMULATION_NAME}_find_exp_assignment (etree_type *);
66 /* The file alignment required for each section. */
67 static unsigned long file_align;
69 /* The maximum size the stack is permitted to grow. This is stored in
71 static unsigned long maxstack;
73 /* The maximum data size. This is stored in the a.out header. */
74 static unsigned long maxdata;
76 /* Whether to perform garbage collection. */
79 /* The module type to use. */
80 static unsigned short modtype = ('1' << 8) | 'L';
82 /* Whether the .text section must be read-only (i.e., no relocs
86 /* Whether to implement Unix like linker semantics. */
89 /* Structure used to hold import file list. */
93 struct filelist *next;
97 /* List of import files. */
98 static struct filelist *import_files;
100 /* List of export symbols read from the export files. */
102 struct export_symbol_list
104 struct export_symbol_list *next;
108 static struct export_symbol_list *export_symbols;
110 /* Maintains the 32 or 64 bit mode state of import file */
111 static unsigned int symbol_mode = 0x04;
113 /* Which symbol modes are valid */
114 static unsigned int symbol_mode_mask = 0x0d;
116 /* Whether this is a 64 bit link */
117 static int is_64bit = 0;
119 /* Which syscalls from import file are valid */
120 static unsigned int syscall_mask = 0x77;
122 /* fake file for -binitfini support */
123 static lang_input_statement_type *initfini_file;
125 /* Whether to do run time linking
126 -brtl enables, -bnortl and -bnortllib disable. */
129 /* Explicit command line library path, -blibpath */
130 static char *command_line_blibpath = NULL;
132 /* This routine is called before anything else is done. */
135 gld${EMULATION_NAME}_before_parse (void)
137 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
139 config.has_shared = TRUE;
141 /* The link_info.[init|fini]_functions are initialized in ld/lexsup.c.
142 Override them here so we can use the link_info.init_function as a
143 state flag that lets the backend know that -binitfini has been done. */
145 link_info.init_function = NULL;
146 link_info.fini_function = NULL;
149 /* Handle AIX specific options. */
177 gld${EMULATION_NAME}_add_options
178 (int ns, char **shortopts, int nl, struct option **longopts,
179 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
181 static const char xtra_short[] = "D:H:KT:z";
182 static const struct option xtra_long[] = {
183 /* -binitfini has special handling in the linker backend. The native linker
184 uses the arguemnts to generate a table of init and fini functions for
185 the executable. The important use for this option is to support aix 4.2+
186 c++ constructors and destructors. This is tied into gcc via collect2.c.
188 The function table is accessed by the runtime linker/loader by checking if
189 the first symbol in the loader symbol table is __rtinit. The gnu linker
190 generates this symbol and makes it the first loader symbol. */
192 {"basis", no_argument, NULL, OPTION_IGNORE},
193 {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
194 {"bcomprld", no_argument, NULL, OPTION_IGNORE},
195 {"bcrld", no_argument, NULL, OPTION_IGNORE},
196 {"bcror31", no_argument, NULL, OPTION_IGNORE},
197 {"bD", required_argument, NULL, OPTION_MAXDATA},
198 {"bE", required_argument, NULL, OPTION_EXPORT},
199 {"bernotok", no_argument, NULL, OPTION_ERNOTOK},
200 {"berok", no_argument, NULL, OPTION_EROK},
201 {"berrmsg", no_argument, NULL, OPTION_IGNORE},
202 {"bexport", required_argument, NULL, OPTION_EXPORT},
203 {"bf", no_argument, NULL, OPTION_ERNOTOK},
204 {"bgc", no_argument, &gc, 1},
205 {"bh", required_argument, NULL, OPTION_IGNORE},
206 {"bhalt", required_argument, NULL, OPTION_IGNORE},
207 {"bI", required_argument, NULL, OPTION_IMPORT},
208 {"bimport", required_argument, NULL, OPTION_IMPORT},
209 {"binitfini", required_argument, NULL, OPTION_INITFINI},
210 {"bl", required_argument, NULL, OPTION_LOADMAP},
211 {"bloadmap", required_argument, NULL, OPTION_LOADMAP},
212 {"bmaxdata", required_argument, NULL, OPTION_MAXDATA},
213 {"bmaxstack", required_argument, NULL, OPTION_MAXSTACK},
214 {"bM", required_argument, NULL, OPTION_MODTYPE},
215 {"bmodtype", required_argument, NULL, OPTION_MODTYPE},
216 {"bnoautoimp", no_argument, NULL, OPTION_NOAUTOIMP},
217 {"bnodelcsect", no_argument, NULL, OPTION_IGNORE},
218 {"bnoentry", no_argument, NULL, OPTION_IGNORE},
219 {"bnogc", no_argument, &gc, 0},
220 {"bnso", no_argument, NULL, OPTION_NOAUTOIMP},
221 {"bnostrcmpct", no_argument, NULL, OPTION_NOSTRCMPCT},
222 {"bnotextro", no_argument, &textro, 0},
223 {"bnro", no_argument, &textro, 0},
224 {"bpD", required_argument, NULL, OPTION_PD},
225 {"bpT", required_argument, NULL, OPTION_PT},
226 {"bro", no_argument, &textro, 1},
227 {"brtl", no_argument, &rtld, 1},
228 {"bnortl", no_argument, &rtld, 0},
229 {"bnortllib", no_argument, &rtld, 0},
230 {"bS", required_argument, NULL, OPTION_MAXSTACK},
231 {"bso", no_argument, NULL, OPTION_AUTOIMP},
232 {"bstrcmpct", no_argument, NULL, OPTION_STRCMPCT},
233 {"btextro", no_argument, &textro, 1},
234 {"b32", no_argument, NULL, OPTION_32},
235 {"b64", no_argument, NULL, OPTION_64},
236 {"static", no_argument, NULL, OPTION_NOAUTOIMP},
237 {"unix", no_argument, NULL, OPTION_UNIX},
238 {"blibpath", required_argument, NULL, OPTION_LIBPATH},
239 {"bnolibpath", required_argument, NULL, OPTION_NOLIBPATH},
240 {NULL, no_argument, NULL, 0}
243 /* Options supported by the AIX linker which we do not support: -f,
244 -S, -v, -Z, -bbindcmds, -bbinder, -bbindopts, -bcalls, -bcaps,
245 -bcror15, -bdebugopt, -bdbg, -bdelcsect, -bex?, -bfilelist, -bfl,
246 -bgcbypass, -bglink, -binsert, -bi, -bloadmap, -bl, -bmap, -bnl,
247 -bnobind, -bnocomprld, -bnocrld, -bnoerrmsg, -bnoglink,
248 -bnoloadmap, -bnl, -bnoobjreorder, -bnoquiet, -bnoreorder,
249 -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
252 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
253 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
254 *longopts = xrealloc (*longopts,
255 nl * sizeof (struct option) + sizeof (xtra_long));
256 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
260 gld${EMULATION_NAME}_parse_args (int argc, char **argv)
264 /* If the current option starts with -b, change the first : to an =.
265 The AIX linker uses : to separate the option from the argument;
266 changing it to = lets us treat it as a getopt option. */
271 if (indx < argc && CONST_STRNEQ (argv[indx], "-b"))
275 for (s = argv[indx]; *s != '\0'; s++)
288 gld${EMULATION_NAME}_handle_option (int optc)
299 /* Long option which just sets a flag. */
303 val = bfd_scan_vma (optarg, &end, 0);
305 einfo ("%P: warning: ignoring invalid -D number %s\n", optarg);
307 lang_section_start (".data", exp_intop (val), NULL);
311 val = bfd_scan_vma (optarg, &end, 0);
312 if (*end != '\0' || (val & (val - 1)) != 0)
313 einfo ("%P: warning: ignoring invalid -H number %s\n", optarg);
320 /* FIXME: This should use the page size for the target system. */
325 /* On AIX this is the same as GNU ld -Ttext. When we see -T
326 number, we assume the AIX option is intended. Otherwise, we
327 assume the usual GNU ld -T option is intended. We can't just
328 ignore the AIX option, because gcc passes it to the linker. */
329 val = bfd_scan_vma (optarg, &end, 0);
332 lang_section_start (".text", exp_intop (val), NULL);
338 case OPTION_INITFINI:
341 * The aix linker init fini has the format :
343 * -binitfini:[ Initial][:Termination][:Priority]
345 * it allows the Termination and Priority to be optional.
347 * Since we support only one init/fini pair, we ignore the Priority.
349 * Define the special symbol __rtinit.
351 * strtok does not correctly handle the case of -binitfini::fini: so
357 while (*t && ':' != *t)
363 link_info.init_function = i;
366 while (*t && ':' != *t)
371 link_info.fini_function = f;
376 link_info.static_link = FALSE;
380 force_make_executable = FALSE;
384 force_make_executable = TRUE;
388 gld${EMULATION_NAME}_read_file (optarg, FALSE);
394 struct filelist **flpp;
396 n = (struct filelist *) xmalloc (sizeof (struct filelist));
399 flpp = &import_files;
400 while (*flpp != NULL)
401 flpp = &(*flpp)->next;
407 config.map_filename = optarg;
411 val = bfd_scan_vma (optarg, &end, 0);
413 einfo ("%P: warning: ignoring invalid -bmaxdata number %s\n", optarg);
418 case OPTION_MAXSTACK:
419 val = bfd_scan_vma (optarg, &end, 0);
421 einfo ("%P: warning: ignoring invalid -bmaxstack number %s\n",
430 link_info.shared = TRUE;
433 if (*optarg == '\0' || optarg[1] == '\0')
434 einfo ("%P: warning: ignoring invalid module type %s\n", optarg);
436 modtype = (*optarg << 8) | optarg[1];
439 case OPTION_NOAUTOIMP:
440 link_info.static_link = TRUE;
443 case OPTION_NOSTRCMPCT:
444 link_info.traditional_format = TRUE;
448 /* This sets the page that the .data section is supposed to
449 start on. The offset within the page should still be the
450 offset within the file, so we need to build an appropriate
452 val = bfd_scan_vma (optarg, &end, 0);
454 einfo ("%P: warning: ignoring invalid -pD number %s\n", optarg);
462 exp_nameop (NAME, "."),
465 exp_binop ('+', t, exp_intop (31)),
466 exp_intop (~(bfd_vma) 31));
467 lang_section_start (".data", t, NULL);
472 /* This set the page that the .text section is supposed to start
473 on. The offset within the page should still be the offset
475 val = bfd_scan_vma (optarg, &end, 0);
477 einfo ("%P: warning: ignoring invalid -pT number %s\n", optarg);
484 exp_nameop (SIZEOF_HEADERS, NULL));
486 exp_binop ('+', t, exp_intop (31)),
487 exp_intop (~(bfd_vma) 31));
488 lang_section_start (".text", t, NULL);
492 case OPTION_STRCMPCT:
493 link_info.traditional_format = FALSE;
503 symbol_mode_mask = 0x0d;
509 symbol_mode_mask = 0x0e;
513 command_line_blibpath = optarg;
516 case OPTION_NOLIBPATH:
517 command_line_blibpath = NULL;
525 /* This is called when an input file can not be recognized as a BFD
526 object or an archive. If the file starts with #!, we must treat it
527 as an import file. This is for AIX compatibility. */
530 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry)
535 e = fopen (entry->filename, FOPEN_RT);
541 if (getc (e) == '#' && getc (e) == '!')
544 struct filelist **flpp;
546 n = (struct filelist *) xmalloc (sizeof (struct filelist));
548 n->name = entry->filename;
549 flpp = &import_files;
550 while (*flpp != NULL)
551 flpp = &(*flpp)->next;
555 entry->loaded = TRUE;
563 /* This is called after the input files have been opened. */
566 gld${EMULATION_NAME}_after_open (void)
571 /* Call ldctor_build_sets, after pretending that this is a
572 relocatable link. We do this because AIX requires relocation
573 entries for all references to symbols, even in a final
574 executable. Of course, we only want to do this if we are
575 producing an XCOFF output file. */
576 r = link_info.relocatable;
577 if (strstr (bfd_get_target (output_bfd), "xcoff") != NULL)
578 link_info.relocatable = TRUE;
579 ldctor_build_sets ();
580 link_info.relocatable = r;
582 /* For each set, record the size, so that the XCOFF backend can
583 output the correct csect length. */
584 for (p = sets; p != (struct set_info *) NULL; p = p->next)
588 /* If the symbol is defined, we may have been invoked from
589 collect, and the sets may already have been built, so we do
591 if (p->h->type == bfd_link_hash_defined
592 || p->h->type == bfd_link_hash_defweak)
595 if (p->reloc != BFD_RELOC_CTOR)
597 /* Handle this if we need to. */
601 size = (p->count + 2) * 4;
602 if (!bfd_xcoff_link_record_set (output_bfd, &link_info, p->h, size))
603 einfo ("%F%P: bfd_xcoff_link_record_set failed: %E\n");
607 /* This is called after the sections have been attached to output
608 sections, but before any sizes or addresses have been set. */
611 gld${EMULATION_NAME}_before_allocation (void)
614 struct export_symbol_list *el;
616 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
619 /* Handle the import and export files, if any. */
620 for (fl = import_files; fl != NULL; fl = fl->next)
621 gld${EMULATION_NAME}_read_file (fl->name, TRUE);
622 for (el = export_symbols; el != NULL; el = el->next)
624 struct bfd_link_hash_entry *h;
626 h = bfd_link_hash_lookup (link_info.hash, el->name, FALSE, FALSE, FALSE);
628 einfo ("%P%F: bfd_link_hash_lookup of export symbol failed: %E\n");
629 if (!bfd_xcoff_export_symbol (output_bfd, &link_info, h))
630 einfo ("%P%F: bfd_xcoff_export_symbol failed: %E\n");
633 /* Track down all relocations called for by the linker script (these
634 are typically constructor/destructor entries created by
635 CONSTRUCTORS) and let the backend know it will need to create
636 .loader relocs for them. */
637 lang_for_each_statement (gld${EMULATION_NAME}_find_relocs);
639 /* Precedence of LIBPATH
640 -blibpath: native support always first
641 -rpath: gnu extension
642 -L build from command line -L's */
643 if (command_line_blibpath != NULL)
644 libpath = command_line_blibpath;
645 else if (command_line.rpath != NULL)
646 libpath = command_line.rpath;
647 else if (search_head == NULL)
648 libpath = (char *) "";
652 search_dirs_type *search;
654 /* PR ld/4023: Strip sysroot prefix from any paths
655 being inserted into the output binary's DT_RPATH. */
656 if (ld_sysroot != NULL
657 && * ld_sysroot != 0)
659 const char * name = search_head->name;
660 size_t ld_sysroot_len = strlen (ld_sysroot);
662 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
663 name += ld_sysroot_len;
666 libpath = xmalloc (len + 1);
667 strcpy (libpath, name);
669 for (search = search_head->next; search != NULL; search = search->next)
674 if (strncmp (name, ld_sysroot, ld_sysroot_len) == 0)
675 name += ld_sysroot_len;
677 nlen = strlen (name);
678 libpath = xrealloc (libpath, len + nlen + 2);
680 strcpy (libpath + len + 1, name);
686 len = strlen (search_head->name);
687 libpath = xmalloc (len + 1);
688 strcpy (libpath, search_head->name);
690 for (search = search_head->next; search != NULL; search = search->next)
694 nlen = strlen (search->name);
695 libpath = xrealloc (libpath, len + nlen + 2);
697 strcpy (libpath + len + 1, search->name);
703 /* Let the XCOFF backend set up the .loader section. */
704 if (!bfd_xcoff_size_dynamic_sections
705 (output_bfd, &link_info, libpath, entry_symbol.name, file_align,
706 maxstack, maxdata, gc && !unix_ld ? TRUE : FALSE,
707 modtype, textro ? TRUE : FALSE, unix_ld, special_sections,
708 rtld ? TRUE : FALSE))
709 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
711 /* Look through the special sections, and put them in the right
712 place in the link ordering. This is especially magic. */
713 for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
716 lang_output_section_statement_type *os;
717 lang_statement_union_type **pls;
718 lang_input_section_type *is;
722 sec = special_sections[i];
726 /* Remove this section from the list of the output section.
727 This assumes we know what the script looks like. */
729 os = lang_output_section_find (sec->output_section->name);
731 einfo ("%P%F: can't find output section %s\n",
732 sec->output_section->name);
734 for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->header.next)
736 if ((*pls)->header.type == lang_input_section_enum
737 && (*pls)->input_section.section == sec)
739 is = (lang_input_section_type *) * pls;
740 *pls = (*pls)->header.next;
744 if ((*pls)->header.type == lang_wild_statement_enum)
746 lang_statement_union_type **pwls;
748 for (pwls = &(*pls)->wild_statement.children.head;
749 *pwls != NULL; pwls = &(*pwls)->header.next)
752 if ((*pwls)->header.type == lang_input_section_enum
753 && (*pwls)->input_section.section == sec)
755 is = (lang_input_section_type *) * pwls;
756 *pwls = (*pwls)->header.next;
768 einfo ("%P%F: can't find %s in output section\n",
769 bfd_get_section_name (sec->owner, sec));
772 /* Now figure out where the section should go. */
776 default: /* to avoid warnings */
777 case XCOFF_SPECIAL_SECTION_TEXT:
783 case XCOFF_SPECIAL_SECTION_ETEXT:
789 case XCOFF_SPECIAL_SECTION_DATA:
795 case XCOFF_SPECIAL_SECTION_EDATA:
801 case XCOFF_SPECIAL_SECTION_END:
802 case XCOFF_SPECIAL_SECTION_END2:
809 os = lang_output_section_find (oname);
813 is->header.next = os->children.head;
814 os->children.head = (lang_statement_union_type *) is;
818 is->header.next = NULL;
819 lang_statement_append (&os->children,
820 (lang_statement_union_type *) is,
825 before_allocation_default ();
829 gld${EMULATION_NAME}_choose_target (int argc, char **argv)
832 static char *from_outside;
833 static char *from_inside;
834 static char *argv_to_target[][2] = {
835 {NULL, "${OUTPUT_FORMAT}"},
836 {"-b32", "${OUTPUT_FORMAT_32BIT}"},
837 {"-b64", "${OUTPUT_FORMAT_64BIT}"},
842 from_outside = getenv (TARGET_ENVIRON);
843 if (from_outside != (char *) NULL)
846 /* Set to default. */
847 from_inside = argv_to_target[0][1];
848 for (i = 1; i < argc; i++)
850 for (j = 1; j < jmax; j++)
852 if (0 == strcmp (argv[i], argv_to_target[j][0]))
853 from_inside = argv_to_target[j][1];
864 change_symbol_mode (char *input)
866 char *symbol_mode_string[] = {
877 for (bit = 0;; bit++)
879 string = symbol_mode_string[bit];
883 if (0 == strcmp (input, string))
885 symbol_mode = (1 << bit);
889 /* should not be here */
896 -1 : error, try something else */
898 is_syscall (char *input, unsigned int *flag)
904 char *syscall_string;
907 { "svc" /* 0x01 */, XCOFF_SYSCALL32 },
908 { "svc32" /* 0x02 */, XCOFF_SYSCALL32 },
909 { "svc3264" /* 0x04 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
910 { "svc64" /* 0x08 */, XCOFF_SYSCALL64 },
911 { "syscall" /* 0x10 */, XCOFF_SYSCALL32 },
912 { "syscall32" /* 0x20 */, XCOFF_SYSCALL32 },
913 { "syscall3264" /* 0x40 */, XCOFF_SYSCALL32 | XCOFF_SYSCALL64 },
914 { "syscall64" /* 0x80 */, XCOFF_SYSCALL64 },
920 for (bit = 0;; bit++)
922 string = s[bit].syscall_string;
926 if (0 == strcmp (input, string))
928 if (1 << bit & syscall_mask)
939 /* should not be here */
943 /* Read an import or export file. For an import file, this is called
944 by the before_allocation emulation routine. For an export file,
945 this is called by the handle_option emulation routine. */
948 gld${EMULATION_NAME}_read_file (const char *filename, bfd_boolean import)
957 const char *impmember;
959 o = (struct obstack *) xmalloc (sizeof (struct obstack));
960 obstack_specify_allocation (o, 0, 0, xmalloc, gld${EMULATION_NAME}_free);
962 f = fopen (filename, FOPEN_RT);
965 bfd_set_error (bfd_error_system_call);
966 einfo ("%F%s: %E\n", filename);
977 /* Default to 32 and 64 bit mode
978 symbols at top of /lib/syscalls.exp do not have a mode modifier and they
979 are not repeated, assume 64 bit routines also want to use them.
980 See the routine change_symbol_mode for more information. */
984 while ((c = getc (f)) != EOF)
988 unsigned int syscall_flag = 0;
990 struct bfd_link_hash_entry *h;
994 obstack_1grow (o, c);
998 obstack_1grow (o, '\0');
1001 s = (char *) obstack_base (o);
1002 while (ISSPACE (*s))
1006 || change_symbol_mode (s)
1007 || (*s == '#' && s[1] == ' ')
1008 || (!import && *s == '#' && s[1] == '!'))
1010 obstack_free (o, obstack_base (o));
1014 if (*s == '#' && s[1] == '!')
1017 while (ISSPACE (*s))
1024 obstack_free (o, obstack_base (o));
1027 einfo ("%F%s%d: #! ([member]) is not supported in import files\n",
1034 (void) obstack_finish (o);
1038 while (!ISSPACE (*s) && *s != '(' && *s != '\0')
1048 if (imppath == file - 1)
1058 while (ISSPACE (cs))
1067 einfo ("%s:%d: warning: syntax error in import file\n",
1074 while (*s != ')' && *s != '\0')
1079 einfo ("%s:%d: warning: syntax error in import file\n",
1087 if (symbol_mode & symbol_mode_mask)
1089 /* This is a symbol to be imported or exported. */
1092 address = (bfd_vma) -1;
1094 while (!ISSPACE (*s) && *s != '\0')
1102 while (ISSPACE (*s))
1106 while (!ISSPACE (*se) && *se != '\0')
1111 while (ISSPACE (*se))
1114 einfo ("%s%d: warning: syntax error in import/export file\n",
1123 status = is_syscall (s, &syscall_flag);
1127 /* not a system call, check for address */
1128 address = bfd_scan_vma (s, &end, 0);
1131 einfo ("%s:%d: warning: syntax error in import/export file\n",
1141 struct export_symbol_list *n;
1143 ldlang_add_undef (symname);
1144 n = ((struct export_symbol_list *)
1145 xmalloc (sizeof (struct export_symbol_list)));
1146 n->next = export_symbols;
1147 n->name = xstrdup (symname);
1152 h = bfd_link_hash_lookup (link_info.hash, symname, FALSE, FALSE,
1154 if (h == NULL || h->type == bfd_link_hash_new)
1156 /* We can just ignore attempts to import an unreferenced
1161 if (!bfd_xcoff_import_symbol (output_bfd, &link_info, h,
1162 address, imppath, impfile,
1163 impmember, syscall_flag))
1164 einfo ("%X%s:%d: failed to import symbol %s: %E\n",
1165 filename, lineno, symname);
1169 obstack_free (o, obstack_base (o));
1172 if (obstack_object_size (o) > 0)
1174 einfo ("%s:%d: warning: ignoring unterminated last line\n",
1176 obstack_free (o, obstack_base (o));
1181 obstack_free (o, NULL);
1186 /* This routine saves us from worrying about declaring free. */
1189 gld${EMULATION_NAME}_free (void *p)
1194 /* This is called by the before_allocation routine via
1195 lang_for_each_statement. It looks for relocations and assignments
1199 gld${EMULATION_NAME}_find_relocs (lang_statement_union_type *s)
1201 if (s->header.type == lang_reloc_statement_enum)
1203 lang_reloc_statement_type *rs;
1205 rs = &s->reloc_statement;
1206 if (rs->name == NULL)
1207 einfo ("%F%P: only relocations against symbols are permitted\n");
1208 if (!bfd_xcoff_link_count_reloc (output_bfd, &link_info, rs->name))
1209 einfo ("%F%P: bfd_xcoff_link_count_reloc failed: %E\n");
1212 if (s->header.type == lang_assignment_statement_enum)
1213 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1216 /* Look through an expression for an assignment statement. */
1219 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1221 struct bfd_link_hash_entry *h;
1223 switch (exp->type.node_class)
1226 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst,
1227 FALSE, FALSE, FALSE);
1232 if (strcmp (exp->assign.dst, ".") != 0)
1234 if (!bfd_xcoff_record_link_assignment (output_bfd, &link_info,
1236 einfo ("%P%F: failed to record assignment to %s: %E\n",
1239 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1243 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1244 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1248 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1249 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1250 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1254 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1263 gld${EMULATION_NAME}_get_script (int *isfile)
1266 if test -n "$COMPILE_IN"
1268 # Scripts compiled in.
1270 # sed commands to quote an ld script as a C string.
1271 sc="-f ${srcdir}/emultempl/ostring.sed"
1273 cat >>e${EMULATION_NAME}.c <<EOF
1277 if (link_info.relocatable && config.build_constructors)
1280 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1281 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1282 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1283 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1284 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1285 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1286 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1287 echo ' ; else return' >> e${EMULATION_NAME}.c
1288 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1289 echo '; }' >> e${EMULATION_NAME}.c
1292 # Scripts read from the filesystem.
1294 cat >>e${EMULATION_NAME}.c <<EOF
1298 if (link_info.relocatable && config.build_constructors)
1299 return "ldscripts/${EMULATION_NAME}.xu";
1300 else if (link_info.relocatable)
1301 return "ldscripts/${EMULATION_NAME}.xr";
1302 else if (!config.text_read_only)
1303 return "ldscripts/${EMULATION_NAME}.xbn";
1304 else if (!config.magic_demand_paged)
1305 return "ldscripts/${EMULATION_NAME}.xn";
1307 return "ldscripts/${EMULATION_NAME}.x";
1313 cat >>e${EMULATION_NAME}.c <<EOF
1316 gld${EMULATION_NAME}_create_output_section_statements (void)
1319 if ((bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour)
1320 && (link_info.init_function != NULL
1321 || link_info.fini_function != NULL
1324 initfini_file = lang_add_input_file ("initfini",
1325 lang_input_file_is_file_enum,
1328 initfini_file->the_bfd = bfd_create ("initfini", output_bfd);
1329 if (initfini_file->the_bfd == NULL
1330 || ! bfd_set_arch_mach (initfini_file->the_bfd,
1331 bfd_get_arch (output_bfd),
1332 bfd_get_mach (output_bfd)))
1334 einfo ("%X%P: can not create BFD %E\n");
1338 /* Call backend to fill in the rest */
1339 if (! bfd_xcoff_link_generate_rtinit (initfini_file->the_bfd,
1340 link_info.init_function,
1341 link_info.fini_function,
1344 einfo ("%X%P: can not create BFD %E\n");
1348 /* __rtld defined in /lib/librtl.a */
1350 lang_add_input_file ("rtl", lang_input_file_is_l_enum, NULL);
1355 gld${EMULATION_NAME}_set_output_arch (void)
1357 bfd_set_arch_mach (output_bfd,
1358 bfd_xcoff_architecture (output_bfd),
1359 bfd_xcoff_machine (output_bfd));
1361 ldfile_output_architecture = bfd_get_arch (output_bfd);
1362 ldfile_output_machine = bfd_get_mach (output_bfd);
1363 ldfile_output_machine_name = bfd_printable_name (output_bfd);
1366 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = {
1367 gld${EMULATION_NAME}_before_parse,
1370 after_parse_default,
1371 gld${EMULATION_NAME}_after_open,
1372 after_allocation_default,
1373 gld${EMULATION_NAME}_set_output_arch,
1374 gld${EMULATION_NAME}_choose_target,
1375 gld${EMULATION_NAME}_before_allocation,
1376 gld${EMULATION_NAME}_get_script,
1377 "${EMULATION_NAME}",
1380 gld${EMULATION_NAME}_create_output_section_statements,
1381 0, /* open_dynamic_archive */
1382 0, /* place_orphan */
1383 0, /* set_symbols */
1384 gld${EMULATION_NAME}_parse_args,
1385 gld${EMULATION_NAME}_add_options,
1386 gld${EMULATION_NAME}_handle_option,
1387 gld${EMULATION_NAME}_unrecognized_file,
1388 NULL, /* list_options */
1389 NULL, /* recognized_file */
1390 NULL, /* find potential_libraries */
1391 NULL /* new_vers_pattern */