]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/pep.em
Regenerate rl78 opcodes file
[thirdparty/binutils-gdb.git] / ld / emultempl / pep.em
CommitLineData
99ad8390
NC
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
99ad8390
NC
3if [ -z "$MACHINE" ]; then
4 OUTPUT_ARCH=${ARCH}
5else
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
7fi
a07ee50e
CV
8
9case ${target} in
10 *-*-cygwin*)
11 move_default_addr_high=1
12 ;;
13 *)
14 move_default_addr_high=0;
15 ;;
16esac
17
99ad8390
NC
18rm -f e${EMULATION_NAME}.c
19(echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
92b93329 20fragment <<EOF
6f2750fe 21/* Copyright (C) 2006-2016 Free Software Foundation, Inc.
f96b4a7b
NC
22 Written by Kai Tietz, OneVision Software GmbH&CoKg.
23
24 This file is part of the GNU Binutils.
99ad8390
NC
25
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
f96b4a7b 28 the Free Software Foundation; either version 3 of the License, or
99ad8390
NC
29 (at your option) any later version.
30
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.
35
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
f96b4a7b
NC
38 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
39 MA 02110-1301, USA. */
40
99ad8390
NC
41
42/* For WINDOWS_XP64 and higher */
43/* Based on pe.em, but modified for 64 bit support. */
44
45#define TARGET_IS_${EMULATION_NAME}
46
47#define COFF_IMAGE_WITH_PE
48#define COFF_WITH_PE
49#define COFF_WITH_pex64
50
99ad8390 51#include "sysdep.h"
3db64b00 52#include "bfd.h"
99ad8390
NC
53#include "bfdlink.h"
54#include "getopt.h"
55#include "libiberty.h"
42627821 56#include "filenames.h"
99ad8390
NC
57#include "ld.h"
58#include "ldmain.h"
59#include "ldexp.h"
60#include "ldlang.h"
61#include "ldfile.h"
62#include "ldemul.h"
63#include <ldgram.h>
64#include "ldlex.h"
65#include "ldmisc.h"
66#include "ldctor.h"
61e2488c 67#include "ldbuildid.h"
99ad8390
NC
68#include "coff/internal.h"
69
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"
73#include "coff/pe.h"
74
61e2488c 75/* FIXME: These are BFD internal header files, and we should not be
99ad8390
NC
76 using it here. */
77#include "../bfd/libcoff.h"
61e2488c 78#include "../bfd/libpei.h"
99ad8390
NC
79
80#undef AOUTSZ
81#define AOUTSZ PEPAOUTSZ
82#define PEAOUTHDR PEPAOUTHDR
83
84#include "deffile.h"
85#include "pep-dll.h"
86#include "safe-ctype.h"
87
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}
95#endif
96
97#ifdef TARGET_IS_i386pep
98#define DLL_SUPPORT
99#endif
100
101#if defined(TARGET_IS_i386pep) || ! defined(DLL_SUPPORT)
102#define PE_DEF_SUBSYSTEM 3
a07ee50e
CV
103#undef NT_EXE_IMAGE_BASE
104#define NT_EXE_IMAGE_BASE \
105 ((bfd_vma) (${move_default_addr_high} ? 0x100400000LL \
106 : 0x400000LL))
107#undef NT_DLL_IMAGE_BASE
108#define NT_DLL_IMAGE_BASE \
109 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
110 : 0x10000000LL))
111#undef NT_DLL_AUTO_IMAGE_BASE
112#define NT_DLL_AUTO_IMAGE_BASE \
113 ((bfd_vma) (${move_default_addr_high} ? 0x400000000LL \
114 : 0x61300000LL))
115#undef NT_DLL_AUTO_IMAGE_MASK
116#define NT_DLL_AUTO_IMAGE_MASK \
117 ((bfd_vma) (${move_default_addr_high} ? 0x1ffff0000LL \
118 : 0x0ffc0000LL))
99ad8390
NC
119#else
120#undef NT_EXE_IMAGE_BASE
a07ee50e
CV
121#define NT_EXE_IMAGE_BASE \
122 ((bfd_vma) (${move_default_addr_high} ? 0x100010000LL \
123 : 0x10000LL))
124#undef NT_DLL_IMAGE_BASE
125#define NT_DLL_IMAGE_BASE \
126 ((bfd_vma) (${move_default_addr_high} ? 0x110000000LL \
127 : 0x10000000LL))
128#undef NT_DLL_AUTO_IMAGE_BASE
129#define NT_DLL_AUTO_IMAGE_BASE \
130 ((bfd_vma) (${move_default_addr_high} ? 0x120000000LL \
131 : 0x61300000LL))
132#undef NT_DLL_AUTO_IMAGE_MASK
133#define NT_DLL_AUTO_IMAGE_MASK \
134 ((bfd_vma) (${move_default_addr_high} ? 0x0ffff0000LL \
135 : 0x0ffc0000LL))
99ad8390
NC
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
141#endif
142
99ad8390
NC
143static struct internal_extra_pe_aouthdr pep;
144static int dll;
decfa41e 145static int pep_subsystem = ${SUBSYSTEM};
99ad8390
NC
146static flagword real_flags = IMAGE_FILE_LARGE_ADDRESS_AWARE;
147static int support_old_code = 0;
148static lang_assignment_statement_type *image_base_statement = 0;
2f563b51 149static unsigned short pe_dll_characteristics = 0;
eeb14e5a 150static bfd_boolean insert_timestamp = TRUE;
61e2488c 151static const char *emit_build_id;
99ad8390
NC
152
153#ifdef DLL_SUPPORT
880383ca 154static int pep_enable_stdcall_fixup = 1; /* 0=disable 1=enable (default). */
99ad8390
NC
155static char * pep_out_def_filename = NULL;
156static char * pep_implib_filename = NULL;
157static int pep_enable_auto_image_base = 0;
158static char * pep_dll_search_prefix = NULL;
159#endif
160
161extern const char *output_filename;
162
d74720d2 163static int is_underscoring (void)
99ad8390 164{
d74720d2
KT
165 int u = 0;
166 if (pep_leading_underscore != -1)
167 return pep_leading_underscore;
168 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
b804e4af
KT
169 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
170
171 if (u == -1)
172 abort ();
d74720d2
KT
173 pep_leading_underscore = (u != 0 ? 1 : 0);
174 return pep_leading_underscore;
175}
b804e4af 176
d74720d2
KT
177
178static void
179gld_${EMULATION_NAME}_before_parse (void)
180{
181 is_underscoring ();
99ad8390
NC
182 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
183 output_filename = "${EXECUTABLE_NAME:-a.exe}";
184#ifdef DLL_SUPPORT
66be1055 185 input_flags.dynamic = TRUE;
99ad8390 186 config.has_shared = 1;
6ec6c79c 187 link_info.pei386_auto_import = 1;
6cb442d3 188 link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2. */
99ad8390
NC
189#endif
190}
191\f
192/* PE format extra command line options. */
193
194/* Used for setting flags in the PE header. */
195enum options
196{
197 OPTION_BASE_FILE = 300 + 1,
198 OPTION_DLL,
199 OPTION_FILE_ALIGNMENT,
200 OPTION_IMAGE_BASE,
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,
208 OPTION_STACK,
209 OPTION_SUBSYSTEM,
210 OPTION_HEAP,
211 OPTION_SUPPORT_OLD_CODE,
212 OPTION_OUT_DEF,
213 OPTION_EXPORT_ALL,
214 OPTION_EXCLUDE_SYMBOLS,
2927aaca 215 OPTION_EXCLUDE_ALL_SYMBOLS,
99ad8390
NC
216 OPTION_KILL_ATS,
217 OPTION_STDCALL_ALIASES,
218 OPTION_ENABLE_STDCALL_FIXUP,
219 OPTION_DISABLE_STDCALL_FIXUP,
220 OPTION_IMPLIB_FILENAME,
221 OPTION_WARN_DUPLICATE_EXPORTS,
222 OPTION_IMP_COMPAT,
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,
230 OPTION_EXCLUDE_LIBS,
231 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
6cb442d3 232 OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
e1c37eb5 233 OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
ce11ba6c 234 OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
88183869 235 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
522f09cd
KT
236 OPTION_NO_LEADING_UNDERSCORE,
237 OPTION_LEADING_UNDERSCORE,
88183869 238 OPTION_ENABLE_LONG_SECTION_NAMES,
2f563b51 239 OPTION_DISABLE_LONG_SECTION_NAMES,
2d5c3743 240 OPTION_HIGH_ENTROPY_VA,
2f563b51
DK
241 OPTION_DYNAMIC_BASE,
242 OPTION_FORCE_INTEGRITY,
243 OPTION_NX_COMPAT,
244 OPTION_NO_ISOLATION,
245 OPTION_NO_SEH,
246 OPTION_NO_BIND,
247 OPTION_WDM_DRIVER,
0cb112f7 248 OPTION_INSERT_TIMESTAMP,
eeb14e5a 249 OPTION_NO_INSERT_TIMESTAMP,
61e2488c
JT
250 OPTION_TERMINAL_SERVER_AWARE,
251 OPTION_BUILD_ID
99ad8390
NC
252};
253
254static void
255gld${EMULATION_NAME}_add_options
256 (int ns ATTRIBUTE_UNUSED,
257 char **shortopts ATTRIBUTE_UNUSED,
258 int nl,
259 struct option **longopts,
260 int nrl ATTRIBUTE_UNUSED,
261 struct option **really_longopts ATTRIBUTE_UNUSED)
262{
263 static const struct option xtra_long[] =
264 {
265 /* PE options */
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},
ce11ba6c
KT
281 {"use-nul-prefixed-import-tables", no_argument, NULL,
282 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
522f09cd
KT
283 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
284 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
99ad8390
NC
285#ifdef DLL_SUPPORT
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},
2927aaca 292 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
99ad8390 293 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
e1c37eb5 294 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
99ad8390
NC
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},
6cb442d3 314 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
99ad8390 315#endif
88183869
DK
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},
2d5c3743 318 {"high-entropy-va", no_argument, NULL, OPTION_HIGH_ENTROPY_VA},
2f563b51
DK
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},
d127ecce 326 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
0cb112f7 327 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
eeb14e5a 328 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
61e2488c 329 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
d127ecce 330 {NULL, no_argument, NULL, 0}
99ad8390
NC
331 };
332
d127ecce
AM
333 *longopts
334 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
99ad8390
NC
335 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
336}
337
338/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
339 parameters which may be input from the command line. */
340
341typedef struct
342{
343 void *ptr;
344 int size;
0ead4f8d 345 bfd_vma value;
99ad8390
NC
346 char *symbol;
347 int inited;
522f09cd
KT
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
350 settings. */
351 bfd_boolean is_c_symbol;
99ad8390
NC
352} definfo;
353
522f09cd
KT
354#define GET_INIT_SYMBOL_NAME(IDX) \
355 (init[(IDX)].symbol \
d74720d2 356 + ((init[(IDX)].is_c_symbol == FALSE || (is_underscoring () == 1)) ? 0 : 1))
522f09cd
KT
357
358/* Decorates the C visible symbol by underscore, if target requires. */
359#define U(CSTR) \
d74720d2 360 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
522f09cd
KT
361
362/* Get size of constant string for a possible underscore prefixed
363 C visible symbol. */
364#define U_SIZE(CSTR) \
d74720d2 365 (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
522f09cd 366
61e2488c 367#define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
99ad8390
NC
368
369static definfo init[] =
370{
371 /* imagebase must be first */
372#define IMAGEBASEOFF 0
522f09cd 373 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, FALSE),
99ad8390 374#define DLLOFF 1
522f09cd 375 {&dll, sizeof(dll), 0, "__dll__", 0, FALSE},
99ad8390 376#define MSIMAGEBASEOFF 2
522f09cd
KT
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}
99ad8390
NC
394};
395
396
397static void
398gld_${EMULATION_NAME}_list_options (FILE *file)
399{
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"));
522f09cd 415 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
eeb14e5a 416 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero. (default)\n"));
0cb112f7 417 fprintf (file, _(" This makes binaries non-deterministic\n"));
99ad8390
NC
418#ifdef DLL_SUPPORT
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"));
2927aaca 423 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
99ad8390 424 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
e1c37eb5
DK
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"));
99ad8390
NC
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"));
c85f715a 441 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
99ad8390
NC
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\
446 runtime.\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"));
88183869
DK
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"));
2d5c3743
NC
455 fprintf (file, _(" --high-entropy-va Image is compatible with 64-bit address space\n\
456 layout randomization (ASLR)\n"));
2f563b51
DK
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"));
d127ecce 464 fprintf (file, _(" --no-bind Do not bind this image\n"));
2f563b51 465 fprintf (file, _(" --wdmdriver Driver uses the WDM model\n"));
522f09cd 466 fprintf (file, _(" --tsaware Image is Terminal Server aware\n"));
61e2488c 467 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
99ad8390
NC
468#endif
469}
470
471
472static void
0ead4f8d 473set_pep_name (char *name, bfd_vma val)
99ad8390 474{
d74720d2
KT
475 int i;
476 is_underscoring ();
99ad8390
NC
477 /* Find the name and set it. */
478 for (i = 0; init[i].ptr; i++)
479 {
522f09cd 480 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
99ad8390
NC
481 {
482 init[i].value = val;
483 init[i].inited = 1;
484 if (strcmp (name,"__image_base__") == 0)
522f09cd 485 set_pep_name (U ("__ImageBase"), val);
99ad8390
NC
486 return;
487 }
488 }
489 abort ();
490}
491
decfa41e
KT
492static void
493set_entry_point (void)
494{
495 const char *entry;
496 const char *initial_symbol_char;
d74720d2 497 int i;
decfa41e
KT
498
499 static const struct
500 {
501 const int value;
502 const char *entry;
503 }
504 v[] =
505 {
506 { 1, "NtProcessStartup" },
507 { 2, "WinMainCRTStartup" },
508 { 3, "mainCRTStartup" },
509 { 7, "__PosixProcessStartup" },
510 { 9, "WinMainCRTStartup" },
511 {14, "mainCRTStartup" },
512 { 0, NULL }
513 };
514
515 /* Entry point name for arbitrary subsystem numbers. */
516 static const char default_entry[] = "mainCRTStartup";
517
0e1862bb 518 if (bfd_link_pic (&link_info) || dll)
decfa41e
KT
519 {
520 entry = "DllMainCRTStartup";
521 }
522 else
523 {
524 for (i = 0; v[i].entry; i++)
525 if (v[i].value == pep_subsystem)
526 break;
527
528 /* If no match, use the default. */
529 if (v[i].entry != NULL)
530 entry = v[i].entry;
531 else
532 entry = default_entry;
533 }
534
522f09cd 535 /* Now we check target's default for getting proper symbol_char. */
d74720d2 536 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
522f09cd 537
decfa41e
KT
538 if (*initial_symbol_char != '\0')
539 {
540 char *alc_entry;
541
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)
545 + strlen (entry)
546 + 1);
547 strcpy (alc_entry, initial_symbol_char);
548 strcat (alc_entry, entry);
549 entry = alc_entry;
550 }
551
552 lang_default_entry (entry);
553}
99ad8390
NC
554
555static void
556set_pep_subsystem (void)
557{
558 const char *sver;
99ad8390
NC
559 char *end;
560 int len;
561 int i;
99ad8390
NC
562 unsigned long temp_subsystem;
563 static const struct
564 {
565 const char *name;
566 const int value;
99ad8390
NC
567 }
568 v[] =
569 {
decfa41e
KT
570 { "native", 1 },
571 { "windows", 2 },
572 { "console", 3 },
573 { "posix", 7 },
574 { "wince", 9 },
575 { "xbox", 14 },
576 { NULL, 0 }
99ad8390 577 };
99ad8390
NC
578
579 /* Check for the presence of a version number. */
580 sver = strchr (optarg, ':');
581 if (sver == NULL)
582 len = strlen (optarg);
583 else
584 {
585 len = sver - optarg;
586 set_pep_name ("__major_subsystem_version__",
587 strtoul (sver + 1, &end, 0));
588 if (*end == '.')
589 set_pep_name ("__minor_subsystem_version__",
590 strtoul (end + 1, &end, 0));
591 if (*end != '\0')
592 einfo (_("%P: warning: bad version number in -subsystem option\n"));
593 }
594
595 /* Check for numeric subsystem. */
596 temp_subsystem = strtoul (optarg, & end, 0);
597 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
598 {
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)
602 break;
603
99ad8390 604 /* Use this subsystem. */
decfa41e 605 pep_subsystem = (int) temp_subsystem;
99ad8390
NC
606 }
607 else
608 {
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')
613 break;
614
615 if (v[i].name == NULL)
616 {
617 einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
618 return;
619 }
620
decfa41e 621 pep_subsystem = v[i].value;
99ad8390
NC
622 }
623
decfa41e 624 set_pep_name ("__subsystem__", pep_subsystem);
99ad8390
NC
625
626 return;
627}
628
629
630static void
631set_pep_value (char *name)
632{
633 char *end;
634
0ead4f8d 635 set_pep_name (name, (bfd_vma) strtoull (optarg, &end, 0));
99ad8390
NC
636
637 if (end == optarg)
638 einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
639
640 optarg = end;
641}
642
643
644static void
645set_pep_stack_heap (char *resname, char *comname)
646{
647 set_pep_value (resname);
648
649 if (*optarg == ',')
650 {
651 optarg++;
652 set_pep_value (comname);
653 }
654 else if (*optarg)
655 einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
656}
657
61e2488c 658#define DEFAULT_BUILD_ID_STYLE "md5"
99ad8390
NC
659
660static bfd_boolean
661gld${EMULATION_NAME}_handle_option (int optc)
662{
d74720d2 663 is_underscoring ();
99ad8390
NC
664 switch (optc)
665 {
666 default:
667 return FALSE;
668
669 case OPTION_BASE_FILE:
670 link_info.base_file = fopen (optarg, FOPEN_WB);
671 if (link_info.base_file == NULL)
e922bcab 672 einfo (_("%F%P: cannot open base file %s\n"), optarg);
99ad8390
NC
673 break;
674
675 /* PE options. */
676 case OPTION_HEAP:
677 set_pep_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
678 break;
679 case OPTION_STACK:
680 set_pep_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
681 break;
682 case OPTION_SUBSYSTEM:
683 set_pep_subsystem ();
684 break;
685 case OPTION_MAJOR_OS_VERSION:
686 set_pep_value ("__major_os_version__");
687 break;
688 case OPTION_MINOR_OS_VERSION:
689 set_pep_value ("__minor_os_version__");
690 break;
691 case OPTION_MAJOR_SUBSYSTEM_VERSION:
692 set_pep_value ("__major_subsystem_version__");
693 break;
694 case OPTION_MINOR_SUBSYSTEM_VERSION:
695 set_pep_value ("__minor_subsystem_version__");
696 break;
697 case OPTION_MAJOR_IMAGE_VERSION:
698 set_pep_value ("__major_image_version__");
699 break;
700 case OPTION_MINOR_IMAGE_VERSION:
701 set_pep_value ("__minor_image_version__");
702 break;
703 case OPTION_FILE_ALIGNMENT:
704 set_pep_value ("__file_alignment__");
705 break;
706 case OPTION_SECTION_ALIGNMENT:
707 set_pep_value ("__section_alignment__");
708 break;
709 case OPTION_DLL:
710 set_pep_name ("__dll__", 1);
711 break;
712 case OPTION_IMAGE_BASE:
713 set_pep_value ("__image_base__");
714 break;
715 case OPTION_SUPPORT_OLD_CODE:
716 support_old_code = 1;
717 break;
ce11ba6c
KT
718 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
719 pep_use_nul_prefixed_import_tables = TRUE;
720 break;
522f09cd
KT
721 case OPTION_NO_LEADING_UNDERSCORE:
722 pep_leading_underscore = 0;
723 break;
724 case OPTION_LEADING_UNDERSCORE:
725 pep_leading_underscore = 1;
726 break;
0cb112f7
CF
727 case OPTION_INSERT_TIMESTAMP:
728 insert_timestamp = TRUE;
729 break;
eeb14e5a
LZ
730 case OPTION_NO_INSERT_TIMESTAMP:
731 insert_timestamp = FALSE;
732 break;
99ad8390
NC
733#ifdef DLL_SUPPORT
734 case OPTION_OUT_DEF:
735 pep_out_def_filename = xstrdup (optarg);
736 break;
737 case OPTION_EXPORT_ALL:
738 pep_dll_export_everything = 1;
739 break;
740 case OPTION_EXCLUDE_SYMBOLS:
e1c37eb5 741 pep_dll_add_excludes (optarg, EXCLUDESYMS);
99ad8390 742 break;
2927aaca
NC
743 case OPTION_EXCLUDE_ALL_SYMBOLS:
744 pep_dll_exclude_all_symbols = 1;
745 break;
99ad8390 746 case OPTION_EXCLUDE_LIBS:
e1c37eb5
DK
747 pep_dll_add_excludes (optarg, EXCLUDELIBS);
748 break;
749 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
750 pep_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
99ad8390
NC
751 break;
752 case OPTION_KILL_ATS:
753 pep_dll_kill_ats = 1;
754 break;
755 case OPTION_STDCALL_ALIASES:
756 pep_dll_stdcall_aliases = 1;
757 break;
758 case OPTION_ENABLE_STDCALL_FIXUP:
759 pep_enable_stdcall_fixup = 1;
760 break;
761 case OPTION_DISABLE_STDCALL_FIXUP:
762 pep_enable_stdcall_fixup = 0;
763 break;
764 case OPTION_IMPLIB_FILENAME:
765 pep_implib_filename = xstrdup (optarg);
766 break;
767 case OPTION_WARN_DUPLICATE_EXPORTS:
768 pep_dll_warn_dup_exports = 1;
769 break;
770 case OPTION_IMP_COMPAT:
771 pep_dll_compat_implib = 1;
772 break;
773 case OPTION_ENABLE_AUTO_IMAGE_BASE:
774 pep_enable_auto_image_base = 1;
775 break;
776 case OPTION_DISABLE_AUTO_IMAGE_BASE:
777 pep_enable_auto_image_base = 0;
778 break;
779 case OPTION_DLL_SEARCH_PREFIX:
780 pep_dll_search_prefix = xstrdup (optarg);
781 break;
782 case OPTION_NO_DEFAULT_EXCLUDES:
783 pep_dll_do_default_excludes = 0;
784 break;
785 case OPTION_DLL_ENABLE_AUTO_IMPORT:
786 link_info.pei386_auto_import = 1;
787 break;
788 case OPTION_DLL_DISABLE_AUTO_IMPORT:
789 link_info.pei386_auto_import = 0;
790 break;
791 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
6cb442d3 792 link_info.pei386_runtime_pseudo_reloc = 2;
99ad8390
NC
793 break;
794 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
795 link_info.pei386_runtime_pseudo_reloc = 0;
796 break;
6cb442d3
KT
797 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
798 link_info.pei386_runtime_pseudo_reloc = 2;
799 break;
99ad8390
NC
800 case OPTION_ENABLE_EXTRA_PE_DEBUG:
801 pep_dll_extra_pe_debug = 1;
802 break;
803#endif
88183869
DK
804 case OPTION_ENABLE_LONG_SECTION_NAMES:
805 pep_use_coff_long_section_names = 1;
806 break;
807 case OPTION_DISABLE_LONG_SECTION_NAMES:
808 pep_use_coff_long_section_names = 0;
809 break;
2f563b51 810 /* Get DLLCharacteristics bits */
2d5c3743
NC
811 case OPTION_HIGH_ENTROPY_VA:
812 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA;
813 break;
2f563b51
DK
814 case OPTION_DYNAMIC_BASE:
815 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
816 break;
817 case OPTION_FORCE_INTEGRITY:
818 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
819 break;
820 case OPTION_NX_COMPAT:
821 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
822 break;
823 case OPTION_NO_ISOLATION:
824 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
825 break;
826 case OPTION_NO_SEH:
827 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
828 break;
829 case OPTION_NO_BIND:
830 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
831 break;
832 case OPTION_WDM_DRIVER:
833 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
834 break;
835 case OPTION_TERMINAL_SERVER_AWARE:
836 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
837 break;
61e2488c
JT
838 case OPTION_BUILD_ID:
839 if (emit_build_id != NULL)
840 {
841 free ((char *) emit_build_id);
842 emit_build_id = NULL;
843 }
844 if (optarg == NULL)
845 optarg = DEFAULT_BUILD_ID_STYLE;
846 if (strcmp (optarg, "none"))
847 emit_build_id = xstrdup (optarg);
848 break;
99ad8390 849 }
2f563b51
DK
850
851 /* Set DLLCharacteristics bits */
852 set_pep_name ("__dll_characteristics__", pe_dll_characteristics);
e4492aa0 853
99ad8390
NC
854 return TRUE;
855}
856\f
857
858#ifdef DLL_SUPPORT
859static unsigned long
860strhash (const char *str)
861{
862 const unsigned char *s;
863 unsigned long hash;
864 unsigned int c;
865 unsigned int len;
866
867 hash = 0;
868 len = 0;
869 s = (const unsigned char *) str;
870 while ((c = *s++) != '\0')
871 {
872 hash += c + (c << 17);
873 hash ^= hash >> 2;
874 ++len;
875 }
876 hash += len + (len << 17);
877 hash ^= hash >> 2;
878
879 return hash;
880}
881
882/* Use the output file to create a image base for relocatable DLLs. */
883
0ead4f8d 884static bfd_vma
99ad8390
NC
885compute_dll_image_base (const char *ofile)
886{
0ead4f8d 887 bfd_vma hash = (bfd_vma) strhash (ofile);
a07ee50e 888 return NT_DLL_AUTO_IMAGE_BASE + ((hash << 16) & NT_DLL_AUTO_IMAGE_MASK);
99ad8390
NC
889}
890#endif
891
892/* Assign values to the special symbols before the linker script is
893 read. */
894
895static void
896gld_${EMULATION_NAME}_set_symbols (void)
897{
898 /* Run through and invent symbols for all the
899 names and insert the defaults. */
d74720d2 900 int j;
b804e4af 901
d74720d2 902 is_underscoring ();
99ad8390
NC
903
904 if (!init[IMAGEBASEOFF].inited)
905 {
0e1862bb 906 if (bfd_link_relocatable (&link_info))
99ad8390 907 init[IMAGEBASEOFF].value = 0;
0e1862bb 908 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
d127ecce 909 {
99ad8390 910#ifdef DLL_SUPPORT
d127ecce
AM
911 init[IMAGEBASEOFF].value = (pep_enable_auto_image_base
912 ? compute_dll_image_base (output_filename)
913 : NT_DLL_IMAGE_BASE);
99ad8390 914#else
d127ecce 915 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
99ad8390 916#endif
d127ecce 917 }
99ad8390
NC
918 else
919 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
d127ecce 920 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
99ad8390
NC
921 }
922
923 /* Don't do any symbol assignments if this is a relocatable link. */
0e1862bb 924 if (bfd_link_relocatable (&link_info))
99ad8390
NC
925 return;
926
927 /* Glue the assignments into the abs section. */
bde18da4 928 push_stat_ptr (&abs_output_section->children);
99ad8390
NC
929
930 for (j = 0; init[j].ptr; j++)
931 {
0ead4f8d 932 bfd_vma val = init[j].value;
99ad8390 933 lang_assignment_statement_type *rv;
522f09cd 934
2e57b2af 935 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
eb8476a6 936 exp_intop (val), FALSE));
99ad8390 937 if (init[j].size == sizeof (short))
0ead4f8d 938 *(short *) init[j].ptr = (short) val;
99ad8390 939 else if (init[j].size == sizeof (int))
0ead4f8d 940 *(int *) init[j].ptr = (int) val;
99ad8390 941 else if (init[j].size == sizeof (long))
0ead4f8d 942 *(long *) init[j].ptr = (long) val;
99ad8390
NC
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;
946 else abort ();
947 if (j == IMAGEBASEOFF)
948 image_base_statement = rv;
949 }
950 /* Restore the pointer. */
bde18da4 951 pop_stat_ptr ();
99ad8390
NC
952
953 if (pep.FileAlignment > pep.SectionAlignment)
954 {
955 einfo (_("%P: warning, file alignment > section alignment.\n"));
956 }
957}
958
959/* This is called after the linker script and the command line options
960 have been read. */
961
962static void
963gld_${EMULATION_NAME}_after_parse (void)
964{
8b747e1a
DK
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"));
97b11f40 970
decfa41e 971 set_entry_point ();
e4492aa0 972
97b11f40 973 after_parse_default ();
99ad8390
NC
974}
975
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. */
981char * pep_data_import_dll;
982
983#ifdef DLL_SUPPORT
984static struct bfd_link_hash_entry *pep_undef_found_sym;
985
986static bfd_boolean
987pep_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
988{
989 int sl;
990 char *string = inf;
8a9eab9b 991 const char *hs = h->root.string;
99ad8390
NC
992
993 sl = strlen (string);
994 if (h->type == bfd_link_hash_defined
8a9eab9b
KT
995 && ((*hs == '@' && *string == '_'
996 && strncmp (hs + 1, string + 1, sl - 1) == 0)
997 || strncmp (hs, string, sl) == 0)
99ad8390
NC
998 && h->root.string[sl] == '@')
999 {
1000 pep_undef_found_sym = h;
1001 return FALSE;
1002 }
1003 return TRUE;
1004}
1005
1006static void
1007pep_fixup_stdcalls (void)
1008{
1009 static int gave_warning_message = 0;
1010 struct bfd_link_hash_entry *undef, *sym;
1011
1012 if (pep_dll_extra_pe_debug)
1013 printf ("%s\n", __FUNCTION__);
1014
1015 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1016 if (undef->type == bfd_link_hash_undefined)
1017 {
1018 char* at = strchr (undef->root.string, '@');
1019 int lead_at = (*undef->root.string == '@');
8a9eab9b
KT
1020 if (lead_at)
1021 at = strchr (undef->root.string + 1, '@');
1022 if (at || lead_at)
99ad8390
NC
1023 {
1024 /* The symbol is a stdcall symbol, so let's look for a
1025 cdecl symbol with the same name and resolve to that. */
8a9eab9b
KT
1026 char *cname = xstrdup (undef->root.string);
1027
1028 if (lead_at)
1029 *cname = '_';
99ad8390 1030 at = strchr (cname, '@');
8a9eab9b
KT
1031 if (at)
1032 *at = 0;
99ad8390
NC
1033 sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
1034
1035 if (sym && sym->type == bfd_link_hash_defined)
1036 {
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;
1040
1041 if (pep_enable_stdcall_fixup == -1)
1042 {
1043 einfo (_("Warning: resolving %s by linking to %s\n"),
1044 undef->root.string, cname);
1045 if (! gave_warning_message)
1046 {
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"));
1050 }
1051 }
1052 }
1053 }
1054 else
1055 {
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;
1062 if (sym)
1063 {
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;
1067
1068 if (pep_enable_stdcall_fixup == -1)
1069 {
1070 einfo (_("Warning: resolving %s by linking to %s\n"),
1071 undef->root.string, sym->root.string);
1072 if (! gave_warning_message)
1073 {
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"));
1077 }
1078 }
1079 }
1080 }
1081 }
1082}
1083
1084static int
1085make_import_fixup (arelent *rel, asection *s)
1086{
1087 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
6cb442d3
KT
1088 char addend[8];
1089 bfd_vma _addend = 0;
1090 int suc = 0;
99ad8390
NC
1091
1092 if (pep_dll_extra_pe_debug)
1093 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
0af1713e 1094 (unsigned long) rel->address, (long) rel->addend);
99ad8390 1095
6cb442d3
KT
1096 memset (addend, 0, sizeof (addend));
1097 switch ((rel->howto->bitsize))
1098 {
1099 case 8:
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)));
1103 else if (suc)
1104 _addend = ((bfd_vma) bfd_get_8 (s->owner, addend)) & 0xff;
1105 break;
1106 case 16:
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)));
1110 else if (suc)
1111 _addend = ((bfd_vma) bfd_get_16 (s->owner, addend)) & 0xffff;
1112 break;
1113 case 32:
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)));
1117 else if (suc)
1118 _addend = ((bfd_vma) bfd_get_32 (s->owner, addend)) & 0xffffffff;
1119 break;
1120 case 64:
1121 suc = bfd_get_section_contents (s->owner, s, addend, rel->address, 8);
1122 if (suc)
1123 _addend = ((bfd_vma) bfd_get_64 (s->owner, addend));
1124 break;
1125 }
1126 if (! suc)
99ad8390
NC
1127 einfo (_("%C: Cannot get section contents - auto-import exception\n"),
1128 s->owner, s, rel->address);
1129
6cb442d3
KT
1130 if (pep_dll_extra_pe_debug)
1131 {
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);
1135 }
1136 pep_create_import_fixup (rel, s, _addend);
99ad8390
NC
1137
1138 return 1;
1139}
1140
1141static void
1142pep_find_data_imports (void)
1143{
1144 struct bfd_link_hash_entry *undef, *sym;
1145
1146 if (link_info.pei386_auto_import == 0)
1147 return;
1148
1149 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1150 {
1151 if (undef->type == bfd_link_hash_undefined)
1152 {
1153 /* C++ symbols are *long*. */
a2a4d60d
NC
1154#define BUF_SIZE 4096
1155 char buf[BUF_SIZE];
99ad8390
NC
1156
1157 if (pep_dll_extra_pe_debug)
1158 printf ("%s:%s\n", __FUNCTION__, undef->root.string);
1159
a2a4d60d
NC
1160 if (strlen (undef->root.string) > (BUF_SIZE - 6))
1161 {
1162 /* PR linker/18466. */
1163 einfo (_("%P: internal error: symbol too long: %s\n"),
1164 undef->root.string);
1165 return;
1166 }
1167
99ad8390
NC
1168 sprintf (buf, "__imp_%s", undef->root.string);
1169
1170 sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
1171
1172 if (sym && sym->type == bfd_link_hash_defined)
1173 {
1174 bfd *b = sym->u.def.section->owner;
1175 asymbol **symbols;
5c1d2f5f 1176 int nsyms, i;
99ad8390 1177
5c1d2f5f
AM
1178 if (!bfd_generic_link_read_symbols (b))
1179 {
1180 einfo (_("%B%F: could not read symbols: %E\n"), b);
1181 return;
1182 }
1183
1184 symbols = bfd_get_outsymbols (b);
1185 nsyms = bfd_get_symcount (b);
99ad8390
NC
1186
1187 for (i = 0; i < nsyms; i++)
1188 {
522f09cd 1189 if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
99ad8390
NC
1190 continue;
1191
1192 if (pep_dll_extra_pe_debug)
1193 printf ("->%s\n", symbols[i]->name);
1194
1195 pep_data_import_dll = (char*) (symbols[i]->name +
522f09cd 1196 U_SIZE ("_head_") - 1);
99ad8390
NC
1197 break;
1198 }
1199
1200 pep_walk_relocs_of_symbol (&link_info, undef->root.string,
d127ecce 1201 make_import_fixup);
99ad8390
NC
1202
1203 /* Let's differentiate it somehow from defined. */
1204 undef->type = bfd_link_hash_defweak;
1205 /* We replace original name with __imp_ prefixed, this
1206 1) may trash memory 2) leads to duplicate symbol generation.
1207 Still, IMHO it's better than having name poluted. */
1208 undef->root.string = sym->root.string;
1209 undef->u.def.value = sym->u.def.value;
1210 undef->u.def.section = sym->u.def.section;
1211 }
1212 }
1213 }
1214}
1215
1216static bfd_boolean
1217pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1218{
80cc85a9 1219 printf ("+%s\n", h->string);
99ad8390
NC
1220
1221 return TRUE;
1222}
1223#endif /* DLL_SUPPORT */
1224
e4492aa0 1225static void
3efd345c
DK
1226debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1227{
1228 int *found = (int *) obj;
61e2488c 1229
3efd345c
DK
1230 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1231 *found = 1;
1232}
99ad8390 1233
61e2488c
JT
1234static bfd_boolean
1235pecoff_checksum_contents (bfd *abfd,
1236 void (*process) (const void *, size_t, void *),
1237 void *arg)
1238{
1239 file_ptr filepos = (file_ptr) 0;
1240
1241 while (1)
1242 {
1243 unsigned char b;
1244 int status;
1245
1246 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1247 return 0;
1248
1249 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1250 if (status < 1)
1251 {
1252 break;
1253 }
1254
1255 (*process) (&b, 1, arg);
1256 filepos += 1;
1257 }
1258
1259 return TRUE;
1260}
1261
1262static bfd_boolean
1263write_build_id (bfd *abfd)
1264{
1265 struct pe_tdata *t = pe_data (abfd);
1266 asection *asec;
1267 struct bfd_link_order *link_order = NULL;
1268 unsigned char *contents;
1269 bfd_size_type size;
1270 bfd_size_type build_id_size;
1271 unsigned char *build_id;
1272
74fffc39 1273 /* Find the section the .buildid output section has been merged info. */
61e2488c
JT
1274 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1275 {
1276 struct bfd_link_order *l = NULL;
1277 for (l = asec->map_head.link_order; l != NULL; l = l->next)
1278 {
b6518b38 1279 if (l->type == bfd_indirect_link_order)
61e2488c
JT
1280 {
1281 if (l->u.indirect.section == t->build_id.sec)
1282 {
1283 link_order = l;
1284 break;
1285 }
1286 }
1287 }
1288
1289 if (link_order)
1290 break;
1291 }
1292
1293 if (!link_order)
1294 {
74fffc39 1295 einfo (_("%P: warning: .buildid section discarded,"
61e2488c
JT
1296 " --build-id ignored.\n"));
1297 return TRUE;
1298 }
1299
1300 if (t->build_id.sec->contents == NULL)
1301 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1302 contents = t->build_id.sec->contents;
1303 size = t->build_id.sec->size;
1304
1305 build_id_size = compute_build_id_size (t->build_id.style);
1306 build_id = xmalloc (build_id_size);
1307 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1308
1309 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1310
1311 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1312 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1313 idd.Characteristics = 0;
1314 idd.TimeDateStamp = 0;
1315 idd.MajorVersion = 0;
1316 idd.MinorVersion = 0;
1317 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1318 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1319 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1320 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1321 idd.PointerToRawData = asec->filepos + link_order->offset
1322 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1323
1324 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1325 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1326
1327 /* Write the debug directory enttry */
1328 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1329 return 0;
1330
b6518b38 1331 if (bfd_bwrite (contents, size, abfd) != size)
61e2488c
JT
1332 return 0;
1333
1334 /* Construct the CodeView record. */
1335 CODEVIEW_INFO cvinfo;
1336 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1337 cvinfo.Age = 1;
1338
1339 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1340 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1341 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1342 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1343
1344 free (build_id);
1345
1346 /* Write the codeview record. */
1347 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1348 return 0;
1349
1350 /* Record the location of the debug directory in the data directory. */
1351 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1352 = asec->vma - ib + link_order->offset;
1353 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1354 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1355
1356 return TRUE;
1357}
1358
74fffc39 1359/* Make .buildid section, and set up coff_tdata->build_id. */
61e2488c
JT
1360static bfd_boolean
1361setup_build_id (bfd *ibfd)
1362{
1363 asection *s;
1364 flagword flags;
1365
1366 if (!validate_build_id_style (emit_build_id))
1367 {
1368 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1369 return FALSE;
1370 }
1371
1372 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1373 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
74fffc39 1374 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
61e2488c
JT
1375 if (s != NULL)
1376 {
1377 struct pe_tdata *t = pe_data (link_info.output_bfd);
1378 t->build_id.after_write_object_contents = &write_build_id;
1379 t->build_id.style = emit_build_id;
1380 t->build_id.sec = s;
1381
1382 /* Section is a fixed size:
1383 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1384 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1385 null byte for PdbFileName. */
1386 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1387 + sizeof (CV_INFO_PDB70) + 1;
1388
1389 return TRUE;
1390 }
1391
74fffc39 1392 einfo ("%P: warning: Cannot create .buildid section,"
61e2488c
JT
1393 " --build-id ignored.\n");
1394 return FALSE;
1395}
1396
99ad8390
NC
1397static void
1398gld_${EMULATION_NAME}_after_open (void)
1399{
5c3049d2
AM
1400 after_open_default ();
1401
d74720d2 1402 is_underscoring ();
99ad8390
NC
1403#ifdef DLL_SUPPORT
1404 if (pep_dll_extra_pe_debug)
1405 {
1406 bfd *a;
1407 struct bfd_link_hash_entry *sym;
1408
1409 printf ("%s()\n", __FUNCTION__);
1410
1411 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1412 printf ("-%s\n", sym->root.string);
1413 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
1414
c72f2fb2 1415 for (a = link_info.input_bfds; a; a = a->link.next)
99ad8390
NC
1416 printf ("*%s\n",a->filename);
1417 }
1418#endif
1419
61e2488c
JT
1420 if (emit_build_id != NULL)
1421 {
1422 bfd *abfd;
1423
1424 /* Find a COFF input. */
1425 for (abfd = link_info.input_bfds;
c72f2fb2 1426 abfd != (bfd *) NULL; abfd = abfd->link.next)
61e2488c
JT
1427 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1428 break;
1429
1430 /* If there are no COFF input files do not try to
1431 add a build-id section. */
1432 if (abfd == NULL
1433 || !setup_build_id (abfd))
1434 {
1435 free ((char *) emit_build_id);
1436 emit_build_id = NULL;
1437 }
1438 }
1439
99ad8390
NC
1440 /* Pass the wacky PE command line options into the output bfd.
1441 FIXME: This should be done via a function, rather than by
1442 including an internal BFD header. */
1443
f13a99db
AM
1444 if (coff_data (link_info.output_bfd) == NULL
1445 || coff_data (link_info.output_bfd)->pe == 0)
1446 einfo (_("%F%P: cannot perform PE operations on non PE output file '%B'.\n"),
1447 link_info.output_bfd);
99ad8390 1448
f13a99db
AM
1449 pe_data (link_info.output_bfd)->pe_opthdr = pep;
1450 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1451 pe_data (link_info.output_bfd)->real_flags |= real_flags;
0cb112f7 1452 pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
3efd345c
DK
1453
1454 /* At this point we must decide whether to use long section names
1455 in the output or not. If the user hasn't explicitly specified
1456 on the command line, we leave it to the default for the format
1457 (object files yes, image files no), except if there is debug
1458 information present; GDB relies on the long section names to
1459 find it, so enable it in that case. */
1460 if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1461 {
0e1862bb 1462 if (bfd_link_relocatable (&link_info))
61e2488c
JT
1463 pep_use_coff_long_section_names = 1;
1464 else
3efd345c 1465 {
61e2488c
JT
1466 /* Iterate over all sections of all input BFDs, checking
1467 for any that begin 'debug_' and are long names. */
1468 LANG_FOR_EACH_INPUT_STATEMENT (is)
1469 {
1470 int found_debug = 0;
1471
1472 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1473 if (found_debug)
1474 {
1475 pep_use_coff_long_section_names = 1;
1476 break;
1477 }
1478 }
3efd345c
DK
1479 }
1480 }
1481
88183869 1482 pep_output_file_set_long_section_names (link_info.output_bfd);
99ad8390
NC
1483
1484#ifdef DLL_SUPPORT
1485 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1486 pep_fixup_stdcalls ();
1487
f13a99db 1488 pep_process_import_defs (link_info.output_bfd, &link_info);
99ad8390
NC
1489
1490 pep_find_data_imports ();
1491
8a9eab9b
KT
1492 /* As possibly new symbols are added by imports, we rerun
1493 stdcall/fastcall fixup here. */
1494 if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
1495 pep_fixup_stdcalls ();
1496
99ad8390 1497#ifndef TARGET_IS_i386pep
0e1862bb 1498 if (bfd_link_pic (&link_info))
99ad8390 1499#else
0e1862bb 1500 if (!bfd_link_relocatable (&link_info))
99ad8390 1501#endif
f13a99db 1502 pep_dll_build_sections (link_info.output_bfd, &link_info);
99ad8390
NC
1503
1504#ifndef TARGET_IS_i386pep
1505 else
f13a99db 1506 pep_exe_build_sections (link_info.output_bfd, &link_info);
99ad8390
NC
1507#endif
1508#endif /* DLL_SUPPORT */
1509
1510 {
1511 /* This next chunk of code tries to detect the case where you have
1512 two import libraries for the same DLL (specifically,
1513 symbolically linking libm.a and libc.a in cygwin to
1514 libcygwin.a). In those cases, it's possible for function
1515 thunks from the second implib to be used but without the
1516 head/tail objects, causing an improper import table. We detect
1517 those cases and rename the "other" import libraries to match
1518 the one the head/tail come from, so that the linker will sort
1519 things nicely and produce a valid import table. */
1520
1521 LANG_FOR_EACH_INPUT_STATEMENT (is)
1522 {
1523 if (is->the_bfd->my_archive)
1524 {
1525 int idata2 = 0, reloc_count=0, is_imp = 0;
1526 asection *sec;
1527
1528 /* See if this is an import library thunk. */
1529 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1530 {
1531 if (strcmp (sec->name, ".idata\$2") == 0)
1532 idata2 = 1;
1533 if (CONST_STRNEQ (sec->name, ".idata\$"))
1534 is_imp = 1;
1535 reloc_count += sec->reloc_count;
1536 }
1537
1538 if (is_imp && !idata2 && reloc_count)
1539 {
1540 /* It is, look for the reference to head and see if it's
1541 from our own library. */
1542 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1543 {
1544 int i;
99ad8390
NC
1545 long relsize;
1546 asymbol **symbols;
1547 arelent **relocs;
1548 int nrelocs;
1549
99ad8390
NC
1550 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1551 if (relsize < 1)
1552 break;
1553
5c1d2f5f 1554 if (!bfd_generic_link_read_symbols (is->the_bfd))
99ad8390 1555 {
5c1d2f5f
AM
1556 einfo (_("%B%F: could not read symbols: %E\n"),
1557 is->the_bfd);
99ad8390
NC
1558 return;
1559 }
5c1d2f5f 1560 symbols = bfd_get_outsymbols (is->the_bfd);
99ad8390
NC
1561
1562 relocs = xmalloc ((size_t) relsize);
1563 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1564 relocs, symbols);
1565 if (nrelocs < 0)
1566 {
1567 free (relocs);
44e36d8a 1568 einfo ("%X%P: unable to process relocs: %E\n");
99ad8390
NC
1569 return;
1570 }
1571
1572 for (i = 0; i < nrelocs; i++)
1573 {
1574 struct bfd_symbol *s;
1575 struct bfd_link_hash_entry * blhe;
1576 char *other_bfd_filename;
1577 char *n;
1578
1579 s = (relocs[i]->sym_ptr_ptr)[0];
1580
1581 if (s->flags & BSF_LOCAL)
1582 continue;
1583
1584 /* Thunk section with reloc to another bfd. */
1585 blhe = bfd_link_hash_lookup (link_info.hash,
1586 s->name,
1587 FALSE, FALSE, TRUE);
1588
1589 if (blhe == NULL
1590 || blhe->type != bfd_link_hash_defined)
1591 continue;
1592
1593 other_bfd_filename
1594 = blhe->u.def.section->owner->my_archive
1595 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1596 : bfd_get_filename (blhe->u.def.section->owner);
1597
42627821
KT
1598 if (filename_cmp (bfd_get_filename
1599 (is->the_bfd->my_archive),
1600 other_bfd_filename) == 0)
99ad8390
NC
1601 continue;
1602
1603 /* Rename this implib to match the other one. */
1604 n = xmalloc (strlen (other_bfd_filename) + 1);
1605 strcpy (n, other_bfd_filename);
1606 is->the_bfd->my_archive->filename = n;
1607 }
1608
1609 free (relocs);
1610 /* Note - we do not free the symbols,
1611 they are now cached in the BFD. */
1612 }
1613 }
1614 }
1615 }
1616 }
1617
1618 {
1619 int is_ms_arch = 0;
1620 bfd *cur_arch = 0;
1621 lang_input_statement_type *is2;
1622 lang_input_statement_type *is3;
1623
1624 /* Careful - this is a shell script. Watch those dollar signs! */
1625 /* Microsoft import libraries have every member named the same,
1626 and not in the right order for us to link them correctly. We
1627 must detect these and rename the members so that they'll link
1628 correctly. There are three types of objects: the head, the
1629 thunks, and the sentinel(s). The head is easy; it's the one
1630 with idata2. We assume that the sentinels won't have relocs,
1631 and the thunks will. It's easier than checking the symbol
1632 table for external references. */
1633 LANG_FOR_EACH_INPUT_STATEMENT (is)
1634 {
1635 if (is->the_bfd->my_archive)
1636 {
1637 char *pnt;
1638 bfd *arch = is->the_bfd->my_archive;
1639
1640 if (cur_arch != arch)
1641 {
1642 cur_arch = arch;
1643 is_ms_arch = 1;
1644
1645 for (is3 = is;
1646 is3 && is3->the_bfd->my_archive == arch;
1647 is3 = (lang_input_statement_type *) is3->next)
1648 {
1649 /* A MS dynamic import library can also contain static
1650 members, so look for the first element with a .dll
1651 extension, and use that for the remainder of the
1652 comparisons. */
1653 pnt = strrchr (is3->the_bfd->filename, '.');
42627821 1654 if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
99ad8390
NC
1655 break;
1656 }
1657
1658 if (is3 == NULL)
1659 is_ms_arch = 0;
1660 else
1661 {
1662 /* OK, found one. Now look to see if the remaining
1663 (dynamic import) members use the same name. */
1664 for (is2 = is;
1665 is2 && is2->the_bfd->my_archive == arch;
1666 is2 = (lang_input_statement_type *) is2->next)
1667 {
1668 /* Skip static members, ie anything with a .obj
1669 extension. */
1670 pnt = strrchr (is2->the_bfd->filename, '.');
42627821 1671 if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
99ad8390
NC
1672 continue;
1673
42627821
KT
1674 if (filename_cmp (is3->the_bfd->filename,
1675 is2->the_bfd->filename))
99ad8390
NC
1676 {
1677 is_ms_arch = 0;
1678 break;
1679 }
1680 }
1681 }
1682 }
1683
1684 /* This fragment might have come from an .obj file in a Microsoft
1685 import, and not an actual import record. If this is the case,
1686 then leave the filename alone. */
1687 pnt = strrchr (is->the_bfd->filename, '.');
1688
42627821 1689 if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
99ad8390
NC
1690 {
1691 int idata2 = 0, reloc_count=0;
1692 asection *sec;
1693 char *new_name, seq;
1694
1695 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1696 {
1697 if (strcmp (sec->name, ".idata\$2") == 0)
1698 idata2 = 1;
1699 reloc_count += sec->reloc_count;
1700 }
1701
1702 if (idata2) /* .idata2 is the TOC */
1703 seq = 'a';
1704 else if (reloc_count > 0) /* thunks */
1705 seq = 'b';
1706 else /* sentinel */
1707 seq = 'c';
1708
1709 new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1710 sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1711 is->the_bfd->filename = new_name;
1712
1713 new_name = xmalloc (strlen (is->filename) + 3);
1714 sprintf (new_name, "%s.%c", is->filename, seq);
1715 is->filename = new_name;
1716 }
1717 }
1718 }
1719 }
1720}
1721\f
1722static void
1723gld_${EMULATION_NAME}_before_allocation (void)
1724{
d74720d2 1725 is_underscoring ();
99ad8390
NC
1726 before_allocation_default ();
1727}
1728\f
1729#ifdef DLL_SUPPORT
1730/* This is called when an input file isn't recognized as a BFD. We
1731 check here for .DEF files and pull them in automatically. */
1732
1733static int
1734saw_option (char *option)
1735{
1736 int i;
1737
d74720d2
KT
1738 is_underscoring ();
1739
99ad8390 1740 for (i = 0; init[i].ptr; i++)
522f09cd 1741 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
99ad8390
NC
1742 return init[i].inited;
1743 return 0;
1744}
1745#endif /* DLL_SUPPORT */
1746
1747static bfd_boolean
1748gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1749{
1750#ifdef DLL_SUPPORT
1751 const char *ext = entry->filename + strlen (entry->filename) - 4;
1752
42627821 1753 if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
99ad8390
NC
1754 {
1755 pep_def_file = def_file_parse (entry->filename, pep_def_file);
1756
1757 if (pep_def_file)
1758 {
1759 int i, buflen=0, len;
1760 char *buf;
1761
1762 for (i = 0; i < pep_def_file->num_exports; i++)
1763 {
1764 len = strlen (pep_def_file->exports[i].internal_name);
1765 if (buflen < len + 2)
1766 buflen = len + 2;
1767 }
1768
1769 buf = xmalloc (buflen);
1770
1771 for (i = 0; i < pep_def_file->num_exports; i++)
1772 {
1773 struct bfd_link_hash_entry *h;
1774
522f09cd
KT
1775 sprintf (buf, "%s%s", U (""),
1776 pep_def_file->exports[i].internal_name);
99ad8390
NC
1777
1778 h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
1779 if (h == (struct bfd_link_hash_entry *) NULL)
1780 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1781 if (h->type == bfd_link_hash_new)
1782 {
1783 h->type = bfd_link_hash_undefined;
1784 h->u.undef.abfd = NULL;
1785 bfd_link_add_undef (link_info.hash, h);
1786 }
1787 }
1788 free (buf);
1789
1790 /* def_file_print (stdout, pep_def_file); */
1791 if (pep_def_file->is_dll == 1)
64d94ba0 1792 link_info.type = type_dll;
99ad8390
NC
1793
1794 if (pep_def_file->base_address != (bfd_vma)(-1))
1795 {
f13a99db
AM
1796 pep.ImageBase
1797 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1798 = init[IMAGEBASEOFF].value
1799 = pep_def_file->base_address;
99ad8390
NC
1800 init[IMAGEBASEOFF].inited = 1;
1801 if (image_base_statement)
eb8476a6
MR
1802 image_base_statement->exp
1803 = exp_assign ("__image_base__", exp_intop (pep.ImageBase),
1804 FALSE);
99ad8390
NC
1805 }
1806
1807 if (pep_def_file->stack_reserve != -1
1808 && ! saw_option ("__size_of_stack_reserve__"))
1809 {
1810 pep.SizeOfStackReserve = pep_def_file->stack_reserve;
1811 if (pep_def_file->stack_commit != -1)
1812 pep.SizeOfStackCommit = pep_def_file->stack_commit;
1813 }
1814 if (pep_def_file->heap_reserve != -1
1815 && ! saw_option ("__size_of_heap_reserve__"))
1816 {
1817 pep.SizeOfHeapReserve = pep_def_file->heap_reserve;
1818 if (pep_def_file->heap_commit != -1)
1819 pep.SizeOfHeapCommit = pep_def_file->heap_commit;
1820 }
1821 return TRUE;
1822 }
1823 }
1824#endif
1825 return FALSE;
1826}
1827
1828static bfd_boolean
1829gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1830{
d74720d2 1831 is_underscoring ();
99ad8390
NC
1832#ifdef DLL_SUPPORT
1833#ifdef TARGET_IS_i386pep
1834 pep_dll_id_target ("pei-x86-64");
1835#endif
880383ca
NC
1836 if (pep_bfd_is_dll (entry->the_bfd))
1837 return pep_implied_import_dll (entry->filename);
99ad8390
NC
1838#endif
1839 return FALSE;
1840}
1841
1842static void
1843gld_${EMULATION_NAME}_finish (void)
1844{
d74720d2 1845 is_underscoring ();
99ad8390
NC
1846 finish_default ();
1847
1848#ifdef DLL_SUPPORT
0e1862bb
L
1849 if (bfd_link_pic (&link_info)
1850 || (!bfd_link_relocatable (&link_info)
1851 && pep_def_file->num_exports != 0))
99ad8390 1852 {
f13a99db 1853 pep_dll_fill_sections (link_info.output_bfd, &link_info);
99ad8390 1854 if (pep_implib_filename)
e1c37eb5 1855 pep_dll_generate_implib (pep_def_file, pep_implib_filename, &link_info);
99ad8390
NC
1856 }
1857
1858 if (pep_out_def_filename)
1859 pep_dll_generate_def_file (pep_out_def_filename);
1860#endif /* DLL_SUPPORT */
1861
1862 /* I don't know where .idata gets set as code, but it shouldn't be. */
1863 {
f13a99db 1864 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
99ad8390
NC
1865
1866 if (asec)
1867 {
1868 asec->flags &= ~SEC_CODE;
1869 asec->flags |= SEC_DATA;
1870 }
1871 }
1872}
1873
1874\f
1875/* Place an orphan section.
1876
1877 We use this to put sections in a reasonable place in the file, and
1878 to ensure that they are aligned as required.
1879
d34c1c51 1880 We handle grouped sections here as well. A section named .foo\$nn
99ad8390
NC
1881 goes into the output section .foo. All grouped sections are sorted
1882 by name.
1883
1884 Grouped sections for the default sections are handled by the
1885 default linker script using wildcards, and are sorted by
1886 sort_sections. */
1887
c2edb4b8 1888static lang_output_section_statement_type *
8a99a385
AM
1889gld_${EMULATION_NAME}_place_orphan (asection *s,
1890 const char *secname,
1891 int constraint)
99ad8390 1892{
bcacc0f5 1893 const char *orig_secname = secname;
99ad8390
NC
1894 char *dollar = NULL;
1895 lang_output_section_statement_type *os;
1896 lang_statement_list_type add_child;
b5f14a6d 1897 lang_output_section_statement_type *match_by_name = NULL;
011aa75f 1898 lang_statement_union_type **pl;
99ad8390 1899
99ad8390 1900 /* Look through the script to see where to place this section. */
0e1862bb 1901 if (!bfd_link_relocatable (&link_info)
d34c1c51 1902 && (dollar = strchr (secname, '\$')) != NULL)
99ad8390 1903 {
bcacc0f5 1904 size_t len = dollar - secname;
99ad8390 1905 char *newname = xmalloc (len + 1);
bcacc0f5 1906 memcpy (newname, secname, len);
99ad8390
NC
1907 newname[len] = '\0';
1908 secname = newname;
1909 }
1910
99ad8390
NC
1911 lang_list_init (&add_child);
1912
d127ecce
AM
1913 os = NULL;
1914 if (constraint == 0)
1915 for (os = lang_output_section_find (secname);
1916 os != NULL;
1917 os = next_matching_output_section_statement (os, 0))
1918 {
1919 /* If we don't match an existing output section, tell
1920 lang_insert_orphan to create a new output section. */
1921 constraint = SPECIAL;
1922
1923 if (os->bfd_section != NULL
1924 && (os->bfd_section->flags == 0
1925 || ((s->flags ^ os->bfd_section->flags)
1926 & (SEC_LOAD | SEC_ALLOC)) == 0))
1927 {
1928 /* We already have an output section statement with this
1929 name, and its bfd section has compatible flags.
1930 If the section already exists but does not have any flags set,
1931 then it has been created by the linker, probably as a result of
1932 a --section-start command line switch. */
b9c361e0 1933 lang_add_section (&add_child, s, NULL, os);
d127ecce
AM
1934 break;
1935 }
b5f14a6d
DD
1936
1937 /* Save unused output sections in case we can match them
1938 against orphans later. */
1939 if (os->bfd_section == NULL)
1940 match_by_name = os;
d127ecce
AM
1941 }
1942
b5f14a6d
DD
1943 /* If we didn't match an active output section, see if we matched an
1944 unused one and use that. */
1945 if (os == NULL && match_by_name)
1946 {
b9c361e0 1947 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
b5f14a6d
DD
1948 return match_by_name;
1949 }
1950
d127ecce 1951 if (os == NULL)
99ad8390
NC
1952 {
1953 static struct orphan_save hold[] =
1954 {
1955 { ".text",
1956 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1957 0, 0, 0, 0 },
d4874973
KT
1958 { ".idata",
1959 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1960 0, 0, 0, 0 },
99ad8390
NC
1961 { ".rdata",
1962 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1963 0, 0, 0, 0 },
1964 { ".data",
1965 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1966 0, 0, 0, 0 },
1967 { ".bss",
1968 SEC_ALLOC,
1969 0, 0, 0, 0 }
1970 };
1971 enum orphan_save_index
1972 {
1973 orphan_text = 0,
d4874973 1974 orphan_idata,
99ad8390
NC
1975 orphan_rodata,
1976 orphan_data,
1977 orphan_bss
1978 };
1979 static int orphan_init_done = 0;
1980 struct orphan_save *place;
1981 lang_output_section_statement_type *after;
1982 etree_type *address;
93638471
AM
1983 flagword flags;
1984 asection *nexts;
99ad8390
NC
1985
1986 if (!orphan_init_done)
1987 {
1988 struct orphan_save *ho;
1989 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1990 if (ho->name != NULL)
1991 {
1992 ho->os = lang_output_section_find (ho->name);
1993 if (ho->os != NULL && ho->os->flags == 0)
1994 ho->os->flags = ho->flags;
1995 }
1996 orphan_init_done = 1;
1997 }
1998
1999 /* Try to put the new output section in a reasonable place based
2000 on the section name and section flags. */
2001
93638471
AM
2002 flags = s->flags;
2003 nexts = s;
2004 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts)))
2005 if (nexts->output_section == NULL
2006 && (nexts->flags & SEC_EXCLUDE) == 0
2007 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2008 && (nexts->owner->flags & DYNAMIC) == 0
2009 && nexts->owner->usrdata != NULL
2010 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2011 ->flags.just_syms))
2012 flags = (((flags ^ SEC_READONLY) | (nexts->flags ^ SEC_READONLY))
2013 ^ SEC_READONLY);
99ad8390 2014 place = NULL;
93638471 2015 if ((flags & SEC_ALLOC) == 0)
99ad8390 2016 ;
93638471 2017 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
99ad8390 2018 place = &hold[orphan_bss];
93638471 2019 else if ((flags & SEC_READONLY) == 0)
99ad8390 2020 place = &hold[orphan_data];
93638471 2021 else if ((flags & SEC_CODE) == 0)
d4874973
KT
2022 {
2023 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2024 : &hold[orphan_rodata]);
2025 }
99ad8390
NC
2026 else
2027 place = &hold[orphan_text];
2028
2029 after = NULL;
2030 if (place != NULL)
2031 {
2032 if (place->os == NULL)
2033 place->os = lang_output_section_find (place->name);
2034 after = place->os;
2035 if (after == NULL)
93638471
AM
2036 after = lang_output_section_find_by_flags (s, flags, &place->os,
2037 NULL);
99ad8390
NC
2038 if (after == NULL)
2039 /* *ABS* is always the first output section statement. */
2040 after = (&lang_output_section_statement.head
2041 ->output_section_statement);
2042 }
2043
4bf0cafb
DK
2044 /* All sections in an executable must be aligned to a page boundary.
2045 In a relocatable link, just preserve the incoming alignment; the
2046 address is discarded by lang_insert_orphan in that case, anyway. */
99ad8390 2047 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
8a99a385
AM
2048 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2049 &add_child);
0e1862bb 2050 if (bfd_link_relocatable (&link_info))
4bf0cafb
DK
2051 {
2052 os->section_alignment = s->alignment_power;
2053 os->bfd_section->alignment_power = s->alignment_power;
2054 }
99ad8390
NC
2055 }
2056
011aa75f
AM
2057 /* If the section name has a '\$', sort it with the other '\$'
2058 sections. */
2059 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2060 {
2061 lang_input_section_type *ls;
2062 const char *lname;
99ad8390 2063
011aa75f
AM
2064 if ((*pl)->header.type != lang_input_section_enum)
2065 continue;
99ad8390 2066
011aa75f 2067 ls = &(*pl)->input_section;
99ad8390 2068
011aa75f
AM
2069 lname = bfd_get_section_name (ls->section->owner, ls->section);
2070 if (strchr (lname, '\$') != NULL
2071 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2072 break;
2073 }
99ad8390 2074
011aa75f
AM
2075 if (add_child.head != NULL)
2076 {
2077 *add_child.tail = *pl;
2078 *pl = add_child.head;
2079 }
99ad8390 2080
c2edb4b8 2081 return os;
99ad8390
NC
2082}
2083
2084static bfd_boolean
2085gld_${EMULATION_NAME}_open_dynamic_archive
2086 (const char *arch ATTRIBUTE_UNUSED,
2087 search_dirs_type *search,
2088 lang_input_statement_type *entry)
2089{
2090 static const struct
2091 {
2092 const char * format;
2093 bfd_boolean use_prefix;
2094 }
2095 libname_fmt [] =
2096 {
2097 /* Preferred explicit import library for dll's. */
2098 { "lib%s.dll.a", FALSE },
2099 /* Alternate explicit import library for dll's. */
2100 { "%s.dll.a", FALSE },
2101 /* "libfoo.a" could be either an import lib or a static lib.
2102 For backwards compatibility, libfoo.a needs to precede
2103 libfoo.dll and foo.dll in the search. */
2104 { "lib%s.a", FALSE },
92b93329 2105 /* The 'native' spelling of an import lib name is "foo.lib". */
99ad8390
NC
2106 { "%s.lib", FALSE },
2107#ifdef DLL_SUPPORT
2108 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
2109 { "%s%s.dll", TRUE },
2110#endif
2111 /* Try "libfoo.dll" (default preferred dll name). */
2112 { "lib%s.dll", FALSE },
2113 /* Finally try 'native' dll name "foo.dll". */
2114 { "%s.dll", FALSE },
2115 /* Note: If adding more formats to this table, make sure to check to
2116 see if their length is longer than libname_fmt[0].format, and if
2117 so, update the call to xmalloc() below. */
2118 { NULL, FALSE }
2119 };
2120 static unsigned int format_max_len = 0;
2121 const char * filename;
2122 char * full_string;
2123 char * base_string;
2124 unsigned int i;
2125
2126
d4ae5fb0 2127 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
99ad8390
NC
2128 return FALSE;
2129
2130 filename = entry->filename;
2131
2132 if (format_max_len == 0)
2133 /* We need to allow space in the memory that we are going to allocate
2134 for the characters in the format string. Since the format array is
2135 static we only need to calculate this information once. In theory
2136 this value could also be computed statically, but this introduces
2137 the possibility for a discrepancy and hence a possible memory
2138 corruption. The lengths we compute here will be too long because
2139 they will include any formating characters (%s) in the strings, but
2140 this will not matter. */
2141 for (i = 0; libname_fmt[i].format; i++)
2142 if (format_max_len < strlen (libname_fmt[i].format))
2143 format_max_len = strlen (libname_fmt[i].format);
2144
2145 full_string = xmalloc (strlen (search->name)
2146 + strlen (filename)
2147 + format_max_len
2148#ifdef DLL_SUPPORT
2149 + (pep_dll_search_prefix
2150 ? strlen (pep_dll_search_prefix) : 0)
2151#endif
2152 /* Allow for the terminating NUL and for the path
2153 separator character that is inserted between
2154 search->name and the start of the format string. */
2155 + 2);
2156
2157 sprintf (full_string, "%s/", search->name);
2158 base_string = full_string + strlen (full_string);
2159
2160 for (i = 0; libname_fmt[i].format; i++)
2161 {
92b93329 2162#ifdef DLL_SUPPORT
99ad8390
NC
2163 if (libname_fmt[i].use_prefix)
2164 {
2165 if (!pep_dll_search_prefix)
2166 continue;
2167 sprintf (base_string, libname_fmt[i].format, pep_dll_search_prefix, filename);
2168 }
2169 else
2170#endif
2171 sprintf (base_string, libname_fmt[i].format, filename);
2172
2173 if (ldfile_try_open_bfd (full_string, entry))
2174 break;
2175 }
2176
2177 if (!libname_fmt[i].format)
2178 {
2179 free (full_string);
2180 return FALSE;
2181 }
2182
2183 entry->filename = full_string;
2184
2185 return TRUE;
2186}
2187
2188static int
2189gld_${EMULATION_NAME}_find_potential_libraries
2190 (char *name, lang_input_statement_type *entry)
2191{
2192 return ldfile_open_file_search (name, entry, "", ".lib");
2193}
2194\f
2195static char *
2196gld_${EMULATION_NAME}_get_script (int *isfile)
2197EOF
2198# Scripts compiled in.
2199# sed commands to quote an ld script as a C string.
2200sc="-f stringify.sed"
2201
92b93329 2202fragment <<EOF
99ad8390
NC
2203{
2204 *isfile = 0;
2205
0e1862bb 2206 if (bfd_link_relocatable (&link_info) && config.build_constructors)
99ad8390
NC
2207 return
2208EOF
2209sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
0e1862bb 2210echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
99ad8390
NC
2211sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2212echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2213sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2214echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2215sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
e2a83dd0 2216if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
6ec6c79c 2217echo ' ; else if (link_info.pei386_auto_import == 1 && link_info.pei386_runtime_pseudo_reloc != 2) return' >> e${EMULATION_NAME}.c
e2a83dd0
NC
2218sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2219fi
99ad8390
NC
2220echo ' ; else return' >> e${EMULATION_NAME}.c
2221sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2222echo '; }' >> e${EMULATION_NAME}.c
2223
92b93329 2224fragment <<EOF
99ad8390
NC
2225
2226
2227struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2228{
2229 gld_${EMULATION_NAME}_before_parse,
2230 syslib_default,
2231 hll_default,
2232 gld_${EMULATION_NAME}_after_parse,
2233 gld_${EMULATION_NAME}_after_open,
2234 after_allocation_default,
2235 set_output_arch_default,
2236 ldemul_default_target,
2237 gld_${EMULATION_NAME}_before_allocation,
2238 gld_${EMULATION_NAME}_get_script,
2239 "${EMULATION_NAME}",
2240 "${OUTPUT_FORMAT}",
2241 gld_${EMULATION_NAME}_finish,
2242 NULL, /* Create output section statements. */
2243 gld_${EMULATION_NAME}_open_dynamic_archive,
2244 gld_${EMULATION_NAME}_place_orphan,
2245 gld_${EMULATION_NAME}_set_symbols,
2246 NULL, /* parse_args */
2247 gld${EMULATION_NAME}_add_options,
2248 gld${EMULATION_NAME}_handle_option,
2249 gld_${EMULATION_NAME}_unrecognized_file,
2250 gld_${EMULATION_NAME}_list_options,
2251 gld_${EMULATION_NAME}_recognized_file,
2252 gld_${EMULATION_NAME}_find_potential_libraries,
7a2f2d82
DD
2253 NULL, /* new_vers_pattern. */
2254 NULL /* extra_map_file_text */
99ad8390
NC
2255};
2256EOF