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