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 rm -f e${EMULATION_NAME}.c
9 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
10 cat >>e${EMULATION_NAME}.c <<EOF
11 /* This file is part of GLD, the Gnu Linker.
12 Copyright 1995, 1996, 1997, 1998, 1999, 2000
13 Free Software Foundation, Inc.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 /* The original file generated returned different default scripts depending
31 on whether certain switches were set, but these switches pertain to the
32 Linux system and that particular version of coff. In the NT case, we
33 only determine if the subsystem is console or windows in order to select
34 the correct entry point by default. */
40 #include "libiberty.h"
51 #include "coff/internal.h"
53 /* FIXME: This is a BFD internal header file, and we should not be
55 #include "../bfd/libcoff.h"
62 #define TARGET_IS_${EMULATION_NAME}
64 /* Permit the emulation parameters to override the default section
65 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
66 it seem that include/coff/internal.h should not define
67 PE_DEF_SECTION_ALIGNMENT. */
68 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
69 #undef PE_DEF_SECTION_ALIGNMENT
70 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
73 #if defined(TARGET_IS_i386pe)
76 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe) || defined(TARGET_IS_armpe)
80 #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
81 #define PE_DEF_SUBSYSTEM 3
83 #undef NT_EXE_IMAGE_BASE
84 #undef PE_DEF_SECTION_ALIGNMENT
85 #undef PE_DEF_FILE_ALIGNMENT
86 #define NT_EXE_IMAGE_BASE 0x00010000
87 #ifdef TARGET_IS_armpe
88 #define PE_DEF_SECTION_ALIGNMENT 0x00001000
89 #define PE_DEF_SUBSYSTEM 9
91 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
92 #define PE_DEF_SUBSYSTEM 2
94 #define PE_DEF_FILE_ALIGNMENT 0x00000200
97 #ifdef TARGET_IS_arm_epoc_pe
98 #define bfd_arm_pe_allocate_interworking_sections \
99 bfd_arm_epoc_pe_allocate_interworking_sections
100 #define bfd_arm_pe_get_bfd_for_interworking \
101 bfd_arm_epoc_pe_get_bfd_for_interworking
102 #define bfd_arm_pe_process_before_allocation \
103 bfd_arm_epoc_pe_process_before_allocation
106 static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
107 static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
108 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
109 static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
110 static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
111 static boolean gld_${EMULATION_NAME}_place_orphan
112 PARAMS ((lang_input_statement_type *, asection *));
113 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
114 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
115 static void gld_${EMULATION_NAME}_finish PARAMS ((void));
116 static boolean gld_${EMULATION_NAME}_open_dynamic_archive
117 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
119 static struct internal_extra_pe_aouthdr pe;
121 static int support_old_code = 0;
122 static char * thumb_entry_symbol = NULL;
123 static lang_assignment_statement_type *image_base_statement = 0;
126 static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */
127 static char *pe_out_def_filename = NULL;
128 static char *pe_implib_filename = NULL;
129 static int pe_enable_auto_image_base = 0;
130 static char *pe_dll_search_prefix = NULL;
133 extern const char *output_filename;
136 gld_${EMULATION_NAME}_before_parse()
138 const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
141 ldfile_output_architecture = arch->arch;
142 ldfile_output_machine = arch->mach;
143 ldfile_output_machine_name = arch->printable_name;
146 ldfile_output_architecture = bfd_arch_${ARCH};
147 output_filename = "${EXECUTABLE_NAME:-a.exe}";
149 config.has_shared = 1;
151 #if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
152 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
153 lang_add_entry ("WinMainCRTStartup", 1);
155 lang_add_entry ("_WinMainCRTStartup", 1);
161 /* PE format extra command line options. */
163 /* Used for setting flags in the PE header. */
164 #define OPTION_BASE_FILE (300 + 1)
165 #define OPTION_DLL (OPTION_BASE_FILE + 1)
166 #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
167 #define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
168 #define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
169 #define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
170 #define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
171 #define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
172 #define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
173 #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
174 #define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
175 #define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
176 #define OPTION_SUBSYSTEM (OPTION_STACK + 1)
177 #define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
178 #define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
179 #define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
180 #define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
181 #define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
182 #define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
183 #define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
184 #define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
185 #define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
186 #define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1)
187 #define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1)
188 #define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
189 #define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
190 #define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1)
191 #define OPTION_DISABLE_AUTO_IMAGE_BASE (OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
192 #define OPTION_DLL_SEARCH_PREFIX (OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
193 #define OPTION_NO_DEFAULT_EXCLUDES (OPTION_DLL_SEARCH_PREFIX + 1)
195 static struct option longopts[] = {
197 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
198 {"dll", no_argument, NULL, OPTION_DLL},
199 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
200 {"heap", required_argument, NULL, OPTION_HEAP},
201 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
202 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
203 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
204 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
205 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
206 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
207 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
208 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
209 {"stack", required_argument, NULL, OPTION_STACK},
210 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
211 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
212 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
214 /* getopt allows abbreviations, so we do this to stop it from treating -o
215 as an abbreviation for this option */
216 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
217 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
218 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
219 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
220 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
221 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
222 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
223 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
224 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
225 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
226 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
227 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
228 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
229 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
230 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
232 {NULL, no_argument, NULL, 0}
236 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
237 parameters which may be input from the command line */
248 #define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
250 static definfo init[] =
252 /* imagebase must be first */
253 #define IMAGEBASEOFF 0
254 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
256 {&dll, sizeof(dll), 0, "__dll__", 0},
257 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
258 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
259 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
260 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
261 D(MajorImageVersion,"__major_image_version__", 1),
262 D(MinorImageVersion,"__minor_image_version__", 0),
263 #ifdef TARGET_IS_armpe
264 D(MajorSubsystemVersion,"__major_subsystem_version__", 2),
266 D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
268 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
269 D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
270 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000),
271 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
272 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
273 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
274 D(LoaderFlags,"__loader_flags__", 0x0),
275 { NULL, 0, 0, NULL, 0 }
279 gld_${EMULATION_NAME}_list_options (file)
282 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
283 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
284 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
285 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
286 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
287 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
288 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
289 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
290 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
291 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
292 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
293 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
294 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
295 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
296 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
297 fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
299 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
300 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
301 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
302 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
303 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
304 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
305 fprintf (file, _(" --out-implib <file> Generate import library\n"));
306 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
307 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
308 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n"));
309 fprintf (file, _(" create __imp_<SYMBOL> as well.\n"));
310 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n"));
311 fprintf (file, _(" unless user specifies one\n"));
312 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
313 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll witout an\n"));
314 fprintf (file, _(" importlib, use <string><basename>.dll \n"));
315 fprintf (file, _(" in preference to lib<basename>.dll \n"));
320 set_pe_name (name, val)
325 /* Find the name and set it. */
326 for (i = 0; init[i].ptr; i++)
328 if (strcmp (name, init[i].symbol) == 0)
353 { "native", 1, "NtProcessStartup" },
354 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
355 { "windows", 2, "WinMainCRTStartup" },
357 { "windows", 2, "WinMainCRTStartup" },
359 { "console", 3, "mainCRTStartup" },
361 /* The Microsoft linker does not recognize this. */
364 { "posix", 7, "__PosixProcessStartup"},
365 { "wince", 9, "_WinMainCRTStartup" },
369 sver = strchr (optarg, ':');
371 len = strlen (optarg);
377 set_pe_name ("__major_subsystem_version__",
378 strtoul (sver + 1, &end, 0));
380 set_pe_name ("__minor_subsystem_version__",
381 strtoul (end + 1, &end, 0));
383 einfo (_("%P: warning: bad version number in -subsystem option\n"));
386 for (i = 0; v[i].name; i++)
388 if (strncmp (optarg, v[i].name, len) == 0
389 && v[i].name[len] == '\0')
391 const char *initial_symbol_char;
394 set_pe_name ("__subsystem__", v[i].value);
396 initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
397 if (*initial_symbol_char == '\0')
403 /* lang_add_entry expects its argument to be permanently
404 allocated, so we don't free this string. */
405 alc_entry = xmalloc (strlen (initial_symbol_char)
406 + strlen (v[i].entry)
408 strcpy (alc_entry, initial_symbol_char);
409 strcat (alc_entry, v[i].entry);
413 lang_add_entry (entry, 1);
419 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
431 set_pe_name (name, strtoul (optarg, &end, 0));
434 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
440 set_pe_stack_heap (resname, comname)
444 set_pe_value (resname);
449 set_pe_value (comname);
452 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
458 gld_${EMULATION_NAME}_parse_args(argc, argv)
464 int prevoptind = optind;
465 int prevopterr = opterr;
467 static int lastoptind = -1;
469 if (lastoptind != optind)
475 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
486 case OPTION_BASE_FILE:
487 link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
488 if (link_info.base_file == NULL)
490 /* xgettext:c-format */
491 fprintf (stderr, _("%s: Can't open base file %s\n"),
492 program_name, optarg);
499 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
502 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
504 case OPTION_SUBSYSTEM:
507 case OPTION_MAJOR_OS_VERSION:
508 set_pe_value ("__major_os_version__");
510 case OPTION_MINOR_OS_VERSION:
511 set_pe_value ("__minor_os_version__");
513 case OPTION_MAJOR_SUBSYSTEM_VERSION:
514 set_pe_value ("__major_subsystem_version__");
516 case OPTION_MINOR_SUBSYSTEM_VERSION:
517 set_pe_value ("__minor_subsystem_version__");
519 case OPTION_MAJOR_IMAGE_VERSION:
520 set_pe_value ("__major_image_version__");
522 case OPTION_MINOR_IMAGE_VERSION:
523 set_pe_value ("__minor_image_version__");
525 case OPTION_FILE_ALIGNMENT:
526 set_pe_value ("__file_alignment__");
528 case OPTION_SECTION_ALIGNMENT:
529 set_pe_value ("__section_alignment__");
532 set_pe_name ("__dll__", 1);
534 case OPTION_IMAGE_BASE:
535 set_pe_value ("__image_base__");
537 case OPTION_SUPPORT_OLD_CODE:
538 support_old_code = 1;
540 case OPTION_THUMB_ENTRY:
541 thumb_entry_symbol = optarg;
545 pe_out_def_filename = xstrdup (optarg);
547 case OPTION_EXPORT_ALL:
548 pe_dll_export_everything = 1;
550 case OPTION_EXCLUDE_SYMBOLS:
551 pe_dll_add_excludes (optarg);
553 case OPTION_KILL_ATS:
556 case OPTION_STDCALL_ALIASES:
557 pe_dll_stdcall_aliases = 1;
559 case OPTION_ENABLE_STDCALL_FIXUP:
560 pe_enable_stdcall_fixup = 1;
562 case OPTION_DISABLE_STDCALL_FIXUP:
563 pe_enable_stdcall_fixup = 0;
565 case OPTION_IMPLIB_FILENAME:
566 pe_implib_filename = xstrdup (optarg);
568 case OPTION_WARN_DUPLICATE_EXPORTS:
569 pe_dll_warn_dup_exports = 1;
571 case OPTION_IMP_COMPAT:
572 pe_dll_compat_implib = 1;
574 case OPTION_ENABLE_AUTO_IMAGE_BASE:
575 pe_enable_auto_image_base = 1;
577 case OPTION_DISABLE_AUTO_IMAGE_BASE:
578 pe_enable_auto_image_base = 0;
580 case OPTION_DLL_SEARCH_PREFIX:
581 pe_dll_search_prefix = xstrdup( optarg );
583 case OPTION_NO_DEFAULT_EXCLUDES:
584 pe_dll_do_default_excludes = 0;
594 strhash (const char *str)
596 const unsigned char *s;
603 s = (const unsigned char *) str;
604 while ((c = *s++) != '\0')
606 hash += c + (c << 17);
610 hash += len + (len << 17);
616 /* Use the output file to create a image base for relocatable DLLs. */
618 compute_dll_image_base (const char *ofile)
620 unsigned long hash = strhash (ofile);
621 return 0x60000000 | ((hash << 16) & 0x0FFC0000);
625 /* Assign values to the special symbols before the linker script is
629 gld_${EMULATION_NAME}_set_symbols ()
631 /* Run through and invent symbols for all the
632 names and insert the defaults. */
634 lang_statement_list_type *save;
636 if (!init[IMAGEBASEOFF].inited)
638 if (link_info.relocateable)
639 init[IMAGEBASEOFF].value = 0;
640 else if (init[DLLOFF].value || link_info.shared)
642 init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?
643 compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
645 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
648 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
651 /* Don't do any symbol assignments if this is a relocateable link. */
652 if (link_info.relocateable)
655 /* Glue the assignments into the abs section */
658 stat_ptr = &(abs_output_section->children);
660 for (j = 0; init[j].ptr; j++)
662 long val = init[j].value;
663 lang_assignment_statement_type *rv;
664 rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
665 if (init[j].size == sizeof(short))
666 *(short *)init[j].ptr = val;
667 else if (init[j].size == sizeof(int))
668 *(int *)init[j].ptr = val;
669 else if (init[j].size == sizeof(long))
670 *(long *)init[j].ptr = val;
671 /* This might be a long long or other special type. */
672 else if (init[j].size == sizeof(bfd_vma))
673 *(bfd_vma *)init[j].ptr = val;
675 if (j == IMAGEBASEOFF)
676 image_base_statement = rv;
678 /* Restore the pointer. */
681 if (pe.FileAlignment >
684 einfo (_("%P: warning, file alignment > section alignment.\n"));
688 /* This is called after the linker script and the command line options
692 gld_${EMULATION_NAME}_after_parse ()
694 /* The Windows libraries are designed for the linker to treat the
695 entry point as an undefined symbol. Otherwise, the .obj that
696 defines mainCRTStartup is brought in because it is the first
697 encountered in libc.lib and it has other symbols in it which will
698 be pulled in by the link process. To avoid this, we act as
699 though the user specified -u with the entry point symbol.
701 This function is called after the linker script and command line
702 options have been read, so at this point we know the right entry
703 point. This function is called before the input files are
704 opened, so registering the symbol as undefined will make a
707 if (! link_info.relocateable && entry_symbol != NULL)
708 ldlang_add_undef (entry_symbol);
712 static struct bfd_link_hash_entry *pe_undef_found_sym;
715 pe_undef_cdecl_match (h, string)
716 struct bfd_link_hash_entry *h;
719 int sl = strlen (string);
720 if (h->type == bfd_link_hash_defined
721 && strncmp (h->root.string, string, sl) == 0
722 && h->root.string[sl] == '@')
724 pe_undef_found_sym = h;
733 static int gave_warning_message = 0;
734 struct bfd_link_hash_entry *undef, *sym;
736 for (undef = link_info.hash->undefs; undef; undef=undef->next)
737 if (undef->type == bfd_link_hash_undefined)
739 at = strchr (undef->root.string, '@');
742 /* The symbol is a stdcall symbol, so let's look for a cdecl
743 symbol with the same name and resolve to that */
744 char *cname = xstrdup (undef->root.string);
745 at = strchr (cname, '@');
747 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
748 if (sym && sym->type == bfd_link_hash_defined)
750 undef->type = bfd_link_hash_defined;
751 undef->u.def.value = sym->u.def.value;
752 undef->u.def.section = sym->u.def.section;
753 if (pe_enable_stdcall_fixup == -1)
755 einfo (_("Warning: resolving %s by linking to %s\n"),
756 undef->root.string, cname);
757 if (! gave_warning_message)
759 gave_warning_message = 1;
760 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
761 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
768 /* The symbol is a cdecl symbol, so we look for stdcall
769 symbols - which means scanning the whole symbol table */
770 pe_undef_found_sym = 0;
771 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
772 (PTR) undef->root.string);
773 sym = pe_undef_found_sym;
776 undef->type = bfd_link_hash_defined;
777 undef->u.def.value = sym->u.def.value;
778 undef->u.def.section = sym->u.def.section;
779 if (pe_enable_stdcall_fixup == -1)
781 einfo (_("Warning: resolving %s by linking to %s\n"),
782 undef->root.string, sym->root.string);
783 if (! gave_warning_message)
785 gave_warning_message = 1;
786 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
787 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
794 #endif /* DLL_SUPPORT */
797 gld_${EMULATION_NAME}_after_open ()
799 /* Pass the wacky PE command line options into the output bfd.
800 FIXME: This should be done via a function, rather than by
801 including an internal BFD header. */
803 if (!coff_data (output_bfd)->pe)
804 einfo (_("%F%P: PE operations on non PE file.\n"));
806 pe_data (output_bfd)->pe_opthdr = pe;
807 pe_data (output_bfd)->dll = init[DLLOFF].value;
810 if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
811 pe_fixup_stdcalls ();
813 pe_process_import_defs(output_bfd, &link_info);
814 if (link_info.shared)
815 pe_dll_build_sections (output_bfd, &link_info);
817 #ifndef TARGET_IS_i386pe
818 #ifndef TARGET_IS_armpe
820 pe_exe_build_sections (output_bfd, &link_info);
825 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
826 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
828 /* The arm backend needs special fields in the output hash structure.
829 These will only be created if the output format is an arm format,
830 hence we do not support linking and changing output formats at the
831 same time. Use a link followed by objcopy to change output formats. */
832 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
836 /* Find a BFD that can hold the interworking stubs. */
837 LANG_FOR_EACH_INPUT_STATEMENT (is)
839 if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))
846 /* This next chunk of code tries to detect the case where you have
847 two import libraries for the same DLL (specifically,
848 symbolically linking libm.a and libc.a in cygwin to
849 libcygwin.a). In those cases, it's possible for function
850 thunks from the second implib to be used but without the
851 head/tail objects, causing an improper import table. We detect
852 those cases and rename the "other" import libraries to match
853 the one the head/tail come from, so that the linker will sort
854 things nicely and produce a valid import table. */
856 LANG_FOR_EACH_INPUT_STATEMENT (is)
858 if (is->the_bfd->my_archive)
860 int idata2 = 0, reloc_count=0, is_imp = 0;
863 /* See if this is an import library thunk. */
864 for (sec = is->the_bfd->sections; sec; sec = sec->next)
866 if (strcmp (sec->name, ".idata\$2") == 0)
868 if (strncmp (sec->name, ".idata\$", 7) == 0)
870 reloc_count += sec->reloc_count;
873 if (is_imp && !idata2 && reloc_count)
875 /* It is, look for the reference to head and see if it's
876 from our own library. */
877 for (sec = is->the_bfd->sections; sec; sec = sec->next)
886 symsize = bfd_get_symtab_upper_bound (is->the_bfd);
889 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
893 symbols = (asymbol **) xmalloc (symsize);
894 symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
897 einfo ("%X%P: unable to process symbols: %E");
901 relocs = (arelent **) xmalloc ((size_t) relsize);
902 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
907 einfo ("%X%P: unable to process relocs: %E");
911 for (i = 0; i < nrelocs; i++)
913 struct symbol_cache_entry *s;
914 struct bfd_link_hash_entry * blhe;
918 s = (relocs[i]->sym_ptr_ptr)[0];
920 if (s->flags & BSF_LOCAL)
923 /* Thunk section with reloc to another bfd. */
924 blhe = bfd_link_hash_lookup (link_info.hash,
929 || blhe->type != bfd_link_hash_defined)
932 other_bfd = blhe->u.def.section->owner;
934 if (strcmp (is->the_bfd->my_archive->filename,
935 other_bfd->my_archive->filename) == 0)
938 /* Rename this implib to match the other. */
939 n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
941 strcpy (n, other_bfd->my_archive->filename);
943 is->the_bfd->my_archive->filename = n;
947 /* Note - we do not free the symbols,
948 they are now cached in the BFD. */
958 lang_input_statement_type *is2;
960 /* Careful - this is a shell script. Watch those dollar signs! */
961 /* Microsoft import libraries have every member named the same,
962 and not in the right order for us to link them correctly. We
963 must detect these and rename the members so that they'll link
964 correctly. There are three types of objects: the head, the
965 thunks, and the sentinel(s). The head is easy; it's the one
966 with idata2. We assume that the sentinels won't have relocs,
967 and the thunks will. It's easier than checking the symbol
968 table for external references. */
969 LANG_FOR_EACH_INPUT_STATEMENT (is)
971 if (is->the_bfd->my_archive)
973 bfd *arch = is->the_bfd->my_archive;
974 if (cur_arch != arch)
979 is2 && is2->the_bfd->my_archive == arch;
980 is2 = (lang_input_statement_type *)is2->next)
982 if (strcmp (is->the_bfd->filename, is2->the_bfd->filename))
989 int idata2 = 0, reloc_count=0;
993 for (sec = is->the_bfd->sections; sec; sec = sec->next)
995 if (strcmp (sec->name, ".idata\$2") == 0)
997 reloc_count += sec->reloc_count;
1000 if (idata2) /* .idata2 is the TOC */
1002 else if (reloc_count > 0) /* thunks */
1007 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1008 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1009 is->the_bfd->filename = new_name;
1011 new_name = xmalloc (strlen (is->filename) + 3);
1012 sprintf (new_name, "%s.%c", is->filename, seq);
1013 is->filename = new_name;
1021 gld_${EMULATION_NAME}_before_allocation()
1023 #ifdef TARGET_IS_ppcpe
1024 /* Here we rummage through the found bfds to collect toc information */
1026 LANG_FOR_EACH_INPUT_STATEMENT (is)
1028 if (!ppc_process_before_allocation (is->the_bfd, &link_info))
1030 /* xgettext:c-format */
1031 einfo (_("Errors encountered processing file %s\n"), is->filename);
1036 /* We have seen it all. Allocate it, and carry on */
1037 ppc_allocate_toc_section (&link_info);
1038 #endif /* TARGET_IS_ppcpe */
1040 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
1041 /* FIXME: we should be able to set the size of the interworking stub
1044 Here we rummage through the found bfds to collect glue
1045 information. FIXME: should this be based on a command line
1046 option? krk@cygnus.com */
1048 LANG_FOR_EACH_INPUT_STATEMENT (is)
1050 if (! bfd_arm_pe_process_before_allocation
1051 (is->the_bfd, & link_info, support_old_code))
1053 /* xgettext:c-format */
1054 einfo (_("Errors encountered processing file %s for interworking"),
1060 /* We have seen it all. Allocate it, and carry on */
1061 bfd_arm_pe_allocate_interworking_sections (& link_info);
1062 #endif /* TARGET_IS_armpe */
1066 /* This is called when an input file isn't recognized as a BFD. We
1067 check here for .DEF files and pull them in automatically. */
1070 saw_option(char *option)
1073 for (i=0; init[i].ptr; i++)
1074 if (strcmp (init[i].symbol, option) == 0)
1075 return init[i].inited;
1078 #endif /* DLL_SUPPORT */
1081 gld_${EMULATION_NAME}_unrecognized_file(entry)
1082 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1085 const char *ext = entry->filename + strlen (entry->filename) - 4;
1087 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
1089 if (pe_def_file == 0)
1090 pe_def_file = def_file_empty ();
1091 def_file_parse (entry->filename, pe_def_file);
1094 int i, buflen=0, len;
1096 for (i=0; i<pe_def_file->num_exports; i++)
1098 len = strlen(pe_def_file->exports[i].internal_name);
1102 buf = (char *) xmalloc (buflen);
1103 for (i=0; i<pe_def_file->num_exports; i++)
1105 struct bfd_link_hash_entry *h;
1106 sprintf(buf, "_%s", pe_def_file->exports[i].internal_name);
1108 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1109 if (h == (struct bfd_link_hash_entry *) NULL)
1110 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1111 if (h->type == bfd_link_hash_new)
1113 h->type = bfd_link_hash_undefined;
1114 h->u.undef.abfd = NULL;
1115 bfd_link_add_undef (link_info.hash, h);
1120 /* def_file_print (stdout, pe_def_file); */
1121 if (pe_def_file->is_dll == 1)
1122 link_info.shared = 1;
1124 if (pe_def_file->base_address != (bfd_vma)(-1))
1127 pe_data (output_bfd)->pe_opthdr.ImageBase =
1128 init[IMAGEBASEOFF].value = pe_def_file->base_address;
1129 init[IMAGEBASEOFF].inited = 1;
1130 if (image_base_statement)
1131 image_base_statement->exp =
1132 exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
1136 /* Not sure if these *should* be set */
1137 if (pe_def_file->version_major != -1)
1139 pe.MajorImageVersion = pe_def_file->version_major;
1140 pe.MinorImageVersion = pe_def_file->version_minor;
1143 if (pe_def_file->stack_reserve != -1
1144 && ! saw_option ("__size_of_stack_reserve__"))
1146 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
1147 if (pe_def_file->stack_commit != -1)
1148 pe.SizeOfStackCommit = pe_def_file->stack_commit;
1150 if (pe_def_file->heap_reserve != -1
1151 && ! saw_option ("__size_of_heap_reserve__"))
1153 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
1154 if (pe_def_file->heap_commit != -1)
1155 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
1166 gld_${EMULATION_NAME}_recognized_file(entry)
1167 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1170 #ifdef TARGET_IS_i386pe
1171 pe_dll_id_target ("pei-i386");
1173 #ifdef TARGET_IS_shpe
1174 pe_dll_id_target ("pei-shl");
1176 #ifdef TARGET_IS_mipspe
1177 pe_dll_id_target ("pei-mips");
1179 #ifdef TARGET_IS_armpe
1180 pe_dll_id_target ("pei-arm-little");
1182 if (bfd_get_format (entry->the_bfd) == bfd_object)
1184 const char *ext = entry->filename + strlen (entry->filename) - 4;
1185 if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
1186 return pe_implied_import_dll (entry->filename);
1193 gld_${EMULATION_NAME}_finish ()
1195 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
1196 struct bfd_link_hash_entry * h;
1198 if (thumb_entry_symbol != NULL)
1200 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
1202 if (h != (struct bfd_link_hash_entry *) NULL
1203 && (h->type == bfd_link_hash_defined
1204 || h->type == bfd_link_hash_defweak)
1205 && h->u.def.section->output_section != NULL)
1207 static char buffer[32];
1210 /* Special procesing is required for a Thumb entry symbol. The
1211 bottom bit of its address must be set. */
1212 val = (h->u.def.value
1213 + bfd_get_section_vma (output_bfd,
1214 h->u.def.section->output_section)
1215 + h->u.def.section->output_offset);
1219 /* Now convert this value into a string and store it in entry_symbol
1220 where the lang_finish() function will pick it up. */
1224 sprintf_vma (buffer + 2, val);
1226 if (entry_symbol != NULL && entry_from_cmdline)
1227 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
1228 thumb_entry_symbol, entry_symbol);
1229 entry_symbol = buffer;
1232 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
1234 #endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) */
1237 if (link_info.shared)
1239 pe_dll_fill_sections (output_bfd, &link_info);
1240 if (pe_implib_filename)
1241 pe_dll_generate_implib (pe_def_file, pe_implib_filename);
1243 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe)
1244 /* ARM doesn't need relocs. */
1247 pe_exe_fill_sections (output_bfd, &link_info);
1251 if (pe_out_def_filename)
1252 pe_dll_generate_def_file (pe_out_def_filename);
1253 #endif /* DLL_SUPPORT */
1257 /* Place an orphan section.
1259 We use this to put sections in a reasonable place in the file, and
1260 to ensure that they are aligned as required.
1262 We handle grouped sections here as well. A section named .foo$nn
1263 goes into the output section .foo. All grouped sections are sorted
1266 Grouped sections for the default sections are handled by the
1267 default linker script using wildcards, and are sorted by
1272 lang_output_section_statement_type *os;
1274 lang_statement_union_type **stmt;
1279 gld_${EMULATION_NAME}_place_orphan (file, s)
1280 lang_input_statement_type *file;
1283 const char *secname;
1284 char *hold_section_name;
1285 char *dollar = NULL;
1286 const char *ps = NULL;
1287 lang_output_section_statement_type *os;
1288 lang_statement_list_type add_child;
1290 secname = bfd_get_section_name (s->owner, s);
1292 /* Look through the script to see where to place this section. */
1294 hold_section_name = xstrdup (secname);
1295 if (!link_info.relocateable)
1297 dollar = strchr (hold_section_name, '$');
1302 os = lang_output_section_find (hold_section_name);
1304 lang_list_init (&add_child);
1307 && os->bfd_section != NULL
1308 && ((s->flags ^ os->bfd_section->flags) & (SEC_LOAD | SEC_ALLOC)) == 0)
1310 wild_doit (&add_child, s, os, file);
1314 struct orphan_save *place;
1315 static struct orphan_save hold_text;
1316 static struct orphan_save hold_rdata;
1317 static struct orphan_save hold_data;
1318 static struct orphan_save hold_bss;
1320 lang_statement_list_type *old;
1321 lang_statement_list_type add;
1322 etree_type *address;
1324 /* Try to put the new output section in a reasonable place based
1325 on the section name and section flags. */
1326 #define HAVE_SECTION(hold, name) \
1327 (hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL)
1330 if ((s->flags & SEC_ALLOC) == 0)
1332 else if ((s->flags & SEC_HAS_CONTENTS) == 0
1333 && HAVE_SECTION (hold_bss, ".bss"))
1335 else if ((s->flags & SEC_READONLY) == 0
1336 && HAVE_SECTION (hold_data, ".data"))
1338 else if ((s->flags & SEC_CODE) == 0
1339 && (s->flags & SEC_READONLY) != 0
1340 && HAVE_SECTION (hold_rdata, ".rdata"))
1341 place = &hold_rdata;
1342 else if ((s->flags & SEC_READONLY) != 0
1343 && HAVE_SECTION (hold_text, ".text"))
1348 /* Choose a unique name for the section. This will be needed if
1349 the same section name appears in the input file with
1350 different loadable or allocateable characteristics. */
1351 outsecname = xstrdup (hold_section_name);
1352 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
1358 len = strlen (outsecname);
1359 newname = xmalloc (len + 5);
1360 strcpy (newname, outsecname);
1364 sprintf (newname + len, "%d", i);
1367 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
1370 outsecname = newname;
1373 /* Start building a list of statements for this section. */
1376 lang_list_init (stat_ptr);
1378 if (config.build_constructors)
1380 /* If the name of the section is representable in C, then create
1381 symbols to mark the start and the end of the section. */
1382 for (ps = outsecname; *ps != '\0'; ps++)
1383 if (! isalnum ((unsigned char) *ps) && *ps != '_')
1388 etree_type *e_align;
1390 symname = (char *) xmalloc (ps - outsecname + sizeof "___start_");
1391 sprintf (symname, "___start_%s", outsecname);
1392 e_align = exp_unop (ALIGN_K,
1393 exp_intop ((bfd_vma) 1 << s->alignment_power));
1394 lang_add_assignment (exp_assop ('=', symname, e_align));
1398 if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
1399 address = exp_intop ((bfd_vma) 0);
1402 /* All sections in an executable must be aligned to a page
1404 address = exp_unop (ALIGN_K,
1405 exp_nameop (NAME, "__section_alignment__"));
1408 os = lang_enter_output_section_statement (outsecname, address, 0,
1410 (etree_type *) NULL,
1411 (etree_type *) NULL,
1412 (etree_type *) NULL);
1414 wild_doit (&add_child, s, os, file);
1416 lang_leave_output_section_statement
1417 ((bfd_vma) 0, "*default*",
1418 (struct lang_output_section_phdr_list *) NULL, "*default*");
1420 if (config.build_constructors && *ps == '\0')
1424 /* lang_leave_ouput_section_statement resets stat_ptr. Put
1425 stat_ptr back where we want it. */
1429 symname = (char *) xmalloc (ps - outsecname + sizeof "___stop_");
1430 sprintf (symname, "___stop_%s", outsecname);
1431 lang_add_assignment (exp_assop ('=', symname,
1432 exp_nameop (NAME, ".")));
1439 asection *snew, **pps;
1441 snew = os->bfd_section;
1442 if (place->os->bfd_section != NULL || place->section != NULL)
1444 /* Shuffle the section to make the output file look neater. */
1445 if (place->section == NULL)
1448 /* Finding the end of the list is a little tricky. We
1449 make a wild stab at it by comparing section flags. */
1450 flagword first_flags = place->os->bfd_section->flags;
1451 for (pps = &place->os->bfd_section->next;
1452 *pps != NULL && (*pps)->flags == first_flags;
1453 pps = &(*pps)->next)
1455 place->section = pps;
1457 /* Put orphans after the first section on the list. */
1458 place->section = &place->os->bfd_section->next;
1462 /* Unlink the section. */
1463 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
1467 /* Now tack it on to the "place->os" section list. */
1468 snew->next = *place->section;
1469 *place->section = snew;
1471 place->section = &snew->next; /* Save the end of this list. */
1473 if (place->stmt == NULL)
1475 /* Put the new statement list right at the head. */
1476 *add.tail = place->os->header.next;
1477 place->os->header.next = add.head;
1481 /* Put it after the last orphan statement we added. */
1482 *add.tail = *place->stmt;
1483 *place->stmt = add.head;
1485 place->stmt = add.tail; /* Save the end of this list. */
1490 lang_statement_union_type **pl = &os->children.head;
1494 boolean found_dollar;
1496 /* The section name has a '$'. Sort it with the other '$'
1499 found_dollar = false;
1500 for ( ; *pl != NULL; pl = &(*pl)->next)
1502 lang_input_section_type *ls;
1505 if ((*pl)->header.type != lang_input_section_enum)
1508 ls = &(*pl)->input_section;
1510 lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
1511 if (strchr (lname, '$') == NULL)
1518 found_dollar = true;
1519 if (strcmp (secname, lname) < 0)
1525 if (add_child.head != NULL)
1527 add_child.head->next = *pl;
1528 *pl = add_child.head;
1532 free (hold_section_name);
1538 gld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
1539 const char * arch ATTRIBUTE_UNUSED;
1540 search_dirs_type * search;
1541 lang_input_statement_type * entry;
1543 const char * filename;
1546 if (! entry->is_archive)
1549 filename = entry->filename;
1551 string = (char *) xmalloc (strlen (search->name)
1553 + sizeof "/lib.a.dll"
1555 + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
1559 /* Try "libfoo.dll.a" first (preferred explicit import library for dll's */
1560 sprintf (string, "%s/lib%s.dll.a", search->name, filename);
1562 if (! ldfile_try_open_bfd (string, entry))
1564 /* Try "foo.dll.a" next (alternate explicit import library for dll's */
1565 sprintf (string, "%s/%s.dll.a", search->name, filename);
1566 if (! ldfile_try_open_bfd (string, entry))
1569 Try libfoo.a next. Normally, this would be interpreted as a static
1570 library, but it *could* be an import library. For backwards compatibility,
1571 libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search,
1572 or sometimes errors occur when building legacy packages.
1574 Putting libfoo.a here means that in a failure case (i.e. the library
1575 -lfoo is not found) we will search for libfoo.a twice before
1576 giving up -- once here, and once when searching for a "static" lib.
1579 /* Try "libfoo.a" (import lib, or static lib, but must
1580 take precedence over dll's) */
1581 sprintf (string, "%s/lib%s.a", search->name, filename);
1582 if (! ldfile_try_open_bfd (string, entry))
1585 if (pe_dll_search_prefix)
1587 /* Try "<prefix>foo.dll" (preferred dll name, if specified) */
1588 sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
1589 if (! ldfile_try_open_bfd (string, entry))
1591 /* Try "libfoo.dll" (default preferred dll name) */
1592 sprintf (string, "%s/lib%s.dll", search->name, filename);
1593 if (! ldfile_try_open_bfd (string, entry))
1595 /* Finally, try "foo.dll" (alternate dll name) */
1596 sprintf (string, "%s/%s.dll", search->name, filename);
1597 if (! ldfile_try_open_bfd (string, entry))
1605 else /* pe_dll_search_prefix not specified */
1608 /* Try "libfoo.dll" (preferred dll name) */
1609 sprintf (string, "%s/lib%s.dll", search->name, filename);
1610 if (! ldfile_try_open_bfd (string, entry))
1612 /* Finally, try "foo.dll" (alternate dll name) */
1613 sprintf (string, "%s/%s.dll", search->name, filename);
1614 if (! ldfile_try_open_bfd (string, entry))
1625 entry->filename = string;
1631 gld_${EMULATION_NAME}_find_potential_libraries (name, entry)
1633 lang_input_statement_type * entry;
1635 return ldfile_open_file_search (name, entry, "", ".lib");
1639 gld_${EMULATION_NAME}_get_script(isfile)
1642 # Scripts compiled in.
1643 # sed commands to quote an ld script as a C string.
1644 sc="-f stringify.sed"
1646 cat >>e${EMULATION_NAME}.c <<EOF
1650 if (link_info.relocateable == true && config.build_constructors == true)
1653 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1654 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1655 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1656 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1657 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1658 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1659 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1660 echo ' ; else return' >> e${EMULATION_NAME}.c
1661 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1662 echo '; }' >> e${EMULATION_NAME}.c
1664 cat >>e${EMULATION_NAME}.c <<EOF
1667 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1669 gld_${EMULATION_NAME}_before_parse,
1672 gld_${EMULATION_NAME}_after_parse,
1673 gld_${EMULATION_NAME}_after_open,
1674 after_allocation_default,
1675 set_output_arch_default,
1676 ldemul_default_target,
1677 gld_${EMULATION_NAME}_before_allocation,
1678 gld_${EMULATION_NAME}_get_script,
1679 "${EMULATION_NAME}",
1681 gld_${EMULATION_NAME}_finish, /* finish */
1682 NULL, /* create output section statements */
1683 gld_${EMULATION_NAME}_open_dynamic_archive,
1684 gld_${EMULATION_NAME}_place_orphan,
1685 gld_${EMULATION_NAME}_set_symbols,
1686 gld_${EMULATION_NAME}_parse_args,
1687 gld_${EMULATION_NAME}_unrecognized_file,
1688 gld_${EMULATION_NAME}_list_options,
1689 gld_${EMULATION_NAME}_recognized_file,
1690 gld_${EMULATION_NAME}_find_potential_libraries