]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/emultempl/pe.em
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / emultempl / pe.em
CommitLineData
252b5132
RH
1# This shell script emits a C file. -*- C -*-
2# It does some substitutions.
3fc90ddb 3if [ -z "$MACHINE" ]; then
86af25fe
L
4 OUTPUT_ARCH=${ARCH}
5else
6 OUTPUT_ARCH=${ARCH}:${MACHINE}
7fi
ef6379e1
JD
8
9case ${target} in
10 *-*-cygwin*)
11 cygwin_behavior=1
12 ;;
13 *)
14 cygwin_behavior=0;
15 ;;
16esac
17
361d94e7
ILT
18rm -f e${EMULATION_NAME}.c
19(echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
92b93329 20fragment <<EOF
a2c58332 21/* Copyright (C) 1995-2022 Free Software Foundation, Inc.
252b5132 22
f96b4a7b
NC
23 This file is part of the GNU Binutils.
24
2fa9fc65
NC
25 This program is free software; you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
f96b4a7b 27 the Free Software Foundation; either version 3 of the License, or
2fa9fc65 28 (at your option) any later version.
252b5132 29
2fa9fc65
NC
30 This program is distributed in the hope that it will be useful,
31 but WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 GNU General Public License for more details.
252b5132 34
2fa9fc65
NC
35 You should have received a copy of the GNU General Public License
36 along with this program; if not, write to the Free Software
f96b4a7b
NC
37 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
38 MA 02110-1301, USA. */
39
252b5132
RH
40
41/* For WINDOWS_NT */
42/* The original file generated returned different default scripts depending
43 on whether certain switches were set, but these switches pertain to the
44 Linux system and that particular version of coff. In the NT case, we
45 only determine if the subsystem is console or windows in order to select
3fc90ddb
AJ
46 the correct entry point by default. */
47
db09f25b
AM
48#define TARGET_IS_${EMULATION_NAME}
49
252b5132 50#include "sysdep.h"
3db64b00 51#include "bfd.h"
252b5132 52#include "bfdlink.h"
1ff6de03 53#include "ctf-api.h"
252b5132
RH
54#include "getopt.h"
55#include "libiberty.h"
42627821 56#include "filenames.h"
252b5132
RH
57#include "ld.h"
58#include "ldmain.h"
252b5132
RH
59#include "ldexp.h"
60#include "ldlang.h"
b71e2778 61#include "ldfile.h"
252b5132 62#include "ldemul.h"
df2a7313 63#include <ldgram.h>
252b5132
RH
64#include "ldlex.h"
65#include "ldmisc.h"
66#include "ldctor.h"
61e2488c 67#include "ldbuildid.h"
252b5132 68#include "coff/internal.h"
71add731 69
26d2d8a2
BF
70/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
71 header in generic PE code. */
72#include "coff/i386.h"
73#include "coff/pe.h"
74
61e2488c 75/* FIXME: These are BFD internal header files, and we should not be
71add731 76 using it here. */
252b5132 77#include "../bfd/libcoff.h"
61e2488c 78#include "../bfd/libpei.h"
71add731 79
f37164d7
AM
80#if defined(TARGET_IS_armpe) \
81 || defined(TARGET_IS_arm_wince_pe)
82#define bfd_arm_allocate_interworking_sections \
83 bfd_${EMULATION_NAME}_allocate_interworking_sections
84#define bfd_arm_get_bfd_for_interworking \
85 bfd_${EMULATION_NAME}_get_bfd_for_interworking
86#define bfd_arm_process_before_allocation \
87 bfd_${EMULATION_NAME}_process_before_allocation
88#include "coff-arm.h"
89#endif
90
252b5132 91#include "deffile.h"
1069dd8d 92#include "pe-dll.h"
29e1a6e4 93#include "safe-ctype.h"
14fe918e 94
2be9b2c7
ILT
95/* Permit the emulation parameters to override the default section
96 alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
97 it seem that include/coff/internal.h should not define
98 PE_DEF_SECTION_ALIGNMENT. */
99#if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
100#undef PE_DEF_SECTION_ALIGNMENT
101#define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
102#endif
103
7148cc28
NC
104#if defined(TARGET_IS_i386pe) \
105 || defined(TARGET_IS_shpe) \
7148cc28 106 || defined(TARGET_IS_armpe) \
7148cc28 107 || defined(TARGET_IS_arm_wince_pe)
344a211f
NC
108#define DLL_SUPPORT
109#endif
c6c37250 110
e468a046
KT
111#if defined(TARGET_IS_i386pe)
112#define DEFAULT_PSEUDO_RELOC_VERSION 2
113#else
114#define DEFAULT_PSEUDO_RELOC_VERSION 1
115#endif
116
ef6379e1
JD
117#define DEFAULT_DLL_CHARACTERISTICS (${cygwin_behavior} ? 0 : \
118 IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE \
514b4e19
JD
119 | IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)
120
344a211f 121#if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
c6c37250 122#define PE_DEF_SUBSYSTEM 3
344a211f
NC
123#else
124#undef NT_EXE_IMAGE_BASE
125#undef PE_DEF_SECTION_ALIGNMENT
126#undef PE_DEF_FILE_ALIGNMENT
127#define NT_EXE_IMAGE_BASE 0x00010000
7148cc28
NC
128
129#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
344a211f
NC
130#define PE_DEF_SECTION_ALIGNMENT 0x00001000
131#define PE_DEF_SUBSYSTEM 9
132#else
133#define PE_DEF_SECTION_ALIGNMENT 0x00000400
134#define PE_DEF_SUBSYSTEM 2
135#endif
136#define PE_DEF_FILE_ALIGNMENT 0x00000200
137#endif
c6c37250 138
252b5132
RH
139static struct internal_extra_pe_aouthdr pe;
140static int dll;
decfa41e 141static int pe_subsystem = ${SUBSYSTEM};
26d2d8a2 142static flagword real_flags = 0;
252b5132 143static int support_old_code = 0;
6f798e5c 144static char * thumb_entry_symbol = NULL;
252b5132 145static lang_assignment_statement_type *image_base_statement = 0;
514b4e19 146static unsigned short pe_dll_characteristics = DEFAULT_DLL_CHARACTERISTICS;
f38a2680 147static bool insert_timestamp = true;
61e2488c 148static const char *emit_build_id;
252b5132 149
f0c87f88 150#ifdef DLL_SUPPORT
4cd89863 151static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */
690a460e 152static char *pe_out_def_filename = NULL;
5f577f7d 153static int pe_enable_auto_image_base = 0;
d0e6d77b 154static unsigned long pe_auto_image_base = 0x61500000;
627427de 155static char *pe_dll_search_prefix = NULL;
f0c87f88 156#endif
252b5132
RH
157
158extern const char *output_filename;
159
d74720d2 160static int is_underscoring (void)
252b5132 161{
d74720d2
KT
162 int u = 0;
163 if (pe_leading_underscore != -1)
164 return pe_leading_underscore;
165 if (!bfd_get_target_info ("${OUTPUT_FORMAT}", NULL, NULL, &u, NULL))
b804e4af
KT
166 bfd_get_target_info ("${RELOCATEABLE_OUTPUT_FORMAT}", NULL, NULL, &u, NULL);
167
168 if (u == -1)
169 abort ();
d74720d2
KT
170 pe_leading_underscore = (u != 0 ? 1 : 0);
171 return pe_leading_underscore;
172}
b804e4af 173
d74720d2
KT
174static void
175gld_${EMULATION_NAME}_before_parse (void)
176{
177 is_underscoring ();
5e2f1575 178 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
db8d4f23 179 output_filename = "${EXECUTABLE_NAME:-a.exe}";
c6c37250 180#ifdef DLL_SUPPORT
f38a2680 181 input_flags.dynamic = true;
252b5132 182 config.has_shared = 1;
5b9c6027
DK
183EOF
184
185# Cygwin no longer wants these noisy warnings. Other PE
186# targets might like to consider adding themselves here.
27320b85
NC
187# See also the mail thread starting here for the reason why
188# merge_rdata defaults to 0 for cygwin:
189# http://cygwin.com/ml/cygwin-apps/2013-04/msg00187.html
5b9c6027
DK
190case ${target} in
191 *-*-cygwin*)
192 default_auto_import=1
27320b85 193 default_merge_rdata=0
ca5f2203 194 ;;
09db93a8 195 i[3-7]86-*-mingw* | x86_64-*-mingw*)
ca5f2203
KT
196 default_auto_import=1
197 default_merge_rdata=0
5b9c6027
DK
198 ;;
199 *)
200 default_auto_import=-1
ca5f2203 201 default_merge_rdata=1
5b9c6027
DK
202 ;;
203esac
204
205fragment <<EOF
206 link_info.pei386_auto_import = ${default_auto_import};
e468a046
KT
207 /* Use by default version. */
208 link_info.pei386_runtime_pseudo_reloc = DEFAULT_PSEUDO_RELOC_VERSION;
252b5132
RH
209#endif
210}
211\f
ca5f2203
KT
212/* Indicates if RDATA shall be merged into DATA when pseudo-relocation
213 version 2 is used and auto-import is enabled. */
214#define MERGE_RDATA_V2 ${default_merge_rdata}
215
252b5132
RH
216/* PE format extra command line options. */
217
4cd89863 218/* Used for setting flags in the PE header. */
252b5132
RH
219#define OPTION_BASE_FILE (300 + 1)
220#define OPTION_DLL (OPTION_BASE_FILE + 1)
221#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
222#define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
223#define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
224#define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
225#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
226#define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
227#define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
228#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
229#define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
0c7a8e5a
AM
230#define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
231#define OPTION_SUBSYSTEM (OPTION_STACK + 1)
252b5132
RH
232#define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
233#define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
234#define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
235#define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
236#define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
2927aaca
NC
237#define OPTION_EXCLUDE_ALL_SYMBOLS (OPTION_EXCLUDE_SYMBOLS + 1)
238#define OPTION_KILL_ATS (OPTION_EXCLUDE_ALL_SYMBOLS + 1)
252b5132
RH
239#define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
240#define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
241#define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
76359541 242#define OPTION_THUMB_ENTRY (OPTION_DISABLE_STDCALL_FIXUP + 1)
870df5dc
NC
243#define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
244#define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
5f577f7d
DD
245#define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1)
246#define OPTION_DISABLE_AUTO_IMAGE_BASE (OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
1122a5fc
NC
247#define OPTION_DLL_SEARCH_PREFIX (OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
248#define OPTION_NO_DEFAULT_EXCLUDES (OPTION_DLL_SEARCH_PREFIX + 1)
decc3638
CW
249#define OPTION_DLL_ENABLE_AUTO_IMPORT (OPTION_NO_DEFAULT_EXCLUDES + 1)
250#define OPTION_DLL_DISABLE_AUTO_IMPORT (OPTION_DLL_ENABLE_AUTO_IMPORT + 1)
251#define OPTION_ENABLE_EXTRA_PE_DEBUG (OPTION_DLL_DISABLE_AUTO_IMPORT + 1)
70b0be79 252#define OPTION_EXCLUDE_LIBS (OPTION_ENABLE_EXTRA_PE_DEBUG + 1)
2fa9fc65
NC
253#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC \
254 (OPTION_EXCLUDE_LIBS + 1)
255#define OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC \
256 (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC + 1)
6c19b93b 257#define OPTION_LARGE_ADDRESS_AWARE (OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC + 1)
f69a2f97 258#define OPTION_DISABLE_LARGE_ADDRESS_AWARE \
6c19b93b 259 (OPTION_LARGE_ADDRESS_AWARE + 1)
6cb442d3 260#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1 \
f69a2f97 261 (OPTION_DISABLE_LARGE_ADDRESS_AWARE + 1)
6cb442d3
KT
262#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2 \
263 (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1 + 1)
e1c37eb5
DK
264#define OPTION_EXCLUDE_MODULES_FOR_IMPLIB \
265 (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2 + 1)
ce11ba6c 266#define OPTION_USE_NUL_PREFIXED_IMPORT_TABLES \
88183869 267 (OPTION_EXCLUDE_MODULES_FOR_IMPLIB + 1)
6c19b93b
AM
268#define OPTION_NO_LEADING_UNDERSCORE (OPTION_USE_NUL_PREFIXED_IMPORT_TABLES + 1)
269#define OPTION_LEADING_UNDERSCORE (OPTION_NO_LEADING_UNDERSCORE + 1)
522f09cd
KT
270#define OPTION_ENABLE_LONG_SECTION_NAMES \
271 (OPTION_LEADING_UNDERSCORE + 1)
88183869
DK
272#define OPTION_DISABLE_LONG_SECTION_NAMES \
273 (OPTION_ENABLE_LONG_SECTION_NAMES + 1)
0cb112f7 274/* DLLCharacteristics flags. */
2f563b51
DK
275#define OPTION_DYNAMIC_BASE (OPTION_DISABLE_LONG_SECTION_NAMES + 1)
276#define OPTION_FORCE_INTEGRITY (OPTION_DYNAMIC_BASE + 1)
277#define OPTION_NX_COMPAT (OPTION_FORCE_INTEGRITY + 1)
e4492aa0 278#define OPTION_NO_ISOLATION (OPTION_NX_COMPAT + 1)
2f563b51
DK
279#define OPTION_NO_SEH (OPTION_NO_ISOLATION + 1)
280#define OPTION_NO_BIND (OPTION_NO_SEH + 1)
281#define OPTION_WDM_DRIVER (OPTION_NO_BIND + 1)
282#define OPTION_TERMINAL_SERVER_AWARE (OPTION_WDM_DRIVER + 1)
0cb112f7
CF
283/* Determinism. */
284#define OPTION_INSERT_TIMESTAMP (OPTION_TERMINAL_SERVER_AWARE + 1)
eeb14e5a
LZ
285#define OPTION_NO_INSERT_TIMESTAMP (OPTION_INSERT_TIMESTAMP + 1)
286#define OPTION_BUILD_ID (OPTION_NO_INSERT_TIMESTAMP + 1)
dc9bd8c9 287#define OPTION_ENABLE_RELOC_SECTION (OPTION_BUILD_ID + 1)
514b4e19
JD
288#define OPTION_DISABLE_RELOC_SECTION (OPTION_ENABLE_RELOC_SECTION + 1)
289/* DLL Characteristics flags. */
290#define OPTION_DISABLE_DYNAMIC_BASE (OPTION_DISABLE_RELOC_SECTION + 1)
291#define OPTION_DISABLE_FORCE_INTEGRITY (OPTION_DISABLE_DYNAMIC_BASE + 1)
292#define OPTION_DISABLE_NX_COMPAT (OPTION_DISABLE_FORCE_INTEGRITY + 1)
293#define OPTION_DISABLE_NO_ISOLATION (OPTION_DISABLE_NX_COMPAT + 1)
294#define OPTION_DISABLE_NO_SEH (OPTION_DISABLE_NO_ISOLATION + 1)
295#define OPTION_DISABLE_NO_BIND (OPTION_DISABLE_NO_SEH + 1)
296#define OPTION_DISABLE_WDM_DRIVER (OPTION_DISABLE_NO_BIND + 1)
297#define OPTION_DISABLE_TERMINAL_SERVER_AWARE \
298 (OPTION_DISABLE_WDM_DRIVER + 1)
252b5132 299
3bcf5557 300static void
0c7a8e5a 301gld${EMULATION_NAME}_add_options
d127ecce
AM
302 (int ns ATTRIBUTE_UNUSED,
303 char **shortopts ATTRIBUTE_UNUSED,
304 int nl,
305 struct option **longopts,
306 int nrl ATTRIBUTE_UNUSED,
307 struct option **really_longopts ATTRIBUTE_UNUSED)
3bcf5557 308{
27320b85
NC
309 static const struct option xtra_long[] =
310 {
311 /* PE options. */
3bcf5557
AM
312 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
313 {"dll", no_argument, NULL, OPTION_DLL},
314 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
315 {"heap", required_argument, NULL, OPTION_HEAP},
316 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
317 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
318 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
319 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
320 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
321 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
322 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
323 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
324 {"stack", required_argument, NULL, OPTION_STACK},
325 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
326 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
327 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
ce11ba6c
KT
328 {"use-nul-prefixed-import-tables", no_argument, NULL,
329 OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
522f09cd
KT
330 {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
331 {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
0cb112f7 332 {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
eeb14e5a 333 {"no-insert-timestamp", no_argument, NULL, OPTION_NO_INSERT_TIMESTAMP},
c6c37250 334#ifdef DLL_SUPPORT
d127ecce
AM
335 /* getopt allows abbreviations, so we do this to stop it
336 from treating -o as an abbreviation for this option. */
3bcf5557
AM
337 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
338 {"output-def", required_argument, NULL, OPTION_OUT_DEF},
339 {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
340 {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
2927aaca 341 {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
3bcf5557 342 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
e1c37eb5 343 {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
3bcf5557
AM
344 {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
345 {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
346 {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
347 {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
3bcf5557
AM
348 {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
349 /* getopt() allows abbreviations, so we do this to stop it from
350 treating -c as an abbreviation for these --compat-implib. */
351 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
352 {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
d0e6d77b 353 {"enable-auto-image-base", optional_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
3bcf5557
AM
354 {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
355 {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
356 {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
357 {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
358 {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
359 {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
360 {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
361 {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
6cb442d3
KT
362 {"enable-runtime-pseudo-reloc-v1", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1},
363 {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
252b5132 364#endif
26d2d8a2 365 {"large-address-aware", no_argument, NULL, OPTION_LARGE_ADDRESS_AWARE},
f69a2f97 366 {"disable-large-address-aware", no_argument, NULL, OPTION_DISABLE_LARGE_ADDRESS_AWARE},
88183869
DK
367 {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
368 {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
2f563b51 369 {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
514b4e19 370 {"disable-dynamicbase",no_argument, NULL, OPTION_DISABLE_DYNAMIC_BASE},
2f563b51 371 {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
514b4e19 372 {"disable-forceinteg", no_argument, NULL, OPTION_DISABLE_FORCE_INTEGRITY},
2f563b51 373 {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
514b4e19 374 {"disable-nxcompat", no_argument, NULL, OPTION_DISABLE_NX_COMPAT},
2f563b51 375 {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
514b4e19 376 {"disable-no-isolation", no_argument, NULL, OPTION_DISABLE_NO_ISOLATION},
2f563b51 377 {"no-seh", no_argument, NULL, OPTION_NO_SEH},
514b4e19 378 {"disable-no-seh", no_argument, NULL, OPTION_DISABLE_NO_SEH},
2f563b51 379 {"no-bind", no_argument, NULL, OPTION_NO_BIND},
514b4e19 380 {"disable-no-bind", no_argument, NULL, OPTION_DISABLE_NO_BIND},
2f563b51 381 {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
514b4e19 382 {"disable-wdmdriver", no_argument, NULL, OPTION_DISABLE_WDM_DRIVER},
2f563b51 383 {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
514b4e19 384 {"disable-tsaware", no_argument, NULL, OPTION_DISABLE_TERMINAL_SERVER_AWARE},
61e2488c 385 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
dc9bd8c9 386 {"enable-reloc-section", no_argument, NULL, OPTION_ENABLE_RELOC_SECTION},
514b4e19 387 {"disable-reloc-section", no_argument, NULL, OPTION_DISABLE_RELOC_SECTION},
3bcf5557
AM
388 {NULL, no_argument, NULL, 0}
389 };
252b5132 390
d127ecce
AM
391 *longopts
392 = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
3bcf5557
AM
393 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
394}
252b5132
RH
395
396/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
4cd89863 397 parameters which may be input from the command line. */
252b5132
RH
398
399typedef struct
400{
401 void *ptr;
402 int size;
403 int value;
404 char *symbol;
405 int inited;
522f09cd
KT
406 /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
407 C visible symbols can be prefixed by underscore dependent to target's
408 settings. */
f38a2680 409 bool is_c_symbol;
252b5132
RH
410} definfo;
411
522f09cd
KT
412/* Get symbol name dependent to kind and C visible state of
413 underscore. */
414#define GET_INIT_SYMBOL_NAME(IDX) \
415 (init[(IDX)].symbol \
535b785f 416 + ((!init[(IDX)].is_c_symbol || is_underscoring () != 0) ? 0 : 1))
522f09cd
KT
417
418/* Decorates the C visible symbol by underscore, if target requires. */
419#define U(CSTR) \
d74720d2 420 ((is_underscoring () == 0) ? CSTR : "_" CSTR)
522f09cd 421
61e2488c 422#define D(field,symbol,def,usc) {&pe.field, sizeof (pe.field), def, symbol, 0, usc}
252b5132
RH
423
424static definfo init[] =
425{
426 /* imagebase must be first */
427#define IMAGEBASEOFF 0
f38a2680 428 D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE, false),
252b5132 429#define DLLOFF 1
f38a2680 430 {&dll, sizeof(dll), 0, "__dll__", 0, false},
dffc6a64 431#define MSIMAGEBASEOFF 2
f38a2680
AM
432 D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, true),
433 D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, false),
434 D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, false),
435 D(MajorOperatingSystemVersion,"__major_os_version__", 4, false),
436 D(MinorOperatingSystemVersion,"__minor_os_version__", 0, false),
437 D(MajorImageVersion,"__major_image_version__", 1, false),
438 D(MinorImageVersion,"__minor_image_version__", 0, false),
7148cc28 439#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
f38a2680 440 D(MajorSubsystemVersion,"__major_subsystem_version__", 3, false),
344a211f 441#else
f38a2680 442 D(MajorSubsystemVersion,"__major_subsystem_version__", 4, false),
344a211f 443#endif
f38a2680
AM
444 D(MinorSubsystemVersion,"__minor_subsystem_version__", 0, false),
445 D(Subsystem,"__subsystem__", ${SUBSYSTEM}, false),
446 D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, false),
447 D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, false),
448 D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, false),
449 D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, false),
450 D(LoaderFlags,"__loader_flags__", 0x0, false),
451 D(DllCharacteristics, "__dll_characteristics__", DEFAULT_DLL_CHARACTERISTICS, false),
452 { NULL, 0, 0, NULL, 0 , false}
252b5132
RH
453};
454
4cd89863 455
252b5132 456static void
0c7a8e5a 457gld_${EMULATION_NAME}_list_options (FILE *file)
252b5132
RH
458{
459 fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
460 fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
461 fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
462 fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
463 fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
464 fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
465 fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
466 fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
467 fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
468 fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
469 fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
470 fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
471 fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
472 fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
473 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
522f09cd 474 fprintf (file, _(" --[no-]leading-underscore Set explicit symbol underscore prefix mode\n"));
6f798e5c 475 fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
eeb14e5a 476 fprintf (file, _(" --[no-]insert-timestamp Use a real timestamp rather than zero (default).\n"));
0cb112f7 477 fprintf (file, _(" This makes binaries non-deterministic\n"));
c6c37250 478#ifdef DLL_SUPPORT
252b5132
RH
479 fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
480 fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
481 fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
482 fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
2927aaca 483 fprintf (file, _(" --exclude-all-symbols Exclude all symbols from automatic export\n"));
b34976b6 484 fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
e1c37eb5
DK
485 fprintf (file, _(" --exclude-modules-for-implib mod,mod,...\n"));
486 fprintf (file, _(" Exclude objects, archive members from auto\n"));
487 fprintf (file, _(" export, place into import library instead.\n"));
252b5132
RH
488 fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
489 fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
252b5132 490 fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
d0e6d77b 491 fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports\n"));
e3c8793a
NC
492 fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
493 create __imp_<SYMBOL> as well.\n"));
d0e6d77b
CF
494 fprintf (file, _(" --enable-auto-image-base[=<address>] Automatically choose image base for DLLs\n\
495 (optionally starting with address) unless\n\
496 specifically set with --image-base\n"));
5f577f7d 497 fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
489d0400
NC
498 fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
499 an importlib, use <string><basename>.dll\n\
e3c8793a 500 in preference to lib<basename>.dll \n"));
c85f715a 501 fprintf (file, _(" --enable-auto-import Do sophisticated linking of _sym to\n\
e3c8793a 502 __imp_sym for DATA references\n"));
decc3638 503 fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
2fa9fc65 504 fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
489d0400
NC
505 adding pseudo-relocations resolved at\n\
506 runtime.\n"));
2fa9fc65
NC
507 fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
508 auto-imported DATA.\n"));
e3c8793a
NC
509 fprintf (file, _(" --enable-extra-pe-debug Enable verbose debug output when building\n\
510 or linking to DLLs (esp. auto-import)\n"));
252b5132 511#endif
26d2d8a2
BF
512 fprintf (file, _(" --large-address-aware Executable supports virtual addresses\n\
513 greater than 2 gigabytes\n"));
f69a2f97
NC
514 fprintf (file, _(" --disable-large-address-aware Executable does not support virtual\n\
515 addresses greater than 2 gigabytes\n"));
88183869
DK
516 fprintf (file, _(" --enable-long-section-names Use long COFF section names even in\n\
517 executable image files\n"));
518 fprintf (file, _(" --disable-long-section-names Never use long COFF section names, even\n\
519 in object files\n"));
514b4e19 520 fprintf (file, _(" --[disable-]dynamicbase Image base address may be relocated using\n\
df5f2391 521 address space layout randomization (ASLR)\n"));
dc9bd8c9 522 fprintf (file, _(" --enable-reloc-section Create the base relocation table\n"));
514b4e19
JD
523 fprintf (file, _(" --disable-reloc-section Do not create the base relocation table\n"));
524 fprintf (file, _(" --[disable-]forceinteg Code integrity checks are enforced\n"));
525 fprintf (file, _(" --[disable-]nxcompat Image is compatible with data execution\n\
526 prevention\n"));
527 fprintf (file, _(" --[disable-]no-isolation Image understands isolation but do not\n\
528 isolate the image\n"));
529 fprintf (file, _(" --[disable-]no-seh Image does not use SEH. No SE handler may\n\
df5f2391 530 be called in this image\n"));
514b4e19
JD
531 fprintf (file, _(" --[disable-]no-bind Do not bind this image\n"));
532 fprintf (file, _(" --[disable-]wdmdriver Driver uses the WDM model\n"));
533 fprintf (file, _(" --[disable-]tsaware Image is Terminal Server aware\n"));
534 fprintf (file, _(" --build-id[=STYLE] Generate build ID\n"));
252b5132
RH
535}
536
4cd89863 537
252b5132 538static void
0c7a8e5a 539set_pe_name (char *name, long val)
252b5132 540{
d74720d2
KT
541 int i;
542 is_underscoring ();
4cd89863
NC
543
544 /* Find the name and set it. */
252b5132
RH
545 for (i = 0; init[i].ptr; i++)
546 {
522f09cd 547 if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
252b5132
RH
548 {
549 init[i].value = val;
550 init[i].inited = 1;
dffc6a64
KT
551 if (strcmp (name,"__image_base__") == 0)
552 set_pe_name (U ("__ImageBase"), val);
252b5132
RH
553 return;
554 }
555 }
939ba9d0 556 abort ();
252b5132
RH
557}
558
decfa41e
KT
559static void
560set_entry_point (void)
561{
562 const char *entry;
563 const char *initial_symbol_char;
d74720d2 564 int i;
decfa41e
KT
565
566 static const struct
6c19b93b
AM
567 {
568 const int value;
569 const char *entry;
570 }
decfa41e
KT
571 v[] =
572 {
573 { 1, "NtProcessStartup" },
574 { 2, "WinMainCRTStartup" },
575 { 3, "mainCRTStartup" },
576 { 7, "__PosixProcessStartup"},
577 { 9, "WinMainCRTStartup" },
578 {14, "mainCRTStartup" },
579 { 0, NULL }
580 };
581
582 /* Entry point name for arbitrary subsystem numbers. */
583 static const char default_entry[] = "mainCRTStartup";
584
307f2595 585 if (bfd_link_dll (&link_info) || dll)
decfa41e
KT
586 {
587#if defined (TARGET_IS_i386pe)
588 entry = "DllMainCRTStartup@12";
589#else
590 entry = "DllMainCRTStartup";
591#endif
592 }
593 else
594 {
decfa41e 595 for (i = 0; v[i].entry; i++)
6c19b93b
AM
596 if (v[i].value == pe_subsystem)
597 break;
decfa41e
KT
598
599 /* If no match, use the default. */
600 if (v[i].entry != NULL)
6c19b93b 601 entry = v[i].entry;
decfa41e 602 else
6c19b93b 603 entry = default_entry;
decfa41e
KT
604 }
605
d74720d2 606 initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
522f09cd 607
decfa41e
KT
608 if (*initial_symbol_char != '\0')
609 {
610 char *alc_entry;
611
612 /* lang_default_entry expects its argument to be permanently
613 allocated, so we don't free this string. */
614 alc_entry = xmalloc (strlen (initial_symbol_char)
615 + strlen (entry)
616 + 1);
617 strcpy (alc_entry, initial_symbol_char);
618 strcat (alc_entry, entry);
619 entry = alc_entry;
620 }
621
622 lang_default_entry (entry);
623}
252b5132
RH
624
625static void
0c7a8e5a 626set_pe_subsystem (void)
252b5132
RH
627{
628 const char *sver;
33f362e1 629 char *end;
252b5132
RH
630 int len;
631 int i;
33f362e1 632 unsigned long temp_subsystem;
3fc90ddb 633 static const struct
252b5132
RH
634 {
635 const char *name;
636 const int value;
252b5132
RH
637 }
638 v[] =
639 {
decfa41e
KT
640 { "native", 1},
641 { "windows", 2},
642 { "console", 3},
643 { "posix", 7},
644 { "wince", 9},
645 { "xbox", 14},
646 { NULL, 0 }
252b5132
RH
647 };
648
33f362e1 649 /* Check for the presence of a version number. */
252b5132
RH
650 sver = strchr (optarg, ':');
651 if (sver == NULL)
652 len = strlen (optarg);
653 else
654 {
252b5132
RH
655 len = sver - optarg;
656 set_pe_name ("__major_subsystem_version__",
decfa41e 657 strtoul (sver + 1, &end, 0));
252b5132
RH
658 if (*end == '.')
659 set_pe_name ("__minor_subsystem_version__",
decfa41e 660 strtoul (end + 1, &end, 0));
252b5132
RH
661 if (*end != '\0')
662 einfo (_("%P: warning: bad version number in -subsystem option\n"));
663 }
664
33f362e1
NC
665 /* Check for numeric subsystem. */
666 temp_subsystem = strtoul (optarg, & end, 0);
667 if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
252b5132 668 {
33f362e1
NC
669 /* Search list for a numeric match to use its entry point. */
670 for (i = 0; v[i].name; i++)
671 if (v[i].value == (int) temp_subsystem)
672 break;
673
33f362e1 674 /* Use this subsystem. */
decfa41e 675 pe_subsystem = (int) temp_subsystem;
33f362e1
NC
676 }
677 else
678 {
679 /* Search for subsystem by name. */
680 for (i = 0; v[i].name; i++)
681 if (strncmp (optarg, v[i].name, len) == 0
682 && v[i].name[len] == '\0')
683 break;
252b5132 684
33f362e1
NC
685 if (v[i].name == NULL)
686 {
df5f2391 687 einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
252b5132
RH
688 return;
689 }
33f362e1 690
decfa41e 691 pe_subsystem = v[i].value;
252b5132 692 }
3fc90ddb 693
decfa41e 694 set_pe_name ("__subsystem__", pe_subsystem);
33f362e1
NC
695
696 return;
252b5132
RH
697}
698
699
252b5132 700static void
0c7a8e5a 701set_pe_value (char *name)
252b5132
RH
702{
703 char *end;
3fc90ddb 704
252b5132 705 set_pe_name (name, strtoul (optarg, &end, 0));
3fc90ddb 706
252b5132 707 if (end == optarg)
df5f2391 708 einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
252b5132
RH
709
710 optarg = end;
711}
712
4cd89863 713
252b5132 714static void
0c7a8e5a 715set_pe_stack_heap (char *resname, char *comname)
252b5132
RH
716{
717 set_pe_value (resname);
3fc90ddb 718
252b5132
RH
719 if (*optarg == ',')
720 {
721 optarg++;
722 set_pe_value (comname);
723 }
724 else if (*optarg)
df5f2391 725 einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
252b5132
RH
726}
727
61e2488c 728#define DEFAULT_BUILD_ID_STYLE "md5"
252b5132 729
f38a2680 730static bool
0c7a8e5a 731gld${EMULATION_NAME}_handle_option (int optc)
252b5132 732{
252b5132
RH
733 switch (optc)
734 {
735 default:
f38a2680 736 return false;
252b5132
RH
737
738 case OPTION_BASE_FILE:
0c7a8e5a 739 link_info.base_file = fopen (optarg, FOPEN_WB);
252b5132 740 if (link_info.base_file == NULL)
e922bcab 741 einfo (_("%F%P: cannot open base file %s\n"), optarg);
252b5132
RH
742 break;
743
4cd89863 744 /* PE options. */
3fc90ddb 745 case OPTION_HEAP:
252b5132
RH
746 set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
747 break;
3fc90ddb 748 case OPTION_STACK:
252b5132
RH
749 set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
750 break;
751 case OPTION_SUBSYSTEM:
752 set_pe_subsystem ();
753 break;
754 case OPTION_MAJOR_OS_VERSION:
755 set_pe_value ("__major_os_version__");
756 break;
757 case OPTION_MINOR_OS_VERSION:
758 set_pe_value ("__minor_os_version__");
759 break;
760 case OPTION_MAJOR_SUBSYSTEM_VERSION:
761 set_pe_value ("__major_subsystem_version__");
762 break;
763 case OPTION_MINOR_SUBSYSTEM_VERSION:
764 set_pe_value ("__minor_subsystem_version__");
765 break;
766 case OPTION_MAJOR_IMAGE_VERSION:
767 set_pe_value ("__major_image_version__");
768 break;
769 case OPTION_MINOR_IMAGE_VERSION:
770 set_pe_value ("__minor_image_version__");
771 break;
772 case OPTION_FILE_ALIGNMENT:
773 set_pe_value ("__file_alignment__");
774 break;
775 case OPTION_SECTION_ALIGNMENT:
776 set_pe_value ("__section_alignment__");
777 break;
778 case OPTION_DLL:
779 set_pe_name ("__dll__", 1);
780 break;
781 case OPTION_IMAGE_BASE:
782 set_pe_value ("__image_base__");
783 break;
784 case OPTION_SUPPORT_OLD_CODE:
785 support_old_code = 1;
786 break;
6f798e5c
NC
787 case OPTION_THUMB_ENTRY:
788 thumb_entry_symbol = optarg;
789 break;
ce11ba6c 790 case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
f38a2680 791 pe_use_nul_prefixed_import_tables = true;
ce11ba6c 792 break;
522f09cd
KT
793 case OPTION_NO_LEADING_UNDERSCORE:
794 pe_leading_underscore = 0;
795 break;
796 case OPTION_LEADING_UNDERSCORE:
797 pe_leading_underscore = 1;
798 break;
0cb112f7 799 case OPTION_INSERT_TIMESTAMP:
f38a2680 800 insert_timestamp = true;
0cb112f7 801 break;
eeb14e5a 802 case OPTION_NO_INSERT_TIMESTAMP:
f38a2680 803 insert_timestamp = false;
eeb14e5a 804 break;
c6c37250 805#ifdef DLL_SUPPORT
252b5132
RH
806 case OPTION_OUT_DEF:
807 pe_out_def_filename = xstrdup (optarg);
808 break;
809 case OPTION_EXPORT_ALL:
810 pe_dll_export_everything = 1;
811 break;
812 case OPTION_EXCLUDE_SYMBOLS:
e1c37eb5 813 pe_dll_add_excludes (optarg, EXCLUDESYMS);
70b0be79 814 break;
2927aaca
NC
815 case OPTION_EXCLUDE_ALL_SYMBOLS:
816 pe_dll_exclude_all_symbols = 1;
817 break;
70b0be79 818 case OPTION_EXCLUDE_LIBS:
e1c37eb5
DK
819 pe_dll_add_excludes (optarg, EXCLUDELIBS);
820 break;
821 case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
822 pe_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
252b5132
RH
823 break;
824 case OPTION_KILL_ATS:
825 pe_dll_kill_ats = 1;
826 break;
827 case OPTION_STDCALL_ALIASES:
828 pe_dll_stdcall_aliases = 1;
829 break;
830 case OPTION_ENABLE_STDCALL_FIXUP:
831 pe_enable_stdcall_fixup = 1;
832 break;
833 case OPTION_DISABLE_STDCALL_FIXUP:
834 pe_enable_stdcall_fixup = 0;
835 break;
870df5dc
NC
836 case OPTION_WARN_DUPLICATE_EXPORTS:
837 pe_dll_warn_dup_exports = 1;
838 break;
839 case OPTION_IMP_COMPAT:
840 pe_dll_compat_implib = 1;
841 break;
5f577f7d
DD
842 case OPTION_ENABLE_AUTO_IMAGE_BASE:
843 pe_enable_auto_image_base = 1;
d0e6d77b
CF
844 if (optarg && *optarg)
845 {
846 char *end;
61e2488c 847 pe_auto_image_base = strtoul (optarg, &end, 0);
d0e6d77b
CF
848 /* XXX should check that we actually parsed something */
849 }
5f577f7d
DD
850 break;
851 case OPTION_DISABLE_AUTO_IMAGE_BASE:
852 pe_enable_auto_image_base = 0;
853 break;
627427de 854 case OPTION_DLL_SEARCH_PREFIX:
939ba9d0 855 pe_dll_search_prefix = xstrdup (optarg);
627427de 856 break;
1122a5fc
NC
857 case OPTION_NO_DEFAULT_EXCLUDES:
858 pe_dll_do_default_excludes = 0;
859 break;
decc3638 860 case OPTION_DLL_ENABLE_AUTO_IMPORT:
e0076ab3 861 link_info.pei386_auto_import = 1;
decc3638
CW
862 break;
863 case OPTION_DLL_DISABLE_AUTO_IMPORT:
e0076ab3 864 link_info.pei386_auto_import = 0;
decc3638 865 break;
2fa9fc65 866 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
e468a046
KT
867 link_info.pei386_runtime_pseudo_reloc =
868 DEFAULT_PSEUDO_RELOC_VERSION;
2fa9fc65 869 break;
6cb442d3
KT
870 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1:
871 link_info.pei386_runtime_pseudo_reloc = 1;
872 break;
873 case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
874 link_info.pei386_runtime_pseudo_reloc = 2;
875 break;
2fa9fc65
NC
876 case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
877 link_info.pei386_runtime_pseudo_reloc = 0;
878 break;
decc3638
CW
879 case OPTION_ENABLE_EXTRA_PE_DEBUG:
880 pe_dll_extra_pe_debug = 1;
881 break;
c6c37250 882#endif
26d2d8a2
BF
883 case OPTION_LARGE_ADDRESS_AWARE:
884 real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
885 break;
f69a2f97
NC
886 case OPTION_DISABLE_LARGE_ADDRESS_AWARE:
887 real_flags &= ~ IMAGE_FILE_LARGE_ADDRESS_AWARE;
888 break;
88183869
DK
889 case OPTION_ENABLE_LONG_SECTION_NAMES:
890 pe_use_coff_long_section_names = 1;
891 break;
892 case OPTION_DISABLE_LONG_SECTION_NAMES:
893 pe_use_coff_long_section_names = 0;
894 break;
2f563b51
DK
895/* Get DLLCharacteristics bits */
896 case OPTION_DYNAMIC_BASE:
897 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
dc9bd8c9
HD
898 /* fall through */
899 case OPTION_ENABLE_RELOC_SECTION:
900 pe_dll_enable_reloc_section = 1;
2f563b51 901 break;
514b4e19
JD
902 case OPTION_DISABLE_RELOC_SECTION:
903 pe_dll_enable_reloc_section = 0;
904 /* fall through */
905 case OPTION_DISABLE_DYNAMIC_BASE:
906 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
907 break;
2f563b51
DK
908 case OPTION_FORCE_INTEGRITY:
909 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
910 break;
514b4e19
JD
911 case OPTION_DISABLE_FORCE_INTEGRITY:
912 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
913 break;
2f563b51
DK
914 case OPTION_NX_COMPAT:
915 pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
916 break;
514b4e19
JD
917 case OPTION_DISABLE_NX_COMPAT:
918 pe_dll_characteristics &= ~ IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
919 break;
2f563b51
DK
920 case OPTION_NO_ISOLATION:
921 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
922 break;
514b4e19
JD
923 case OPTION_DISABLE_NO_ISOLATION:
924 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
925 break;
2f563b51
DK
926 case OPTION_NO_SEH:
927 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
928 break;
514b4e19
JD
929 case OPTION_DISABLE_NO_SEH:
930 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_SEH;
931 break;
2f563b51
DK
932 case OPTION_NO_BIND:
933 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
934 break;
514b4e19
JD
935 case OPTION_DISABLE_NO_BIND:
936 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_NO_BIND;
937 break;
2f563b51
DK
938 case OPTION_WDM_DRIVER:
939 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
940 break;
514b4e19
JD
941 case OPTION_DISABLE_WDM_DRIVER:
942 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
943 break;
2f563b51
DK
944 case OPTION_TERMINAL_SERVER_AWARE:
945 pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
946 break;
514b4e19
JD
947 case OPTION_DISABLE_TERMINAL_SERVER_AWARE:
948 pe_dll_characteristics &= ~ IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
949 break;
61e2488c 950 case OPTION_BUILD_ID:
5e2ab612
AM
951 free ((char *) emit_build_id);
952 emit_build_id = NULL;
61e2488c
JT
953 if (optarg == NULL)
954 optarg = DEFAULT_BUILD_ID_STYLE;
955 if (strcmp (optarg, "none"))
956 emit_build_id = xstrdup (optarg);
957 break;
252b5132 958 }
2f563b51
DK
959
960 /* Set DLLCharacteristics bits */
961 set_pe_name ("__dll_characteristics__", pe_dll_characteristics);
962
f38a2680 963 return true;
252b5132
RH
964}
965\f
5f577f7d 966
2ef53d66 967#ifdef DLL_SUPPORT
3fc90ddb 968static unsigned long
5f577f7d
DD
969strhash (const char *str)
970{
971 const unsigned char *s;
972 unsigned long hash;
973 unsigned int c;
974 unsigned int len;
975
976 hash = 0;
977 len = 0;
978 s = (const unsigned char *) str;
979 while ((c = *s++) != '\0')
980 {
981 hash += c + (c << 17);
982 hash ^= hash >> 2;
983 ++len;
984 }
985 hash += len + (len << 17);
986 hash ^= hash >> 2;
987
988 return hash;
989}
990
4cd89863
NC
991/* Use the output file to create a image base for relocatable DLLs. */
992
5f577f7d
DD
993static unsigned long
994compute_dll_image_base (const char *ofile)
995{
996 unsigned long hash = strhash (ofile);
d0e6d77b 997 return pe_auto_image_base + ((hash << 16) & 0x0FFC0000);
5f577f7d 998}
2ef53d66 999#endif
5f577f7d 1000
252b5132
RH
1001/* Assign values to the special symbols before the linker script is
1002 read. */
1003
1004static void
0c7a8e5a 1005gld_${EMULATION_NAME}_set_symbols (void)
252b5132
RH
1006{
1007 /* Run through and invent symbols for all the
4cd89863 1008 names and insert the defaults. */
d74720d2 1009 int j;
b804e4af 1010
d74720d2 1011 is_underscoring ();
252b5132
RH
1012
1013 if (!init[IMAGEBASEOFF].inited)
1014 {
0e1862bb 1015 if (bfd_link_relocatable (&link_info))
252b5132 1016 init[IMAGEBASEOFF].value = 0;
0e1862bb 1017 else if (init[DLLOFF].value || bfd_link_dll (&link_info))
d127ecce 1018 {
2ef53d66 1019#ifdef DLL_SUPPORT
d127ecce
AM
1020 init[IMAGEBASEOFF].value = (pe_enable_auto_image_base
1021 ? compute_dll_image_base (output_filename)
1022 : NT_DLL_IMAGE_BASE);
2ef53d66 1023#else
d127ecce 1024 init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
2ef53d66 1025#endif
d127ecce 1026 }
252b5132
RH
1027 else
1028 init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
dffc6a64 1029 init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
252b5132
RH
1030 }
1031
1049f94e 1032 /* Don't do any symbol assignments if this is a relocatable link. */
0e1862bb 1033 if (bfd_link_relocatable (&link_info))
252b5132
RH
1034 return;
1035
4cd89863 1036 /* Glue the assignments into the abs section. */
bde18da4 1037 push_stat_ptr (&abs_output_section->children);
252b5132
RH
1038
1039 for (j = 0; init[j].ptr; j++)
1040 {
1041 long val = init[j].value;
1042 lang_assignment_statement_type *rv;
522f09cd 1043
2e57b2af 1044 rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
f38a2680 1045 exp_intop (val), false));
939ba9d0
NC
1046 if (init[j].size == sizeof (short))
1047 *(short *) init[j].ptr = val;
1048 else if (init[j].size == sizeof (int))
1049 *(int *) init[j].ptr = val;
1050 else if (init[j].size == sizeof (long))
1051 *(long *) init[j].ptr = val;
252b5132 1052 /* This might be a long long or other special type. */
939ba9d0
NC
1053 else if (init[j].size == sizeof (bfd_vma))
1054 *(bfd_vma *) init[j].ptr = val;
1055 else abort ();
252b5132
RH
1056 if (j == IMAGEBASEOFF)
1057 image_base_statement = rv;
1058 }
4cd89863 1059 /* Restore the pointer. */
bde18da4 1060 pop_stat_ptr ();
3fc90ddb 1061
d127ecce 1062 if (pe.FileAlignment > pe.SectionAlignment)
252b5132 1063 {
df5f2391 1064 einfo (_("%P: warning, file alignment > section alignment\n"));
252b5132
RH
1065 }
1066}
1067
1068/* This is called after the linker script and the command line options
1069 have been read. */
1070
1071static void
0c7a8e5a 1072gld_${EMULATION_NAME}_after_parse (void)
252b5132 1073{
8b747e1a
DK
1074 /* PR ld/6744: Warn the user if they have used an ELF-only
1075 option hoping it will work on PE. */
1076 if (link_info.export_dynamic)
1077 einfo (_("%P: warning: --export-dynamic is not supported for PE "
1078 "targets, did you mean --export-all-symbols?\n"));
97b11f40 1079
decfa41e
KT
1080 set_entry_point ();
1081
97b11f40 1082 after_parse_default ();
252b5132
RH
1083}
1084
2ef53d66 1085#ifdef DLL_SUPPORT
252b5132
RH
1086static struct bfd_link_hash_entry *pe_undef_found_sym;
1087
f38a2680 1088static bool
0c7a8e5a 1089pe_undef_cdecl_match (struct bfd_link_hash_entry *h, void *inf)
252b5132 1090{
decc3638 1091 int sl;
0c7a8e5a 1092 char *string = inf;
8a9eab9b 1093 const char *hs = h->root.string;
4cd89863 1094
0c7a8e5a 1095 sl = strlen (string);
252b5132 1096 if (h->type == bfd_link_hash_defined
8a9eab9b
KT
1097 && ((*hs == '@' && *string == '_'
1098 && strncmp (hs + 1, string + 1, sl - 1) == 0)
1099 || strncmp (hs, string, sl) == 0)
252b5132 1100 && h->root.string[sl] == '@')
decc3638
CW
1101 {
1102 pe_undef_found_sym = h;
f38a2680 1103 return false;
decc3638 1104 }
f38a2680 1105 return true;
252b5132
RH
1106}
1107
67f101ee
NC
1108/* Change UNDEF to a defined symbol, taking data from SYM. */
1109
1110static void
1111change_undef (struct bfd_link_hash_entry * undef,
1112 struct bfd_link_hash_entry * sym)
1113{
f38a2680 1114 static bool gave_warning_message = false;
67f101ee
NC
1115
1116 undef->type = bfd_link_hash_defined;
1117 undef->u.def.value = sym->u.def.value;
1118 undef->u.def.section = sym->u.def.section;
1119
1120 if (pe_enable_stdcall_fixup == -1)
1121 {
df5f2391 1122 einfo (_("%P: warning: resolving %s by linking to %s\n"),
67f101ee
NC
1123 undef->root.string, sym->root.string);
1124
1125 if (! gave_warning_message)
1126 {
1127 einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1128 einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
f38a2680 1129 gave_warning_message = true;
67f101ee
NC
1130 }
1131 }
1132
1133 /* PR 19803: Make sure that the linked symbol is not garbage collected. */
1134 lang_add_gc_name (sym->root.string);
1135}
1136
252b5132 1137static void
0c7a8e5a 1138pe_fixup_stdcalls (void)
252b5132 1139{
252b5132 1140 struct bfd_link_hash_entry *undef, *sym;
c9e38879 1141
3fc90ddb 1142 if (pe_dll_extra_pe_debug)
c9e38879 1143 printf ("%s\n", __FUNCTION__);
3fc90ddb 1144
f6e332e6 1145 for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
252b5132 1146 if (undef->type == bfd_link_hash_undefined)
252b5132 1147 {
67f101ee
NC
1148 const char * name = undef->root.string;
1149 char * at;
1150 int lead_at = (*name == '@');
1151
8a9eab9b 1152 if (lead_at)
67f101ee
NC
1153 at = strchr (name + 1, '@');
1154 else
1155 at = strchr (name, '@');
b34976b6 1156
8a9eab9b 1157 if (at || lead_at)
c9e38879
NC
1158 {
1159 /* The symbol is a stdcall symbol, so let's look for a
1160 cdecl symbol with the same name and resolve to that. */
67f101ee 1161 char *cname = xstrdup (name);
8a9eab9b
KT
1162
1163 if (lead_at)
1164 *cname = '_';
6c19b93b 1165 if (at)
67f101ee 1166 * strchr (cname, '@') = 0;
f38a2680 1167 sym = bfd_link_hash_lookup (link_info.hash, cname, false, false, true);
c9e38879
NC
1168
1169 if (sym && sym->type == bfd_link_hash_defined)
67f101ee 1170 change_undef (undef, sym);
c9e38879
NC
1171 }
1172 else
1173 {
1174 /* The symbol is a cdecl symbol, so we look for stdcall
4cd89863 1175 symbols - which means scanning the whole symbol table. */
67f101ee 1176 pe_undef_found_sym = NULL;
c9e38879 1177 bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
67f101ee
NC
1178 (char *) name);
1179 if (pe_undef_found_sym)
1180 change_undef (undef, pe_undef_found_sym);
c9e38879 1181 }
252b5132 1182 }
252b5132 1183}
decc3638 1184
317ff008
EB
1185static void
1186make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
decc3638 1187{
fc0a2244 1188 struct bfd_symbol *sym = *rel->sym_ptr_ptr;
c99b8138 1189 char addend[4];
317ff008 1190 bfd_vma _addend;
decc3638 1191
3fc90ddb 1192 if (pe_dll_extra_pe_debug)
c9e38879 1193 printf ("arelent: %s@%#lx: add=%li\n", sym->name,
0af1713e 1194 (unsigned long) rel->address, (long) rel->addend);
0d888aac 1195
c99b8138 1196 if (! bfd_get_section_contents (s->owner, s, addend, rel->address, sizeof (addend)))
df5f2391 1197 einfo (_("%P: %C: cannot get section contents - auto-import exception\n"),
c9e38879 1198 s->owner, s, rel->address);
0d888aac 1199
317ff008
EB
1200 _addend = bfd_get_32 (s->owner, addend);
1201 pe_create_import_fixup (rel, s, _addend, name, symname);
decc3638 1202}
252b5132 1203
f38a2680 1204static bool
0c7a8e5a 1205pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
decc3638 1206{
80cc85a9 1207 printf ("+%s\n", h->string);
c9e38879 1208
f38a2680 1209 return true;
decc3638 1210}
4b83d615 1211#endif /* DLL_SUPPORT */
decc3638 1212
e4492aa0 1213static void
3efd345c
DK
1214debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1215{
1216 int *found = (int *) obj;
1217 if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
1218 *found = 1;
1219}
decc3638 1220
f38a2680 1221static bool
61e2488c
JT
1222pecoff_checksum_contents (bfd *abfd,
1223 void (*process) (const void *, size_t, void *),
1224 void *arg)
1225{
1226 file_ptr filepos = (file_ptr) 0;
1227
1228 while (1)
1229 {
1230 unsigned char b;
1231 int status;
1232
1233 if (bfd_seek (abfd, filepos, SEEK_SET) != 0)
1234 return 0;
1235
1236 status = bfd_bread (&b, (bfd_size_type) 1, abfd);
1237 if (status < 1)
6c19b93b
AM
1238 {
1239 break;
1240 }
61e2488c
JT
1241
1242 (*process) (&b, 1, arg);
1243 filepos += 1;
1244 }
1245
f38a2680 1246 return true;
61e2488c
JT
1247}
1248
f38a2680 1249static bool
61e2488c
JT
1250write_build_id (bfd *abfd)
1251{
1252 struct pe_tdata *t = pe_data (abfd);
1253 asection *asec;
1254 struct bfd_link_order *link_order = NULL;
1255 unsigned char *contents;
1256 bfd_size_type size;
1257 bfd_size_type build_id_size;
1258 unsigned char *build_id;
1259
74fffc39 1260 /* Find the section the .buildid output section has been merged info. */
61e2488c
JT
1261 for (asec = abfd->sections; asec != NULL; asec = asec->next)
1262 {
1263 struct bfd_link_order *l = NULL;
1264 for (l = asec->map_head.link_order; l != NULL; l = l->next)
6c19b93b
AM
1265 {
1266 if (l->type == bfd_indirect_link_order)
1267 {
1268 if (l->u.indirect.section == t->build_id.sec)
1269 {
1270 link_order = l;
1271 break;
1272 }
1273 }
1274 }
61e2488c
JT
1275
1276 if (link_order)
6c19b93b 1277 break;
61e2488c
JT
1278 }
1279
1280 if (!link_order)
1281 {
74fffc39 1282 einfo (_("%P: warning: .buildid section discarded,"
df5f2391 1283 " --build-id ignored\n"));
f38a2680 1284 return true;
61e2488c
JT
1285 }
1286
1287 if (t->build_id.sec->contents == NULL)
1288 t->build_id.sec->contents = (unsigned char *) xmalloc (t->build_id.sec->size);
1289 contents = t->build_id.sec->contents;
1290 size = t->build_id.sec->size;
1291
1292 build_id_size = compute_build_id_size (t->build_id.style);
1293 build_id = xmalloc (build_id_size);
1294 generate_build_id (abfd, t->build_id.style, pecoff_checksum_contents, build_id, build_id_size);
1295
1296 bfd_vma ib = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase;
1297
1298 /* Construct a debug directory entry which points to an immediately following CodeView record. */
1299 struct internal_IMAGE_DEBUG_DIRECTORY idd;
1300 idd.Characteristics = 0;
1301 idd.TimeDateStamp = 0;
1302 idd.MajorVersion = 0;
1303 idd.MinorVersion = 0;
1304 idd.Type = PE_IMAGE_DEBUG_TYPE_CODEVIEW;
1305 idd.SizeOfData = sizeof (CV_INFO_PDB70) + 1;
1306 idd.AddressOfRawData = asec->vma - ib + link_order->offset
1307 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1308 idd.PointerToRawData = asec->filepos + link_order->offset
1309 + sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1310
1311 struct external_IMAGE_DEBUG_DIRECTORY *ext = (struct external_IMAGE_DEBUG_DIRECTORY *)contents;
1312 _bfd_XXi_swap_debugdir_out (abfd, &idd, ext);
1313
1314 /* Write the debug directory entry. */
1315 if (bfd_seek (abfd, asec->filepos + link_order->offset, SEEK_SET) != 0)
1316 return 0;
1317
b6518b38 1318 if (bfd_bwrite (contents, size, abfd) != size)
61e2488c
JT
1319 return 0;
1320
1321 /* Construct the CodeView record. */
1322 CODEVIEW_INFO cvinfo;
1323 cvinfo.CVSignature = CVINFO_PDB70_CVSIGNATURE;
1324 cvinfo.Age = 1;
1325
1326 /* Zero pad or truncate the generated build_id to fit in the CodeView record. */
1327 memset (&(cvinfo.Signature), 0, CV_INFO_SIGNATURE_LENGTH);
1328 memcpy (&(cvinfo.Signature), build_id, (build_id_size > CV_INFO_SIGNATURE_LENGTH)
1329 ? CV_INFO_SIGNATURE_LENGTH : build_id_size);
1330
1331 free (build_id);
1332
1333 /* Write the codeview record. */
1334 if (_bfd_XXi_write_codeview_record (abfd, idd.PointerToRawData, &cvinfo) == 0)
1335 return 0;
1336
1337 /* Record the location of the debug directory in the data directory. */
1338 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].VirtualAddress
1339 = asec->vma - ib + link_order->offset;
1340 pe_data (link_info.output_bfd)->pe_opthdr.DataDirectory[PE_DEBUG_DATA].Size
1341 = sizeof (struct external_IMAGE_DEBUG_DIRECTORY);
1342
f38a2680 1343 return true;
61e2488c
JT
1344}
1345
74fffc39 1346/* Make .buildid section, and set up coff_tdata->build_id. */
f38a2680 1347static bool
61e2488c
JT
1348setup_build_id (bfd *ibfd)
1349{
1350 asection *s;
1351 flagword flags;
1352
1353 if (!validate_build_id_style (emit_build_id))
1354 {
df5f2391 1355 einfo (_("%P: warning: unrecognized --build-id style ignored\n"));
f38a2680 1356 return false;
61e2488c
JT
1357 }
1358
1359 flags = (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1360 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
74fffc39 1361 s = bfd_make_section_anyway_with_flags (ibfd, ".buildid", flags);
61e2488c
JT
1362 if (s != NULL)
1363 {
1364 struct pe_tdata *t = pe_data (link_info.output_bfd);
1365 t->build_id.after_write_object_contents = &write_build_id;
1366 t->build_id.style = emit_build_id;
1367 t->build_id.sec = s;
1368
1369 /* Section is a fixed size:
1370 One IMAGE_DEBUG_DIRECTORY entry, of type IMAGE_DEBUG_TYPE_CODEVIEW,
1371 pointing at a CV_INFO_PDB70 record containing the build-id, with a
1372 null byte for PdbFileName. */
1373 s->size = sizeof (struct external_IMAGE_DEBUG_DIRECTORY)
1374 + sizeof (CV_INFO_PDB70) + 1;
1375
f38a2680 1376 return true;
61e2488c
JT
1377 }
1378
df5f2391
AM
1379 einfo (_("%P: warning: cannot create .buildid section,"
1380 " --build-id ignored\n"));
f38a2680 1381 return false;
61e2488c
JT
1382}
1383
252b5132 1384static void
0c7a8e5a 1385gld_${EMULATION_NAME}_after_open (void)
252b5132 1386{
5c3049d2
AM
1387 after_open_default ();
1388
4b83d615 1389#ifdef DLL_SUPPORT
3fc90ddb 1390 if (pe_dll_extra_pe_debug)
decc3638
CW
1391 {
1392 bfd *a;
1393 struct bfd_link_hash_entry *sym;
c9e38879 1394
decc3638
CW
1395 printf ("%s()\n", __FUNCTION__);
1396
f6e332e6 1397 for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1af699f4 1398 printf ("-%s\n", sym->root.string);
0c7a8e5a 1399 bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
decc3638 1400
c72f2fb2 1401 for (a = link_info.input_bfds; a; a = a->link.next)
607b4833 1402 printf ("*%s\n", bfd_get_filename (a));
decc3638 1403 }
4b83d615 1404#endif
3fc90ddb 1405
61e2488c
JT
1406 if (emit_build_id != NULL)
1407 {
1408 bfd *abfd;
1409
1410 /* Find a COFF input. */
1411 for (abfd = link_info.input_bfds;
c72f2fb2 1412 abfd != (bfd *) NULL; abfd = abfd->link.next)
61e2488c
JT
1413 if (bfd_get_flavour (abfd) == bfd_target_coff_flavour)
1414 break;
1415
1416 /* If there are no COFF input files do not try to
1417 add a build-id section. */
1418 if (abfd == NULL
1419 || !setup_build_id (abfd))
1420 {
1421 free ((char *) emit_build_id);
1422 emit_build_id = NULL;
1423 }
1424 }
1425
252b5132
RH
1426 /* Pass the wacky PE command line options into the output bfd.
1427 FIXME: This should be done via a function, rather than by
1428 including an internal BFD header. */
3fc90ddb 1429
eabf307f
AM
1430 if (bfd_get_flavour (link_info.output_bfd) != bfd_target_coff_flavour
1431 || coff_data (link_info.output_bfd) == NULL
f13a99db 1432 || coff_data (link_info.output_bfd)->pe == 0)
df5f2391 1433 einfo (_("%F%P: cannot perform PE operations on non PE output file '%pB'\n"),
f13a99db 1434 link_info.output_bfd);
252b5132 1435
f13a99db
AM
1436 pe_data (link_info.output_bfd)->pe_opthdr = pe;
1437 pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1438 pe_data (link_info.output_bfd)->real_flags |= real_flags;
00386881
NC
1439 if (insert_timestamp)
1440 pe_data (link_info.output_bfd)->timestamp = -1;
1441 else
1442 pe_data (link_info.output_bfd)->timestamp = 0;
3efd345c
DK
1443
1444 /* At this point we must decide whether to use long section names
1445 in the output or not. If the user hasn't explicitly specified
1446 on the command line, we leave it to the default for the format
1447 (object files yes, image files no), except if there is debug
1448 information present; GDB relies on the long section names to
1449 find it, so enable it in that case. */
1450 if (pe_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1451 {
0e1862bb 1452 if (bfd_link_relocatable (&link_info))
61e2488c
JT
1453 pe_use_coff_long_section_names = 1;
1454 else
3efd345c 1455 {
61e2488c
JT
1456 /* Iterate over all sections of all input BFDs, checking
1457 for any that begin 'debug_' and are long names. */
1458 LANG_FOR_EACH_INPUT_STATEMENT (is)
1459 {
1460 int found_debug = 0;
1461
1462 bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1463 if (found_debug)
1464 {
1465 pe_use_coff_long_section_names = 1;
1466 break;
1467 }
1468 }
3efd345c
DK
1469 }
1470 }
1471
88183869 1472 pe_output_file_set_long_section_names (link_info.output_bfd);
252b5132 1473
c6c37250 1474#ifdef DLL_SUPPORT
f13a99db 1475 pe_process_import_defs (link_info.output_bfd, &link_info);
939ba9d0 1476
317ff008
EB
1477 if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
1478 pe_find_data_imports (U ("_head_"), make_import_fixup);
decc3638 1479
317ff008
EB
1480 /* The implementation of the feature is rather dumb and would cause the
1481 compilation time to go through the roof if there are many undefined
1482 symbols in the link, so it needs to be run after auto-import. */
1483 if (pe_enable_stdcall_fixup) /* -1=warn or 1=enable */
8a9eab9b
KT
1484 pe_fixup_stdcalls ();
1485
7148cc28
NC
1486#if defined (TARGET_IS_i386pe) \
1487 || defined (TARGET_IS_armpe) \
7148cc28 1488 || defined (TARGET_IS_arm_wince_pe)
0e1862bb 1489 if (!bfd_link_relocatable (&link_info))
f13a99db 1490 pe_dll_build_sections (link_info.output_bfd, &link_info);
7148cc28 1491#else
0e1862bb 1492 if (bfd_link_pic (&link_info))
f13a99db 1493 pe_dll_build_sections (link_info.output_bfd, &link_info);
1491f1f0
DK
1494 else
1495 pe_exe_build_sections (link_info.output_bfd, &link_info);
344a211f 1496#endif
7148cc28 1497#endif /* DLL_SUPPORT */
252b5132 1498
ddb00039 1499#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
f13a99db 1500 if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL)
f11523b0
NC
1501 {
1502 /* The arm backend needs special fields in the output hash structure.
1503 These will only be created if the output format is an arm format,
1504 hence we do not support linking and changing output formats at the
1505 same time. Use a link followed by objcopy to change output formats. */
df5f2391
AM
1506 einfo (_("%F%P: error: cannot change output format "
1507 "whilst linking %s binaries\n"), "ARM");
f11523b0
NC
1508 return;
1509 }
252b5132
RH
1510 {
1511 /* Find a BFD that can hold the interworking stubs. */
1512 LANG_FOR_EACH_INPUT_STATEMENT (is)
1513 {
7148cc28 1514 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
252b5132
RH
1515 break;
1516 }
1517 }
1518#endif
c6c37250 1519
486e80e2 1520 {
486e80e2
DD
1521 /* This next chunk of code tries to detect the case where you have
1522 two import libraries for the same DLL (specifically,
1523 symbolically linking libm.a and libc.a in cygwin to
1524 libcygwin.a). In those cases, it's possible for function
1525 thunks from the second implib to be used but without the
1526 head/tail objects, causing an improper import table. We detect
1527 those cases and rename the "other" import libraries to match
1528 the one the head/tail come from, so that the linker will sort
4cd89863 1529 things nicely and produce a valid import table. */
486e80e2
DD
1530
1531 LANG_FOR_EACH_INPUT_STATEMENT (is)
1532 {
1533 if (is->the_bfd->my_archive)
1534 {
1535 int idata2 = 0, reloc_count=0, is_imp = 0;
1536 asection *sec;
3fc90ddb 1537
6e45556a 1538 /* See if this is an import library thunk. */
486e80e2
DD
1539 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1540 {
1541 if (strcmp (sec->name, ".idata\$2") == 0)
1542 idata2 = 1;
08dedd66 1543 if (startswith (sec->name, ".idata\$"))
486e80e2
DD
1544 is_imp = 1;
1545 reloc_count += sec->reloc_count;
1546 }
3fc90ddb 1547
486e80e2
DD
1548 if (is_imp && !idata2 && reloc_count)
1549 {
6e45556a
NC
1550 /* It is, look for the reference to head and see if it's
1551 from our own library. */
486e80e2
DD
1552 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1553 {
1554 int i;
6e45556a 1555 long relsize;
102c86f8 1556 asymbol **symbols;
102c86f8
NC
1557 arelent **relocs;
1558 int nrelocs;
3fc90ddb 1559
102c86f8 1560 relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
6e45556a
NC
1561 if (relsize < 1)
1562 break;
3fc90ddb 1563
5c1d2f5f 1564 if (!bfd_generic_link_read_symbols (is->the_bfd))
6e45556a 1565 {
df5f2391 1566 einfo (_("%F%P: %pB: could not read symbols: %E\n"),
5c1d2f5f 1567 is->the_bfd);
6e45556a
NC
1568 return;
1569 }
5c1d2f5f 1570 symbols = bfd_get_outsymbols (is->the_bfd);
3fc90ddb 1571
d127ecce 1572 relocs = xmalloc ((size_t) relsize);
102c86f8 1573 nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
f6e332e6 1574 relocs, symbols);
6e45556a
NC
1575 if (nrelocs < 0)
1576 {
1577 free (relocs);
d003af55 1578 einfo (_("%X%P: unable to process relocs: %E\n"));
6e45556a
NC
1579 return;
1580 }
3fc90ddb 1581
6e45556a 1582 for (i = 0; i < nrelocs; i++)
486e80e2 1583 {
fc0a2244 1584 struct bfd_symbol *s;
6e45556a 1585 struct bfd_link_hash_entry * blhe;
b16c44de 1586 const char *other_bfd_filename;
3fc90ddb 1587
486e80e2 1588 s = (relocs[i]->sym_ptr_ptr)[0];
3fc90ddb 1589
6e45556a
NC
1590 if (s->flags & BSF_LOCAL)
1591 continue;
3fc90ddb 1592
6e45556a
NC
1593 /* Thunk section with reloc to another bfd. */
1594 blhe = bfd_link_hash_lookup (link_info.hash,
1595 s->name,
f38a2680 1596 false, false, true);
3fc90ddb 1597
6e45556a
NC
1598 if (blhe == NULL
1599 || blhe->type != bfd_link_hash_defined)
1600 continue;
3fc90ddb 1601
2a08daf3
DS
1602 other_bfd_filename
1603 = blhe->u.def.section->owner->my_archive
1604 ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1605 : bfd_get_filename (blhe->u.def.section->owner);
3fc90ddb 1606
42627821
KT
1607 if (filename_cmp (bfd_get_filename
1608 (is->the_bfd->my_archive),
1609 other_bfd_filename) == 0)
6e45556a 1610 continue;
3fc90ddb 1611
c034e3e0 1612 /* Rename this implib to match the other one. */
7b958a48
AM
1613 if (!bfd_set_filename (is->the_bfd->my_archive,
1614 other_bfd_filename))
1615 einfo ("%F%P: %pB: %E\n", is->the_bfd);
486e80e2
DD
1616 }
1617
1618 free (relocs);
6e45556a
NC
1619 /* Note - we do not free the symbols,
1620 they are now cached in the BFD. */
486e80e2
DD
1621 }
1622 }
1623 }
1624 }
1625 }
1626
c6c37250 1627 {
f0c87f88 1628 int is_ms_arch = 0;
1069dd8d 1629 bfd *cur_arch = 0;
c6c37250 1630 lang_input_statement_type *is2;
44dbf363 1631 lang_input_statement_type *is3;
1069dd8d 1632
c6c37250
DD
1633 /* Careful - this is a shell script. Watch those dollar signs! */
1634 /* Microsoft import libraries have every member named the same,
1635 and not in the right order for us to link them correctly. We
1636 must detect these and rename the members so that they'll link
1637 correctly. There are three types of objects: the head, the
1638 thunks, and the sentinel(s). The head is easy; it's the one
1639 with idata2. We assume that the sentinels won't have relocs,
1640 and the thunks will. It's easier than checking the symbol
1069dd8d 1641 table for external references. */
c6c37250
DD
1642 LANG_FOR_EACH_INPUT_STATEMENT (is)
1643 {
1644 if (is->the_bfd->my_archive)
1645 {
44dbf363 1646 char *pnt;
c6c37250 1647 bfd *arch = is->the_bfd->my_archive;
44dbf363 1648
c6c37250
DD
1649 if (cur_arch != arch)
1650 {
1651 cur_arch = arch;
1652 is_ms_arch = 1;
44dbf363
NC
1653
1654 for (is3 = is;
1655 is3 && is3->the_bfd->my_archive == arch;
1656 is3 = (lang_input_statement_type *) is3->next)
1657 {
1af699f4 1658 /* A MS dynamic import library can also contain static
44dbf363
NC
1659 members, so look for the first element with a .dll
1660 extension, and use that for the remainder of the
1661 comparisons. */
607b4833 1662 pnt = strrchr (bfd_get_filename (is3->the_bfd), '.');
42627821 1663 if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
ff71f4f7 1664 break;
44dbf363
NC
1665 }
1666
1667 if (is3 == NULL)
1668 is_ms_arch = 0;
1669 else
c6c37250 1670 {
44dbf363
NC
1671 /* OK, found one. Now look to see if the remaining
1672 (dynamic import) members use the same name. */
1673 for (is2 = is;
1674 is2 && is2->the_bfd->my_archive == arch;
1675 is2 = (lang_input_statement_type *) is2->next)
1676 {
1677 /* Skip static members, ie anything with a .obj
1678 extension. */
607b4833 1679 pnt = strrchr (bfd_get_filename (is2->the_bfd), '.');
42627821 1680 if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
44dbf363
NC
1681 continue;
1682
607b4833
AM
1683 if (filename_cmp (bfd_get_filename (is3->the_bfd),
1684 bfd_get_filename (is2->the_bfd)))
44dbf363
NC
1685 {
1686 is_ms_arch = 0;
1687 break;
1688 }
1689 }
c6c37250
DD
1690 }
1691 }
1692
44dbf363
NC
1693 /* This fragment might have come from an .obj file in a Microsoft
1694 import, and not an actual import record. If this is the case,
1695 then leave the filename alone. */
607b4833 1696 pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
44dbf363 1697
42627821 1698 if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
c6c37250 1699 {
1069dd8d 1700 int idata2 = 0, reloc_count=0;
c6c37250
DD
1701 asection *sec;
1702 char *new_name, seq;
1069dd8d 1703
c6c37250
DD
1704 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1705 {
1706 if (strcmp (sec->name, ".idata\$2") == 0)
1707 idata2 = 1;
1708 reloc_count += sec->reloc_count;
1709 }
1710
1711 if (idata2) /* .idata2 is the TOC */
1712 seq = 'a';
1713 else if (reloc_count > 0) /* thunks */
1714 seq = 'b';
1715 else /* sentinel */
1716 seq = 'c';
1717
7b958a48
AM
1718 new_name
1719 = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
1720 sprintf (new_name, "%s.%c",
1721 bfd_get_filename (is->the_bfd), seq);
1722 is->filename = bfd_set_filename (is->the_bfd, new_name);
1723 free (new_name);
1724 if (!is->filename)
1725 einfo ("%F%P: %pB: %E\n", is->the_bfd);
c6c37250
DD
1726 }
1727 }
1728 }
1729 }
54727719
NC
1730
1731 {
1732 /* The following chunk of code tries to identify jump stubs in
1733 import libraries which are dead code and eliminates them
1734 from the final link. For each exported symbol <sym>, there
1735 is a object file in the import library with a .text section
d34c1c51 1736 and several .idata\$* sections. The .text section contains the
54727719 1737 symbol definition for <sym> which is a jump stub of the form
d34c1c51 1738 jmp *__imp_<sym>. The .idata\$5 contains the symbol definition
54727719
NC
1739 for __imp_<sym> which is the address of the slot for <sym> in
1740 the import address table. When a symbol is imported explicitly
1741 using __declspec(dllimport) declaration, the compiler generates
1742 a reference to __imp_<sym> which directly resolves to the
d34c1c51 1743 symbol in .idata\$5, in which case the jump stub code is not
54727719
NC
1744 needed. The following code tries to identify jump stub sections
1745 in import libraries which are not referred to by anyone and
1746 marks them for exclusion from the final link. */
1747 LANG_FOR_EACH_INPUT_STATEMENT (is)
1748 {
1749 if (is->the_bfd->my_archive)
1750 {
1751 int is_imp = 0;
1752 asection *sec, *stub_sec = NULL;
1753
1754 /* See if this is an import library thunk. */
1755 for (sec = is->the_bfd->sections; sec; sec = sec->next)
1756 {
1757 if (strncmp (sec->name, ".idata\$", 7) == 0)
1758 is_imp = 1;
1759 /* The section containing the jmp stub has code
1760 and has a reloc. */
1761 if ((sec->flags & SEC_CODE) && sec->reloc_count)
1762 stub_sec = sec;
1763 }
92b93329 1764
54727719
NC
1765 if (is_imp && stub_sec)
1766 {
54727719 1767 asymbol **symbols;
5c1d2f5f 1768 long nsyms, src_count;
54727719
NC
1769 struct bfd_link_hash_entry * blhe;
1770
5c1d2f5f
AM
1771 if (!bfd_generic_link_read_symbols (is->the_bfd))
1772 {
df5f2391 1773 einfo (_("%F%P: %pB: could not read symbols: %E\n"),
5c1d2f5f
AM
1774 is->the_bfd);
1775 return;
1776 }
1777 symbols = bfd_get_outsymbols (is->the_bfd);
1778 nsyms = bfd_get_symcount (is->the_bfd);
54727719 1779
5c1d2f5f 1780 for (src_count = 0; src_count < nsyms; src_count++)
54727719
NC
1781 {
1782 if (symbols[src_count]->section->id == stub_sec->id)
1783 {
1784 /* This symbol belongs to the section containing
1785 the stub. */
1786 blhe = bfd_link_hash_lookup (link_info.hash,
1787 symbols[src_count]->name,
f38a2680 1788 false, false, true);
54727719
NC
1789 /* If the symbol in the stub section has no other
1790 undefined references, exclude the stub section
1791 from the final link. */
e0605dbe
AM
1792 if (blhe != NULL
1793 && blhe->type == bfd_link_hash_defined
1794 && blhe->u.undef.next == NULL
1795 && blhe != link_info.hash->undefs_tail)
54727719
NC
1796 stub_sec->flags |= SEC_EXCLUDE;
1797 }
1798 }
54727719
NC
1799 }
1800 }
1801 }
1802 }
252b5132
RH
1803}
1804\f
3fc90ddb 1805static void
0c7a8e5a 1806gld_${EMULATION_NAME}_before_allocation (void)
252b5132 1807{
ddb00039 1808#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
252b5132
RH
1809 /* FIXME: we should be able to set the size of the interworking stub
1810 section.
1811
1812 Here we rummage through the found bfds to collect glue
1813 information. FIXME: should this be based on a command line
c9e38879 1814 option? krk@cygnus.com. */
252b5132
RH
1815 {
1816 LANG_FOR_EACH_INPUT_STATEMENT (is)
1817 {
7148cc28 1818 if (! bfd_arm_process_before_allocation
252b5132
RH
1819 (is->the_bfd, & link_info, support_old_code))
1820 {
1821 /* xgettext:c-format */
df5f2391 1822 einfo (_("%P: errors encountered processing file %s for interworking\n"),
252b5132
RH
1823 is->filename);
1824 }
1825 }
1826 }
1827
c9e38879 1828 /* We have seen it all. Allocate it, and carry on. */
7148cc28 1829 bfd_arm_allocate_interworking_sections (& link_info);
ddb00039 1830#endif /* TARGET_IS_armpe || TARGET_IS_arm_wince_pe */
8423293d 1831
1e035701 1832 before_allocation_default ();
252b5132
RH
1833}
1834\f
690a460e 1835#ifdef DLL_SUPPORT
252b5132 1836/* This is called when an input file isn't recognized as a BFD. We
c9e38879 1837 check here for .DEF files and pull them in automatically. */
690a460e 1838
252b5132 1839static int
0c7a8e5a 1840saw_option (char *option)
252b5132
RH
1841{
1842 int i;
c9e38879
NC
1843
1844 for (i = 0; init[i].ptr; i++)
522f09cd 1845 if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
252b5132
RH
1846 return init[i].inited;
1847 return 0;
1848}
690a460e 1849#endif /* DLL_SUPPORT */
252b5132 1850
f38a2680 1851static bool
0c7a8e5a 1852gld_${EMULATION_NAME}_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
252b5132 1853{
c6c37250 1854#ifdef DLL_SUPPORT
252b5132
RH
1855 const char *ext = entry->filename + strlen (entry->filename) - 4;
1856
42627821 1857 if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
252b5132 1858 {
f2d3750d 1859 pe_def_file = def_file_parse (entry->filename, pe_def_file);
c9e38879
NC
1860
1861 if (pe_def_file)
252b5132 1862 {
c9e38879
NC
1863 int i, buflen=0, len;
1864 char *buf;
252b5132 1865
c9e38879 1866 for (i = 0; i < pe_def_file->num_exports; i++)
252b5132 1867 {
939ba9d0 1868 len = strlen (pe_def_file->exports[i].internal_name);
c9e38879
NC
1869 if (buflen < len + 2)
1870 buflen = len + 2;
252b5132 1871 }
252b5132 1872
d127ecce 1873 buf = xmalloc (buflen);
252b5132 1874
c9e38879
NC
1875 for (i = 0; i < pe_def_file->num_exports; i++)
1876 {
1877 struct bfd_link_hash_entry *h;
1878
522f09cd 1879 sprintf (buf, "%s%s", U (""),
6c19b93b 1880 pe_def_file->exports[i].internal_name);
c9e38879 1881
f38a2680 1882 h = bfd_link_hash_lookup (link_info.hash, buf, true, true, true);
c9e38879 1883 if (h == (struct bfd_link_hash_entry *) NULL)
df5f2391 1884 einfo (_("%F%P: bfd_link_hash_lookup failed: %E\n"));
c9e38879
NC
1885 if (h->type == bfd_link_hash_new)
1886 {
1887 h->type = bfd_link_hash_undefined;
1888 h->u.undef.abfd = NULL;
1889 bfd_link_add_undef (link_info.hash, h);
1890 }
1891 }
1892 free (buf);
1893
1894 /* def_file_print (stdout, pe_def_file); */
1895 if (pe_def_file->is_dll == 1)
64d94ba0 1896 link_info.type = type_dll;
c9e38879
NC
1897
1898 if (pe_def_file->base_address != (bfd_vma)(-1))
1899 {
f13a99db
AM
1900 pe.ImageBase
1901 = pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1902 = init[IMAGEBASEOFF].value
1903 = pe_def_file->base_address;
c9e38879
NC
1904 init[IMAGEBASEOFF].inited = 1;
1905 if (image_base_statement)
eb8476a6
MR
1906 image_base_statement->exp
1907 = exp_assign ("__image_base__", exp_intop (pe.ImageBase),
f38a2680 1908 false);
c9e38879 1909 }
252b5132 1910
c9e38879
NC
1911 if (pe_def_file->stack_reserve != -1
1912 && ! saw_option ("__size_of_stack_reserve__"))
1913 {
1914 pe.SizeOfStackReserve = pe_def_file->stack_reserve;
1915 if (pe_def_file->stack_commit != -1)
1916 pe.SizeOfStackCommit = pe_def_file->stack_commit;
1917 }
1918 if (pe_def_file->heap_reserve != -1
1919 && ! saw_option ("__size_of_heap_reserve__"))
1920 {
1921 pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
1922 if (pe_def_file->heap_commit != -1)
1923 pe.SizeOfHeapCommit = pe_def_file->heap_commit;
1924 }
f38a2680 1925 return true;
c9e38879 1926 }
252b5132 1927 }
252b5132 1928#endif
f38a2680 1929 return false;
252b5132
RH
1930}
1931
f38a2680 1932static bool
0c7a8e5a 1933gld_${EMULATION_NAME}_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
252b5132 1934{
c6c37250 1935#ifdef DLL_SUPPORT
252b5132 1936#ifdef TARGET_IS_i386pe
c6c37250 1937 pe_dll_id_target ("pei-i386");
344a211f
NC
1938#endif
1939#ifdef TARGET_IS_shpe
1940 pe_dll_id_target ("pei-shl");
1941#endif
344a211f
NC
1942#ifdef TARGET_IS_armpe
1943 pe_dll_id_target ("pei-arm-little");
7148cc28 1944#endif
7148cc28
NC
1945#ifdef TARGET_IS_arm_wince_pe
1946 pe_dll_id_target ("pei-arm-wince-little");
c6c37250 1947#endif
ff2bdb9c
CF
1948 if (pe_bfd_is_dll (entry->the_bfd))
1949 return pe_implied_import_dll (entry->filename);
252b5132 1950#endif
f38a2680 1951 return false;
252b5132
RH
1952}
1953
1954static void
0c7a8e5a 1955gld_${EMULATION_NAME}_finish (void)
252b5132 1956{
ddb00039 1957#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
6f798e5c
NC
1958 struct bfd_link_hash_entry * h;
1959
1960 if (thumb_entry_symbol != NULL)
1961 {
b34976b6 1962 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
f38a2680 1963 false, false, true);
3fc90ddb 1964
6f798e5c
NC
1965 if (h != (struct bfd_link_hash_entry *) NULL
1966 && (h->type == bfd_link_hash_defined
1967 || h->type == bfd_link_hash_defweak)
1968 && h->u.def.section->output_section != NULL)
1969 {
1970 static char buffer[32];
1971 bfd_vma val;
3fc90ddb 1972
6f798e5c
NC
1973 /* Special procesing is required for a Thumb entry symbol. The
1974 bottom bit of its address must be set. */
1975 val = (h->u.def.value
fd361982 1976 + bfd_section_vma (h->u.def.section->output_section)
6f798e5c 1977 + h->u.def.section->output_offset);
3fc90ddb 1978
6f798e5c 1979 val |= 1;
3fc90ddb 1980
6f798e5c
NC
1981 /* Now convert this value into a string and store it in entry_symbol
1982 where the lang_finish() function will pick it up. */
1983 buffer[0] = '0';
1984 buffer[1] = 'x';
3fc90ddb 1985
6f798e5c 1986 sprintf_vma (buffer + 2, val);
3fc90ddb 1987
e3e942e9 1988 if (entry_symbol.name != NULL && entry_from_cmdline)
6f798e5c 1989 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
e3e942e9
AM
1990 thumb_entry_symbol, entry_symbol.name);
1991 entry_symbol.name = buffer;
6f798e5c
NC
1992 }
1993 else
c58dea77 1994 einfo (_("%P: warning: cannot find thumb start symbol %s\n"), thumb_entry_symbol);
6f798e5c 1995 }
ddb00039 1996#endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe) */
6f798e5c 1997
1e035701
AM
1998 finish_default ();
1999
c6c37250 2000#ifdef DLL_SUPPORT
0e1862bb 2001 if (bfd_link_pic (&link_info)
e8044f35 2002#if !defined(TARGET_IS_shpe)
dc9bd8c9 2003 || pe_dll_enable_reloc_section
0e1862bb
L
2004 || (!bfd_link_relocatable (&link_info)
2005 && pe_def_file->num_exports != 0)
2b817be1
NC
2006#endif
2007 )
252b5132 2008 {
f13a99db 2009 pe_dll_fill_sections (link_info.output_bfd, &link_info);
9cdc5bac 2010 if (command_line.out_implib_filename
51dee44b
JD
2011 && (pe_def_file->num_exports != 0
2012 || bfd_link_pic (&link_info)))
76359541
TP
2013 pe_dll_generate_implib (pe_def_file, command_line.out_implib_filename,
2014 &link_info);
252b5132 2015 }
e8044f35 2016#if defined(TARGET_IS_shpe)
690a460e 2017 /* ARM doesn't need relocs. */
344a211f
NC
2018 else
2019 {
f13a99db 2020 pe_exe_fill_sections (link_info.output_bfd, &link_info);
344a211f
NC
2021 }
2022#endif
3fc90ddb 2023
252b5132
RH
2024 if (pe_out_def_filename)
2025 pe_dll_generate_def_file (pe_out_def_filename);
690a460e 2026#endif /* DLL_SUPPORT */
decc3638 2027
c9e38879 2028 /* I don't know where .idata gets set as code, but it shouldn't be. */
decc3638 2029 {
f13a99db 2030 asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
c9e38879 2031
decc3638
CW
2032 if (asec)
2033 {
1af699f4
AM
2034 asec->flags &= ~SEC_CODE;
2035 asec->flags |= SEC_DATA;
decc3638
CW
2036 }
2037 }
252b5132
RH
2038}
2039
2040\f
2041/* Place an orphan section.
2042
2043 We use this to put sections in a reasonable place in the file, and
2044 to ensure that they are aligned as required.
2045
d34c1c51 2046 We handle grouped sections here as well. A section named .foo\$nn
252b5132
RH
2047 goes into the output section .foo. All grouped sections are sorted
2048 by name.
2049
2050 Grouped sections for the default sections are handled by the
2051 default linker script using wildcards, and are sorted by
2052 sort_sections. */
2053
c2edb4b8 2054static lang_output_section_statement_type *
8a99a385
AM
2055gld_${EMULATION_NAME}_place_orphan (asection *s,
2056 const char *secname,
2057 int constraint)
252b5132 2058{
bcacc0f5 2059 const char *orig_secname = secname;
f0c87f88 2060 char *dollar = NULL;
aea4bd9d 2061 lang_output_section_statement_type *os;
5ba47421 2062 lang_statement_list_type add_child;
b5f14a6d 2063 lang_output_section_statement_type *match_by_name = NULL;
011aa75f 2064 lang_statement_union_type **pl;
252b5132 2065
252b5132 2066 /* Look through the script to see where to place this section. */
0e1862bb 2067 if (!bfd_link_relocatable (&link_info)
d34c1c51 2068 && (dollar = strchr (secname, '\$')) != NULL)
6eec49fc 2069 {
bcacc0f5 2070 size_t len = dollar - secname;
afd7a018 2071 char *newname = xmalloc (len + 1);
bcacc0f5 2072 memcpy (newname, secname, len);
afd7a018
AM
2073 newname[len] = '\0';
2074 secname = newname;
6eec49fc 2075 }
252b5132 2076
5ba47421
AM
2077 lang_list_init (&add_child);
2078
d127ecce
AM
2079 os = NULL;
2080 if (constraint == 0)
2081 for (os = lang_output_section_find (secname);
2082 os != NULL;
2083 os = next_matching_output_section_statement (os, 0))
2084 {
2085 /* If we don't match an existing output section, tell
2086 lang_insert_orphan to create a new output section. */
2087 constraint = SPECIAL;
2088
2089 if (os->bfd_section != NULL
2090 && (os->bfd_section->flags == 0
2091 || ((s->flags ^ os->bfd_section->flags)
2092 & (SEC_LOAD | SEC_ALLOC)) == 0))
2093 {
2094 /* We already have an output section statement with this
2095 name, and its bfd section has compatible flags.
2096 If the section already exists but does not have any flags set,
2097 then it has been created by the linker, probably as a result of
2098 a --section-start command line switch. */
b209b5a6 2099 lang_add_section (&add_child, s, NULL, NULL, os);
d127ecce
AM
2100 break;
2101 }
b5f14a6d
DD
2102
2103 /* Save unused output sections in case we can match them
2104 against orphans later. */
2105 if (os->bfd_section == NULL)
2106 match_by_name = os;
d127ecce
AM
2107 }
2108
b5f14a6d
DD
2109 /* If we didn't match an active output section, see if we matched an
2110 unused one and use that. */
2111 if (os == NULL && match_by_name)
2112 {
b209b5a6 2113 lang_add_section (&match_by_name->children, s, NULL, NULL, match_by_name);
b5f14a6d
DD
2114 return match_by_name;
2115 }
2116
d127ecce 2117 if (os == NULL)
252b5132 2118 {
afd7a018
AM
2119 static struct orphan_save hold[] =
2120 {
2121 { ".text",
2122 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2123 0, 0, 0, 0 },
d4874973
KT
2124 { ".idata",
2125 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2126 0, 0, 0, 0 },
afd7a018
AM
2127 { ".rdata",
2128 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2129 0, 0, 0, 0 },
2130 { ".data",
2131 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2132 0, 0, 0, 0 },
2133 { ".bss",
2134 SEC_ALLOC,
2135 0, 0, 0, 0 }
2136 };
2137 enum orphan_save_index
2138 {
2139 orphan_text = 0,
d4874973 2140 orphan_idata,
afd7a018
AM
2141 orphan_rodata,
2142 orphan_data,
2143 orphan_bss
2144 };
2145 static int orphan_init_done = 0;
6a345e87 2146 struct orphan_save *place;
afd7a018 2147 lang_output_section_statement_type *after;
252b5132 2148 etree_type *address;
93638471
AM
2149 flagword flags;
2150 asection *nexts;
afd7a018
AM
2151
2152 if (!orphan_init_done)
2153 {
2154 struct orphan_save *ho;
2155 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2156 if (ho->name != NULL)
2157 {
2158 ho->os = lang_output_section_find (ho->name);
2159 if (ho->os != NULL && ho->os->flags == 0)
2160 ho->os->flags = ho->flags;
2161 }
2162 orphan_init_done = 1;
2163 }
252b5132 2164
523f4c92
L
2165 flags = s->flags;
2166 if (!bfd_link_relocatable (&link_info))
2167 {
2168 nexts = s;
2169 while ((nexts = bfd_get_next_section_by_name (nexts->owner,
2170 nexts)))
2171 if (nexts->output_section == NULL
2172 && (nexts->flags & SEC_EXCLUDE) == 0
2173 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2174 && (nexts->owner->flags & DYNAMIC) == 0
00f93c44 2175 && !bfd_input_just_syms (nexts->owner))
523f4c92
L
2176 flags = (((flags ^ SEC_READONLY)
2177 | (nexts->flags ^ SEC_READONLY))
2178 ^ SEC_READONLY);
2179 }
2180
252b5132
RH
2181 /* Try to put the new output section in a reasonable place based
2182 on the section name and section flags. */
aea4bd9d 2183
252b5132 2184 place = NULL;
93638471 2185 if ((flags & SEC_ALLOC) == 0)
5ba47421 2186 ;
93638471 2187 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
afd7a018 2188 place = &hold[orphan_bss];
93638471 2189 else if ((flags & SEC_READONLY) == 0)
afd7a018 2190 place = &hold[orphan_data];
93638471 2191 else if ((flags & SEC_CODE) == 0)
d4874973
KT
2192 {
2193 place = (!strncmp (secname, ".idata\$", 7) ? &hold[orphan_idata]
2194 : &hold[orphan_rodata]);
2195 }
1af699f4 2196 else
afd7a018 2197 place = &hold[orphan_text];
1af699f4 2198
afd7a018 2199 after = NULL;
1af699f4
AM
2200 if (place != NULL)
2201 {
afd7a018
AM
2202 if (place->os == NULL)
2203 place->os = lang_output_section_find (place->name);
2204 after = place->os;
2205 if (after == NULL)
93638471
AM
2206 after = lang_output_section_find_by_flags (s, flags, &place->os,
2207 NULL);
afd7a018
AM
2208 if (after == NULL)
2209 /* *ABS* is always the first output section statement. */
8ce18f9c 2210 after = (void *) lang_os_list.head;
252b5132
RH
2211 }
2212
4bf0cafb
DK
2213 /* All sections in an executable must be aligned to a page boundary.
2214 In a relocatable link, just preserve the incoming alignment; the
2215 address is discarded by lang_insert_orphan in that case, anyway. */
afd7a018 2216 address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
8a99a385
AM
2217 os = lang_insert_orphan (s, secname, constraint, after, place, address,
2218 &add_child);
0e1862bb 2219 if (bfd_link_relocatable (&link_info))
4bf0cafb 2220 {
3d9c8f6b 2221 os->section_alignment = exp_intop (1U << s->alignment_power);
4bf0cafb
DK
2222 os->bfd_section->alignment_power = s->alignment_power;
2223 }
252b5132
RH
2224 }
2225
011aa75f
AM
2226 /* If the section name has a '\$', sort it with the other '\$'
2227 sections. */
2228 for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
2229 {
2230 lang_input_section_type *ls;
2231 const char *lname;
252b5132 2232
011aa75f
AM
2233 if ((*pl)->header.type != lang_input_section_enum)
2234 continue;
252b5132 2235
011aa75f 2236 ls = &(*pl)->input_section;
252b5132 2237
fd361982 2238 lname = bfd_section_name (ls->section);
011aa75f
AM
2239 if (strchr (lname, '\$') != NULL
2240 && (dollar == NULL || strcmp (orig_secname, lname) < 0))
2241 break;
2242 }
5ba47421 2243
011aa75f
AM
2244 if (add_child.head != NULL)
2245 {
2246 *add_child.tail = *pl;
2247 *pl = add_child.head;
2248 }
252b5132 2249
c2edb4b8 2250 return os;
252b5132
RH
2251}
2252
f38a2680 2253static bool
0c7a8e5a 2254gld_${EMULATION_NAME}_open_dynamic_archive
d127ecce
AM
2255 (const char *arch ATTRIBUTE_UNUSED,
2256 search_dirs_type *search,
0c7a8e5a 2257 lang_input_statement_type *entry)
690a460e 2258{
45e948fe
NC
2259 static const struct
2260 {
2261 const char * format;
f38a2680 2262 bool use_prefix;
45e948fe
NC
2263 }
2264 libname_fmt [] =
2265 {
2266 /* Preferred explicit import library for dll's. */
f38a2680 2267 { "lib%s.dll.a", false },
45e948fe 2268 /* Alternate explicit import library for dll's. */
f38a2680 2269 { "%s.dll.a", false },
45e948fe 2270 /* "libfoo.a" could be either an import lib or a static lib.
6c19b93b
AM
2271 For backwards compatibility, libfoo.a needs to precede
2272 libfoo.dll and foo.dll in the search. */
f38a2680 2273 { "lib%s.a", false },
92b93329 2274 /* The 'native' spelling of an import lib name is "foo.lib". */
f38a2680 2275 { "%s.lib", false },
f6c4d4b1 2276 /* PR 22948 - Check for an import library. */
f38a2680 2277 { "lib%s.lib", false },
45e948fe
NC
2278#ifdef DLL_SUPPORT
2279 /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
f38a2680 2280 { "%s%s.dll", true },
45e948fe
NC
2281#endif
2282 /* Try "libfoo.dll" (default preferred dll name). */
f38a2680 2283 { "lib%s.dll", false },
45e948fe 2284 /* Finally try 'native' dll name "foo.dll". */
f38a2680 2285 { "%s.dll", false },
45e948fe
NC
2286 /* Note: If adding more formats to this table, make sure to check to
2287 see if their length is longer than libname_fmt[0].format, and if
2288 so, update the call to xmalloc() below. */
f38a2680 2289 { NULL, false }
45e948fe 2290 };
b1d9458a 2291 static unsigned int format_max_len = 0;
690a460e 2292 const char * filename;
45e948fe
NC
2293 char * full_string;
2294 char * base_string;
2295 unsigned int i;
2296
690a460e 2297
d4ae5fb0 2298 if (! entry->flags.maybe_archive || entry->flags.full_name_provided)
f38a2680 2299 return false;
690a460e
NC
2300
2301 filename = entry->filename;
2302
b1d9458a
NC
2303 if (format_max_len == 0)
2304 /* We need to allow space in the memory that we are going to allocate
2305 for the characters in the format string. Since the format array is
2306 static we only need to calculate this information once. In theory
2307 this value could also be computed statically, but this introduces
2308 the possibility for a discrepancy and hence a possible memory
2309 corruption. The lengths we compute here will be too long because
2310 they will include any formating characters (%s) in the strings, but
2311 this will not matter. */
2312 for (i = 0; libname_fmt[i].format; i++)
2313 if (format_max_len < strlen (libname_fmt[i].format))
2314 format_max_len = strlen (libname_fmt[i].format);
2315
45e948fe
NC
2316 full_string = xmalloc (strlen (search->name)
2317 + strlen (filename)
b1d9458a 2318 + format_max_len
b9a69188 2319#ifdef DLL_SUPPORT
45e948fe
NC
2320 + (pe_dll_search_prefix
2321 ? strlen (pe_dll_search_prefix) : 0)
b9a69188 2322#endif
b1d9458a
NC
2323 /* Allow for the terminating NUL and for the path
2324 separator character that is inserted between
2325 search->name and the start of the format string. */
2326 + 2);
690a460e 2327
45e948fe
NC
2328 sprintf (full_string, "%s/", search->name);
2329 base_string = full_string + strlen (full_string);
690a460e 2330
45e948fe 2331 for (i = 0; libname_fmt[i].format; i++)
690a460e 2332 {
92b93329 2333#ifdef DLL_SUPPORT
45e948fe 2334 if (libname_fmt[i].use_prefix)
1af699f4 2335 {
45e948fe
NC
2336 if (!pe_dll_search_prefix)
2337 continue;
2338 sprintf (base_string, libname_fmt[i].format, pe_dll_search_prefix, filename);
1af699f4 2339 }
45e948fe
NC
2340 else
2341#endif
2342 sprintf (base_string, libname_fmt[i].format, filename);
2343
2344 if (ldfile_try_open_bfd (full_string, entry))
2345 break;
2346 }
2347
2348 if (!libname_fmt[i].format)
2349 {
2350 free (full_string);
f38a2680 2351 return false;
690a460e 2352 }
602e90d3 2353
45e948fe 2354 entry->filename = full_string;
690a460e 2355
f38a2680 2356 return true;
690a460e
NC
2357}
2358
344a211f 2359static int
0c7a8e5a
AM
2360gld_${EMULATION_NAME}_find_potential_libraries
2361 (char *name, lang_input_statement_type *entry)
344a211f
NC
2362{
2363 return ldfile_open_file_search (name, entry, "", ".lib");
2364}
252b5132
RH
2365\f
2366static char *
0c7a8e5a 2367gld_${EMULATION_NAME}_get_script (int *isfile)
252b5132 2368EOF
1c9c9b9b
AM
2369
2370if test x"$COMPILE_IN" = xyes
2371then
252b5132 2372# Scripts compiled in.
1c9c9b9b 2373
252b5132 2374# sed commands to quote an ld script as a C string.
597e2591 2375sc="-f stringify.sed"
252b5132 2376
92b93329 2377fragment <<EOF
3fc90ddb 2378{
252b5132
RH
2379 *isfile = 0;
2380
0e1862bb 2381 if (bfd_link_relocatable (&link_info) && config.build_constructors)
252b5132
RH
2382 return
2383EOF
1af699f4 2384sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
0e1862bb 2385echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
1af699f4
AM
2386sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2387echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2388sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2389echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2390sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
e2a83dd0 2391if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
ca5f2203 2392echo ' ; else if (link_info.pei386_auto_import == 1 && (MERGE_RDATA_V2 || link_info.pei386_runtime_pseudo_reloc != 2)) return' >> e${EMULATION_NAME}.c
e2a83dd0
NC
2393sed $sc ldscripts/${EMULATION_NAME}.xa >> e${EMULATION_NAME}.c
2394fi
1af699f4
AM
2395echo ' ; else return' >> e${EMULATION_NAME}.c
2396sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2397echo '; }' >> e${EMULATION_NAME}.c
252b5132 2398
1c9c9b9b
AM
2399else
2400# Scripts read from the filesystem.
2401
2402fragment <<EOF
2403{
2404 *isfile = 1;
2405
2406 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2407 return "ldscripts/${EMULATION_NAME}.xu";
2408 else if (bfd_link_relocatable (&link_info))
2409 return "ldscripts/${EMULATION_NAME}.xr";
2410 else if (!config.text_read_only)
2411 return "ldscripts/${EMULATION_NAME}.xbn";
2412 else if (!config.magic_demand_paged)
2413 return "ldscripts/${EMULATION_NAME}.xn";
2414EOF
2415if test -n "$GENERATE_AUTO_IMPORT_SCRIPT" ; then
2416fragment <<EOF
2417 else if (link_info.pei386_auto_import == 1
2418 && (MERGE_RDATA_V2 || link_info.pei386_runtime_pseudo_reloc != 2))
2419 return "ldscripts/${EMULATION_NAME}.xa";
2420EOF
2421fi
2422fragment <<EOF
2423 else
2424 return "ldscripts/${EMULATION_NAME}.x";
2425}
2426EOF
2427fi
2428
92b93329 2429fragment <<EOF
252b5132
RH
2430
2431
3fc90ddb 2432struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
252b5132
RH
2433{
2434 gld_${EMULATION_NAME}_before_parse,
2435 syslib_default,
2436 hll_default,
2437 gld_${EMULATION_NAME}_after_parse,
2438 gld_${EMULATION_NAME}_after_open,
5c3261b0 2439 after_check_relocs_default,
9b538ba7 2440 before_place_orphans_default,
252b5132
RH
2441 after_allocation_default,
2442 set_output_arch_default,
2443 ldemul_default_target,
2444 gld_${EMULATION_NAME}_before_allocation,
2445 gld_${EMULATION_NAME}_get_script,
2446 "${EMULATION_NAME}",
2447 "${OUTPUT_FORMAT}",
4cd89863
NC
2448 gld_${EMULATION_NAME}_finish,
2449 NULL, /* Create output section statements. */
690a460e 2450 gld_${EMULATION_NAME}_open_dynamic_archive,
252b5132
RH
2451 gld_${EMULATION_NAME}_place_orphan,
2452 gld_${EMULATION_NAME}_set_symbols,
3bcf5557
AM
2453 NULL, /* parse_args */
2454 gld${EMULATION_NAME}_add_options,
2455 gld${EMULATION_NAME}_handle_option,
252b5132
RH
2456 gld_${EMULATION_NAME}_unrecognized_file,
2457 gld_${EMULATION_NAME}_list_options,
344a211f 2458 gld_${EMULATION_NAME}_recognized_file,
fac1652d 2459 gld_${EMULATION_NAME}_find_potential_libraries,
7a2f2d82 2460 NULL, /* new_vers_pattern. */
1ff6de03
NA
2461 NULL, /* extra_map_file_text. */
2462 ${LDEMUL_EMIT_CTF_EARLY-NULL},
3d16b64e
NA
2463 ${LDEMUL_ACQUIRE_STRINGS_FOR_CTF-NULL},
2464 ${LDEMUL_NEW_DYNSYM_FOR_CTF-NULL},
3edf7b9f 2465 ${LDEMUL_PRINT_SYMBOL-NULL}
252b5132
RH
2466};
2467EOF