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
14 move_default_addr_high=0;
18 rm -f e${EMULATION_NAME}.c
19 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
21 /* Copyright (C) 2006-2021 Free Software Foundation, Inc.
22 Written by Kai Tietz, OneVision Software GmbH&CoKg.
24 This file is part of the GNU Binutils.
26 This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 3 of the License, or
29 (at your option) any later version.
31 This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
36 You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software
38 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
39 MA 02110-1301, USA. */
42 /* For WINDOWS_XP64 and higher */
43 /* Based on pe.em, but modified for 64 bit support. */
45 #define TARGET_IS_${EMULATION_NAME}
47 #define COFF_IMAGE_WITH_PE
49 #define COFF_WITH_pex64
56 #include "libiberty.h"
57 #include "filenames.h"
68 #include "ldbuildid.h"
69 #include "coff/internal.h"
71 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
72 header in generic PE code. */
73 #include "coff/x86_64.h"
76 /* FIXME: These are BFD internal header files, and we should not be
78 #include "../bfd/libcoff.h"
79 #include "../bfd/libpei.h"
82 #define AOUTSZ PEPAOUTSZ
83 #define PEAOUTHDR PEPAOUTHDR
87 #include "safe-ctype.h"
89 /* Permit the emulation parameters to override the default section
90 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
91 it seem that include/coff/internal.h should not define
92 PE_DEF_SECTION_ALIGNMENT. */
93 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
94 #undef PE_DEF_SECTION_ALIGNMENT
95 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
98 #ifdef TARGET_IS_i386pep
102 #define DEFAULT_DLL_CHARACTERISTICS (IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
103 | IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA \
104 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
106 #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
107 #define PE_DEF_SUBSYSTEM 3
108 #undef NT_EXE_IMAGE_BASE
109 #define NT_EXE_IMAGE_BASE \
110 ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
112 #undef NT_DLL_IMAGE_BASE
113 #define NT_DLL_IMAGE_BASE \
114 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
116 #undef NT_DLL_AUTO_IMAGE_BASE
117 #define NT_DLL_AUTO_IMAGE_BASE \
118 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
120 #undef NT_DLL_AUTO_IMAGE_MASK
121 #define NT_DLL_AUTO_IMAGE_MASK \
122 ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
125 #undef NT_EXE_IMAGE_BASE
126 #define NT_EXE_IMAGE_BASE \
127 ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
129 #undef NT_DLL_IMAGE_BASE
130 #define NT_DLL_IMAGE_BASE \
131 ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
133 #undef NT_DLL_AUTO_IMAGE_BASE
134 #define NT_DLL_AUTO_IMAGE_BASE \
135 ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
137 #undef NT_DLL_AUTO_IMAGE_MASK
138 #define NT_DLL_AUTO_IMAGE_MASK \
139 ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
141 #undef PE_DEF_SECTION_ALIGNMENT
142 #define PE_DEF_SUBSYSTEM 2
143 #undef PE_DEF_FILE_ALIGNMENT
144 #define PE_DEF_FILE_ALIGNMENT 0x00000200
145 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
148 static struct internal_extra_pe_aouthdr pep;
150 static int pep_subsystem = ${SUBSYSTEM};
151 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
152 static int support_old_code = 0;
153 static lang_assignment_statement_type *image_base_statement = 0;
154 static unsigned short pe_dll_characteristics = DEFAULT_DLL_CHARACTERISTICS;
155 static bool insert_timestamp = true;
156 static const char *emit_build_id;
159 static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
160 static char * pep_out_def_filename = NULL;
161 static int pep_enable_auto_image_base = 0;
162 static char * pep_dll_search_prefix = NULL;
165 extern const char *output_filename;
167 static int is_underscoring (void)
170 if (pep_leading_underscore != -1)
171 return pep_leading_underscore;
172 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
173 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
177 pep_leading_underscore = (u != 0 ? 1 : 0);
178 return pep_leading_underscore;
183 gld_${EMULATION_NAME}_before_parse (void)
186 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
187 output_filename = "${EXECUTABLE_NAME:-a.exe}";
189 input_flags.dynamic = true;
190 config.has_shared = 1;
191 link_info.pei386_auto_import = 1;
192 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
196 /* PE format extra command line options. */
198 /* Used for setting flags in the PE header. */
201 OPTION_BASE_FILE = 300 + 1,
203 OPTION_FILE_ALIGNMENT,
205 OPTION_MAJOR_IMAGE_VERSION,
206 OPTION_MAJOR_OS_VERSION,
207 OPTION_MAJOR_SUBSYSTEM_VERSION,
208 OPTION_MINOR_IMAGE_VERSION,
209 OPTION_MINOR_OS_VERSION,
210 OPTION_MINOR_SUBSYSTEM_VERSION,
211 OPTION_SECTION_ALIGNMENT,
215 OPTION_SUPPORT_OLD_CODE,
218 OPTION_EXCLUDE_SYMBOLS,
219 OPTION_EXCLUDE_ALL_SYMBOLS,
221 OPTION_STDCALL_ALIASES,
222 OPTION_ENABLE_STDCALL_FIXUP,
223 OPTION_DISABLE_STDCALL_FIXUP,
224 OPTION_WARN_DUPLICATE_EXPORTS,
226 OPTION_ENABLE_AUTO_IMAGE_BASE,
227 OPTION_DISABLE_AUTO_IMAGE_BASE,
228 OPTION_DLL_SEARCH_PREFIX,
229 OPTION_NO_DEFAULT_EXCLUDES,
230 OPTION_DLL_ENABLE_AUTO_IMPORT,
231 OPTION_DLL_DISABLE_AUTO_IMPORT,
232 OPTION_ENABLE_EXTRA_PE_DEBUG,
234 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
235 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
236 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
237 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
238 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
239 OPTION_NO_LEADING_UNDERSCORE,
240 OPTION_LEADING_UNDERSCORE,
241 OPTION_ENABLE_LONG_SECTION_NAMES,
242 OPTION_DISABLE_LONG_SECTION_NAMES,
243 OPTION_HIGH_ENTROPY_VA,
245 OPTION_FORCE_INTEGRITY,
251 OPTION_INSERT_TIMESTAMP,
252 OPTION_NO_INSERT_TIMESTAMP,
253 OPTION_TERMINAL_SERVER_AWARE,
255 OPTION_ENABLE_RELOC_SECTION,
256 OPTION_DISABLE_RELOC_SECTION,
257 OPTION_DISABLE_HIGH_ENTROPY_VA,
258 OPTION_DISABLE_DYNAMIC_BASE,
259 OPTION_DISABLE_FORCE_INTEGRITY,
260 OPTION_DISABLE_NX_COMPAT,
261 OPTION_DISABLE_NO_ISOLATION,
262 OPTION_DISABLE_NO_SEH,
263 OPTION_DISABLE_NO_BIND,
264 OPTION_DISABLE_WDM_DRIVER,
265 OPTION_DISABLE_TERMINAL_SERVER_AWARE
269 gld${EMULATION_NAME}_add_options
270 (int ns ATTRIBUTE_UNUSED,
271 char **shortopts ATTRIBUTE_UNUSED,
273 struct option **longopts,
274 int nrl ATTRIBUTE_UNUSED,
275 struct option **really_longopts ATTRIBUTE_UNUSED)
277 static const struct option xtra_long[] =
280 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
281 {"dll", no_argument, NULL, OPTION_DLL},
282 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
283 {"heap", required_argument, NULL, OPTION_HEAP},
284 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
285 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
286 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
287 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
288 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
289 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
290 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
291 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
292 {"stack", required_argument, NULL, OPTION_STACK},
293 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
294 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
295 {"use-nul-prefixed-import-tables", no_argument, NULL,
296 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
297 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
298 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
300 /* getopt allows abbreviations, so we do this to stop it
301 from treating -o as an abbreviation for this option. */
302 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
303 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
304 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
305 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
306 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
307 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
308 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
309 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
310 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
311 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
312 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
313 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
314 /* getopt() allows abbreviations, so we do this to stop it from
315 treating -c as an abbreviation for these --compat-implib. */
316 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
317 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
318 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
319 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
320 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
321 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
322 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
323 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
324 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
325 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
326 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
327 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
329 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
330 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
331 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
332 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
333 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
334 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
335 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
336 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
337 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
338 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
339 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
340 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
341 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
342 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
343 {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
344 {"disable-reloc-section", no_argument, NULL, OPTION_DISABLE_RELOC_SECTION},
345 {"disable-high-entropy-va", no_argument, NULL, OPTION_DISABLE_HIGH_ENTROPY_VA},
346 {"disable-dynamicbase",no_argument, NULL, OPTION_DISABLE_DYNAMIC_BASE},
347 {"disable-forceinteg", no_argument, NULL, OPTION_DISABLE_FORCE_INTEGRITY},
348 {"disable-nxcompat", no_argument, NULL, OPTION_DISABLE_NX_COMPAT},
349 {"disable-no-isolation", no_argument, NULL, OPTION_DISABLE_NO_ISOLATION},
350 {"disable-no-seh", no_argument, NULL, OPTION_DISABLE_NO_SEH},
351 {"disable-no-bind", no_argument, NULL, OPTION_DISABLE_NO_BIND},
352 {"disable-wdmdriver", no_argument, NULL, OPTION_DISABLE_WDM_DRIVER},
353 {"disable-tsaware", no_argument, NULL, OPTION_DISABLE_TERMINAL_SERVER_AWARE},
354 {NULL, no_argument, NULL, 0}
358 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
359 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
362 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
363 parameters which may be input from the command line. */
372 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
373 C visible symbols can be prefixed by underscore dependent on target's
378 #define GET_INIT_SYMBOL_NAME(IDX) \
379 (init[(IDX)].symbol \
380 + ((!init[(IDX)].is_c_symbol || is_underscoring () == 1) ? 0 : 1))
382 /* Decorates the C visible symbol by underscore, if target requires. */
384 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
386 #define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
388 static definfo init[] =
390 /* imagebase must be first */
391 #define IMAGEBASEOFF 0
392 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, false),
394 {&dll, sizeof(dll), 0, "__dll__", 0, false},
395 #define MSIMAGEBASEOFF 2
396 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, true),
397 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, false),
398 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, false),
399 D(MajorOperatingSystemVersion,"__major_os_version__", 4, false),
400 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, false),
401 D(MajorImageVersion,"__major_image_version__", 0, false),
402 D(MinorImageVersion,"__minor_image_version__", 0, false),
403 D(MajorSubsystemVersion,"__major_subsystem_version__", 5, false),
404 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2, false),
405 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, false),
406 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, false),
407 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, false),
408 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, false),
409 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, false),
410 D(LoaderFlags,"__loader_flags__", 0x0, false),
411 D(DllCharacteristics, "__dll_characteristics__", DEFAULT_DLL_CHARACTERISTICS, false),
412 { NULL, 0, 0, NULL, 0, false}
417 gld_${EMULATION_NAME}_list_options (FILE *file)
419 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
420 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
421 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
422 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
423 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
424 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
425 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
426 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
427 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
428 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
429 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
430 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
431 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
432 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
433 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
434 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
435 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero (default)\n"));
436 fprintf (file, _(" This makes binaries non-deterministic\n"));
438 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
439 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
440 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
441 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
442 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
443 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
444 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
445 fprintf (file, _(" Exclude objects, archive members from auto\n"));
446 fprintf (file, _(" export, place into import library instead\n"));
447 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
448 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
449 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
450 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports\n"));
451 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
452 create __imp_<SYMBOL> as well\n"));
453 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
454 unless user specifies one\n"));
455 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base (default)\n"));
456 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
457 an importlib, use <string><basename>.dll\n\
458 in preference to lib<basename>.dll \n"));
459 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
460 __imp_sym for DATA references\n"));
461 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
462 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
463 adding pseudo-relocations resolved at\n\
465 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
466 auto-imported DATA\n"));
467 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
468 or linking to DLLs (esp. auto-import)\n"));
469 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
470 executable image files\n"));
471 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
472 in object files\n"));
473 fprintf (file, _(" --[disable-]high-entropy-va Image is compatible with 64-bit address space\n\
474 layout randomization (ASLR)\n"));
475 fprintf (file, _(" --[disable-]dynamicbase Image base address may be relocated using\n\
476 address space layout randomization (ASLR)\n"));
477 fprintf (file, _(" --enable-reloc-section Create the base relocation table\n"));
478 fprintf (file, _(" --disable-reloc-section Do not create the base relocation table\n"));
479 fprintf (file, _(" --[disable-]forceinteg Code integrity checks are enforced\n"));
480 fprintf (file, _(" --[disable-]nxcompat Image is compatible with data execution\n\
482 fprintf (file, _(" --[disable-]no-isolation Image understands isolation but do not\n\
483 isolate the image\n"));
484 fprintf (file, _(" --[disable-]no-seh Image does not use SEH; no SE handler may\n\
485 be called in this image\n"));
486 fprintf (file, _(" --[disable-]no-bind Do not bind this image\n"));
487 fprintf (file, _(" --[disable-]wdmdriver Driver uses the WDM model\n"));
488 fprintf (file, _(" --[disable-]tsaware Image is Terminal Server aware\n"));
489 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
495 set_pep_name (char *name, bfd_vma val)
499 /* Find the name and set it. */
500 for (i = 0; init[i].ptr; i++)
502 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
506 if (strcmp (name,"__image_base__") == 0)
507 set_pep_name (U ("__ImageBase"), val);
515 set_entry_point (void)
518 const char *initial_symbol_char;
528 { 1, "NtProcessStartup" },
529 { 2, "WinMainCRTStartup" },
530 { 3, "mainCRTStartup" },
531 { 7, "__PosixProcessStartup" },
532 { 9, "WinMainCRTStartup" },
533 {14, "mainCRTStartup" },
537 /* Entry point name for arbitrary subsystem numbers. */
538 static const char default_entry[] = "mainCRTStartup";
540 if (bfd_link_dll (&link_info) || dll)
542 entry = "DllMainCRTStartup";
546 for (i = 0; v[i].entry; i++)
547 if (v[i].value == pep_subsystem)
550 /* If no match, use the default. */
551 if (v[i].entry != NULL)
554 entry = default_entry;
557 /* Now we check target's default for getting proper symbol_char. */
558 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
560 if (*initial_symbol_char != '\0')
564 /* lang_default_entry expects its argument to be permanently
565 allocated, so we don't free this string. */
566 alc_entry = xmalloc (strlen (initial_symbol_char)
569 strcpy (alc_entry, initial_symbol_char);
570 strcat (alc_entry, entry);
574 lang_default_entry (entry);
578 set_pep_subsystem (void)
584 unsigned long temp_subsystem;
601 /* Check for the presence of a version number. */
602 sver = strchr (optarg, ':');
604 len = strlen (optarg);
608 set_pep_name ("__major_subsystem_version__",
609 strtoul (sver + 1, &end, 0));
611 set_pep_name ("__minor_subsystem_version__",
612 strtoul (end + 1, &end, 0));
614 einfo (_("%P: warning: bad version number in -subsystem option\n"));
617 /* Check for numeric subsystem. */
618 temp_subsystem = strtoul (optarg, & end, 0);
619 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
621 /* Search list for a numeric match to use its entry point. */
622 for (i = 0; v[i].name; i++)
623 if (v[i].value == (int) temp_subsystem)
626 /* Use this subsystem. */
627 pep_subsystem = (int) temp_subsystem;
631 /* Search for subsystem by name. */
632 for (i = 0; v[i].name; i++)
633 if (strncmp (optarg, v[i].name, len) == 0
634 && v[i].name[len] == '\0')
637 if (v[i].name == NULL)
639 einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
643 pep_subsystem = v[i].value;
646 set_pep_name ("__subsystem__", pep_subsystem);
653 set_pep_value (char *name)
657 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
660 einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
667 set_pep_stack_heap (char *resname, char *comname)
669 set_pep_value (resname);
674 set_pep_value (comname);
677 einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
680 #define DEFAULT_BUILD_ID_STYLE "md5"
683 gld${EMULATION_NAME}_handle_option (int optc)
691 case OPTION_BASE_FILE:
692 link_info.base_file = fopen (optarg, FOPEN_WB);
693 if (link_info.base_file == NULL)
694 einfo (_("%F%P: cannot open base file %s\n"), optarg);
699 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
702 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
704 case OPTION_SUBSYSTEM:
705 set_pep_subsystem ();
707 case OPTION_MAJOR_OS_VERSION:
708 set_pep_value ("__major_os_version__");
710 case OPTION_MINOR_OS_VERSION:
711 set_pep_value ("__minor_os_version__");
713 case OPTION_MAJOR_SUBSYSTEM_VERSION:
714 set_pep_value ("__major_subsystem_version__");
716 case OPTION_MINOR_SUBSYSTEM_VERSION:
717 set_pep_value ("__minor_subsystem_version__");
719 case OPTION_MAJOR_IMAGE_VERSION:
720 set_pep_value ("__major_image_version__");
722 case OPTION_MINOR_IMAGE_VERSION:
723 set_pep_value ("__minor_image_version__");
725 case OPTION_FILE_ALIGNMENT:
726 set_pep_value ("__file_alignment__");
728 case OPTION_SECTION_ALIGNMENT:
729 set_pep_value ("__section_alignment__");
732 set_pep_name ("__dll__", 1);
734 case OPTION_IMAGE_BASE:
735 set_pep_value ("__image_base__");
737 case OPTION_SUPPORT_OLD_CODE:
738 support_old_code = 1;
740 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
741 pep_use_nul_prefixed_import_tables = true;
743 case OPTION_NO_LEADING_UNDERSCORE:
744 pep_leading_underscore = 0;
746 case OPTION_LEADING_UNDERSCORE:
747 pep_leading_underscore = 1;
749 case OPTION_INSERT_TIMESTAMP:
750 insert_timestamp = true;
752 case OPTION_NO_INSERT_TIMESTAMP:
753 insert_timestamp = false;
757 pep_out_def_filename = xstrdup (optarg);
759 case OPTION_EXPORT_ALL:
760 pep_dll_export_everything = 1;
762 case OPTION_EXCLUDE_SYMBOLS:
763 pep_dll_add_excludes (optarg, EXCLUDESYMS);
765 case OPTION_EXCLUDE_ALL_SYMBOLS:
766 pep_dll_exclude_all_symbols = 1;
768 case OPTION_EXCLUDE_LIBS:
769 pep_dll_add_excludes (optarg, EXCLUDELIBS);
771 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
772 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
774 case OPTION_KILL_ATS:
775 pep_dll_kill_ats = 1;
777 case OPTION_STDCALL_ALIASES:
778 pep_dll_stdcall_aliases = 1;
780 case OPTION_ENABLE_STDCALL_FIXUP:
781 pep_enable_stdcall_fixup = 1;
783 case OPTION_DISABLE_STDCALL_FIXUP:
784 pep_enable_stdcall_fixup = 0;
786 case OPTION_WARN_DUPLICATE_EXPORTS:
787 pep_dll_warn_dup_exports = 1;
789 case OPTION_IMP_COMPAT:
790 pep_dll_compat_implib = 1;
792 case OPTION_ENABLE_AUTO_IMAGE_BASE:
793 pep_enable_auto_image_base = 1;
795 case OPTION_DISABLE_AUTO_IMAGE_BASE:
796 pep_enable_auto_image_base = 0;
798 case OPTION_DLL_SEARCH_PREFIX:
799 pep_dll_search_prefix = xstrdup (optarg);
801 case OPTION_NO_DEFAULT_EXCLUDES:
802 pep_dll_do_default_excludes = 0;
804 case OPTION_DLL_ENABLE_AUTO_IMPORT:
805 link_info.pei386_auto_import = 1;
807 case OPTION_DLL_DISABLE_AUTO_IMPORT:
808 link_info.pei386_auto_import = 0;
810 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
811 link_info.pei386_runtime_pseudo_reloc = 2;
813 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
814 link_info.pei386_runtime_pseudo_reloc = 0;
816 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
817 link_info.pei386_runtime_pseudo_reloc = 2;
819 case OPTION_ENABLE_EXTRA_PE_DEBUG:
820 pep_dll_extra_pe_debug = 1;
823 case OPTION_ENABLE_LONG_SECTION_NAMES:
824 pep_use_coff_long_section_names = 1;
826 case OPTION_DISABLE_LONG_SECTION_NAMES:
827 pep_use_coff_long_section_names = 0;
829 /* Get DLLCharacteristics bits */
830 case OPTION_HIGH_ENTROPY_VA:
831 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
833 case OPTION_DYNAMIC_BASE:
834 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
836 case OPTION_ENABLE_RELOC_SECTION:
837 pep_dll_enable_reloc_section = 1;
839 case OPTION_DISABLE_RELOC_SECTION:
840 pep_dll_enable_reloc_section = 0;
842 case OPTION_DISABLE_DYNAMIC_BASE:
843 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
845 case OPTION_DISABLE_HIGH_ENTROPY_VA:
846 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
848 case OPTION_FORCE_INTEGRITY:
849 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
851 case OPTION_DISABLE_FORCE_INTEGRITY:
852 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
854 case OPTION_NX_COMPAT:
855 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
857 case OPTION_DISABLE_NX_COMPAT:
858 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
860 case OPTION_NO_ISOLATION:
861 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
863 case OPTION_DISABLE_NO_ISOLATION:
864 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
867 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
869 case OPTION_DISABLE_NO_SEH:
870 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_SEH;
873 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
875 case OPTION_DISABLE_NO_BIND:
876 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_BIND;
878 case OPTION_WDM_DRIVER:
879 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
881 case OPTION_DISABLE_WDM_DRIVER:
882 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
884 case OPTION_TERMINAL_SERVER_AWARE:
885 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
887 case OPTION_DISABLE_TERMINAL_SERVER_AWARE:
888 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
890 case OPTION_BUILD_ID:
891 free ((char *) emit_build_id);
892 emit_build_id = NULL;
894 optarg = DEFAULT_BUILD_ID_STYLE;
895 if (strcmp (optarg, "none"))
896 emit_build_id = xstrdup (optarg);
900 /* Set DLLCharacteristics bits */
901 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
909 strhash (const char *str)
911 const unsigned char *s;
918 s = (const unsigned char *) str;
919 while ((c = *s++) != '\0')
921 hash += c + (c << 17);
925 hash += len + (len << 17);
931 /* Use the output file to create a image base for relocatable DLLs. */
934 compute_dll_image_base (const char *ofile)
936 bfd_vma hash = (bfd_vma) strhash (ofile);
937 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
941 /* Assign values to the special symbols before the linker script is
945 gld_${EMULATION_NAME}_set_symbols (void)
947 /* Run through and invent symbols for all the
948 names and insert the defaults. */
953 if (!init[IMAGEBASEOFF].inited)
955 if (bfd_link_relocatable (&link_info))
956 init[IMAGEBASEOFF].value = 0;
957 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
960 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
961 ? compute_dll_image_base (output_filename)
962 : NT_DLL_IMAGE_BASE);
964 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
968 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
969 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
972 /* Don't do any symbol assignments if this is a relocatable link. */
973 if (bfd_link_relocatable (&link_info))
976 /* Glue the assignments into the abs section. */
977 push_stat_ptr (&abs_output_section->children);
979 for (j = 0; init[j].ptr; j++)
981 bfd_vma val = init[j].value;
982 lang_assignment_statement_type *rv;
984 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
985 exp_intop (val), false));
986 if (init[j].size == sizeof (short))
987 *(short *) init[j].ptr = (short) val;
988 else if (init[j].size == sizeof (int))
989 *(int *) init[j].ptr = (int) val;
990 else if (init[j].size == sizeof (long))
991 *(long *) init[j].ptr = (long) val;
992 /* This might be a long long or other special type. */
993 else if (init[j].size == sizeof (bfd_vma))
994 *(bfd_vma *) init[j].ptr = val;
996 if (j == IMAGEBASEOFF)
997 image_base_statement = rv;
999 /* Restore the pointer. */
1002 if (pep.FileAlignment > pep.SectionAlignment)
1004 einfo (_("%P: warning, file alignment > section alignment\n"));
1008 /* This is called after the linker script and the command line options
1012 gld_${EMULATION_NAME}_after_parse (void)
1014 /* PR ld/6744: Warn the user if they have used an ELF-only
1015 option hoping it will work on PE+. */
1016 if (link_info.export_dynamic)
1017 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
1018 "targets, did you mean --export-all-symbols?\n"));
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 pep_fixup_stdcalls (void)
1051 static int gave_warning_message = 0;
1052 struct bfd_link_hash_entry *undef, *sym;
1054 if (pep_dll_extra_pe_debug)
1055 printf ("%s\n", __FUNCTION__);
1057 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1058 if (undef->type == bfd_link_hash_undefined)
1060 char* at = strchr (undef->root.string, '@');
1061 int lead_at = (*undef->root.string == '@');
1063 at = strchr (undef->root.string + 1, '@');
1066 /* The symbol is a stdcall symbol, so let's look for a
1067 cdecl symbol with the same name and resolve to that. */
1068 char *cname = xstrdup (undef->root.string);
1072 at = strchr (cname, '@');
1075 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1077 if (sym && sym->type == bfd_link_hash_defined)
1079 undef->type = bfd_link_hash_defined;
1080 undef->u.def.value = sym->u.def.value;
1081 undef->u.def.section = sym->u.def.section;
1083 if (pep_enable_stdcall_fixup == -1)
1085 einfo (_("warning: resolving %s by linking to %s\n"),
1086 undef->root.string, cname);
1087 if (! gave_warning_message)
1089 gave_warning_message = 1;
1090 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1091 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1098 /* The symbol is a cdecl symbol, so we look for stdcall
1099 symbols - which means scanning the whole symbol table. */
1100 pep_undef_found_sym = 0;
1101 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
1102 (char *) undef->root.string);
1103 sym = pep_undef_found_sym;
1106 undef->type = bfd_link_hash_defined;
1107 undef->u.def.value = sym->u.def.value;
1108 undef->u.def.section = sym->u.def.section;
1110 if (pep_enable_stdcall_fixup == -1)
1112 einfo (_("warning: resolving %s by linking to %s\n"),
1113 undef->root.string, sym->root.string);
1114 if (! gave_warning_message)
1116 gave_warning_message = 1;
1117 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1118 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1127 make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
1129 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1131 bfd_vma _addend = 0;
1134 if (pep_dll_extra_pe_debug)
1135 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1136 (unsigned long) rel->address, (long) rel->addend);
1138 memset (addend, 0, sizeof (addend));
1139 switch ((rel->howto->bitsize))
1142 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 1);
1143 if (suc && rel->howto->pc_relative)
1144 _addend = bfd_get_signed_8 (s->owner, addend);
1146 _addend = bfd_get_8 (s->owner, addend);
1149 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 2);
1150 if (suc && rel->howto->pc_relative)
1151 _addend = bfd_get_signed_16 (s->owner, addend);
1153 _addend = bfd_get_16 (s->owner, addend);
1156 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
1157 if (suc && rel->howto->pc_relative)
1158 _addend = bfd_get_signed_32 (s->owner, addend);
1160 _addend = bfd_get_32 (s->owner, addend);
1163 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
1165 _addend = bfd_get_64 (s->owner, addend);
1169 einfo (_("%P: %C: cannot get section contents - auto-import exception\n"),
1170 s->owner, s, rel->address);
1172 if (pep_dll_extra_pe_debug)
1174 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx",
1175 (long) _addend, (long) rel->addend, (long) rel->address);
1176 if (rel->howto->pc_relative)
1178 printf (" %d bit rel.\n", (int) rel->howto->bitsize);
1181 pep_create_import_fixup (rel, s, _addend, name, symname);
1185 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1187 printf ("+%s\n", h->string);
1191 #endif /* DLL_SUPPORT */
1194 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1196 int *found = (int *) obj;
1198 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1203 pecoff_checksum_contents (bfd *abfd,
1204 void (*process) (const void *, size_t, void *),
1207 file_ptr filepos = (file_ptr) 0;
1214 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1217 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1223 (*process) (&b, 1, arg);
1231 write_build_id (bfd *abfd)
1233 struct pe_tdata *t = pe_data (abfd);
1235 struct bfd_link_order *link_order = NULL;
1236 unsigned char *contents;
1238 bfd_size_type build_id_size;
1239 unsigned char *build_id;
1241 /* Find the section the .buildid output section has been merged info. */
1242 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1244 struct bfd_link_order *l = NULL;
1245 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1247 if (l->type == bfd_indirect_link_order)
1249 if (l->u.indirect.section == t->build_id.sec)
1263 einfo (_("%P: warning: .buildid section discarded,"
1264 " --build-id ignored\n"));
1268 if (t->build_id.sec->contents == NULL)
1269 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1270 contents = t->build_id.sec->contents;
1271 size = t->build_id.sec->size;
1273 build_id_size = compute_build_id_size (t->build_id.style);
1274 build_id = xmalloc (build_id_size);
1275 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1277 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1279 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1280 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1281 idd.Characteristics = 0;
1282 idd.TimeDateStamp = 0;
1283 idd.MajorVersion = 0;
1284 idd.MinorVersion = 0;
1285 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1286 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1287 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1288 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1289 idd.PointerToRawData = asec->filepos + link_order->offset
1290 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1292 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1293 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1295 /* Write the debug directory enttry */
1296 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1299 if (bfd_bwrite (contents, size, abfd) != size)
1302 /* Construct the CodeView record. */
1303 CODEVIEW_INFO cvinfo;
1304 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1307 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1308 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1309 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1310 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1314 /* Write the codeview record. */
1315 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1318 /* Record the location of the debug directory in the data directory. */
1319 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1320 = asec->vma - ib + link_order->offset;
1321 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1322 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1327 /* Make .buildid section, and set up coff_tdata->build_id. */
1329 setup_build_id (bfd *ibfd)
1334 if (!validate_build_id_style (emit_build_id))
1336 einfo (_("%P: warning: unrecognized --build-id style ignored\n"));
1340 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1341 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1342 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
1345 struct pe_tdata *t = pe_data (link_info.output_bfd);
1346 t->build_id.after_write_object_contents = &write_build_id;
1347 t->build_id.style = emit_build_id;
1348 t->build_id.sec = s;
1350 /* Section is a fixed size:
1351 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1352 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1353 null byte for PdbFileName. */
1354 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1355 + sizeof (CV_INFO_PDB70) + 1;
1360 einfo (_("%P: warning: cannot create .buildid section,"
1361 " --build-id ignored\n"));
1366 gld_${EMULATION_NAME}_after_open (void)
1368 after_open_default ();
1372 if (pep_dll_extra_pe_debug)
1375 struct bfd_link_hash_entry *sym;
1377 printf ("%s()\n", __FUNCTION__);
1379 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1380 printf ("-%s\n", sym->root.string);
1381 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1383 for (a = link_info.input_bfds; a; a = a->link.next)
1384 printf ("*%s\n", bfd_get_filename (a));
1388 if (emit_build_id != NULL)
1392 /* Find a COFF input. */
1393 for (abfd = link_info.input_bfds;
1394 abfd != (bfd *) NULL; abfd = abfd->link.next)
1395 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1398 /* If there are no COFF input files do not try to
1399 add a build-id section. */
1401 || !setup_build_id (abfd))
1403 free ((char *) emit_build_id);
1404 emit_build_id = NULL;
1408 /* Pass the wacky PE command line options into the output bfd.
1409 FIXME: This should be done via a function, rather than by
1410 including an internal BFD header. */
1412 if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
1413 || coff_data (link_info.output_bfd) == NULL
1414 || coff_data (link_info.output_bfd)->pe == 0)
1415 einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
1416 link_info.output_bfd);
1418 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1419 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1420 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1421 if (insert_timestamp)
1422 pe_data (link_info.output_bfd)->timestamp = -1;
1424 pe_data (link_info.output_bfd)->timestamp = 0;
1426 /* At this point we must decide whether to use long section names
1427 in the output or not. If the user hasn't explicitly specified
1428 on the command line, we leave it to the default for the format
1429 (object files yes, image files no), except if there is debug
1430 information present; GDB relies on the long section names to
1431 find it, so enable it in that case. */
1432 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1434 if (bfd_link_relocatable (&link_info))
1435 pep_use_coff_long_section_names = 1;
1438 /* Iterate over all sections of all input BFDs, checking
1439 for any that begin 'debug_' and are long names. */
1440 LANG_FOR_EACH_INPUT_STATEMENT (is)
1442 int found_debug = 0;
1444 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1447 pep_use_coff_long_section_names = 1;
1454 pep_output_file_set_long_section_names (link_info.output_bfd);
1457 pep_process_import_defs (link_info.output_bfd, &link_info);
1459 if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
1460 pep_find_data_imports (U ("_head_"), make_import_fixup);
1462 /* The implementation of the feature is rather dumb and would cause the
1463 compilation time to go through the roof if there are many undefined
1464 symbols in the link, so it needs to be run after auto-import. */
1465 if (pep_enable_stdcall_fixup) /* -1=warn or 1=enable */
1466 pep_fixup_stdcalls ();
1468 #ifndef TARGET_IS_i386pep
1469 if (bfd_link_pic (&link_info))
1471 if (!bfd_link_relocatable (&link_info))
1473 pep_dll_build_sections (link_info.output_bfd, &link_info);
1475 #ifndef TARGET_IS_i386pep
1477 pep_exe_build_sections (link_info.output_bfd, &link_info);
1479 #endif /* DLL_SUPPORT */
1482 /* This next chunk of code tries to detect the case where you have
1483 two import libraries for the same DLL (specifically,
1484 symbolically linking libm.a and libc.a in cygwin to
1485 libcygwin.a). In those cases, it's possible for function
1486 thunks from the second implib to be used but without the
1487 head/tail objects, causing an improper import table. We detect
1488 those cases and rename the "other" import libraries to match
1489 the one the head/tail come from, so that the linker will sort
1490 things nicely and produce a valid import table. */
1492 LANG_FOR_EACH_INPUT_STATEMENT (is)
1494 if (is->the_bfd->my_archive)
1496 int idata2 = 0, reloc_count=0, is_imp = 0;
1499 /* See if this is an import library thunk. */
1500 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1502 if (strcmp (sec->name, ".idata\$2") == 0)
1504 if (startswith (sec->name, ".idata\$"))
1506 reloc_count += sec->reloc_count;
1509 if (is_imp && !idata2 && reloc_count)
1511 /* It is, look for the reference to head and see if it's
1512 from our own library. */
1513 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1521 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1525 if (!bfd_generic_link_read_symbols (is->the_bfd))
1527 einfo (_("%F%P: %pB: could not read symbols: %E\n"),
1531 symbols = bfd_get_outsymbols (is->the_bfd);
1533 relocs = xmalloc ((size_t) relsize);
1534 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1539 einfo (_("%X%P: unable to process relocs: %E\n"));
1543 for (i = 0; i < nrelocs; i++)
1545 struct bfd_symbol *s;
1546 struct bfd_link_hash_entry * blhe;
1547 const char *other_bfd_filename;
1549 s = (relocs[i]->sym_ptr_ptr)[0];
1551 if (s->flags & BSF_LOCAL)
1554 /* Thunk section with reloc to another bfd. */
1555 blhe = bfd_link_hash_lookup (link_info.hash,
1557 false, false, true);
1560 || blhe->type != bfd_link_hash_defined)
1564 = blhe->u.def.section->owner->my_archive
1565 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1566 : bfd_get_filename (blhe->u.def.section->owner);
1568 if (filename_cmp (bfd_get_filename
1569 (is->the_bfd->my_archive),
1570 other_bfd_filename) == 0)
1573 /* Rename this implib to match the other one. */
1574 if (!bfd_set_filename (is->the_bfd->my_archive,
1575 other_bfd_filename))
1576 einfo ("%F%P: %pB: %E\n", is->the_bfd);
1580 /* Note - we do not free the symbols,
1581 they are now cached in the BFD. */
1591 lang_input_statement_type *is2;
1592 lang_input_statement_type *is3;
1594 /* Careful - this is a shell script. Watch those dollar signs! */
1595 /* Microsoft import libraries have every member named the same,
1596 and not in the right order for us to link them correctly. We
1597 must detect these and rename the members so that they'll link
1598 correctly. There are three types of objects: the head, the
1599 thunks, and the sentinel(s). The head is easy; it's the one
1600 with idata2. We assume that the sentinels won't have relocs,
1601 and the thunks will. It's easier than checking the symbol
1602 table for external references. */
1603 LANG_FOR_EACH_INPUT_STATEMENT (is)
1605 if (is->the_bfd->my_archive)
1608 bfd *arch = is->the_bfd->my_archive;
1610 if (cur_arch != arch)
1616 is3 && is3->the_bfd->my_archive == arch;
1617 is3 = (lang_input_statement_type *) is3->next)
1619 /* A MS dynamic import library can also contain static
1620 members, so look for the first element with a .dll
1621 extension, and use that for the remainder of the
1623 pnt = strrchr (bfd_get_filename (is3->the_bfd), '.');
1624 if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
1632 /* OK, found one. Now look to see if the remaining
1633 (dynamic import) members use the same name. */
1635 is2 && is2->the_bfd->my_archive == arch;
1636 is2 = (lang_input_statement_type *) is2->next)
1638 /* Skip static members, ie anything with a .obj
1640 pnt = strrchr (bfd_get_filename (is2->the_bfd), '.');
1641 if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
1644 if (filename_cmp (bfd_get_filename (is3->the_bfd),
1645 bfd_get_filename (is2->the_bfd)))
1654 /* This fragment might have come from an .obj file in a Microsoft
1655 import, and not an actual import record. If this is the case,
1656 then leave the filename alone. */
1657 pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
1659 if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
1661 int idata2 = 0, reloc_count=0;
1663 char *new_name, seq;
1665 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1667 if (strcmp (sec->name, ".idata\$2") == 0)
1669 reloc_count += sec->reloc_count;
1672 if (idata2) /* .idata2 is the TOC */
1674 else if (reloc_count > 0) /* thunks */
1680 = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
1681 sprintf (new_name, "%s.%c",
1682 bfd_get_filename (is->the_bfd), seq);
1683 is->filename = bfd_set_filename (is->the_bfd, new_name);
1686 einfo ("%F%P: %pB: %E\n", is->the_bfd);
1694 gld_${EMULATION_NAME}_before_allocation (void)
1697 before_allocation_default ();
1701 /* This is called when an input file isn't recognized as a BFD. We
1702 check here for .DEF files and pull them in automatically. */
1705 saw_option (char *option)
1711 for (i = 0; init[i].ptr; i++)
1712 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1713 return init[i].inited;
1716 #endif /* DLL_SUPPORT */
1719 gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1722 const char *ext = entry->filename + strlen (entry->filename) - 4;
1724 if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
1726 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1730 int i, buflen=0, len;
1733 for (i = 0; i < pep_def_file->num_exports; i++)
1735 len = strlen (pep_def_file->exports[i].internal_name);
1736 if (buflen < len + 2)
1740 buf = xmalloc (buflen);
1742 for (i = 0; i < pep_def_file->num_exports; i++)
1744 struct bfd_link_hash_entry *h;
1746 sprintf (buf, "%s%s", U (""),
1747 pep_def_file->exports[i].internal_name);
1749 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
1750 if (h == (struct bfd_link_hash_entry *) NULL)
1751 einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
1752 if (h->type == bfd_link_hash_new)
1754 h->type = bfd_link_hash_undefined;
1755 h->u.undef.abfd = NULL;
1756 bfd_link_add_undef (link_info.hash, h);
1761 /* def_file_print (stdout, pep_def_file); */
1762 if (pep_def_file->is_dll == 1)
1763 link_info.type = type_dll;
1765 if (pep_def_file->base_address != (bfd_vma)(-1))
1768 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1769 = init[IMAGEBASEOFF].value
1770 = pep_def_file->base_address;
1771 init[IMAGEBASEOFF].inited = 1;
1772 if (image_base_statement)
1773 image_base_statement->exp
1774 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1778 if (pep_def_file->stack_reserve != -1
1779 && ! saw_option ("__size_of_stack_reserve__"))
1781 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1782 if (pep_def_file->stack_commit != -1)
1783 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1785 if (pep_def_file->heap_reserve != -1
1786 && ! saw_option ("__size_of_heap_reserve__"))
1788 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1789 if (pep_def_file->heap_commit != -1)
1790 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1800 gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1804 #ifdef TARGET_IS_i386pep
1805 pep_dll_id_target ("pei-x86-64");
1807 if (pep_bfd_is_dll (entry->the_bfd))
1808 return pep_implied_import_dll (entry->filename);
1814 gld_${EMULATION_NAME}_finish (void)
1820 if (bfd_link_pic (&link_info)
1821 || pep_dll_enable_reloc_section
1822 || (!bfd_link_relocatable (&link_info)
1823 && pep_def_file->num_exports != 0))
1825 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1826 if (command_line.out_implib_filename
1827 && (pep_def_file->num_exports != 0
1828 || bfd_link_pic (&link_info)))
1829 pep_dll_generate_implib (pep_def_file,
1830 command_line.out_implib_filename, &link_info);
1833 if (pep_out_def_filename)
1834 pep_dll_generate_def_file (pep_out_def_filename);
1835 #endif /* DLL_SUPPORT */
1837 /* I don't know where .idata gets set as code, but it shouldn't be. */
1839 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1843 asec->flags &= ~SEC_CODE;
1844 asec->flags |= SEC_DATA;
1850 /* Place an orphan section.
1852 We use this to put sections in a reasonable place in the file, and
1853 to ensure that they are aligned as required.
1855 We handle grouped sections here as well. A section named .foo\$nn
1856 goes into the output section .foo. All grouped sections are sorted
1859 Grouped sections for the default sections are handled by the
1860 default linker script using wildcards, and are sorted by
1863 static lang_output_section_statement_type *
1864 gld_${EMULATION_NAME}_place_orphan (asection *s,
1865 const char *secname,
1868 const char *orig_secname = secname;
1869 char *dollar = NULL;
1870 lang_output_section_statement_type *os;
1871 lang_statement_list_type add_child;
1872 lang_output_section_statement_type *match_by_name = NULL;
1873 lang_statement_union_type **pl;
1875 /* Look through the script to see where to place this section. */
1876 if (!bfd_link_relocatable (&link_info)
1877 && (dollar = strchr (secname, '\$')) != NULL)
1879 size_t len = dollar - secname;
1880 char *newname = xmalloc (len + 1);
1881 memcpy (newname, secname, len);
1882 newname[len] = '\0';
1886 lang_list_init (&add_child);
1889 if (constraint == 0)
1890 for (os = lang_output_section_find (secname);
1892 os = next_matching_output_section_statement (os, 0))
1894 /* If we don't match an existing output section, tell
1895 lang_insert_orphan to create a new output section. */
1896 constraint = SPECIAL;
1898 if (os->bfd_section != NULL
1899 && (os->bfd_section->flags == 0
1900 || ((s->flags ^ os->bfd_section->flags)
1901 & (SEC_LOAD | SEC_ALLOC)) == 0))
1903 /* We already have an output section statement with this
1904 name, and its bfd section has compatible flags.
1905 If the section already exists but does not have any flags set,
1906 then it has been created by the linker, probably as a result of
1907 a --section-start command line switch. */
1908 lang_add_section (&add_child, s, NULL, NULL, os);
1912 /* Save unused output sections in case we can match them
1913 against orphans later. */
1914 if (os->bfd_section == NULL)
1918 /* If we didn't match an active output section, see if we matched an
1919 unused one and use that. */
1920 if (os == NULL && match_by_name)
1922 lang_add_section (&match_by_name->children, s, NULL, NULL, match_by_name);
1923 return match_by_name;
1928 static struct orphan_save hold[] =
1931 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1934 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1937 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1940 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1946 enum orphan_save_index
1954 static int orphan_init_done = 0;
1955 struct orphan_save *place;
1956 lang_output_section_statement_type *after;
1957 etree_type *address;
1961 if (!orphan_init_done)
1963 struct orphan_save *ho;
1964 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1965 if (ho->name != NULL)
1967 ho->os = lang_output_section_find (ho->name);
1968 if (ho->os != NULL && ho->os->flags == 0)
1969 ho->os->flags = ho->flags;
1971 orphan_init_done = 1;
1975 if (!bfd_link_relocatable (&link_info))
1978 while ((nexts = bfd_get_next_section_by_name (nexts->owner,
1980 if (nexts->output_section == NULL
1981 && (nexts->flags & SEC_EXCLUDE) == 0
1982 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
1983 && (nexts->owner->flags & DYNAMIC) == 0
1984 && !bfd_input_just_syms (nexts->owner))
1985 flags = (((flags ^ SEC_READONLY)
1986 | (nexts->flags ^ SEC_READONLY))
1990 /* Try to put the new output section in a reasonable place based
1991 on the section name and section flags. */
1994 if ((flags & SEC_ALLOC) == 0)
1996 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1997 place = &hold[orphan_bss];
1998 else if ((flags & SEC_READONLY) == 0)
1999 place = &hold[orphan_data];
2000 else if ((flags & SEC_CODE) == 0)
2002 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2003 : &hold[orphan_rodata]);
2006 place = &hold[orphan_text];
2011 if (place->os == NULL)
2012 place->os = lang_output_section_find (place->name);
2015 after = lang_output_section_find_by_flags (s, flags, &place->os,
2018 /* *ABS* is always the first output section statement. */
2019 after = (void *) lang_os_list.head;
2022 /* All sections in an executable must be aligned to a page boundary.
2023 In a relocatable link, just preserve the incoming alignment; the
2024 address is discarded by lang_insert_orphan in that case, anyway. */
2025 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
2026 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2028 if (bfd_link_relocatable (&link_info))
2030 os->section_alignment = exp_intop (1U << s->alignment_power);
2031 os->bfd_section->alignment_power = s->alignment_power;
2035 /* If the section name has a '\$', sort it with the other '\$'
2037 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2039 lang_input_section_type *ls;
2042 if ((*pl)->header.type != lang_input_section_enum)
2045 ls = &(*pl)->input_section;
2047 lname = bfd_section_name (ls->section);
2048 if (strchr (lname, '\$') != NULL
2049 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2053 if (add_child.head != NULL)
2055 *add_child.tail = *pl;
2056 *pl = add_child.head;
2063 gld_${EMULATION_NAME}_open_dynamic_archive
2064 (const char *arch ATTRIBUTE_UNUSED,
2065 search_dirs_type *search,
2066 lang_input_statement_type *entry)
2070 const char * format;
2075 /* Preferred explicit import library for dll's. */
2076 { "lib%s.dll.a", false },
2077 /* Alternate explicit import library for dll's. */
2078 { "%s.dll.a", false },
2079 /* "libfoo.a" could be either an import lib or a static lib.
2080 For backwards compatibility, libfoo.a needs to precede
2081 libfoo.dll and foo.dll in the search. */
2082 { "lib%s.a", false },
2083 /* The 'native' spelling of an import lib name is "foo.lib". */
2084 { "%s.lib", false },
2085 /* PR 22948 - Check for an import library. */
2086 { "lib%s.lib", false },
2088 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2089 { "%s%s.dll", true },
2091 /* Try "libfoo.dll" (default preferred dll name). */
2092 { "lib%s.dll", false },
2093 /* Finally try 'native' dll name "foo.dll". */
2094 { "%s.dll", false },
2095 /* Note: If adding more formats to this table, make sure to check to
2096 see if their length is longer than libname_fmt[0].format, and if
2097 so, update the call to xmalloc() below. */
2100 static unsigned int format_max_len = 0;
2101 const char * filename;
2107 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
2110 filename = entry->filename;
2112 if (format_max_len == 0)
2113 /* We need to allow space in the memory that we are going to allocate
2114 for the characters in the format string. Since the format array is
2115 static we only need to calculate this information once. In theory
2116 this value could also be computed statically, but this introduces
2117 the possibility for a discrepancy and hence a possible memory
2118 corruption. The lengths we compute here will be too long because
2119 they will include any formating characters (%s) in the strings, but
2120 this will not matter. */
2121 for (i = 0; libname_fmt[i].format; i++)
2122 if (format_max_len < strlen (libname_fmt[i].format))
2123 format_max_len = strlen (libname_fmt[i].format);
2125 full_string = xmalloc (strlen (search->name)
2129 + (pep_dll_search_prefix
2130 ? strlen (pep_dll_search_prefix) : 0)
2132 /* Allow for the terminating NUL and for the path
2133 separator character that is inserted between
2134 search->name and the start of the format string. */
2137 sprintf (full_string, "%s/", search->name);
2138 base_string = full_string + strlen (full_string);
2140 for (i = 0; libname_fmt[i].format; i++)
2143 if (libname_fmt[i].use_prefix)
2145 if (!pep_dll_search_prefix)
2147 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2151 sprintf (base_string, libname_fmt[i].format, filename);
2153 if (ldfile_try_open_bfd (full_string, entry))
2157 if (!libname_fmt[i].format)
2163 entry->filename = full_string;
2169 gld_${EMULATION_NAME}_find_potential_libraries
2170 (char *name, lang_input_statement_type *entry)
2172 return ldfile_open_file_search (name, entry, "", ".lib");
2176 gld_${EMULATION_NAME}_get_script (int *isfile)
2179 if test x"$COMPILE_IN" = xyes
2181 # Scripts compiled in.
2183 # sed commands to quote an ld script as a C string.
2184 sc="-f stringify.sed"
2190 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2193 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2194 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2195 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2196 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2197 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2198 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2199 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2200 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2201 echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
2202 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2204 echo ' ; else return' >> e${EMULATION_NAME}.c
2205 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2206 echo '; }' >> e${EMULATION_NAME}.c
2209 # Scripts read from the filesystem.
2215 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2216 return "ldscripts/${EMULATION_NAME}.xu";
2217 else if (bfd_link_relocatable (&link_info))
2218 return "ldscripts/${EMULATION_NAME}.xr";
2219 else if (!config.text_read_only)
2220 return "ldscripts/${EMULATION_NAME}.xbn";
2221 else if (!config.magic_demand_paged)
2222 return "ldscripts/${EMULATION_NAME}.xn";
2224 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2226 else if (link_info.pei386_auto_import == 1
2227 && link_info.pei386_runtime_pseudo_reloc != 2)
2228 return "ldscripts/${EMULATION_NAME}.xa";
2233 return "ldscripts/${EMULATION_NAME}.x";
2241 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2243 gld_${EMULATION_NAME}_before_parse,
2246 gld_${EMULATION_NAME}_after_parse,
2247 gld_${EMULATION_NAME}_after_open,
2248 after_check_relocs_default,
2249 before_place_orphans_default,
2250 after_allocation_default,
2251 set_output_arch_default,
2252 ldemul_default_target,
2253 gld_${EMULATION_NAME}_before_allocation,
2254 gld_${EMULATION_NAME}_get_script,
2255 "${EMULATION_NAME}",
2257 gld_${EMULATION_NAME}_finish,
2258 NULL, /* Create output section statements. */
2259 gld_${EMULATION_NAME}_open_dynamic_archive,
2260 gld_${EMULATION_NAME}_place_orphan,
2261 gld_${EMULATION_NAME}_set_symbols,
2262 NULL, /* parse_args */
2263 gld${EMULATION_NAME}_add_options,
2264 gld${EMULATION_NAME}_handle_option,
2265 gld_${EMULATION_NAME}_unrecognized_file,
2266 gld_${EMULATION_NAME}_list_options,
2267 gld_${EMULATION_NAME}_recognized_file,
2268 gld_${EMULATION_NAME}_find_potential_libraries,
2269 NULL, /* new_vers_pattern. */
2270 NULL, /* extra_map_file_text */
2271 ${LDEMUL_EMIT_CTF_EARLY-NULL},
2272 ${LDEMUL_ACQUIRE_STRINGS_FOR_CTF-NULL},
2273 ${LDEMUL_NEW_DYNSYM_FOR_CTF-NULL},
2274 ${LDEMUL_PRINT_SYMBOL-NULL}