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-2016 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
55 #include "libiberty.h"
56 #include "filenames.h"
67 #include "ldbuildid.h"
68 #include "coff/internal.h"
70 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
71 header in generic PE code. */
72 #include "coff/x86_64.h"
75 /* FIXME: These are BFD internal header files, and we should not be
77 #include "../bfd/libcoff.h"
78 #include "../bfd/libpei.h"
81 #define AOUTSZ PEPAOUTSZ
82 #define PEAOUTHDR PEPAOUTHDR
86 #include "safe-ctype.h"
88 /* Permit the emulation parameters to override the default section
89 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
90 it seem that include/coff/internal.h should not define
91 PE_DEF_SECTION_ALIGNMENT. */
92 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
93 #undef PE_DEF_SECTION_ALIGNMENT
94 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
97 #ifdef TARGET_IS_i386pep
101 #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
102 #define PE_DEF_SUBSYSTEM 3
103 #undef NT_EXE_IMAGE_BASE
104 #define NT_EXE_IMAGE_BASE \
105 ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
107 #undef NT_DLL_IMAGE_BASE
108 #define NT_DLL_IMAGE_BASE \
109 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
111 #undef NT_DLL_AUTO_IMAGE_BASE
112 #define NT_DLL_AUTO_IMAGE_BASE \
113 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
115 #undef NT_DLL_AUTO_IMAGE_MASK
116 #define NT_DLL_AUTO_IMAGE_MASK \
117 ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
120 #undef NT_EXE_IMAGE_BASE
121 #define NT_EXE_IMAGE_BASE \
122 ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
124 #undef NT_DLL_IMAGE_BASE
125 #define NT_DLL_IMAGE_BASE \
126 ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
128 #undef NT_DLL_AUTO_IMAGE_BASE
129 #define NT_DLL_AUTO_IMAGE_BASE \
130 ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
132 #undef NT_DLL_AUTO_IMAGE_MASK
133 #define NT_DLL_AUTO_IMAGE_MASK \
134 ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
136 #undef PE_DEF_SECTION_ALIGNMENT
137 #define PE_DEF_SUBSYSTEM 2
138 #undef PE_DEF_FILE_ALIGNMENT
139 #define PE_DEF_FILE_ALIGNMENT 0x00000200
140 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
143 static struct internal_extra_pe_aouthdr pep;
145 static int pep_subsystem = ${SUBSYSTEM};
146 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
147 static int support_old_code = 0;
148 static lang_assignment_statement_type *image_base_statement = 0;
149 static unsigned short pe_dll_characteristics = 0;
150 static bfd_boolean insert_timestamp = TRUE;
151 static const char *emit_build_id;
154 static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
155 static char * pep_out_def_filename = NULL;
156 static int pep_enable_auto_image_base = 0;
157 static char * pep_dll_search_prefix = NULL;
160 extern const char *output_filename;
162 static int is_underscoring (void)
165 if (pep_leading_underscore != -1)
166 return pep_leading_underscore;
167 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
168 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
172 pep_leading_underscore = (u != 0 ? 1 : 0);
173 return pep_leading_underscore;
178 gld_${EMULATION_NAME}_before_parse (void)
181 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
182 output_filename = "${EXECUTABLE_NAME:-a.exe}";
184 input_flags.dynamic = TRUE;
185 config.has_shared = 1;
186 link_info.pei386_auto_import = 1;
187 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
191 /* PE format extra command line options. */
193 /* Used for setting flags in the PE header. */
196 OPTION_BASE_FILE = 300 + 1,
198 OPTION_FILE_ALIGNMENT,
200 OPTION_MAJOR_IMAGE_VERSION,
201 OPTION_MAJOR_OS_VERSION,
202 OPTION_MAJOR_SUBSYSTEM_VERSION,
203 OPTION_MINOR_IMAGE_VERSION,
204 OPTION_MINOR_OS_VERSION,
205 OPTION_MINOR_SUBSYSTEM_VERSION,
206 OPTION_SECTION_ALIGNMENT,
210 OPTION_SUPPORT_OLD_CODE,
213 OPTION_EXCLUDE_SYMBOLS,
214 OPTION_EXCLUDE_ALL_SYMBOLS,
216 OPTION_STDCALL_ALIASES,
217 OPTION_ENABLE_STDCALL_FIXUP,
218 OPTION_DISABLE_STDCALL_FIXUP,
219 OPTION_WARN_DUPLICATE_EXPORTS,
221 OPTION_ENABLE_AUTO_IMAGE_BASE,
222 OPTION_DISABLE_AUTO_IMAGE_BASE,
223 OPTION_DLL_SEARCH_PREFIX,
224 OPTION_NO_DEFAULT_EXCLUDES,
225 OPTION_DLL_ENABLE_AUTO_IMPORT,
226 OPTION_DLL_DISABLE_AUTO_IMPORT,
227 OPTION_ENABLE_EXTRA_PE_DEBUG,
229 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
230 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
231 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
232 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
233 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
234 OPTION_NO_LEADING_UNDERSCORE,
235 OPTION_LEADING_UNDERSCORE,
236 OPTION_ENABLE_LONG_SECTION_NAMES,
237 OPTION_DISABLE_LONG_SECTION_NAMES,
238 OPTION_HIGH_ENTROPY_VA,
240 OPTION_FORCE_INTEGRITY,
246 OPTION_INSERT_TIMESTAMP,
247 OPTION_NO_INSERT_TIMESTAMP,
248 OPTION_TERMINAL_SERVER_AWARE,
253 gld${EMULATION_NAME}_add_options
254 (int ns ATTRIBUTE_UNUSED,
255 char **shortopts ATTRIBUTE_UNUSED,
257 struct option **longopts,
258 int nrl ATTRIBUTE_UNUSED,
259 struct option **really_longopts ATTRIBUTE_UNUSED)
261 static const struct option xtra_long[] =
264 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
265 {"dll", no_argument, NULL, OPTION_DLL},
266 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
267 {"heap", required_argument, NULL, OPTION_HEAP},
268 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
269 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
270 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
271 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
272 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
273 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
274 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
275 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
276 {"stack", required_argument, NULL, OPTION_STACK},
277 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
278 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
279 {"use-nul-prefixed-import-tables", no_argument, NULL,
280 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
281 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
282 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
284 /* getopt allows abbreviations, so we do this to stop it
285 from treating -o as an abbreviation for this option. */
286 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
287 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
288 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
289 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
290 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
291 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
292 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
293 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
294 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
295 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
296 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
297 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
298 /* getopt() allows abbreviations, so we do this to stop it from
299 treating -c as an abbreviation for these --compat-implib. */
300 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
301 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
302 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
303 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
304 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
305 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
306 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
307 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
308 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
309 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
310 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
311 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
313 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
314 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
315 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
316 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
317 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
318 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
319 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
320 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
321 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
322 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
323 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
324 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
325 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
326 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
327 {NULL, no_argument, NULL, 0}
331 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
332 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
335 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
336 parameters which may be input from the command line. */
345 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
346 C visible symbols can be prefixed by underscore dependent on target's
348 bfd_boolean is_c_symbol;
351 #define GET_INIT_SYMBOL_NAME(IDX) \
352 (init[(IDX)].symbol \
353 + ((init[(IDX)].is_c_symbol == FALSE || (is_underscoring () == 1)) ? 0 : 1))
355 /* Decorates the C visible symbol by underscore, if target requires. */
357 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
359 /* Get size of constant string for a possible underscore prefixed
361 #define U_SIZE(CSTR) \
362 (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
364 #define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
366 static definfo init[] =
368 /* imagebase must be first */
369 #define IMAGEBASEOFF 0
370 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, FALSE),
372 {&dll, sizeof(dll), 0, "__dll__", 0, FALSE},
373 #define MSIMAGEBASEOFF 2
374 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, TRUE),
375 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, FALSE),
376 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, FALSE),
377 D(MajorOperatingSystemVersion,"__major_os_version__", 4, FALSE),
378 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, FALSE),
379 D(MajorImageVersion,"__major_image_version__", 0, FALSE),
380 D(MinorImageVersion,"__minor_image_version__", 0, FALSE),
381 D(MajorSubsystemVersion,"__major_subsystem_version__", 5, FALSE),
382 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2, FALSE),
383 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, FALSE),
384 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, FALSE),
385 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, FALSE),
386 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, FALSE),
387 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, FALSE),
388 D(LoaderFlags,"__loader_flags__", 0x0, FALSE),
389 D(DllCharacteristics, "__dll_characteristics__", 0x0, FALSE),
390 { NULL, 0, 0, NULL, 0, FALSE}
395 gld_${EMULATION_NAME}_list_options (FILE *file)
397 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
398 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
399 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
400 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
401 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
402 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
403 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
404 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
405 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
406 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
407 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
408 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
409 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
410 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
411 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
412 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
413 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero. (default)\n"));
414 fprintf (file, _(" This makes binaries non-deterministic\n"));
416 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
417 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
418 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
419 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
420 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
421 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
422 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
423 fprintf (file, _(" Exclude objects, archive members from auto\n"));
424 fprintf (file, _(" export, place into import library instead.\n"));
425 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
426 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
427 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
428 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
429 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
430 create __imp_<SYMBOL> as well.\n"));
431 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
432 unless user specifies one\n"));
433 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
434 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
435 an importlib, use <string><basename>.dll\n\
436 in preference to lib<basename>.dll \n"));
437 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
438 __imp_sym for DATA references\n"));
439 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
440 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
441 adding pseudo-relocations resolved at\n\
443 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
444 auto-imported DATA.\n"));
445 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
446 or linking to DLLs (esp. auto-import)\n"));
447 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
448 executable image files\n"));
449 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
450 in object files\n"));
451 fprintf (file, _(" --high-entropy-va Image is compatible with 64-bit address space\n\
452 layout randomization (ASLR)\n"));
453 fprintf (file, _(" --dynamicbase Image base address may be relocated using\n\
454 address space layout randomization (ASLR)\n"));
455 fprintf (file, _(" --forceinteg Code integrity checks are enforced\n"));
456 fprintf (file, _(" --nxcompat Image is compatible with data execution prevention\n"));
457 fprintf (file, _(" --no-isolation Image understands isolation but do not isolate the image\n"));
458 fprintf (file, _(" --no-seh Image does not use SEH. No SE handler may\n\
459 be called in this image\n"));
460 fprintf (file, _(" --no-bind Do not bind this image\n"));
461 fprintf (file, _(" --wdmdriver Driver uses the WDM model\n"));
462 fprintf (file, _(" --tsaware Image is Terminal Server aware\n"));
463 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
469 set_pep_name (char *name, bfd_vma val)
473 /* Find the name and set it. */
474 for (i = 0; init[i].ptr; i++)
476 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
480 if (strcmp (name,"__image_base__") == 0)
481 set_pep_name (U ("__ImageBase"), val);
489 set_entry_point (void)
492 const char *initial_symbol_char;
502 { 1, "NtProcessStartup" },
503 { 2, "WinMainCRTStartup" },
504 { 3, "mainCRTStartup" },
505 { 7, "__PosixProcessStartup" },
506 { 9, "WinMainCRTStartup" },
507 {14, "mainCRTStartup" },
511 /* Entry point name for arbitrary subsystem numbers. */
512 static const char default_entry[] = "mainCRTStartup";
514 if (bfd_link_pic (&link_info) || dll)
516 entry = "DllMainCRTStartup";
520 for (i = 0; v[i].entry; i++)
521 if (v[i].value == pep_subsystem)
524 /* If no match, use the default. */
525 if (v[i].entry != NULL)
528 entry = default_entry;
531 /* Now we check target's default for getting proper symbol_char. */
532 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
534 if (*initial_symbol_char != '\0')
538 /* lang_default_entry expects its argument to be permanently
539 allocated, so we don't free this string. */
540 alc_entry = xmalloc (strlen (initial_symbol_char)
543 strcpy (alc_entry, initial_symbol_char);
544 strcat (alc_entry, entry);
548 lang_default_entry (entry);
552 set_pep_subsystem (void)
558 unsigned long temp_subsystem;
575 /* Check for the presence of a version number. */
576 sver = strchr (optarg, ':');
578 len = strlen (optarg);
582 set_pep_name ("__major_subsystem_version__",
583 strtoul (sver + 1, &end, 0));
585 set_pep_name ("__minor_subsystem_version__",
586 strtoul (end + 1, &end, 0));
588 einfo (_("%P: warning: bad version number in -subsystem option\n"));
591 /* Check for numeric subsystem. */
592 temp_subsystem = strtoul (optarg, & end, 0);
593 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
595 /* Search list for a numeric match to use its entry point. */
596 for (i = 0; v[i].name; i++)
597 if (v[i].value == (int) temp_subsystem)
600 /* Use this subsystem. */
601 pep_subsystem = (int) temp_subsystem;
605 /* Search for subsystem by name. */
606 for (i = 0; v[i].name; i++)
607 if (strncmp (optarg, v[i].name, len) == 0
608 && v[i].name[len] == '\0')
611 if (v[i].name == NULL)
613 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
617 pep_subsystem = v[i].value;
620 set_pep_name ("__subsystem__", pep_subsystem);
627 set_pep_value (char *name)
631 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
634 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
641 set_pep_stack_heap (char *resname, char *comname)
643 set_pep_value (resname);
648 set_pep_value (comname);
651 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
654 #define DEFAULT_BUILD_ID_STYLE "md5"
657 gld${EMULATION_NAME}_handle_option (int optc)
665 case OPTION_BASE_FILE:
666 link_info.base_file = fopen (optarg, FOPEN_WB);
667 if (link_info.base_file == NULL)
668 einfo (_("%F%P: cannot open base file %s\n"), optarg);
673 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
676 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
678 case OPTION_SUBSYSTEM:
679 set_pep_subsystem ();
681 case OPTION_MAJOR_OS_VERSION:
682 set_pep_value ("__major_os_version__");
684 case OPTION_MINOR_OS_VERSION:
685 set_pep_value ("__minor_os_version__");
687 case OPTION_MAJOR_SUBSYSTEM_VERSION:
688 set_pep_value ("__major_subsystem_version__");
690 case OPTION_MINOR_SUBSYSTEM_VERSION:
691 set_pep_value ("__minor_subsystem_version__");
693 case OPTION_MAJOR_IMAGE_VERSION:
694 set_pep_value ("__major_image_version__");
696 case OPTION_MINOR_IMAGE_VERSION:
697 set_pep_value ("__minor_image_version__");
699 case OPTION_FILE_ALIGNMENT:
700 set_pep_value ("__file_alignment__");
702 case OPTION_SECTION_ALIGNMENT:
703 set_pep_value ("__section_alignment__");
706 set_pep_name ("__dll__", 1);
708 case OPTION_IMAGE_BASE:
709 set_pep_value ("__image_base__");
711 case OPTION_SUPPORT_OLD_CODE:
712 support_old_code = 1;
714 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
715 pep_use_nul_prefixed_import_tables = TRUE;
717 case OPTION_NO_LEADING_UNDERSCORE:
718 pep_leading_underscore = 0;
720 case OPTION_LEADING_UNDERSCORE:
721 pep_leading_underscore = 1;
723 case OPTION_INSERT_TIMESTAMP:
724 insert_timestamp = TRUE;
726 case OPTION_NO_INSERT_TIMESTAMP:
727 insert_timestamp = FALSE;
731 pep_out_def_filename = xstrdup (optarg);
733 case OPTION_EXPORT_ALL:
734 pep_dll_export_everything = 1;
736 case OPTION_EXCLUDE_SYMBOLS:
737 pep_dll_add_excludes (optarg, EXCLUDESYMS);
739 case OPTION_EXCLUDE_ALL_SYMBOLS:
740 pep_dll_exclude_all_symbols = 1;
742 case OPTION_EXCLUDE_LIBS:
743 pep_dll_add_excludes (optarg, EXCLUDELIBS);
745 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
746 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
748 case OPTION_KILL_ATS:
749 pep_dll_kill_ats = 1;
751 case OPTION_STDCALL_ALIASES:
752 pep_dll_stdcall_aliases = 1;
754 case OPTION_ENABLE_STDCALL_FIXUP:
755 pep_enable_stdcall_fixup = 1;
757 case OPTION_DISABLE_STDCALL_FIXUP:
758 pep_enable_stdcall_fixup = 0;
760 case OPTION_WARN_DUPLICATE_EXPORTS:
761 pep_dll_warn_dup_exports = 1;
763 case OPTION_IMP_COMPAT:
764 pep_dll_compat_implib = 1;
766 case OPTION_ENABLE_AUTO_IMAGE_BASE:
767 pep_enable_auto_image_base = 1;
769 case OPTION_DISABLE_AUTO_IMAGE_BASE:
770 pep_enable_auto_image_base = 0;
772 case OPTION_DLL_SEARCH_PREFIX:
773 pep_dll_search_prefix = xstrdup (optarg);
775 case OPTION_NO_DEFAULT_EXCLUDES:
776 pep_dll_do_default_excludes = 0;
778 case OPTION_DLL_ENABLE_AUTO_IMPORT:
779 link_info.pei386_auto_import = 1;
781 case OPTION_DLL_DISABLE_AUTO_IMPORT:
782 link_info.pei386_auto_import = 0;
784 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
785 link_info.pei386_runtime_pseudo_reloc = 2;
787 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
788 link_info.pei386_runtime_pseudo_reloc = 0;
790 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
791 link_info.pei386_runtime_pseudo_reloc = 2;
793 case OPTION_ENABLE_EXTRA_PE_DEBUG:
794 pep_dll_extra_pe_debug = 1;
797 case OPTION_ENABLE_LONG_SECTION_NAMES:
798 pep_use_coff_long_section_names = 1;
800 case OPTION_DISABLE_LONG_SECTION_NAMES:
801 pep_use_coff_long_section_names = 0;
803 /* Get DLLCharacteristics bits */
804 case OPTION_HIGH_ENTROPY_VA:
805 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
807 case OPTION_DYNAMIC_BASE:
808 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
810 case OPTION_FORCE_INTEGRITY:
811 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
813 case OPTION_NX_COMPAT:
814 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
816 case OPTION_NO_ISOLATION:
817 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
820 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
823 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
825 case OPTION_WDM_DRIVER:
826 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
828 case OPTION_TERMINAL_SERVER_AWARE:
829 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
831 case OPTION_BUILD_ID:
832 if (emit_build_id != NULL)
834 free ((char *) emit_build_id);
835 emit_build_id = NULL;
838 optarg = DEFAULT_BUILD_ID_STYLE;
839 if (strcmp (optarg, "none"))
840 emit_build_id = xstrdup (optarg);
844 /* Set DLLCharacteristics bits */
845 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
853 strhash (const char *str)
855 const unsigned char *s;
862 s = (const unsigned char *) str;
863 while ((c = *s++) != '\0')
865 hash += c + (c << 17);
869 hash += len + (len << 17);
875 /* Use the output file to create a image base for relocatable DLLs. */
878 compute_dll_image_base (const char *ofile)
880 bfd_vma hash = (bfd_vma) strhash (ofile);
881 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
885 /* Assign values to the special symbols before the linker script is
889 gld_${EMULATION_NAME}_set_symbols (void)
891 /* Run through and invent symbols for all the
892 names and insert the defaults. */
897 if (!init[IMAGEBASEOFF].inited)
899 if (bfd_link_relocatable (&link_info))
900 init[IMAGEBASEOFF].value = 0;
901 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
904 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
905 ? compute_dll_image_base (output_filename)
906 : NT_DLL_IMAGE_BASE);
908 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
912 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
913 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
916 /* Don't do any symbol assignments if this is a relocatable link. */
917 if (bfd_link_relocatable (&link_info))
920 /* Glue the assignments into the abs section. */
921 push_stat_ptr (&abs_output_section->children);
923 for (j = 0; init[j].ptr; j++)
925 bfd_vma val = init[j].value;
926 lang_assignment_statement_type *rv;
928 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
929 exp_intop (val), FALSE));
930 if (init[j].size == sizeof (short))
931 *(short *) init[j].ptr = (short) val;
932 else if (init[j].size == sizeof (int))
933 *(int *) init[j].ptr = (int) val;
934 else if (init[j].size == sizeof (long))
935 *(long *) init[j].ptr = (long) val;
936 /* This might be a long long or other special type. */
937 else if (init[j].size == sizeof (bfd_vma))
938 *(bfd_vma *) init[j].ptr = val;
940 if (j == IMAGEBASEOFF)
941 image_base_statement = rv;
943 /* Restore the pointer. */
946 if (pep.FileAlignment > pep.SectionAlignment)
948 einfo (_("%P: warning, file alignment > section alignment.\n"));
952 /* This is called after the linker script and the command line options
956 gld_${EMULATION_NAME}_after_parse (void)
958 /* PR ld/6744: Warn the user if they have used an ELF-only
959 option hoping it will work on PE+. */
960 if (link_info.export_dynamic)
961 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
962 "targets, did you mean --export-all-symbols?\n"));
966 after_parse_default ();
969 /* pep-dll.c directly accesses pep_data_import_dll,
970 so it must be defined outside of #ifdef DLL_SUPPORT.
971 Note - this variable is deliberately not initialised.
972 This allows it to be treated as a common varaible, and only
973 exist in one incarnation in a multiple target enabled linker. */
974 char * pep_data_import_dll;
977 static struct bfd_link_hash_entry *pep_undef_found_sym;
980 pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
984 const char *hs = h->root.string;
986 sl = strlen (string);
987 if (h->type == bfd_link_hash_defined
988 && ((*hs == '@' && *string == '_'
989 && strncmp (hs + 1, string + 1, sl - 1) == 0)
990 || strncmp (hs, string, sl) == 0)
991 && h->root.string[sl] == '@')
993 pep_undef_found_sym = h;
1000 pep_fixup_stdcalls (void)
1002 static int gave_warning_message = 0;
1003 struct bfd_link_hash_entry *undef, *sym;
1005 if (pep_dll_extra_pe_debug)
1006 printf ("%s\n", __FUNCTION__);
1008 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1009 if (undef->type == bfd_link_hash_undefined)
1011 char* at = strchr (undef->root.string, '@');
1012 int lead_at = (*undef->root.string == '@');
1014 at = strchr (undef->root.string + 1, '@');
1017 /* The symbol is a stdcall symbol, so let's look for a
1018 cdecl symbol with the same name and resolve to that. */
1019 char *cname = xstrdup (undef->root.string);
1023 at = strchr (cname, '@');
1026 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1028 if (sym && sym->type == bfd_link_hash_defined)
1030 undef->type = bfd_link_hash_defined;
1031 undef->u.def.value = sym->u.def.value;
1032 undef->u.def.section = sym->u.def.section;
1034 if (pep_enable_stdcall_fixup == -1)
1036 einfo (_("Warning: resolving %s by linking to %s\n"),
1037 undef->root.string, cname);
1038 if (! gave_warning_message)
1040 gave_warning_message = 1;
1041 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1042 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1049 /* The symbol is a cdecl symbol, so we look for stdcall
1050 symbols - which means scanning the whole symbol table. */
1051 pep_undef_found_sym = 0;
1052 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
1053 (char *) undef->root.string);
1054 sym = pep_undef_found_sym;
1057 undef->type = bfd_link_hash_defined;
1058 undef->u.def.value = sym->u.def.value;
1059 undef->u.def.section = sym->u.def.section;
1061 if (pep_enable_stdcall_fixup == -1)
1063 einfo (_("Warning: resolving %s by linking to %s\n"),
1064 undef->root.string, sym->root.string);
1065 if (! gave_warning_message)
1067 gave_warning_message = 1;
1068 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1069 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1078 make_import_fixup (arelent *rel, asection *s)
1080 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1082 bfd_vma _addend = 0;
1085 if (pep_dll_extra_pe_debug)
1086 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1087 (unsigned long) rel->address, (long) rel->addend);
1089 memset (addend, 0, sizeof (addend));
1090 switch ((rel->howto->bitsize))
1093 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 1);
1094 if (suc && rel->howto->pc_relative)
1095 _addend = (bfd_vma) ((bfd_signed_vma) ((char) bfd_get_8 (s->owner, addend)));
1097 _addend = ((bfd_vma) bfd_get_8 (s->owner, addend)) & 0xff;
1100 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 2);
1101 if (suc && rel->howto->pc_relative)
1102 _addend = (bfd_vma) ((bfd_signed_vma) ((short) bfd_get_16 (s->owner, addend)));
1104 _addend = ((bfd_vma) bfd_get_16 (s->owner, addend)) & 0xffff;
1107 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
1108 if (suc && rel->howto->pc_relative)
1109 _addend = (bfd_vma) ((bfd_signed_vma) ((int) bfd_get_32 (s->owner, addend)));
1111 _addend = ((bfd_vma) bfd_get_32 (s->owner, addend)) & 0xffffffff;
1114 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
1116 _addend = ((bfd_vma) bfd_get_64 (s->owner, addend));
1120 einfo (_("%C: Cannot get section contents - auto-import exception\n"),
1121 s->owner, s, rel->address);
1123 if (pep_dll_extra_pe_debug)
1125 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx", (long) _addend, (long) rel->addend, (long) rel->address);
1126 if (rel->howto->pc_relative) printf (" pcrel");
1127 printf (" %d bit rel.\n",(int) rel->howto->bitsize);
1129 pep_create_import_fixup (rel, s, _addend);
1135 pep_find_data_imports (void)
1137 struct bfd_link_hash_entry *undef, *sym;
1139 if (link_info.pei386_auto_import == 0)
1142 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1144 if (undef->type == bfd_link_hash_undefined)
1146 /* C++ symbols are *long*. */
1147 #define BUF_SIZE 4096
1150 if (pep_dll_extra_pe_debug)
1151 printf ("%s:%s\n", __FUNCTION__, undef->root.string);
1153 if (strlen (undef->root.string) > (BUF_SIZE - 6))
1155 /* PR linker/18466. */
1156 einfo (_("%P: internal error: symbol too long: %s\n"),
1157 undef->root.string);
1161 sprintf (buf, "__imp_%s", undef->root.string);
1163 sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
1165 if (sym && sym->type == bfd_link_hash_defined)
1167 bfd *b = sym->u.def.section->owner;
1171 if (!bfd_generic_link_read_symbols (b))
1173 einfo (_("%B%F: could not read symbols: %E\n"), b);
1177 symbols = bfd_get_outsymbols (b);
1178 nsyms = bfd_get_symcount (b);
1180 for (i = 0; i < nsyms; i++)
1182 if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
1185 if (pep_dll_extra_pe_debug)
1186 printf ("->%s\n", symbols[i]->name);
1188 pep_data_import_dll = (char*) (symbols[i]->name +
1189 U_SIZE ("_head_") - 1);
1193 pep_walk_relocs_of_symbol (&link_info, undef->root.string,
1196 /* Let's differentiate it somehow from defined. */
1197 undef->type = bfd_link_hash_defweak;
1198 /* We replace original name with __imp_ prefixed, this
1199 1) may trash memory 2) leads to duplicate symbol generation.
1200 Still, IMHO it's better than having name polluted. */
1201 undef->root.string = sym->root.string;
1202 undef->u.def.value = sym->u.def.value;
1203 undef->u.def.section = sym->u.def.section;
1210 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1212 printf ("+%s\n", h->string);
1216 #endif /* DLL_SUPPORT */
1219 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1221 int *found = (int *) obj;
1223 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1228 pecoff_checksum_contents (bfd *abfd,
1229 void (*process) (const void *, size_t, void *),
1232 file_ptr filepos = (file_ptr) 0;
1239 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1242 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1248 (*process) (&b, 1, arg);
1256 write_build_id (bfd *abfd)
1258 struct pe_tdata *t = pe_data (abfd);
1260 struct bfd_link_order *link_order = NULL;
1261 unsigned char *contents;
1263 bfd_size_type build_id_size;
1264 unsigned char *build_id;
1266 /* Find the section the .buildid output section has been merged info. */
1267 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1269 struct bfd_link_order *l = NULL;
1270 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1272 if (l->type == bfd_indirect_link_order)
1274 if (l->u.indirect.section == t->build_id.sec)
1288 einfo (_("%P: warning: .buildid section discarded,"
1289 " --build-id ignored.\n"));
1293 if (t->build_id.sec->contents == NULL)
1294 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1295 contents = t->build_id.sec->contents;
1296 size = t->build_id.sec->size;
1298 build_id_size = compute_build_id_size (t->build_id.style);
1299 build_id = xmalloc (build_id_size);
1300 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1302 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1304 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1305 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1306 idd.Characteristics = 0;
1307 idd.TimeDateStamp = 0;
1308 idd.MajorVersion = 0;
1309 idd.MinorVersion = 0;
1310 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1311 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1312 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1313 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1314 idd.PointerToRawData = asec->filepos + link_order->offset
1315 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1317 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1318 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1320 /* Write the debug directory enttry */
1321 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1324 if (bfd_bwrite (contents, size, abfd) != size)
1327 /* Construct the CodeView record. */
1328 CODEVIEW_INFO cvinfo;
1329 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1332 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1333 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1334 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1335 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1339 /* Write the codeview record. */
1340 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1343 /* Record the location of the debug directory in the data directory. */
1344 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1345 = asec->vma - ib + link_order->offset;
1346 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1347 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1352 /* Make .buildid section, and set up coff_tdata->build_id. */
1354 setup_build_id (bfd *ibfd)
1359 if (!validate_build_id_style (emit_build_id))
1361 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1365 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1366 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1367 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
1370 struct pe_tdata *t = pe_data (link_info.output_bfd);
1371 t->build_id.after_write_object_contents = &write_build_id;
1372 t->build_id.style = emit_build_id;
1373 t->build_id.sec = s;
1375 /* Section is a fixed size:
1376 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1377 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1378 null byte for PdbFileName. */
1379 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1380 + sizeof (CV_INFO_PDB70) + 1;
1385 einfo ("%P: warning: Cannot create .buildid section,"
1386 " --build-id ignored.\n");
1391 gld_${EMULATION_NAME}_after_open (void)
1393 after_open_default ();
1397 if (pep_dll_extra_pe_debug)
1400 struct bfd_link_hash_entry *sym;
1402 printf ("%s()\n", __FUNCTION__);
1404 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1405 printf ("-%s\n", sym->root.string);
1406 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1408 for (a = link_info.input_bfds; a; a = a->link.next)
1409 printf ("*%s\n",a->filename);
1413 if (emit_build_id != NULL)
1417 /* Find a COFF input. */
1418 for (abfd = link_info.input_bfds;
1419 abfd != (bfd *) NULL; abfd = abfd->link.next)
1420 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1423 /* If there are no COFF input files do not try to
1424 add a build-id section. */
1426 || !setup_build_id (abfd))
1428 free ((char *) emit_build_id);
1429 emit_build_id = NULL;
1433 /* Pass the wacky PE command line options into the output bfd.
1434 FIXME: This should be done via a function, rather than by
1435 including an internal BFD header. */
1437 if (coff_data (link_info.output_bfd) == NULL
1438 || coff_data (link_info.output_bfd)->pe == 0)
1439 einfo (_("%F%P: cannot perform PE operations on non PE output file '%B'.\n"),
1440 link_info.output_bfd);
1442 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1443 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1444 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1445 pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
1447 /* At this point we must decide whether to use long section names
1448 in the output or not. If the user hasn't explicitly specified
1449 on the command line, we leave it to the default for the format
1450 (object files yes, image files no), except if there is debug
1451 information present; GDB relies on the long section names to
1452 find it, so enable it in that case. */
1453 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1455 if (bfd_link_relocatable (&link_info))
1456 pep_use_coff_long_section_names = 1;
1459 /* Iterate over all sections of all input BFDs, checking
1460 for any that begin 'debug_' and are long names. */
1461 LANG_FOR_EACH_INPUT_STATEMENT (is)
1463 int found_debug = 0;
1465 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1468 pep_use_coff_long_section_names = 1;
1475 pep_output_file_set_long_section_names (link_info.output_bfd);
1478 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1479 pep_fixup_stdcalls ();
1481 pep_process_import_defs (link_info.output_bfd, &link_info);
1483 pep_find_data_imports ();
1485 /* As possibly new symbols are added by imports, we rerun
1486 stdcall/fastcall fixup here. */
1487 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1488 pep_fixup_stdcalls ();
1490 #ifndef TARGET_IS_i386pep
1491 if (bfd_link_pic (&link_info))
1493 if (!bfd_link_relocatable (&link_info))
1495 pep_dll_build_sections (link_info.output_bfd, &link_info);
1497 #ifndef TARGET_IS_i386pep
1499 pep_exe_build_sections (link_info.output_bfd, &link_info);
1501 #endif /* DLL_SUPPORT */
1504 /* This next chunk of code tries to detect the case where you have
1505 two import libraries for the same DLL (specifically,
1506 symbolically linking libm.a and libc.a in cygwin to
1507 libcygwin.a). In those cases, it's possible for function
1508 thunks from the second implib to be used but without the
1509 head/tail objects, causing an improper import table. We detect
1510 those cases and rename the "other" import libraries to match
1511 the one the head/tail come from, so that the linker will sort
1512 things nicely and produce a valid import table. */
1514 LANG_FOR_EACH_INPUT_STATEMENT (is)
1516 if (is->the_bfd->my_archive)
1518 int idata2 = 0, reloc_count=0, is_imp = 0;
1521 /* See if this is an import library thunk. */
1522 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1524 if (strcmp (sec->name, ".idata\$2") == 0)
1526 if (CONST_STRNEQ (sec->name, ".idata\$"))
1528 reloc_count += sec->reloc_count;
1531 if (is_imp && !idata2 && reloc_count)
1533 /* It is, look for the reference to head and see if it's
1534 from our own library. */
1535 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1543 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1547 if (!bfd_generic_link_read_symbols (is->the_bfd))
1549 einfo (_("%B%F: could not read symbols: %E\n"),
1553 symbols = bfd_get_outsymbols (is->the_bfd);
1555 relocs = xmalloc ((size_t) relsize);
1556 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1561 einfo ("%X%P: unable to process relocs: %E\n");
1565 for (i = 0; i < nrelocs; i++)
1567 struct bfd_symbol *s;
1568 struct bfd_link_hash_entry * blhe;
1569 char *other_bfd_filename;
1572 s = (relocs[i]->sym_ptr_ptr)[0];
1574 if (s->flags & BSF_LOCAL)
1577 /* Thunk section with reloc to another bfd. */
1578 blhe = bfd_link_hash_lookup (link_info.hash,
1580 FALSE, FALSE, TRUE);
1583 || blhe->type != bfd_link_hash_defined)
1587 = blhe->u.def.section->owner->my_archive
1588 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1589 : bfd_get_filename (blhe->u.def.section->owner);
1591 if (filename_cmp (bfd_get_filename
1592 (is->the_bfd->my_archive),
1593 other_bfd_filename) == 0)
1596 /* Rename this implib to match the other one. */
1597 n = xmalloc (strlen (other_bfd_filename) + 1);
1598 strcpy (n, other_bfd_filename);
1599 is->the_bfd->my_archive->filename = n;
1603 /* Note - we do not free the symbols,
1604 they are now cached in the BFD. */
1614 lang_input_statement_type *is2;
1615 lang_input_statement_type *is3;
1617 /* Careful - this is a shell script. Watch those dollar signs! */
1618 /* Microsoft import libraries have every member named the same,
1619 and not in the right order for us to link them correctly. We
1620 must detect these and rename the members so that they'll link
1621 correctly. There are three types of objects: the head, the
1622 thunks, and the sentinel(s). The head is easy; it's the one
1623 with idata2. We assume that the sentinels won't have relocs,
1624 and the thunks will. It's easier than checking the symbol
1625 table for external references. */
1626 LANG_FOR_EACH_INPUT_STATEMENT (is)
1628 if (is->the_bfd->my_archive)
1631 bfd *arch = is->the_bfd->my_archive;
1633 if (cur_arch != arch)
1639 is3 && is3->the_bfd->my_archive == arch;
1640 is3 = (lang_input_statement_type *) is3->next)
1642 /* A MS dynamic import library can also contain static
1643 members, so look for the first element with a .dll
1644 extension, and use that for the remainder of the
1646 pnt = strrchr (is3->the_bfd->filename, '.');
1647 if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
1655 /* OK, found one. Now look to see if the remaining
1656 (dynamic import) members use the same name. */
1658 is2 && is2->the_bfd->my_archive == arch;
1659 is2 = (lang_input_statement_type *) is2->next)
1661 /* Skip static members, ie anything with a .obj
1663 pnt = strrchr (is2->the_bfd->filename, '.');
1664 if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
1667 if (filename_cmp (is3->the_bfd->filename,
1668 is2->the_bfd->filename))
1677 /* This fragment might have come from an .obj file in a Microsoft
1678 import, and not an actual import record. If this is the case,
1679 then leave the filename alone. */
1680 pnt = strrchr (is->the_bfd->filename, '.');
1682 if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
1684 int idata2 = 0, reloc_count=0;
1686 char *new_name, seq;
1688 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1690 if (strcmp (sec->name, ".idata\$2") == 0)
1692 reloc_count += sec->reloc_count;
1695 if (idata2) /* .idata2 is the TOC */
1697 else if (reloc_count > 0) /* thunks */
1702 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1703 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1704 is->the_bfd->filename = new_name;
1706 new_name = xmalloc (strlen (is->filename) + 3);
1707 sprintf (new_name, "%s.%c", is->filename, seq);
1708 is->filename = new_name;
1716 gld_${EMULATION_NAME}_before_allocation (void)
1719 before_allocation_default ();
1723 /* This is called when an input file isn't recognized as a BFD. We
1724 check here for .DEF files and pull them in automatically. */
1727 saw_option (char *option)
1733 for (i = 0; init[i].ptr; i++)
1734 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1735 return init[i].inited;
1738 #endif /* DLL_SUPPORT */
1741 gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1744 const char *ext = entry->filename + strlen (entry->filename) - 4;
1746 if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
1748 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1752 int i, buflen=0, len;
1755 for (i = 0; i < pep_def_file->num_exports; i++)
1757 len = strlen (pep_def_file->exports[i].internal_name);
1758 if (buflen < len + 2)
1762 buf = xmalloc (buflen);
1764 for (i = 0; i < pep_def_file->num_exports; i++)
1766 struct bfd_link_hash_entry *h;
1768 sprintf (buf, "%s%s", U (""),
1769 pep_def_file->exports[i].internal_name);
1771 h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
1772 if (h == (struct bfd_link_hash_entry *) NULL)
1773 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1774 if (h->type == bfd_link_hash_new)
1776 h->type = bfd_link_hash_undefined;
1777 h->u.undef.abfd = NULL;
1778 bfd_link_add_undef (link_info.hash, h);
1783 /* def_file_print (stdout, pep_def_file); */
1784 if (pep_def_file->is_dll == 1)
1785 link_info.type = type_dll;
1787 if (pep_def_file->base_address != (bfd_vma)(-1))
1790 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1791 = init[IMAGEBASEOFF].value
1792 = pep_def_file->base_address;
1793 init[IMAGEBASEOFF].inited = 1;
1794 if (image_base_statement)
1795 image_base_statement->exp
1796 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1800 if (pep_def_file->stack_reserve != -1
1801 && ! saw_option ("__size_of_stack_reserve__"))
1803 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1804 if (pep_def_file->stack_commit != -1)
1805 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1807 if (pep_def_file->heap_reserve != -1
1808 && ! saw_option ("__size_of_heap_reserve__"))
1810 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1811 if (pep_def_file->heap_commit != -1)
1812 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1822 gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1826 #ifdef TARGET_IS_i386pep
1827 pep_dll_id_target ("pei-x86-64");
1829 if (pep_bfd_is_dll (entry->the_bfd))
1830 return pep_implied_import_dll (entry->filename);
1836 gld_${EMULATION_NAME}_finish (void)
1842 if (bfd_link_pic (&link_info)
1843 || (!bfd_link_relocatable (&link_info)
1844 && pep_def_file->num_exports != 0))
1846 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1847 if (command_line.out_implib_filename)
1848 pep_dll_generate_implib (pep_def_file,
1849 command_line.out_implib_filename, &link_info);
1852 if (pep_out_def_filename)
1853 pep_dll_generate_def_file (pep_out_def_filename);
1854 #endif /* DLL_SUPPORT */
1856 /* I don't know where .idata gets set as code, but it shouldn't be. */
1858 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1862 asec->flags &= ~SEC_CODE;
1863 asec->flags |= SEC_DATA;
1869 /* Place an orphan section.
1871 We use this to put sections in a reasonable place in the file, and
1872 to ensure that they are aligned as required.
1874 We handle grouped sections here as well. A section named .foo\$nn
1875 goes into the output section .foo. All grouped sections are sorted
1878 Grouped sections for the default sections are handled by the
1879 default linker script using wildcards, and are sorted by
1882 static lang_output_section_statement_type *
1883 gld_${EMULATION_NAME}_place_orphan (asection *s,
1884 const char *secname,
1887 const char *orig_secname = secname;
1888 char *dollar = NULL;
1889 lang_output_section_statement_type *os;
1890 lang_statement_list_type add_child;
1891 lang_output_section_statement_type *match_by_name = NULL;
1892 lang_statement_union_type **pl;
1894 /* Look through the script to see where to place this section. */
1895 if (!bfd_link_relocatable (&link_info)
1896 && (dollar = strchr (secname, '\$')) != NULL)
1898 size_t len = dollar - secname;
1899 char *newname = xmalloc (len + 1);
1900 memcpy (newname, secname, len);
1901 newname[len] = '\0';
1905 lang_list_init (&add_child);
1908 if (constraint == 0)
1909 for (os = lang_output_section_find (secname);
1911 os = next_matching_output_section_statement (os, 0))
1913 /* If we don't match an existing output section, tell
1914 lang_insert_orphan to create a new output section. */
1915 constraint = SPECIAL;
1917 if (os->bfd_section != NULL
1918 && (os->bfd_section->flags == 0
1919 || ((s->flags ^ os->bfd_section->flags)
1920 & (SEC_LOAD | SEC_ALLOC)) == 0))
1922 /* We already have an output section statement with this
1923 name, and its bfd section has compatible flags.
1924 If the section already exists but does not have any flags set,
1925 then it has been created by the linker, probably as a result of
1926 a --section-start command line switch. */
1927 lang_add_section (&add_child, s, NULL, os);
1931 /* Save unused output sections in case we can match them
1932 against orphans later. */
1933 if (os->bfd_section == NULL)
1937 /* If we didn't match an active output section, see if we matched an
1938 unused one and use that. */
1939 if (os == NULL && match_by_name)
1941 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
1942 return match_by_name;
1947 static struct orphan_save hold[] =
1950 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1953 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1956 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1959 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1965 enum orphan_save_index
1973 static int orphan_init_done = 0;
1974 struct orphan_save *place;
1975 lang_output_section_statement_type *after;
1976 etree_type *address;
1980 if (!orphan_init_done)
1982 struct orphan_save *ho;
1983 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1984 if (ho->name != NULL)
1986 ho->os = lang_output_section_find (ho->name);
1987 if (ho->os != NULL && ho->os->flags == 0)
1988 ho->os->flags = ho->flags;
1990 orphan_init_done = 1;
1994 if (!bfd_link_relocatable (&link_info))
1997 while ((nexts = bfd_get_next_section_by_name (nexts->owner,
1999 if (nexts->output_section == NULL
2000 && (nexts->flags & SEC_EXCLUDE) == 0
2001 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2002 && (nexts->owner->flags & DYNAMIC) == 0
2003 && nexts->owner->usrdata != NULL
2004 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2006 flags = (((flags ^ SEC_READONLY)
2007 | (nexts->flags ^ SEC_READONLY))
2011 /* Try to put the new output section in a reasonable place based
2012 on the section name and section flags. */
2015 if ((flags & SEC_ALLOC) == 0)
2017 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2018 place = &hold[orphan_bss];
2019 else if ((flags & SEC_READONLY) == 0)
2020 place = &hold[orphan_data];
2021 else if ((flags & SEC_CODE) == 0)
2023 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2024 : &hold[orphan_rodata]);
2027 place = &hold[orphan_text];
2032 if (place->os == NULL)
2033 place->os = lang_output_section_find (place->name);
2036 after = lang_output_section_find_by_flags (s, flags, &place->os,
2039 /* *ABS* is always the first output section statement. */
2040 after = (&lang_output_section_statement.head
2041 ->output_section_statement);
2044 /* All sections in an executable must be aligned to a page boundary.
2045 In a relocatable link, just preserve the incoming alignment; the
2046 address is discarded by lang_insert_orphan in that case, anyway. */
2047 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
2048 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2050 if (bfd_link_relocatable (&link_info))
2052 os->section_alignment = s->alignment_power;
2053 os->bfd_section->alignment_power = s->alignment_power;
2057 /* If the section name has a '\$', sort it with the other '\$'
2059 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2061 lang_input_section_type *ls;
2064 if ((*pl)->header.type != lang_input_section_enum)
2067 ls = &(*pl)->input_section;
2069 lname = bfd_get_section_name (ls->section->owner, ls->section);
2070 if (strchr (lname, '\$') != NULL
2071 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2075 if (add_child.head != NULL)
2077 *add_child.tail = *pl;
2078 *pl = add_child.head;
2085 gld_${EMULATION_NAME}_open_dynamic_archive
2086 (const char *arch ATTRIBUTE_UNUSED,
2087 search_dirs_type *search,
2088 lang_input_statement_type *entry)
2092 const char * format;
2093 bfd_boolean use_prefix;
2097 /* Preferred explicit import library for dll's. */
2098 { "lib%s.dll.a", FALSE },
2099 /* Alternate explicit import library for dll's. */
2100 { "%s.dll.a", FALSE },
2101 /* "libfoo.a" could be either an import lib or a static lib.
2102 For backwards compatibility, libfoo.a needs to precede
2103 libfoo.dll and foo.dll in the search. */
2104 { "lib%s.a", FALSE },
2105 /* The 'native' spelling of an import lib name is "foo.lib". */
2106 { "%s.lib", FALSE },
2108 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2109 { "%s%s.dll", TRUE },
2111 /* Try "libfoo.dll" (default preferred dll name). */
2112 { "lib%s.dll", FALSE },
2113 /* Finally try 'native' dll name "foo.dll". */
2114 { "%s.dll", FALSE },
2115 /* Note: If adding more formats to this table, make sure to check to
2116 see if their length is longer than libname_fmt[0].format, and if
2117 so, update the call to xmalloc() below. */
2120 static unsigned int format_max_len = 0;
2121 const char * filename;
2127 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
2130 filename = entry->filename;
2132 if (format_max_len == 0)
2133 /* We need to allow space in the memory that we are going to allocate
2134 for the characters in the format string. Since the format array is
2135 static we only need to calculate this information once. In theory
2136 this value could also be computed statically, but this introduces
2137 the possibility for a discrepancy and hence a possible memory
2138 corruption. The lengths we compute here will be too long because
2139 they will include any formating characters (%s) in the strings, but
2140 this will not matter. */
2141 for (i = 0; libname_fmt[i].format; i++)
2142 if (format_max_len < strlen (libname_fmt[i].format))
2143 format_max_len = strlen (libname_fmt[i].format);
2145 full_string = xmalloc (strlen (search->name)
2149 + (pep_dll_search_prefix
2150 ? strlen (pep_dll_search_prefix) : 0)
2152 /* Allow for the terminating NUL and for the path
2153 separator character that is inserted between
2154 search->name and the start of the format string. */
2157 sprintf (full_string, "%s/", search->name);
2158 base_string = full_string + strlen (full_string);
2160 for (i = 0; libname_fmt[i].format; i++)
2163 if (libname_fmt[i].use_prefix)
2165 if (!pep_dll_search_prefix)
2167 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2171 sprintf (base_string, libname_fmt[i].format, filename);
2173 if (ldfile_try_open_bfd (full_string, entry))
2177 if (!libname_fmt[i].format)
2183 entry->filename = full_string;
2189 gld_${EMULATION_NAME}_find_potential_libraries
2190 (char *name, lang_input_statement_type *entry)
2192 return ldfile_open_file_search (name, entry, "", ".lib");
2196 gld_${EMULATION_NAME}_get_script (int *isfile)
2198 # Scripts compiled in.
2199 # sed commands to quote an ld script as a C string.
2200 sc="-f stringify.sed"
2206 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2209 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2210 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2211 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2212 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2213 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2214 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2215 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2216 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2217 echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
2218 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2220 echo ' ; else return' >> e${EMULATION_NAME}.c
2221 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2222 echo '; }' >> e${EMULATION_NAME}.c
2227 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2229 gld_${EMULATION_NAME}_before_parse,
2232 gld_${EMULATION_NAME}_after_parse,
2233 gld_${EMULATION_NAME}_after_open,
2234 after_allocation_default,
2235 set_output_arch_default,
2236 ldemul_default_target,
2237 gld_${EMULATION_NAME}_before_allocation,
2238 gld_${EMULATION_NAME}_get_script,
2239 "${EMULATION_NAME}",
2241 gld_${EMULATION_NAME}_finish,
2242 NULL, /* Create output section statements. */
2243 gld_${EMULATION_NAME}_open_dynamic_archive,
2244 gld_${EMULATION_NAME}_place_orphan,
2245 gld_${EMULATION_NAME}_set_symbols,
2246 NULL, /* parse_args */
2247 gld${EMULATION_NAME}_add_options,
2248 gld${EMULATION_NAME}_handle_option,
2249 gld_${EMULATION_NAME}_unrecognized_file,
2250 gld_${EMULATION_NAME}_list_options,
2251 gld_${EMULATION_NAME}_recognized_file,
2252 gld_${EMULATION_NAME}_find_potential_libraries,
2253 NULL, /* new_vers_pattern. */
2254 NULL /* extra_map_file_text */