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, 1996, 1997, 1998, 1999, 2000
8 Free Software Foundation, Inc.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* The original file generated returned different default scripts depending
26 on whether certain switches were set, but these switches pertain to the
27 Linux system and that particular version of coff. In the NT case, we
28 only determine if the subsystem is console or windows in order to select
29 the correct entry point by default. */
35 #include "libiberty.h"
46 #include "coff/internal.h"
48 /* FIXME: This is a BFD internal header file, and we should not be
50 #include "../bfd/libcoff.h"
55 #define TARGET_IS_${EMULATION_NAME}
57 /* Permit the emulation parameters to override the default section
58 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
59 it seem that include/coff/internal.h should not define
60 PE_DEF_SECTION_ALIGNMENT. */
61 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
62 #undef PE_DEF_SECTION_ALIGNMENT
63 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
66 #if defined(TARGET_IS_i386pe)
69 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe) || defined(TARGET_IS_armpe)
73 #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
74 #define PE_DEF_SUBSYSTEM 3
76 #undef NT_EXE_IMAGE_BASE
77 #undef PE_DEF_SECTION_ALIGNMENT
78 #undef PE_DEF_FILE_ALIGNMENT
79 #define NT_EXE_IMAGE_BASE 0x00010000
80 #ifdef TARGET_IS_armpe
81 #define PE_DEF_SECTION_ALIGNMENT 0x00001000
82 #define PE_DEF_SUBSYSTEM 9
84 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
85 #define PE_DEF_SUBSYSTEM 2
87 #define PE_DEF_FILE_ALIGNMENT 0x00000200
90 #ifdef TARGET_IS_arm_epoc_pe
91 #define bfd_arm_pe_allocate_interworking_sections \
92 bfd_arm_epoc_pe_allocate_interworking_sections
93 #define bfd_arm_pe_get_bfd_for_interworking \
94 bfd_arm_epoc_pe_get_bfd_for_interworking
95 #define bfd_arm_pe_process_before_allocation \
96 bfd_arm_epoc_pe_process_before_allocation
99 static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
100 static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
101 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
102 static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
103 static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
104 static boolean gld_${EMULATION_NAME}_place_orphan
105 PARAMS ((lang_input_statement_type *, asection *));
106 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
107 static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
108 static void gld_${EMULATION_NAME}_finish PARAMS ((void));
109 static boolean gld_${EMULATION_NAME}_open_dynamic_archive
110 PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
112 static struct internal_extra_pe_aouthdr pe;
114 static int support_old_code = 0;
115 static char * thumb_entry_symbol = NULL;
116 static lang_assignment_statement_type *image_base_statement = 0;
119 static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */
120 static char *pe_out_def_filename = NULL;
121 static char *pe_implib_filename = NULL;
122 static int pe_enable_auto_image_base = 0;
123 static char *pe_dll_search_prefix = NULL;
126 extern const char *output_filename;
129 gld_${EMULATION_NAME}_before_parse()
131 output_filename = "${EXECUTABLE_NAME:-a.exe}";
132 ldfile_output_architecture = bfd_arch_${ARCH};
134 config.has_shared = 1;
136 #if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
137 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
138 lang_add_entry ("WinMainCRTStartup", 1);
140 lang_add_entry ("_WinMainCRTStartup", 1);
146 /* PE format extra command line options. */
148 /* Used for setting flags in the PE header. */
149 #define OPTION_BASE_FILE (300 + 1)
150 #define OPTION_DLL (OPTION_BASE_FILE + 1)
151 #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
152 #define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
153 #define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
154 #define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
155 #define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
156 #define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
157 #define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
158 #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
159 #define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
160 #define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
161 #define OPTION_SUBSYSTEM (OPTION_STACK + 1)
162 #define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
163 #define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
164 #define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
165 #define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
166 #define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
167 #define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
168 #define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
169 #define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
170 #define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
171 #define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1)
172 #define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1)
173 #define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
174 #define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
175 #define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1)
176 #define OPTION_DISABLE_AUTO_IMAGE_BASE (OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
177 #define OPTION_DLL_SEARCH_PREFIX (OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
178 #define OPTION_NO_DEFAULT_EXCLUDES (OPTION_DLL_SEARCH_PREFIX + 1)
180 static struct option longopts[] = {
182 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
183 {"dll", no_argument, NULL, OPTION_DLL},
184 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
185 {"heap", required_argument, NULL, OPTION_HEAP},
186 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
187 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
188 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
189 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
190 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
191 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
192 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
193 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
194 {"stack", required_argument, NULL, OPTION_STACK},
195 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
196 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
197 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
199 /* getopt allows abbreviations, so we do this to stop it from treating -o
200 as an abbreviation for this option */
201 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
202 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
203 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
204 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
205 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
206 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
207 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
208 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
209 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
210 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
211 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
212 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
213 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
214 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
215 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
217 {NULL, no_argument, NULL, 0}
221 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
222 parameters which may be input from the command line */
233 #define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
235 static definfo init[] =
237 /* imagebase must be first */
238 #define IMAGEBASEOFF 0
239 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
241 {&dll, sizeof(dll), 0, "__dll__", 0},
242 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
243 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
244 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
245 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
246 D(MajorImageVersion,"__major_image_version__", 1),
247 D(MinorImageVersion,"__minor_image_version__", 0),
248 #ifdef TARGET_IS_armpe
249 D(MajorSubsystemVersion,"__major_subsystem_version__", 2),
251 D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
253 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
254 D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
255 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
256 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
257 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
258 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
259 D(LoaderFlags,"__loader_flags__", 0x0),
260 { NULL, 0, 0, NULL, 0 }
264 gld_${EMULATION_NAME}_list_options (file)
267 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
268 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
269 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
270 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
271 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
272 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
273 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
274 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
275 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
276 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
277 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
278 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
279 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
280 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
281 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
282 fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
284 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
285 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
286 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
287 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
288 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
289 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
290 fprintf (file, _(" --out-implib <file> Generate import library\n"));
291 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
292 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
293 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n"));
294 fprintf (file, _(" create __imp_<SYMBOL> as well.\n"));
295 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n"));
296 fprintf (file, _(" unless user specifies one\n"));
297 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
298 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll witout an\n"));
299 fprintf (file, _(" importlib, use <string><basename>.dll \n"));
300 fprintf (file, _(" in preference to lib<basename>.dll \n"));
305 set_pe_name (name, val)
310 /* Find the name and set it. */
311 for (i = 0; init[i].ptr; i++)
313 if (strcmp (name, init[i].symbol) == 0)
338 { "native", 1, "NtProcessStartup" },
339 #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
340 { "windows", 2, "WinMainCRTStartup" },
342 { "windows", 2, "WinMainCRTStartup" },
344 { "console", 3, "mainCRTStartup" },
346 /* The Microsoft linker does not recognize this. */
349 { "posix", 7, "__PosixProcessStartup"},
350 { "wince", 9, "_WinMainCRTStartup" },
354 sver = strchr (optarg, ':');
356 len = strlen (optarg);
362 set_pe_name ("__major_subsystem_version__",
363 strtoul (sver + 1, &end, 0));
365 set_pe_name ("__minor_subsystem_version__",
366 strtoul (end + 1, &end, 0));
368 einfo (_("%P: warning: bad version number in -subsystem option\n"));
371 for (i = 0; v[i].name; i++)
373 if (strncmp (optarg, v[i].name, len) == 0
374 && v[i].name[len] == '\0')
376 const char *initial_symbol_char;
379 set_pe_name ("__subsystem__", v[i].value);
381 initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
382 if (*initial_symbol_char == '\0')
388 /* lang_add_entry expects its argument to be permanently
389 allocated, so we don't free this string. */
390 alc_entry = xmalloc (strlen (initial_symbol_char)
391 + strlen (v[i].entry)
393 strcpy (alc_entry, initial_symbol_char);
394 strcat (alc_entry, v[i].entry);
398 lang_add_entry (entry, 1);
404 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
416 set_pe_name (name, strtoul (optarg, &end, 0));
419 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
425 set_pe_stack_heap (resname, comname)
429 set_pe_value (resname);
434 set_pe_value (comname);
437 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
443 gld_${EMULATION_NAME}_parse_args(argc, argv)
449 int prevoptind = optind;
450 int prevopterr = opterr;
452 static int lastoptind = -1;
454 if (lastoptind != optind)
460 optc = getopt_long_only (argc, argv, "-", longopts, &longind);
471 case OPTION_BASE_FILE:
472 link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
473 if (link_info.base_file == NULL)
475 /* xgettext:c-format */
476 fprintf (stderr, _("%s: Can't open base file %s\n"),
477 program_name, optarg);
484 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
487 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
489 case OPTION_SUBSYSTEM:
492 case OPTION_MAJOR_OS_VERSION:
493 set_pe_value ("__major_os_version__");
495 case OPTION_MINOR_OS_VERSION:
496 set_pe_value ("__minor_os_version__");
498 case OPTION_MAJOR_SUBSYSTEM_VERSION:
499 set_pe_value ("__major_subsystem_version__");
501 case OPTION_MINOR_SUBSYSTEM_VERSION:
502 set_pe_value ("__minor_subsystem_version__");
504 case OPTION_MAJOR_IMAGE_VERSION:
505 set_pe_value ("__major_image_version__");
507 case OPTION_MINOR_IMAGE_VERSION:
508 set_pe_value ("__minor_image_version__");
510 case OPTION_FILE_ALIGNMENT:
511 set_pe_value ("__file_alignment__");
513 case OPTION_SECTION_ALIGNMENT:
514 set_pe_value ("__section_alignment__");
517 set_pe_name ("__dll__", 1);
519 case OPTION_IMAGE_BASE:
520 set_pe_value ("__image_base__");
522 case OPTION_SUPPORT_OLD_CODE:
523 support_old_code = 1;
525 case OPTION_THUMB_ENTRY:
526 thumb_entry_symbol = optarg;
530 pe_out_def_filename = xstrdup (optarg);
532 case OPTION_EXPORT_ALL:
533 pe_dll_export_everything = 1;
535 case OPTION_EXCLUDE_SYMBOLS:
536 pe_dll_add_excludes (optarg);
538 case OPTION_KILL_ATS:
541 case OPTION_STDCALL_ALIASES:
542 pe_dll_stdcall_aliases = 1;
544 case OPTION_ENABLE_STDCALL_FIXUP:
545 pe_enable_stdcall_fixup = 1;
547 case OPTION_DISABLE_STDCALL_FIXUP:
548 pe_enable_stdcall_fixup = 0;
550 case OPTION_IMPLIB_FILENAME:
551 pe_implib_filename = xstrdup (optarg);
553 case OPTION_WARN_DUPLICATE_EXPORTS:
554 pe_dll_warn_dup_exports = 1;
556 case OPTION_IMP_COMPAT:
557 pe_dll_compat_implib = 1;
559 case OPTION_ENABLE_AUTO_IMAGE_BASE:
560 pe_enable_auto_image_base = 1;
562 case OPTION_DISABLE_AUTO_IMAGE_BASE:
563 pe_enable_auto_image_base = 0;
565 case OPTION_DLL_SEARCH_PREFIX:
566 pe_dll_search_prefix = xstrdup( optarg );
568 case OPTION_NO_DEFAULT_EXCLUDES:
569 pe_dll_do_default_excludes = 0;
579 strhash (const char *str)
581 const unsigned char *s;
588 s = (const unsigned char *) str;
589 while ((c = *s++) != '\0')
591 hash += c + (c << 17);
595 hash += len + (len << 17);
601 /* Use the output file to create a image base for relocatable DLLs. */
603 compute_dll_image_base (const char *ofile)
605 unsigned long hash = strhash (ofile);
606 return 0x60000000 | ((hash << 16) & 0x0FFC0000);
610 /* Assign values to the special symbols before the linker script is
614 gld_${EMULATION_NAME}_set_symbols ()
616 /* Run through and invent symbols for all the
617 names and insert the defaults. */
619 lang_statement_list_type *save;
621 if (!init[IMAGEBASEOFF].inited)
623 if (link_info.relocateable)
624 init[IMAGEBASEOFF].value = 0;
625 else if (init[DLLOFF].value || link_info.shared)
627 init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?
628 compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
630 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
633 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
636 /* Don't do any symbol assignments if this is a relocateable link. */
637 if (link_info.relocateable)
640 /* Glue the assignments into the abs section */
643 stat_ptr = &(abs_output_section->children);
645 for (j = 0; init[j].ptr; j++)
647 long val = init[j].value;
648 lang_assignment_statement_type *rv;
649 rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
650 if (init[j].size == sizeof(short))
651 *(short *)init[j].ptr = val;
652 else if (init[j].size == sizeof(int))
653 *(int *)init[j].ptr = val;
654 else if (init[j].size == sizeof(long))
655 *(long *)init[j].ptr = val;
656 /* This might be a long long or other special type. */
657 else if (init[j].size == sizeof(bfd_vma))
658 *(bfd_vma *)init[j].ptr = val;
660 if (j == IMAGEBASEOFF)
661 image_base_statement = rv;
663 /* Restore the pointer. */
666 if (pe.FileAlignment >
669 einfo (_("%P: warning, file alignment > section alignment.\n"));
673 /* This is called after the linker script and the command line options
677 gld_${EMULATION_NAME}_after_parse ()
679 /* The Windows libraries are designed for the linker to treat the
680 entry point as an undefined symbol. Otherwise, the .obj that
681 defines mainCRTStartup is brought in because it is the first
682 encountered in libc.lib and it has other symbols in it which will
683 be pulled in by the link process. To avoid this, we act as
684 though the user specified -u with the entry point symbol.
686 This function is called after the linker script and command line
687 options have been read, so at this point we know the right entry
688 point. This function is called before the input files are
689 opened, so registering the symbol as undefined will make a
692 if (! link_info.relocateable && entry_symbol != NULL)
693 ldlang_add_undef (entry_symbol);
697 static struct bfd_link_hash_entry *pe_undef_found_sym;
700 pe_undef_cdecl_match (h, string)
701 struct bfd_link_hash_entry *h;
704 int sl = strlen (string);
705 if (h->type == bfd_link_hash_defined
706 && strncmp (h->root.string, string, sl) == 0
707 && h->root.string[sl] == '@')
709 pe_undef_found_sym = h;
718 static int gave_warning_message = 0;
719 struct bfd_link_hash_entry *undef, *sym;
721 for (undef = link_info.hash->undefs; undef; undef=undef->next)
722 if (undef->type == bfd_link_hash_undefined)
724 at = strchr (undef->root.string, '@');
727 /* The symbol is a stdcall symbol, so let's look for a cdecl
728 symbol with the same name and resolve to that */
729 char *cname = xstrdup (undef->root.string);
730 at = strchr (cname, '@');
732 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
733 if (sym && sym->type == bfd_link_hash_defined)
735 undef->type = bfd_link_hash_defined;
736 undef->u.def.value = sym->u.def.value;
737 undef->u.def.section = sym->u.def.section;
738 if (pe_enable_stdcall_fixup == -1)
740 einfo (_("Warning: resolving %s by linking to %s\n"),
741 undef->root.string, cname);
742 if (! gave_warning_message)
744 gave_warning_message = 1;
745 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
746 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
753 /* The symbol is a cdecl symbol, so we look for stdcall
754 symbols - which means scanning the whole symbol table */
755 pe_undef_found_sym = 0;
756 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
757 (PTR) undef->root.string);
758 sym = pe_undef_found_sym;
761 undef->type = bfd_link_hash_defined;
762 undef->u.def.value = sym->u.def.value;
763 undef->u.def.section = sym->u.def.section;
764 if (pe_enable_stdcall_fixup == -1)
766 einfo (_("Warning: resolving %s by linking to %s\n"),
767 undef->root.string, sym->root.string);
768 if (! gave_warning_message)
770 gave_warning_message = 1;
771 einfo(_("Use --enable-stdcall-fixup to disable these warnings\n"));
772 einfo(_("Use --disable-stdcall-fixup to disable these fixups\n"));
779 #endif /* DLL_SUPPORT */
782 gld_${EMULATION_NAME}_after_open ()
784 /* Pass the wacky PE command line options into the output bfd.
785 FIXME: This should be done via a function, rather than by
786 including an internal BFD header. */
788 if (!coff_data (output_bfd)->pe)
789 einfo (_("%F%P: PE operations on non PE file.\n"));
791 pe_data (output_bfd)->pe_opthdr = pe;
792 pe_data (output_bfd)->dll = init[DLLOFF].value;
795 if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
796 pe_fixup_stdcalls ();
798 pe_process_import_defs(output_bfd, &link_info);
799 if (link_info.shared)
800 pe_dll_build_sections (output_bfd, &link_info);
802 #ifndef TARGET_IS_i386pe
803 #ifndef TARGET_IS_armpe
805 pe_exe_build_sections (output_bfd, &link_info);
810 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
811 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
813 /* The arm backend needs special fields in the output hash structure.
814 These will only be created if the output format is an arm format,
815 hence we do not support linking and changing output formats at the
816 same time. Use a link followed by objcopy to change output formats. */
817 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
821 /* Find a BFD that can hold the interworking stubs. */
822 LANG_FOR_EACH_INPUT_STATEMENT (is)
824 if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))
831 /* This next chunk of code tries to detect the case where you have
832 two import libraries for the same DLL (specifically,
833 symbolically linking libm.a and libc.a in cygwin to
834 libcygwin.a). In those cases, it's possible for function
835 thunks from the second implib to be used but without the
836 head/tail objects, causing an improper import table. We detect
837 those cases and rename the "other" import libraries to match
838 the one the head/tail come from, so that the linker will sort
839 things nicely and produce a valid import table. */
841 LANG_FOR_EACH_INPUT_STATEMENT (is)
843 if (is->the_bfd->my_archive)
845 int idata2 = 0, reloc_count=0, is_imp = 0;
848 /* See if this is an import library thunk. */
849 for (sec = is->the_bfd->sections; sec; sec = sec->next)
851 if (strcmp (sec->name, ".idata\$2") == 0)
853 if (strncmp (sec->name, ".idata\$", 7) == 0)
855 reloc_count += sec->reloc_count;
858 if (is_imp && !idata2 && reloc_count)
860 /* It is, look for the reference to head and see if it's
861 from our own library. */
862 for (sec = is->the_bfd->sections; sec; sec = sec->next)
871 symsize = bfd_get_symtab_upper_bound (is->the_bfd);
874 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
878 symbols = (asymbol **) xmalloc (symsize);
879 symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
882 einfo ("%X%P: unable to process symbols: %E");
886 relocs = (arelent **) xmalloc ((size_t) relsize);
887 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
892 einfo ("%X%P: unable to process relocs: %E");
896 for (i = 0; i < nrelocs; i++)
898 struct symbol_cache_entry *s;
899 struct bfd_link_hash_entry * blhe;
903 s = (relocs[i]->sym_ptr_ptr)[0];
905 if (s->flags & BSF_LOCAL)
908 /* Thunk section with reloc to another bfd. */
909 blhe = bfd_link_hash_lookup (link_info.hash,
914 || blhe->type != bfd_link_hash_defined)
917 other_bfd = blhe->u.def.section->owner;
919 if (strcmp (is->the_bfd->my_archive->filename,
920 other_bfd->my_archive->filename) == 0)
923 /* Rename this implib to match the other. */
924 n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
926 strcpy (n, other_bfd->my_archive->filename);
928 is->the_bfd->my_archive->filename = n;
932 /* Note - we do not free the symbols,
933 they are now cached in the BFD. */
943 lang_input_statement_type *is2;
945 /* Careful - this is a shell script. Watch those dollar signs! */
946 /* Microsoft import libraries have every member named the same,
947 and not in the right order for us to link them correctly. We
948 must detect these and rename the members so that they'll link
949 correctly. There are three types of objects: the head, the
950 thunks, and the sentinel(s). The head is easy; it's the one
951 with idata2. We assume that the sentinels won't have relocs,
952 and the thunks will. It's easier than checking the symbol
953 table for external references. */
954 LANG_FOR_EACH_INPUT_STATEMENT (is)
956 if (is->the_bfd->my_archive)
958 bfd *arch = is->the_bfd->my_archive;
959 if (cur_arch != arch)
964 is2 && is2->the_bfd->my_archive == arch;
965 is2 = (lang_input_statement_type *)is2->next)
967 if (strcmp (is->the_bfd->filename, is2->the_bfd->filename))
974 int idata2 = 0, reloc_count=0;
978 for (sec = is->the_bfd->sections; sec; sec = sec->next)
980 if (strcmp (sec->name, ".idata\$2") == 0)
982 reloc_count += sec->reloc_count;
985 if (idata2) /* .idata2 is the TOC */
987 else if (reloc_count > 0) /* thunks */
992 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
993 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
994 is->the_bfd->filename = new_name;
996 new_name = xmalloc (strlen (is->filename) + 3);
997 sprintf (new_name, "%s.%c", is->filename, seq);
998 is->filename = new_name;
1006 gld_${EMULATION_NAME}_before_allocation()
1008 #ifdef TARGET_IS_ppcpe
1009 /* Here we rummage through the found bfds to collect toc information */
1011 LANG_FOR_EACH_INPUT_STATEMENT (is)
1013 if (!ppc_process_before_allocation (is->the_bfd, &link_info))
1015 /* xgettext:c-format */
1016 einfo (_("Errors encountered processing file %s\n"), is->filename);
1021 /* We have seen it all. Allocate it, and carry on */
1022 ppc_allocate_toc_section (&link_info);
1023 #endif /* TARGET_IS_ppcpe */
1025 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
1026 /* FIXME: we should be able to set the size of the interworking stub
1029 Here we rummage through the found bfds to collect glue
1030 information. FIXME: should this be based on a command line
1031 option? krk@cygnus.com */
1033 LANG_FOR_EACH_INPUT_STATEMENT (is)
1035 if (! bfd_arm_pe_process_before_allocation
1036 (is->the_bfd, & link_info, support_old_code))
1038 /* xgettext:c-format */
1039 einfo (_("Errors encountered processing file %s for interworking"),
1045 /* We have seen it all. Allocate it, and carry on */
1046 bfd_arm_pe_allocate_interworking_sections (& link_info);
1047 #endif /* TARGET_IS_armpe */
1051 /* This is called when an input file isn't recognized as a BFD. We
1052 check here for .DEF files and pull them in automatically. */
1055 saw_option(char *option)
1058 for (i=0; init[i].ptr; i++)
1059 if (strcmp (init[i].symbol, option) == 0)
1060 return init[i].inited;
1063 #endif /* DLL_SUPPORT */
1066 gld_${EMULATION_NAME}_unrecognized_file(entry)
1067 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1070 const char *ext = entry->filename + strlen (entry->filename) - 4;
1072 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
1074 if (pe_def_file == 0)
1075 pe_def_file = def_file_empty ();
1076 def_file_parse (entry->filename, pe_def_file);
1079 int i, buflen=0, len;
1081 for (i=0; i<pe_def_file->num_exports; i++)
1083 len = strlen(pe_def_file->exports[i].internal_name);
1087 buf = (char *) xmalloc (buflen);
1088 for (i=0; i<pe_def_file->num_exports; i++)
1090 struct bfd_link_hash_entry *h;
1091 sprintf(buf, "_%s", pe_def_file->exports[i].internal_name);
1093 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1094 if (h == (struct bfd_link_hash_entry *) NULL)
1095 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1096 if (h->type == bfd_link_hash_new)
1098 h->type = bfd_link_hash_undefined;
1099 h->u.undef.abfd = NULL;
1100 bfd_link_add_undef (link_info.hash, h);
1105 /* def_file_print (stdout, pe_def_file); */
1106 if (pe_def_file->is_dll == 1)
1107 link_info.shared = 1;
1109 if (pe_def_file->base_address != (bfd_vma)(-1))
1112 pe_data (output_bfd)->pe_opthdr.ImageBase =
1113 init[IMAGEBASEOFF].value = pe_def_file->base_address;
1114 init[IMAGEBASEOFF].inited = 1;
1115 if (image_base_statement)
1116 image_base_statement->exp =
1117 exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
1121 /* Not sure if these *should* be set */
1122 if (pe_def_file->version_major != -1)
1124 pe.MajorImageVersion = pe_def_file->version_major;
1125 pe.MinorImageVersion = pe_def_file->version_minor;
1128 if (pe_def_file->stack_reserve != -1
1129 && ! saw_option ("__size_of_stack_reserve__"))
1131 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
1132 if (pe_def_file->stack_commit != -1)
1133 pe.SizeOfStackCommit = pe_def_file->stack_commit;
1135 if (pe_def_file->heap_reserve != -1
1136 && ! saw_option ("__size_of_heap_reserve__"))
1138 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
1139 if (pe_def_file->heap_commit != -1)
1140 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
1151 gld_${EMULATION_NAME}_recognized_file(entry)
1152 lang_input_statement_type *entry ATTRIBUTE_UNUSED;
1155 #ifdef TARGET_IS_i386pe
1156 pe_dll_id_target ("pei-i386");
1158 #ifdef TARGET_IS_shpe
1159 pe_dll_id_target ("pei-shl");
1161 #ifdef TARGET_IS_mipspe
1162 pe_dll_id_target ("pei-mips");
1164 #ifdef TARGET_IS_armpe
1165 pe_dll_id_target ("pei-arm-little");
1167 if (bfd_get_format (entry->the_bfd) == bfd_object)
1169 const char *ext = entry->filename + strlen (entry->filename) - 4;
1170 if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
1171 return pe_implied_import_dll (entry->filename);
1178 gld_${EMULATION_NAME}_finish ()
1180 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
1181 struct bfd_link_hash_entry * h;
1183 if (thumb_entry_symbol != NULL)
1185 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
1187 if (h != (struct bfd_link_hash_entry *) NULL
1188 && (h->type == bfd_link_hash_defined
1189 || h->type == bfd_link_hash_defweak)
1190 && h->u.def.section->output_section != NULL)
1192 static char buffer[32];
1195 /* Special procesing is required for a Thumb entry symbol. The
1196 bottom bit of its address must be set. */
1197 val = (h->u.def.value
1198 + bfd_get_section_vma (output_bfd,
1199 h->u.def.section->output_section)
1200 + h->u.def.section->output_offset);
1204 /* Now convert this value into a string and store it in entry_symbol
1205 where the lang_finish() function will pick it up. */
1209 sprintf_vma (buffer + 2, val);
1211 if (entry_symbol != NULL && entry_from_cmdline)
1212 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
1213 thumb_entry_symbol, entry_symbol);
1214 entry_symbol = buffer;
1217 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
1219 #endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) */
1222 if (link_info.shared)
1224 pe_dll_fill_sections (output_bfd, &link_info);
1225 if (pe_implib_filename)
1226 pe_dll_generate_implib (pe_def_file, pe_implib_filename);
1228 #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe)
1229 /* ARM doesn't need relocs. */
1232 pe_exe_fill_sections (output_bfd, &link_info);
1236 if (pe_out_def_filename)
1237 pe_dll_generate_def_file (pe_out_def_filename);
1238 #endif /* DLL_SUPPORT */
1242 /* Place an orphan section.
1244 We use this to put sections in a reasonable place in the file, and
1245 to ensure that they are aligned as required.
1247 We handle grouped sections here as well. A section named .foo$nn
1248 goes into the output section .foo. All grouped sections are sorted
1251 Grouped sections for the default sections are handled by the
1252 default linker script using wildcards, and are sorted by
1257 lang_output_section_statement_type *os;
1259 lang_statement_union_type **stmt;
1264 gld_${EMULATION_NAME}_place_orphan (file, s)
1265 lang_input_statement_type *file;
1268 const char *secname;
1269 char *hold_section_name;
1270 char *dollar = NULL;
1271 const char *ps = NULL;
1272 lang_output_section_statement_type *os;
1273 lang_statement_list_type add_child;
1275 secname = bfd_get_section_name (s->owner, s);
1277 /* Look through the script to see where to place this section. */
1279 hold_section_name = xstrdup (secname);
1280 if (!link_info.relocateable)
1282 dollar = strchr (hold_section_name, '$');
1287 os = lang_output_section_find (hold_section_name);
1289 lang_list_init (&add_child);
1292 && os->bfd_section != NULL
1293 && ((s->flags ^ os->bfd_section->flags) & (SEC_LOAD | SEC_ALLOC)) == 0)
1295 wild_doit (&add_child, s, os, file);
1299 struct orphan_save *place;
1300 static struct orphan_save hold_text;
1301 static struct orphan_save hold_rdata;
1302 static struct orphan_save hold_data;
1303 static struct orphan_save hold_bss;
1305 lang_statement_list_type *old;
1306 lang_statement_list_type add;
1307 etree_type *address;
1309 /* Try to put the new output section in a reasonable place based
1310 on the section name and section flags. */
1311 #define HAVE_SECTION(hold, name) \
1312 (hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL)
1315 if ((s->flags & SEC_ALLOC) == 0)
1317 else if ((s->flags & SEC_HAS_CONTENTS) == 0
1318 && HAVE_SECTION (hold_bss, ".bss"))
1320 else if ((s->flags & SEC_READONLY) == 0
1321 && HAVE_SECTION (hold_data, ".data"))
1323 else if ((s->flags & SEC_CODE) == 0
1324 && (s->flags & SEC_READONLY) != 0
1325 && HAVE_SECTION (hold_rdata, ".rdata"))
1326 place = &hold_rdata;
1327 else if ((s->flags & SEC_READONLY) != 0
1328 && HAVE_SECTION (hold_text, ".text"))
1333 /* Choose a unique name for the section. This will be needed if
1334 the same section name appears in the input file with
1335 different loadable or allocateable characteristics. */
1336 outsecname = xstrdup (hold_section_name);
1337 if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
1343 len = strlen (outsecname);
1344 newname = xmalloc (len + 5);
1345 strcpy (newname, outsecname);
1349 sprintf (newname + len, "%d", i);
1352 while (bfd_get_section_by_name (output_bfd, newname) != NULL);
1355 outsecname = newname;
1358 /* Start building a list of statements for this section. */
1361 lang_list_init (stat_ptr);
1363 if (config.build_constructors)
1365 /* If the name of the section is representable in C, then create
1366 symbols to mark the start and the end of the section. */
1367 for (ps = outsecname; *ps != '\0'; ps++)
1368 if (! isalnum ((unsigned char) *ps) && *ps != '_')
1373 etree_type *e_align;
1375 symname = (char *) xmalloc (ps - outsecname + sizeof "___start_");
1376 sprintf (symname, "___start_%s", outsecname);
1377 e_align = exp_unop (ALIGN_K,
1378 exp_intop ((bfd_vma) 1 << s->alignment_power));
1379 lang_add_assignment (exp_assop ('=', symname, e_align));
1383 if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
1384 address = exp_intop ((bfd_vma) 0);
1387 /* All sections in an executable must be aligned to a page
1389 address = exp_unop (ALIGN_K,
1390 exp_nameop (NAME, "__section_alignment__"));
1393 os = lang_enter_output_section_statement (outsecname, address, 0,
1395 (etree_type *) NULL,
1396 (etree_type *) NULL,
1397 (etree_type *) NULL);
1399 wild_doit (&add_child, s, os, file);
1401 lang_leave_output_section_statement
1402 ((bfd_vma) 0, "*default*",
1403 (struct lang_output_section_phdr_list *) NULL, "*default*");
1405 if (config.build_constructors && *ps == '\0')
1409 /* lang_leave_ouput_section_statement resets stat_ptr. Put
1410 stat_ptr back where we want it. */
1414 symname = (char *) xmalloc (ps - outsecname + sizeof "___stop_");
1415 sprintf (symname, "___stop_%s", outsecname);
1416 lang_add_assignment (exp_assop ('=', symname,
1417 exp_nameop (NAME, ".")));
1424 asection *snew, **pps;
1426 snew = os->bfd_section;
1427 if (place->os->bfd_section != NULL || place->section != NULL)
1429 /* Shuffle the section to make the output file look neater. */
1430 if (place->section == NULL)
1433 /* Finding the end of the list is a little tricky. We
1434 make a wild stab at it by comparing section flags. */
1435 flagword first_flags = place->os->bfd_section->flags;
1436 for (pps = &place->os->bfd_section->next;
1437 *pps != NULL && (*pps)->flags == first_flags;
1438 pps = &(*pps)->next)
1440 place->section = pps;
1442 /* Put orphans after the first section on the list. */
1443 place->section = &place->os->bfd_section->next;
1447 /* Unlink the section. */
1448 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next)
1452 /* Now tack it on to the "place->os" section list. */
1453 snew->next = *place->section;
1454 *place->section = snew;
1456 place->section = &snew->next; /* Save the end of this list. */
1458 if (place->stmt == NULL)
1460 /* Put the new statement list right at the head. */
1461 *add.tail = place->os->header.next;
1462 place->os->header.next = add.head;
1466 /* Put it after the last orphan statement we added. */
1467 *add.tail = *place->stmt;
1468 *place->stmt = add.head;
1470 place->stmt = add.tail; /* Save the end of this list. */
1475 lang_statement_union_type **pl = &os->children.head;
1479 boolean found_dollar;
1481 /* The section name has a '$'. Sort it with the other '$'
1484 found_dollar = false;
1485 for ( ; *pl != NULL; pl = &(*pl)->next)
1487 lang_input_section_type *ls;
1490 if ((*pl)->header.type != lang_input_section_enum)
1493 ls = &(*pl)->input_section;
1495 lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
1496 if (strchr (lname, '$') == NULL)
1503 found_dollar = true;
1504 if (strcmp (secname, lname) < 0)
1510 if (add_child.head != NULL)
1512 add_child.head->next = *pl;
1513 *pl = add_child.head;
1517 free (hold_section_name);
1523 gld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
1524 const char * arch ATTRIBUTE_UNUSED;
1525 search_dirs_type * search;
1526 lang_input_statement_type * entry;
1528 const char * filename;
1531 if (! entry->is_archive)
1534 filename = entry->filename;
1536 string = (char *) xmalloc (strlen (search->name)
1538 + sizeof "/lib.a.dll"
1540 + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
1544 /* Try "libfoo.dll.a" first (preferred explicit import library for dll's */
1545 sprintf (string, "%s/lib%s.dll.a", search->name, filename);
1547 if (! ldfile_try_open_bfd (string, entry))
1549 /* Try "foo.dll.a" next (alternate explicit import library for dll's */
1550 sprintf (string, "%s/%s.dll.a", search->name, filename);
1551 if (! ldfile_try_open_bfd (string, entry))
1554 Try libfoo.a next. Normally, this would be interpreted as a static
1555 library, but it *could* be an import library. For backwards compatibility,
1556 libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search,
1557 or sometimes errors occur when building legacy packages.
1559 Putting libfoo.a here means that in a failure case (i.e. the library
1560 -lfoo is not found) we will search for libfoo.a twice before
1561 giving up -- once here, and once when searching for a "static" lib.
1564 /* Try "libfoo.a" (import lib, or static lib, but must
1565 take precedence over dll's) */
1566 sprintf (string, "%s/lib%s.a", search->name, filename);
1567 if (! ldfile_try_open_bfd (string, entry))
1570 if (pe_dll_search_prefix)
1572 /* Try "<prefix>foo.dll" (preferred dll name, if specified) */
1573 sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
1574 if (! ldfile_try_open_bfd (string, entry))
1576 /* Try "libfoo.dll" (default preferred dll name) */
1577 sprintf (string, "%s/lib%s.dll", search->name, filename);
1578 if (! ldfile_try_open_bfd (string, entry))
1580 /* Finally, try "foo.dll" (alternate dll name) */
1581 sprintf (string, "%s/%s.dll", search->name, filename);
1582 if (! ldfile_try_open_bfd (string, entry))
1590 else /* pe_dll_search_prefix not specified */
1593 /* Try "libfoo.dll" (preferred dll name) */
1594 sprintf (string, "%s/lib%s.dll", search->name, filename);
1595 if (! ldfile_try_open_bfd (string, entry))
1597 /* Finally, try "foo.dll" (alternate dll name) */
1598 sprintf (string, "%s/%s.dll", search->name, filename);
1599 if (! ldfile_try_open_bfd (string, entry))
1610 entry->filename = string;
1616 gld_${EMULATION_NAME}_find_potential_libraries (name, entry)
1618 lang_input_statement_type * entry;
1620 return ldfile_open_file_search (name, entry, "", ".lib");
1624 gld_${EMULATION_NAME}_get_script(isfile)
1627 # Scripts compiled in.
1628 # sed commands to quote an ld script as a C string.
1629 sc="-f stringify.sed"
1631 cat >>e${EMULATION_NAME}.c <<EOF
1635 if (link_info.relocateable == true && config.build_constructors == true)
1638 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1639 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
1640 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1641 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1642 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1643 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1644 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1645 echo ' ; else return' >> e${EMULATION_NAME}.c
1646 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1647 echo '; }' >> e${EMULATION_NAME}.c
1649 cat >>e${EMULATION_NAME}.c <<EOF
1652 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1654 gld_${EMULATION_NAME}_before_parse,
1657 gld_${EMULATION_NAME}_after_parse,
1658 gld_${EMULATION_NAME}_after_open,
1659 after_allocation_default,
1660 set_output_arch_default,
1661 ldemul_default_target,
1662 gld_${EMULATION_NAME}_before_allocation,
1663 gld_${EMULATION_NAME}_get_script,
1664 "${EMULATION_NAME}",
1666 gld_${EMULATION_NAME}_finish, /* finish */
1667 NULL, /* create output section statements */
1668 gld_${EMULATION_NAME}_open_dynamic_archive,
1669 gld_${EMULATION_NAME}_place_orphan,
1670 gld_${EMULATION_NAME}_set_symbols,
1671 gld_${EMULATION_NAME}_parse_args,
1672 gld_${EMULATION_NAME}_unrecognized_file,
1673 gld_${EMULATION_NAME}_list_options,
1674 gld_${EMULATION_NAME}_recognized_file,
1675 gld_${EMULATION_NAME}_find_potential_libraries