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-2015 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 char * pep_implib_filename = NULL;
157 static int pep_enable_auto_image_base = 0;
158 static char * pep_dll_search_prefix = NULL;
161 extern const char *output_filename;
163 static int is_underscoring (void)
166 if (pep_leading_underscore != -1)
167 return pep_leading_underscore;
168 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
169 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
173 pep_leading_underscore = (u != 0 ? 1 : 0);
174 return pep_leading_underscore;
179 gld_${EMULATION_NAME}_before_parse (void)
182 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
183 output_filename = "${EXECUTABLE_NAME:-a.exe}";
185 input_flags.dynamic = TRUE;
186 config.has_shared = 1;
187 link_info.pei386_auto_import = 1;
188 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
192 /* PE format extra command line options. */
194 /* Used for setting flags in the PE header. */
197 OPTION_BASE_FILE = 300 + 1,
199 OPTION_FILE_ALIGNMENT,
201 OPTION_MAJOR_IMAGE_VERSION,
202 OPTION_MAJOR_OS_VERSION,
203 OPTION_MAJOR_SUBSYSTEM_VERSION,
204 OPTION_MINOR_IMAGE_VERSION,
205 OPTION_MINOR_OS_VERSION,
206 OPTION_MINOR_SUBSYSTEM_VERSION,
207 OPTION_SECTION_ALIGNMENT,
211 OPTION_SUPPORT_OLD_CODE,
214 OPTION_EXCLUDE_SYMBOLS,
215 OPTION_EXCLUDE_ALL_SYMBOLS,
217 OPTION_STDCALL_ALIASES,
218 OPTION_ENABLE_STDCALL_FIXUP,
219 OPTION_DISABLE_STDCALL_FIXUP,
220 OPTION_IMPLIB_FILENAME,
221 OPTION_WARN_DUPLICATE_EXPORTS,
223 OPTION_ENABLE_AUTO_IMAGE_BASE,
224 OPTION_DISABLE_AUTO_IMAGE_BASE,
225 OPTION_DLL_SEARCH_PREFIX,
226 OPTION_NO_DEFAULT_EXCLUDES,
227 OPTION_DLL_ENABLE_AUTO_IMPORT,
228 OPTION_DLL_DISABLE_AUTO_IMPORT,
229 OPTION_ENABLE_EXTRA_PE_DEBUG,
231 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
232 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
233 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
234 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
235 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
236 OPTION_NO_LEADING_UNDERSCORE,
237 OPTION_LEADING_UNDERSCORE,
238 OPTION_ENABLE_LONG_SECTION_NAMES,
239 OPTION_DISABLE_LONG_SECTION_NAMES,
240 OPTION_HIGH_ENTROPY_VA,
242 OPTION_FORCE_INTEGRITY,
248 OPTION_INSERT_TIMESTAMP,
249 OPTION_NO_INSERT_TIMESTAMP,
250 OPTION_TERMINAL_SERVER_AWARE,
255 gld${EMULATION_NAME}_add_options
256 (int ns ATTRIBUTE_UNUSED,
257 char **shortopts ATTRIBUTE_UNUSED,
259 struct option **longopts,
260 int nrl ATTRIBUTE_UNUSED,
261 struct option **really_longopts ATTRIBUTE_UNUSED)
263 static const struct option xtra_long[] =
266 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
267 {"dll", no_argument, NULL, OPTION_DLL},
268 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
269 {"heap", required_argument, NULL, OPTION_HEAP},
270 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
271 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
272 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
273 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
274 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
275 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
276 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
277 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
278 {"stack", required_argument, NULL, OPTION_STACK},
279 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
280 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
281 {"use-nul-prefixed-import-tables", no_argument, NULL,
282 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
283 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
284 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
286 /* getopt allows abbreviations, so we do this to stop it
287 from treating -o as an abbreviation for this option. */
288 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
289 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
290 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
291 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
292 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
293 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
294 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
295 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
296 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
297 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
298 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
299 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
300 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
301 /* getopt() allows abbreviations, so we do this to stop it from
302 treating -c as an abbreviation for these --compat-implib. */
303 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
304 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
305 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
306 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
307 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
308 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
309 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
310 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
311 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
312 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
313 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
314 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
316 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
317 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
318 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
319 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
320 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
321 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
322 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
323 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
324 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
325 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
326 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
327 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
328 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
329 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
330 {NULL, no_argument, NULL, 0}
334 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
335 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
338 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
339 parameters which may be input from the command line. */
348 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
349 C visible symbols can be prefixed by underscore dependent on target's
351 bfd_boolean is_c_symbol;
354 #define GET_INIT_SYMBOL_NAME(IDX) \
355 (init[(IDX)].symbol \
356 + ((init[(IDX)].is_c_symbol == FALSE || (is_underscoring () == 1)) ? 0 : 1))
358 /* Decorates the C visible symbol by underscore, if target requires. */
360 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
362 /* Get size of constant string for a possible underscore prefixed
364 #define U_SIZE(CSTR) \
365 (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
367 #define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
369 static definfo init[] =
371 /* imagebase must be first */
372 #define IMAGEBASEOFF 0
373 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, FALSE),
375 {&dll, sizeof(dll), 0, "__dll__", 0, FALSE},
376 #define MSIMAGEBASEOFF 2
377 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, TRUE),
378 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, FALSE),
379 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, FALSE),
380 D(MajorOperatingSystemVersion,"__major_os_version__", 4, FALSE),
381 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, FALSE),
382 D(MajorImageVersion,"__major_image_version__", 0, FALSE),
383 D(MinorImageVersion,"__minor_image_version__", 0, FALSE),
384 D(MajorSubsystemVersion,"__major_subsystem_version__", 5, FALSE),
385 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2, FALSE),
386 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, FALSE),
387 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, FALSE),
388 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, FALSE),
389 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, FALSE),
390 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, FALSE),
391 D(LoaderFlags,"__loader_flags__", 0x0, FALSE),
392 D(DllCharacteristics, "__dll_characteristics__", 0x0, FALSE),
393 { NULL, 0, 0, NULL, 0, FALSE}
398 gld_${EMULATION_NAME}_list_options (FILE *file)
400 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
401 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
402 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
403 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
404 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
405 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
406 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
407 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
408 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
409 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
410 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
411 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
412 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
413 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
414 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
415 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
416 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero. (default)\n"));
417 fprintf (file, _(" This makes binaries non-deterministic\n"));
419 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
420 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
421 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
422 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
423 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
424 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
425 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
426 fprintf (file, _(" Exclude objects, archive members from auto\n"));
427 fprintf (file, _(" export, place into import library instead.\n"));
428 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
429 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
430 fprintf (file, _(" --out-implib <file> Generate import library\n"));
431 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
432 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
433 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
434 create __imp_<SYMBOL> as well.\n"));
435 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
436 unless user specifies one\n"));
437 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
438 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
439 an importlib, use <string><basename>.dll\n\
440 in preference to lib<basename>.dll \n"));
441 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
442 __imp_sym for DATA references\n"));
443 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
444 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
445 adding pseudo-relocations resolved at\n\
447 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
448 auto-imported DATA.\n"));
449 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
450 or linking to DLLs (esp. auto-import)\n"));
451 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
452 executable image files\n"));
453 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
454 in object files\n"));
455 fprintf (file, _(" --high-entropy-va Image is compatible with 64-bit address space\n\
456 layout randomization (ASLR)\n"));
457 fprintf (file, _(" --dynamicbase Image base address may be relocated using\n\
458 address space layout randomization (ASLR)\n"));
459 fprintf (file, _(" --forceinteg Code integrity checks are enforced\n"));
460 fprintf (file, _(" --nxcompat Image is compatible with data execution prevention\n"));
461 fprintf (file, _(" --no-isolation Image understands isolation but do not isolate the image\n"));
462 fprintf (file, _(" --no-seh Image does not use SEH. No SE handler may\n\
463 be called in this image\n"));
464 fprintf (file, _(" --no-bind Do not bind this image\n"));
465 fprintf (file, _(" --wdmdriver Driver uses the WDM model\n"));
466 fprintf (file, _(" --tsaware Image is Terminal Server aware\n"));
467 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
473 set_pep_name (char *name, bfd_vma val)
477 /* Find the name and set it. */
478 for (i = 0; init[i].ptr; i++)
480 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
484 if (strcmp (name,"__image_base__") == 0)
485 set_pep_name (U ("__ImageBase"), val);
493 set_entry_point (void)
496 const char *initial_symbol_char;
506 { 1, "NtProcessStartup" },
507 { 2, "WinMainCRTStartup" },
508 { 3, "mainCRTStartup" },
509 { 7, "__PosixProcessStartup" },
510 { 9, "WinMainCRTStartup" },
511 {14, "mainCRTStartup" },
515 /* Entry point name for arbitrary subsystem numbers. */
516 static const char default_entry[] = "mainCRTStartup";
518 if (link_info.shared || dll)
520 entry = "DllMainCRTStartup";
524 for (i = 0; v[i].entry; i++)
525 if (v[i].value == pep_subsystem)
528 /* If no match, use the default. */
529 if (v[i].entry != NULL)
532 entry = default_entry;
535 /* Now we check target's default for getting proper symbol_char. */
536 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
538 if (*initial_symbol_char != '\0')
542 /* lang_default_entry expects its argument to be permanently
543 allocated, so we don't free this string. */
544 alc_entry = xmalloc (strlen (initial_symbol_char)
547 strcpy (alc_entry, initial_symbol_char);
548 strcat (alc_entry, entry);
552 lang_default_entry (entry);
556 set_pep_subsystem (void)
562 unsigned long temp_subsystem;
579 /* Check for the presence of a version number. */
580 sver = strchr (optarg, ':');
582 len = strlen (optarg);
586 set_pep_name ("__major_subsystem_version__",
587 strtoul (sver + 1, &end, 0));
589 set_pep_name ("__minor_subsystem_version__",
590 strtoul (end + 1, &end, 0));
592 einfo (_("%P: warning: bad version number in -subsystem option\n"));
595 /* Check for numeric subsystem. */
596 temp_subsystem = strtoul (optarg, & end, 0);
597 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
599 /* Search list for a numeric match to use its entry point. */
600 for (i = 0; v[i].name; i++)
601 if (v[i].value == (int) temp_subsystem)
604 /* Use this subsystem. */
605 pep_subsystem = (int) temp_subsystem;
609 /* Search for subsystem by name. */
610 for (i = 0; v[i].name; i++)
611 if (strncmp (optarg, v[i].name, len) == 0
612 && v[i].name[len] == '\0')
615 if (v[i].name == NULL)
617 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
621 pep_subsystem = v[i].value;
624 set_pep_name ("__subsystem__", pep_subsystem);
631 set_pep_value (char *name)
635 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
638 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
645 set_pep_stack_heap (char *resname, char *comname)
647 set_pep_value (resname);
652 set_pep_value (comname);
655 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
658 #define DEFAULT_BUILD_ID_STYLE "md5"
661 gld${EMULATION_NAME}_handle_option (int optc)
669 case OPTION_BASE_FILE:
670 link_info.base_file = fopen (optarg, FOPEN_WB);
671 if (link_info.base_file == NULL)
672 einfo (_("%F%P: cannot open base file %s\n"), optarg);
677 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
680 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
682 case OPTION_SUBSYSTEM:
683 set_pep_subsystem ();
685 case OPTION_MAJOR_OS_VERSION:
686 set_pep_value ("__major_os_version__");
688 case OPTION_MINOR_OS_VERSION:
689 set_pep_value ("__minor_os_version__");
691 case OPTION_MAJOR_SUBSYSTEM_VERSION:
692 set_pep_value ("__major_subsystem_version__");
694 case OPTION_MINOR_SUBSYSTEM_VERSION:
695 set_pep_value ("__minor_subsystem_version__");
697 case OPTION_MAJOR_IMAGE_VERSION:
698 set_pep_value ("__major_image_version__");
700 case OPTION_MINOR_IMAGE_VERSION:
701 set_pep_value ("__minor_image_version__");
703 case OPTION_FILE_ALIGNMENT:
704 set_pep_value ("__file_alignment__");
706 case OPTION_SECTION_ALIGNMENT:
707 set_pep_value ("__section_alignment__");
710 set_pep_name ("__dll__", 1);
712 case OPTION_IMAGE_BASE:
713 set_pep_value ("__image_base__");
715 case OPTION_SUPPORT_OLD_CODE:
716 support_old_code = 1;
718 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
719 pep_use_nul_prefixed_import_tables = TRUE;
721 case OPTION_NO_LEADING_UNDERSCORE:
722 pep_leading_underscore = 0;
724 case OPTION_LEADING_UNDERSCORE:
725 pep_leading_underscore = 1;
727 case OPTION_INSERT_TIMESTAMP:
728 insert_timestamp = TRUE;
730 case OPTION_NO_INSERT_TIMESTAMP:
731 insert_timestamp = FALSE;
735 pep_out_def_filename = xstrdup (optarg);
737 case OPTION_EXPORT_ALL:
738 pep_dll_export_everything = 1;
740 case OPTION_EXCLUDE_SYMBOLS:
741 pep_dll_add_excludes (optarg, EXCLUDESYMS);
743 case OPTION_EXCLUDE_ALL_SYMBOLS:
744 pep_dll_exclude_all_symbols = 1;
746 case OPTION_EXCLUDE_LIBS:
747 pep_dll_add_excludes (optarg, EXCLUDELIBS);
749 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
750 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
752 case OPTION_KILL_ATS:
753 pep_dll_kill_ats = 1;
755 case OPTION_STDCALL_ALIASES:
756 pep_dll_stdcall_aliases = 1;
758 case OPTION_ENABLE_STDCALL_FIXUP:
759 pep_enable_stdcall_fixup = 1;
761 case OPTION_DISABLE_STDCALL_FIXUP:
762 pep_enable_stdcall_fixup = 0;
764 case OPTION_IMPLIB_FILENAME:
765 pep_implib_filename = xstrdup (optarg);
767 case OPTION_WARN_DUPLICATE_EXPORTS:
768 pep_dll_warn_dup_exports = 1;
770 case OPTION_IMP_COMPAT:
771 pep_dll_compat_implib = 1;
773 case OPTION_ENABLE_AUTO_IMAGE_BASE:
774 pep_enable_auto_image_base = 1;
776 case OPTION_DISABLE_AUTO_IMAGE_BASE:
777 pep_enable_auto_image_base = 0;
779 case OPTION_DLL_SEARCH_PREFIX:
780 pep_dll_search_prefix = xstrdup (optarg);
782 case OPTION_NO_DEFAULT_EXCLUDES:
783 pep_dll_do_default_excludes = 0;
785 case OPTION_DLL_ENABLE_AUTO_IMPORT:
786 link_info.pei386_auto_import = 1;
788 case OPTION_DLL_DISABLE_AUTO_IMPORT:
789 link_info.pei386_auto_import = 0;
791 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
792 link_info.pei386_runtime_pseudo_reloc = 2;
794 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
795 link_info.pei386_runtime_pseudo_reloc = 0;
797 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
798 link_info.pei386_runtime_pseudo_reloc = 2;
800 case OPTION_ENABLE_EXTRA_PE_DEBUG:
801 pep_dll_extra_pe_debug = 1;
804 case OPTION_ENABLE_LONG_SECTION_NAMES:
805 pep_use_coff_long_section_names = 1;
807 case OPTION_DISABLE_LONG_SECTION_NAMES:
808 pep_use_coff_long_section_names = 0;
810 /* Get DLLCharacteristics bits */
811 case OPTION_HIGH_ENTROPY_VA:
812 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
814 case OPTION_DYNAMIC_BASE:
815 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
817 case OPTION_FORCE_INTEGRITY:
818 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
820 case OPTION_NX_COMPAT:
821 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
823 case OPTION_NO_ISOLATION:
824 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
827 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
830 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
832 case OPTION_WDM_DRIVER:
833 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
835 case OPTION_TERMINAL_SERVER_AWARE:
836 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
838 case OPTION_BUILD_ID:
839 if (emit_build_id != NULL)
841 free ((char *) emit_build_id);
842 emit_build_id = NULL;
845 optarg = DEFAULT_BUILD_ID_STYLE;
846 if (strcmp (optarg, "none"))
847 emit_build_id = xstrdup (optarg);
851 /* Set DLLCharacteristics bits */
852 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
860 strhash (const char *str)
862 const unsigned char *s;
869 s = (const unsigned char *) str;
870 while ((c = *s++) != '\0')
872 hash += c + (c << 17);
876 hash += len + (len << 17);
882 /* Use the output file to create a image base for relocatable DLLs. */
885 compute_dll_image_base (const char *ofile)
887 bfd_vma hash = (bfd_vma) strhash (ofile);
888 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
892 /* Assign values to the special symbols before the linker script is
896 gld_${EMULATION_NAME}_set_symbols (void)
898 /* Run through and invent symbols for all the
899 names and insert the defaults. */
904 if (!init[IMAGEBASEOFF].inited)
906 if (link_info.relocatable)
907 init[IMAGEBASEOFF].value = 0;
908 else if (init[DLLOFF].value || (link_info.shared && !link_info.pie))
911 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
912 ? compute_dll_image_base (output_filename)
913 : NT_DLL_IMAGE_BASE);
915 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
919 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
920 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
923 /* Don't do any symbol assignments if this is a relocatable link. */
924 if (link_info.relocatable)
927 /* Glue the assignments into the abs section. */
928 push_stat_ptr (&abs_output_section->children);
930 for (j = 0; init[j].ptr; j++)
932 bfd_vma val = init[j].value;
933 lang_assignment_statement_type *rv;
935 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
936 exp_intop (val), FALSE));
937 if (init[j].size == sizeof (short))
938 *(short *) init[j].ptr = (short) val;
939 else if (init[j].size == sizeof (int))
940 *(int *) init[j].ptr = (int) val;
941 else if (init[j].size == sizeof (long))
942 *(long *) init[j].ptr = (long) val;
943 /* This might be a long long or other special type. */
944 else if (init[j].size == sizeof (bfd_vma))
945 *(bfd_vma *) init[j].ptr = val;
947 if (j == IMAGEBASEOFF)
948 image_base_statement = rv;
950 /* Restore the pointer. */
953 if (pep.FileAlignment > pep.SectionAlignment)
955 einfo (_("%P: warning, file alignment > section alignment.\n"));
959 /* This is called after the linker script and the command line options
963 gld_${EMULATION_NAME}_after_parse (void)
965 /* PR ld/6744: Warn the user if they have used an ELF-only
966 option hoping it will work on PE+. */
967 if (link_info.export_dynamic)
968 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
969 "targets, did you mean --export-all-symbols?\n"));
973 after_parse_default ();
976 /* pep-dll.c directly accesses pep_data_import_dll,
977 so it must be defined outside of #ifdef DLL_SUPPORT.
978 Note - this variable is deliberately not initialised.
979 This allows it to be treated as a common varaible, and only
980 exist in one incarnation in a multiple target enabled linker. */
981 char * pep_data_import_dll;
984 static struct bfd_link_hash_entry *pep_undef_found_sym;
987 pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
991 const char *hs = h->root.string;
993 sl = strlen (string);
994 if (h->type == bfd_link_hash_defined
995 && ((*hs == '@' && *string == '_'
996 && strncmp (hs + 1, string + 1, sl - 1) == 0)
997 || strncmp (hs, string, sl) == 0)
998 && h->root.string[sl] == '@')
1000 pep_undef_found_sym = h;
1007 pep_fixup_stdcalls (void)
1009 static int gave_warning_message = 0;
1010 struct bfd_link_hash_entry *undef, *sym;
1012 if (pep_dll_extra_pe_debug)
1013 printf ("%s\n", __FUNCTION__);
1015 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1016 if (undef->type == bfd_link_hash_undefined)
1018 char* at = strchr (undef->root.string, '@');
1019 int lead_at = (*undef->root.string == '@');
1021 at = strchr (undef->root.string + 1, '@');
1024 /* The symbol is a stdcall symbol, so let's look for a
1025 cdecl symbol with the same name and resolve to that. */
1026 char *cname = xstrdup (undef->root.string);
1030 at = strchr (cname, '@');
1033 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1035 if (sym && sym->type == bfd_link_hash_defined)
1037 undef->type = bfd_link_hash_defined;
1038 undef->u.def.value = sym->u.def.value;
1039 undef->u.def.section = sym->u.def.section;
1041 if (pep_enable_stdcall_fixup == -1)
1043 einfo (_("Warning: resolving %s by linking to %s\n"),
1044 undef->root.string, cname);
1045 if (! gave_warning_message)
1047 gave_warning_message = 1;
1048 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1049 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1056 /* The symbol is a cdecl symbol, so we look for stdcall
1057 symbols - which means scanning the whole symbol table. */
1058 pep_undef_found_sym = 0;
1059 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
1060 (char *) undef->root.string);
1061 sym = pep_undef_found_sym;
1064 undef->type = bfd_link_hash_defined;
1065 undef->u.def.value = sym->u.def.value;
1066 undef->u.def.section = sym->u.def.section;
1068 if (pep_enable_stdcall_fixup == -1)
1070 einfo (_("Warning: resolving %s by linking to %s\n"),
1071 undef->root.string, sym->root.string);
1072 if (! gave_warning_message)
1074 gave_warning_message = 1;
1075 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1076 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1085 make_import_fixup (arelent *rel, asection *s)
1087 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1089 bfd_vma _addend = 0;
1092 if (pep_dll_extra_pe_debug)
1093 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1094 (unsigned long) rel->address, (long) rel->addend);
1096 memset (addend, 0, sizeof (addend));
1097 switch ((rel->howto->bitsize))
1100 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 1);
1101 if (suc && rel->howto->pc_relative)
1102 _addend = (bfd_vma) ((bfd_signed_vma) ((char) bfd_get_8 (s->owner, addend)));
1104 _addend = ((bfd_vma) bfd_get_8 (s->owner, addend)) & 0xff;
1107 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 2);
1108 if (suc && rel->howto->pc_relative)
1109 _addend = (bfd_vma) ((bfd_signed_vma) ((short) bfd_get_16 (s->owner, addend)));
1111 _addend = ((bfd_vma) bfd_get_16 (s->owner, addend)) & 0xffff;
1114 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
1115 if (suc && rel->howto->pc_relative)
1116 _addend = (bfd_vma) ((bfd_signed_vma) ((int) bfd_get_32 (s->owner, addend)));
1118 _addend = ((bfd_vma) bfd_get_32 (s->owner, addend)) & 0xffffffff;
1121 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
1123 _addend = ((bfd_vma) bfd_get_64 (s->owner, addend));
1127 einfo (_("%C: Cannot get section contents - auto-import exception\n"),
1128 s->owner, s, rel->address);
1130 if (pep_dll_extra_pe_debug)
1132 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx", (long) _addend, (long) rel->addend, (long) rel->address);
1133 if (rel->howto->pc_relative) printf (" pcrel");
1134 printf (" %d bit rel.\n",(int) rel->howto->bitsize);
1136 pep_create_import_fixup (rel, s, _addend);
1142 pep_find_data_imports (void)
1144 struct bfd_link_hash_entry *undef, *sym;
1146 if (link_info.pei386_auto_import == 0)
1149 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1151 if (undef->type == bfd_link_hash_undefined)
1153 /* C++ symbols are *long*. */
1156 if (pep_dll_extra_pe_debug)
1157 printf ("%s:%s\n", __FUNCTION__, undef->root.string);
1159 sprintf (buf, "__imp_%s", undef->root.string);
1161 sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
1163 if (sym && sym->type == bfd_link_hash_defined)
1165 bfd *b = sym->u.def.section->owner;
1169 if (!bfd_generic_link_read_symbols (b))
1171 einfo (_("%B%F: could not read symbols: %E\n"), b);
1175 symbols = bfd_get_outsymbols (b);
1176 nsyms = bfd_get_symcount (b);
1178 for (i = 0; i < nsyms; i++)
1180 if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
1183 if (pep_dll_extra_pe_debug)
1184 printf ("->%s\n", symbols[i]->name);
1186 pep_data_import_dll = (char*) (symbols[i]->name +
1187 U_SIZE ("_head_") - 1);
1191 pep_walk_relocs_of_symbol (&link_info, undef->root.string,
1194 /* Let's differentiate it somehow from defined. */
1195 undef->type = bfd_link_hash_defweak;
1196 /* We replace original name with __imp_ prefixed, this
1197 1) may trash memory 2) leads to duplicate symbol generation.
1198 Still, IMHO it's better than having name poluted. */
1199 undef->root.string = sym->root.string;
1200 undef->u.def.value = sym->u.def.value;
1201 undef->u.def.section = sym->u.def.section;
1208 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1210 printf ("+%s\n", h->string);
1214 #endif /* DLL_SUPPORT */
1217 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1219 int *found = (int *) obj;
1221 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1226 pecoff_checksum_contents (bfd *abfd,
1227 void (*process) (const void *, size_t, void *),
1230 file_ptr filepos = (file_ptr) 0;
1237 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1240 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1246 (*process) (&b, 1, arg);
1254 write_build_id (bfd *abfd)
1256 struct pe_tdata *t = pe_data (abfd);
1258 struct bfd_link_order *link_order = NULL;
1259 unsigned char *contents;
1261 bfd_size_type build_id_size;
1262 unsigned char *build_id;
1264 /* Find the section the .buildid output section has been merged info. */
1265 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1267 struct bfd_link_order *l = NULL;
1268 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1270 if ((l->type == bfd_indirect_link_order))
1272 if (l->u.indirect.section == t->build_id.sec)
1286 einfo (_("%P: warning: .buildid section discarded,"
1287 " --build-id ignored.\n"));
1291 if (t->build_id.sec->contents == NULL)
1292 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1293 contents = t->build_id.sec->contents;
1294 size = t->build_id.sec->size;
1296 build_id_size = compute_build_id_size (t->build_id.style);
1297 build_id = xmalloc (build_id_size);
1298 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1300 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1302 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1303 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1304 idd.Characteristics = 0;
1305 idd.TimeDateStamp = 0;
1306 idd.MajorVersion = 0;
1307 idd.MinorVersion = 0;
1308 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1309 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1310 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1311 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1312 idd.PointerToRawData = asec->filepos + link_order->offset
1313 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1315 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1316 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1318 /* Write the debug directory enttry */
1319 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1322 if ((bfd_bwrite (contents, size, abfd) != size))
1325 /* Construct the CodeView record. */
1326 CODEVIEW_INFO cvinfo;
1327 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1330 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1331 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1332 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1333 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1337 /* Write the codeview record. */
1338 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1341 /* Record the location of the debug directory in the data directory. */
1342 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1343 = asec->vma - ib + link_order->offset;
1344 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1345 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1350 /* Make .buildid section, and set up coff_tdata->build_id. */
1352 setup_build_id (bfd *ibfd)
1357 if (!validate_build_id_style (emit_build_id))
1359 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1363 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1364 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1365 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
1368 struct pe_tdata *t = pe_data (link_info.output_bfd);
1369 t->build_id.after_write_object_contents = &write_build_id;
1370 t->build_id.style = emit_build_id;
1371 t->build_id.sec = s;
1373 /* Section is a fixed size:
1374 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1375 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1376 null byte for PdbFileName. */
1377 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1378 + sizeof (CV_INFO_PDB70) + 1;
1383 einfo ("%P: warning: Cannot create .buildid section,"
1384 " --build-id ignored.\n");
1389 gld_${EMULATION_NAME}_after_open (void)
1391 after_open_default ();
1395 if (pep_dll_extra_pe_debug)
1398 struct bfd_link_hash_entry *sym;
1400 printf ("%s()\n", __FUNCTION__);
1402 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1403 printf ("-%s\n", sym->root.string);
1404 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1406 for (a = link_info.input_bfds; a; a = a->link.next)
1407 printf ("*%s\n",a->filename);
1411 if (emit_build_id != NULL)
1415 /* Find a COFF input. */
1416 for (abfd = link_info.input_bfds;
1417 abfd != (bfd *) NULL; abfd = abfd->link.next)
1418 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1421 /* If there are no COFF input files do not try to
1422 add a build-id section. */
1424 || !setup_build_id (abfd))
1426 free ((char *) emit_build_id);
1427 emit_build_id = NULL;
1431 /* Pass the wacky PE command line options into the output bfd.
1432 FIXME: This should be done via a function, rather than by
1433 including an internal BFD header. */
1435 if (coff_data (link_info.output_bfd) == NULL
1436 || coff_data (link_info.output_bfd)->pe == 0)
1437 einfo (_("%F%P: cannot perform PE operations on non PE output file '%B'.\n"),
1438 link_info.output_bfd);
1440 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1441 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1442 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1443 pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
1445 /* At this point we must decide whether to use long section names
1446 in the output or not. If the user hasn't explicitly specified
1447 on the command line, we leave it to the default for the format
1448 (object files yes, image files no), except if there is debug
1449 information present; GDB relies on the long section names to
1450 find it, so enable it in that case. */
1451 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1453 if (link_info.relocatable)
1454 pep_use_coff_long_section_names = 1;
1457 /* Iterate over all sections of all input BFDs, checking
1458 for any that begin 'debug_' and are long names. */
1459 LANG_FOR_EACH_INPUT_STATEMENT (is)
1461 int found_debug = 0;
1463 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1466 pep_use_coff_long_section_names = 1;
1473 pep_output_file_set_long_section_names (link_info.output_bfd);
1476 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1477 pep_fixup_stdcalls ();
1479 pep_process_import_defs (link_info.output_bfd, &link_info);
1481 pep_find_data_imports ();
1483 /* As possibly new symbols are added by imports, we rerun
1484 stdcall/fastcall fixup here. */
1485 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1486 pep_fixup_stdcalls ();
1488 #ifndef TARGET_IS_i386pep
1489 if (link_info.shared)
1491 if (!link_info.relocatable)
1493 pep_dll_build_sections (link_info.output_bfd, &link_info);
1495 #ifndef TARGET_IS_i386pep
1497 pep_exe_build_sections (link_info.output_bfd, &link_info);
1499 #endif /* DLL_SUPPORT */
1502 /* This next chunk of code tries to detect the case where you have
1503 two import libraries for the same DLL (specifically,
1504 symbolically linking libm.a and libc.a in cygwin to
1505 libcygwin.a). In those cases, it's possible for function
1506 thunks from the second implib to be used but without the
1507 head/tail objects, causing an improper import table. We detect
1508 those cases and rename the "other" import libraries to match
1509 the one the head/tail come from, so that the linker will sort
1510 things nicely and produce a valid import table. */
1512 LANG_FOR_EACH_INPUT_STATEMENT (is)
1514 if (is->the_bfd->my_archive)
1516 int idata2 = 0, reloc_count=0, is_imp = 0;
1519 /* See if this is an import library thunk. */
1520 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1522 if (strcmp (sec->name, ".idata\$2") == 0)
1524 if (CONST_STRNEQ (sec->name, ".idata\$"))
1526 reloc_count += sec->reloc_count;
1529 if (is_imp && !idata2 && reloc_count)
1531 /* It is, look for the reference to head and see if it's
1532 from our own library. */
1533 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1541 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1545 if (!bfd_generic_link_read_symbols (is->the_bfd))
1547 einfo (_("%B%F: could not read symbols: %E\n"),
1551 symbols = bfd_get_outsymbols (is->the_bfd);
1553 relocs = xmalloc ((size_t) relsize);
1554 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1559 einfo ("%X%P: unable to process relocs: %E\n");
1563 for (i = 0; i < nrelocs; i++)
1565 struct bfd_symbol *s;
1566 struct bfd_link_hash_entry * blhe;
1567 char *other_bfd_filename;
1570 s = (relocs[i]->sym_ptr_ptr)[0];
1572 if (s->flags & BSF_LOCAL)
1575 /* Thunk section with reloc to another bfd. */
1576 blhe = bfd_link_hash_lookup (link_info.hash,
1578 FALSE, FALSE, TRUE);
1581 || blhe->type != bfd_link_hash_defined)
1585 = blhe->u.def.section->owner->my_archive
1586 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1587 : bfd_get_filename (blhe->u.def.section->owner);
1589 if (filename_cmp (bfd_get_filename
1590 (is->the_bfd->my_archive),
1591 other_bfd_filename) == 0)
1594 /* Rename this implib to match the other one. */
1595 n = xmalloc (strlen (other_bfd_filename) + 1);
1596 strcpy (n, other_bfd_filename);
1597 is->the_bfd->my_archive->filename = n;
1601 /* Note - we do not free the symbols,
1602 they are now cached in the BFD. */
1612 lang_input_statement_type *is2;
1613 lang_input_statement_type *is3;
1615 /* Careful - this is a shell script. Watch those dollar signs! */
1616 /* Microsoft import libraries have every member named the same,
1617 and not in the right order for us to link them correctly. We
1618 must detect these and rename the members so that they'll link
1619 correctly. There are three types of objects: the head, the
1620 thunks, and the sentinel(s). The head is easy; it's the one
1621 with idata2. We assume that the sentinels won't have relocs,
1622 and the thunks will. It's easier than checking the symbol
1623 table for external references. */
1624 LANG_FOR_EACH_INPUT_STATEMENT (is)
1626 if (is->the_bfd->my_archive)
1629 bfd *arch = is->the_bfd->my_archive;
1631 if (cur_arch != arch)
1637 is3 && is3->the_bfd->my_archive == arch;
1638 is3 = (lang_input_statement_type *) is3->next)
1640 /* A MS dynamic import library can also contain static
1641 members, so look for the first element with a .dll
1642 extension, and use that for the remainder of the
1644 pnt = strrchr (is3->the_bfd->filename, '.');
1645 if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
1653 /* OK, found one. Now look to see if the remaining
1654 (dynamic import) members use the same name. */
1656 is2 && is2->the_bfd->my_archive == arch;
1657 is2 = (lang_input_statement_type *) is2->next)
1659 /* Skip static members, ie anything with a .obj
1661 pnt = strrchr (is2->the_bfd->filename, '.');
1662 if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
1665 if (filename_cmp (is3->the_bfd->filename,
1666 is2->the_bfd->filename))
1675 /* This fragment might have come from an .obj file in a Microsoft
1676 import, and not an actual import record. If this is the case,
1677 then leave the filename alone. */
1678 pnt = strrchr (is->the_bfd->filename, '.');
1680 if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
1682 int idata2 = 0, reloc_count=0;
1684 char *new_name, seq;
1686 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1688 if (strcmp (sec->name, ".idata\$2") == 0)
1690 reloc_count += sec->reloc_count;
1693 if (idata2) /* .idata2 is the TOC */
1695 else if (reloc_count > 0) /* thunks */
1700 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1701 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1702 is->the_bfd->filename = new_name;
1704 new_name = xmalloc (strlen (is->filename) + 3);
1705 sprintf (new_name, "%s.%c", is->filename, seq);
1706 is->filename = new_name;
1714 gld_${EMULATION_NAME}_before_allocation (void)
1717 before_allocation_default ();
1721 /* This is called when an input file isn't recognized as a BFD. We
1722 check here for .DEF files and pull them in automatically. */
1725 saw_option (char *option)
1731 for (i = 0; init[i].ptr; i++)
1732 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1733 return init[i].inited;
1736 #endif /* DLL_SUPPORT */
1739 gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1742 const char *ext = entry->filename + strlen (entry->filename) - 4;
1744 if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
1746 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1750 int i, buflen=0, len;
1753 for (i = 0; i < pep_def_file->num_exports; i++)
1755 len = strlen (pep_def_file->exports[i].internal_name);
1756 if (buflen < len + 2)
1760 buf = xmalloc (buflen);
1762 for (i = 0; i < pep_def_file->num_exports; i++)
1764 struct bfd_link_hash_entry *h;
1766 sprintf (buf, "%s%s", U (""),
1767 pep_def_file->exports[i].internal_name);
1769 h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
1770 if (h == (struct bfd_link_hash_entry *) NULL)
1771 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1772 if (h->type == bfd_link_hash_new)
1774 h->type = bfd_link_hash_undefined;
1775 h->u.undef.abfd = NULL;
1776 bfd_link_add_undef (link_info.hash, h);
1781 /* def_file_print (stdout, pep_def_file); */
1782 if (pep_def_file->is_dll == 1)
1783 link_info.shared = 1;
1785 if (pep_def_file->base_address != (bfd_vma)(-1))
1788 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1789 = init[IMAGEBASEOFF].value
1790 = pep_def_file->base_address;
1791 init[IMAGEBASEOFF].inited = 1;
1792 if (image_base_statement)
1793 image_base_statement->exp
1794 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1798 if (pep_def_file->stack_reserve != -1
1799 && ! saw_option ("__size_of_stack_reserve__"))
1801 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1802 if (pep_def_file->stack_commit != -1)
1803 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1805 if (pep_def_file->heap_reserve != -1
1806 && ! saw_option ("__size_of_heap_reserve__"))
1808 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1809 if (pep_def_file->heap_commit != -1)
1810 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1820 gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1824 #ifdef TARGET_IS_i386pep
1825 pep_dll_id_target ("pei-x86-64");
1827 if (pep_bfd_is_dll (entry->the_bfd))
1828 return pep_implied_import_dll (entry->filename);
1834 gld_${EMULATION_NAME}_finish (void)
1840 if (link_info.shared
1841 || (!link_info.relocatable && pep_def_file->num_exports != 0))
1843 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1844 if (pep_implib_filename)
1845 pep_dll_generate_implib (pep_def_file, pep_implib_filename, &link_info);
1848 if (pep_out_def_filename)
1849 pep_dll_generate_def_file (pep_out_def_filename);
1850 #endif /* DLL_SUPPORT */
1852 /* I don't know where .idata gets set as code, but it shouldn't be. */
1854 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1858 asec->flags &= ~SEC_CODE;
1859 asec->flags |= SEC_DATA;
1865 /* Place an orphan section.
1867 We use this to put sections in a reasonable place in the file, and
1868 to ensure that they are aligned as required.
1870 We handle grouped sections here as well. A section named .foo\$nn
1871 goes into the output section .foo. All grouped sections are sorted
1874 Grouped sections for the default sections are handled by the
1875 default linker script using wildcards, and are sorted by
1878 static lang_output_section_statement_type *
1879 gld_${EMULATION_NAME}_place_orphan (asection *s,
1880 const char *secname,
1883 const char *orig_secname = secname;
1884 char *dollar = NULL;
1885 lang_output_section_statement_type *os;
1886 lang_statement_list_type add_child;
1887 lang_output_section_statement_type *match_by_name = NULL;
1888 lang_statement_union_type **pl;
1890 /* Look through the script to see where to place this section. */
1891 if (!link_info.relocatable
1892 && (dollar = strchr (secname, '\$')) != NULL)
1894 size_t len = dollar - secname;
1895 char *newname = xmalloc (len + 1);
1896 memcpy (newname, secname, len);
1897 newname[len] = '\0';
1901 lang_list_init (&add_child);
1904 if (constraint == 0)
1905 for (os = lang_output_section_find (secname);
1907 os = next_matching_output_section_statement (os, 0))
1909 /* If we don't match an existing output section, tell
1910 lang_insert_orphan to create a new output section. */
1911 constraint = SPECIAL;
1913 if (os->bfd_section != NULL
1914 && (os->bfd_section->flags == 0
1915 || ((s->flags ^ os->bfd_section->flags)
1916 & (SEC_LOAD | SEC_ALLOC)) == 0))
1918 /* We already have an output section statement with this
1919 name, and its bfd section has compatible flags.
1920 If the section already exists but does not have any flags set,
1921 then it has been created by the linker, probably as a result of
1922 a --section-start command line switch. */
1923 lang_add_section (&add_child, s, NULL, os);
1927 /* Save unused output sections in case we can match them
1928 against orphans later. */
1929 if (os->bfd_section == NULL)
1933 /* If we didn't match an active output section, see if we matched an
1934 unused one and use that. */
1935 if (os == NULL && match_by_name)
1937 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
1938 return match_by_name;
1943 static struct orphan_save hold[] =
1946 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1949 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1952 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1955 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1961 enum orphan_save_index
1969 static int orphan_init_done = 0;
1970 struct orphan_save *place;
1971 lang_output_section_statement_type *after;
1972 etree_type *address;
1974 if (!orphan_init_done)
1976 struct orphan_save *ho;
1977 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1978 if (ho->name != NULL)
1980 ho->os = lang_output_section_find (ho->name);
1981 if (ho->os != NULL && ho->os->flags == 0)
1982 ho->os->flags = ho->flags;
1984 orphan_init_done = 1;
1987 /* Try to put the new output section in a reasonable place based
1988 on the section name and section flags. */
1991 if ((s->flags & SEC_ALLOC) == 0)
1993 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1994 place = &hold[orphan_bss];
1995 else if ((s->flags & SEC_READONLY) == 0)
1996 place = &hold[orphan_data];
1997 else if ((s->flags & SEC_CODE) == 0)
1999 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2000 : &hold[orphan_rodata]);
2003 place = &hold[orphan_text];
2008 if (place->os == NULL)
2009 place->os = lang_output_section_find (place->name);
2012 after = lang_output_section_find_by_flags (s, &place->os, NULL);
2014 /* *ABS* is always the first output section statement. */
2015 after = (&lang_output_section_statement.head
2016 ->output_section_statement);
2019 /* All sections in an executable must be aligned to a page boundary.
2020 In a relocatable link, just preserve the incoming alignment; the
2021 address is discarded by lang_insert_orphan in that case, anyway. */
2022 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
2023 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2025 if (link_info.relocatable)
2027 os->section_alignment = s->alignment_power;
2028 os->bfd_section->alignment_power = s->alignment_power;
2032 /* If the section name has a '\$', sort it with the other '\$'
2034 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2036 lang_input_section_type *ls;
2039 if ((*pl)->header.type != lang_input_section_enum)
2042 ls = &(*pl)->input_section;
2044 lname = bfd_get_section_name (ls->section->owner, ls->section);
2045 if (strchr (lname, '\$') != NULL
2046 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2050 if (add_child.head != NULL)
2052 *add_child.tail = *pl;
2053 *pl = add_child.head;
2060 gld_${EMULATION_NAME}_open_dynamic_archive
2061 (const char *arch ATTRIBUTE_UNUSED,
2062 search_dirs_type *search,
2063 lang_input_statement_type *entry)
2067 const char * format;
2068 bfd_boolean use_prefix;
2072 /* Preferred explicit import library for dll's. */
2073 { "lib%s.dll.a", FALSE },
2074 /* Alternate explicit import library for dll's. */
2075 { "%s.dll.a", FALSE },
2076 /* "libfoo.a" could be either an import lib or a static lib.
2077 For backwards compatibility, libfoo.a needs to precede
2078 libfoo.dll and foo.dll in the search. */
2079 { "lib%s.a", FALSE },
2080 /* The 'native' spelling of an import lib name is "foo.lib". */
2081 { "%s.lib", FALSE },
2083 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2084 { "%s%s.dll", TRUE },
2086 /* Try "libfoo.dll" (default preferred dll name). */
2087 { "lib%s.dll", FALSE },
2088 /* Finally try 'native' dll name "foo.dll". */
2089 { "%s.dll", FALSE },
2090 /* Note: If adding more formats to this table, make sure to check to
2091 see if their length is longer than libname_fmt[0].format, and if
2092 so, update the call to xmalloc() below. */
2095 static unsigned int format_max_len = 0;
2096 const char * filename;
2102 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
2105 filename = entry->filename;
2107 if (format_max_len == 0)
2108 /* We need to allow space in the memory that we are going to allocate
2109 for the characters in the format string. Since the format array is
2110 static we only need to calculate this information once. In theory
2111 this value could also be computed statically, but this introduces
2112 the possibility for a discrepancy and hence a possible memory
2113 corruption. The lengths we compute here will be too long because
2114 they will include any formating characters (%s) in the strings, but
2115 this will not matter. */
2116 for (i = 0; libname_fmt[i].format; i++)
2117 if (format_max_len < strlen (libname_fmt[i].format))
2118 format_max_len = strlen (libname_fmt[i].format);
2120 full_string = xmalloc (strlen (search->name)
2124 + (pep_dll_search_prefix
2125 ? strlen (pep_dll_search_prefix) : 0)
2127 /* Allow for the terminating NUL and for the path
2128 separator character that is inserted between
2129 search->name and the start of the format string. */
2132 sprintf (full_string, "%s/", search->name);
2133 base_string = full_string + strlen (full_string);
2135 for (i = 0; libname_fmt[i].format; i++)
2138 if (libname_fmt[i].use_prefix)
2140 if (!pep_dll_search_prefix)
2142 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2146 sprintf (base_string, libname_fmt[i].format, filename);
2148 if (ldfile_try_open_bfd (full_string, entry))
2152 if (!libname_fmt[i].format)
2158 entry->filename = full_string;
2164 gld_${EMULATION_NAME}_find_potential_libraries
2165 (char *name, lang_input_statement_type *entry)
2167 return ldfile_open_file_search (name, entry, "", ".lib");
2171 gld_${EMULATION_NAME}_get_script (int *isfile)
2173 # Scripts compiled in.
2174 # sed commands to quote an ld script as a C string.
2175 sc="-f stringify.sed"
2181 if (link_info.relocatable && config.build_constructors)
2184 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2185 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
2186 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2187 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2188 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2189 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2190 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2191 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2192 echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
2193 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2195 echo ' ; else return' >> e${EMULATION_NAME}.c
2196 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2197 echo '; }' >> e${EMULATION_NAME}.c
2202 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2204 gld_${EMULATION_NAME}_before_parse,
2207 gld_${EMULATION_NAME}_after_parse,
2208 gld_${EMULATION_NAME}_after_open,
2209 after_allocation_default,
2210 set_output_arch_default,
2211 ldemul_default_target,
2212 gld_${EMULATION_NAME}_before_allocation,
2213 gld_${EMULATION_NAME}_get_script,
2214 "${EMULATION_NAME}",
2216 gld_${EMULATION_NAME}_finish,
2217 NULL, /* Create output section statements. */
2218 gld_${EMULATION_NAME}_open_dynamic_archive,
2219 gld_${EMULATION_NAME}_place_orphan,
2220 gld_${EMULATION_NAME}_set_symbols,
2221 NULL, /* parse_args */
2222 gld${EMULATION_NAME}_add_options,
2223 gld${EMULATION_NAME}_handle_option,
2224 gld_${EMULATION_NAME}_unrecognized_file,
2225 gld_${EMULATION_NAME}_list_options,
2226 gld_${EMULATION_NAME}_recognized_file,
2227 gld_${EMULATION_NAME}_find_potential_libraries,
2228 NULL, /* new_vers_pattern. */
2229 NULL /* extra_map_file_text */