1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 if [ -z "$MACHINE" ]; then
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
11 move_default_addr_high=1
15 move_default_addr_high=0;
20 rm -f e${EMULATION_NAME}.c
21 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
23 /* Copyright (C) 2006-2024 Free Software Foundation, Inc.
24 Written by Kai Tietz, OneVision Software GmbH&CoKg.
26 This file is part of the GNU Binutils.
28 This program is free software; you can redistribute it and/or modify
29 it under the terms of the GNU General Public License as published by
30 the Free Software Foundation; either version 3 of the License, or
31 (at your option) any later version.
33 This program is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 GNU General Public License for more details.
38 You should have received a copy of the GNU General Public License
39 along with this program; if not, write to the Free Software
40 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
41 MA 02110-1301, USA. */
44 /* For WINDOWS_XP64 and higher */
45 /* Based on pe.em, but modified for 64 bit support. */
47 #define TARGET_IS_${EMULATION_NAME}
49 #define COFF_IMAGE_WITH_PE
51 #ifdef TARGET_IS_aarch64pe
52 #define COFF_WITH_peAArch64
53 #elif defined TARGET_IS_arm64pe
54 #define COFF_WITH_peAArch64
55 #elif defined (TARGET_IS_i386pep)
56 #define COFF_WITH_pex64
64 #include "libiberty.h"
65 #include "filenames.h"
76 #include "ldbuildid.h"
77 #include "coff/internal.h"
81 x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin | \
82 i[3-7]86-*-mingw32* | i[3-7]86-*-cygwin* | i[3-7]86-*-winnt | i[3-7]86-*-pe | \
83 aarch64-*-mingw* | aarch64-*-pe* )
92 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
93 header in generic PE code. */
94 #ifdef TARGET_IS_i386pep
95 # include "coff/x86_64.h"
96 #elif defined TARGET_IS_aarch64pe
97 # include "coff/aarch64.h"
98 #elif defined TARGET_IS_arm64pe
99 # include "coff/aarch64.h"
103 /* FIXME: These are BFD internal header files, and we should not be
105 #include "../bfd/libcoff.h"
106 #include "../bfd/libpei.h"
109 #define AOUTSZ PEPAOUTSZ
110 #define PEAOUTHDR PEPAOUTHDR
114 #include "safe-ctype.h"
116 /* Permit the emulation parameters to override the default section
117 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
118 it seem that include/coff/internal.h should not define
119 PE_DEF_SECTION_ALIGNMENT. */
120 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
121 #undef PE_DEF_SECTION_ALIGNMENT
122 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
125 #if defined(TARGET_IS_i386pep) || defined(COFF_WITH_peAArch64)
129 #define DEFAULT_DLL_CHARACTERISTICS (${cygwin_behavior} ? 0 : \
130 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
131 | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
132 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
134 #if defined(TARGET_IS_i386pep) || defined(COFF_WITH_peAArch64) || ! defined(DLL_SUPPORT)
135 #define PE_DEF_SUBSYSTEM IMAGE_SUBSYSTEM_WINDOWS_CUI
136 #undef NT_EXE_IMAGE_BASE
137 #define NT_EXE_IMAGE_BASE \
138 ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
140 #undef NT_DLL_IMAGE_BASE
141 #define NT_DLL_IMAGE_BASE \
142 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
144 #undef NT_DLL_AUTO_IMAGE_BASE
145 #define NT_DLL_AUTO_IMAGE_BASE \
146 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
148 #undef NT_DLL_AUTO_IMAGE_MASK
149 #define NT_DLL_AUTO_IMAGE_MASK \
150 ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
153 #undef NT_EXE_IMAGE_BASE
154 #define NT_EXE_IMAGE_BASE \
155 ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
157 #undef NT_DLL_IMAGE_BASE
158 #define NT_DLL_IMAGE_BASE \
159 ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
161 #undef NT_DLL_AUTO_IMAGE_BASE
162 #define NT_DLL_AUTO_IMAGE_BASE \
163 ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
165 #undef NT_DLL_AUTO_IMAGE_MASK
166 #define NT_DLL_AUTO_IMAGE_MASK \
167 ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
169 #undef PE_DEF_SECTION_ALIGNMENT
170 #define PE_DEF_SUBSYSTEM IMAGE_SUBSYSTEM_WINDOWS_GUI
171 #undef PE_DEF_FILE_ALIGNMENT
172 #define PE_DEF_FILE_ALIGNMENT 0x00000200
173 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
176 static struct internal_extra_pe_aouthdr pep;
178 static int pep_subsystem = ${SUBSYSTEM};
179 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
180 static int support_old_code = 0;
181 static lang_assignment_statement_type *image_base_statement = 0;
182 static unsigned short pe_dll_characteristics = DEFAULT_DLL_CHARACTERISTICS;
183 static bool insert_timestamp = true;
184 static const char *emit_build_id;
187 static char *pdb_name;
191 static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
192 static char * pep_out_def_filename = NULL;
193 static int pep_enable_auto_image_base = 0;
194 static char * pep_dll_search_prefix = NULL;
197 extern const char *output_filename;
200 is_underscoring (void)
203 if (pep_leading_underscore != -1)
204 return pep_leading_underscore;
205 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
206 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
210 pep_leading_underscore = (u != 0 ? 1 : 0);
211 return pep_leading_underscore;
214 /* A case insensitive comparison, regardless of the host platform, used for
215 comparing file extensions. */
217 fileext_cmp (const char *s1, const char *s2)
221 int c1 = TOLOWER (*s1++);
222 int c2 = *s2++; /* Assumed to be lower case from the caller. */
233 gld${EMULATION_NAME}_before_parse (void)
236 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
237 output_filename = "${EXECUTABLE_NAME:-a.exe}";
239 input_flags.dynamic = true;
240 config.has_shared = 1;
241 link_info.pei386_auto_import = 1;
242 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
246 /* PE format extra command line options. */
249 gld${EMULATION_NAME}_add_options
250 (int ns ATTRIBUTE_UNUSED,
251 char **shortopts ATTRIBUTE_UNUSED,
253 struct option **longopts,
254 int nrl ATTRIBUTE_UNUSED,
255 struct option **really_longopts ATTRIBUTE_UNUSED)
257 static const struct option xtra_long[] =
260 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
261 {"dll", no_argument, NULL, OPTION_DLL},
262 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
263 {"heap", required_argument, NULL, OPTION_HEAP},
264 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
265 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
266 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
267 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
268 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
269 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
270 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
271 {"stack", required_argument, NULL, OPTION_STACK},
272 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
273 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
274 {"use-nul-prefixed-import-tables", no_argument, NULL,
275 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
276 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
277 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
279 /* getopt allows abbreviations, so we do this to stop it
280 from treating -o as an abbreviation for this option. */
281 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
282 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
283 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
284 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
285 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
286 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
287 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
288 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
289 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
290 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
291 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
292 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
293 /* getopt() allows abbreviations, so we do this to stop it from
294 treating -c as an abbreviation for these --compat-implib. */
295 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
296 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
297 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
298 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
299 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
300 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
301 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
302 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
303 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
304 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
305 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
306 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
308 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
309 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
310 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
311 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
312 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
313 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
314 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
315 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
316 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
317 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
318 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
319 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
320 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
321 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
323 {"pdb", required_argument, NULL, OPTION_PDB},
325 {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
326 {"disable-reloc-section", no_argument, NULL, OPTION_DISABLE_RELOC_SECTION},
327 {"disable-high-entropy-va", no_argument, NULL, OPTION_DISABLE_HIGH_ENTROPY_VA},
328 {"disable-dynamicbase",no_argument, NULL, OPTION_DISABLE_DYNAMIC_BASE},
329 {"disable-forceinteg", no_argument, NULL, OPTION_DISABLE_FORCE_INTEGRITY},
330 {"disable-nxcompat", no_argument, NULL, OPTION_DISABLE_NX_COMPAT},
331 {"disable-no-isolation", no_argument, NULL, OPTION_DISABLE_NO_ISOLATION},
332 {"disable-no-seh", no_argument, NULL, OPTION_DISABLE_NO_SEH},
333 {"disable-no-bind", no_argument, NULL, OPTION_DISABLE_NO_BIND},
334 {"disable-wdmdriver", no_argument, NULL, OPTION_DISABLE_WDM_DRIVER},
335 {"disable-tsaware", no_argument, NULL, OPTION_DISABLE_TERMINAL_SERVER_AWARE},
336 {NULL, no_argument, NULL, 0}
340 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
341 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
344 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
345 parameters which may be input from the command line. */
354 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
355 C visible symbols can be prefixed by underscore dependent on target's
360 #define GET_INIT_SYMBOL_NAME(IDX) \
361 (init[(IDX)].symbol \
362 + ((!init[(IDX)].is_c_symbol || is_underscoring () == 1) ? 0 : 1))
364 /* Decorates the C visible symbol by underscore, if target requires. */
366 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
368 #define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
370 static definfo init[] =
372 /* imagebase must be first */
373 #define IMAGEBASEOFF 0
374 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, false),
376 {&dll, sizeof(dll), 0, "__dll__", 0, false},
377 #define MSIMAGEBASEOFF 2
378 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, true),
379 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, false),
380 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, false),
381 D(MajorOperatingSystemVersion,"__major_os_version__", 4, false),
382 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, false),
383 D(MajorImageVersion,"__major_image_version__", 0, false),
384 D(MinorImageVersion,"__minor_image_version__", 0, false),
385 D(MajorSubsystemVersion,"__major_subsystem_version__", 5, false),
386 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2, false),
387 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, false),
388 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, false),
389 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, false),
390 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, false),
391 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, false),
392 D(LoaderFlags,"__loader_flags__", 0x0, false),
393 D(DllCharacteristics, "__dll_characteristics__", DEFAULT_DLL_CHARACTERISTICS, false),
394 { NULL, 0, 0, NULL, 0, false}
399 gld${EMULATION_NAME}_list_options (FILE *file)
401 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
402 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
403 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
404 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
405 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
406 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
407 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
408 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
409 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
410 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
411 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
412 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
413 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
414 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
415 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
416 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
417 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero (default)\n"));
418 fprintf (file, _(" This makes binaries non-deterministic\n"));
420 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
421 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
422 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
423 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
424 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
425 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
426 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
427 fprintf (file, _(" Exclude objects, archive members from auto\n"));
428 fprintf (file, _(" export, place into import library instead\n"));
429 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
430 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
431 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
432 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports\n"));
433 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
434 create __imp_<SYMBOL> as well\n"));
435 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
436 unless user specifies one\n"));
437 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base (default)\n"));
438 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
439 an importlib, use <string><basename>.dll\n\
440 in preference to lib<basename>.dll \n"));
441 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
442 __imp_sym for DATA references\n"));
443 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
444 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
445 adding pseudo-relocations resolved at\n\
447 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
448 auto-imported DATA\n"));
449 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
450 or linking to DLLs (esp. auto-import)\n"));
451 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
452 executable image files\n"));
453 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
454 in object files\n"));
455 fprintf (file, _(" --[disable-]high-entropy-va Image is compatible with 64-bit address space\n\
456 layout randomization (ASLR)\n"));
457 fprintf (file, _(" --[disable-]dynamicbase Image base address may be relocated using\n\
458 address space layout randomization (ASLR)\n"));
459 fprintf (file, _(" --enable-reloc-section Create the base relocation table\n"));
460 fprintf (file, _(" --disable-reloc-section Do not create the base relocation table\n"));
461 fprintf (file, _(" --[disable-]forceinteg Code integrity checks are enforced\n"));
462 fprintf (file, _(" --[disable-]nxcompat Image is compatible with data execution\n\
464 fprintf (file, _(" --[disable-]no-isolation Image understands isolation but do not\n\
465 isolate the image\n"));
466 fprintf (file, _(" --[disable-]no-seh Image does not use SEH; no SE handler may\n\
467 be called in this image\n"));
468 fprintf (file, _(" --[disable-]no-bind Do not bind this image\n"));
469 fprintf (file, _(" --[disable-]wdmdriver Driver uses the WDM model\n"));
470 fprintf (file, _(" --[disable-]tsaware Image is Terminal Server aware\n"));
471 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
473 fprintf (file, _(" --pdb=[FILENAME] Generate PDB file\n"));
480 set_pep_name (char *name, bfd_vma val)
484 /* Find the name and set it. */
485 for (i = 0; init[i].ptr; i++)
487 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
491 if (strcmp (name,"__image_base__") == 0)
492 set_pep_name (U ("__ImageBase"), val);
500 set_entry_point (void)
503 const char *initial_symbol_char;
513 { 1, "NtProcessStartup" },
514 { 2, "WinMainCRTStartup" },
515 { 3, "mainCRTStartup" },
516 { 7, "__PosixProcessStartup" },
517 { 9, "WinMainCRTStartup" },
518 {14, "mainCRTStartup" },
522 /* Entry point name for arbitrary subsystem numbers. */
523 static const char default_entry[] = "mainCRTStartup";
525 if (bfd_link_dll (&link_info) || dll)
527 entry = "DllMainCRTStartup";
531 for (i = 0; v[i].entry; i++)
532 if (v[i].value == pep_subsystem)
535 /* If no match, use the default. */
536 if (v[i].entry != NULL)
539 entry = default_entry;
542 /* Now we check target's default for getting proper symbol_char. */
543 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
545 if (*initial_symbol_char != '\0')
549 /* lang_default_entry expects its argument to be permanently
550 allocated, so we don't free this string. */
551 alc_entry = xmalloc (strlen (initial_symbol_char)
554 strcpy (alc_entry, initial_symbol_char);
555 strcat (alc_entry, entry);
559 lang_default_entry (entry);
561 if (bfd_link_executable (&link_info) && ! entry_from_cmdline)
562 ldlang_add_undef (entry, false);
566 set_pep_subsystem (void)
572 unsigned long temp_subsystem;
589 /* Check for the presence of a version number. */
590 sver = strchr (optarg, ':');
592 len = strlen (optarg);
596 set_pep_name ("__major_subsystem_version__",
597 strtoul (sver + 1, &end, 0));
599 set_pep_name ("__minor_subsystem_version__",
600 strtoul (end + 1, &end, 0));
602 einfo (_("%P: warning: bad version number in -subsystem option\n"));
605 /* Check for numeric subsystem. */
606 temp_subsystem = strtoul (optarg, & end, 0);
607 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
609 /* Search list for a numeric match to use its entry point. */
610 for (i = 0; v[i].name; i++)
611 if (v[i].value == (int) temp_subsystem)
614 /* Use this subsystem. */
615 pep_subsystem = (int) temp_subsystem;
619 /* Search for subsystem by name. */
620 for (i = 0; v[i].name; i++)
621 if (strncmp (optarg, v[i].name, len) == 0
622 && v[i].name[len] == '\0')
625 if (v[i].name == NULL)
627 einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
631 pep_subsystem = v[i].value;
634 set_pep_name ("__subsystem__", pep_subsystem);
641 set_pep_value (char *name)
645 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
648 einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
655 set_pep_stack_heap (char *resname, char *comname)
657 set_pep_value (resname);
662 set_pep_value (comname);
665 einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
668 #define DEFAULT_BUILD_ID_STYLE "md5"
671 gld${EMULATION_NAME}_handle_option (int optc)
679 case OPTION_BASE_FILE:
680 link_info.base_file = fopen (optarg, FOPEN_WB);
681 if (link_info.base_file == NULL)
682 einfo (_("%F%P: cannot open base file %s\n"), optarg);
687 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
690 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
692 case OPTION_SUBSYSTEM:
693 set_pep_subsystem ();
695 case OPTION_MAJOR_OS_VERSION:
696 set_pep_value ("__major_os_version__");
698 case OPTION_MINOR_OS_VERSION:
699 set_pep_value ("__minor_os_version__");
701 case OPTION_MAJOR_SUBSYSTEM_VERSION:
702 set_pep_value ("__major_subsystem_version__");
704 case OPTION_MINOR_SUBSYSTEM_VERSION:
705 set_pep_value ("__minor_subsystem_version__");
707 case OPTION_MAJOR_IMAGE_VERSION:
708 set_pep_value ("__major_image_version__");
710 case OPTION_MINOR_IMAGE_VERSION:
711 set_pep_value ("__minor_image_version__");
713 case OPTION_FILE_ALIGNMENT:
714 set_pep_value ("__file_alignment__");
716 case OPTION_SECTION_ALIGNMENT:
717 set_pep_value ("__section_alignment__");
720 set_pep_name ("__dll__", 1);
722 case OPTION_IMAGE_BASE:
723 set_pep_value ("__image_base__");
725 case OPTION_SUPPORT_OLD_CODE:
726 support_old_code = 1;
728 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
729 pep_use_nul_prefixed_import_tables = true;
731 case OPTION_NO_LEADING_UNDERSCORE:
732 pep_leading_underscore = 0;
734 case OPTION_LEADING_UNDERSCORE:
735 pep_leading_underscore = 1;
737 case OPTION_INSERT_TIMESTAMP:
738 insert_timestamp = true;
740 case OPTION_NO_INSERT_TIMESTAMP:
741 insert_timestamp = false;
745 pep_out_def_filename = xstrdup (optarg);
747 case OPTION_EXPORT_ALL:
748 pep_dll_export_everything = 1;
750 case OPTION_EXCLUDE_SYMBOLS:
751 pep_dll_add_excludes (optarg, EXCLUDESYMS);
753 case OPTION_EXCLUDE_ALL_SYMBOLS:
754 pep_dll_exclude_all_symbols = 1;
756 case OPTION_EXCLUDE_LIBS:
757 pep_dll_add_excludes (optarg, EXCLUDELIBS);
759 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
760 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
762 case OPTION_KILL_ATS:
763 pep_dll_kill_ats = 1;
765 case OPTION_STDCALL_ALIASES:
766 pep_dll_stdcall_aliases = 1;
768 case OPTION_ENABLE_STDCALL_FIXUP:
769 pep_enable_stdcall_fixup = 1;
771 case OPTION_DISABLE_STDCALL_FIXUP:
772 pep_enable_stdcall_fixup = 0;
774 case OPTION_WARN_DUPLICATE_EXPORTS:
775 pep_dll_warn_dup_exports = 1;
777 case OPTION_IMP_COMPAT:
778 pep_dll_compat_implib = 1;
780 case OPTION_ENABLE_AUTO_IMAGE_BASE:
781 pep_enable_auto_image_base = 1;
783 case OPTION_DISABLE_AUTO_IMAGE_BASE:
784 pep_enable_auto_image_base = 0;
786 case OPTION_DLL_SEARCH_PREFIX:
787 pep_dll_search_prefix = xstrdup (optarg);
789 case OPTION_NO_DEFAULT_EXCLUDES:
790 pep_dll_do_default_excludes = 0;
792 case OPTION_DLL_ENABLE_AUTO_IMPORT:
793 link_info.pei386_auto_import = 1;
795 case OPTION_DLL_DISABLE_AUTO_IMPORT:
796 link_info.pei386_auto_import = 0;
798 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
799 link_info.pei386_runtime_pseudo_reloc = 2;
801 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
802 link_info.pei386_runtime_pseudo_reloc = 0;
804 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
805 link_info.pei386_runtime_pseudo_reloc = 2;
807 case OPTION_ENABLE_EXTRA_PE_DEBUG:
808 pep_dll_extra_pe_debug = 1;
811 case OPTION_ENABLE_LONG_SECTION_NAMES:
812 pep_use_coff_long_section_names = 1;
814 case OPTION_DISABLE_LONG_SECTION_NAMES:
815 pep_use_coff_long_section_names = 0;
817 /* Get DLLCharacteristics bits */
818 case OPTION_HIGH_ENTROPY_VA:
819 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
821 case OPTION_DYNAMIC_BASE:
822 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
824 case OPTION_ENABLE_RELOC_SECTION:
825 pep_dll_enable_reloc_section = 1;
827 case OPTION_DISABLE_RELOC_SECTION:
828 pep_dll_enable_reloc_section = 0;
830 case OPTION_DISABLE_DYNAMIC_BASE:
831 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
833 case OPTION_DISABLE_HIGH_ENTROPY_VA:
834 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
836 case OPTION_FORCE_INTEGRITY:
837 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
839 case OPTION_DISABLE_FORCE_INTEGRITY:
840 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
842 case OPTION_NX_COMPAT:
843 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
845 case OPTION_DISABLE_NX_COMPAT:
846 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
848 case OPTION_NO_ISOLATION:
849 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
851 case OPTION_DISABLE_NO_ISOLATION:
852 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
855 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
857 case OPTION_DISABLE_NO_SEH:
858 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_SEH;
861 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
863 case OPTION_DISABLE_NO_BIND:
864 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_BIND;
866 case OPTION_WDM_DRIVER:
867 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
869 case OPTION_DISABLE_WDM_DRIVER:
870 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
872 case OPTION_TERMINAL_SERVER_AWARE:
873 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
875 case OPTION_DISABLE_TERMINAL_SERVER_AWARE:
876 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
878 case OPTION_BUILD_ID:
879 free ((char *) emit_build_id);
880 emit_build_id = NULL;
882 optarg = DEFAULT_BUILD_ID_STYLE;
883 if (strcmp (optarg, "none"))
884 emit_build_id = xstrdup (optarg);
889 if (optarg && optarg[0])
890 pdb_name = xstrdup (optarg);
895 /* Set DLLCharacteristics bits */
896 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
904 strhash (const char *str)
906 const unsigned char *s;
913 s = (const unsigned char *) str;
914 while ((c = *s++) != '\0')
916 hash += c + (c << 17);
920 hash += len + (len << 17);
926 /* Use the output file to create a image base for relocatable DLLs. */
929 compute_dll_image_base (const char *ofile)
931 bfd_vma hash = (bfd_vma) strhash (ofile);
932 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
936 /* Assign values to the special symbols before the linker script is
940 gld${EMULATION_NAME}_set_symbols (void)
942 /* Run through and invent symbols for all the
943 names and insert the defaults. */
948 if (!init[IMAGEBASEOFF].inited)
950 if (bfd_link_relocatable (&link_info))
951 init[IMAGEBASEOFF].value = 0;
952 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
955 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
956 ? compute_dll_image_base (output_filename)
957 : NT_DLL_IMAGE_BASE);
959 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
963 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
964 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
967 /* Don't do any symbol assignments if this is a relocatable link. */
968 if (bfd_link_relocatable (&link_info))
971 /* Glue the assignments into the abs section. */
972 push_stat_ptr (&abs_output_section->children);
974 for (j = 0; init[j].ptr; j++)
976 bfd_vma val = init[j].value;
977 lang_assignment_statement_type *rv;
979 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
980 exp_intop (val), false));
981 if (init[j].size == sizeof (short))
982 *(short *) init[j].ptr = (short) val;
983 else if (init[j].size == sizeof (int))
984 *(int *) init[j].ptr = (int) val;
985 else if (init[j].size == sizeof (long))
986 *(long *) init[j].ptr = (long) val;
987 /* This might be a long long or other special type. */
988 else if (init[j].size == sizeof (bfd_vma))
989 *(bfd_vma *) init[j].ptr = val;
991 if (j == IMAGEBASEOFF)
992 image_base_statement = rv;
994 /* Restore the pointer. */
997 if (pep.FileAlignment > pep.SectionAlignment)
999 einfo (_("%P: warning, file alignment > section alignment\n"));
1003 /* This is called after the linker script and the command line options
1007 gld${EMULATION_NAME}_after_parse (void)
1009 /* PR ld/6744: Warn the user if they have used an ELF-only
1010 option hoping it will work on PE+. */
1011 if (link_info.export_dynamic)
1012 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
1013 "targets, did you mean --export-all-symbols?\n"));
1016 if (pdb && emit_build_id == NULL)
1017 emit_build_id = xstrdup (DEFAULT_BUILD_ID_STYLE);
1022 after_parse_default ();
1026 static struct bfd_link_hash_entry *pep_undef_found_sym;
1029 pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
1033 const char *hs = h->root.string;
1035 sl = strlen (string);
1036 if (h->type == bfd_link_hash_defined
1037 && ((*hs == '@' && *string == '_'
1038 && strncmp (hs + 1, string + 1, sl - 1) == 0)
1039 || strncmp (hs, string, sl) == 0)
1040 && h->root.string[sl] == '@')
1042 pep_undef_found_sym = h;
1049 set_decoration (const char *undecorated_name,
1050 struct bfd_link_hash_entry * decoration)
1052 static bool gave_warning_message = false;
1053 struct decoration_hash_entry *entry;
1055 if (is_underscoring () && undecorated_name[0] == '_')
1058 entry = (struct decoration_hash_entry *)
1059 bfd_hash_lookup (&(coff_hash_table (&link_info)->decoration_hash),
1060 undecorated_name, true /* create */, false /* copy */);
1062 if (entry->decorated_link != NULL && !gave_warning_message)
1064 einfo (_("%P: warning: overwriting decorated name %s with %s\n"),
1065 entry->decorated_link->root.string, undecorated_name);
1066 gave_warning_message = true;
1069 entry->decorated_link = decoration;
1073 pep_fixup_stdcalls (void)
1075 static int gave_warning_message = 0;
1076 struct bfd_link_hash_entry *undef, *sym;
1078 if (pep_dll_extra_pe_debug)
1079 printf ("%s\n", __func__);
1081 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1082 if (undef->type == bfd_link_hash_undefined)
1084 char* at = strchr (undef->root.string, '@');
1085 int lead_at = (*undef->root.string == '@');
1087 at = strchr (undef->root.string + 1, '@');
1090 /* The symbol is a stdcall symbol, so let's look for a
1091 cdecl symbol with the same name and resolve to that. */
1092 char *cname = xstrdup (undef->root.string);
1096 at = strchr (cname, '@');
1099 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1101 if (sym && sym->type == bfd_link_hash_defined)
1103 undef->type = bfd_link_hash_defined;
1104 undef->u.def.value = sym->u.def.value;
1105 undef->u.def.section = sym->u.def.section;
1107 if (pep_enable_stdcall_fixup == -1)
1109 einfo (_("warning: resolving %s by linking to %s\n"),
1110 undef->root.string, cname);
1111 if (! gave_warning_message)
1113 gave_warning_message = 1;
1114 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1115 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1122 /* The symbol is a cdecl symbol, so we look for stdcall
1123 symbols - which means scanning the whole symbol table. */
1124 pep_undef_found_sym = 0;
1125 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
1126 (char *) undef->root.string);
1127 sym = pep_undef_found_sym;
1130 undef->type = bfd_link_hash_defined;
1131 undef->u.def.value = sym->u.def.value;
1132 undef->u.def.section = sym->u.def.section;
1133 set_decoration (undef->root.string, sym);
1135 if (pep_enable_stdcall_fixup == -1)
1137 einfo (_("warning: resolving %s by linking to %s\n"),
1138 undef->root.string, sym->root.string);
1139 if (! gave_warning_message)
1141 gave_warning_message = 1;
1142 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1143 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1152 read_addend (arelent *rel, asection *s)
1158 switch (rel->howto->bitsize)
1161 ok = bfd_get_section_contents (s->owner, s, buf, rel->address, 1);
1164 if (rel->howto->pc_relative)
1165 addend = bfd_get_signed_8 (s->owner, buf);
1167 addend = bfd_get_8 (s->owner, buf);
1171 ok = bfd_get_section_contents (s->owner, s, buf, rel->address, 2);
1174 if (rel->howto->pc_relative)
1175 addend = bfd_get_signed_16 (s->owner, buf);
1177 addend = bfd_get_16 (s->owner, buf);
1182 ok = bfd_get_section_contents (s->owner, s, buf, rel->address, 4);
1185 if (rel->howto->pc_relative)
1186 addend = bfd_get_signed_32 (s->owner, buf);
1188 addend = bfd_get_32 (s->owner, buf);
1192 ok = bfd_get_section_contents (s->owner, s, buf, rel->address, 8);
1194 addend = bfd_get_64 (s->owner, buf);
1198 einfo (_("%P: %H: cannot get section contents - auto-import exception\n"),
1199 s->owner, s, rel->address);
1204 make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
1206 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1209 if (pep_dll_extra_pe_debug)
1210 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1211 (unsigned long) rel->address, (long) rel->addend);
1213 addend = read_addend (rel, s);
1215 if (pep_dll_extra_pe_debug)
1217 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx",
1218 (long) addend, (long) rel->addend, (long) rel->address);
1219 if (rel->howto->pc_relative)
1221 printf (" %d bit rel.\n", (int) rel->howto->bitsize);
1224 pep_create_import_fixup (rel, s, addend, name, symname);
1228 make_runtime_ref (void)
1230 const char *rr = U ("_pei386_runtime_relocator");
1231 struct bfd_link_hash_entry *h
1232 = bfd_wrapped_link_hash_lookup (link_info.output_bfd, &link_info,
1233 rr, true, false, true);
1235 einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
1238 if (h->type == bfd_link_hash_new)
1240 h->type = bfd_link_hash_undefined;
1241 h->u.undef.abfd = NULL;
1242 if (h->u.undef.next == NULL && h != link_info.hash->undefs_tail)
1243 bfd_link_add_undef (link_info.hash, h);
1245 h->non_ir_ref_regular = true;
1250 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1252 printf ("+%s\n", h->string);
1256 #endif /* DLL_SUPPORT */
1259 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1261 int *found = (int *) obj;
1263 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1268 pecoff_checksum_contents (bfd *abfd,
1269 void (*process) (const void *, size_t, void *),
1272 file_ptr filepos = (file_ptr) 0;
1279 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1282 status = bfd_read (&b, 1, abfd);
1288 (*process) (&b, 1, arg);
1296 write_build_id (bfd *abfd)
1298 struct pe_tdata *td = pe_data (abfd);
1300 struct bfd_link_order *link_order = NULL;
1301 unsigned char *contents;
1302 bfd_size_type build_id_size;
1303 unsigned char *build_id;
1304 const char *pdb_base_name = NULL;
1306 /* Find the section the .buildid output section has been merged info. */
1307 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1309 struct bfd_link_order *l = NULL;
1310 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1312 if (l->type == bfd_indirect_link_order)
1314 if (l->u.indirect.section == td->build_id.sec)
1328 einfo (_("%P: warning: .buildid section discarded,"
1329 " --build-id ignored\n"));
1333 if (td->build_id.sec->contents == NULL)
1334 td->build_id.sec->contents = xmalloc (td->build_id.sec->size);
1335 contents = td->build_id.sec->contents;
1337 build_id_size = compute_build_id_size (td->build_id.style);
1338 build_id = xmalloc (build_id_size);
1339 generate_build_id (abfd, td->build_id.style, pecoff_checksum_contents,
1340 build_id, build_id_size);
1342 bfd_vma ib = td->pe_opthdr.ImageBase;
1346 pdb_base_name = lbasename (pdb_name);
1349 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1350 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1351 idd.Characteristics = 0;
1352 idd.TimeDateStamp = 0;
1353 idd.MajorVersion = 0;
1354 idd.MinorVersion = 0;
1355 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1356 idd.SizeOfData = (sizeof (CV_INFO_PDB70)
1358 + (pdb_base_name ? strlen (pdb_base_name) : 0)
1361 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1362 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1363 idd.PointerToRawData = asec->filepos + link_order->offset
1364 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1366 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1367 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1369 /* Write the debug directory entry. */
1370 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1373 if (bfd_write (contents, sizeof (*ext), abfd) != sizeof (*ext))
1379 if (!create_pdb_file (abfd, pdb_name, build_id))
1384 /* Construct the CodeView record. */
1385 CODEVIEW_INFO cvinfo;
1386 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1389 /* Zero pad or truncate the generated build_id to fit in the
1391 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1392 memcpy (&(cvinfo.Signature), build_id,
1393 (build_id_size > CV_INFO_SIGNATURE_LENGTH
1394 ? CV_INFO_SIGNATURE_LENGTH : build_id_size));
1398 /* Write the codeview record. */
1399 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo,
1400 pdb_base_name) == 0)
1403 /* Record the location of the debug directory in the data directory. */
1404 td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1405 = asec->vma - ib + link_order->offset;
1406 td->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1407 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1412 /* Make .buildid section, and set up coff_tdata->build_id. */
1414 setup_build_id (bfd *ibfd)
1419 if (!validate_build_id_style (emit_build_id))
1421 einfo (_("%P: warning: unrecognized --build-id style ignored\n"));
1425 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1426 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1427 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
1430 struct pe_tdata *td = pe_data (link_info.output_bfd);
1431 td->build_id.after_write_object_contents = &write_build_id;
1432 td->build_id.style = emit_build_id;
1433 td->build_id.sec = s;
1435 /* Section is a fixed size:
1436 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1437 pointing at a CV_INFO_PDB70 record containing the build-id, followed by
1438 PdbFileName if relevant. */
1439 s->size = (sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1440 + sizeof (CV_INFO_PDB70) + 1);
1444 s->size += strlen (lbasename (pdb_name));
1449 einfo (_("%P: warning: cannot create .buildid section,"
1450 " --build-id ignored\n"));
1455 gld${EMULATION_NAME}_before_plugin_all_symbols_read (void)
1458 if (link_info.lto_plugin_active
1459 && link_info.pei386_auto_import) /* -1=warn or 1=enable */
1460 make_runtime_ref ();
1465 gld${EMULATION_NAME}_after_open (void)
1467 after_open_default ();
1471 if (pep_dll_extra_pe_debug)
1474 struct bfd_link_hash_entry *sym;
1476 printf ("%s()\n", __func__);
1478 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1479 printf ("-%s\n", sym->root.string);
1480 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1482 for (a = link_info.input_bfds; a; a = a->link.next)
1483 printf ("*%s\n", bfd_get_filename (a));
1488 if (pdb && !pdb_name)
1490 const char *base = lbasename (bfd_get_filename (link_info.output_bfd));
1491 size_t len = strlen (base);
1492 static const char suffix[] = ".pdb";
1494 while (len > 0 && base[len] != '.')
1500 len = strlen (base);
1502 pdb_name = xmalloc (len + sizeof (suffix));
1503 memcpy (pdb_name, base, len);
1504 memcpy (pdb_name + len, suffix, sizeof (suffix));
1508 if (emit_build_id != NULL)
1512 /* Find a COFF input. */
1513 for (abfd = link_info.input_bfds;
1514 abfd != (bfd *) NULL; abfd = abfd->link.next)
1515 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1518 /* If there are no COFF input files do not try to
1519 add a build-id section. */
1521 || !setup_build_id (abfd))
1523 free ((char *) emit_build_id);
1524 emit_build_id = NULL;
1528 /* Pass the wacky PE command line options into the output bfd.
1529 FIXME: This should be done via a function, rather than by
1530 including an internal BFD header. */
1532 if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
1533 || coff_data (link_info.output_bfd) == NULL
1534 || !obj_pe (link_info.output_bfd))
1535 einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
1536 link_info.output_bfd);
1538 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1539 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1540 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1541 if (insert_timestamp)
1542 pe_data (link_info.output_bfd)->timestamp = -1;
1544 pe_data (link_info.output_bfd)->timestamp = 0;
1546 /* At this point we must decide whether to use long section names
1547 in the output or not. If the user hasn't explicitly specified
1548 on the command line, we leave it to the default for the format
1549 (object files yes, image files no), except if there is debug
1550 information present; GDB relies on the long section names to
1551 find it, so enable it in that case. */
1552 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1554 if (bfd_link_relocatable (&link_info))
1555 pep_use_coff_long_section_names = 1;
1558 /* Iterate over all sections of all input BFDs, checking
1559 for any that begin 'debug_' and are long names. */
1560 LANG_FOR_EACH_INPUT_STATEMENT (is)
1562 int found_debug = 0;
1564 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1567 pep_use_coff_long_section_names = 1;
1574 pep_output_file_set_long_section_names (link_info.output_bfd);
1577 pep_process_import_defs (link_info.output_bfd, &link_info);
1579 if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
1580 pep_find_data_imports (U ("_head_"), make_import_fixup);
1582 /* The implementation of the feature is rather dumb and would cause the
1583 compilation time to go through the roof if there are many undefined
1584 symbols in the link, so it needs to be run after auto-import. */
1585 if (pep_enable_stdcall_fixup) /* -1=warn or 1=enable */
1586 pep_fixup_stdcalls ();
1588 #if !defined(TARGET_IS_i386pep) && !defined(COFF_WITH_peAArch64)
1589 if (bfd_link_pic (&link_info))
1591 if (!bfd_link_relocatable (&link_info))
1593 pep_dll_build_sections (link_info.output_bfd, &link_info);
1595 #if !defined(TARGET_IS_i386pep) && !defined(COFF_WITH_peAArch64)
1597 pep_exe_build_sections (link_info.output_bfd, &link_info);
1599 #endif /* DLL_SUPPORT */
1602 /* This next chunk of code tries to detect the case where you have
1603 two import libraries for the same DLL (specifically,
1604 symbolically linking libm.a and libc.a in cygwin to
1605 libcygwin.a). In those cases, it's possible for function
1606 thunks from the second implib to be used but without the
1607 head/tail objects, causing an improper import table. We detect
1608 those cases and rename the "other" import libraries to match
1609 the one the head/tail come from, so that the linker will sort
1610 things nicely and produce a valid import table. */
1612 LANG_FOR_EACH_INPUT_STATEMENT (is)
1614 if (is->the_bfd->my_archive)
1616 int idata2 = 0, reloc_count=0, is_imp = 0;
1619 /* See if this is an import library thunk. */
1620 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1622 if (strcmp (sec->name, ".idata\$2") == 0)
1624 if (startswith (sec->name, ".idata\$"))
1626 reloc_count += sec->reloc_count;
1629 if (is_imp && !idata2 && reloc_count)
1631 /* It is, look for the reference to head and see if it's
1632 from our own library. */
1633 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1641 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1645 if (!bfd_generic_link_read_symbols (is->the_bfd))
1647 einfo (_("%F%P: %pB: could not read symbols: %E\n"),
1651 symbols = bfd_get_outsymbols (is->the_bfd);
1653 relocs = xmalloc ((size_t) relsize);
1654 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1659 einfo (_("%X%P: unable to process relocs: %E\n"));
1663 for (i = 0; i < nrelocs; i++)
1665 struct bfd_symbol *s;
1666 struct bfd_link_hash_entry * blhe;
1668 const char *other_bfd_filename;
1670 s = (relocs[i]->sym_ptr_ptr)[0];
1672 if (s->flags & BSF_LOCAL)
1675 /* Thunk section with reloc to another bfd. */
1676 blhe = bfd_link_hash_lookup (link_info.hash,
1678 false, false, true);
1681 || blhe->type != bfd_link_hash_defined)
1684 other_bfd = blhe->u.def.section->owner;
1685 if (other_bfd->my_archive == is->the_bfd->my_archive)
1689 = (other_bfd->my_archive
1690 ? bfd_get_filename (other_bfd->my_archive)
1691 : bfd_get_filename (other_bfd));
1693 if (filename_cmp (bfd_get_filename
1694 (is->the_bfd->my_archive),
1695 other_bfd_filename) == 0)
1698 /* Sort this implib to match the other one. */
1699 lang_input_statement_type *arch_is
1700 = bfd_usrdata (is->the_bfd->my_archive);
1701 arch_is->sort_key = other_bfd_filename;
1706 /* Note - we do not free the symbols,
1707 they are now cached in the BFD. */
1716 /* Careful - this is a shell script. Watch those dollar signs! */
1717 /* Microsoft import libraries have every member named the same,
1718 and not in the right order for us to link them correctly. We
1719 must detect these and rename the members so that they'll link
1720 correctly. There are three types of objects: the head, the
1721 thunks, and the sentinel(s). The head is easy; it's the one
1722 with idata2. We assume that the sentinels won't have relocs,
1723 and the thunks will. It's easier than checking the symbol
1724 table for external references. */
1725 LANG_FOR_EACH_INPUT_STATEMENT (is)
1727 if (is->the_bfd->my_archive)
1731 /* Microsoft import libraries may contain archive members for
1732 one or more DLLs, together with static object files.
1733 Inspect all members that are named *.dll - check whether
1734 they contain .idata sections. Do the renaming of all
1735 archive members that seem to be Microsoft style import
1737 pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
1739 if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0))
1741 int idata2 = 0, reloc_count = 0, idata = 0;
1743 char *new_name, seq;
1745 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1747 if (strcmp (sec->name, ".idata\$2") == 0)
1749 if (strncmp (sec->name, ".idata\$", 6) == 0)
1751 reloc_count += sec->reloc_count;
1754 /* An archive member named .dll, but not having any .idata
1755 sections - apparently not a Microsoft import object
1756 after all: Skip renaming it. */
1760 if (idata2) /* .idata2 is the TOC */
1762 else if (reloc_count > 0) /* thunks */
1768 = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
1769 sprintf (new_name, "%s.%c",
1770 bfd_get_filename (is->the_bfd), seq);
1771 is->sort_key = new_name;
1779 gld${EMULATION_NAME}_before_allocation (void)
1782 before_allocation_default ();
1786 /* This is called when an input file isn't recognized as a BFD. We
1787 check here for .DEF files and pull them in automatically. */
1790 saw_option (char *option)
1796 for (i = 0; init[i].ptr; i++)
1797 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1798 return init[i].inited;
1801 #endif /* DLL_SUPPORT */
1804 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1807 const char *ext = strrchr (entry->filename, '.');
1809 if (ext != NULL && fileext_cmp (ext + 1, "def") == 0)
1811 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1815 int i, buflen=0, len;
1818 for (i = 0; i < pep_def_file->num_exports; i++)
1820 len = strlen (pep_def_file->exports[i].internal_name);
1821 if (buflen < len + 2)
1825 buf = xmalloc (buflen);
1827 for (i = 0; i < pep_def_file->num_exports; i++)
1829 struct bfd_link_hash_entry *h;
1831 sprintf (buf, "%s%s", U (""),
1832 pep_def_file->exports[i].internal_name);
1834 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1835 if (h == (struct bfd_link_hash_entry *) NULL)
1836 einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
1837 if (h->type == bfd_link_hash_new)
1839 h->type = bfd_link_hash_undefined;
1840 h->u.undef.abfd = NULL;
1841 bfd_link_add_undef (link_info.hash, h);
1846 /* def_file_print (stdout, pep_def_file); */
1847 if (pep_def_file->is_dll == 1)
1848 link_info.type = type_dll;
1850 if (pep_def_file->base_address != (bfd_vma)(-1))
1853 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1854 = init[IMAGEBASEOFF].value
1855 = pep_def_file->base_address;
1856 init[IMAGEBASEOFF].inited = 1;
1857 if (image_base_statement)
1858 image_base_statement->exp
1859 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1863 if (pep_def_file->stack_reserve != -1
1864 && ! saw_option ("__size_of_stack_reserve__"))
1866 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1867 if (pep_def_file->stack_commit != -1)
1868 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1870 if (pep_def_file->heap_reserve != -1
1871 && ! saw_option ("__size_of_heap_reserve__"))
1873 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1874 if (pep_def_file->heap_commit != -1)
1875 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1885 gld${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1889 #ifdef TARGET_IS_i386pep
1890 pep_dll_id_target ("pei-x86-64");
1891 #elif defined(COFF_WITH_peAArch64)
1892 pep_dll_id_target ("pei-aarch64-little");
1894 if (pep_bfd_is_dll (entry->the_bfd))
1895 return pep_implied_import_dll (entry->filename);
1901 gld${EMULATION_NAME}_finish (void)
1907 if (bfd_link_pic (&link_info)
1908 || pep_dll_enable_reloc_section
1909 || (!bfd_link_relocatable (&link_info)
1910 && pep_def_file->num_exports != 0))
1912 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1913 if (command_line.out_implib_filename
1914 && (pep_def_file->num_exports != 0
1915 || bfd_link_pic (&link_info)))
1916 pep_dll_generate_implib (pep_def_file,
1917 command_line.out_implib_filename, &link_info);
1920 if (pep_out_def_filename)
1921 pep_dll_generate_def_file (pep_out_def_filename);
1922 #endif /* DLL_SUPPORT */
1924 /* I don't know where .idata gets set as code, but it shouldn't be. */
1926 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1930 asec->flags &= ~SEC_CODE;
1931 asec->flags |= SEC_DATA;
1937 /* Place an orphan section.
1939 We use this to put sections in a reasonable place in the file, and
1940 to ensure that they are aligned as required.
1942 We handle grouped sections here as well. A section named .foo\$nn
1943 goes into the output section .foo. All grouped sections are sorted
1946 Grouped sections for the default sections are handled by the
1947 default linker script using wildcards, and are sorted by
1950 static lang_output_section_statement_type *
1951 gld${EMULATION_NAME}_place_orphan (asection *s,
1952 const char *secname,
1955 const char *orig_secname = secname;
1956 char *dollar = NULL;
1957 lang_output_section_statement_type *os;
1958 lang_statement_list_type add_child;
1959 lang_output_section_statement_type *match_by_name = NULL;
1960 lang_statement_union_type **pl;
1962 /* Look through the script to see where to place this section. */
1963 if (!bfd_link_relocatable (&link_info)
1964 && (dollar = strchr (secname, '\$')) != NULL)
1966 size_t len = dollar - secname;
1967 char *newname = xmalloc (len + 1);
1968 memcpy (newname, secname, len);
1969 newname[len] = '\0';
1973 lang_list_init (&add_child);
1976 if (constraint == 0)
1977 for (os = lang_output_section_find (secname);
1979 os = next_matching_output_section_statement (os, 0))
1981 /* If we don't match an existing output section, tell
1982 lang_insert_orphan to create a new output section. */
1983 constraint = SPECIAL;
1985 if (os->bfd_section != NULL
1986 && (os->bfd_section->flags == 0
1987 || ((s->flags ^ os->bfd_section->flags)
1988 & (SEC_LOAD | SEC_ALLOC)) == 0))
1990 /* We already have an output section statement with this
1991 name, and its bfd section has compatible flags.
1992 If the section already exists but does not have any flags set,
1993 then it has been created by the linker, probably as a result of
1994 a --section-start command line switch. */
1995 lang_add_section (&add_child, s, NULL, NULL, os);
1999 /* Save unused output sections in case we can match them
2000 against orphans later. */
2001 if (os->bfd_section == NULL)
2005 /* If we didn't match an active output section, see if we matched an
2006 unused one and use that. */
2007 if (os == NULL && match_by_name)
2009 lang_add_section (&match_by_name->children, s, NULL, NULL, match_by_name);
2010 return match_by_name;
2015 static struct orphan_save hold[] =
2018 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2021 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2024 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2027 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2033 enum orphan_save_index
2041 static int orphan_init_done = 0;
2042 struct orphan_save *place;
2043 lang_output_section_statement_type *after;
2044 etree_type *address;
2048 if (!orphan_init_done)
2050 struct orphan_save *ho;
2051 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2052 if (ho->name != NULL)
2054 ho->os = lang_output_section_find (ho->name);
2055 if (ho->os != NULL && ho->os->flags == 0)
2056 ho->os->flags = ho->flags;
2058 orphan_init_done = 1;
2062 if (!bfd_link_relocatable (&link_info))
2065 while ((nexts = bfd_get_next_section_by_name (nexts->owner,
2067 if (nexts->output_section == NULL
2068 && (nexts->flags & SEC_EXCLUDE) == 0
2069 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2070 && (nexts->owner->flags & DYNAMIC) == 0
2071 && !bfd_input_just_syms (nexts->owner))
2072 flags = (((flags ^ SEC_READONLY)
2073 | (nexts->flags ^ SEC_READONLY))
2077 /* Try to put the new output section in a reasonable place based
2078 on the section name and section flags. */
2081 if ((flags & SEC_ALLOC) == 0)
2083 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2084 place = &hold[orphan_bss];
2085 else if ((flags & SEC_READONLY) == 0)
2086 place = &hold[orphan_data];
2087 else if ((flags & SEC_CODE) == 0)
2089 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2090 : &hold[orphan_rodata]);
2093 place = &hold[orphan_text];
2098 if (place->os == NULL)
2099 place->os = lang_output_section_find (place->name);
2102 after = lang_output_section_find_by_flags (s, flags, &place->os,
2105 /* *ABS* is always the first output section statement. */
2106 after = (void *) lang_os_list.head;
2109 /* All sections in an executable must be aligned to a page boundary.
2110 In a relocatable link, just preserve the incoming alignment; the
2111 address is discarded by lang_insert_orphan in that case, anyway. */
2112 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
2113 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2115 if (bfd_link_relocatable (&link_info))
2117 os->section_alignment = exp_intop (1U << s->alignment_power);
2118 os->bfd_section->alignment_power = s->alignment_power;
2122 /* If the section name has a '\$', sort it with the other '\$'
2124 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2126 lang_input_section_type *ls;
2129 if ((*pl)->header.type != lang_input_section_enum)
2132 ls = &(*pl)->input_section;
2134 lname = bfd_section_name (ls->section);
2135 if (strchr (lname, '\$') != NULL
2136 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2140 if (add_child.head != NULL)
2142 *add_child.tail = *pl;
2143 *pl = add_child.head;
2150 gld${EMULATION_NAME}_open_dynamic_archive
2151 (const char *arch ATTRIBUTE_UNUSED,
2152 search_dirs_type *search,
2153 lang_input_statement_type *entry)
2157 const char * format;
2162 /* Preferred explicit import library for dll's. */
2163 { "lib%s.dll.a", false },
2164 /* Alternate explicit import library for dll's. */
2165 { "%s.dll.a", false },
2166 /* "libfoo.a" could be either an import lib or a static lib.
2167 For backwards compatibility, libfoo.a needs to precede
2168 libfoo.dll and foo.dll in the search. */
2169 { "lib%s.a", false },
2170 /* The 'native' spelling of an import lib name is "foo.lib". */
2171 { "%s.lib", false },
2172 /* PR 22948 - Check for an import library. */
2173 { "lib%s.lib", false },
2175 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2176 { "%s%s.dll", true },
2178 /* Try "libfoo.dll" (default preferred dll name). */
2179 { "lib%s.dll", false },
2180 /* Finally try 'native' dll name "foo.dll". */
2181 { "%s.dll", false },
2182 /* Note: If adding more formats to this table, make sure to check to
2183 see if their length is longer than libname_fmt[0].format, and if
2184 so, update the call to xmalloc() below. */
2187 static unsigned int format_max_len = 0;
2188 const char * filename;
2194 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
2197 filename = entry->filename;
2199 if (format_max_len == 0)
2200 /* We need to allow space in the memory that we are going to allocate
2201 for the characters in the format string. Since the format array is
2202 static we only need to calculate this information once. In theory
2203 this value could also be computed statically, but this introduces
2204 the possibility for a discrepancy and hence a possible memory
2205 corruption. The lengths we compute here will be too long because
2206 they will include any formating characters (%s) in the strings, but
2207 this will not matter. */
2208 for (i = 0; libname_fmt[i].format; i++)
2209 if (format_max_len < strlen (libname_fmt[i].format))
2210 format_max_len = strlen (libname_fmt[i].format);
2212 full_string = xmalloc (strlen (search->name)
2216 + (pep_dll_search_prefix
2217 ? strlen (pep_dll_search_prefix) : 0)
2219 /* Allow for the terminating NUL and for the path
2220 separator character that is inserted between
2221 search->name and the start of the format string. */
2224 base_string = stpcpy (full_string, search->name);
2225 *base_string++ = '/';
2227 for (i = 0; libname_fmt[i].format; i++)
2230 if (libname_fmt[i].use_prefix)
2232 if (!pep_dll_search_prefix)
2234 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2238 sprintf (base_string, libname_fmt[i].format, filename);
2240 if (ldfile_try_open_bfd (full_string, entry))
2244 if (!libname_fmt[i].format)
2250 entry->filename = full_string;
2256 gld${EMULATION_NAME}_find_potential_libraries
2257 (char *name, lang_input_statement_type *entry)
2259 return ldfile_open_file_search (name, entry, "", ".lib");
2263 gld${EMULATION_NAME}_get_script (int *isfile)
2266 if test x"$COMPILE_IN" = xyes
2268 # Scripts compiled in.
2270 # sed commands to quote an ld script as a C string.
2271 sc="-f ${srcdir}/emultempl/stringify.sed"
2277 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2280 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2281 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2282 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2283 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2284 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2285 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2286 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2287 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2288 echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
2289 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2291 echo ' ; else return' >> e${EMULATION_NAME}.c
2292 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2293 echo '; }' >> e${EMULATION_NAME}.c
2296 # Scripts read from the filesystem.
2302 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2303 return "ldscripts/${EMULATION_NAME}.xu";
2304 else if (bfd_link_relocatable (&link_info))
2305 return "ldscripts/${EMULATION_NAME}.xr";
2306 else if (!config.text_read_only)
2307 return "ldscripts/${EMULATION_NAME}.xbn";
2308 else if (!config.magic_demand_paged)
2309 return "ldscripts/${EMULATION_NAME}.xn";
2311 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2313 else if (link_info.pei386_auto_import == 1
2314 && link_info.pei386_runtime_pseudo_reloc != 2)
2315 return "ldscripts/${EMULATION_NAME}.xa";
2320 return "ldscripts/${EMULATION_NAME}.x";
2325 LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
2326 LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ=gld${EMULATION_NAME}_before_plugin_all_symbols_read
2327 LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
2328 LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation
2329 LDEMUL_FINISH=gld${EMULATION_NAME}_finish
2330 LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld${EMULATION_NAME}_open_dynamic_archive
2331 LDEMUL_PLACE_ORPHAN=gld${EMULATION_NAME}_place_orphan
2332 LDEMUL_SET_SYMBOLS=gld${EMULATION_NAME}_set_symbols
2333 LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
2334 LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
2335 LDEMUL_UNRECOGNIZED_FILE=gld${EMULATION_NAME}_unrecognized_file
2336 LDEMUL_LIST_OPTIONS=gld${EMULATION_NAME}_list_options
2337 LDEMUL_RECOGNIZED_FILE=gld${EMULATION_NAME}_recognized_file
2338 LDEMUL_FIND_POTENTIAL_LIBRARIES=gld${EMULATION_NAME}_find_potential_libraries
2340 source_em ${srcdir}/emultempl/emulation.em