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