1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 rm -f e${EMULATION_NAME}.c
4 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
5 cat >>e${EMULATION_NAME}.c <<EOF
6 /* This file is part of GLD, the Gnu Linker.
7 Copyright 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* The original file generated returned different default scripts depending
25 on whether certain switches were set, but these switches pertain to the
26 Linux system and that particular version of coff. In the NT case, we
27 only determine if the subsystem is console or windows in order to select
28 the correct entry point by default. */
34 #include "libiberty.h"
45 #include "coff/internal.h"
47 /* FIXME: This is a BFD internal header file, and we should not be
49 #include "../bfd/libcoff.h"
54 #define TARGET_IS_${EMULATION_NAME}
56 /* Permit the emulation parameters to override the default section
57 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
58 it seem that include/coff/internal.h should not define
59 PE_DEF_SECTION_ALIGNMENT. */
60 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
61 #undef PE_DEF_SECTION_ALIGNMENT
62 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
65 #if defined(TARGET_IS_i386pe)
68 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe) || defined(TARGET_IS_armpe)
72 #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
73 #define PE_DEF_SUBSYSTEM 3
75 #undef NT_EXE_IMAGE_BASE
76 #undef PE_DEF_SECTION_ALIGNMENT
77 #undef PE_DEF_FILE_ALIGNMENT
78 #define NT_EXE_IMAGE_BASE 0x00010000
79 #ifdef TARGET_IS_armpe
80 #define PE_DEF_SECTION_ALIGNMENT 0x00001000
81 #define PE_DEF_SUBSYSTEM 9
83 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
84 #define PE_DEF_SUBSYSTEM 2
86 #define PE_DEF_FILE_ALIGNMENT 0x00000200
89 #ifdef TARGET_IS_arm_epoc_pe
90 #define bfd_arm_pe_allocate_interworking_sections \
91 bfd_arm_epoc_pe_allocate_interworking_sections
92 #define bfd_arm_pe_get_bfd_for_interworking \
93 bfd_arm_epoc_pe_get_bfd_for_interworking
94 #define bfd_arm_pe_process_before_allocation \
95 bfd_arm_epoc_pe_process_before_allocation
98 static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
99 static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
100 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
101 static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
102 static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
103 static boolean gld_${EMULATION_NAME}_place_orphan
104 PARAMS ((lang_input_statement_type *, asection *));
105 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
106 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
107 static void gld_${EMULATION_NAME}_finish PARAMS ((void));
108 static boolean gld_${EMULATION_NAME}_open_dynamic_archive
109 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
111 static struct internal_extra_pe_aouthdr pe;
113 static int support_old_code = 0;
114 static char * thumb_entry_symbol = NULL;
115 static lang_assignment_statement_type *image_base_statement = 0;
118 static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */
119 static char *pe_out_def_filename = NULL;
120 static char *pe_implib_filename = NULL;
121 static int pe_enable_auto_image_base = 0;
122 static char *pe_dll_search_prefix = NULL;
125 extern const char *output_filename;
128 gld_${EMULATION_NAME}_before_parse()
130 output_filename = "${EXECUTABLE_NAME:-a.exe}";
131 ldfile_output_architecture = bfd_arch_${ARCH};
133 config.has_shared = 1;
135 #if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
136 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
137 lang_add_entry ("WinMainCRTStartup", 1);
139 lang_add_entry ("_WinMainCRTStartup", 1);
145 /* PE format extra command line options. */
147 /* Used for setting flags in the PE header. */
148 #define OPTION_BASE_FILE (300 + 1)
149 #define OPTION_DLL (OPTION_BASE_FILE + 1)
150 #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
151 #define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
152 #define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
153 #define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
154 #define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
155 #define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
156 #define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
157 #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
158 #define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
159 #define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
160 #define OPTION_SUBSYSTEM (OPTION_STACK + 1)
161 #define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
162 #define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
163 #define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
164 #define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
165 #define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
166 #define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
167 #define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
168 #define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
169 #define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
170 #define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1)
171 #define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1)
172 #define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
173 #define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
174 #define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1)
175 #define OPTION_DISABLE_AUTO_IMAGE_BASE (OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
176 #define OPTION_DLL_SEARCH_PREFIX (OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
178 static struct option longopts[] =
181 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
182 {"dll", no_argument, NULL, OPTION_DLL},
183 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
184 {"heap", required_argument, NULL, OPTION_HEAP},
185 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
186 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
187 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
188 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
189 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
190 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
191 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
192 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
193 {"stack", required_argument, NULL, OPTION_STACK},
194 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
195 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
196 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
198 /* getopt allows abbreviations, so we do this to stop it from treating -o
199 as an abbreviation for this option */
200 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
201 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
202 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
203 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
204 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
205 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
206 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
207 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
208 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
209 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
210 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
211 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
212 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
213 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
215 {NULL, no_argument, NULL, 0}
219 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
220 parameters which may be input from the command line */
231 #define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
233 static definfo init[] =
235 /* imagebase must be first */
236 #define IMAGEBASEOFF 0
237 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
239 {&dll, sizeof(dll), 0, "__dll__", 0},
240 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
241 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
242 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
243 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
244 D(MajorImageVersion,"__major_image_version__", 1),
245 D(MinorImageVersion,"__minor_image_version__", 0),
246 #ifdef TARGET_IS_armpe
247 D(MajorSubsystemVersion,"__major_subsystem_version__", 2),
249 D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
251 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
252 D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
253 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
254 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
255 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
256 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
257 D(LoaderFlags,"__loader_flags__", 0x0),
258 { NULL, 0, 0, NULL, 0 }
262 gld_${EMULATION_NAME}_list_options (file)
265 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
266 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
267 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
268 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
269 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
270 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
271 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
272 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
273 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
274 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
275 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
276 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
277 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
278 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
279 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
280 fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
282 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
283 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
284 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
285 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
286 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
287 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
288 fprintf (file, _(" --out-implib <file> Generate import library\n"));
289 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
290 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
291 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n"));
292 fprintf (file, _(" create __imp_<SYMBOL> as well.\n"));
293 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n"));
294 fprintf (file, _(" unless user specifies one\n"));
295 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
296 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll witout an\n"));
297 fprintf (file, _(" importlib, use <string><basename>.dll \n"));
298 fprintf (file, _(" in preference to lib<basename>.dll \n"));
303 set_pe_name (name, val)
308 /* Find the name and set it. */
309 for (i = 0; init[i].ptr; i++)
311 if (strcmp (name, init[i].symbol) == 0)
336 { "native", 1, "NtProcessStartup" },
337 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
338 { "windows", 2, "WinMainCRTStartup" },
340 { "windows", 2, "WinMainCRTStartup" },
342 { "console", 3, "mainCRTStartup" },
344 /* The Microsoft linker does not recognize this. */
347 { "posix", 7, "__PosixProcessStartup"},
348 { "wince", 9, "_WinMainCRTStartup" },
352 sver = strchr (optarg, ':');
354 len = strlen (optarg);
360 set_pe_name ("__major_subsystem_version__",
361 strtoul (sver + 1, &end, 0));
363 set_pe_name ("__minor_subsystem_version__",
364 strtoul (end + 1, &end, 0));
366 einfo (_("%P: warning: bad version number in -subsystem option\n"));
369 for (i = 0; v[i].name; i++)
371 if (strncmp (optarg, v[i].name, len) == 0
372 && v[i].name[len] == '\0')
374 const char *initial_symbol_char;
377 set_pe_name ("__subsystem__", v[i].value);
379 initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
380 if (*initial_symbol_char == '\0')
386 /* lang_add_entry expects its argument to be permanently
387 allocated, so we don't free this string. */
388 alc_entry = xmalloc (strlen (initial_symbol_char)
389 + strlen (v[i].entry)
391 strcpy (alc_entry, initial_symbol_char);
392 strcat (alc_entry, v[i].entry);
396 lang_add_entry (entry, 1);
402 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
414 set_pe_name (name, strtoul (optarg, &end, 0));
417 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
423 set_pe_stack_heap (resname, comname)
427 set_pe_value (resname);
432 set_pe_value (comname);
435 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
441 gld_${EMULATION_NAME}_parse_args(argc, argv)
447 int prevoptind = optind;
448 int prevopterr = opterr;
450 static int lastoptind = -1;
452 if (lastoptind != optind)
458 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
469 case OPTION_BASE_FILE:
470 link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
471 if (link_info.base_file == NULL)
473 /* xgettext:c-format */
474 fprintf (stderr, _("%s: Can't open base file %s\n"),
475 program_name, optarg);
482 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
485 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
487 case OPTION_SUBSYSTEM:
490 case OPTION_MAJOR_OS_VERSION:
491 set_pe_value ("__major_os_version__");
493 case OPTION_MINOR_OS_VERSION:
494 set_pe_value ("__minor_os_version__");
496 case OPTION_MAJOR_SUBSYSTEM_VERSION:
497 set_pe_value ("__major_subsystem_version__");
499 case OPTION_MINOR_SUBSYSTEM_VERSION:
500 set_pe_value ("__minor_subsystem_version__");
502 case OPTION_MAJOR_IMAGE_VERSION:
503 set_pe_value ("__major_image_version__");
505 case OPTION_MINOR_IMAGE_VERSION:
506 set_pe_value ("__minor_image_version__");
508 case OPTION_FILE_ALIGNMENT:
509 set_pe_value ("__file_alignment__");
511 case OPTION_SECTION_ALIGNMENT:
512 set_pe_value ("__section_alignment__");
515 set_pe_name ("__dll__", 1);
517 case OPTION_IMAGE_BASE:
518 set_pe_value ("__image_base__");
520 case OPTION_SUPPORT_OLD_CODE:
521 support_old_code = 1;
523 case OPTION_THUMB_ENTRY:
524 thumb_entry_symbol = optarg;
528 pe_out_def_filename = xstrdup (optarg);
530 case OPTION_EXPORT_ALL:
531 pe_dll_export_everything = 1;
533 case OPTION_EXCLUDE_SYMBOLS:
534 pe_dll_add_excludes (optarg);
536 case OPTION_KILL_ATS:
539 case OPTION_STDCALL_ALIASES:
540 pe_dll_stdcall_aliases = 1;
542 case OPTION_ENABLE_STDCALL_FIXUP:
543 pe_enable_stdcall_fixup = 1;
545 case OPTION_DISABLE_STDCALL_FIXUP:
546 pe_enable_stdcall_fixup = 0;
548 case OPTION_IMPLIB_FILENAME:
549 pe_implib_filename = xstrdup (optarg);
551 case OPTION_WARN_DUPLICATE_EXPORTS:
552 pe_dll_warn_dup_exports = 1;
554 case OPTION_IMP_COMPAT:
555 pe_dll_compat_implib = 1;
557 case OPTION_ENABLE_AUTO_IMAGE_BASE:
558 pe_enable_auto_image_base = 1;
560 case OPTION_DISABLE_AUTO_IMAGE_BASE:
561 pe_enable_auto_image_base = 0;
563 case OPTION_DLL_SEARCH_PREFIX:
564 pe_dll_search_prefix = xstrdup( optarg );
574 strhash (const char *str)
576 const unsigned char *s;
583 s = (const unsigned char *) str;
584 while ((c = *s++) != '\0')
586 hash += c + (c << 17);
590 hash += len + (len << 17);
596 /* Use the output file to create a image base for relocatable DLLs. */
598 compute_dll_image_base (const char *ofile)
600 unsigned long hash = strhash (ofile);
601 return 0x60000000 | ((hash << 16) & 0x0FFC0000);
605 /* Assign values to the special symbols before the linker script is
609 gld_${EMULATION_NAME}_set_symbols ()
611 /* Run through and invent symbols for all the
612 names and insert the defaults. */
614 lang_statement_list_type *save;
616 if (!init[IMAGEBASEOFF].inited)
618 if (link_info.relocateable)
619 init[IMAGEBASEOFF].value = 0;
620 else if (init[DLLOFF].value || link_info.shared)
622 init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?
623 compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
625 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
628 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
631 /* Don't do any symbol assignments if this is a relocateable link. */
632 if (link_info.relocateable)
635 /* Glue the assignments into the abs section */
638 stat_ptr = &(abs_output_section->children);
640 for (j = 0; init[j].ptr; j++)
642 long val = init[j].value;
643 lang_assignment_statement_type *rv;
644 rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
645 if (init[j].size == sizeof(short))
646 *(short *)init[j].ptr = val;
647 else if (init[j].size == sizeof(int))
648 *(int *)init[j].ptr = val;
649 else if (init[j].size == sizeof(long))
650 *(long *)init[j].ptr = val;
651 /* This might be a long long or other special type. */
652 else if (init[j].size == sizeof(bfd_vma))
653 *(bfd_vma *)init[j].ptr = val;
655 if (j == IMAGEBASEOFF)
656 image_base_statement = rv;
658 /* Restore the pointer. */
661 if (pe.FileAlignment >
664 einfo (_("%P: warning, file alignment > section alignment.\n"));
668 /* This is called after the linker script and the command line options
672 gld_${EMULATION_NAME}_after_parse ()
674 /* The Windows libraries are designed for the linker to treat the
675 entry point as an undefined symbol. Otherwise, the .obj that
676 defines mainCRTStartup is brought in because it is the first
677 encountered in libc.lib and it has other symbols in it which will
678 be pulled in by the link process. To avoid this, we act as
679 though the user specified -u with the entry point symbol.
681 This function is called after the linker script and command line
682 options have been read, so at this point we know the right entry
683 point. This function is called before the input files are
684 opened, so registering the symbol as undefined will make a
687 if (! link_info.relocateable && entry_symbol != NULL)
688 ldlang_add_undef (entry_symbol);
692 static struct bfd_link_hash_entry *pe_undef_found_sym;
695 pe_undef_cdecl_match (h, string)
696 struct bfd_link_hash_entry *h;
699 int sl = strlen (string);
700 if (h->type == bfd_link_hash_defined
701 && strncmp (h->root.string, string, sl) == 0
702 && h->root.string[sl] == '@')
704 pe_undef_found_sym = h;
713 static int gave_warning_message = 0;
714 struct bfd_link_hash_entry *undef, *sym;
716 for (undef = link_info.hash->undefs; undef; undef=undef->next)
717 if (undef->type == bfd_link_hash_undefined)
719 at = strchr (undef->root.string, '@');
722 /* The symbol is a stdcall symbol, so let's look for a cdecl
723 symbol with the same name and resolve to that */
724 char *cname = xstrdup (undef->root.string);
725 at = strchr (cname, '@');
727 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
728 if (sym && sym->type == bfd_link_hash_defined)
730 undef->type = bfd_link_hash_defined;
731 undef->u.def.value = sym->u.def.value;
732 undef->u.def.section = sym->u.def.section;
733 if (pe_enable_stdcall_fixup == -1)
735 einfo (_("Warning: resolving %s by linking to %s\n"),
736 undef->root.string, cname);
737 if (! gave_warning_message)
739 gave_warning_message = 1;
740 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
741 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
748 /* The symbol is a cdecl symbol, so we look for stdcall
749 symbols - which means scanning the whole symbol table */
750 pe_undef_found_sym = 0;
751 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
752 (PTR) undef->root.string);
753 sym = pe_undef_found_sym;
756 undef->type = bfd_link_hash_defined;
757 undef->u.def.value = sym->u.def.value;
758 undef->u.def.section = sym->u.def.section;
759 if (pe_enable_stdcall_fixup == -1)
761 einfo (_("Warning: resolving %s by linking to %s\n"),
762 undef->root.string, sym->root.string);
763 if (! gave_warning_message)
765 gave_warning_message = 1;
766 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
767 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
774 #endif /* DLL_SUPPORT */
777 gld_${EMULATION_NAME}_after_open ()
779 /* Pass the wacky PE command line options into the output bfd.
780 FIXME: This should be done via a function, rather than by
781 including an internal BFD header. */
783 if (!coff_data (output_bfd)->pe)
784 einfo (_("%F%P: PE operations on non PE file.\n"));
786 pe_data (output_bfd)->pe_opthdr = pe;
787 pe_data (output_bfd)->dll = init[DLLOFF].value;
790 if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
791 pe_fixup_stdcalls ();
793 pe_process_import_defs(output_bfd, &link_info);
794 if (link_info.shared)
795 pe_dll_build_sections (output_bfd, &link_info);
797 #ifndef TARGET_IS_i386pe
798 #ifndef TARGET_IS_armpe
800 pe_exe_build_sections (output_bfd, &link_info);
805 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
806 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
808 /* The arm backend needs special fields in the output hash structure.
809 These will only be created if the output format is an arm format,
810 hence we do not support linking and changing output formats at the
811 same time. Use a link followed by objcopy to change output formats. */
812 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
816 /* Find a BFD that can hold the interworking stubs. */
817 LANG_FOR_EACH_INPUT_STATEMENT (is)
819 if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))
826 /* This next chunk of code tries to detect the case where you have
827 two import libraries for the same DLL (specifically,
828 symbolically linking libm.a and libc.a in cygwin to
829 libcygwin.a). In those cases, it's possible for function
830 thunks from the second implib to be used but without the
831 head/tail objects, causing an improper import table. We detect
832 those cases and rename the "other" import libraries to match
833 the one the head/tail come from, so that the linker will sort
834 things nicely and produce a valid import table. */
836 LANG_FOR_EACH_INPUT_STATEMENT (is)
838 if (is->the_bfd->my_archive)
840 int idata2 = 0, reloc_count=0, is_imp = 0;
842 /* See if this is an import library thunk */
843 for (sec = is->the_bfd->sections; sec; sec = sec->next)
845 if (strcmp (sec->name, ".idata\$2") == 0)
847 if (strncmp (sec->name, ".idata\$", 7) == 0)
849 reloc_count += sec->reloc_count;
851 if (is_imp && !idata2 && reloc_count)
853 /* it is, look for the reference to head and see if it's
854 from our own library */
855 for (sec = is->the_bfd->sections; sec; sec = sec->next)
864 symsize = bfd_get_symtab_upper_bound (is->the_bfd);
865 symbols = (asymbol **) xmalloc (symsize);
866 bfd_canonicalize_symtab (is->the_bfd, symbols);
867 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
868 relocs = (arelent **) xmalloc ((size_t) relsize);
869 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
871 for (i=0; i<nrelocs; i++)
873 struct symbol_cache_entry *s;
874 s = (relocs[i]->sym_ptr_ptr)[0];
875 if (!s->flags & BSF_LOCAL)
877 /* thunk section with reloc to another bfd... */
878 struct bfd_link_hash_entry *blhe;
879 blhe = bfd_link_hash_lookup (link_info.hash,
882 if (blhe && blhe->type == bfd_link_hash_defined)
884 bfd *other_bfd = blhe->u.def.section->owner;
885 if (strcmp (is->the_bfd->my_archive->filename,
886 other_bfd->my_archive->filename))
888 /* Rename this implib to match the other */
889 char *n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
890 strcpy (n, other_bfd->my_archive->filename);
891 is->the_bfd->my_archive->filename = n;
907 lang_input_statement_type *is2;
909 /* Careful - this is a shell script. Watch those dollar signs! */
910 /* Microsoft import libraries have every member named the same,
911 and not in the right order for us to link them correctly. We
912 must detect these and rename the members so that they'll link
913 correctly. There are three types of objects: the head, the
914 thunks, and the sentinel(s). The head is easy; it's the one
915 with idata2. We assume that the sentinels won't have relocs,
916 and the thunks will. It's easier than checking the symbol
917 table for external references. */
918 LANG_FOR_EACH_INPUT_STATEMENT (is)
920 if (is->the_bfd->my_archive)
922 bfd *arch = is->the_bfd->my_archive;
923 if (cur_arch != arch)
928 is2 && is2->the_bfd->my_archive == arch;
929 is2 = (lang_input_statement_type *)is2->next)
931 if (strcmp (is->the_bfd->filename, is2->the_bfd->filename))
938 int idata2 = 0, reloc_count=0;
942 for (sec = is->the_bfd->sections; sec; sec = sec->next)
944 if (strcmp (sec->name, ".idata\$2") == 0)
946 reloc_count += sec->reloc_count;
949 if (idata2) /* .idata2 is the TOC */
951 else if (reloc_count > 0) /* thunks */
956 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
957 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
958 is->the_bfd->filename = new_name;
960 new_name = xmalloc (strlen (is->filename) + 3);
961 sprintf (new_name, "%s.%c", is->filename, seq);
962 is->filename = new_name;
970 gld_${EMULATION_NAME}_before_allocation()
972 #ifdef TARGET_IS_ppcpe
973 /* Here we rummage through the found bfds to collect toc information */
975 LANG_FOR_EACH_INPUT_STATEMENT (is)
977 if (!ppc_process_before_allocation (is->the_bfd, &link_info))
979 /* xgettext:c-format */
980 einfo (_("Errors encountered processing file %s\n"), is->filename);
985 /* We have seen it all. Allocate it, and carry on */
986 ppc_allocate_toc_section (&link_info);
987 #endif /* TARGET_IS_ppcpe */
989 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
990 /* FIXME: we should be able to set the size of the interworking stub
993 Here we rummage through the found bfds to collect glue
994 information. FIXME: should this be based on a command line
995 option? krk@cygnus.com */
997 LANG_FOR_EACH_INPUT_STATEMENT (is)
999 if (! bfd_arm_pe_process_before_allocation
1000 (is->the_bfd, & link_info, support_old_code))
1002 /* xgettext:c-format */
1003 einfo (_("Errors encountered processing file %s for interworking"),
1009 /* We have seen it all. Allocate it, and carry on */
1010 bfd_arm_pe_allocate_interworking_sections (& link_info);
1011 #endif /* TARGET_IS_armpe */
1015 /* This is called when an input file isn't recognized as a BFD. We
1016 check here for .DEF files and pull them in automatically. */
1019 saw_option(char *option)
1022 for (i=0; init[i].ptr; i++)
1023 if (strcmp (init[i].symbol, option) == 0)
1024 return init[i].inited;
1027 #endif /* DLL_SUPPORT */
1030 gld_${EMULATION_NAME}_unrecognized_file(entry)
1031 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1034 const char *ext = entry->filename + strlen (entry->filename) - 4;
1036 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
1038 if (pe_def_file == 0)
1039 pe_def_file = def_file_empty ();
1040 def_file_parse (entry->filename, pe_def_file);
1043 int i, buflen=0, len;
1045 for (i=0; i<pe_def_file->num_exports; i++)
1047 len = strlen(pe_def_file->exports[i].internal_name);
1051 buf = (char *) xmalloc (buflen);
1052 for (i=0; i<pe_def_file->num_exports; i++)
1054 struct bfd_link_hash_entry *h;
1055 sprintf(buf, "_%s", pe_def_file->exports[i].internal_name);
1057 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1058 if (h == (struct bfd_link_hash_entry *) NULL)
1059 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1060 if (h->type == bfd_link_hash_new)
1062 h->type = bfd_link_hash_undefined;
1063 h->u.undef.abfd = NULL;
1064 bfd_link_add_undef (link_info.hash, h);
1069 /* def_file_print (stdout, pe_def_file); */
1070 if (pe_def_file->is_dll == 1)
1071 link_info.shared = 1;
1073 if (pe_def_file->base_address != (bfd_vma)(-1))
1076 pe_data (output_bfd)->pe_opthdr.ImageBase =
1077 init[IMAGEBASEOFF].value = pe_def_file->base_address;
1078 init[IMAGEBASEOFF].inited = 1;
1079 if (image_base_statement)
1080 image_base_statement->exp =
1081 exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
1085 /* Not sure if these *should* be set */
1086 if (pe_def_file->version_major != -1)
1088 pe.MajorImageVersion = pe_def_file->version_major;
1089 pe.MinorImageVersion = pe_def_file->version_minor;
1092 if (pe_def_file->stack_reserve != -1
1093 && ! saw_option ("__size_of_stack_reserve__"))
1095 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
1096 if (pe_def_file->stack_commit != -1)
1097 pe.SizeOfStackCommit = pe_def_file->stack_commit;
1099 if (pe_def_file->heap_reserve != -1
1100 && ! saw_option ("__size_of_heap_reserve__"))
1102 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
1103 if (pe_def_file->heap_commit != -1)
1104 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
1115 gld_${EMULATION_NAME}_recognized_file(entry)
1116 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1119 #ifdef TARGET_IS_i386pe
1120 pe_dll_id_target ("pei-i386");
1122 #ifdef TARGET_IS_shpe
1123 pe_dll_id_target ("pei-shl");
1125 #ifdef TARGET_IS_mipspe
1126 pe_dll_id_target ("pei-mips");
1128 #ifdef TARGET_IS_armpe
1129 pe_dll_id_target ("pei-arm-little");
1131 if (bfd_get_format (entry->the_bfd) == bfd_object)
1133 const char *ext = entry->filename + strlen (entry->filename) - 4;
1134 if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
1135 return pe_implied_import_dll (entry->filename);
1142 gld_${EMULATION_NAME}_finish ()
1144 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
1145 struct bfd_link_hash_entry * h;
1147 if (thumb_entry_symbol != NULL)
1149 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
1151 if (h != (struct bfd_link_hash_entry *) NULL
1152 && (h->type == bfd_link_hash_defined
1153 || h->type == bfd_link_hash_defweak)
1154 && h->u.def.section->output_section != NULL)
1156 static char buffer[32];
1159 /* Special procesing is required for a Thumb entry symbol. The
1160 bottom bit of its address must be set. */
1161 val = (h->u.def.value
1162 + bfd_get_section_vma (output_bfd,
1163 h->u.def.section->output_section)
1164 + h->u.def.section->output_offset);
1168 /* Now convert this value into a string and store it in entry_symbol
1169 where the lang_finish() function will pick it up. */
1173 sprintf_vma (buffer + 2, val);
1175 if (entry_symbol != NULL && entry_from_cmdline)
1176 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
1177 thumb_entry_symbol, entry_symbol);
1178 entry_symbol = buffer;
1181 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
1183 #endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) */
1186 if (link_info.shared)
1188 pe_dll_fill_sections (output_bfd, &link_info);
1189 if (pe_implib_filename)
1190 pe_dll_generate_implib (pe_def_file, pe_implib_filename);
1192 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe)
1193 /* ARM doesn't need relocs. */
1196 pe_exe_fill_sections (output_bfd, &link_info);
1200 if (pe_out_def_filename)
1201 pe_dll_generate_def_file (pe_out_def_filename);
1202 #endif /* DLL_SUPPORT */
1206 /* Place an orphan section.
1208 We use this to put sections in a reasonable place in the file, and
1209 to ensure that they are aligned as required.
1211 We handle grouped sections here as well. A section named .foo$nn
1212 goes into the output section .foo. All grouped sections are sorted
1215 Grouped sections for the default sections are handled by the
1216 default linker script using wildcards, and are sorted by
1221 lang_output_section_statement_type *os;
1223 lang_statement_union_type **stmt;
1228 gld_${EMULATION_NAME}_place_orphan (file, s)
1229 lang_input_statement_type *file;
1232 const char *secname;
1233 char *hold_section_name;
1234 char *dollar = NULL;
1235 lang_output_section_statement_type *os;
1236 lang_statement_list_type add_child;
1238 secname = bfd_get_section_name (s->owner, s);
1240 /* Look through the script to see where to place this section. */
1242 hold_section_name = xstrdup (secname);
1243 if (!link_info.relocateable)
1245 dollar = strchr (hold_section_name, '$');
1250 os = lang_output_section_find (hold_section_name);
1252 lang_list_init (&add_child);
1255 && os->bfd_section != NULL
1256 && ((s->flags ^ os->bfd_section->flags) & (SEC_LOAD | SEC_ALLOC)) == 0)
1258 wild_doit (&add_child, s, os, file);
1262 struct orphan_save *place;
1263 static struct orphan_save hold_text;
1264 static struct orphan_save hold_rdata;
1265 static struct orphan_save hold_data;
1266 static struct orphan_save hold_bss;
1268 lang_statement_list_type *old;
1269 lang_statement_list_type add;
1270 etree_type *address;
1272 /* Try to put the new output section in a reasonable place based
1273 on the section name and section flags. */
1274 #define HAVE_SECTION(hold, name) \
1275 (hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL)
1278 if ((s->flags & SEC_ALLOC) == 0)
1280 else if ((s->flags & SEC_HAS_CONTENTS) == 0
1281 && HAVE_SECTION (hold_bss, ".bss"))
1283 else if ((s->flags & SEC_READONLY) == 0
1284 && HAVE_SECTION (hold_data, ".data"))
1286 else if ((s->flags & SEC_CODE) == 0
1287 && (s->flags & SEC_READONLY) != 0
1288 && HAVE_SECTION (hold_rdata, ".rdata"))
1289 place = &hold_rdata;
1290 else if ((s->flags & SEC_READONLY) != 0
1291 && HAVE_SECTION (hold_text, ".text"))
1296 /* Choose a unique name for the section. This will be needed if
1297 the same section name appears in the input file with
1298 different loadable or allocateable characteristics. */
1299 outsecname = xstrdup (hold_section_name);
1300 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
1306 len = strlen (outsecname);
1307 newname = xmalloc (len + 5);
1308 strcpy (newname, outsecname);
1312 sprintf (newname + len, "%d", i);
1315 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
1318 outsecname = newname;
1321 /* Start building a list of statements for this section. */
1324 lang_list_init (stat_ptr);
1326 if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
1327 address = exp_intop ((bfd_vma) 0);
1330 /* All sections in an executable must be aligned to a page
1332 address = exp_unop (ALIGN_K,
1333 exp_nameop (NAME, "__section_alignment__"));
1336 os = lang_enter_output_section_statement (outsecname, address, 0,
1338 (etree_type *) NULL,
1339 (etree_type *) NULL,
1340 (etree_type *) NULL);
1342 wild_doit (&add_child, s, os, file);
1344 lang_leave_output_section_statement
1345 ((bfd_vma) 0, "*default*",
1346 (struct lang_output_section_phdr_list *) NULL, "*default*");
1352 asection *snew, **pps;
1354 snew = os->bfd_section;
1355 if (place->os->bfd_section != NULL || place->section != NULL)
1357 /* Shuffle the section to make the output file look neater. */
1358 if (place->section == NULL)
1361 /* Finding the end of the list is a little tricky. We
1362 make a wild stab at it by comparing section flags. */
1363 flagword first_flags = place->os->bfd_section->flags;
1364 for (pps = &place->os->bfd_section->next;
1365 *pps != NULL && (*pps)->flags == first_flags;
1366 pps = &(*pps)->next)
1368 place->section = pps;
1370 /* Put orphans after the first section on the list. */
1371 place->section = &place->os->bfd_section->next;
1375 /* Unlink the section. */
1376 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
1380 /* Now tack it on to the "place->os" section list. */
1381 snew->next = *place->section;
1382 *place->section = snew;
1384 place->section = &snew->next; /* Save the end of this list. */
1386 if (place->stmt == NULL)
1388 /* Put the new statement list right at the head. */
1389 *add.tail = place->os->header.next;
1390 place->os->header.next = add.head;
1394 /* Put it after the last orphan statement we added. */
1395 *add.tail = *place->stmt;
1396 *place->stmt = add.head;
1398 place->stmt = add.tail; /* Save the end of this list. */
1403 lang_statement_union_type **pl = &os->children.head;
1407 boolean found_dollar;
1409 /* The section name has a '$'. Sort it with the other '$'
1412 found_dollar = false;
1413 for ( ; *pl != NULL; pl = &(*pl)->next)
1415 lang_input_section_type *ls;
1418 if ((*pl)->header.type != lang_input_section_enum)
1421 ls = &(*pl)->input_section;
1423 lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
1424 if (strchr (lname, '$') == NULL)
1431 found_dollar = true;
1432 if (strcmp (secname, lname) < 0)
1438 if (add_child.head != NULL)
1440 add_child.head->next = *pl;
1441 *pl = add_child.head;
1445 free (hold_section_name);
1451 gld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
1452 const char * arch ATTRIBUTE_UNUSED;
1453 search_dirs_type * search;
1454 lang_input_statement_type * entry;
1456 const char * filename;
1459 if (! entry->is_archive)
1462 filename = entry->filename;
1464 string = (char *) xmalloc (strlen (search->name)
1466 + sizeof "/lib.a.dll"
1468 + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
1472 /* Try "libfoo.dll.a" first (preferred explicit import library for dll's */
1473 sprintf (string, "%s/lib%s.dll.a", search->name, filename);
1475 if (! ldfile_try_open_bfd (string, entry))
1477 /* Try "foo.dll.a" next (alternate explicit import library for dll's */
1478 sprintf (string, "%s/%s.dll.a", search->name, filename);
1479 if (! ldfile_try_open_bfd (string, entry))
1482 Try libfoo.a next. Normally, this would be interpreted as a static
1483 library, but it *could* be an import library. For backwards compatibility,
1484 libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search,
1485 or sometimes errors occur when building legacy packages.
1487 Putting libfoo.a here means that in a failure case (i.e. the library
1488 -lfoo is not found) we will search for libfoo.a twice before
1489 giving up -- once here, and once when searching for a "static" lib.
1492 /* Try "libfoo.a" (import lib, or static lib, but must
1493 take precedence over dll's) */
1494 sprintf (string, "%s/lib%s.a", search->name, filename);
1495 if (! ldfile_try_open_bfd (string, entry))
1498 if (pe_dll_search_prefix)
1500 /* Try "<prefix>foo.dll" (preferred dll name, if specified) */
1501 sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
1502 if (! ldfile_try_open_bfd (string, entry))
1504 /* Try "libfoo.dll" (default preferred dll name) */
1505 sprintf (string, "%s/lib%s.dll", search->name, filename);
1506 if (! ldfile_try_open_bfd (string, entry))
1508 /* Finally, try "foo.dll" (alternate dll name) */
1509 sprintf (string, "%s/%s.dll", search->name, filename);
1510 if (! ldfile_try_open_bfd (string, entry))
1518 else /* pe_dll_search_prefix not specified */
1521 /* Try "libfoo.dll" (preferred dll name) */
1522 sprintf (string, "%s/lib%s.dll", search->name, filename);
1523 if (! ldfile_try_open_bfd (string, entry))
1525 /* Finally, try "foo.dll" (alternate dll name) */
1526 sprintf (string, "%s/%s.dll", search->name, filename);
1527 if (! ldfile_try_open_bfd (string, entry))
1538 entry->filename = string;
1544 gld_${EMULATION_NAME}_find_potential_libraries (name, entry)
1546 lang_input_statement_type * entry;
1548 return ldfile_open_file_search (name, entry, "", ".lib");
1552 gld_${EMULATION_NAME}_get_script(isfile)
1555 # Scripts compiled in.
1556 # sed commands to quote an ld script as a C string.
1557 sc="-f stringify.sed"
1559 cat >>e${EMULATION_NAME}.c <<EOF
1563 if (link_info.relocateable == true && config.build_constructors == true)
1566 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1567 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1568 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1569 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1570 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1571 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1572 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1573 echo ' ; else return' >> e${EMULATION_NAME}.c
1574 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1575 echo '; }' >> e${EMULATION_NAME}.c
1577 cat >>e${EMULATION_NAME}.c <<EOF
1580 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1582 gld_${EMULATION_NAME}_before_parse,
1585 gld_${EMULATION_NAME}_after_parse,
1586 gld_${EMULATION_NAME}_after_open,
1587 after_allocation_default,
1588 set_output_arch_default,
1589 ldemul_default_target,
1590 gld_${EMULATION_NAME}_before_allocation,
1591 gld_${EMULATION_NAME}_get_script,
1592 "${EMULATION_NAME}",
1594 gld_${EMULATION_NAME}_finish, /* finish */
1595 NULL, /* create output section statements */
1596 gld_${EMULATION_NAME}_open_dynamic_archive,
1597 gld_${EMULATION_NAME}_place_orphan,
1598 gld_${EMULATION_NAME}_set_symbols,
1599 gld_${EMULATION_NAME}_parse_args,
1600 gld_${EMULATION_NAME}_unrecognized_file,
1601 gld_${EMULATION_NAME}_list_options,
1602 gld_${EMULATION_NAME}_recognized_file,
1603 gld_${EMULATION_NAME}_find_potential_libraries