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-2022 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_i386pep)
54 #define COFF_WITH_pex64
62 #include "libiberty.h"
63 #include "filenames.h"
74 #include "ldbuildid.h"
75 #include "coff/internal.h"
77 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
78 header in generic PE code. */
79 #ifdef TARGET_IS_i386pep
80 # include "coff/x86_64.h"
81 #elif defined TARGET_IS_aarch64pe
82 # include "coff/aarch64.h"
86 /* FIXME: These are BFD internal header files, and we should not be
88 #include "../bfd/libcoff.h"
89 #include "../bfd/libpei.h"
92 #define AOUTSZ PEPAOUTSZ
93 #define PEAOUTHDR PEPAOUTHDR
97 #include "safe-ctype.h"
99 /* Permit the emulation parameters to override the default section
100 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
101 it seem that include/coff/internal.h should not define
102 PE_DEF_SECTION_ALIGNMENT. */
103 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
104 #undef PE_DEF_SECTION_ALIGNMENT
105 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
108 #ifdef TARGET_IS_i386pep
112 #define DEFAULT_DLL_CHARACTERISTICS (${cygwin_behavior} ? 0 : \
113 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
114 | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
115 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
117 #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
118 #define PE_DEF_SUBSYSTEM 3
119 #undef NT_EXE_IMAGE_BASE
120 #define NT_EXE_IMAGE_BASE \
121 ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
123 #undef NT_DLL_IMAGE_BASE
124 #define NT_DLL_IMAGE_BASE \
125 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
127 #undef NT_DLL_AUTO_IMAGE_BASE
128 #define NT_DLL_AUTO_IMAGE_BASE \
129 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
131 #undef NT_DLL_AUTO_IMAGE_MASK
132 #define NT_DLL_AUTO_IMAGE_MASK \
133 ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
136 #undef NT_EXE_IMAGE_BASE
137 #define NT_EXE_IMAGE_BASE \
138 ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
140 #undef NT_DLL_IMAGE_BASE
141 #define NT_DLL_IMAGE_BASE \
142 ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
144 #undef NT_DLL_AUTO_IMAGE_BASE
145 #define NT_DLL_AUTO_IMAGE_BASE \
146 ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
148 #undef NT_DLL_AUTO_IMAGE_MASK
149 #define NT_DLL_AUTO_IMAGE_MASK \
150 ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
152 #undef PE_DEF_SECTION_ALIGNMENT
153 #define PE_DEF_SUBSYSTEM 2
154 #undef PE_DEF_FILE_ALIGNMENT
155 #define PE_DEF_FILE_ALIGNMENT 0x00000200
156 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
159 static struct internal_extra_pe_aouthdr pep;
161 static int pep_subsystem = ${SUBSYSTEM};
162 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
163 static int support_old_code = 0;
164 static lang_assignment_statement_type *image_base_statement = 0;
165 static unsigned short pe_dll_characteristics = DEFAULT_DLL_CHARACTERISTICS;
166 static bool insert_timestamp = true;
167 static const char *emit_build_id;
170 static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
171 static char * pep_out_def_filename = NULL;
172 static int pep_enable_auto_image_base = 0;
173 static char * pep_dll_search_prefix = NULL;
176 extern const char *output_filename;
179 is_underscoring (void)
182 if (pep_leading_underscore != -1)
183 return pep_leading_underscore;
184 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
185 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
189 pep_leading_underscore = (u != 0 ? 1 : 0);
190 return pep_leading_underscore;
193 /* A case insensitive comparison, regardless of the host platform, used for
194 comparing file extensions. */
196 fileext_cmp (const char *s1, const char *s2)
200 int c1 = TOLOWER (*s1++);
201 int c2 = *s2++; /* Assumed to be lower case from the caller. */
212 gld${EMULATION_NAME}_before_parse (void)
215 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
216 output_filename = "${EXECUTABLE_NAME:-a.exe}";
218 input_flags.dynamic = true;
219 config.has_shared = 1;
220 link_info.pei386_auto_import = 1;
221 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
225 /* PE format extra command line options. */
227 /* Used for setting flags in the PE header. */
230 OPTION_BASE_FILE = 300 + 1,
232 OPTION_FILE_ALIGNMENT,
234 OPTION_MAJOR_IMAGE_VERSION,
235 OPTION_MAJOR_OS_VERSION,
236 OPTION_MAJOR_SUBSYSTEM_VERSION,
237 OPTION_MINOR_IMAGE_VERSION,
238 OPTION_MINOR_OS_VERSION,
239 OPTION_MINOR_SUBSYSTEM_VERSION,
240 OPTION_SECTION_ALIGNMENT,
244 OPTION_SUPPORT_OLD_CODE,
247 OPTION_EXCLUDE_SYMBOLS,
248 OPTION_EXCLUDE_ALL_SYMBOLS,
250 OPTION_STDCALL_ALIASES,
251 OPTION_ENABLE_STDCALL_FIXUP,
252 OPTION_DISABLE_STDCALL_FIXUP,
253 OPTION_WARN_DUPLICATE_EXPORTS,
255 OPTION_ENABLE_AUTO_IMAGE_BASE,
256 OPTION_DISABLE_AUTO_IMAGE_BASE,
257 OPTION_DLL_SEARCH_PREFIX,
258 OPTION_NO_DEFAULT_EXCLUDES,
259 OPTION_DLL_ENABLE_AUTO_IMPORT,
260 OPTION_DLL_DISABLE_AUTO_IMPORT,
261 OPTION_ENABLE_EXTRA_PE_DEBUG,
263 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
264 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
265 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
266 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
267 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
268 OPTION_NO_LEADING_UNDERSCORE,
269 OPTION_LEADING_UNDERSCORE,
270 OPTION_ENABLE_LONG_SECTION_NAMES,
271 OPTION_DISABLE_LONG_SECTION_NAMES,
272 OPTION_HIGH_ENTROPY_VA,
274 OPTION_FORCE_INTEGRITY,
280 OPTION_INSERT_TIMESTAMP,
281 OPTION_NO_INSERT_TIMESTAMP,
282 OPTION_TERMINAL_SERVER_AWARE,
284 OPTION_ENABLE_RELOC_SECTION,
285 OPTION_DISABLE_RELOC_SECTION,
286 OPTION_DISABLE_HIGH_ENTROPY_VA,
287 OPTION_DISABLE_DYNAMIC_BASE,
288 OPTION_DISABLE_FORCE_INTEGRITY,
289 OPTION_DISABLE_NX_COMPAT,
290 OPTION_DISABLE_NO_ISOLATION,
291 OPTION_DISABLE_NO_SEH,
292 OPTION_DISABLE_NO_BIND,
293 OPTION_DISABLE_WDM_DRIVER,
294 OPTION_DISABLE_TERMINAL_SERVER_AWARE
298 gld${EMULATION_NAME}_add_options
299 (int ns ATTRIBUTE_UNUSED,
300 char **shortopts ATTRIBUTE_UNUSED,
302 struct option **longopts,
303 int nrl ATTRIBUTE_UNUSED,
304 struct option **really_longopts ATTRIBUTE_UNUSED)
306 static const struct option xtra_long[] =
309 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
310 {"dll", no_argument, NULL, OPTION_DLL},
311 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
312 {"heap", required_argument, NULL, OPTION_HEAP},
313 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
314 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
315 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
316 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
317 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
318 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
319 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
320 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
321 {"stack", required_argument, NULL, OPTION_STACK},
322 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
323 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
324 {"use-nul-prefixed-import-tables", no_argument, NULL,
325 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
326 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
327 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
329 /* getopt allows abbreviations, so we do this to stop it
330 from treating -o as an abbreviation for this option. */
331 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
332 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
333 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
334 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
335 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
336 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
337 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
338 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
339 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
340 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
341 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
342 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
343 /* getopt() allows abbreviations, so we do this to stop it from
344 treating -c as an abbreviation for these --compat-implib. */
345 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
346 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
347 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
348 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
349 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
350 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
351 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
352 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
353 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
354 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
355 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
356 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
358 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
359 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
360 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
361 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
362 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
363 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
364 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
365 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
366 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
367 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
368 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
369 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
370 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
371 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
372 {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
373 {"disable-reloc-section", no_argument, NULL, OPTION_DISABLE_RELOC_SECTION},
374 {"disable-high-entropy-va", no_argument, NULL, OPTION_DISABLE_HIGH_ENTROPY_VA},
375 {"disable-dynamicbase",no_argument, NULL, OPTION_DISABLE_DYNAMIC_BASE},
376 {"disable-forceinteg", no_argument, NULL, OPTION_DISABLE_FORCE_INTEGRITY},
377 {"disable-nxcompat", no_argument, NULL, OPTION_DISABLE_NX_COMPAT},
378 {"disable-no-isolation", no_argument, NULL, OPTION_DISABLE_NO_ISOLATION},
379 {"disable-no-seh", no_argument, NULL, OPTION_DISABLE_NO_SEH},
380 {"disable-no-bind", no_argument, NULL, OPTION_DISABLE_NO_BIND},
381 {"disable-wdmdriver", no_argument, NULL, OPTION_DISABLE_WDM_DRIVER},
382 {"disable-tsaware", no_argument, NULL, OPTION_DISABLE_TERMINAL_SERVER_AWARE},
383 {NULL, no_argument, NULL, 0}
387 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
388 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
391 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
392 parameters which may be input from the command line. */
401 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
402 C visible symbols can be prefixed by underscore dependent on target's
407 #define GET_INIT_SYMBOL_NAME(IDX) \
408 (init[(IDX)].symbol \
409 + ((!init[(IDX)].is_c_symbol || is_underscoring () == 1) ? 0 : 1))
411 /* Decorates the C visible symbol by underscore, if target requires. */
413 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
415 #define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
417 static definfo init[] =
419 /* imagebase must be first */
420 #define IMAGEBASEOFF 0
421 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, false),
423 {&dll, sizeof(dll), 0, "__dll__", 0, false},
424 #define MSIMAGEBASEOFF 2
425 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, true),
426 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, false),
427 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, false),
428 D(MajorOperatingSystemVersion,"__major_os_version__", 4, false),
429 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, false),
430 D(MajorImageVersion,"__major_image_version__", 0, false),
431 D(MinorImageVersion,"__minor_image_version__", 0, false),
432 D(MajorSubsystemVersion,"__major_subsystem_version__", 5, false),
433 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2, false),
434 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, false),
435 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, false),
436 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, false),
437 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, false),
438 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, false),
439 D(LoaderFlags,"__loader_flags__", 0x0, false),
440 D(DllCharacteristics, "__dll_characteristics__", DEFAULT_DLL_CHARACTERISTICS, false),
441 { NULL, 0, 0, NULL, 0, false}
446 gld${EMULATION_NAME}_list_options (FILE *file)
448 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
449 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
450 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
451 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
452 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
453 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
454 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
455 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
456 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
457 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
458 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
459 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
460 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
461 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
462 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
463 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
464 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero (default)\n"));
465 fprintf (file, _(" This makes binaries non-deterministic\n"));
467 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
468 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
469 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
470 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
471 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
472 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
473 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
474 fprintf (file, _(" Exclude objects, archive members from auto\n"));
475 fprintf (file, _(" export, place into import library instead\n"));
476 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
477 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
478 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
479 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports\n"));
480 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
481 create __imp_<SYMBOL> as well\n"));
482 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
483 unless user specifies one\n"));
484 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base (default)\n"));
485 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
486 an importlib, use <string><basename>.dll\n\
487 in preference to lib<basename>.dll \n"));
488 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
489 __imp_sym for DATA references\n"));
490 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
491 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
492 adding pseudo-relocations resolved at\n\
494 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
495 auto-imported DATA\n"));
496 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
497 or linking to DLLs (esp. auto-import)\n"));
498 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
499 executable image files\n"));
500 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
501 in object files\n"));
502 fprintf (file, _(" --[disable-]high-entropy-va Image is compatible with 64-bit address space\n\
503 layout randomization (ASLR)\n"));
504 fprintf (file, _(" --[disable-]dynamicbase Image base address may be relocated using\n\
505 address space layout randomization (ASLR)\n"));
506 fprintf (file, _(" --enable-reloc-section Create the base relocation table\n"));
507 fprintf (file, _(" --disable-reloc-section Do not create the base relocation table\n"));
508 fprintf (file, _(" --[disable-]forceinteg Code integrity checks are enforced\n"));
509 fprintf (file, _(" --[disable-]nxcompat Image is compatible with data execution\n\
511 fprintf (file, _(" --[disable-]no-isolation Image understands isolation but do not\n\
512 isolate the image\n"));
513 fprintf (file, _(" --[disable-]no-seh Image does not use SEH; no SE handler may\n\
514 be called in this image\n"));
515 fprintf (file, _(" --[disable-]no-bind Do not bind this image\n"));
516 fprintf (file, _(" --[disable-]wdmdriver Driver uses the WDM model\n"));
517 fprintf (file, _(" --[disable-]tsaware Image is Terminal Server aware\n"));
518 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
524 set_pep_name (char *name, bfd_vma val)
528 /* Find the name and set it. */
529 for (i = 0; init[i].ptr; i++)
531 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
535 if (strcmp (name,"__image_base__") == 0)
536 set_pep_name (U ("__ImageBase"), val);
544 set_entry_point (void)
547 const char *initial_symbol_char;
557 { 1, "NtProcessStartup" },
558 { 2, "WinMainCRTStartup" },
559 { 3, "mainCRTStartup" },
560 { 7, "__PosixProcessStartup" },
561 { 9, "WinMainCRTStartup" },
562 {14, "mainCRTStartup" },
566 /* Entry point name for arbitrary subsystem numbers. */
567 static const char default_entry[] = "mainCRTStartup";
569 if (bfd_link_dll (&link_info) || dll)
571 entry = "DllMainCRTStartup";
575 for (i = 0; v[i].entry; i++)
576 if (v[i].value == pep_subsystem)
579 /* If no match, use the default. */
580 if (v[i].entry != NULL)
583 entry = default_entry;
586 /* Now we check target's default for getting proper symbol_char. */
587 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
589 if (*initial_symbol_char != '\0')
593 /* lang_default_entry expects its argument to be permanently
594 allocated, so we don't free this string. */
595 alc_entry = xmalloc (strlen (initial_symbol_char)
598 strcpy (alc_entry, initial_symbol_char);
599 strcat (alc_entry, entry);
603 lang_default_entry (entry);
607 set_pep_subsystem (void)
613 unsigned long temp_subsystem;
630 /* Check for the presence of a version number. */
631 sver = strchr (optarg, ':');
633 len = strlen (optarg);
637 set_pep_name ("__major_subsystem_version__",
638 strtoul (sver + 1, &end, 0));
640 set_pep_name ("__minor_subsystem_version__",
641 strtoul (end + 1, &end, 0));
643 einfo (_("%P: warning: bad version number in -subsystem option\n"));
646 /* Check for numeric subsystem. */
647 temp_subsystem = strtoul (optarg, & end, 0);
648 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
650 /* Search list for a numeric match to use its entry point. */
651 for (i = 0; v[i].name; i++)
652 if (v[i].value == (int) temp_subsystem)
655 /* Use this subsystem. */
656 pep_subsystem = (int) temp_subsystem;
660 /* Search for subsystem by name. */
661 for (i = 0; v[i].name; i++)
662 if (strncmp (optarg, v[i].name, len) == 0
663 && v[i].name[len] == '\0')
666 if (v[i].name == NULL)
668 einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
672 pep_subsystem = v[i].value;
675 set_pep_name ("__subsystem__", pep_subsystem);
682 set_pep_value (char *name)
686 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
689 einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
696 set_pep_stack_heap (char *resname, char *comname)
698 set_pep_value (resname);
703 set_pep_value (comname);
706 einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
709 #define DEFAULT_BUILD_ID_STYLE "md5"
712 gld${EMULATION_NAME}_handle_option (int optc)
720 case OPTION_BASE_FILE:
721 link_info.base_file = fopen (optarg, FOPEN_WB);
722 if (link_info.base_file == NULL)
723 einfo (_("%F%P: cannot open base file %s\n"), optarg);
728 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
731 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
733 case OPTION_SUBSYSTEM:
734 set_pep_subsystem ();
736 case OPTION_MAJOR_OS_VERSION:
737 set_pep_value ("__major_os_version__");
739 case OPTION_MINOR_OS_VERSION:
740 set_pep_value ("__minor_os_version__");
742 case OPTION_MAJOR_SUBSYSTEM_VERSION:
743 set_pep_value ("__major_subsystem_version__");
745 case OPTION_MINOR_SUBSYSTEM_VERSION:
746 set_pep_value ("__minor_subsystem_version__");
748 case OPTION_MAJOR_IMAGE_VERSION:
749 set_pep_value ("__major_image_version__");
751 case OPTION_MINOR_IMAGE_VERSION:
752 set_pep_value ("__minor_image_version__");
754 case OPTION_FILE_ALIGNMENT:
755 set_pep_value ("__file_alignment__");
757 case OPTION_SECTION_ALIGNMENT:
758 set_pep_value ("__section_alignment__");
761 set_pep_name ("__dll__", 1);
763 case OPTION_IMAGE_BASE:
764 set_pep_value ("__image_base__");
766 case OPTION_SUPPORT_OLD_CODE:
767 support_old_code = 1;
769 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
770 pep_use_nul_prefixed_import_tables = true;
772 case OPTION_NO_LEADING_UNDERSCORE:
773 pep_leading_underscore = 0;
775 case OPTION_LEADING_UNDERSCORE:
776 pep_leading_underscore = 1;
778 case OPTION_INSERT_TIMESTAMP:
779 insert_timestamp = true;
781 case OPTION_NO_INSERT_TIMESTAMP:
782 insert_timestamp = false;
786 pep_out_def_filename = xstrdup (optarg);
788 case OPTION_EXPORT_ALL:
789 pep_dll_export_everything = 1;
791 case OPTION_EXCLUDE_SYMBOLS:
792 pep_dll_add_excludes (optarg, EXCLUDESYMS);
794 case OPTION_EXCLUDE_ALL_SYMBOLS:
795 pep_dll_exclude_all_symbols = 1;
797 case OPTION_EXCLUDE_LIBS:
798 pep_dll_add_excludes (optarg, EXCLUDELIBS);
800 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
801 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
803 case OPTION_KILL_ATS:
804 pep_dll_kill_ats = 1;
806 case OPTION_STDCALL_ALIASES:
807 pep_dll_stdcall_aliases = 1;
809 case OPTION_ENABLE_STDCALL_FIXUP:
810 pep_enable_stdcall_fixup = 1;
812 case OPTION_DISABLE_STDCALL_FIXUP:
813 pep_enable_stdcall_fixup = 0;
815 case OPTION_WARN_DUPLICATE_EXPORTS:
816 pep_dll_warn_dup_exports = 1;
818 case OPTION_IMP_COMPAT:
819 pep_dll_compat_implib = 1;
821 case OPTION_ENABLE_AUTO_IMAGE_BASE:
822 pep_enable_auto_image_base = 1;
824 case OPTION_DISABLE_AUTO_IMAGE_BASE:
825 pep_enable_auto_image_base = 0;
827 case OPTION_DLL_SEARCH_PREFIX:
828 pep_dll_search_prefix = xstrdup (optarg);
830 case OPTION_NO_DEFAULT_EXCLUDES:
831 pep_dll_do_default_excludes = 0;
833 case OPTION_DLL_ENABLE_AUTO_IMPORT:
834 link_info.pei386_auto_import = 1;
836 case OPTION_DLL_DISABLE_AUTO_IMPORT:
837 link_info.pei386_auto_import = 0;
839 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
840 link_info.pei386_runtime_pseudo_reloc = 2;
842 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
843 link_info.pei386_runtime_pseudo_reloc = 0;
845 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
846 link_info.pei386_runtime_pseudo_reloc = 2;
848 case OPTION_ENABLE_EXTRA_PE_DEBUG:
849 pep_dll_extra_pe_debug = 1;
852 case OPTION_ENABLE_LONG_SECTION_NAMES:
853 pep_use_coff_long_section_names = 1;
855 case OPTION_DISABLE_LONG_SECTION_NAMES:
856 pep_use_coff_long_section_names = 0;
858 /* Get DLLCharacteristics bits */
859 case OPTION_HIGH_ENTROPY_VA:
860 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
862 case OPTION_DYNAMIC_BASE:
863 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
865 case OPTION_ENABLE_RELOC_SECTION:
866 pep_dll_enable_reloc_section = 1;
868 case OPTION_DISABLE_RELOC_SECTION:
869 pep_dll_enable_reloc_section = 0;
871 case OPTION_DISABLE_DYNAMIC_BASE:
872 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
874 case OPTION_DISABLE_HIGH_ENTROPY_VA:
875 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
877 case OPTION_FORCE_INTEGRITY:
878 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
880 case OPTION_DISABLE_FORCE_INTEGRITY:
881 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
883 case OPTION_NX_COMPAT:
884 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
886 case OPTION_DISABLE_NX_COMPAT:
887 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
889 case OPTION_NO_ISOLATION:
890 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
892 case OPTION_DISABLE_NO_ISOLATION:
893 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
896 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
898 case OPTION_DISABLE_NO_SEH:
899 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_SEH;
902 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
904 case OPTION_DISABLE_NO_BIND:
905 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_BIND;
907 case OPTION_WDM_DRIVER:
908 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
910 case OPTION_DISABLE_WDM_DRIVER:
911 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
913 case OPTION_TERMINAL_SERVER_AWARE:
914 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
916 case OPTION_DISABLE_TERMINAL_SERVER_AWARE:
917 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
919 case OPTION_BUILD_ID:
920 free ((char *) emit_build_id);
921 emit_build_id = NULL;
923 optarg = DEFAULT_BUILD_ID_STYLE;
924 if (strcmp (optarg, "none"))
925 emit_build_id = xstrdup (optarg);
929 /* Set DLLCharacteristics bits */
930 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
938 strhash (const char *str)
940 const unsigned char *s;
947 s = (const unsigned char *) str;
948 while ((c = *s++) != '\0')
950 hash += c + (c << 17);
954 hash += len + (len << 17);
960 /* Use the output file to create a image base for relocatable DLLs. */
963 compute_dll_image_base (const char *ofile)
965 bfd_vma hash = (bfd_vma) strhash (ofile);
966 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
970 /* Assign values to the special symbols before the linker script is
974 gld${EMULATION_NAME}_set_symbols (void)
976 /* Run through and invent symbols for all the
977 names and insert the defaults. */
982 if (!init[IMAGEBASEOFF].inited)
984 if (bfd_link_relocatable (&link_info))
985 init[IMAGEBASEOFF].value = 0;
986 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
989 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
990 ? compute_dll_image_base (output_filename)
991 : NT_DLL_IMAGE_BASE);
993 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
997 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
998 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
1001 /* Don't do any symbol assignments if this is a relocatable link. */
1002 if (bfd_link_relocatable (&link_info))
1005 /* Glue the assignments into the abs section. */
1006 push_stat_ptr (&abs_output_section->children);
1008 for (j = 0; init[j].ptr; j++)
1010 bfd_vma val = init[j].value;
1011 lang_assignment_statement_type *rv;
1013 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
1014 exp_intop (val), false));
1015 if (init[j].size == sizeof (short))
1016 *(short *) init[j].ptr = (short) val;
1017 else if (init[j].size == sizeof (int))
1018 *(int *) init[j].ptr = (int) val;
1019 else if (init[j].size == sizeof (long))
1020 *(long *) init[j].ptr = (long) val;
1021 /* This might be a long long or other special type. */
1022 else if (init[j].size == sizeof (bfd_vma))
1023 *(bfd_vma *) init[j].ptr = val;
1025 if (j == IMAGEBASEOFF)
1026 image_base_statement = rv;
1028 /* Restore the pointer. */
1031 if (pep.FileAlignment > pep.SectionAlignment)
1033 einfo (_("%P: warning, file alignment > section alignment\n"));
1037 /* This is called after the linker script and the command line options
1041 gld${EMULATION_NAME}_after_parse (void)
1043 /* PR ld/6744: Warn the user if they have used an ELF-only
1044 option hoping it will work on PE+. */
1045 if (link_info.export_dynamic)
1046 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
1047 "targets, did you mean --export-all-symbols?\n"));
1051 after_parse_default ();
1055 static struct bfd_link_hash_entry *pep_undef_found_sym;
1058 pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
1062 const char *hs = h->root.string;
1064 sl = strlen (string);
1065 if (h->type == bfd_link_hash_defined
1066 && ((*hs == '@' && *string == '_'
1067 && strncmp (hs + 1, string + 1, sl - 1) == 0)
1068 || strncmp (hs, string, sl) == 0)
1069 && h->root.string[sl] == '@')
1071 pep_undef_found_sym = h;
1078 pep_fixup_stdcalls (void)
1080 static int gave_warning_message = 0;
1081 struct bfd_link_hash_entry *undef, *sym;
1083 if (pep_dll_extra_pe_debug)
1084 printf ("%s\n", __FUNCTION__);
1086 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1087 if (undef->type == bfd_link_hash_undefined)
1089 char* at = strchr (undef->root.string, '@');
1090 int lead_at = (*undef->root.string == '@');
1092 at = strchr (undef->root.string + 1, '@');
1095 /* The symbol is a stdcall symbol, so let's look for a
1096 cdecl symbol with the same name and resolve to that. */
1097 char *cname = xstrdup (undef->root.string);
1101 at = strchr (cname, '@');
1104 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1106 if (sym && sym->type == bfd_link_hash_defined)
1108 undef->type = bfd_link_hash_defined;
1109 undef->u.def.value = sym->u.def.value;
1110 undef->u.def.section = sym->u.def.section;
1112 if (pep_enable_stdcall_fixup == -1)
1114 einfo (_("warning: resolving %s by linking to %s\n"),
1115 undef->root.string, cname);
1116 if (! gave_warning_message)
1118 gave_warning_message = 1;
1119 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1120 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1127 /* The symbol is a cdecl symbol, so we look for stdcall
1128 symbols - which means scanning the whole symbol table. */
1129 pep_undef_found_sym = 0;
1130 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
1131 (char *) undef->root.string);
1132 sym = pep_undef_found_sym;
1135 undef->type = bfd_link_hash_defined;
1136 undef->u.def.value = sym->u.def.value;
1137 undef->u.def.section = sym->u.def.section;
1139 if (pep_enable_stdcall_fixup == -1)
1141 einfo (_("warning: resolving %s by linking to %s\n"),
1142 undef->root.string, sym->root.string);
1143 if (! gave_warning_message)
1145 gave_warning_message = 1;
1146 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1147 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1156 make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
1158 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1160 bfd_vma _addend = 0;
1163 if (pep_dll_extra_pe_debug)
1164 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1165 (unsigned long) rel->address, (long) rel->addend);
1167 memset (addend, 0, sizeof (addend));
1168 switch ((rel->howto->bitsize))
1171 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 1);
1172 if (suc && rel->howto->pc_relative)
1173 _addend = bfd_get_signed_8 (s->owner, addend);
1175 _addend = bfd_get_8 (s->owner, addend);
1178 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 2);
1179 if (suc && rel->howto->pc_relative)
1180 _addend = bfd_get_signed_16 (s->owner, addend);
1182 _addend = bfd_get_16 (s->owner, addend);
1185 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
1186 if (suc && rel->howto->pc_relative)
1187 _addend = bfd_get_signed_32 (s->owner, addend);
1189 _addend = bfd_get_32 (s->owner, addend);
1192 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
1194 _addend = bfd_get_64 (s->owner, addend);
1198 einfo (_("%P: %C: cannot get section contents - auto-import exception\n"),
1199 s->owner, s, rel->address);
1201 if (pep_dll_extra_pe_debug)
1203 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx",
1204 (long) _addend, (long) rel->addend, (long) rel->address);
1205 if (rel->howto->pc_relative)
1207 printf (" %d bit rel.\n", (int) rel->howto->bitsize);
1210 pep_create_import_fixup (rel, s, _addend, name, symname);
1214 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1216 printf ("+%s\n", h->string);
1220 #endif /* DLL_SUPPORT */
1223 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1225 int *found = (int *) obj;
1227 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1232 pecoff_checksum_contents (bfd *abfd,
1233 void (*process) (const void *, size_t, void *),
1236 file_ptr filepos = (file_ptr) 0;
1243 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1246 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1252 (*process) (&b, 1, arg);
1260 write_build_id (bfd *abfd)
1262 struct pe_tdata *t = pe_data (abfd);
1264 struct bfd_link_order *link_order = NULL;
1265 unsigned char *contents;
1267 bfd_size_type build_id_size;
1268 unsigned char *build_id;
1270 /* Find the section the .buildid output section has been merged info. */
1271 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1273 struct bfd_link_order *l = NULL;
1274 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1276 if (l->type == bfd_indirect_link_order)
1278 if (l->u.indirect.section == t->build_id.sec)
1292 einfo (_("%P: warning: .buildid section discarded,"
1293 " --build-id ignored\n"));
1297 if (t->build_id.sec->contents == NULL)
1298 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1299 contents = t->build_id.sec->contents;
1300 size = t->build_id.sec->size;
1302 build_id_size = compute_build_id_size (t->build_id.style);
1303 build_id = xmalloc (build_id_size);
1304 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1306 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1308 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1309 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1310 idd.Characteristics = 0;
1311 idd.TimeDateStamp = 0;
1312 idd.MajorVersion = 0;
1313 idd.MinorVersion = 0;
1314 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1315 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1316 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1317 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1318 idd.PointerToRawData = asec->filepos + link_order->offset
1319 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1321 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1322 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1324 /* Write the debug directory enttry */
1325 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1328 if (bfd_bwrite (contents, size, abfd) != size)
1331 /* Construct the CodeView record. */
1332 CODEVIEW_INFO cvinfo;
1333 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1336 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1337 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1338 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1339 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1343 /* Write the codeview record. */
1344 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1347 /* Record the location of the debug directory in the data directory. */
1348 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1349 = asec->vma - ib + link_order->offset;
1350 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1351 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1356 /* Make .buildid section, and set up coff_tdata->build_id. */
1358 setup_build_id (bfd *ibfd)
1363 if (!validate_build_id_style (emit_build_id))
1365 einfo (_("%P: warning: unrecognized --build-id style ignored\n"));
1369 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1370 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1371 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
1374 struct pe_tdata *t = pe_data (link_info.output_bfd);
1375 t->build_id.after_write_object_contents = &write_build_id;
1376 t->build_id.style = emit_build_id;
1377 t->build_id.sec = s;
1379 /* Section is a fixed size:
1380 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1381 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1382 null byte for PdbFileName. */
1383 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1384 + sizeof (CV_INFO_PDB70) + 1;
1389 einfo (_("%P: warning: cannot create .buildid section,"
1390 " --build-id ignored\n"));
1395 gld${EMULATION_NAME}_after_open (void)
1397 after_open_default ();
1401 if (pep_dll_extra_pe_debug)
1404 struct bfd_link_hash_entry *sym;
1406 printf ("%s()\n", __FUNCTION__);
1408 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1409 printf ("-%s\n", sym->root.string);
1410 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1412 for (a = link_info.input_bfds; a; a = a->link.next)
1413 printf ("*%s\n", bfd_get_filename (a));
1417 if (emit_build_id != NULL)
1421 /* Find a COFF input. */
1422 for (abfd = link_info.input_bfds;
1423 abfd != (bfd *) NULL; abfd = abfd->link.next)
1424 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1427 /* If there are no COFF input files do not try to
1428 add a build-id section. */
1430 || !setup_build_id (abfd))
1432 free ((char *) emit_build_id);
1433 emit_build_id = NULL;
1437 /* Pass the wacky PE command line options into the output bfd.
1438 FIXME: This should be done via a function, rather than by
1439 including an internal BFD header. */
1441 if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
1442 || coff_data (link_info.output_bfd) == NULL
1443 || coff_data (link_info.output_bfd)->pe == 0)
1444 einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
1445 link_info.output_bfd);
1447 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1448 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1449 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1450 if (insert_timestamp)
1451 pe_data (link_info.output_bfd)->timestamp = -1;
1453 pe_data (link_info.output_bfd)->timestamp = 0;
1455 /* At this point we must decide whether to use long section names
1456 in the output or not. If the user hasn't explicitly specified
1457 on the command line, we leave it to the default for the format
1458 (object files yes, image files no), except if there is debug
1459 information present; GDB relies on the long section names to
1460 find it, so enable it in that case. */
1461 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1463 if (bfd_link_relocatable (&link_info))
1464 pep_use_coff_long_section_names = 1;
1467 /* Iterate over all sections of all input BFDs, checking
1468 for any that begin 'debug_' and are long names. */
1469 LANG_FOR_EACH_INPUT_STATEMENT (is)
1471 int found_debug = 0;
1473 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1476 pep_use_coff_long_section_names = 1;
1483 pep_output_file_set_long_section_names (link_info.output_bfd);
1486 pep_process_import_defs (link_info.output_bfd, &link_info);
1488 if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
1489 pep_find_data_imports (U ("_head_"), make_import_fixup);
1491 /* The implementation of the feature is rather dumb and would cause the
1492 compilation time to go through the roof if there are many undefined
1493 symbols in the link, so it needs to be run after auto-import. */
1494 if (pep_enable_stdcall_fixup) /* -1=warn or 1=enable */
1495 pep_fixup_stdcalls ();
1497 #ifndef TARGET_IS_i386pep
1498 if (bfd_link_pic (&link_info))
1500 if (!bfd_link_relocatable (&link_info))
1502 pep_dll_build_sections (link_info.output_bfd, &link_info);
1504 #ifndef TARGET_IS_i386pep
1506 pep_exe_build_sections (link_info.output_bfd, &link_info);
1508 #endif /* DLL_SUPPORT */
1511 /* This next chunk of code tries to detect the case where you have
1512 two import libraries for the same DLL (specifically,
1513 symbolically linking libm.a and libc.a in cygwin to
1514 libcygwin.a). In those cases, it's possible for function
1515 thunks from the second implib to be used but without the
1516 head/tail objects, causing an improper import table. We detect
1517 those cases and rename the "other" import libraries to match
1518 the one the head/tail come from, so that the linker will sort
1519 things nicely and produce a valid import table. */
1521 LANG_FOR_EACH_INPUT_STATEMENT (is)
1523 if (is->the_bfd->my_archive)
1525 int idata2 = 0, reloc_count=0, is_imp = 0;
1528 /* See if this is an import library thunk. */
1529 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1531 if (strcmp (sec->name, ".idata\$2") == 0)
1533 if (startswith (sec->name, ".idata\$"))
1535 reloc_count += sec->reloc_count;
1538 if (is_imp && !idata2 && reloc_count)
1540 /* It is, look for the reference to head and see if it's
1541 from our own library. */
1542 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1550 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1554 if (!bfd_generic_link_read_symbols (is->the_bfd))
1556 einfo (_("%F%P: %pB: could not read symbols: %E\n"),
1560 symbols = bfd_get_outsymbols (is->the_bfd);
1562 relocs = xmalloc ((size_t) relsize);
1563 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1568 einfo (_("%X%P: unable to process relocs: %E\n"));
1572 for (i = 0; i < nrelocs; i++)
1574 struct bfd_symbol *s;
1575 struct bfd_link_hash_entry * blhe;
1577 const char *other_bfd_filename;
1579 s = (relocs[i]->sym_ptr_ptr)[0];
1581 if (s->flags & BSF_LOCAL)
1584 /* Thunk section with reloc to another bfd. */
1585 blhe = bfd_link_hash_lookup (link_info.hash,
1587 false, false, true);
1590 || blhe->type != bfd_link_hash_defined)
1593 other_bfd = blhe->u.def.section->owner;
1594 if (other_bfd->my_archive == is->the_bfd->my_archive)
1598 = (other_bfd->my_archive
1599 ? bfd_get_filename (other_bfd->my_archive)
1600 : bfd_get_filename (other_bfd));
1602 if (filename_cmp (bfd_get_filename
1603 (is->the_bfd->my_archive),
1604 other_bfd_filename) == 0)
1607 /* Sort this implib to match the other one. */
1608 lang_input_statement_type *arch_is
1609 = bfd_usrdata (is->the_bfd->my_archive);
1610 arch_is->sort_key = other_bfd_filename;
1615 /* Note - we do not free the symbols,
1616 they are now cached in the BFD. */
1625 /* Careful - this is a shell script. Watch those dollar signs! */
1626 /* Microsoft import libraries have every member named the same,
1627 and not in the right order for us to link them correctly. We
1628 must detect these and rename the members so that they'll link
1629 correctly. There are three types of objects: the head, the
1630 thunks, and the sentinel(s). The head is easy; it's the one
1631 with idata2. We assume that the sentinels won't have relocs,
1632 and the thunks will. It's easier than checking the symbol
1633 table for external references. */
1634 LANG_FOR_EACH_INPUT_STATEMENT (is)
1636 if (is->the_bfd->my_archive)
1640 /* Microsoft import libraries may contain archive members for
1641 one or more DLLs, together with static object files.
1642 Inspect all members that are named *.dll - check whether
1643 they contain .idata sections. Do the renaming of all
1644 archive members that seem to be Microsoft style import
1646 pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
1648 if (pnt != NULL && (fileext_cmp (pnt + 1, "dll") == 0))
1650 int idata2 = 0, reloc_count = 0, idata = 0;
1652 char *new_name, seq;
1654 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1656 if (strcmp (sec->name, ".idata\$2") == 0)
1658 if (strncmp (sec->name, ".idata\$", 6) == 0)
1660 reloc_count += sec->reloc_count;
1663 /* An archive member named .dll, but not having any .idata
1664 sections - apparently not a Microsoft import object
1665 after all: Skip renaming it. */
1669 if (idata2) /* .idata2 is the TOC */
1671 else if (reloc_count > 0) /* thunks */
1677 = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
1678 sprintf (new_name, "%s.%c",
1679 bfd_get_filename (is->the_bfd), seq);
1680 is->sort_key = new_name;
1688 gld${EMULATION_NAME}_before_allocation (void)
1691 before_allocation_default ();
1695 /* This is called when an input file isn't recognized as a BFD. We
1696 check here for .DEF files and pull them in automatically. */
1699 saw_option (char *option)
1705 for (i = 0; init[i].ptr; i++)
1706 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1707 return init[i].inited;
1710 #endif /* DLL_SUPPORT */
1713 gld${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1716 const char *ext = strrchr (entry->filename, '.');
1718 if (ext != NULL && fileext_cmp (ext + 1, "def") == 0)
1720 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1724 int i, buflen=0, len;
1727 for (i = 0; i < pep_def_file->num_exports; i++)
1729 len = strlen (pep_def_file->exports[i].internal_name);
1730 if (buflen < len + 2)
1734 buf = xmalloc (buflen);
1736 for (i = 0; i < pep_def_file->num_exports; i++)
1738 struct bfd_link_hash_entry *h;
1740 sprintf (buf, "%s%s", U (""),
1741 pep_def_file->exports[i].internal_name);
1743 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1744 if (h == (struct bfd_link_hash_entry *) NULL)
1745 einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
1746 if (h->type == bfd_link_hash_new)
1748 h->type = bfd_link_hash_undefined;
1749 h->u.undef.abfd = NULL;
1750 bfd_link_add_undef (link_info.hash, h);
1755 /* def_file_print (stdout, pep_def_file); */
1756 if (pep_def_file->is_dll == 1)
1757 link_info.type = type_dll;
1759 if (pep_def_file->base_address != (bfd_vma)(-1))
1762 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1763 = init[IMAGEBASEOFF].value
1764 = pep_def_file->base_address;
1765 init[IMAGEBASEOFF].inited = 1;
1766 if (image_base_statement)
1767 image_base_statement->exp
1768 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1772 if (pep_def_file->stack_reserve != -1
1773 && ! saw_option ("__size_of_stack_reserve__"))
1775 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1776 if (pep_def_file->stack_commit != -1)
1777 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1779 if (pep_def_file->heap_reserve != -1
1780 && ! saw_option ("__size_of_heap_reserve__"))
1782 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1783 if (pep_def_file->heap_commit != -1)
1784 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1794 gld${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1798 #ifdef TARGET_IS_i386pep
1799 pep_dll_id_target ("pei-x86-64");
1801 if (pep_bfd_is_dll (entry->the_bfd))
1802 return pep_implied_import_dll (entry->filename);
1808 gld${EMULATION_NAME}_finish (void)
1814 if (bfd_link_pic (&link_info)
1815 || pep_dll_enable_reloc_section
1816 || (!bfd_link_relocatable (&link_info)
1817 && pep_def_file->num_exports != 0))
1819 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1820 if (command_line.out_implib_filename
1821 && (pep_def_file->num_exports != 0
1822 || bfd_link_pic (&link_info)))
1823 pep_dll_generate_implib (pep_def_file,
1824 command_line.out_implib_filename, &link_info);
1827 if (pep_out_def_filename)
1828 pep_dll_generate_def_file (pep_out_def_filename);
1829 #endif /* DLL_SUPPORT */
1831 /* I don't know where .idata gets set as code, but it shouldn't be. */
1833 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1837 asec->flags &= ~SEC_CODE;
1838 asec->flags |= SEC_DATA;
1844 /* Place an orphan section.
1846 We use this to put sections in a reasonable place in the file, and
1847 to ensure that they are aligned as required.
1849 We handle grouped sections here as well. A section named .foo\$nn
1850 goes into the output section .foo. All grouped sections are sorted
1853 Grouped sections for the default sections are handled by the
1854 default linker script using wildcards, and are sorted by
1857 static lang_output_section_statement_type *
1858 gld${EMULATION_NAME}_place_orphan (asection *s,
1859 const char *secname,
1862 const char *orig_secname = secname;
1863 char *dollar = NULL;
1864 lang_output_section_statement_type *os;
1865 lang_statement_list_type add_child;
1866 lang_output_section_statement_type *match_by_name = NULL;
1867 lang_statement_union_type **pl;
1869 /* Look through the script to see where to place this section. */
1870 if (!bfd_link_relocatable (&link_info)
1871 && (dollar = strchr (secname, '\$')) != NULL)
1873 size_t len = dollar - secname;
1874 char *newname = xmalloc (len + 1);
1875 memcpy (newname, secname, len);
1876 newname[len] = '\0';
1880 lang_list_init (&add_child);
1883 if (constraint == 0)
1884 for (os = lang_output_section_find (secname);
1886 os = next_matching_output_section_statement (os, 0))
1888 /* If we don't match an existing output section, tell
1889 lang_insert_orphan to create a new output section. */
1890 constraint = SPECIAL;
1892 if (os->bfd_section != NULL
1893 && (os->bfd_section->flags == 0
1894 || ((s->flags ^ os->bfd_section->flags)
1895 & (SEC_LOAD | SEC_ALLOC)) == 0))
1897 /* We already have an output section statement with this
1898 name, and its bfd section has compatible flags.
1899 If the section already exists but does not have any flags set,
1900 then it has been created by the linker, probably as a result of
1901 a --section-start command line switch. */
1902 lang_add_section (&add_child, s, NULL, NULL, os);
1906 /* Save unused output sections in case we can match them
1907 against orphans later. */
1908 if (os->bfd_section == NULL)
1912 /* If we didn't match an active output section, see if we matched an
1913 unused one and use that. */
1914 if (os == NULL && match_by_name)
1916 lang_add_section (&match_by_name->children, s, NULL, NULL, match_by_name);
1917 return match_by_name;
1922 static struct orphan_save hold[] =
1925 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1928 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1931 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1934 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1940 enum orphan_save_index
1948 static int orphan_init_done = 0;
1949 struct orphan_save *place;
1950 lang_output_section_statement_type *after;
1951 etree_type *address;
1955 if (!orphan_init_done)
1957 struct orphan_save *ho;
1958 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1959 if (ho->name != NULL)
1961 ho->os = lang_output_section_find (ho->name);
1962 if (ho->os != NULL && ho->os->flags == 0)
1963 ho->os->flags = ho->flags;
1965 orphan_init_done = 1;
1969 if (!bfd_link_relocatable (&link_info))
1972 while ((nexts = bfd_get_next_section_by_name (nexts->owner,
1974 if (nexts->output_section == NULL
1975 && (nexts->flags & SEC_EXCLUDE) == 0
1976 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
1977 && (nexts->owner->flags & DYNAMIC) == 0
1978 && !bfd_input_just_syms (nexts->owner))
1979 flags = (((flags ^ SEC_READONLY)
1980 | (nexts->flags ^ SEC_READONLY))
1984 /* Try to put the new output section in a reasonable place based
1985 on the section name and section flags. */
1988 if ((flags & SEC_ALLOC) == 0)
1990 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1991 place = &hold[orphan_bss];
1992 else if ((flags & SEC_READONLY) == 0)
1993 place = &hold[orphan_data];
1994 else if ((flags & SEC_CODE) == 0)
1996 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
1997 : &hold[orphan_rodata]);
2000 place = &hold[orphan_text];
2005 if (place->os == NULL)
2006 place->os = lang_output_section_find (place->name);
2009 after = lang_output_section_find_by_flags (s, flags, &place->os,
2012 /* *ABS* is always the first output section statement. */
2013 after = (void *) lang_os_list.head;
2016 /* All sections in an executable must be aligned to a page boundary.
2017 In a relocatable link, just preserve the incoming alignment; the
2018 address is discarded by lang_insert_orphan in that case, anyway. */
2019 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
2020 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2022 if (bfd_link_relocatable (&link_info))
2024 os->section_alignment = exp_intop (1U << s->alignment_power);
2025 os->bfd_section->alignment_power = s->alignment_power;
2029 /* If the section name has a '\$', sort it with the other '\$'
2031 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2033 lang_input_section_type *ls;
2036 if ((*pl)->header.type != lang_input_section_enum)
2039 ls = &(*pl)->input_section;
2041 lname = bfd_section_name (ls->section);
2042 if (strchr (lname, '\$') != NULL
2043 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2047 if (add_child.head != NULL)
2049 *add_child.tail = *pl;
2050 *pl = add_child.head;
2057 gld${EMULATION_NAME}_open_dynamic_archive
2058 (const char *arch ATTRIBUTE_UNUSED,
2059 search_dirs_type *search,
2060 lang_input_statement_type *entry)
2064 const char * format;
2069 /* Preferred explicit import library for dll's. */
2070 { "lib%s.dll.a", false },
2071 /* Alternate explicit import library for dll's. */
2072 { "%s.dll.a", false },
2073 /* "libfoo.a" could be either an import lib or a static lib.
2074 For backwards compatibility, libfoo.a needs to precede
2075 libfoo.dll and foo.dll in the search. */
2076 { "lib%s.a", false },
2077 /* The 'native' spelling of an import lib name is "foo.lib". */
2078 { "%s.lib", false },
2079 /* PR 22948 - Check for an import library. */
2080 { "lib%s.lib", false },
2082 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2083 { "%s%s.dll", true },
2085 /* Try "libfoo.dll" (default preferred dll name). */
2086 { "lib%s.dll", false },
2087 /* Finally try 'native' dll name "foo.dll". */
2088 { "%s.dll", false },
2089 /* Note: If adding more formats to this table, make sure to check to
2090 see if their length is longer than libname_fmt[0].format, and if
2091 so, update the call to xmalloc() below. */
2094 static unsigned int format_max_len = 0;
2095 const char * filename;
2101 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
2104 filename = entry->filename;
2106 if (format_max_len == 0)
2107 /* We need to allow space in the memory that we are going to allocate
2108 for the characters in the format string. Since the format array is
2109 static we only need to calculate this information once. In theory
2110 this value could also be computed statically, but this introduces
2111 the possibility for a discrepancy and hence a possible memory
2112 corruption. The lengths we compute here will be too long because
2113 they will include any formating characters (%s) in the strings, but
2114 this will not matter. */
2115 for (i = 0; libname_fmt[i].format; i++)
2116 if (format_max_len < strlen (libname_fmt[i].format))
2117 format_max_len = strlen (libname_fmt[i].format);
2119 full_string = xmalloc (strlen (search->name)
2123 + (pep_dll_search_prefix
2124 ? strlen (pep_dll_search_prefix) : 0)
2126 /* Allow for the terminating NUL and for the path
2127 separator character that is inserted between
2128 search->name and the start of the format string. */
2131 sprintf (full_string, "%s/", search->name);
2132 base_string = full_string + strlen (full_string);
2134 for (i = 0; libname_fmt[i].format; i++)
2137 if (libname_fmt[i].use_prefix)
2139 if (!pep_dll_search_prefix)
2141 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2145 sprintf (base_string, libname_fmt[i].format, filename);
2147 if (ldfile_try_open_bfd (full_string, entry))
2151 if (!libname_fmt[i].format)
2157 entry->filename = full_string;
2163 gld${EMULATION_NAME}_find_potential_libraries
2164 (char *name, lang_input_statement_type *entry)
2166 return ldfile_open_file_search (name, entry, "", ".lib");
2170 gld${EMULATION_NAME}_get_script (int *isfile)
2173 if test x"$COMPILE_IN" = xyes
2175 # Scripts compiled in.
2177 # sed commands to quote an ld script as a C string.
2178 sc="-f stringify.sed"
2184 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2187 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2188 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2189 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2190 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2191 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2192 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2193 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2194 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2195 echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
2196 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2198 echo ' ; else return' >> e${EMULATION_NAME}.c
2199 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2200 echo '; }' >> e${EMULATION_NAME}.c
2203 # Scripts read from the filesystem.
2209 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2210 return "ldscripts/${EMULATION_NAME}.xu";
2211 else if (bfd_link_relocatable (&link_info))
2212 return "ldscripts/${EMULATION_NAME}.xr";
2213 else if (!config.text_read_only)
2214 return "ldscripts/${EMULATION_NAME}.xbn";
2215 else if (!config.magic_demand_paged)
2216 return "ldscripts/${EMULATION_NAME}.xn";
2218 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2220 else if (link_info.pei386_auto_import == 1
2221 && link_info.pei386_runtime_pseudo_reloc != 2)
2222 return "ldscripts/${EMULATION_NAME}.xa";
2227 return "ldscripts/${EMULATION_NAME}.x";
2232 LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse
2233 LDEMUL_AFTER_OPEN=gld${EMULATION_NAME}_after_open
2234 LDEMUL_BEFORE_ALLOCATION=gld${EMULATION_NAME}_before_allocation
2235 LDEMUL_FINISH=gld${EMULATION_NAME}_finish
2236 LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld${EMULATION_NAME}_open_dynamic_archive
2237 LDEMUL_PLACE_ORPHAN=gld${EMULATION_NAME}_place_orphan
2238 LDEMUL_SET_SYMBOLS=gld${EMULATION_NAME}_set_symbols
2239 LDEMUL_ADD_OPTIONS=gld${EMULATION_NAME}_add_options
2240 LDEMUL_HANDLE_OPTION=gld${EMULATION_NAME}_handle_option
2241 LDEMUL_UNRECOGNIZED_FILE=gld${EMULATION_NAME}_unrecognized_file
2242 LDEMUL_LIST_OPTIONS=gld${EMULATION_NAME}_list_options
2243 LDEMUL_RECOGNIZED_FILE=gld${EMULATION_NAME}_recognized_file
2244 LDEMUL_FIND_POTENTIAL_LIBRARIES=gld${EMULATION_NAME}_find_potential_libraries
2246 source_em ${srcdir}/emultempl/emulation.em