1 | # This shell script emits a C file. -*- C -*-
|
---|
2 | # It does some substitutions.
|
---|
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 ;-)
|
---|
10 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
11 | /* This file is part of GLD, the Gnu Linker.
|
---|
12 | Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
---|
13 | Free Software Foundation, Inc.
|
---|
14 |
|
---|
15 | This program is free software; you can redistribute it and/or modify
|
---|
16 | it under the terms of the GNU General Public License as published by
|
---|
17 | the Free Software Foundation; either version 2 of the License, or
|
---|
18 | (at your option) any later version.
|
---|
19 |
|
---|
20 | This program is distributed in the hope that it will be useful,
|
---|
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
23 | GNU General Public License for more details.
|
---|
24 |
|
---|
25 | You should have received a copy of the GNU General Public License
|
---|
26 | along with this program; if not, write to the Free Software
|
---|
27 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
---|
28 |
|
---|
29 | /* For WINDOWS_NT */
|
---|
30 | /* The original file generated returned different default scripts depending
|
---|
31 | on whether certain switches were set, but these switches pertain to the
|
---|
32 | Linux system and that particular version of coff. In the NT case, we
|
---|
33 | only determine if the subsystem is console or windows in order to select
|
---|
34 | the correct entry point by default. */
|
---|
35 |
|
---|
36 | #define TARGET_IS_${EMULATION_NAME}
|
---|
37 |
|
---|
38 | /* Do this before including bfd.h, so we prototype the right functions. */
|
---|
39 | #ifdef TARGET_IS_arm_epoc_pe
|
---|
40 | #define bfd_arm_pe_allocate_interworking_sections \
|
---|
41 | bfd_arm_epoc_pe_allocate_interworking_sections
|
---|
42 | #define bfd_arm_pe_get_bfd_for_interworking \
|
---|
43 | bfd_arm_epoc_pe_get_bfd_for_interworking
|
---|
44 | #define bfd_arm_pe_process_before_allocation \
|
---|
45 | bfd_arm_epoc_pe_process_before_allocation
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #include "bfd.h"
|
---|
49 | #include "sysdep.h"
|
---|
50 | #include "bfdlink.h"
|
---|
51 | #include "getopt.h"
|
---|
52 | #include "libiberty.h"
|
---|
53 | #include "ld.h"
|
---|
54 | #include "ldmain.h"
|
---|
55 | #include "ldexp.h"
|
---|
56 | #include "ldlang.h"
|
---|
57 | #include "ldfile.h"
|
---|
58 | #include "ldemul.h"
|
---|
59 | #include <ldgram.h>
|
---|
60 | #include "ldlex.h"
|
---|
61 | #include "ldmisc.h"
|
---|
62 | #include "ldctor.h"
|
---|
63 | #include "coff/internal.h"
|
---|
64 |
|
---|
65 | /* FIXME: This is a BFD internal header file, and we should not be
|
---|
66 | using it here. */
|
---|
67 | #include "../bfd/libcoff.h"
|
---|
68 |
|
---|
69 | #include "deffile.h"
|
---|
70 | #include "pe-dll.h"
|
---|
71 |
|
---|
72 | #include <ctype.h>
|
---|
73 |
|
---|
74 | /* Permit the emulation parameters to override the default section
|
---|
75 | alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
|
---|
76 | it seem that include/coff/internal.h should not define
|
---|
77 | PE_DEF_SECTION_ALIGNMENT. */
|
---|
78 | #if PE_DEF_SECTION_ALIGNMENT != ${OVERRIDE_SECTION_ALIGNMENT:-PE_DEF_SECTION_ALIGNMENT}
|
---|
79 | #undef PE_DEF_SECTION_ALIGNMENT
|
---|
80 | #define PE_DEF_SECTION_ALIGNMENT ${OVERRIDE_SECTION_ALIGNMENT}
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | #if defined(TARGET_IS_i386pe)
|
---|
84 | #define DLL_SUPPORT
|
---|
85 | #endif
|
---|
86 | #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe) || defined(TARGET_IS_armpe)
|
---|
87 | #define DLL_SUPPORT
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
|
---|
91 | #define PE_DEF_SUBSYSTEM 3
|
---|
92 | #else
|
---|
93 | #undef NT_EXE_IMAGE_BASE
|
---|
94 | #undef PE_DEF_SECTION_ALIGNMENT
|
---|
95 | #undef PE_DEF_FILE_ALIGNMENT
|
---|
96 | #define NT_EXE_IMAGE_BASE 0x00010000
|
---|
97 | #ifdef TARGET_IS_armpe
|
---|
98 | #define PE_DEF_SECTION_ALIGNMENT 0x00001000
|
---|
99 | #define PE_DEF_SUBSYSTEM 9
|
---|
100 | #else
|
---|
101 | #define PE_DEF_SECTION_ALIGNMENT 0x00000400
|
---|
102 | #define PE_DEF_SUBSYSTEM 2
|
---|
103 | #endif
|
---|
104 | #define PE_DEF_FILE_ALIGNMENT 0x00000200
|
---|
105 | #endif
|
---|
106 |
|
---|
107 | static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
|
---|
108 | static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
|
---|
109 | static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
|
---|
110 | static void gld_${EMULATION_NAME}_after_parse PARAMS ((void));
|
---|
111 | static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
|
---|
112 | static asection *output_prev_sec_find
|
---|
113 | PARAMS ((lang_output_section_statement_type *));
|
---|
114 | static bfd_boolean gld_${EMULATION_NAME}_place_orphan
|
---|
115 | PARAMS ((lang_input_statement_type *, asection *));
|
---|
116 | static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
|
---|
117 | static void gld_${EMULATION_NAME}_finish PARAMS ((void));
|
---|
118 | static bfd_boolean gld_${EMULATION_NAME}_open_dynamic_archive
|
---|
119 | PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
|
---|
120 | static void gld${EMULATION_NAME}_add_options
|
---|
121 | PARAMS ((int, char **, int, struct option **, int, struct option **));
|
---|
122 | static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
|
---|
123 | static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
|
---|
124 | static void set_pe_name PARAMS ((char *, long));
|
---|
125 | static void set_pe_subsystem PARAMS ((void));
|
---|
126 | static void set_pe_value PARAMS ((char *));
|
---|
127 | static void set_pe_stack_heap PARAMS ((char *, char *));
|
---|
128 |
|
---|
129 | #ifdef DLL_SUPPORT
|
---|
130 | static bfd_boolean pe_undef_cdecl_match
|
---|
131 | PARAMS ((struct bfd_link_hash_entry *, PTR));
|
---|
132 | static void pe_fixup_stdcalls PARAMS ((void));
|
---|
133 | static int make_import_fixup PARAMS ((arelent *, asection *));
|
---|
134 | static void pe_find_data_imports PARAMS ((void));
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | static bfd_boolean pr_sym PARAMS ((struct bfd_hash_entry *, PTR));
|
---|
138 | static bfd_boolean gld_${EMULATION_NAME}_unrecognized_file
|
---|
139 | PARAMS ((lang_input_statement_type *));
|
---|
140 | static bfd_boolean gld_${EMULATION_NAME}_recognized_file
|
---|
141 | PARAMS ((lang_input_statement_type *));
|
---|
142 | static int gld_${EMULATION_NAME}_find_potential_libraries
|
---|
143 | PARAMS ((char *, lang_input_statement_type *));
|
---|
144 |
|
---|
145 |
|
---|
146 | static struct internal_extra_pe_aouthdr pe;
|
---|
147 | static int dll;
|
---|
148 | static int support_old_code = 0;
|
---|
149 | static char * thumb_entry_symbol = NULL;
|
---|
150 | static lang_assignment_statement_type *image_base_statement = 0;
|
---|
151 |
|
---|
152 | #ifdef DLL_SUPPORT
|
---|
153 | static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */
|
---|
154 | static char *pe_out_def_filename = NULL;
|
---|
155 | static char *pe_implib_filename = NULL;
|
---|
156 | static int pe_enable_auto_image_base = 0;
|
---|
157 | static char *pe_dll_search_prefix = NULL;
|
---|
158 | #endif
|
---|
159 |
|
---|
160 | extern const char *output_filename;
|
---|
161 |
|
---|
162 | static void
|
---|
163 | gld_${EMULATION_NAME}_before_parse()
|
---|
164 | {
|
---|
165 | const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
|
---|
166 | if (arch)
|
---|
167 | {
|
---|
168 | ldfile_output_architecture = arch->arch;
|
---|
169 | ldfile_output_machine = arch->mach;
|
---|
170 | ldfile_output_machine_name = arch->printable_name;
|
---|
171 | }
|
---|
172 | else
|
---|
173 | ldfile_output_architecture = bfd_arch_${ARCH};
|
---|
174 | output_filename = "${EXECUTABLE_NAME:-a.exe}";
|
---|
175 | #ifdef DLL_SUPPORT
|
---|
176 | config.dynamic_link = TRUE;
|
---|
177 | config.has_shared = 1;
|
---|
178 | link_info.pei386_auto_import = -1;
|
---|
179 | link_info.pei386_runtime_pseudo_reloc = FALSE;
|
---|
180 |
|
---|
181 | #if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
|
---|
182 | #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
|
---|
183 | lang_add_entry ("WinMainCRTStartup", 1);
|
---|
184 | #else
|
---|
185 | lang_add_entry ("_WinMainCRTStartup", 1);
|
---|
186 | #endif
|
---|
187 | #endif
|
---|
188 | #endif
|
---|
189 | }
|
---|
190 | |
---|
191 |
|
---|
192 | /* PE format extra command line options. */
|
---|
193 |
|
---|
194 | /* Used for setting flags in the PE header. */
|
---|
195 | #define OPTION_BASE_FILE (300 + 1)
|
---|
196 | #define OPTION_DLL (OPTION_BASE_FILE + 1)
|
---|
197 | #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
|
---|
198 | #define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
|
---|
199 | #define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
|
---|
200 | #define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
|
---|
201 | #define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
|
---|
202 | #define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
|
---|
203 | #define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
|
---|
204 | #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
|
---|
205 | #define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
|
---|
206 | #define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
|
---|
207 | #define OPTION_SUBSYSTEM (OPTION_STACK + 1)
|
---|
208 | #define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
|
---|
209 | #define OPTION_SUPPORT_OLD_CODE (OPTION_HEAP + 1)
|
---|
210 | #define OPTION_OUT_DEF (OPTION_SUPPORT_OLD_CODE + 1)
|
---|
211 | #define OPTION_EXPORT_ALL (OPTION_OUT_DEF + 1)
|
---|
212 | #define OPTION_EXCLUDE_SYMBOLS (OPTION_EXPORT_ALL + 1)
|
---|
213 | #define OPTION_KILL_ATS (OPTION_EXCLUDE_SYMBOLS + 1)
|
---|
214 | #define OPTION_STDCALL_ALIASES (OPTION_KILL_ATS + 1)
|
---|
215 | #define OPTION_ENABLE_STDCALL_FIXUP (OPTION_STDCALL_ALIASES + 1)
|
---|
216 | #define OPTION_DISABLE_STDCALL_FIXUP (OPTION_ENABLE_STDCALL_FIXUP + 1)
|
---|
217 | #define OPTION_IMPLIB_FILENAME (OPTION_DISABLE_STDCALL_FIXUP + 1)
|
---|
218 | #define OPTION_THUMB_ENTRY (OPTION_IMPLIB_FILENAME + 1)
|
---|
219 | #define OPTION_WARN_DUPLICATE_EXPORTS (OPTION_THUMB_ENTRY + 1)
|
---|
220 | #define OPTION_IMP_COMPAT (OPTION_WARN_DUPLICATE_EXPORTS + 1)
|
---|
221 | #define OPTION_ENABLE_AUTO_IMAGE_BASE (OPTION_IMP_COMPAT + 1)
|
---|
222 | #define OPTION_DISABLE_AUTO_IMAGE_BASE (OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
|
---|
223 | #define OPTION_DLL_SEARCH_PREFIX (OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
|
---|
224 | #define OPTION_NO_DEFAULT_EXCLUDES (OPTION_DLL_SEARCH_PREFIX + 1)
|
---|
225 | #define OPTION_DLL_ENABLE_AUTO_IMPORT (OPTION_NO_DEFAULT_EXCLUDES + 1)
|
---|
226 | #define OPTION_DLL_DISABLE_AUTO_IMPORT (OPTION_DLL_ENABLE_AUTO_IMPORT + 1)
|
---|
227 | #define OPTION_ENABLE_EXTRA_PE_DEBUG (OPTION_DLL_DISABLE_AUTO_IMPORT + 1)
|
---|
228 | #define OPTION_EXCLUDE_LIBS (OPTION_ENABLE_EXTRA_PE_DEBUG + 1)
|
---|
229 | #define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC \
|
---|
230 | (OPTION_EXCLUDE_LIBS + 1)
|
---|
231 | #define OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC \
|
---|
232 | (OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC + 1)
|
---|
233 |
|
---|
234 | static void
|
---|
235 | gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
|
---|
236 | int ns ATTRIBUTE_UNUSED;
|
---|
237 | char **shortopts ATTRIBUTE_UNUSED;
|
---|
238 | int nl;
|
---|
239 | struct option **longopts;
|
---|
240 | int nrl ATTRIBUTE_UNUSED;
|
---|
241 | struct option **really_longopts ATTRIBUTE_UNUSED;
|
---|
242 | {
|
---|
243 | static const struct option xtra_long[] = {
|
---|
244 | /* PE options */
|
---|
245 | {"base-file", required_argument, NULL, OPTION_BASE_FILE},
|
---|
246 | {"dll", no_argument, NULL, OPTION_DLL},
|
---|
247 | {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
|
---|
248 | {"heap", required_argument, NULL, OPTION_HEAP},
|
---|
249 | {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
|
---|
250 | {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
|
---|
251 | {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
|
---|
252 | {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
|
---|
253 | {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
|
---|
254 | {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
|
---|
255 | {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
|
---|
256 | {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
|
---|
257 | {"stack", required_argument, NULL, OPTION_STACK},
|
---|
258 | {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
|
---|
259 | {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
|
---|
260 | {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
|
---|
261 | #ifdef DLL_SUPPORT
|
---|
262 | /* getopt allows abbreviations, so we do this to stop it from treating -o
|
---|
263 | as an abbreviation for this option */
|
---|
264 | {"output-def", required_argument, NULL, OPTION_OUT_DEF},
|
---|
265 | {"output-def", required_argument, NULL, OPTION_OUT_DEF},
|
---|
266 | {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
|
---|
267 | {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
|
---|
268 | {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
|
---|
269 | {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
|
---|
270 | {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
|
---|
271 | {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
|
---|
272 | {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
|
---|
273 | {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
|
---|
274 | {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
|
---|
275 | /* getopt() allows abbreviations, so we do this to stop it from
|
---|
276 | treating -c as an abbreviation for these --compat-implib. */
|
---|
277 | {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
|
---|
278 | {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
|
---|
279 | {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
|
---|
280 | {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
|
---|
281 | {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
|
---|
282 | {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
|
---|
283 | {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
|
---|
284 | {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
|
---|
285 | {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
|
---|
286 | {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
|
---|
287 | {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
|
---|
288 | #endif
|
---|
289 | {NULL, no_argument, NULL, 0}
|
---|
290 | };
|
---|
291 |
|
---|
292 | *longopts = (struct option *)
|
---|
293 | xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
|
---|
294 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
|
---|
295 | }
|
---|
296 |
|
---|
297 | /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
|
---|
298 | parameters which may be input from the command line. */
|
---|
299 |
|
---|
300 | typedef struct
|
---|
301 | {
|
---|
302 | void *ptr;
|
---|
303 | int size;
|
---|
304 | int value;
|
---|
305 | char *symbol;
|
---|
306 | int inited;
|
---|
307 | } definfo;
|
---|
308 |
|
---|
309 | #define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
|
---|
310 |
|
---|
311 | static definfo init[] =
|
---|
312 | {
|
---|
313 | /* imagebase must be first */
|
---|
314 | #define IMAGEBASEOFF 0
|
---|
315 | D(ImageBase,"__image_base__", NT_EXE_IMAGE_BASE),
|
---|
316 | #define DLLOFF 1
|
---|
317 | {&dll, sizeof(dll), 0, "__dll__", 0},
|
---|
318 | D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
|
---|
319 | D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
|
---|
320 | D(MajorOperatingSystemVersion,"__major_os_version__", 4),
|
---|
321 | D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
|
---|
322 | D(MajorImageVersion,"__major_image_version__", 1),
|
---|
323 | D(MinorImageVersion,"__minor_image_version__", 0),
|
---|
324 | #ifdef TARGET_IS_armpe
|
---|
325 | D(MajorSubsystemVersion,"__major_subsystem_version__", 2),
|
---|
326 | #else
|
---|
327 | D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
|
---|
328 | #endif
|
---|
329 | D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
|
---|
330 | D(Subsystem,"__subsystem__", ${SUBSYSTEM}),
|
---|
331 | D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000),
|
---|
332 | D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
|
---|
333 | D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
|
---|
334 | D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
|
---|
335 | D(LoaderFlags,"__loader_flags__", 0x0),
|
---|
336 | { NULL, 0, 0, NULL, 0 }
|
---|
337 | };
|
---|
338 |
|
---|
339 |
|
---|
340 | static void
|
---|
341 | gld_${EMULATION_NAME}_list_options (file)
|
---|
342 | FILE * file;
|
---|
343 | {
|
---|
344 | fprintf (file, _(" --base_file <basefile> Generate a base file for relocatable DLLs\n"));
|
---|
345 | fprintf (file, _(" --dll Set image base to the default for DLLs\n"));
|
---|
346 | fprintf (file, _(" --file-alignment <size> Set file alignment\n"));
|
---|
347 | fprintf (file, _(" --heap <size> Set initial size of the heap\n"));
|
---|
348 | fprintf (file, _(" --image-base <address> Set start address of the executable\n"));
|
---|
349 | fprintf (file, _(" --major-image-version <number> Set version number of the executable\n"));
|
---|
350 | fprintf (file, _(" --major-os-version <number> Set minimum required OS version\n"));
|
---|
351 | fprintf (file, _(" --major-subsystem-version <number> Set minimum required OS subsystem version\n"));
|
---|
352 | fprintf (file, _(" --minor-image-version <number> Set revision number of the executable\n"));
|
---|
353 | fprintf (file, _(" --minor-os-version <number> Set minimum required OS revision\n"));
|
---|
354 | fprintf (file, _(" --minor-subsystem-version <number> Set minimum required OS subsystem revision\n"));
|
---|
355 | fprintf (file, _(" --section-alignment <size> Set section alignment\n"));
|
---|
356 | fprintf (file, _(" --stack <size> Set size of the initial stack\n"));
|
---|
357 | fprintf (file, _(" --subsystem <name>[:<version>] Set required OS subsystem [& version]\n"));
|
---|
358 | fprintf (file, _(" --support-old-code Support interworking with old code\n"));
|
---|
359 | fprintf (file, _(" --thumb-entry=<symbol> Set the entry point to be Thumb <symbol>\n"));
|
---|
360 | #ifdef DLL_SUPPORT
|
---|
361 | fprintf (file, _(" --add-stdcall-alias Export symbols with and without @nn\n"));
|
---|
362 | fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
|
---|
363 | fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
|
---|
364 | fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
|
---|
365 | fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
|
---|
366 | fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
|
---|
367 | fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
|
---|
368 | fprintf (file, _(" --out-implib <file> Generate import library\n"));
|
---|
369 | fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
|
---|
370 | fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
|
---|
371 | fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
|
---|
372 | create __imp_<SYMBOL> as well.\n"));
|
---|
373 | fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
|
---|
374 | unless user specifies one\n"));
|
---|
375 | fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
|
---|
376 | fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without\n\
|
---|
377 | an importlib, use <string><basename>.dll\n\
|
---|
378 | in preference to lib<basename>.dll \n"));
|
---|
379 | fprintf (file, _(" --enable-auto-import Do sophistcated linking of _sym to\n\
|
---|
380 | __imp_sym for DATA references\n"));
|
---|
381 | fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
|
---|
382 | fprintf (file, _(" --enable-runtime-pseudo-reloc Work around auto-import limitations by\n\
|
---|
383 | adding pseudo-relocations resolved at\n\
|
---|
384 | runtime.\n"));
|
---|
385 | fprintf (file, _(" --disable-runtime-pseudo-reloc Do not add runtime pseudo-relocations for\n\
|
---|
386 | auto-imported DATA.\n"));
|
---|
387 | fprintf (file, _(" --enable-extra-pe-debug Enable verbose debug output when building\n\
|
---|
388 | or linking to DLLs (esp. auto-import)\n"));
|
---|
389 | #endif
|
---|
390 | }
|
---|
391 |
|
---|
392 |
|
---|
393 | static void
|
---|
394 | set_pe_name (name, val)
|
---|
395 | char *name;
|
---|
396 | long val;
|
---|
397 | {
|
---|
398 | int i;
|
---|
399 |
|
---|
400 | /* Find the name and set it. */
|
---|
401 | for (i = 0; init[i].ptr; i++)
|
---|
402 | {
|
---|
403 | if (strcmp (name, init[i].symbol) == 0)
|
---|
404 | {
|
---|
405 | init[i].value = val;
|
---|
406 | init[i].inited = 1;
|
---|
407 | return;
|
---|
408 | }
|
---|
409 | }
|
---|
410 | abort ();
|
---|
411 | }
|
---|
412 |
|
---|
413 |
|
---|
414 | static void
|
---|
415 | set_pe_subsystem ()
|
---|
416 | {
|
---|
417 | const char *sver;
|
---|
418 | int len;
|
---|
419 | int i;
|
---|
420 | static const struct
|
---|
421 | {
|
---|
422 | const char *name;
|
---|
423 | const int value;
|
---|
424 | const char *entry;
|
---|
425 | }
|
---|
426 | v[] =
|
---|
427 | {
|
---|
428 | { "native", 1, "NtProcessStartup" },
|
---|
429 | #if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
|
---|
430 | { "windows", 2, "WinMainCRTStartup" },
|
---|
431 | #else
|
---|
432 | { "windows", 2, "WinMainCRTStartup" },
|
---|
433 | #endif
|
---|
434 | { "console", 3, "mainCRTStartup" },
|
---|
435 | #if 0
|
---|
436 | /* The Microsoft linker does not recognize this. */
|
---|
437 | { "os2", 5, "" },
|
---|
438 | #endif
|
---|
439 | { "posix", 7, "__PosixProcessStartup"},
|
---|
440 | { "wince", 9, "_WinMainCRTStartup" },
|
---|
441 | { 0, 0, 0 }
|
---|
442 | };
|
---|
443 |
|
---|
444 | sver = strchr (optarg, ':');
|
---|
445 | if (sver == NULL)
|
---|
446 | len = strlen (optarg);
|
---|
447 | else
|
---|
448 | {
|
---|
449 | char *end;
|
---|
450 |
|
---|
451 | len = sver - optarg;
|
---|
452 | set_pe_name ("__major_subsystem_version__",
|
---|
453 | strtoul (sver + 1, &end, 0));
|
---|
454 | if (*end == '.')
|
---|
455 | set_pe_name ("__minor_subsystem_version__",
|
---|
456 | strtoul (end + 1, &end, 0));
|
---|
457 | if (*end != '\0')
|
---|
458 | einfo (_("%P: warning: bad version number in -subsystem option\n"));
|
---|
459 | }
|
---|
460 |
|
---|
461 | for (i = 0; v[i].name; i++)
|
---|
462 | {
|
---|
463 | if (strncmp (optarg, v[i].name, len) == 0
|
---|
464 | && v[i].name[len] == '\0')
|
---|
465 | {
|
---|
466 | const char *initial_symbol_char;
|
---|
467 | const char *entry;
|
---|
468 |
|
---|
469 | set_pe_name ("__subsystem__", v[i].value);
|
---|
470 |
|
---|
471 | initial_symbol_char = ${INITIAL_SYMBOL_CHAR};
|
---|
472 | if (*initial_symbol_char == '\0')
|
---|
473 | entry = v[i].entry;
|
---|
474 | else
|
---|
475 | {
|
---|
476 | char *alc_entry;
|
---|
477 |
|
---|
478 | /* lang_add_entry expects its argument to be permanently
|
---|
479 | allocated, so we don't free this string. */
|
---|
480 | alc_entry = xmalloc (strlen (initial_symbol_char)
|
---|
481 | + strlen (v[i].entry)
|
---|
482 | + 1);
|
---|
483 | strcpy (alc_entry, initial_symbol_char);
|
---|
484 | strcat (alc_entry, v[i].entry);
|
---|
485 | entry = alc_entry;
|
---|
486 | }
|
---|
487 |
|
---|
488 | lang_add_entry (entry, 0);
|
---|
489 |
|
---|
490 | return;
|
---|
491 | }
|
---|
492 | }
|
---|
493 |
|
---|
494 | einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
|
---|
495 | }
|
---|
496 |
|
---|
497 |
|
---|
498 | static void
|
---|
499 | set_pe_value (name)
|
---|
500 | char *name;
|
---|
501 |
|
---|
502 | {
|
---|
503 | char *end;
|
---|
504 |
|
---|
505 | set_pe_name (name, strtoul (optarg, &end, 0));
|
---|
506 |
|
---|
507 | if (end == optarg)
|
---|
508 | einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
|
---|
509 |
|
---|
510 | optarg = end;
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | static void
|
---|
515 | set_pe_stack_heap (resname, comname)
|
---|
516 | char *resname;
|
---|
517 | char *comname;
|
---|
518 | {
|
---|
519 | set_pe_value (resname);
|
---|
520 |
|
---|
521 | if (*optarg == ',')
|
---|
522 | {
|
---|
523 | optarg++;
|
---|
524 | set_pe_value (comname);
|
---|
525 | }
|
---|
526 | else if (*optarg)
|
---|
527 | einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 | static bfd_boolean
|
---|
532 | gld${EMULATION_NAME}_handle_option (optc)
|
---|
533 | int optc;
|
---|
534 | {
|
---|
535 | switch (optc)
|
---|
536 | {
|
---|
537 | default:
|
---|
538 | return FALSE;
|
---|
539 |
|
---|
540 | case OPTION_BASE_FILE:
|
---|
541 | link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
|
---|
542 | if (link_info.base_file == NULL)
|
---|
543 | {
|
---|
544 | /* xgettext:c-format */
|
---|
545 | fprintf (stderr, _("%s: Can't open base file %s\n"),
|
---|
546 | program_name, optarg);
|
---|
547 | xexit (1);
|
---|
548 | }
|
---|
549 | break;
|
---|
550 |
|
---|
551 | /* PE options. */
|
---|
552 | case OPTION_HEAP:
|
---|
553 | set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
|
---|
554 | break;
|
---|
555 | case OPTION_STACK:
|
---|
556 | set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
|
---|
557 | break;
|
---|
558 | case OPTION_SUBSYSTEM:
|
---|
559 | set_pe_subsystem ();
|
---|
560 | break;
|
---|
561 | case OPTION_MAJOR_OS_VERSION:
|
---|
562 | set_pe_value ("__major_os_version__");
|
---|
563 | break;
|
---|
564 | case OPTION_MINOR_OS_VERSION:
|
---|
565 | set_pe_value ("__minor_os_version__");
|
---|
566 | break;
|
---|
567 | case OPTION_MAJOR_SUBSYSTEM_VERSION:
|
---|
568 | set_pe_value ("__major_subsystem_version__");
|
---|
569 | break;
|
---|
570 | case OPTION_MINOR_SUBSYSTEM_VERSION:
|
---|
571 | set_pe_value ("__minor_subsystem_version__");
|
---|
572 | break;
|
---|
573 | case OPTION_MAJOR_IMAGE_VERSION:
|
---|
574 | set_pe_value ("__major_image_version__");
|
---|
575 | break;
|
---|
576 | case OPTION_MINOR_IMAGE_VERSION:
|
---|
577 | set_pe_value ("__minor_image_version__");
|
---|
578 | break;
|
---|
579 | case OPTION_FILE_ALIGNMENT:
|
---|
580 | set_pe_value ("__file_alignment__");
|
---|
581 | break;
|
---|
582 | case OPTION_SECTION_ALIGNMENT:
|
---|
583 | set_pe_value ("__section_alignment__");
|
---|
584 | break;
|
---|
585 | case OPTION_DLL:
|
---|
586 | set_pe_name ("__dll__", 1);
|
---|
587 | break;
|
---|
588 | case OPTION_IMAGE_BASE:
|
---|
589 | set_pe_value ("__image_base__");
|
---|
590 | break;
|
---|
591 | case OPTION_SUPPORT_OLD_CODE:
|
---|
592 | support_old_code = 1;
|
---|
593 | break;
|
---|
594 | case OPTION_THUMB_ENTRY:
|
---|
595 | thumb_entry_symbol = optarg;
|
---|
596 | break;
|
---|
597 | #ifdef DLL_SUPPORT
|
---|
598 | case OPTION_OUT_DEF:
|
---|
599 | pe_out_def_filename = xstrdup (optarg);
|
---|
600 | break;
|
---|
601 | case OPTION_EXPORT_ALL:
|
---|
602 | pe_dll_export_everything = 1;
|
---|
603 | break;
|
---|
604 | case OPTION_EXCLUDE_SYMBOLS:
|
---|
605 | pe_dll_add_excludes (optarg, 0);
|
---|
606 | break;
|
---|
607 | case OPTION_EXCLUDE_LIBS:
|
---|
608 | pe_dll_add_excludes (optarg, 1);
|
---|
609 | break;
|
---|
610 | case OPTION_KILL_ATS:
|
---|
611 | pe_dll_kill_ats = 1;
|
---|
612 | break;
|
---|
613 | case OPTION_STDCALL_ALIASES:
|
---|
614 | pe_dll_stdcall_aliases = 1;
|
---|
615 | break;
|
---|
616 | case OPTION_ENABLE_STDCALL_FIXUP:
|
---|
617 | pe_enable_stdcall_fixup = 1;
|
---|
618 | break;
|
---|
619 | case OPTION_DISABLE_STDCALL_FIXUP:
|
---|
620 | pe_enable_stdcall_fixup = 0;
|
---|
621 | break;
|
---|
622 | case OPTION_IMPLIB_FILENAME:
|
---|
623 | pe_implib_filename = xstrdup (optarg);
|
---|
624 | break;
|
---|
625 | case OPTION_WARN_DUPLICATE_EXPORTS:
|
---|
626 | pe_dll_warn_dup_exports = 1;
|
---|
627 | break;
|
---|
628 | case OPTION_IMP_COMPAT:
|
---|
629 | pe_dll_compat_implib = 1;
|
---|
630 | break;
|
---|
631 | case OPTION_ENABLE_AUTO_IMAGE_BASE:
|
---|
632 | pe_enable_auto_image_base = 1;
|
---|
633 | break;
|
---|
634 | case OPTION_DISABLE_AUTO_IMAGE_BASE:
|
---|
635 | pe_enable_auto_image_base = 0;
|
---|
636 | break;
|
---|
637 | case OPTION_DLL_SEARCH_PREFIX:
|
---|
638 | pe_dll_search_prefix = xstrdup (optarg);
|
---|
639 | break;
|
---|
640 | case OPTION_NO_DEFAULT_EXCLUDES:
|
---|
641 | pe_dll_do_default_excludes = 0;
|
---|
642 | break;
|
---|
643 | case OPTION_DLL_ENABLE_AUTO_IMPORT:
|
---|
644 | link_info.pei386_auto_import = 1;
|
---|
645 | break;
|
---|
646 | case OPTION_DLL_DISABLE_AUTO_IMPORT:
|
---|
647 | link_info.pei386_auto_import = 0;
|
---|
648 | break;
|
---|
649 | case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
|
---|
650 | link_info.pei386_runtime_pseudo_reloc = 1;
|
---|
651 | break;
|
---|
652 | case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
|
---|
653 | link_info.pei386_runtime_pseudo_reloc = 0;
|
---|
654 | break;
|
---|
655 | case OPTION_ENABLE_EXTRA_PE_DEBUG:
|
---|
656 | pe_dll_extra_pe_debug = 1;
|
---|
657 | break;
|
---|
658 | #endif
|
---|
659 | }
|
---|
660 | return TRUE;
|
---|
661 | }
|
---|
662 | |
---|
663 |
|
---|
664 |
|
---|
665 | #ifdef DLL_SUPPORT
|
---|
666 | static unsigned long
|
---|
667 | strhash (const char *str)
|
---|
668 | {
|
---|
669 | const unsigned char *s;
|
---|
670 | unsigned long hash;
|
---|
671 | unsigned int c;
|
---|
672 | unsigned int len;
|
---|
673 |
|
---|
674 | hash = 0;
|
---|
675 | len = 0;
|
---|
676 | s = (const unsigned char *) str;
|
---|
677 | while ((c = *s++) != '\0')
|
---|
678 | {
|
---|
679 | hash += c + (c << 17);
|
---|
680 | hash ^= hash >> 2;
|
---|
681 | ++len;
|
---|
682 | }
|
---|
683 | hash += len + (len << 17);
|
---|
684 | hash ^= hash >> 2;
|
---|
685 |
|
---|
686 | return hash;
|
---|
687 | }
|
---|
688 |
|
---|
689 | /* Use the output file to create a image base for relocatable DLLs. */
|
---|
690 |
|
---|
691 | static unsigned long
|
---|
692 | compute_dll_image_base (const char *ofile)
|
---|
693 | {
|
---|
694 | unsigned long hash = strhash (ofile);
|
---|
695 | return 0x60000000 | ((hash << 16) & 0x0FFC0000);
|
---|
696 | }
|
---|
697 | #endif
|
---|
698 |
|
---|
699 | /* Assign values to the special symbols before the linker script is
|
---|
700 | read. */
|
---|
701 |
|
---|
702 | static void
|
---|
703 | gld_${EMULATION_NAME}_set_symbols ()
|
---|
704 | {
|
---|
705 | /* Run through and invent symbols for all the
|
---|
706 | names and insert the defaults. */
|
---|
707 | int j;
|
---|
708 | lang_statement_list_type *save;
|
---|
709 |
|
---|
710 | if (!init[IMAGEBASEOFF].inited)
|
---|
711 | {
|
---|
712 | if (link_info.relocateable)
|
---|
713 | init[IMAGEBASEOFF].value = 0;
|
---|
714 | else if (init[DLLOFF].value || link_info.shared)
|
---|
715 | #ifdef DLL_SUPPORT
|
---|
716 | init[IMAGEBASEOFF].value = (pe_enable_auto_image_base) ?
|
---|
717 | compute_dll_image_base (output_filename) : NT_DLL_IMAGE_BASE;
|
---|
718 | #else
|
---|
719 | init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
|
---|
720 | #endif
|
---|
721 | else
|
---|
722 | init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
|
---|
723 | }
|
---|
724 |
|
---|
725 | /* Don't do any symbol assignments if this is a relocateable link. */
|
---|
726 | if (link_info.relocateable)
|
---|
727 | return;
|
---|
728 |
|
---|
729 | /* Glue the assignments into the abs section. */
|
---|
730 | save = stat_ptr;
|
---|
731 |
|
---|
732 | stat_ptr = &(abs_output_section->children);
|
---|
733 |
|
---|
734 | for (j = 0; init[j].ptr; j++)
|
---|
735 | {
|
---|
736 | long val = init[j].value;
|
---|
737 | lang_assignment_statement_type *rv;
|
---|
738 | rv = lang_add_assignment (exp_assop ('=', init[j].symbol,
|
---|
739 | exp_intop (val)));
|
---|
740 | if (init[j].size == sizeof (short))
|
---|
741 | *(short *) init[j].ptr = val;
|
---|
742 | else if (init[j].size == sizeof (int))
|
---|
743 | *(int *) init[j].ptr = val;
|
---|
744 | else if (init[j].size == sizeof (long))
|
---|
745 | *(long *) init[j].ptr = val;
|
---|
746 | /* This might be a long long or other special type. */
|
---|
747 | else if (init[j].size == sizeof (bfd_vma))
|
---|
748 | *(bfd_vma *) init[j].ptr = val;
|
---|
749 | else abort ();
|
---|
750 | if (j == IMAGEBASEOFF)
|
---|
751 | image_base_statement = rv;
|
---|
752 | }
|
---|
753 | /* Restore the pointer. */
|
---|
754 | stat_ptr = save;
|
---|
755 |
|
---|
756 | if (pe.FileAlignment >
|
---|
757 | pe.SectionAlignment)
|
---|
758 | {
|
---|
759 | einfo (_("%P: warning, file alignment > section alignment.\n"));
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | /* This is called after the linker script and the command line options
|
---|
764 | have been read. */
|
---|
765 |
|
---|
766 | static void
|
---|
767 | gld_${EMULATION_NAME}_after_parse ()
|
---|
768 | {
|
---|
769 | /* The Windows libraries are designed for the linker to treat the
|
---|
770 | entry point as an undefined symbol. Otherwise, the .obj that
|
---|
771 | defines mainCRTStartup is brought in because it is the first
|
---|
772 | encountered in libc.lib and it has other symbols in it which will
|
---|
773 | be pulled in by the link process. To avoid this, we act as
|
---|
774 | though the user specified -u with the entry point symbol.
|
---|
775 |
|
---|
776 | This function is called after the linker script and command line
|
---|
777 | options have been read, so at this point we know the right entry
|
---|
778 | point. This function is called before the input files are
|
---|
779 | opened, so registering the symbol as undefined will make a
|
---|
780 | difference. */
|
---|
781 |
|
---|
782 | if (! link_info.relocateable && entry_symbol.name != NULL)
|
---|
783 | ldlang_add_undef (entry_symbol.name);
|
---|
784 | }
|
---|
785 |
|
---|
786 | /* pe-dll.c directly accesses pe_data_import_dll,
|
---|
787 | so it must be defined outside of #ifdef DLL_SUPPORT.
|
---|
788 | Note - this variable is deliberately not initialised.
|
---|
789 | This allows it to be treated as a common varaible, and only
|
---|
790 | exist in one incarnation in a multiple target enabled linker. */
|
---|
791 | char * pe_data_import_dll;
|
---|
792 |
|
---|
793 | #ifdef DLL_SUPPORT
|
---|
794 | static struct bfd_link_hash_entry *pe_undef_found_sym;
|
---|
795 |
|
---|
796 | static bfd_boolean
|
---|
797 | pe_undef_cdecl_match (h, string)
|
---|
798 | struct bfd_link_hash_entry *h;
|
---|
799 | PTR string;
|
---|
800 | {
|
---|
801 | int sl;
|
---|
802 |
|
---|
803 | sl = strlen (string); /* Silence compiler warning. */
|
---|
804 | if (h->type == bfd_link_hash_defined
|
---|
805 | && strncmp (h->root.string, string, sl) == 0
|
---|
806 | && h->root.string[sl] == '@')
|
---|
807 | {
|
---|
808 | pe_undef_found_sym = h;
|
---|
809 | return FALSE;
|
---|
810 | }
|
---|
811 | return TRUE;
|
---|
812 | }
|
---|
813 |
|
---|
814 | static void
|
---|
815 | pe_fixup_stdcalls ()
|
---|
816 | {
|
---|
817 | static int gave_warning_message = 0;
|
---|
818 | struct bfd_link_hash_entry *undef, *sym;
|
---|
819 |
|
---|
820 | if (pe_dll_extra_pe_debug)
|
---|
821 | printf ("%s\n", __FUNCTION__);
|
---|
822 |
|
---|
823 | for (undef = link_info.hash->undefs; undef; undef=undef->next)
|
---|
824 | if (undef->type == bfd_link_hash_undefined)
|
---|
825 | {
|
---|
826 | char* at = strchr (undef->root.string, '@');
|
---|
827 | int lead_at = (*undef->root.string == '@');
|
---|
828 | /* For now, don't try to fixup fastcall symbols. */
|
---|
829 |
|
---|
830 | if (at && !lead_at)
|
---|
831 | {
|
---|
832 | /* The symbol is a stdcall symbol, so let's look for a
|
---|
833 | cdecl symbol with the same name and resolve to that. */
|
---|
834 | char *cname = xstrdup (undef->root.string /* + lead_at */);
|
---|
835 | at = strchr (cname, '@');
|
---|
836 | *at = 0;
|
---|
837 | sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
|
---|
838 |
|
---|
839 | if (sym && sym->type == bfd_link_hash_defined)
|
---|
840 | {
|
---|
841 | undef->type = bfd_link_hash_defined;
|
---|
842 | undef->u.def.value = sym->u.def.value;
|
---|
843 | undef->u.def.section = sym->u.def.section;
|
---|
844 |
|
---|
845 | if (pe_enable_stdcall_fixup == -1)
|
---|
846 | {
|
---|
847 | einfo (_("Warning: resolving %s by linking to %s\n"),
|
---|
848 | undef->root.string, cname);
|
---|
849 | if (! gave_warning_message)
|
---|
850 | {
|
---|
851 | gave_warning_message = 1;
|
---|
852 | einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
|
---|
853 | einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
|
---|
854 | }
|
---|
855 | }
|
---|
856 | }
|
---|
857 | }
|
---|
858 | else
|
---|
859 | {
|
---|
860 | /* The symbol is a cdecl symbol, so we look for stdcall
|
---|
861 | symbols - which means scanning the whole symbol table. */
|
---|
862 | pe_undef_found_sym = 0;
|
---|
863 | bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
|
---|
864 | (PTR) undef->root.string);
|
---|
865 | sym = pe_undef_found_sym;
|
---|
866 | if (sym)
|
---|
867 | {
|
---|
868 | undef->type = bfd_link_hash_defined;
|
---|
869 | undef->u.def.value = sym->u.def.value;
|
---|
870 | undef->u.def.section = sym->u.def.section;
|
---|
871 |
|
---|
872 | if (pe_enable_stdcall_fixup == -1)
|
---|
873 | {
|
---|
874 | einfo (_("Warning: resolving %s by linking to %s\n"),
|
---|
875 | undef->root.string, sym->root.string);
|
---|
876 | if (! gave_warning_message)
|
---|
877 | {
|
---|
878 | gave_warning_message = 1;
|
---|
879 | einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
|
---|
880 | einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
|
---|
881 | }
|
---|
882 | }
|
---|
883 | }
|
---|
884 | }
|
---|
885 | }
|
---|
886 | }
|
---|
887 |
|
---|
888 | static int
|
---|
889 | make_import_fixup (rel, s)
|
---|
890 | arelent *rel;
|
---|
891 | asection *s;
|
---|
892 | {
|
---|
893 | struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;
|
---|
894 | int addend = 0;
|
---|
895 |
|
---|
896 | if (pe_dll_extra_pe_debug)
|
---|
897 | printf ("arelent: %s@%#lx: add=%li\n", sym->name,
|
---|
898 | (long) rel->address, (long) rel->addend);
|
---|
899 |
|
---|
900 | if (! bfd_get_section_contents (s->owner, s, &addend, rel->address, sizeof (addend)))
|
---|
901 | einfo (_("%C: Cannot get section contents - auto-import exception\n"),
|
---|
902 | s->owner, s, rel->address);
|
---|
903 |
|
---|
904 | pe_create_import_fixup (rel, s, addend);
|
---|
905 |
|
---|
906 | return 1;
|
---|
907 | }
|
---|
908 |
|
---|
909 | static void
|
---|
910 | pe_find_data_imports ()
|
---|
911 | {
|
---|
912 | struct bfd_link_hash_entry *undef, *sym;
|
---|
913 |
|
---|
914 | if (link_info.pei386_auto_import == 0)
|
---|
915 | return;
|
---|
916 |
|
---|
917 | for (undef = link_info.hash->undefs; undef; undef=undef->next)
|
---|
918 | {
|
---|
919 | if (undef->type == bfd_link_hash_undefined)
|
---|
920 | {
|
---|
921 | /* C++ symbols are *long*. */
|
---|
922 | char buf[4096];
|
---|
923 |
|
---|
924 | if (pe_dll_extra_pe_debug)
|
---|
925 | printf ("%s:%s\n", __FUNCTION__, undef->root.string);
|
---|
926 |
|
---|
927 | sprintf (buf, "__imp_%s", undef->root.string);
|
---|
928 |
|
---|
929 | sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
|
---|
930 |
|
---|
931 | if (sym && sym->type == bfd_link_hash_defined)
|
---|
932 | {
|
---|
933 | bfd *b = sym->u.def.section->owner;
|
---|
934 | asymbol **symbols;
|
---|
935 | int nsyms, symsize, i;
|
---|
936 |
|
---|
937 | if (link_info.pei386_auto_import == -1)
|
---|
938 | info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"),
|
---|
939 | undef->root.string, buf);
|
---|
940 |
|
---|
941 | symsize = bfd_get_symtab_upper_bound (b);
|
---|
942 | symbols = (asymbol **) xmalloc (symsize);
|
---|
943 | nsyms = bfd_canonicalize_symtab (b, symbols);
|
---|
944 |
|
---|
945 | for (i = 0; i < nsyms; i++)
|
---|
946 | {
|
---|
947 | if (memcmp (symbols[i]->name, "__head_",
|
---|
948 | sizeof ("__head_") - 1))
|
---|
949 | continue;
|
---|
950 |
|
---|
951 | if (pe_dll_extra_pe_debug)
|
---|
952 | printf ("->%s\n", symbols[i]->name);
|
---|
953 |
|
---|
954 | pe_data_import_dll = (char*) (symbols[i]->name +
|
---|
955 | sizeof ("__head_") - 1);
|
---|
956 | break;
|
---|
957 | }
|
---|
958 |
|
---|
959 | pe_walk_relocs_of_symbol (&link_info, undef->root.string,
|
---|
960 | make_import_fixup);
|
---|
961 |
|
---|
962 | /* Let's differentiate it somehow from defined. */
|
---|
963 | undef->type = bfd_link_hash_defweak;
|
---|
964 | /* We replace original name with __imp_ prefixed, this
|
---|
965 | 1) may trash memory 2) leads to duplicate symbol generation.
|
---|
966 | Still, IMHO it's better than having name poluted. */
|
---|
967 | undef->root.string = sym->root.string;
|
---|
968 | undef->u.def.value = sym->u.def.value;
|
---|
969 | undef->u.def.section = sym->u.def.section;
|
---|
970 | }
|
---|
971 | }
|
---|
972 | }
|
---|
973 | }
|
---|
974 | #endif /* DLL_SUPPORT */
|
---|
975 |
|
---|
976 | static bfd_boolean
|
---|
977 | pr_sym (h, string)
|
---|
978 | struct bfd_hash_entry *h;
|
---|
979 | PTR string ATTRIBUTE_UNUSED;
|
---|
980 | {
|
---|
981 | if (pe_dll_extra_pe_debug)
|
---|
982 | printf ("+%s\n",h->string);
|
---|
983 |
|
---|
984 | return TRUE;
|
---|
985 | }
|
---|
986 |
|
---|
987 |
|
---|
988 | static void
|
---|
989 | gld_${EMULATION_NAME}_after_open ()
|
---|
990 | {
|
---|
991 | if (pe_dll_extra_pe_debug)
|
---|
992 | {
|
---|
993 | bfd *a;
|
---|
994 | struct bfd_link_hash_entry *sym;
|
---|
995 |
|
---|
996 | printf ("%s()\n", __FUNCTION__);
|
---|
997 |
|
---|
998 | for (sym = link_info.hash->undefs; sym; sym=sym->next)
|
---|
999 | printf ("-%s\n", sym->root.string);
|
---|
1000 | bfd_hash_traverse (&link_info.hash->table, pr_sym,NULL);
|
---|
1001 |
|
---|
1002 | for (a = link_info.input_bfds; a; a = a->link_next)
|
---|
1003 | printf ("*%s\n",a->filename);
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | /* Pass the wacky PE command line options into the output bfd.
|
---|
1007 | FIXME: This should be done via a function, rather than by
|
---|
1008 | including an internal BFD header. */
|
---|
1009 |
|
---|
1010 | if (coff_data (output_bfd) == NULL || coff_data (output_bfd)->pe == 0)
|
---|
1011 | einfo (_("%F%P: PE operations on non PE file.\n"));
|
---|
1012 |
|
---|
1013 | pe_data (output_bfd)->pe_opthdr = pe;
|
---|
1014 | pe_data (output_bfd)->dll = init[DLLOFF].value;
|
---|
1015 |
|
---|
1016 | #ifdef DLL_SUPPORT
|
---|
1017 | if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
|
---|
1018 | pe_fixup_stdcalls ();
|
---|
1019 |
|
---|
1020 | pe_process_import_defs (output_bfd, & link_info);
|
---|
1021 |
|
---|
1022 | pe_find_data_imports ();
|
---|
1023 |
|
---|
1024 | #if ! (defined (TARGET_IS_i386pe) || defined (TARGET_IS_armpe))
|
---|
1025 | if (link_info.shared)
|
---|
1026 | #else
|
---|
1027 | if (!link_info.relocateable)
|
---|
1028 | #endif
|
---|
1029 | pe_dll_build_sections (output_bfd, &link_info);
|
---|
1030 |
|
---|
1031 | #ifndef TARGET_IS_i386pe
|
---|
1032 | #ifndef TARGET_IS_armpe
|
---|
1033 | else
|
---|
1034 | pe_exe_build_sections (output_bfd, &link_info);
|
---|
1035 | #endif
|
---|
1036 | #endif
|
---|
1037 | #endif
|
---|
1038 |
|
---|
1039 | #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
|
---|
1040 | if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
|
---|
1041 | {
|
---|
1042 | /* The arm backend needs special fields in the output hash structure.
|
---|
1043 | These will only be created if the output format is an arm format,
|
---|
1044 | hence we do not support linking and changing output formats at the
|
---|
1045 | same time. Use a link followed by objcopy to change output formats. */
|
---|
1046 | einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
|
---|
1047 | return;
|
---|
1048 | }
|
---|
1049 | {
|
---|
1050 | /* Find a BFD that can hold the interworking stubs. */
|
---|
1051 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
---|
1052 | {
|
---|
1053 | if (bfd_arm_pe_get_bfd_for_interworking (is->the_bfd, & link_info))
|
---|
1054 | break;
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | #endif
|
---|
1058 |
|
---|
1059 | {
|
---|
1060 | /* This next chunk of code tries to detect the case where you have
|
---|
1061 | two import libraries for the same DLL (specifically,
|
---|
1062 | symbolically linking libm.a and libc.a in cygwin to
|
---|
1063 | libcygwin.a). In those cases, it's possible for function
|
---|
1064 | thunks from the second implib to be used but without the
|
---|
1065 | head/tail objects, causing an improper import table. We detect
|
---|
1066 | those cases and rename the "other" import libraries to match
|
---|
1067 | the one the head/tail come from, so that the linker will sort
|
---|
1068 | things nicely and produce a valid import table. */
|
---|
1069 |
|
---|
1070 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
---|
1071 | {
|
---|
1072 | if (is->the_bfd->my_archive)
|
---|
1073 | {
|
---|
1074 | int idata2 = 0, reloc_count=0, is_imp = 0;
|
---|
1075 | asection *sec;
|
---|
1076 |
|
---|
1077 | /* See if this is an import library thunk. */
|
---|
1078 | for (sec = is->the_bfd->sections; sec; sec = sec->next)
|
---|
1079 | {
|
---|
1080 | if (strcmp (sec->name, ".idata\$2") == 0)
|
---|
1081 | idata2 = 1;
|
---|
1082 | if (strncmp (sec->name, ".idata\$", 7) == 0)
|
---|
1083 | is_imp = 1;
|
---|
1084 | reloc_count += sec->reloc_count;
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | if (is_imp && !idata2 && reloc_count)
|
---|
1088 | {
|
---|
1089 | /* It is, look for the reference to head and see if it's
|
---|
1090 | from our own library. */
|
---|
1091 | for (sec = is->the_bfd->sections; sec; sec = sec->next)
|
---|
1092 | {
|
---|
1093 | int i;
|
---|
1094 | long symsize;
|
---|
1095 | long relsize;
|
---|
1096 | asymbol **symbols;
|
---|
1097 | arelent **relocs;
|
---|
1098 | int nrelocs;
|
---|
1099 |
|
---|
1100 | symsize = bfd_get_symtab_upper_bound (is->the_bfd);
|
---|
1101 | if (symsize < 1)
|
---|
1102 | break;
|
---|
1103 | relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
|
---|
1104 | if (relsize < 1)
|
---|
1105 | break;
|
---|
1106 |
|
---|
1107 | symbols = (asymbol **) xmalloc (symsize);
|
---|
1108 | symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
|
---|
1109 | if (symsize < 0)
|
---|
1110 | {
|
---|
1111 | einfo ("%X%P: unable to process symbols: %E");
|
---|
1112 | return;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | relocs = (arelent **) xmalloc ((size_t) relsize);
|
---|
1116 | nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
|
---|
1117 | relocs, symbols);
|
---|
1118 | if (nrelocs < 0)
|
---|
1119 | {
|
---|
1120 | free (relocs);
|
---|
1121 | einfo ("%X%P: unable to process relocs: %E");
|
---|
1122 | return;
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | for (i = 0; i < nrelocs; i++)
|
---|
1126 | {
|
---|
1127 | struct symbol_cache_entry *s;
|
---|
1128 | struct bfd_link_hash_entry * blhe;
|
---|
1129 | bfd *other_bfd;
|
---|
1130 | char *n;
|
---|
1131 |
|
---|
1132 | s = (relocs[i]->sym_ptr_ptr)[0];
|
---|
1133 |
|
---|
1134 | if (s->flags & BSF_LOCAL)
|
---|
1135 | continue;
|
---|
1136 |
|
---|
1137 | /* Thunk section with reloc to another bfd. */
|
---|
1138 | blhe = bfd_link_hash_lookup (link_info.hash,
|
---|
1139 | s->name,
|
---|
1140 | FALSE, FALSE, TRUE);
|
---|
1141 |
|
---|
1142 | if (blhe == NULL
|
---|
1143 | || blhe->type != bfd_link_hash_defined)
|
---|
1144 | continue;
|
---|
1145 |
|
---|
1146 | other_bfd = blhe->u.def.section->owner;
|
---|
1147 |
|
---|
1148 | if (strcmp (is->the_bfd->my_archive->filename,
|
---|
1149 | other_bfd->my_archive->filename) == 0)
|
---|
1150 | continue;
|
---|
1151 |
|
---|
1152 | /* Rename this implib to match the other. */
|
---|
1153 | n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
|
---|
1154 |
|
---|
1155 | strcpy (n, other_bfd->my_archive->filename);
|
---|
1156 |
|
---|
1157 | is->the_bfd->my_archive->filename = n;
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | free (relocs);
|
---|
1161 | /* Note - we do not free the symbols,
|
---|
1162 | they are now cached in the BFD. */
|
---|
1163 | }
|
---|
1164 | }
|
---|
1165 | }
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | {
|
---|
1170 | int is_ms_arch = 0;
|
---|
1171 | bfd *cur_arch = 0;
|
---|
1172 | lang_input_statement_type *is2;
|
---|
1173 |
|
---|
1174 | /* Careful - this is a shell script. Watch those dollar signs! */
|
---|
1175 | /* Microsoft import libraries have every member named the same,
|
---|
1176 | and not in the right order for us to link them correctly. We
|
---|
1177 | must detect these and rename the members so that they'll link
|
---|
1178 | correctly. There are three types of objects: the head, the
|
---|
1179 | thunks, and the sentinel(s). The head is easy; it's the one
|
---|
1180 | with idata2. We assume that the sentinels won't have relocs,
|
---|
1181 | and the thunks will. It's easier than checking the symbol
|
---|
1182 | table for external references. */
|
---|
1183 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
---|
1184 | {
|
---|
1185 | if (is->the_bfd->my_archive)
|
---|
1186 | {
|
---|
1187 | bfd *arch = is->the_bfd->my_archive;
|
---|
1188 | if (cur_arch != arch)
|
---|
1189 | {
|
---|
1190 | cur_arch = arch;
|
---|
1191 | is_ms_arch = 1;
|
---|
1192 | for (is2 = is;
|
---|
1193 | is2 && is2->the_bfd->my_archive == arch;
|
---|
1194 | is2 = (lang_input_statement_type *)is2->next)
|
---|
1195 | {
|
---|
1196 | if (strcmp (is->the_bfd->filename, is2->the_bfd->filename))
|
---|
1197 | is_ms_arch = 0;
|
---|
1198 | }
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | if (is_ms_arch)
|
---|
1202 | {
|
---|
1203 | int idata2 = 0, reloc_count=0;
|
---|
1204 | asection *sec;
|
---|
1205 | char *new_name, seq;
|
---|
1206 |
|
---|
1207 | for (sec = is->the_bfd->sections; sec; sec = sec->next)
|
---|
1208 | {
|
---|
1209 | if (strcmp (sec->name, ".idata\$2") == 0)
|
---|
1210 | idata2 = 1;
|
---|
1211 | reloc_count += sec->reloc_count;
|
---|
1212 | }
|
---|
1213 |
|
---|
1214 | if (idata2) /* .idata2 is the TOC */
|
---|
1215 | seq = 'a';
|
---|
1216 | else if (reloc_count > 0) /* thunks */
|
---|
1217 | seq = 'b';
|
---|
1218 | else /* sentinel */
|
---|
1219 | seq = 'c';
|
---|
1220 |
|
---|
1221 | new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
|
---|
1222 | sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
|
---|
1223 | is->the_bfd->filename = new_name;
|
---|
1224 |
|
---|
1225 | new_name = xmalloc (strlen (is->filename) + 3);
|
---|
1226 | sprintf (new_name, "%s.%c", is->filename, seq);
|
---|
1227 | is->filename = new_name;
|
---|
1228 | }
|
---|
1229 | }
|
---|
1230 | }
|
---|
1231 | }
|
---|
1232 | }
|
---|
1233 | |
---|
1234 |
|
---|
1235 | static void
|
---|
1236 | gld_${EMULATION_NAME}_before_allocation ()
|
---|
1237 | {
|
---|
1238 | #ifdef TARGET_IS_ppcpe
|
---|
1239 | /* Here we rummage through the found bfds to collect toc information. */
|
---|
1240 | {
|
---|
1241 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
---|
1242 | {
|
---|
1243 | if (!ppc_process_before_allocation (is->the_bfd, &link_info))
|
---|
1244 | {
|
---|
1245 | /* xgettext:c-format */
|
---|
1246 | einfo (_("Errors encountered processing file %s\n"), is->filename);
|
---|
1247 | }
|
---|
1248 | }
|
---|
1249 | }
|
---|
1250 |
|
---|
1251 | /* We have seen it all. Allocate it, and carry on. */
|
---|
1252 | ppc_allocate_toc_section (&link_info);
|
---|
1253 | #endif /* TARGET_IS_ppcpe */
|
---|
1254 |
|
---|
1255 | #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
|
---|
1256 | /* FIXME: we should be able to set the size of the interworking stub
|
---|
1257 | section.
|
---|
1258 |
|
---|
1259 | Here we rummage through the found bfds to collect glue
|
---|
1260 | information. FIXME: should this be based on a command line
|
---|
1261 | option? krk@cygnus.com. */
|
---|
1262 | {
|
---|
1263 | LANG_FOR_EACH_INPUT_STATEMENT (is)
|
---|
1264 | {
|
---|
1265 | if (! bfd_arm_pe_process_before_allocation
|
---|
1266 | (is->the_bfd, & link_info, support_old_code))
|
---|
1267 | {
|
---|
1268 | /* xgettext:c-format */
|
---|
1269 | einfo (_("Errors encountered processing file %s for interworking"),
|
---|
1270 | is->filename);
|
---|
1271 | }
|
---|
1272 | }
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | /* We have seen it all. Allocate it, and carry on. */
|
---|
1276 | bfd_arm_pe_allocate_interworking_sections (& link_info);
|
---|
1277 | #endif /* TARGET_IS_armpe */
|
---|
1278 | }
|
---|
1279 | |
---|
1280 |
|
---|
1281 | #ifdef DLL_SUPPORT
|
---|
1282 | /* This is called when an input file isn't recognized as a BFD. We
|
---|
1283 | check here for .DEF files and pull them in automatically. */
|
---|
1284 |
|
---|
1285 | static int
|
---|
1286 | saw_option (char * option)
|
---|
1287 | {
|
---|
1288 | int i;
|
---|
1289 |
|
---|
1290 | for (i = 0; init[i].ptr; i++)
|
---|
1291 | if (strcmp (init[i].symbol, option) == 0)
|
---|
1292 | return init[i].inited;
|
---|
1293 | return 0;
|
---|
1294 | }
|
---|
1295 | #endif /* DLL_SUPPORT */
|
---|
1296 |
|
---|
1297 | static bfd_boolean
|
---|
1298 | gld_${EMULATION_NAME}_unrecognized_file (entry)
|
---|
1299 | lang_input_statement_type *entry ATTRIBUTE_UNUSED;
|
---|
1300 | {
|
---|
1301 | #ifdef DLL_SUPPORT
|
---|
1302 | const char *ext = entry->filename + strlen (entry->filename) - 4;
|
---|
1303 |
|
---|
1304 | if (strcmp (ext, ".def") == 0 || strcmp (ext, ".DEF") == 0)
|
---|
1305 | {
|
---|
1306 | if (pe_def_file == 0)
|
---|
1307 | pe_def_file = def_file_empty ();
|
---|
1308 |
|
---|
1309 | def_file_parse (entry->filename, pe_def_file);
|
---|
1310 |
|
---|
1311 | if (pe_def_file)
|
---|
1312 | {
|
---|
1313 | int i, buflen=0, len;
|
---|
1314 | char *buf;
|
---|
1315 |
|
---|
1316 | for (i = 0; i < pe_def_file->num_exports; i++)
|
---|
1317 | {
|
---|
1318 | len = strlen (pe_def_file->exports[i].internal_name);
|
---|
1319 | if (buflen < len + 2)
|
---|
1320 | buflen = len + 2;
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | buf = (char *) xmalloc (buflen);
|
---|
1324 |
|
---|
1325 | for (i = 0; i < pe_def_file->num_exports; i++)
|
---|
1326 | {
|
---|
1327 | struct bfd_link_hash_entry *h;
|
---|
1328 |
|
---|
1329 | sprintf (buf, "_%s", pe_def_file->exports[i].internal_name);
|
---|
1330 |
|
---|
1331 | h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
|
---|
1332 | if (h == (struct bfd_link_hash_entry *) NULL)
|
---|
1333 | einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
|
---|
1334 | if (h->type == bfd_link_hash_new)
|
---|
1335 | {
|
---|
1336 | h->type = bfd_link_hash_undefined;
|
---|
1337 | h->u.undef.abfd = NULL;
|
---|
1338 | bfd_link_add_undef (link_info.hash, h);
|
---|
1339 | }
|
---|
1340 | }
|
---|
1341 | free (buf);
|
---|
1342 |
|
---|
1343 | /* def_file_print (stdout, pe_def_file); */
|
---|
1344 | if (pe_def_file->is_dll == 1)
|
---|
1345 | link_info.shared = 1;
|
---|
1346 |
|
---|
1347 | if (pe_def_file->base_address != (bfd_vma)(-1))
|
---|
1348 | {
|
---|
1349 | pe.ImageBase =
|
---|
1350 | pe_data (output_bfd)->pe_opthdr.ImageBase =
|
---|
1351 | init[IMAGEBASEOFF].value = pe_def_file->base_address;
|
---|
1352 | init[IMAGEBASEOFF].inited = 1;
|
---|
1353 | if (image_base_statement)
|
---|
1354 | image_base_statement->exp =
|
---|
1355 | exp_assop ('=', "__image_base__", exp_intop (pe.ImageBase));
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | #if 0
|
---|
1359 | /* Not sure if these *should* be set. */
|
---|
1360 | if (pe_def_file->version_major != -1)
|
---|
1361 | {
|
---|
1362 | pe.MajorImageVersion = pe_def_file->version_major;
|
---|
1363 | pe.MinorImageVersion = pe_def_file->version_minor;
|
---|
1364 | }
|
---|
1365 | #endif
|
---|
1366 | if (pe_def_file->stack_reserve != -1
|
---|
1367 | && ! saw_option ("__size_of_stack_reserve__"))
|
---|
1368 | {
|
---|
1369 | pe.SizeOfStackReserve = pe_def_file->stack_reserve;
|
---|
1370 | if (pe_def_file->stack_commit != -1)
|
---|
1371 | pe.SizeOfStackCommit = pe_def_file->stack_commit;
|
---|
1372 | }
|
---|
1373 | if (pe_def_file->heap_reserve != -1
|
---|
1374 | && ! saw_option ("__size_of_heap_reserve__"))
|
---|
1375 | {
|
---|
1376 | pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
|
---|
1377 | if (pe_def_file->heap_commit != -1)
|
---|
1378 | pe.SizeOfHeapCommit = pe_def_file->heap_commit;
|
---|
1379 | }
|
---|
1380 | return TRUE;
|
---|
1381 | }
|
---|
1382 | }
|
---|
1383 | #endif
|
---|
1384 | return FALSE;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | static bfd_boolean
|
---|
1388 | gld_${EMULATION_NAME}_recognized_file (entry)
|
---|
1389 | lang_input_statement_type *entry ATTRIBUTE_UNUSED;
|
---|
1390 | {
|
---|
1391 | #ifdef DLL_SUPPORT
|
---|
1392 | #ifdef TARGET_IS_i386pe
|
---|
1393 | pe_dll_id_target ("pei-i386");
|
---|
1394 | #endif
|
---|
1395 | #ifdef TARGET_IS_shpe
|
---|
1396 | pe_dll_id_target ("pei-shl");
|
---|
1397 | #endif
|
---|
1398 | #ifdef TARGET_IS_mipspe
|
---|
1399 | pe_dll_id_target ("pei-mips");
|
---|
1400 | #endif
|
---|
1401 | #ifdef TARGET_IS_armpe
|
---|
1402 | pe_dll_id_target ("pei-arm-little");
|
---|
1403 | #endif
|
---|
1404 | if (bfd_get_format (entry->the_bfd) == bfd_object)
|
---|
1405 | {
|
---|
1406 | char fbuf[LD_PATHMAX + 1];
|
---|
1407 | const char *ext;
|
---|
1408 |
|
---|
1409 | if (REALPATH (entry->filename, fbuf) == NULL)
|
---|
1410 | strncpy (fbuf, entry->filename, sizeof (fbuf));
|
---|
1411 |
|
---|
1412 | ext = fbuf + strlen (fbuf) - 4;
|
---|
1413 |
|
---|
1414 | if (strcmp (ext, ".dll") == 0 || strcmp (ext, ".DLL") == 0)
|
---|
1415 | return pe_implied_import_dll (fbuf);
|
---|
1416 | }
|
---|
1417 | #endif
|
---|
1418 | return FALSE;
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | static void
|
---|
1422 | gld_${EMULATION_NAME}_finish ()
|
---|
1423 | {
|
---|
1424 | #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe)
|
---|
1425 | struct bfd_link_hash_entry * h;
|
---|
1426 |
|
---|
1427 | if (thumb_entry_symbol != NULL)
|
---|
1428 | {
|
---|
1429 | h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
|
---|
1430 | FALSE, FALSE, TRUE);
|
---|
1431 |
|
---|
1432 | if (h != (struct bfd_link_hash_entry *) NULL
|
---|
1433 | && (h->type == bfd_link_hash_defined
|
---|
1434 | || h->type == bfd_link_hash_defweak)
|
---|
1435 | && h->u.def.section->output_section != NULL)
|
---|
1436 | {
|
---|
1437 | static char buffer[32];
|
---|
1438 | bfd_vma val;
|
---|
1439 |
|
---|
1440 | /* Special procesing is required for a Thumb entry symbol. The
|
---|
1441 | bottom bit of its address must be set. */
|
---|
1442 | val = (h->u.def.value
|
---|
1443 | + bfd_get_section_vma (output_bfd,
|
---|
1444 | h->u.def.section->output_section)
|
---|
1445 | + h->u.def.section->output_offset);
|
---|
1446 |
|
---|
1447 | val |= 1;
|
---|
1448 |
|
---|
1449 | /* Now convert this value into a string and store it in entry_symbol
|
---|
1450 | where the lang_finish() function will pick it up. */
|
---|
1451 | buffer[0] = '0';
|
---|
1452 | buffer[1] = 'x';
|
---|
1453 |
|
---|
1454 | sprintf_vma (buffer + 2, val);
|
---|
1455 |
|
---|
1456 | if (entry_symbol.name != NULL && entry_from_cmdline)
|
---|
1457 | einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
|
---|
1458 | thumb_entry_symbol, entry_symbol.name);
|
---|
1459 | entry_symbol.name = buffer;
|
---|
1460 | }
|
---|
1461 | else
|
---|
1462 | einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
|
---|
1463 | }
|
---|
1464 | #endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) */
|
---|
1465 |
|
---|
1466 | #ifdef DLL_SUPPORT
|
---|
1467 | if (link_info.shared
|
---|
1468 | #if !defined(TARGET_IS_shpe) && !defined(TARGET_IS_mipspe)
|
---|
1469 | || (!link_info.relocateable && pe_def_file->num_exports != 0)
|
---|
1470 | #endif
|
---|
1471 | )
|
---|
1472 | {
|
---|
1473 | pe_dll_fill_sections (output_bfd, &link_info);
|
---|
1474 | if (pe_implib_filename)
|
---|
1475 | pe_dll_generate_implib (pe_def_file, pe_implib_filename);
|
---|
1476 | }
|
---|
1477 | #if defined(TARGET_IS_shpe) || defined(TARGET_IS_mipspe)
|
---|
1478 | /* ARM doesn't need relocs. */
|
---|
1479 | else
|
---|
1480 | {
|
---|
1481 | pe_exe_fill_sections (output_bfd, &link_info);
|
---|
1482 | }
|
---|
1483 | #endif
|
---|
1484 |
|
---|
1485 | if (pe_out_def_filename)
|
---|
1486 | pe_dll_generate_def_file (pe_out_def_filename);
|
---|
1487 | #endif /* DLL_SUPPORT */
|
---|
1488 |
|
---|
1489 | /* I don't know where .idata gets set as code, but it shouldn't be. */
|
---|
1490 | {
|
---|
1491 | asection *asec = bfd_get_section_by_name (output_bfd, ".idata");
|
---|
1492 |
|
---|
1493 | if (asec)
|
---|
1494 | {
|
---|
1495 | asec->flags &= ~SEC_CODE;
|
---|
1496 | asec->flags |= SEC_DATA;
|
---|
1497 | }
|
---|
1498 | }
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | |
---|
1502 |
|
---|
1503 | /* Find the last output section before given output statement.
|
---|
1504 | Used by place_orphan. */
|
---|
1505 |
|
---|
1506 | static asection *
|
---|
1507 | output_prev_sec_find (os)
|
---|
1508 | lang_output_section_statement_type *os;
|
---|
1509 | {
|
---|
1510 | asection *s = (asection *) NULL;
|
---|
1511 | lang_statement_union_type *u;
|
---|
1512 | lang_output_section_statement_type *lookup;
|
---|
1513 |
|
---|
1514 | for (u = lang_output_section_statement.head;
|
---|
1515 | u != (lang_statement_union_type *) NULL;
|
---|
1516 | u = lookup->next)
|
---|
1517 | {
|
---|
1518 | lookup = &u->output_section_statement;
|
---|
1519 | if (lookup == os)
|
---|
1520 | return s;
|
---|
1521 |
|
---|
1522 | if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL)
|
---|
1523 | s = lookup->bfd_section;
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | return NULL;
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 | /* Place an orphan section.
|
---|
1530 |
|
---|
1531 | We use this to put sections in a reasonable place in the file, and
|
---|
1532 | to ensure that they are aligned as required.
|
---|
1533 |
|
---|
1534 | We handle grouped sections here as well. A section named .foo$nn
|
---|
1535 | goes into the output section .foo. All grouped sections are sorted
|
---|
1536 | by name.
|
---|
1537 |
|
---|
1538 | Grouped sections for the default sections are handled by the
|
---|
1539 | default linker script using wildcards, and are sorted by
|
---|
1540 | sort_sections. */
|
---|
1541 |
|
---|
1542 | struct orphan_save
|
---|
1543 | {
|
---|
1544 | lang_output_section_statement_type *os;
|
---|
1545 | asection **section;
|
---|
1546 | lang_statement_union_type **stmt;
|
---|
1547 | };
|
---|
1548 |
|
---|
1549 | static bfd_boolean
|
---|
1550 | gld_${EMULATION_NAME}_place_orphan (file, s)
|
---|
1551 | lang_input_statement_type *file;
|
---|
1552 | asection *s;
|
---|
1553 | {
|
---|
1554 | const char *secname;
|
---|
1555 | char *hold_section_name;
|
---|
1556 | char *dollar = NULL;
|
---|
1557 | const char *ps = NULL;
|
---|
1558 | lang_output_section_statement_type *os;
|
---|
1559 | lang_statement_list_type add_child;
|
---|
1560 |
|
---|
1561 | secname = bfd_get_section_name (s->owner, s);
|
---|
1562 |
|
---|
1563 | /* Look through the script to see where to place this section. */
|
---|
1564 | hold_section_name = xstrdup (secname);
|
---|
1565 | if (!link_info.relocateable)
|
---|
1566 | {
|
---|
1567 | dollar = strchr (hold_section_name, '$');
|
---|
1568 | if (dollar != NULL)
|
---|
1569 | *dollar = '\0';
|
---|
1570 | }
|
---|
1571 |
|
---|
1572 | os = lang_output_section_find (hold_section_name);
|
---|
1573 |
|
---|
1574 | lang_list_init (&add_child);
|
---|
1575 |
|
---|
1576 | if (os != NULL
|
---|
1577 | && (os->bfd_section == NULL
|
---|
1578 | || ((s->flags ^ os->bfd_section->flags)
|
---|
1579 | & (SEC_LOAD | SEC_ALLOC)) == 0))
|
---|
1580 | {
|
---|
1581 | /* We already have an output section statement with this
|
---|
1582 | name, and its bfd section, if any, has compatible flags. */
|
---|
1583 | lang_add_section (&add_child, s, os, file);
|
---|
1584 | }
|
---|
1585 | else
|
---|
1586 | {
|
---|
1587 | struct orphan_save *place;
|
---|
1588 | static struct orphan_save hold_text;
|
---|
1589 | static struct orphan_save hold_rdata;
|
---|
1590 | static struct orphan_save hold_data;
|
---|
1591 | static struct orphan_save hold_bss;
|
---|
1592 | char *outsecname;
|
---|
1593 | lang_statement_list_type *old;
|
---|
1594 | lang_statement_list_type add;
|
---|
1595 | etree_type *address;
|
---|
1596 |
|
---|
1597 | /* Try to put the new output section in a reasonable place based
|
---|
1598 | on the section name and section flags. */
|
---|
1599 | #define HAVE_SECTION(hold, name) \
|
---|
1600 | (hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL)
|
---|
1601 |
|
---|
1602 | place = NULL;
|
---|
1603 | if ((s->flags & SEC_ALLOC) == 0)
|
---|
1604 | ;
|
---|
1605 | else if ((s->flags & SEC_HAS_CONTENTS) == 0
|
---|
1606 | && HAVE_SECTION (hold_bss, ".bss"))
|
---|
1607 | place = &hold_bss;
|
---|
1608 | else if ((s->flags & SEC_READONLY) == 0
|
---|
1609 | && HAVE_SECTION (hold_data, ".data"))
|
---|
1610 | place = &hold_data;
|
---|
1611 | else if ((s->flags & SEC_CODE) == 0
|
---|
1612 | && (s->flags & SEC_READONLY) != 0
|
---|
1613 | && HAVE_SECTION (hold_rdata, ".rdata"))
|
---|
1614 | place = &hold_rdata;
|
---|
1615 | else if ((s->flags & SEC_READONLY) != 0
|
---|
1616 | && HAVE_SECTION (hold_text, ".text"))
|
---|
1617 | place = &hold_text;
|
---|
1618 |
|
---|
1619 | #undef HAVE_SECTION
|
---|
1620 |
|
---|
1621 | /* Choose a unique name for the section. This will be needed if
|
---|
1622 | the same section name appears in the input file with
|
---|
1623 | different loadable or allocatable characteristics. */
|
---|
1624 | outsecname = xstrdup (hold_section_name);
|
---|
1625 | if (bfd_get_section_by_name (output_bfd, outsecname) != NULL)
|
---|
1626 | {
|
---|
1627 | unsigned int len;
|
---|
1628 | char *newname;
|
---|
1629 | unsigned int i;
|
---|
1630 |
|
---|
1631 | len = strlen (outsecname);
|
---|
1632 | newname = xmalloc (len + 5);
|
---|
1633 | strcpy (newname, outsecname);
|
---|
1634 | i = 0;
|
---|
1635 | do
|
---|
1636 | {
|
---|
1637 | sprintf (newname + len, "%d", i);
|
---|
1638 | ++i;
|
---|
1639 | }
|
---|
1640 | while (bfd_get_section_by_name (output_bfd, newname) != NULL);
|
---|
1641 |
|
---|
1642 | free (outsecname);
|
---|
1643 | outsecname = newname;
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 | /* Start building a list of statements for this section. */
|
---|
1647 | old = stat_ptr;
|
---|
1648 | stat_ptr = &add;
|
---|
1649 | lang_list_init (stat_ptr);
|
---|
1650 |
|
---|
1651 | if (config.build_constructors)
|
---|
1652 | {
|
---|
1653 | /* If the name of the section is representable in C, then create
|
---|
1654 | symbols to mark the start and the end of the section. */
|
---|
1655 | for (ps = outsecname; *ps != '\0'; ps++)
|
---|
1656 | if (! isalnum ((unsigned char) *ps) && *ps != '_')
|
---|
1657 | break;
|
---|
1658 | if (*ps == '\0')
|
---|
1659 | {
|
---|
1660 | char *symname;
|
---|
1661 | etree_type *e_align;
|
---|
1662 |
|
---|
1663 | symname = (char *) xmalloc (ps - outsecname + sizeof "___start_");
|
---|
1664 | sprintf (symname, "___start_%s", outsecname);
|
---|
1665 | e_align = exp_unop (ALIGN_K,
|
---|
1666 | exp_intop ((bfd_vma) 1 << s->alignment_power));
|
---|
1667 | lang_add_assignment (exp_assop ('=', symname, e_align));
|
---|
1668 | }
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
|
---|
1672 | address = exp_intop ((bfd_vma) 0);
|
---|
1673 | else
|
---|
1674 | {
|
---|
1675 | /* All sections in an executable must be aligned to a page
|
---|
1676 | boundary. */
|
---|
1677 | address = exp_unop (ALIGN_K,
|
---|
1678 | exp_nameop (NAME, "__section_alignment__"));
|
---|
1679 | }
|
---|
1680 |
|
---|
1681 | os = lang_enter_output_section_statement (outsecname, address, 0,
|
---|
1682 | (bfd_vma) 0,
|
---|
1683 | (etree_type *) NULL,
|
---|
1684 | (etree_type *) NULL,
|
---|
1685 | (etree_type *) NULL);
|
---|
1686 |
|
---|
1687 | lang_add_section (&add_child, s, os, file);
|
---|
1688 |
|
---|
1689 | lang_leave_output_section_statement
|
---|
1690 | ((bfd_vma) 0, "*default*",
|
---|
1691 | (struct lang_output_section_phdr_list *) NULL, NULL);
|
---|
1692 |
|
---|
1693 | if (config.build_constructors && *ps == '\0')
|
---|
1694 | {
|
---|
1695 | char *symname;
|
---|
1696 |
|
---|
1697 | /* lang_leave_ouput_section_statement resets stat_ptr.
|
---|
1698 | Put stat_ptr back where we want it. */
|
---|
1699 | if (place != NULL)
|
---|
1700 | stat_ptr = &add;
|
---|
1701 |
|
---|
1702 | symname = (char *) xmalloc (ps - outsecname + sizeof "___stop_");
|
---|
1703 | sprintf (symname, "___stop_%s", outsecname);
|
---|
1704 | lang_add_assignment (exp_assop ('=', symname,
|
---|
1705 | exp_nameop (NAME, ".")));
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | stat_ptr = old;
|
---|
1709 |
|
---|
1710 | if (place != NULL && os->bfd_section != NULL)
|
---|
1711 | {
|
---|
1712 | asection *snew, **pps;
|
---|
1713 |
|
---|
1714 | snew = os->bfd_section;
|
---|
1715 |
|
---|
1716 | /* Shuffle the bfd section list to make the output file look
|
---|
1717 | neater. This is really only cosmetic. */
|
---|
1718 | if (place->section == NULL)
|
---|
1719 | {
|
---|
1720 | asection *bfd_section = place->os->bfd_section;
|
---|
1721 |
|
---|
1722 | /* If the output statement hasn't been used to place
|
---|
1723 | any input sections (and thus doesn't have an output
|
---|
1724 | bfd_section), look for the closest prior output statement
|
---|
1725 | having an output section. */
|
---|
1726 | if (bfd_section == NULL)
|
---|
1727 | bfd_section = output_prev_sec_find (place->os);
|
---|
1728 |
|
---|
1729 | if (bfd_section != NULL && bfd_section != snew)
|
---|
1730 | place->section = &bfd_section->next;
|
---|
1731 | }
|
---|
1732 |
|
---|
1733 | if (place->section != NULL)
|
---|
1734 | {
|
---|
1735 | /* Unlink the section. */
|
---|
1736 | for (pps = &output_bfd->sections;
|
---|
1737 | *pps != snew;
|
---|
1738 | pps = &(*pps)->next)
|
---|
1739 | ;
|
---|
1740 | bfd_section_list_remove (output_bfd, pps);
|
---|
1741 |
|
---|
1742 | /* Now tack it on to the "place->os" section list. */
|
---|
1743 | bfd_section_list_insert (output_bfd, place->section, snew);
|
---|
1744 | }
|
---|
1745 |
|
---|
1746 | /* Save the end of this list. Further ophans of this type will
|
---|
1747 | follow the one we've just added. */
|
---|
1748 | place->section = &snew->next;
|
---|
1749 |
|
---|
1750 | /* The following is non-cosmetic. We try to put the output
|
---|
1751 | statements in some sort of reasonable order here, because
|
---|
1752 | they determine the final load addresses of the orphan
|
---|
1753 | sections. In addition, placing output statements in the
|
---|
1754 | wrong order may require extra segments. For instance,
|
---|
1755 | given a typical situation of all read-only sections placed
|
---|
1756 | in one segment and following that a segment containing all
|
---|
1757 | the read-write sections, we wouldn't want to place an orphan
|
---|
1758 | read/write section before or amongst the read-only ones. */
|
---|
1759 | if (add.head != NULL)
|
---|
1760 | {
|
---|
1761 | if (place->stmt == NULL)
|
---|
1762 | {
|
---|
1763 | /* Put the new statement list right at the head. */
|
---|
1764 | *add.tail = place->os->header.next;
|
---|
1765 | place->os->header.next = add.head;
|
---|
1766 | }
|
---|
1767 | else
|
---|
1768 | {
|
---|
1769 | /* Put it after the last orphan statement we added. */
|
---|
1770 | *add.tail = *place->stmt;
|
---|
1771 | *place->stmt = add.head;
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | /* Fix the global list pointer if we happened to tack our
|
---|
1775 | new list at the tail. */
|
---|
1776 | if (*old->tail == add.head)
|
---|
1777 | old->tail = add.tail;
|
---|
1778 |
|
---|
1779 | /* Save the end of this list. */
|
---|
1780 | place->stmt = add.tail;
|
---|
1781 | }
|
---|
1782 | }
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | {
|
---|
1786 | lang_statement_union_type **pl = &os->children.head;
|
---|
1787 |
|
---|
1788 | if (dollar != NULL)
|
---|
1789 | {
|
---|
1790 | bfd_boolean found_dollar;
|
---|
1791 |
|
---|
1792 | /* The section name has a '$'. Sort it with the other '$'
|
---|
1793 | sections. */
|
---|
1794 | found_dollar = FALSE;
|
---|
1795 | for ( ; *pl != NULL; pl = &(*pl)->header.next)
|
---|
1796 | {
|
---|
1797 | lang_input_section_type *ls;
|
---|
1798 | const char *lname;
|
---|
1799 |
|
---|
1800 | if ((*pl)->header.type != lang_input_section_enum)
|
---|
1801 | continue;
|
---|
1802 |
|
---|
1803 | ls = &(*pl)->input_section;
|
---|
1804 |
|
---|
1805 | lname = bfd_get_section_name (ls->ifile->the_bfd, ls->section);
|
---|
1806 | if (strchr (lname, '$') == NULL)
|
---|
1807 | {
|
---|
1808 | if (found_dollar)
|
---|
1809 | break;
|
---|
1810 | }
|
---|
1811 | else
|
---|
1812 | {
|
---|
1813 | found_dollar = TRUE;
|
---|
1814 | if (strcmp (secname, lname) < 0)
|
---|
1815 | break;
|
---|
1816 | }
|
---|
1817 | }
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | if (add_child.head != NULL)
|
---|
1821 | {
|
---|
1822 | add_child.head->header.next = *pl;
|
---|
1823 | *pl = add_child.head;
|
---|
1824 | }
|
---|
1825 | }
|
---|
1826 |
|
---|
1827 | free (hold_section_name);
|
---|
1828 |
|
---|
1829 | return TRUE;
|
---|
1830 | }
|
---|
1831 |
|
---|
1832 | static bfd_boolean
|
---|
1833 | gld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
|
---|
1834 | const char * arch ATTRIBUTE_UNUSED;
|
---|
1835 | search_dirs_type * search;
|
---|
1836 | lang_input_statement_type * entry;
|
---|
1837 | {
|
---|
1838 | const char * filename;
|
---|
1839 | char * string;
|
---|
1840 |
|
---|
1841 | if (! entry->is_archive)
|
---|
1842 | return FALSE;
|
---|
1843 |
|
---|
1844 | filename = entry->filename;
|
---|
1845 |
|
---|
1846 | string = (char *) xmalloc (strlen (search->name)
|
---|
1847 | + strlen (filename)
|
---|
1848 | + sizeof "/lib.a.dll"
|
---|
1849 | #ifdef DLL_SUPPORT
|
---|
1850 | + (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
|
---|
1851 | #endif
|
---|
1852 | + 1);
|
---|
1853 |
|
---|
1854 | /* Try "libfoo.dll.a" first (preferred explicit import library for dll's. */
|
---|
1855 | sprintf (string, "%s/lib%s.dll.a", search->name, filename);
|
---|
1856 |
|
---|
1857 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1858 | {
|
---|
1859 | /* Try "foo.dll.a" next (alternate explicit import library for dll's. */
|
---|
1860 | sprintf (string, "%s/%s.dll.a", search->name, filename);
|
---|
1861 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1862 | {
|
---|
1863 | /* Try libfoo.a next. Normally, this would be interpreted as a static
|
---|
1864 | library, but it *could* be an import library. For backwards compatibility,
|
---|
1865 | libfoo.a needs to ==precede== libfoo.dll and foo.dll in the search,
|
---|
1866 | or sometimes errors occur when building legacy packages.
|
---|
1867 |
|
---|
1868 | Putting libfoo.a here means that in a failure case (i.e. the library
|
---|
1869 | -lfoo is not found) we will search for libfoo.a twice before
|
---|
1870 | giving up -- once here, and once when searching for a "static" lib.
|
---|
1871 | for a "static" lib. */
|
---|
1872 | /* Try "libfoo.a" (import lib, or static lib, but must
|
---|
1873 | take precedence over dll's). */
|
---|
1874 | sprintf (string, "%s/lib%s.a", search->name, filename);
|
---|
1875 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1876 | {
|
---|
1877 | #ifdef DLL_SUPPORT
|
---|
1878 | if (pe_dll_search_prefix)
|
---|
1879 | {
|
---|
1880 | /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
|
---|
1881 | sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
|
---|
1882 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1883 | {
|
---|
1884 | /* Try "libfoo.dll" (default preferred dll name). */
|
---|
1885 | sprintf (string, "%s/lib%s.dll", search->name, filename);
|
---|
1886 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1887 | {
|
---|
1888 | /* Finally, try "foo.dll" (alternate dll name). */
|
---|
1889 | sprintf (string, "%s/%s.dll", search->name, filename);
|
---|
1890 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1891 | {
|
---|
1892 | free (string);
|
---|
1893 | return FALSE;
|
---|
1894 | }
|
---|
1895 | }
|
---|
1896 | }
|
---|
1897 | }
|
---|
1898 | else /* pe_dll_search_prefix not specified. */
|
---|
1899 | #endif
|
---|
1900 | {
|
---|
1901 | /* Try "libfoo.dll" (preferred dll name). */
|
---|
1902 | sprintf (string, "%s/lib%s.dll", search->name, filename);
|
---|
1903 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1904 | {
|
---|
1905 | /* Finally, try "foo.dll" (alternate dll name). */
|
---|
1906 | sprintf (string, "%s/%s.dll", search->name, filename);
|
---|
1907 | if (! ldfile_try_open_bfd (string, entry))
|
---|
1908 | {
|
---|
1909 | free (string);
|
---|
1910 | return FALSE;
|
---|
1911 | }
|
---|
1912 | }
|
---|
1913 | }
|
---|
1914 | }
|
---|
1915 | }
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | entry->filename = string;
|
---|
1919 |
|
---|
1920 | return TRUE;
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | static int
|
---|
1924 | gld_${EMULATION_NAME}_find_potential_libraries (name, entry)
|
---|
1925 | char * name;
|
---|
1926 | lang_input_statement_type * entry;
|
---|
1927 | {
|
---|
1928 | return ldfile_open_file_search (name, entry, "", ".lib");
|
---|
1929 | }
|
---|
1930 | |
---|
1931 |
|
---|
1932 | static char *
|
---|
1933 | gld_${EMULATION_NAME}_get_script (isfile)
|
---|
1934 | int *isfile;
|
---|
1935 | EOF
|
---|
1936 | # Scripts compiled in.
|
---|
1937 | # sed commands to quote an ld script as a C string.
|
---|
1938 | sc="-f stringify.sed"
|
---|
1939 |
|
---|
1940 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
1941 | {
|
---|
1942 | *isfile = 0;
|
---|
1943 |
|
---|
1944 | if (link_info.relocateable && config.build_constructors)
|
---|
1945 | return
|
---|
1946 | EOF
|
---|
1947 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
|
---|
1948 | echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
|
---|
1949 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
|
---|
1950 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
|
---|
1951 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
|
---|
1952 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
|
---|
1953 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
|
---|
1954 | echo ' ; else return' >> e${EMULATION_NAME}.c
|
---|
1955 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
|
---|
1956 | echo '; }' >> e${EMULATION_NAME}.c
|
---|
1957 |
|
---|
1958 | cat >>e${EMULATION_NAME}.c <<EOF
|
---|
1959 |
|
---|
1960 |
|
---|
1961 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
|
---|
1962 | {
|
---|
1963 | gld_${EMULATION_NAME}_before_parse,
|
---|
1964 | syslib_default,
|
---|
1965 | hll_default,
|
---|
1966 | gld_${EMULATION_NAME}_after_parse,
|
---|
1967 | gld_${EMULATION_NAME}_after_open,
|
---|
1968 | after_allocation_default,
|
---|
1969 | set_output_arch_default,
|
---|
1970 | ldemul_default_target,
|
---|
1971 | gld_${EMULATION_NAME}_before_allocation,
|
---|
1972 | gld_${EMULATION_NAME}_get_script,
|
---|
1973 | "${EMULATION_NAME}",
|
---|
1974 | "${OUTPUT_FORMAT}",
|
---|
1975 | gld_${EMULATION_NAME}_finish,
|
---|
1976 | NULL, /* Create output section statements. */
|
---|
1977 | gld_${EMULATION_NAME}_open_dynamic_archive,
|
---|
1978 | gld_${EMULATION_NAME}_place_orphan,
|
---|
1979 | gld_${EMULATION_NAME}_set_symbols,
|
---|
1980 | NULL, /* parse_args */
|
---|
1981 | gld${EMULATION_NAME}_add_options,
|
---|
1982 | gld${EMULATION_NAME}_handle_option,
|
---|
1983 | gld_${EMULATION_NAME}_unrecognized_file,
|
---|
1984 | gld_${EMULATION_NAME}_list_options,
|
---|
1985 | gld_${EMULATION_NAME}_recognized_file,
|
---|
1986 | gld_${EMULATION_NAME}_find_potential_libraries,
|
---|
1987 | NULL /* new_vers_pattern. */
|
---|
1988 | };
|
---|
1989 | EOF
|
---|