* emultempl/pe.em (OPTION_EXCLUDE_ALL_SYMBOLS): New macro.
[deliverable/binutils-gdb.git] / ld / emultempl / pep.em
1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 test -z "${ENTRY}" && ENTRY="_mainCRTStartup"
4 if [ -z "$MACHINE" ]; then
5 OUTPUT_ARCH=${ARCH}
6 else
7 OUTPUT_ARCH=${ARCH}:${MACHINE}
8 fi
9 rm -f e${EMULATION_NAME}.c
10 (echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
11 fragment <<EOF
12 /* Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
13 Written by Kai Tietz, OneVision Software GmbH&CoKg.
14
15 This file is part of the GNU Binutils.
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 3 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
30 MA 02110-1301, USA. */
31
32
33 /* For WINDOWS_XP64 and higher */
34 /* Based on pe.em, but modified for 64 bit support. */
35
36 #define TARGET_IS_${EMULATION_NAME}
37
38 #define COFF_IMAGE_WITH_PE
39 #define COFF_WITH_PE
40 #define COFF_WITH_pex64
41
42 #include "sysdep.h"
43 #include "bfd.h"
44 #include "bfdlink.h"
45 #include "getopt.h"
46 #include "libiberty.h"
47 #include "ld.h"
48 #include "ldmain.h"
49 #include "ldexp.h"
50 #include "ldlang.h"
51 #include "ldfile.h"
52 #include "ldemul.h"
53 #include <ldgram.h>
54 #include "ldlex.h"
55 #include "ldmisc.h"
56 #include "ldctor.h"
57 #include "coff/internal.h"
58
59 /* FIXME: See bfd/peXXigen.c for why we include an architecture specific
60 header in generic PE code. */
61 #include "coff/x86_64.h"
62 #include "coff/pe.h"
63
64 /* FIXME: This is a BFD internal header file, and we should not be
65 using it here. */
66 #include "../bfd/libcoff.h"
67
68 #undef AOUTSZ
69 #define AOUTSZ PEPAOUTSZ
70 #define PEAOUTHDR PEPAOUTHDR
71
72 #include "deffile.h"
73 #include "pep-dll.h"
74 #include "safe-ctype.h"
75
76 /* Permit the emulation parameters to override the default section
77 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
78 it seem that include/coff/internal.h should not define
79 PE_DEF_SECTION_ALIGNMENT. */
80 #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
81 #undef PE_DEF_SECTION_ALIGNMENT
82 #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
83 #endif
84
85 #ifdef TARGET_IS_i386pep
86 #define DLL_SUPPORT
87 #endif
88
89 #if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
90 #define PE_DEF_SUBSYSTEM 3
91 #else
92 #undef NT_EXE_IMAGE_BASE
93 #define NT_EXE_IMAGE_BASE 0x00010000
94 #undef PE_DEF_SECTION_ALIGNMENT
95 #define PE_DEF_SUBSYSTEM 2
96 #undef PE_DEF_FILE_ALIGNMENT
97 #define PE_DEF_FILE_ALIGNMENT 0x00000200
98 #define PE_DEF_SECTION_ALIGNMENT 0x00000400
99 #endif
100
101
102 static struct internal_extra_pe_aouthdr pep;
103 static int dll;
104 static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
105 static int support_old_code = 0;
106 static lang_assignment_statement_type *image_base_statement = 0;
107 static unsigned short pe_dll_characteristics = 0;
108
109 #ifdef DLL_SUPPORT
110 static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
111 static char * pep_out_def_filename = NULL;
112 static char * pep_implib_filename = NULL;
113 static int pep_enable_auto_image_base = 0;
114 static char * pep_dll_search_prefix = NULL;
115 #endif
116
117 extern const char *output_filename;
118
119 static void
120 gld_${EMULATION_NAME}_before_parse (void)
121 {
122 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
123 output_filename = "${EXECUTABLE_NAME:-a.exe}";
124 #ifdef DLL_SUPPORT
125 config.dynamic_link = TRUE;
126 config.has_shared = 1;
127 link_info.pei386_auto_import = -1;
128 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
129
130 #if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
131 lang_default_entry ("_WinMainCRTStartup");
132 #else
133 lang_default_entry ("${ENTRY}");
134 #endif
135 #endif
136 }
137 \f
138 /* PE format extra command line options. */
139
140 /* Used for setting flags in the PE header. */
141 enum options
142 {
143 OPTION_BASE_FILE = 300 + 1,
144 OPTION_DLL,
145 OPTION_FILE_ALIGNMENT,
146 OPTION_IMAGE_BASE,
147 OPTION_MAJOR_IMAGE_VERSION,
148 OPTION_MAJOR_OS_VERSION,
149 OPTION_MAJOR_SUBSYSTEM_VERSION,
150 OPTION_MINOR_IMAGE_VERSION,
151 OPTION_MINOR_OS_VERSION,
152 OPTION_MINOR_SUBSYSTEM_VERSION,
153 OPTION_SECTION_ALIGNMENT,
154 OPTION_STACK,
155 OPTION_SUBSYSTEM,
156 OPTION_HEAP,
157 OPTION_SUPPORT_OLD_CODE,
158 OPTION_OUT_DEF,
159 OPTION_EXPORT_ALL,
160 OPTION_EXCLUDE_SYMBOLS,
161 OPTION_EXCLUDE_ALL_SYMBOLS,
162 OPTION_KILL_ATS,
163 OPTION_STDCALL_ALIASES,
164 OPTION_ENABLE_STDCALL_FIXUP,
165 OPTION_DISABLE_STDCALL_FIXUP,
166 OPTION_IMPLIB_FILENAME,
167 OPTION_WARN_DUPLICATE_EXPORTS,
168 OPTION_IMP_COMPAT,
169 OPTION_ENABLE_AUTO_IMAGE_BASE,
170 OPTION_DISABLE_AUTO_IMAGE_BASE,
171 OPTION_DLL_SEARCH_PREFIX,
172 OPTION_NO_DEFAULT_EXCLUDES,
173 OPTION_DLL_ENABLE_AUTO_IMPORT,
174 OPTION_DLL_DISABLE_AUTO_IMPORT,
175 OPTION_ENABLE_EXTRA_PE_DEBUG,
176 OPTION_EXCLUDE_LIBS,
177 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
178 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
179 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1,
180 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
181 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
182 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
183 OPTION_ENABLE_LONG_SECTION_NAMES,
184 OPTION_DISABLE_LONG_SECTION_NAMES,
185 OPTION_DYNAMIC_BASE,
186 OPTION_FORCE_INTEGRITY,
187 OPTION_NX_COMPAT,
188 OPTION_NO_ISOLATION,
189 OPTION_NO_SEH,
190 OPTION_NO_BIND,
191 OPTION_WDM_DRIVER,
192 OPTION_TERMINAL_SERVER_AWARE
193 };
194
195 static void
196 gld${EMULATION_NAME}_add_options
197 (int ns ATTRIBUTE_UNUSED,
198 char **shortopts ATTRIBUTE_UNUSED,
199 int nl,
200 struct option **longopts,
201 int nrl ATTRIBUTE_UNUSED,
202 struct option **really_longopts ATTRIBUTE_UNUSED)
203 {
204 static const struct option xtra_long[] =
205 {
206 /* PE options */
207 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
208 {"dll", no_argument, NULL, OPTION_DLL},
209 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
210 {"heap", required_argument, NULL, OPTION_HEAP},
211 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
212 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
213 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
214 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
215 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
216 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
217 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
218 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
219 {"stack", required_argument, NULL, OPTION_STACK},
220 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
221 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
222 {"use-nul-prefixed-import-tables", no_argument, NULL,
223 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
224 #ifdef DLL_SUPPORT
225 /* getopt allows abbreviations, so we do this to stop it
226 from treating -o as an abbreviation for this option. */
227 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
228 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
229 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
230 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
231 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
232 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
233 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
234 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
235 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
236 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
237 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
238 {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
239 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
240 /* getopt() allows abbreviations, so we do this to stop it from
241 treating -c as an abbreviation for these --compat-implib. */
242 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
243 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
244 {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
245 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
246 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
247 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
248 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
249 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
250 {"enable-extra-pep-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
251 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
252 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
253 {"enable-runtime-pseudo-reloc-v1", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1},
254 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
255 #endif
256 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
257 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
258 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
259 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
260 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
261 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
262 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
263 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
264 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
265 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
266 {NULL, no_argument, NULL, 0}
267 };
268
269 *longopts
270 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
271 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
272 }
273
274 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
275 parameters which may be input from the command line. */
276
277 typedef struct
278 {
279 void *ptr;
280 int size;
281 bfd_vma value;
282 char *symbol;
283 int inited;
284 } definfo;
285
286 #define D(field,symbol,def) {&pep.field,sizeof(pep.field), def, symbol,0}
287
288 static definfo init[] =
289 {
290 /* imagebase must be first */
291 #define IMAGEBASEOFF 0
292 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
293 #define DLLOFF 1
294 {&dll, sizeof(dll), 0, "__dll__", 0},
295 #define MSIMAGEBASEOFF 2
296 D(ImageBase,"___ImageBase", NT_EXE_IMAGE_BASE),
297 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
298 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
299 D(MajorOperatingSystemVersion,"__major_os_version__", 4),
300 D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
301 D(MajorImageVersion,"__major_image_version__", 0),
302 D(MinorImageVersion,"__minor_image_version__", 0),
303 D(MajorSubsystemVersion,"__major_subsystem_version__", 5),
304 D(MinorSubsystemVersion,"__minor_subsystem_version__", 2),
305 D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
306 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000),
307 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
308 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
309 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
310 D(LoaderFlags,"__loader_flags__", 0x0),
311 D(DllCharacteristics, "__dll_characteristics__", 0x0),
312 { NULL, 0, 0, NULL, 0 }
313 };
314
315
316 static void
317 gld_${EMULATION_NAME}_list_options (FILE *file)
318 {
319 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
320 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
321 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
322 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
323 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
324 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
325 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
326 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
327 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
328 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
329 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
330 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
331 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
332 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
333 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
334 #ifdef DLL_SUPPORT
335 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
336 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
337 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
338 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
339 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
340 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
341 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
342 fprintf (file, _(" Exclude objects, archive members from auto\n"));
343 fprintf (file, _(" export, place into import library instead.\n"));
344 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
345 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
346 fprintf (file, _(" --out-implib <file> Generate import library\n"));
347 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
348 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
349 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
350 create __imp_<SYMBOL> as well.\n"));
351 fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
352 unless user specifies one\n"));
353 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
354 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
355 an importlib, use <string><basename>.dll\n\
356 in preference to lib<basename>.dll \n"));
357 fprintf (file, _(" --enable-auto-import Do sophistcated linking of _sym to\n\
358 __imp_sym for DATA references\n"));
359 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
360 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
361 adding pseudo-relocations resolved at\n\
362 runtime.\n"));
363 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
364 auto-imported DATA.\n"));
365 fprintf (file, _(" --enable-extra-pep-debug Enable verbose debug output when building\n\
366 or linking to DLLs (esp. auto-import)\n"));
367 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
368 executable image files\n"));
369 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
370 in object files\n"));
371 fprintf (file, _(" --dynamicbase Image base address may be relocated using\n\
372 address space layout randomization (ASLR)\n"));
373 fprintf (file, _(" --forceinteg Code integrity checks are enforced\n"));
374 fprintf (file, _(" --nxcompat Image is compatible with data execution prevention\n"));
375 fprintf (file, _(" --no-isolation Image understands isolation but do not isolate the image\n"));
376 fprintf (file, _(" --no-seh Image does not use SEH. No SE handler may\n\
377 be called in this image\n"));
378 fprintf (file, _(" --no-bind Do not bind this image\n"));
379 fprintf (file, _(" --wdmdriver Driver uses the WDM model\n"));
380 fprintf (file, _(" --tsaware Image is Terminal Server aware\n"));
381 #endif
382 }
383
384
385 static void
386 set_pep_name (char *name, bfd_vma val)
387 {
388 int i;
389
390 /* Find the name and set it. */
391 for (i = 0; init[i].ptr; i++)
392 {
393 if (strcmp (name, init[i].symbol) == 0)
394 {
395 init[i].value = val;
396 init[i].inited = 1;
397 if (strcmp (name,"__image_base__") == 0)
398 set_pep_name ("___ImageBase", val);
399 return;
400 }
401 }
402 abort ();
403 }
404
405
406 static void
407 set_pep_subsystem (void)
408 {
409 const char *sver;
410 const char *entry;
411 const char *initial_symbol_char;
412 char *end;
413 int len;
414 int i;
415 int subsystem;
416 unsigned long temp_subsystem;
417 static const struct
418 {
419 const char *name;
420 const int value;
421 const char *entry;
422 }
423 v[] =
424 {
425 { "native", 1, "NtProcessStartup" },
426 { "windows", 2, "WinMainCRTStartup" },
427 { "console", 3, "mainCRTStartup" },
428 { "posix", 7, "__PosixProcessStartup"},
429 { "wince", 9, "_WinMainCRTStartup" },
430 { "xbox", 14, "mainCRTStartup" },
431 { NULL, 0, NULL }
432 };
433 /* Entry point name for arbitrary subsystem numbers. */
434 static const char default_entry[] = "mainCRTStartup";
435
436 /* Check for the presence of a version number. */
437 sver = strchr (optarg, ':');
438 if (sver == NULL)
439 len = strlen (optarg);
440 else
441 {
442 len = sver - optarg;
443 set_pep_name ("__major_subsystem_version__",
444 strtoul (sver + 1, &end, 0));
445 if (*end == '.')
446 set_pep_name ("__minor_subsystem_version__",
447 strtoul (end + 1, &end, 0));
448 if (*end != '\0')
449 einfo (_("%P: warning: bad version number in -subsystem option\n"));
450 }
451
452 /* Check for numeric subsystem. */
453 temp_subsystem = strtoul (optarg, & end, 0);
454 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
455 {
456 /* Search list for a numeric match to use its entry point. */
457 for (i = 0; v[i].name; i++)
458 if (v[i].value == (int) temp_subsystem)
459 break;
460
461 /* If no match, use the default. */
462 if (v[i].name != NULL)
463 entry = v[i].entry;
464 else
465 entry = default_entry;
466
467 /* Use this subsystem. */
468 subsystem = (int) temp_subsystem;
469 }
470 else
471 {
472 /* Search for subsystem by name. */
473 for (i = 0; v[i].name; i++)
474 if (strncmp (optarg, v[i].name, len) == 0
475 && v[i].name[len] == '\0')
476 break;
477
478 if (v[i].name == NULL)
479 {
480 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
481 return;
482 }
483
484 entry = v[i].entry;
485 subsystem = v[i].value;
486 }
487
488 set_pep_name ("__subsystem__", subsystem);
489
490 initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
491 if (*initial_symbol_char != '\0')
492 {
493 char *alc_entry;
494
495 /* lang_default_entry expects its argument to be permanently
496 allocated, so we don't free this string. */
497 alc_entry = xmalloc (strlen (initial_symbol_char)
498 + strlen (entry)
499 + 1);
500 strcpy (alc_entry, initial_symbol_char);
501 strcat (alc_entry, entry);
502 entry = alc_entry;
503 }
504
505 lang_default_entry (entry);
506
507 return;
508 }
509
510
511 static void
512 set_pep_value (char *name)
513 {
514 char *end;
515
516 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
517
518 if (end == optarg)
519 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
520
521 optarg = end;
522 }
523
524
525 static void
526 set_pep_stack_heap (char *resname, char *comname)
527 {
528 set_pep_value (resname);
529
530 if (*optarg == ',')
531 {
532 optarg++;
533 set_pep_value (comname);
534 }
535 else if (*optarg)
536 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
537 }
538
539
540 static bfd_boolean
541 gld${EMULATION_NAME}_handle_option (int optc)
542 {
543 switch (optc)
544 {
545 default:
546 return FALSE;
547
548 case OPTION_BASE_FILE:
549 link_info.base_file = fopen (optarg, FOPEN_WB);
550 if (link_info.base_file == NULL)
551 {
552 /* xgettext:c-format */
553 fprintf (stderr, _("%s: Can't open base file %s\n"),
554 program_name, optarg);
555 xexit (1);
556 }
557 break;
558
559 /* PE options. */
560 case OPTION_HEAP:
561 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
562 break;
563 case OPTION_STACK:
564 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
565 break;
566 case OPTION_SUBSYSTEM:
567 set_pep_subsystem ();
568 break;
569 case OPTION_MAJOR_OS_VERSION:
570 set_pep_value ("__major_os_version__");
571 break;
572 case OPTION_MINOR_OS_VERSION:
573 set_pep_value ("__minor_os_version__");
574 break;
575 case OPTION_MAJOR_SUBSYSTEM_VERSION:
576 set_pep_value ("__major_subsystem_version__");
577 break;
578 case OPTION_MINOR_SUBSYSTEM_VERSION:
579 set_pep_value ("__minor_subsystem_version__");
580 break;
581 case OPTION_MAJOR_IMAGE_VERSION:
582 set_pep_value ("__major_image_version__");
583 break;
584 case OPTION_MINOR_IMAGE_VERSION:
585 set_pep_value ("__minor_image_version__");
586 break;
587 case OPTION_FILE_ALIGNMENT:
588 set_pep_value ("__file_alignment__");
589 break;
590 case OPTION_SECTION_ALIGNMENT:
591 set_pep_value ("__section_alignment__");
592 break;
593 case OPTION_DLL:
594 set_pep_name ("__dll__", 1);
595 break;
596 case OPTION_IMAGE_BASE:
597 set_pep_value ("__image_base__");
598 break;
599 case OPTION_SUPPORT_OLD_CODE:
600 support_old_code = 1;
601 break;
602 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
603 pep_use_nul_prefixed_import_tables = TRUE;
604 break;
605 #ifdef DLL_SUPPORT
606 case OPTION_OUT_DEF:
607 pep_out_def_filename = xstrdup (optarg);
608 break;
609 case OPTION_EXPORT_ALL:
610 pep_dll_export_everything = 1;
611 break;
612 case OPTION_EXCLUDE_SYMBOLS:
613 pep_dll_add_excludes (optarg, EXCLUDESYMS);
614 break;
615 case OPTION_EXCLUDE_ALL_SYMBOLS:
616 pep_dll_exclude_all_symbols = 1;
617 break;
618 case OPTION_EXCLUDE_LIBS:
619 pep_dll_add_excludes (optarg, EXCLUDELIBS);
620 break;
621 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
622 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
623 break;
624 case OPTION_KILL_ATS:
625 pep_dll_kill_ats = 1;
626 break;
627 case OPTION_STDCALL_ALIASES:
628 pep_dll_stdcall_aliases = 1;
629 break;
630 case OPTION_ENABLE_STDCALL_FIXUP:
631 pep_enable_stdcall_fixup = 1;
632 break;
633 case OPTION_DISABLE_STDCALL_FIXUP:
634 pep_enable_stdcall_fixup = 0;
635 break;
636 case OPTION_IMPLIB_FILENAME:
637 pep_implib_filename = xstrdup (optarg);
638 break;
639 case OPTION_WARN_DUPLICATE_EXPORTS:
640 pep_dll_warn_dup_exports = 1;
641 break;
642 case OPTION_IMP_COMPAT:
643 pep_dll_compat_implib = 1;
644 break;
645 case OPTION_ENABLE_AUTO_IMAGE_BASE:
646 pep_enable_auto_image_base = 1;
647 break;
648 case OPTION_DISABLE_AUTO_IMAGE_BASE:
649 pep_enable_auto_image_base = 0;
650 break;
651 case OPTION_DLL_SEARCH_PREFIX:
652 pep_dll_search_prefix = xstrdup (optarg);
653 break;
654 case OPTION_NO_DEFAULT_EXCLUDES:
655 pep_dll_do_default_excludes = 0;
656 break;
657 case OPTION_DLL_ENABLE_AUTO_IMPORT:
658 link_info.pei386_auto_import = 1;
659 break;
660 case OPTION_DLL_DISABLE_AUTO_IMPORT:
661 link_info.pei386_auto_import = 0;
662 break;
663 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
664 link_info.pei386_runtime_pseudo_reloc = 2;
665 break;
666 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
667 link_info.pei386_runtime_pseudo_reloc = 0;
668 break;
669 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1:
670 link_info.pei386_runtime_pseudo_reloc = 1;
671 break;
672 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
673 link_info.pei386_runtime_pseudo_reloc = 2;
674 break;
675 case OPTION_ENABLE_EXTRA_PE_DEBUG:
676 pep_dll_extra_pe_debug = 1;
677 break;
678 #endif
679 case OPTION_ENABLE_LONG_SECTION_NAMES:
680 pep_use_coff_long_section_names = 1;
681 break;
682 case OPTION_DISABLE_LONG_SECTION_NAMES:
683 pep_use_coff_long_section_names = 0;
684 break;
685 /* Get DLLCharacteristics bits */
686 case OPTION_DYNAMIC_BASE:
687 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
688 break;
689 case OPTION_FORCE_INTEGRITY:
690 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
691 break;
692 case OPTION_NX_COMPAT:
693 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
694 break;
695 case OPTION_NO_ISOLATION:
696 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
697 break;
698 case OPTION_NO_SEH:
699 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
700 break;
701 case OPTION_NO_BIND:
702 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
703 break;
704 case OPTION_WDM_DRIVER:
705 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
706 break;
707 case OPTION_TERMINAL_SERVER_AWARE:
708 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
709 break;
710 }
711
712 /* Set DLLCharacteristics bits */
713 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
714
715 return TRUE;
716 }
717 \f
718
719 #ifdef DLL_SUPPORT
720 static unsigned long
721 strhash (const char *str)
722 {
723 const unsigned char *s;
724 unsigned long hash;
725 unsigned int c;
726 unsigned int len;
727
728 hash = 0;
729 len = 0;
730 s = (const unsigned char *) str;
731 while ((c = *s++) != '\0')
732 {
733 hash += c + (c << 17);
734 hash ^= hash >> 2;
735 ++len;
736 }
737 hash += len + (len << 17);
738 hash ^= hash >> 2;
739
740 return hash;
741 }
742
743 /* Use the output file to create a image base for relocatable DLLs. */
744
745 static bfd_vma
746 compute_dll_image_base (const char *ofile)
747 {
748 bfd_vma hash = (bfd_vma) strhash (ofile);
749 return 0x61300000 + ((hash << 16) & 0x0FFC0000);
750 }
751 #endif
752
753 /* Assign values to the special symbols before the linker script is
754 read. */
755
756 static void
757 gld_${EMULATION_NAME}_set_symbols (void)
758 {
759 /* Run through and invent symbols for all the
760 names and insert the defaults. */
761 int j;
762
763 if (!init[IMAGEBASEOFF].inited)
764 {
765 if (link_info.relocatable)
766 init[IMAGEBASEOFF].value = 0;
767 else if (init[DLLOFF].value || (link_info.shared && !link_info.pie))
768 {
769 #ifdef DLL_SUPPORT
770 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
771 ? compute_dll_image_base (output_filename)
772 : NT_DLL_IMAGE_BASE);
773 #else
774 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
775 #endif
776 }
777 else
778 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
779 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
780 }
781
782 /* Don't do any symbol assignments if this is a relocatable link. */
783 if (link_info.relocatable)
784 return;
785
786 /* Glue the assignments into the abs section. */
787 push_stat_ptr (&abs_output_section->children);
788
789 for (j = 0; init[j].ptr; j++)
790 {
791 bfd_vma val = init[j].value;
792 lang_assignment_statement_type *rv;
793 rv = lang_add_assignment (exp_assop ('=', init[j].symbol,
794 exp_intop (val)));
795 if (init[j].size == sizeof (short))
796 *(short *) init[j].ptr = (short) val;
797 else if (init[j].size == sizeof (int))
798 *(int *) init[j].ptr = (int) val;
799 else if (init[j].size == sizeof (long))
800 *(long *) init[j].ptr = (long) val;
801 /* This might be a long long or other special type. */
802 else if (init[j].size == sizeof (bfd_vma))
803 *(bfd_vma *) init[j].ptr = val;
804 else abort ();
805 if (j == IMAGEBASEOFF)
806 image_base_statement = rv;
807 }
808 /* Restore the pointer. */
809 pop_stat_ptr ();
810
811 if (pep.FileAlignment > pep.SectionAlignment)
812 {
813 einfo (_("%P: warning, file alignment > section alignment.\n"));
814 }
815 }
816
817 /* This is called after the linker script and the command line options
818 have been read. */
819
820 static void
821 gld_${EMULATION_NAME}_after_parse (void)
822 {
823 /* PR ld/6744: Warn the user if they have used an ELF-only
824 option hoping it will work on PE+. */
825 if (link_info.export_dynamic)
826 einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
827 "targets, did you mean --export-all-symbols?\n"));
828
829 after_parse_default ();
830 }
831
832 /* pep-dll.c directly accesses pep_data_import_dll,
833 so it must be defined outside of #ifdef DLL_SUPPORT.
834 Note - this variable is deliberately not initialised.
835 This allows it to be treated as a common varaible, and only
836 exist in one incarnation in a multiple target enabled linker. */
837 char * pep_data_import_dll;
838
839 #ifdef DLL_SUPPORT
840 static struct bfd_link_hash_entry *pep_undef_found_sym;
841
842 static bfd_boolean
843 pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
844 {
845 int sl;
846 char *string = inf;
847
848 sl = strlen (string);
849 if (h->type == bfd_link_hash_defined
850 && strncmp (h->root.string, string, sl) == 0
851 && h->root.string[sl] == '@')
852 {
853 pep_undef_found_sym = h;
854 return FALSE;
855 }
856 return TRUE;
857 }
858
859 static void
860 pep_fixup_stdcalls (void)
861 {
862 static int gave_warning_message = 0;
863 struct bfd_link_hash_entry *undef, *sym;
864
865 if (pep_dll_extra_pe_debug)
866 printf ("%s\n", __FUNCTION__);
867
868 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
869 if (undef->type == bfd_link_hash_undefined)
870 {
871 char* at = strchr (undef->root.string, '@');
872 int lead_at = (*undef->root.string == '@');
873 /* For now, don't try to fixup fastcall symbols. */
874
875 if (at && !lead_at)
876 {
877 /* The symbol is a stdcall symbol, so let's look for a
878 cdecl symbol with the same name and resolve to that. */
879 char *cname = xstrdup (undef->root.string /* + lead_at */);
880 at = strchr (cname, '@');
881 *at = 0;
882 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
883
884 if (sym && sym->type == bfd_link_hash_defined)
885 {
886 undef->type = bfd_link_hash_defined;
887 undef->u.def.value = sym->u.def.value;
888 undef->u.def.section = sym->u.def.section;
889
890 if (pep_enable_stdcall_fixup == -1)
891 {
892 einfo (_("Warning: resolving %s by linking to %s\n"),
893 undef->root.string, cname);
894 if (! gave_warning_message)
895 {
896 gave_warning_message = 1;
897 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
898 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
899 }
900 }
901 }
902 }
903 else
904 {
905 /* The symbol is a cdecl symbol, so we look for stdcall
906 symbols - which means scanning the whole symbol table. */
907 pep_undef_found_sym = 0;
908 bfd_link_hash_traverse (link_info.hash, pep_undef_cdecl_match,
909 (char *) undef->root.string);
910 sym = pep_undef_found_sym;
911 if (sym)
912 {
913 undef->type = bfd_link_hash_defined;
914 undef->u.def.value = sym->u.def.value;
915 undef->u.def.section = sym->u.def.section;
916
917 if (pep_enable_stdcall_fixup == -1)
918 {
919 einfo (_("Warning: resolving %s by linking to %s\n"),
920 undef->root.string, sym->root.string);
921 if (! gave_warning_message)
922 {
923 gave_warning_message = 1;
924 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
925 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
926 }
927 }
928 }
929 }
930 }
931 }
932
933 static int
934 make_import_fixup (arelent *rel, asection *s)
935 {
936 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
937 char addend[8];
938 bfd_vma _addend = 0;
939 int suc = 0;
940
941 if (pep_dll_extra_pe_debug)
942 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
943 (unsigned long) rel->address, (long) rel->addend);
944
945 memset (addend, 0, sizeof (addend));
946 switch ((rel->howto->bitsize))
947 {
948 case 8:
949 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 1);
950 if (suc && rel->howto->pc_relative)
951 _addend = (bfd_vma) ((bfd_signed_vma) ((char) bfd_get_8 (s->owner, addend)));
952 else if (suc)
953 _addend = ((bfd_vma) bfd_get_8 (s->owner, addend)) & 0xff;
954 break;
955 case 16:
956 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 2);
957 if (suc && rel->howto->pc_relative)
958 _addend = (bfd_vma) ((bfd_signed_vma) ((short) bfd_get_16 (s->owner, addend)));
959 else if (suc)
960 _addend = ((bfd_vma) bfd_get_16 (s->owner, addend)) & 0xffff;
961 break;
962 case 32:
963 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 4);
964 if (suc && rel->howto->pc_relative)
965 _addend = (bfd_vma) ((bfd_signed_vma) ((int) bfd_get_32 (s->owner, addend)));
966 else if (suc)
967 _addend = ((bfd_vma) bfd_get_32 (s->owner, addend)) & 0xffffffff;
968 break;
969 case 64:
970 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
971 if (suc)
972 _addend = ((bfd_vma) bfd_get_64 (s->owner, addend));
973 break;
974 }
975 if (! suc)
976 einfo (_("%C: Cannot get section contents - auto-import exception\n"),
977 s->owner, s, rel->address);
978
979 if (pep_dll_extra_pe_debug)
980 {
981 printf ("import of 0x%lx(0x%lx) sec_addr=0x%lx", (long) _addend, (long) rel->addend, (long) rel->address);
982 if (rel->howto->pc_relative) printf (" pcrel");
983 printf (" %d bit rel.\n",(int) rel->howto->bitsize);
984 }
985 pep_create_import_fixup (rel, s, _addend);
986
987 return 1;
988 }
989
990 static void
991 pep_find_data_imports (void)
992 {
993 struct bfd_link_hash_entry *undef, *sym;
994
995 if (link_info.pei386_auto_import == 0)
996 return;
997
998 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
999 {
1000 if (undef->type == bfd_link_hash_undefined)
1001 {
1002 /* C++ symbols are *long*. */
1003 char buf[4096];
1004
1005 if (pep_dll_extra_pe_debug)
1006 printf ("%s:%s\n", __FUNCTION__, undef->root.string);
1007
1008 sprintf (buf, "__imp_%s", undef->root.string);
1009
1010 sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
1011
1012 if (sym && sym->type == bfd_link_hash_defined)
1013 {
1014 bfd *b = sym->u.def.section->owner;
1015 asymbol **symbols;
1016 int nsyms, i;
1017
1018 if (link_info.pei386_auto_import == -1)
1019 {
1020 static bfd_boolean warned = FALSE;
1021
1022 info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"),
1023 undef->root.string, buf);
1024
1025 /* PR linker/4844. */
1026 if (! warned)
1027 {
1028 warned = TRUE;
1029 einfo (_("%P: warning: auto-importing has been activated without --enable-auto-import specified on the command line.\n\
1030 This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.\n"));
1031 }
1032 }
1033
1034 if (!bfd_generic_link_read_symbols (b))
1035 {
1036 einfo (_("%B%F: could not read symbols: %E\n"), b);
1037 return;
1038 }
1039
1040 symbols = bfd_get_outsymbols (b);
1041 nsyms = bfd_get_symcount (b);
1042
1043 for (i = 0; i < nsyms; i++)
1044 {
1045 if (! CONST_STRNEQ (symbols[i]->name, "__head_"))
1046 continue;
1047
1048 if (pep_dll_extra_pe_debug)
1049 printf ("->%s\n", symbols[i]->name);
1050
1051 pep_data_import_dll = (char*) (symbols[i]->name +
1052 sizeof ("__head_") - 1);
1053 break;
1054 }
1055
1056 pep_walk_relocs_of_symbol (&link_info, undef->root.string,
1057 make_import_fixup);
1058
1059 /* Let's differentiate it somehow from defined. */
1060 undef->type = bfd_link_hash_defweak;
1061 /* We replace original name with __imp_ prefixed, this
1062 1) may trash memory 2) leads to duplicate symbol generation.
1063 Still, IMHO it's better than having name poluted. */
1064 undef->root.string = sym->root.string;
1065 undef->u.def.value = sym->u.def.value;
1066 undef->u.def.section = sym->u.def.section;
1067 }
1068 }
1069 }
1070 }
1071
1072 static bfd_boolean
1073 pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1074 {
1075 if (pep_dll_extra_pe_debug)
1076 printf ("+%s\n", h->string);
1077
1078 return TRUE;
1079 }
1080 #endif /* DLL_SUPPORT */
1081
1082 static void
1083 debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1084 {
1085 int *found = (int *) obj;
1086 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1087 *found = 1;
1088 }
1089
1090 static void
1091 gld_${EMULATION_NAME}_after_open (void)
1092 {
1093 #ifdef DLL_SUPPORT
1094 if (pep_dll_extra_pe_debug)
1095 {
1096 bfd *a;
1097 struct bfd_link_hash_entry *sym;
1098
1099 printf ("%s()\n", __FUNCTION__);
1100
1101 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1102 printf ("-%s\n", sym->root.string);
1103 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1104
1105 for (a = link_info.input_bfds; a; a = a->link_next)
1106 printf ("*%s\n",a->filename);
1107 }
1108 #endif
1109
1110 /* Pass the wacky PE command line options into the output bfd.
1111 FIXME: This should be done via a function, rather than by
1112 including an internal BFD header. */
1113
1114 if (coff_data (link_info.output_bfd) == NULL
1115 || coff_data (link_info.output_bfd)->pe == 0)
1116 einfo (_("%F%P: cannot perform PE operations on non PE output file '%B'.\n"),
1117 link_info.output_bfd);
1118
1119 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1120 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1121 pe_data (link_info.output_bfd)->real_flags |= real_flags;
1122
1123 /* At this point we must decide whether to use long section names
1124 in the output or not. If the user hasn't explicitly specified
1125 on the command line, we leave it to the default for the format
1126 (object files yes, image files no), except if there is debug
1127 information present; GDB relies on the long section names to
1128 find it, so enable it in that case. */
1129 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1130 {
1131 /* Iterate over all sections of all input BFDs, checking
1132 for any that begin 'debug_' and are long names. */
1133 LANG_FOR_EACH_INPUT_STATEMENT (is)
1134 {
1135 int found_debug = 0;
1136 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1137 if (found_debug)
1138 {
1139 pep_use_coff_long_section_names = 1;
1140 break;
1141 }
1142 }
1143 }
1144
1145 pep_output_file_set_long_section_names (link_info.output_bfd);
1146
1147 #ifdef DLL_SUPPORT
1148 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1149 pep_fixup_stdcalls ();
1150
1151 pep_process_import_defs (link_info.output_bfd, &link_info);
1152
1153 pep_find_data_imports ();
1154
1155 #ifndef TARGET_IS_i386pep
1156 if (link_info.shared)
1157 #else
1158 if (!link_info.relocatable)
1159 #endif
1160 pep_dll_build_sections (link_info.output_bfd, &link_info);
1161
1162 #ifndef TARGET_IS_i386pep
1163 else
1164 pep_exe_build_sections (link_info.output_bfd, &link_info);
1165 #endif
1166 #endif /* DLL_SUPPORT */
1167
1168 {
1169 /* This next chunk of code tries to detect the case where you have
1170 two import libraries for the same DLL (specifically,
1171 symbolically linking libm.a and libc.a in cygwin to
1172 libcygwin.a). In those cases, it's possible for function
1173 thunks from the second implib to be used but without the
1174 head/tail objects, causing an improper import table. We detect
1175 those cases and rename the "other" import libraries to match
1176 the one the head/tail come from, so that the linker will sort
1177 things nicely and produce a valid import table. */
1178
1179 LANG_FOR_EACH_INPUT_STATEMENT (is)
1180 {
1181 if (is->the_bfd->my_archive)
1182 {
1183 int idata2 = 0, reloc_count=0, is_imp = 0;
1184 asection *sec;
1185
1186 /* See if this is an import library thunk. */
1187 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1188 {
1189 if (strcmp (sec->name, ".idata\$2") == 0)
1190 idata2 = 1;
1191 if (CONST_STRNEQ (sec->name, ".idata\$"))
1192 is_imp = 1;
1193 reloc_count += sec->reloc_count;
1194 }
1195
1196 if (is_imp && !idata2 && reloc_count)
1197 {
1198 /* It is, look for the reference to head and see if it's
1199 from our own library. */
1200 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1201 {
1202 int i;
1203 long relsize;
1204 asymbol **symbols;
1205 arelent **relocs;
1206 int nrelocs;
1207
1208 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1209 if (relsize < 1)
1210 break;
1211
1212 if (!bfd_generic_link_read_symbols (is->the_bfd))
1213 {
1214 einfo (_("%B%F: could not read symbols: %E\n"),
1215 is->the_bfd);
1216 return;
1217 }
1218 symbols = bfd_get_outsymbols (is->the_bfd);
1219
1220 relocs = xmalloc ((size_t) relsize);
1221 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1222 relocs, symbols);
1223 if (nrelocs < 0)
1224 {
1225 free (relocs);
1226 einfo ("%X%P: unable to process relocs: %E\n");
1227 return;
1228 }
1229
1230 for (i = 0; i < nrelocs; i++)
1231 {
1232 struct bfd_symbol *s;
1233 struct bfd_link_hash_entry * blhe;
1234 char *other_bfd_filename;
1235 char *n;
1236
1237 s = (relocs[i]->sym_ptr_ptr)[0];
1238
1239 if (s->flags & BSF_LOCAL)
1240 continue;
1241
1242 /* Thunk section with reloc to another bfd. */
1243 blhe = bfd_link_hash_lookup (link_info.hash,
1244 s->name,
1245 FALSE, FALSE, TRUE);
1246
1247 if (blhe == NULL
1248 || blhe->type != bfd_link_hash_defined)
1249 continue;
1250
1251 other_bfd_filename
1252 = blhe->u.def.section->owner->my_archive
1253 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1254 : bfd_get_filename (blhe->u.def.section->owner);
1255
1256 if (strcmp (bfd_get_filename (is->the_bfd->my_archive),
1257 other_bfd_filename) == 0)
1258 continue;
1259
1260 /* Rename this implib to match the other one. */
1261 n = xmalloc (strlen (other_bfd_filename) + 1);
1262 strcpy (n, other_bfd_filename);
1263 is->the_bfd->my_archive->filename = n;
1264 }
1265
1266 free (relocs);
1267 /* Note - we do not free the symbols,
1268 they are now cached in the BFD. */
1269 }
1270 }
1271 }
1272 }
1273 }
1274
1275 {
1276 int is_ms_arch = 0;
1277 bfd *cur_arch = 0;
1278 lang_input_statement_type *is2;
1279 lang_input_statement_type *is3;
1280
1281 /* Careful - this is a shell script. Watch those dollar signs! */
1282 /* Microsoft import libraries have every member named the same,
1283 and not in the right order for us to link them correctly. We
1284 must detect these and rename the members so that they'll link
1285 correctly. There are three types of objects: the head, the
1286 thunks, and the sentinel(s). The head is easy; it's the one
1287 with idata2. We assume that the sentinels won't have relocs,
1288 and the thunks will. It's easier than checking the symbol
1289 table for external references. */
1290 LANG_FOR_EACH_INPUT_STATEMENT (is)
1291 {
1292 if (is->the_bfd->my_archive)
1293 {
1294 char *pnt;
1295 bfd *arch = is->the_bfd->my_archive;
1296
1297 if (cur_arch != arch)
1298 {
1299 cur_arch = arch;
1300 is_ms_arch = 1;
1301
1302 for (is3 = is;
1303 is3 && is3->the_bfd->my_archive == arch;
1304 is3 = (lang_input_statement_type *) is3->next)
1305 {
1306 /* A MS dynamic import library can also contain static
1307 members, so look for the first element with a .dll
1308 extension, and use that for the remainder of the
1309 comparisons. */
1310 pnt = strrchr (is3->the_bfd->filename, '.');
1311 if (pnt != NULL && strcmp (pnt, ".dll") == 0)
1312 break;
1313 }
1314
1315 if (is3 == NULL)
1316 is_ms_arch = 0;
1317 else
1318 {
1319 /* OK, found one. Now look to see if the remaining
1320 (dynamic import) members use the same name. */
1321 for (is2 = is;
1322 is2 && is2->the_bfd->my_archive == arch;
1323 is2 = (lang_input_statement_type *) is2->next)
1324 {
1325 /* Skip static members, ie anything with a .obj
1326 extension. */
1327 pnt = strrchr (is2->the_bfd->filename, '.');
1328 if (pnt != NULL && strcmp (pnt, ".obj") == 0)
1329 continue;
1330
1331 if (strcmp (is3->the_bfd->filename,
1332 is2->the_bfd->filename))
1333 {
1334 is_ms_arch = 0;
1335 break;
1336 }
1337 }
1338 }
1339 }
1340
1341 /* This fragment might have come from an .obj file in a Microsoft
1342 import, and not an actual import record. If this is the case,
1343 then leave the filename alone. */
1344 pnt = strrchr (is->the_bfd->filename, '.');
1345
1346 if (is_ms_arch && (strcmp (pnt, ".dll") == 0))
1347 {
1348 int idata2 = 0, reloc_count=0;
1349 asection *sec;
1350 char *new_name, seq;
1351
1352 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1353 {
1354 if (strcmp (sec->name, ".idata\$2") == 0)
1355 idata2 = 1;
1356 reloc_count += sec->reloc_count;
1357 }
1358
1359 if (idata2) /* .idata2 is the TOC */
1360 seq = 'a';
1361 else if (reloc_count > 0) /* thunks */
1362 seq = 'b';
1363 else /* sentinel */
1364 seq = 'c';
1365
1366 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1367 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1368 is->the_bfd->filename = new_name;
1369
1370 new_name = xmalloc (strlen (is->filename) + 3);
1371 sprintf (new_name, "%s.%c", is->filename, seq);
1372 is->filename = new_name;
1373 }
1374 }
1375 }
1376 }
1377 }
1378 \f
1379 static void
1380 gld_${EMULATION_NAME}_before_allocation (void)
1381 {
1382 before_allocation_default ();
1383 }
1384 \f
1385 #ifdef DLL_SUPPORT
1386 /* This is called when an input file isn't recognized as a BFD. We
1387 check here for .DEF files and pull them in automatically. */
1388
1389 static int
1390 saw_option (char *option)
1391 {
1392 int i;
1393
1394 for (i = 0; init[i].ptr; i++)
1395 if (strcmp (init[i].symbol, option) == 0)
1396 return init[i].inited;
1397 return 0;
1398 }
1399 #endif /* DLL_SUPPORT */
1400
1401 static bfd_boolean
1402 gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1403 {
1404 #ifdef DLL_SUPPORT
1405 const char *ext = entry->filename + strlen (entry->filename) - 4;
1406
1407 if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
1408 {
1409 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1410
1411 if (pep_def_file)
1412 {
1413 int i, buflen=0, len;
1414 char *buf;
1415
1416 for (i = 0; i < pep_def_file->num_exports; i++)
1417 {
1418 len = strlen (pep_def_file->exports[i].internal_name);
1419 if (buflen < len + 2)
1420 buflen = len + 2;
1421 }
1422
1423 buf = xmalloc (buflen);
1424
1425 for (i = 0; i < pep_def_file->num_exports; i++)
1426 {
1427 struct bfd_link_hash_entry *h;
1428
1429 sprintf (buf, "_%s", pep_def_file->exports[i].internal_name);
1430
1431 h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
1432 if (h == (struct bfd_link_hash_entry *) NULL)
1433 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1434 if (h->type == bfd_link_hash_new)
1435 {
1436 h->type = bfd_link_hash_undefined;
1437 h->u.undef.abfd = NULL;
1438 bfd_link_add_undef (link_info.hash, h);
1439 }
1440 }
1441 free (buf);
1442
1443 /* def_file_print (stdout, pep_def_file); */
1444 if (pep_def_file->is_dll == 1)
1445 link_info.shared = 1;
1446
1447 if (pep_def_file->base_address != (bfd_vma)(-1))
1448 {
1449 pep.ImageBase
1450 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1451 = init[IMAGEBASEOFF].value
1452 = pep_def_file->base_address;
1453 init[IMAGEBASEOFF].inited = 1;
1454 if (image_base_statement)
1455 image_base_statement->exp = exp_assop ('=', "__image_base__",
1456 exp_intop (pep.ImageBase));
1457 }
1458
1459 if (pep_def_file->stack_reserve != -1
1460 && ! saw_option ("__size_of_stack_reserve__"))
1461 {
1462 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1463 if (pep_def_file->stack_commit != -1)
1464 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1465 }
1466 if (pep_def_file->heap_reserve != -1
1467 && ! saw_option ("__size_of_heap_reserve__"))
1468 {
1469 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1470 if (pep_def_file->heap_commit != -1)
1471 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1472 }
1473 return TRUE;
1474 }
1475 }
1476 #endif
1477 return FALSE;
1478 }
1479
1480 static bfd_boolean
1481 gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1482 {
1483 #ifdef DLL_SUPPORT
1484 #ifdef TARGET_IS_i386pep
1485 pep_dll_id_target ("pei-x86-64");
1486 #endif
1487 if (pep_bfd_is_dll (entry->the_bfd))
1488 return pep_implied_import_dll (entry->filename);
1489 #endif
1490 return FALSE;
1491 }
1492
1493 static void
1494 gld_${EMULATION_NAME}_finish (void)
1495 {
1496 finish_default ();
1497
1498 #ifdef DLL_SUPPORT
1499 if (link_info.shared
1500 || (!link_info.relocatable && pep_def_file->num_exports != 0))
1501 {
1502 pep_dll_fill_sections (link_info.output_bfd, &link_info);
1503 if (pep_implib_filename)
1504 pep_dll_generate_implib (pep_def_file, pep_implib_filename, &link_info);
1505 }
1506
1507 if (pep_out_def_filename)
1508 pep_dll_generate_def_file (pep_out_def_filename);
1509 #endif /* DLL_SUPPORT */
1510
1511 /* I don't know where .idata gets set as code, but it shouldn't be. */
1512 {
1513 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1514
1515 if (asec)
1516 {
1517 asec->flags &= ~SEC_CODE;
1518 asec->flags |= SEC_DATA;
1519 }
1520 }
1521 }
1522
1523 \f
1524 /* Place an orphan section.
1525
1526 We use this to put sections in a reasonable place in the file, and
1527 to ensure that they are aligned as required.
1528
1529 We handle grouped sections here as well. A section named .foo\$nn
1530 goes into the output section .foo. All grouped sections are sorted
1531 by name.
1532
1533 Grouped sections for the default sections are handled by the
1534 default linker script using wildcards, and are sorted by
1535 sort_sections. */
1536
1537 static lang_output_section_statement_type *
1538 gld_${EMULATION_NAME}_place_orphan (asection *s,
1539 const char *secname,
1540 int constraint)
1541 {
1542 const char *orig_secname = secname;
1543 char *dollar = NULL;
1544 lang_output_section_statement_type *os;
1545 lang_statement_list_type add_child;
1546 lang_statement_union_type **pl;
1547
1548 /* Look through the script to see where to place this section. */
1549 if (!link_info.relocatable
1550 && (dollar = strchr (secname, '\$')) != NULL)
1551 {
1552 size_t len = dollar - secname;
1553 char *newname = xmalloc (len + 1);
1554 memcpy (newname, secname, len);
1555 newname[len] = '\0';
1556 secname = newname;
1557 }
1558
1559 lang_list_init (&add_child);
1560
1561 os = NULL;
1562 if (constraint == 0)
1563 for (os = lang_output_section_find (secname);
1564 os != NULL;
1565 os = next_matching_output_section_statement (os, 0))
1566 {
1567 /* If we don't match an existing output section, tell
1568 lang_insert_orphan to create a new output section. */
1569 constraint = SPECIAL;
1570
1571 if (os->bfd_section != NULL
1572 && (os->bfd_section->flags == 0
1573 || ((s->flags ^ os->bfd_section->flags)
1574 & (SEC_LOAD | SEC_ALLOC)) == 0))
1575 {
1576 /* We already have an output section statement with this
1577 name, and its bfd section has compatible flags.
1578 If the section already exists but does not have any flags set,
1579 then it has been created by the linker, probably as a result of
1580 a --section-start command line switch. */
1581 lang_add_section (&add_child, s, os);
1582 break;
1583 }
1584 }
1585
1586 if (os == NULL)
1587 {
1588 static struct orphan_save hold[] =
1589 {
1590 { ".text",
1591 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1592 0, 0, 0, 0 },
1593 { ".rdata",
1594 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1595 0, 0, 0, 0 },
1596 { ".data",
1597 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1598 0, 0, 0, 0 },
1599 { ".bss",
1600 SEC_ALLOC,
1601 0, 0, 0, 0 }
1602 };
1603 enum orphan_save_index
1604 {
1605 orphan_text = 0,
1606 orphan_rodata,
1607 orphan_data,
1608 orphan_bss
1609 };
1610 static int orphan_init_done = 0;
1611 struct orphan_save *place;
1612 lang_output_section_statement_type *after;
1613 etree_type *address;
1614
1615 if (!orphan_init_done)
1616 {
1617 struct orphan_save *ho;
1618 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1619 if (ho->name != NULL)
1620 {
1621 ho->os = lang_output_section_find (ho->name);
1622 if (ho->os != NULL && ho->os->flags == 0)
1623 ho->os->flags = ho->flags;
1624 }
1625 orphan_init_done = 1;
1626 }
1627
1628 /* Try to put the new output section in a reasonable place based
1629 on the section name and section flags. */
1630
1631 place = NULL;
1632 if ((s->flags & SEC_ALLOC) == 0)
1633 ;
1634 else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1635 place = &hold[orphan_bss];
1636 else if ((s->flags & SEC_READONLY) == 0)
1637 place = &hold[orphan_data];
1638 else if ((s->flags & SEC_CODE) == 0)
1639 place = &hold[orphan_rodata];
1640 else
1641 place = &hold[orphan_text];
1642
1643 after = NULL;
1644 if (place != NULL)
1645 {
1646 if (place->os == NULL)
1647 place->os = lang_output_section_find (place->name);
1648 after = place->os;
1649 if (after == NULL)
1650 after = lang_output_section_find_by_flags (s, &place->os, NULL);
1651 if (after == NULL)
1652 /* *ABS* is always the first output section statement. */
1653 after = (&lang_output_section_statement.head
1654 ->output_section_statement);
1655 }
1656
1657 /* All sections in an executable must be aligned to a page boundary. */
1658 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
1659 os = lang_insert_orphan (s, secname, constraint, after, place, address,
1660 &add_child);
1661 }
1662
1663 /* If the section name has a '\$', sort it with the other '\$'
1664 sections. */
1665 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
1666 {
1667 lang_input_section_type *ls;
1668 const char *lname;
1669
1670 if ((*pl)->header.type != lang_input_section_enum)
1671 continue;
1672
1673 ls = &(*pl)->input_section;
1674
1675 lname = bfd_get_section_name (ls->section->owner, ls->section);
1676 if (strchr (lname, '\$') != NULL
1677 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
1678 break;
1679 }
1680
1681 if (add_child.head != NULL)
1682 {
1683 *add_child.tail = *pl;
1684 *pl = add_child.head;
1685 }
1686
1687 return os;
1688 }
1689
1690 static bfd_boolean
1691 gld_${EMULATION_NAME}_open_dynamic_archive
1692 (const char *arch ATTRIBUTE_UNUSED,
1693 search_dirs_type *search,
1694 lang_input_statement_type *entry)
1695 {
1696 static const struct
1697 {
1698 const char * format;
1699 bfd_boolean use_prefix;
1700 }
1701 libname_fmt [] =
1702 {
1703 /* Preferred explicit import library for dll's. */
1704 { "lib%s.dll.a", FALSE },
1705 /* Alternate explicit import library for dll's. */
1706 { "%s.dll.a", FALSE },
1707 /* "libfoo.a" could be either an import lib or a static lib.
1708 For backwards compatibility, libfoo.a needs to precede
1709 libfoo.dll and foo.dll in the search. */
1710 { "lib%s.a", FALSE },
1711 /* The 'native' spelling of an import lib name is "foo.lib". */
1712 { "%s.lib", FALSE },
1713 #ifdef DLL_SUPPORT
1714 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
1715 { "%s%s.dll", TRUE },
1716 #endif
1717 /* Try "libfoo.dll" (default preferred dll name). */
1718 { "lib%s.dll", FALSE },
1719 /* Finally try 'native' dll name "foo.dll". */
1720 { "%s.dll", FALSE },
1721 /* Note: If adding more formats to this table, make sure to check to
1722 see if their length is longer than libname_fmt[0].format, and if
1723 so, update the call to xmalloc() below. */
1724 { NULL, FALSE }
1725 };
1726 static unsigned int format_max_len = 0;
1727 const char * filename;
1728 char * full_string;
1729 char * base_string;
1730 unsigned int i;
1731
1732
1733 if (! entry->is_archive)
1734 return FALSE;
1735
1736 filename = entry->filename;
1737
1738 if (format_max_len == 0)
1739 /* We need to allow space in the memory that we are going to allocate
1740 for the characters in the format string. Since the format array is
1741 static we only need to calculate this information once. In theory
1742 this value could also be computed statically, but this introduces
1743 the possibility for a discrepancy and hence a possible memory
1744 corruption. The lengths we compute here will be too long because
1745 they will include any formating characters (%s) in the strings, but
1746 this will not matter. */
1747 for (i = 0; libname_fmt[i].format; i++)
1748 if (format_max_len < strlen (libname_fmt[i].format))
1749 format_max_len = strlen (libname_fmt[i].format);
1750
1751 full_string = xmalloc (strlen (search->name)
1752 + strlen (filename)
1753 + format_max_len
1754 #ifdef DLL_SUPPORT
1755 + (pep_dll_search_prefix
1756 ? strlen (pep_dll_search_prefix) : 0)
1757 #endif
1758 /* Allow for the terminating NUL and for the path
1759 separator character that is inserted between
1760 search->name and the start of the format string. */
1761 + 2);
1762
1763 sprintf (full_string, "%s/", search->name);
1764 base_string = full_string + strlen (full_string);
1765
1766 for (i = 0; libname_fmt[i].format; i++)
1767 {
1768 #ifdef DLL_SUPPORT
1769 if (libname_fmt[i].use_prefix)
1770 {
1771 if (!pep_dll_search_prefix)
1772 continue;
1773 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
1774 }
1775 else
1776 #endif
1777 sprintf (base_string, libname_fmt[i].format, filename);
1778
1779 if (ldfile_try_open_bfd (full_string, entry))
1780 break;
1781 }
1782
1783 if (!libname_fmt[i].format)
1784 {
1785 free (full_string);
1786 return FALSE;
1787 }
1788
1789 entry->filename = full_string;
1790
1791 return TRUE;
1792 }
1793
1794 static int
1795 gld_${EMULATION_NAME}_find_potential_libraries
1796 (char *name, lang_input_statement_type *entry)
1797 {
1798 return ldfile_open_file_search (name, entry, "", ".lib");
1799 }
1800 \f
1801 static char *
1802 gld_${EMULATION_NAME}_get_script (int *isfile)
1803 EOF
1804 # Scripts compiled in.
1805 # sed commands to quote an ld script as a C string.
1806 sc="-f stringify.sed"
1807
1808 fragment <<EOF
1809 {
1810 *isfile = 0;
1811
1812 if (link_info.relocatable && config.build_constructors)
1813 return
1814 EOF
1815 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
1816 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
1817 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
1818 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
1819 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
1820 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
1821 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
1822 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
1823 echo ' ; else if (link_info.pei386_auto_import == 1) return' >> e${EMULATION_NAME}.c
1824 sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
1825 fi
1826 echo ' ; else return' >> e${EMULATION_NAME}.c
1827 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
1828 echo '; }' >> e${EMULATION_NAME}.c
1829
1830 fragment <<EOF
1831
1832
1833 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1834 {
1835 gld_${EMULATION_NAME}_before_parse,
1836 syslib_default,
1837 hll_default,
1838 gld_${EMULATION_NAME}_after_parse,
1839 gld_${EMULATION_NAME}_after_open,
1840 after_allocation_default,
1841 set_output_arch_default,
1842 ldemul_default_target,
1843 gld_${EMULATION_NAME}_before_allocation,
1844 gld_${EMULATION_NAME}_get_script,
1845 "${EMULATION_NAME}",
1846 "${OUTPUT_FORMAT}",
1847 gld_${EMULATION_NAME}_finish,
1848 NULL, /* Create output section statements. */
1849 gld_${EMULATION_NAME}_open_dynamic_archive,
1850 gld_${EMULATION_NAME}_place_orphan,
1851 gld_${EMULATION_NAME}_set_symbols,
1852 NULL, /* parse_args */
1853 gld${EMULATION_NAME}_add_options,
1854 gld${EMULATION_NAME}_handle_option,
1855 gld_${EMULATION_NAME}_unrecognized_file,
1856 gld_${EMULATION_NAME}_list_options,
1857 gld_${EMULATION_NAME}_recognized_file,
1858 gld_${EMULATION_NAME}_find_potential_libraries,
1859 NULL /* new_vers_pattern. */
1860 };
1861 EOF
This page took 0.092584 seconds and 5 git commands to generate.