Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5199 serge 1
 
2
 
3
 
4
 
5
 
6
   it under the terms of the GNU General Public License as published by
7
 
8
   (at your option) any later version.
9
 
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, write to the Free Software
17
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18
   MA 02110-1301, USA.  */
19
 
20
21
/* For WINDOWS_NT */
22
/* The original file generated returned different default scripts depending
23
   on whether certain switches were set, but these switches pertain to the
24
 
25
 
26
   the correct entry point by default. */
27
28
#define TARGET_IS_i386pe
29
30
/* Do this before including bfd.h, so we prototype the right functions.  */
31
32
 
33
#define bfd_arm_allocate_interworking_sections 	bfd_i386pe_allocate_interworking_sections
34
 
35
#define bfd_arm_process_before_allocation 	bfd_i386pe_process_before_allocation
36
 
37
38
#include "sysdep.h"
39
#include "bfd.h"
40
#include "bfdlink.h"
41
#include "getopt.h"
42
 
43
#include "filenames.h"
44
#include "ld.h"
45
#include "ldmain.h"
46
#include "ldexp.h"
47
#include "ldlang.h"
48
#include "ldfile.h"
49
#include "ldemul.h"
50
#include 
51
#include "ldlex.h"
52
#include "ldmisc.h"
53
#include "ldctor.h"
54
#include "coff/internal.h"
55
56
/* FIXME: See bfd/peXXigen.c for why we include an architecture specific
57
   header in generic PE code.  */
58
#include "coff/i386.h"
59
#include "coff/pe.h"
60
 
61
/* FIXME: This is a BFD internal header file, and we should not be
62
   using it here.  */
63
#include "../bfd/libcoff.h"
64
65
 
66
#include "pe-dll.h"
67
#include "safe-ctype.h"
68
69
 
70
   alignment by setting OVERRIDE_SECTION_ALIGNMENT.  FIXME: This makes
71
   it seem that include/coff/internal.h should not define
72
   PE_DEF_SECTION_ALIGNMENT.  */
73
 
74
#undef PE_DEF_SECTION_ALIGNMENT
75
#define PE_DEF_SECTION_ALIGNMENT
76
#endif
77
78
#if defined(TARGET_IS_i386pe)     || defined(TARGET_IS_shpe)     || defined(TARGET_IS_armpe)     || defined(TARGET_IS_arm_epoc_pe)     || defined(TARGET_IS_arm_wince_pe)
79
#define DLL_SUPPORT
80
#endif
81
82
 
83
#define DEFAULT_PSEUDO_RELOC_VERSION 2
84
#else
85
#define DEFAULT_PSEUDO_RELOC_VERSION 1
86
 
87
88
#if defined(TARGET_IS_i386pe) || ! defined(DLL_SUPPORT)
89
#define	PE_DEF_SUBSYSTEM		3
90
#else
91
#undef NT_EXE_IMAGE_BASE
92
 
93
#undef PE_DEF_FILE_ALIGNMENT
94
#define NT_EXE_IMAGE_BASE		0x00010000
95
96
#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
97
#define PE_DEF_SECTION_ALIGNMENT	0x00001000
98
#define	PE_DEF_SUBSYSTEM		9
99
#else
100
 
101
#define	PE_DEF_SUBSYSTEM		2
102
#endif
103
#define PE_DEF_FILE_ALIGNMENT		0x00000200
104
#endif
105
106
static struct internal_extra_pe_aouthdr pe;
107
static int dll;
108
static int pe_subsystem = PE_DEF_SUBSYSTEM;
109
static flagword real_flags = 0;
110
 
111
static char * thumb_entry_symbol = NULL;
112
static lang_assignment_statement_type *image_base_statement = 0;
113
static unsigned short pe_dll_characteristics = 0;
114
static bfd_boolean insert_timestamp = FALSE;
115
116
#ifdef DLL_SUPPORT
117
static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable.  */
118
static char *pe_out_def_filename = NULL;
119
static char *pe_implib_filename = NULL;
120
 
121
static char *pe_dll_search_prefix = NULL;
122
#endif
123
124
extern const char *output_filename;
125
126
static int is_underscoring (void)
127
{
128
 
129
  if (pe_leading_underscore != -1)
130
 
131
  if (!bfd_get_target_info ("pei-i386", NULL, NULL, &u, NULL))
132
    bfd_get_target_info ("pe-i386", NULL, NULL, &u, NULL);
133
134
  if (u == -1)
135
    abort ();
136
  pe_leading_underscore = (u != 0 ? 1 : 0);
137
  return pe_leading_underscore;
138
 
139
140
static void
141
gld_i386pe_before_parse (void)
142
{
143
  is_underscoring ();
144
 
145
  output_filename = "a.exe";
146
#ifdef DLL_SUPPORT
147
  input_flags.dynamic = TRUE;
148
  config.has_shared = 1;
149
  link_info.pei386_auto_import = 1;
150
  /* Use by default version.  */
151
  link_info.pei386_runtime_pseudo_reloc = DEFAULT_PSEUDO_RELOC_VERSION;
152
#endif
153
}
154

155
/* Indicates if RDATA shall be merged into DATA when pseudo-relocation
156
   version 2 is used and auto-import is enabled.  */
157
#define MERGE_RDATA_V2 0
158
159
 
160
161
/* Used for setting flags in the PE header.  */
162
#define OPTION_BASE_FILE		(300  + 1)
163
 
164
#define OPTION_FILE_ALIGNMENT		(OPTION_DLL + 1)
165
 
166
#define OPTION_MAJOR_IMAGE_VERSION	(OPTION_IMAGE_BASE + 1)
167
#define OPTION_MAJOR_OS_VERSION		(OPTION_MAJOR_IMAGE_VERSION + 1)
168
#define OPTION_MAJOR_SUBSYSTEM_VERSION	(OPTION_MAJOR_OS_VERSION + 1)
169
#define OPTION_MINOR_IMAGE_VERSION	(OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
170
#define OPTION_MINOR_OS_VERSION		(OPTION_MINOR_IMAGE_VERSION + 1)
171
#define OPTION_MINOR_SUBSYSTEM_VERSION	(OPTION_MINOR_OS_VERSION + 1)
172
#define OPTION_SECTION_ALIGNMENT	(OPTION_MINOR_SUBSYSTEM_VERSION + 1)
173
#define OPTION_STACK			(OPTION_SECTION_ALIGNMENT + 1)
174
#define OPTION_SUBSYSTEM		(OPTION_STACK + 1)
175
#define OPTION_HEAP			(OPTION_SUBSYSTEM + 1)
176
#define OPTION_SUPPORT_OLD_CODE		(OPTION_HEAP + 1)
177
#define OPTION_OUT_DEF			(OPTION_SUPPORT_OLD_CODE + 1)
178
#define OPTION_EXPORT_ALL		(OPTION_OUT_DEF + 1)
179
#define OPTION_EXCLUDE_SYMBOLS		(OPTION_EXPORT_ALL + 1)
180
#define OPTION_EXCLUDE_ALL_SYMBOLS	(OPTION_EXCLUDE_SYMBOLS + 1)
181
#define OPTION_KILL_ATS			(OPTION_EXCLUDE_ALL_SYMBOLS + 1)
182
#define OPTION_STDCALL_ALIASES		(OPTION_KILL_ATS + 1)
183
#define OPTION_ENABLE_STDCALL_FIXUP	(OPTION_STDCALL_ALIASES + 1)
184
#define OPTION_DISABLE_STDCALL_FIXUP	(OPTION_ENABLE_STDCALL_FIXUP + 1)
185
#define OPTION_IMPLIB_FILENAME		(OPTION_DISABLE_STDCALL_FIXUP + 1)
186
#define OPTION_THUMB_ENTRY		(OPTION_IMPLIB_FILENAME + 1)
187
#define OPTION_WARN_DUPLICATE_EXPORTS	(OPTION_THUMB_ENTRY + 1)
188
#define OPTION_IMP_COMPAT		(OPTION_WARN_DUPLICATE_EXPORTS + 1)
189
#define OPTION_ENABLE_AUTO_IMAGE_BASE	(OPTION_IMP_COMPAT + 1)
190
#define OPTION_DISABLE_AUTO_IMAGE_BASE	(OPTION_ENABLE_AUTO_IMAGE_BASE + 1)
191
#define OPTION_DLL_SEARCH_PREFIX	(OPTION_DISABLE_AUTO_IMAGE_BASE + 1)
192
#define OPTION_NO_DEFAULT_EXCLUDES	(OPTION_DLL_SEARCH_PREFIX + 1)
193
#define OPTION_DLL_ENABLE_AUTO_IMPORT	(OPTION_NO_DEFAULT_EXCLUDES + 1)
194
#define OPTION_DLL_DISABLE_AUTO_IMPORT	(OPTION_DLL_ENABLE_AUTO_IMPORT + 1)
195
#define OPTION_ENABLE_EXTRA_PE_DEBUG	(OPTION_DLL_DISABLE_AUTO_IMPORT + 1)
196
#define OPTION_EXCLUDE_LIBS		(OPTION_ENABLE_EXTRA_PE_DEBUG + 1)
197
#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC						(OPTION_EXCLUDE_LIBS + 1)
198
#define OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC						(OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC + 1)
199
#define OPTION_LARGE_ADDRESS_AWARE 	(OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC + 1)
200
#define OPTION_DISABLE_LARGE_ADDRESS_AWARE  					(OPTION_LARGE_ADDRESS_AWARE + 1)
201
#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1						(OPTION_DISABLE_LARGE_ADDRESS_AWARE + 1)
202
#define OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2						(OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1 + 1)
203
#define OPTION_EXCLUDE_MODULES_FOR_IMPLIB 					(OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2 + 1)
204
#define OPTION_USE_NUL_PREFIXED_IMPORT_TABLES 					(OPTION_EXCLUDE_MODULES_FOR_IMPLIB + 1)
205
#define OPTION_NO_LEADING_UNDERSCORE 	(OPTION_USE_NUL_PREFIXED_IMPORT_TABLES + 1)
206
#define OPTION_LEADING_UNDERSCORE 	(OPTION_NO_LEADING_UNDERSCORE + 1)
207
#define OPTION_ENABLE_LONG_SECTION_NAMES 					(OPTION_LEADING_UNDERSCORE + 1)
208
#define OPTION_DISABLE_LONG_SECTION_NAMES 					(OPTION_ENABLE_LONG_SECTION_NAMES + 1)
209
/* DLLCharacteristics flags.  */
210
#define OPTION_DYNAMIC_BASE		(OPTION_DISABLE_LONG_SECTION_NAMES + 1)
211
#define OPTION_FORCE_INTEGRITY		(OPTION_DYNAMIC_BASE + 1)
212
#define OPTION_NX_COMPAT		(OPTION_FORCE_INTEGRITY + 1)
213
#define OPTION_NO_ISOLATION		(OPTION_NX_COMPAT + 1)
214
#define OPTION_NO_SEH			(OPTION_NO_ISOLATION + 1)
215
#define OPTION_NO_BIND			(OPTION_NO_SEH + 1)
216
#define OPTION_WDM_DRIVER		(OPTION_NO_BIND + 1)
217
#define OPTION_TERMINAL_SERVER_AWARE	(OPTION_WDM_DRIVER + 1)
218
/* Determinism.  */
219
#define OPTION_INSERT_TIMESTAMP		(OPTION_TERMINAL_SERVER_AWARE + 1)
220
221
static void
222
gldi386pe_add_options
223
  (int ns ATTRIBUTE_UNUSED,
224
   char **shortopts ATTRIBUTE_UNUSED,
225
 
226
   struct option **longopts,
227
   int nrl ATTRIBUTE_UNUSED,
228
   struct option **really_longopts ATTRIBUTE_UNUSED)
229
{
230
  static const struct option xtra_long[] =
231
  {
232
    /* PE options.  */
233
    {"base-file", required_argument, NULL, OPTION_BASE_FILE},
234
    {"dll", no_argument, NULL, OPTION_DLL},
235
    {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
236
    {"heap", required_argument, NULL, OPTION_HEAP},
237
    {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
238
    {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
239
    {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
240
    {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
241
    {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
242
    {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
243
    {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
244
    {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
245
    {"stack", required_argument, NULL, OPTION_STACK},
246
    {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
247
    {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
248
    {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
249
    {"use-nul-prefixed-import-tables", no_argument, NULL,
250
     OPTION_USE_NUL_PREFIXED_IMPORT_TABLES},
251
    {"no-leading-underscore", no_argument, NULL, OPTION_NO_LEADING_UNDERSCORE},
252
    {"leading-underscore", no_argument, NULL, OPTION_LEADING_UNDERSCORE},
253
    {"insert-timestamp", no_argument, NULL, OPTION_INSERT_TIMESTAMP},
254
#ifdef DLL_SUPPORT
255
    /* getopt allows abbreviations, so we do this to stop it
256
       from treating -o as an abbreviation for this option.  */
257
    {"output-def", required_argument, NULL, OPTION_OUT_DEF},
258
    {"output-def", required_argument, NULL, OPTION_OUT_DEF},
259
    {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
260
    {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
261
    {"exclude-all-symbols", no_argument, NULL, OPTION_EXCLUDE_ALL_SYMBOLS},
262
    {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
263
    {"exclude-modules-for-implib", required_argument, NULL, OPTION_EXCLUDE_MODULES_FOR_IMPLIB},
264
    {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
265
    {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
266
    {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
267
    {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
268
    {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
269
    {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
270
    /* getopt() allows abbreviations, so we do this to stop it from
271
       treating -c as an abbreviation for these --compat-implib.  */
272
    {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
273
    {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
274
    {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
275
    {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
276
    {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
277
    {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
278
    {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
279
    {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
280
    {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
281
    {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
282
    {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
283
    {"enable-runtime-pseudo-reloc-v1", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1},
284
    {"enable-runtime-pseudo-reloc-v2", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2},
285
#endif
286
    {"large-address-aware", no_argument, NULL, OPTION_LARGE_ADDRESS_AWARE},
287
    {"disable-large-address-aware", no_argument, NULL, OPTION_DISABLE_LARGE_ADDRESS_AWARE},
288
    {"enable-long-section-names", no_argument, NULL, OPTION_ENABLE_LONG_SECTION_NAMES},
289
    {"disable-long-section-names", no_argument, NULL, OPTION_DISABLE_LONG_SECTION_NAMES},
290
    {"dynamicbase",no_argument, NULL, OPTION_DYNAMIC_BASE},
291
    {"forceinteg", no_argument, NULL, OPTION_FORCE_INTEGRITY},
292
    {"nxcompat", no_argument, NULL, OPTION_NX_COMPAT},
293
    {"no-isolation", no_argument, NULL, OPTION_NO_ISOLATION},
294
    {"no-seh", no_argument, NULL, OPTION_NO_SEH},
295
    {"no-bind", no_argument, NULL, OPTION_NO_BIND},
296
    {"wdmdriver", no_argument, NULL, OPTION_WDM_DRIVER},
297
    {"tsaware", no_argument, NULL, OPTION_TERMINAL_SERVER_AWARE},
298
    {NULL, no_argument, NULL, 0}
299
  };
300
301
  *longopts
302
    = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
303
  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
304
}
305
 
306
/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
307
   parameters which may be input from the command line.  */
308
309
typedef struct
310
 
311
  void *ptr;
312
  int size;
313
 
314
  char *symbol;
315
  int inited;
316
  /* FALSE for an assembly level symbol and TRUE for a C visible symbol.
317
     C visible symbols can be prefixed by underscore dependent to target's
318
     settings.  */
319
  bfd_boolean is_c_symbol;
320
} definfo;
321
322
/* Get symbol name dependent to kind and C visible state of
323
   underscore.  */
324
#define GET_INIT_SYMBOL_NAME(IDX)   (init[(IDX)].symbol   + ((init[(IDX)].is_c_symbol == FALSE || (is_underscoring () != 0)) ? 0 : 1))
325
326
 
327
#define U(CSTR)   ((is_underscoring () == 0) ? CSTR : "_" CSTR)
328
329
/* Get size of constant string for a possible underscore prefixed
330
 
331
#define U_SIZE(CSTR)   (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
332
333
 
334
335
static definfo init[] =
336
{
337
 
338
#define IMAGEBASEOFF 0
339
 
340
#define DLLOFF 1
341
  {&dll, sizeof(dll), 0, "__dll__", 0, FALSE},
342
#define MSIMAGEBASEOFF	2
343
  D(ImageBase, "___ImageBase", NT_EXE_IMAGE_BASE, TRUE),
344
  D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT, FALSE),
345
  D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT, FALSE),
346
  D(MajorOperatingSystemVersion,"__major_os_version__", 4, FALSE),
347
  D(MinorOperatingSystemVersion,"__minor_os_version__", 0, FALSE),
348
  D(MajorImageVersion,"__major_image_version__", 1, FALSE),
349
  D(MinorImageVersion,"__minor_image_version__", 0, FALSE),
350
#if defined(TARGET_IS_armpe)  || defined(TARGET_IS_arm_wince_pe)
351
  D(MajorSubsystemVersion,"__major_subsystem_version__", 3, FALSE),
352
#else
353
  D(MajorSubsystemVersion,"__major_subsystem_version__", 4, FALSE),
354
#endif
355
  D(MinorSubsystemVersion,"__minor_subsystem_version__", 0, FALSE),
356
  D(Subsystem,"__subsystem__", PE_DEF_SUBSYSTEM, FALSE),
357
  D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x200000, FALSE),
358
  D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000, FALSE),
359
  D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000, FALSE),
360
  D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000, FALSE),
361
  D(LoaderFlags,"__loader_flags__", 0x0, FALSE),
362
  D(DllCharacteristics, "__dll_characteristics__", 0x0, FALSE),
363
  { NULL, 0, 0, NULL, 0 , FALSE}
364
};
365
366
367
static void
368
gld_i386pe_list_options (FILE *file)
369
{
370
 
371
 
372
  fprintf (file, _("  --file-alignment             Set file alignment\n"));
373
  fprintf (file, _("  --heap                       Set initial size of the heap\n"));
374
  fprintf (file, _("  --image-base 
Set start address of the executable\n"));
375
  fprintf (file, _("  --major-image-version      Set version number of the executable\n"));
376
  fprintf (file, _("  --major-os-version         Set minimum required OS version\n"));
377
  fprintf (file, _("  --major-subsystem-version  Set minimum required OS subsystem version\n"));
378
  fprintf (file, _("  --minor-image-version      Set revision number of the executable\n"));
379
  fprintf (file, _("  --minor-os-version         Set minimum required OS revision\n"));
380
  fprintf (file, _("  --minor-subsystem-version  Set minimum required OS subsystem revision\n"));
381
  fprintf (file, _("  --section-alignment          Set section alignment\n"));
382
  fprintf (file, _("  --stack                      Set size of the initial stack\n"));
383
  fprintf (file, _("  --subsystem [:]     Set required OS subsystem [& version]\n"));
384
  fprintf (file, _("  --support-old-code                 Support interworking with old code\n"));
385
  fprintf (file, _("  --[no-]leading-underscore          Set explicit symbol underscore prefix mode\n"));
386
  fprintf (file, _("  --thumb-entry=             Set the entry point to be Thumb \n"));
387
  fprintf (file, _("  --insert-timestamp                 Use a real timestamp rather than zero.\n"));
388
  fprintf (file, _("                                     This makes binaries non-deterministic\n"));
389
#ifdef DLL_SUPPORT
390
  fprintf (file, _("  --add-stdcall-alias                Export symbols with and without @nn\n"));
391
  fprintf (file, _("  --disable-stdcall-fixup            Don't link _sym to _sym@nn\n"));
392
  fprintf (file, _("  --enable-stdcall-fixup             Link _sym to _sym@nn without warnings\n"));
393
  fprintf (file, _("  --exclude-symbols sym,sym,...      Exclude symbols from automatic export\n"));
394
  fprintf (file, _("  --exclude-all-symbols              Exclude all symbols from automatic export\n"));
395
  fprintf (file, _("  --exclude-libs lib,lib,...         Exclude libraries from automatic export\n"));
396
  fprintf (file, _("  --exclude-modules-for-implib mod,mod,...\n"));
397
  fprintf (file, _("                                     Exclude objects, archive members from auto\n"));
398
  fprintf (file, _("                                     export, place into import library instead.\n"));
399
  fprintf (file, _("  --export-all-symbols               Automatically export all globals to DLL\n"));
400
  fprintf (file, _("  --kill-at                          Remove @nn from exported symbols\n"));
401
  fprintf (file, _("  --out-implib                 Generate import library\n"));
402
  fprintf (file, _("  --output-def                 Generate a .DEF file for the built DLL\n"));
403
  fprintf (file, _("  --warn-duplicate-exports           Warn about duplicate exports.\n"));
404
  fprintf (file, _("  --compat-implib                    Create backward compatible import libs;\n                                       create __imp_ as well.\n"));
405
  fprintf (file, _("  --enable-auto-image-base           Automatically choose image base for DLLs\n                                       unless user specifies one\n"));
406
  fprintf (file, _("  --disable-auto-image-base          Do not auto-choose image base. (default)\n"));
407
  fprintf (file, _("  --dll-search-prefix=       When linking dynamically to a dll without\n                                       an importlib, use .dll\n                                       in preference to lib.dll \n"));
408
  fprintf (file, _("  --enable-auto-import               Do sophisticated linking of _sym to\n                                       __imp_sym for DATA references\n"));
409
  fprintf (file, _("  --disable-auto-import              Do not auto-import DATA items from DLLs\n"));
410
  fprintf (file, _("  --enable-runtime-pseudo-reloc      Work around auto-import limitations by\n                                       adding pseudo-relocations resolved at\n                                       runtime.\n"));
411
  fprintf (file, _("  --disable-runtime-pseudo-reloc     Do not add runtime pseudo-relocations for\n                                       auto-imported DATA.\n"));
412
  fprintf (file, _("  --enable-extra-pe-debug            Enable verbose debug output when building\n                                       or linking to DLLs (esp. auto-import)\n"));
413
#endif
414
  fprintf (file, _("  --large-address-aware              Executable supports virtual addresses\n                                       greater than 2 gigabytes\n"));
415
  fprintf (file, _("  --disable-large-address-aware      Executable does not support virtual\n                                       addresses greater than 2 gigabytes\n"));
416
  fprintf (file, _("  --enable-long-section-names        Use long COFF section names even in\n                                       executable image files\n"));
417
  fprintf (file, _("  --disable-long-section-names       Never use long COFF section names, even\n                                       in object files\n"));
418
  fprintf (file, _("  --dynamicbase			 Image base address may be relocated using\n				       address space layout randomization (ASLR)\n"));
419
  fprintf (file, _("  --forceinteg		 Code integrity checks are enforced\n"));
420
  fprintf (file, _("  --nxcompat		 Image is compatible with data execution prevention\n"));
421
  fprintf (file, _("  --no-isolation		 Image understands isolation but do not isolate the image\n"));
422
  fprintf (file, _("  --no-seh			 Image does not use SEH. No SE handler may\n				       be called in this image\n"));
423
  fprintf (file, _("  --no-bind			 Do not bind this image\n"));
424
  fprintf (file, _("  --wdmdriver		 Driver uses the WDM model\n"));
425
  fprintf (file, _("  --tsaware                  Image is Terminal Server aware\n"));
426
}
427
428
429
static void
430
set_pe_name (char *name, long val)
431
{
432
 
433
 
434
435
  /* Find the name and set it.  */
436
  for (i = 0; init[i].ptr; i++)
437
    {
438
      if (strcmp (name, GET_INIT_SYMBOL_NAME (i)) == 0)
439
 
440
	  init[i].value = val;
441
	  init[i].inited = 1;
442
	  if (strcmp (name,"__image_base__") == 0)
443
	    set_pe_name (U ("__ImageBase"), val);
444
	  return;
445
	}
446
    }
447
  abort ();
448
}
449
450
static void
451
set_entry_point (void)
452
{
453
  const char *entry;
454
 
455
  int i;
456
457
  static const struct
458
    {
459
      const int value;
460
      const char *entry;
461
 
462
  v[] =
463
    {
464
      { 1, "NtProcessStartup"  },
465
      { 2, "WinMainCRTStartup" },
466
      { 3, "mainCRTStartup"    },
467
      { 7, "__PosixProcessStartup"},
468
      { 9, "WinMainCRTStartup" },
469
      {14, "mainCRTStartup"    },
470
      { 0, NULL          }
471
    };
472
473
  /* Entry point name for arbitrary subsystem numbers.  */
474
  static const char default_entry[] = "mainCRTStartup";
475
476
  if (link_info.shared || dll)
477
 
478
#if defined (TARGET_IS_i386pe)
479
      entry = "DllMainCRTStartup@12";
480
 
481
      entry = "DllMainCRTStartup";
482
#endif
483
    }
484
  else
485
    {
486
487
      for (i = 0; v[i].entry; i++)
488
        if (v[i].value == pe_subsystem)
489
          break;
490
491
 
492
      if (v[i].entry != NULL)
493
        entry = v[i].entry;
494
      else
495
 
496
    }
497
498
  initial_symbol_char = (is_underscoring () != 0 ? "_" : "");
499
500
  if (*initial_symbol_char != '\0')
501
    {
502
 
503
504
 
505
	 allocated, so we don't free this string.  */
506
      alc_entry = xmalloc (strlen (initial_symbol_char)
507
			   + strlen (entry)
508
 
509
      strcpy (alc_entry, initial_symbol_char);
510
      strcat (alc_entry, entry);
511
      entry = alc_entry;
512
    }
513
514
  lang_default_entry (entry);
515
}
516
517
static void
518
 
519
{
520
  const char *sver;
521
 
522
  int len;
523
  int i;
524
  unsigned long temp_subsystem;
525
  static const struct
526
    {
527
      const char *name;
528
      const int value;
529
    }
530
  v[] =
531
    {
532
      { "native",  1},
533
      { "windows", 2},
534
      { "console", 3},
535
      { "posix",   7},
536
      { "wince",   9},
537
      { "xbox",   14},
538
      { NULL, 0 }
539
    };
540
541
  /* Check for the presence of a version number.  */
542
  sver = strchr (optarg, ':');
543
  if (sver == NULL)
544
    len = strlen (optarg);
545
 
546
    {
547
      len = sver - optarg;
548
      set_pe_name ("__major_subsystem_version__",
549
		    strtoul (sver + 1, &end, 0));
550
      if (*end == '.')
551
	set_pe_name ("__minor_subsystem_version__",
552
		      strtoul (end + 1, &end, 0));
553
      if (*end != '\0')
554
	einfo (_("%P: warning: bad version number in -subsystem option\n"));
555
    }
556
557
  /* Check for numeric subsystem.  */
558
  temp_subsystem = strtoul (optarg, & end, 0);
559
  if ((*end == ':' || *end == '\0') && (temp_subsystem < 65536))
560
    {
561
 
562
      for (i = 0; v[i].name; i++)
563
	if (v[i].value == (int) temp_subsystem)
564
	  break;
565
566
      /* Use this subsystem.  */
567
      pe_subsystem = (int) temp_subsystem;
568
    }
569
  else
570
 
571
      /* Search for subsystem by name.  */
572
      for (i = 0; v[i].name; i++)
573
	if (strncmp (optarg, v[i].name, len) == 0
574
	    && v[i].name[len] == '\0')
575
	  break;
576
577
      if (v[i].name == NULL)
578
	{
579
	  einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
580
	  return;
581
 
582
583
      pe_subsystem = v[i].value;
584
    }
585
586
  set_pe_name ("__subsystem__", pe_subsystem);
587
 
588
  return;
589
}
590
 
591
592
 
593
set_pe_value (char *name)
594
{
595
 
596
 
597
  set_pe_name (name,  strtoul (optarg, &end, 0));
598
599
  if (end == optarg)
600
    einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
601
 
602
  optarg = end;
603
 
604
605
606
 
607
set_pe_stack_heap (char *resname, char *comname)
608
{
609
 
610
 
611
  if (*optarg == ',')
612
    {
613
      optarg++;
614
      set_pe_value (comname);
615
 
616
  else if (*optarg)
617
    einfo (_("%P%F: strange hex info for PE parameter '%s'\n"), optarg);
618
}
619
620
621
static bfd_boolean
622
gldi386pe_handle_option (int optc)
623
{
624
 
625
 
626
    default:
627
      return FALSE;
628
629
    case OPTION_BASE_FILE:
630
      link_info.base_file = fopen (optarg, FOPEN_WB);
631
      if (link_info.base_file == NULL)
632
	einfo (_("%F%P: cannot open base file %s\n"), optarg);
633
 
634
635
      /* PE options.  */
636
    case OPTION_HEAP:
637
      set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
638
      break;
639
 
640
      set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
641
      break;
642
    case OPTION_SUBSYSTEM:
643
      set_pe_subsystem ();
644
      break;
645
    case OPTION_MAJOR_OS_VERSION:
646
      set_pe_value ("__major_os_version__");
647
      break;
648
    case OPTION_MINOR_OS_VERSION:
649
      set_pe_value ("__minor_os_version__");
650
      break;
651
    case OPTION_MAJOR_SUBSYSTEM_VERSION:
652
      set_pe_value ("__major_subsystem_version__");
653
      break;
654
    case OPTION_MINOR_SUBSYSTEM_VERSION:
655
      set_pe_value ("__minor_subsystem_version__");
656
      break;
657
    case OPTION_MAJOR_IMAGE_VERSION:
658
      set_pe_value ("__major_image_version__");
659
      break;
660
    case OPTION_MINOR_IMAGE_VERSION:
661
      set_pe_value ("__minor_image_version__");
662
      break;
663
    case OPTION_FILE_ALIGNMENT:
664
      set_pe_value ("__file_alignment__");
665
      break;
666
    case OPTION_SECTION_ALIGNMENT:
667
      set_pe_value ("__section_alignment__");
668
      break;
669
    case OPTION_DLL:
670
      set_pe_name ("__dll__", 1);
671
      break;
672
    case OPTION_IMAGE_BASE:
673
      set_pe_value ("__image_base__");
674
      break;
675
    case OPTION_SUPPORT_OLD_CODE:
676
      support_old_code = 1;
677
      break;
678
    case OPTION_THUMB_ENTRY:
679
      thumb_entry_symbol = optarg;
680
      break;
681
    case OPTION_USE_NUL_PREFIXED_IMPORT_TABLES:
682
      pe_use_nul_prefixed_import_tables = TRUE;
683
      break;
684
    case OPTION_NO_LEADING_UNDERSCORE:
685
      pe_leading_underscore = 0;
686
      break;
687
    case OPTION_LEADING_UNDERSCORE:
688
      pe_leading_underscore = 1;
689
      break;
690
    case OPTION_INSERT_TIMESTAMP:
691
      insert_timestamp = TRUE;
692
      break;
693
#ifdef DLL_SUPPORT
694
    case OPTION_OUT_DEF:
695
      pe_out_def_filename = xstrdup (optarg);
696
      break;
697
    case OPTION_EXPORT_ALL:
698
      pe_dll_export_everything = 1;
699
      break;
700
    case OPTION_EXCLUDE_SYMBOLS:
701
      pe_dll_add_excludes (optarg, EXCLUDESYMS);
702
      break;
703
    case OPTION_EXCLUDE_ALL_SYMBOLS:
704
      pe_dll_exclude_all_symbols = 1;
705
      break;
706
    case OPTION_EXCLUDE_LIBS:
707
      pe_dll_add_excludes (optarg, EXCLUDELIBS);
708
      break;
709
    case OPTION_EXCLUDE_MODULES_FOR_IMPLIB:
710
      pe_dll_add_excludes (optarg, EXCLUDEFORIMPLIB);
711
      break;
712
    case OPTION_KILL_ATS:
713
      pe_dll_kill_ats = 1;
714
      break;
715
    case OPTION_STDCALL_ALIASES:
716
      pe_dll_stdcall_aliases = 1;
717
      break;
718
    case OPTION_ENABLE_STDCALL_FIXUP:
719
      pe_enable_stdcall_fixup = 1;
720
      break;
721
    case OPTION_DISABLE_STDCALL_FIXUP:
722
      pe_enable_stdcall_fixup = 0;
723
      break;
724
    case OPTION_IMPLIB_FILENAME:
725
      pe_implib_filename = xstrdup (optarg);
726
      break;
727
    case OPTION_WARN_DUPLICATE_EXPORTS:
728
      pe_dll_warn_dup_exports = 1;
729
      break;
730
    case OPTION_IMP_COMPAT:
731
      pe_dll_compat_implib = 1;
732
      break;
733
    case OPTION_ENABLE_AUTO_IMAGE_BASE:
734
      pe_enable_auto_image_base = 1;
735
      break;
736
    case OPTION_DISABLE_AUTO_IMAGE_BASE:
737
      pe_enable_auto_image_base = 0;
738
      break;
739
    case OPTION_DLL_SEARCH_PREFIX:
740
      pe_dll_search_prefix = xstrdup (optarg);
741
      break;
742
    case OPTION_NO_DEFAULT_EXCLUDES:
743
      pe_dll_do_default_excludes = 0;
744
      break;
745
    case OPTION_DLL_ENABLE_AUTO_IMPORT:
746
      link_info.pei386_auto_import = 1;
747
      break;
748
    case OPTION_DLL_DISABLE_AUTO_IMPORT:
749
      link_info.pei386_auto_import = 0;
750
      break;
751
    case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC:
752
      link_info.pei386_runtime_pseudo_reloc =
753
	DEFAULT_PSEUDO_RELOC_VERSION;
754
      break;
755
    case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1:
756
      link_info.pei386_runtime_pseudo_reloc = 1;
757
      break;
758
    case OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2:
759
      link_info.pei386_runtime_pseudo_reloc = 2;
760
      break;
761
    case OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC:
762
      link_info.pei386_runtime_pseudo_reloc = 0;
763
      break;
764
    case OPTION_ENABLE_EXTRA_PE_DEBUG:
765
      pe_dll_extra_pe_debug = 1;
766
      break;
767
#endif
768
    case OPTION_LARGE_ADDRESS_AWARE:
769
      real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
770
      break;
771
    case OPTION_DISABLE_LARGE_ADDRESS_AWARE:
772
      real_flags &= ~ IMAGE_FILE_LARGE_ADDRESS_AWARE;
773
      break;
774
    case OPTION_ENABLE_LONG_SECTION_NAMES:
775
      pe_use_coff_long_section_names = 1;
776
      break;
777
    case OPTION_DISABLE_LONG_SECTION_NAMES:
778
      pe_use_coff_long_section_names = 0;
779
      break;
780
/*  Get DLLCharacteristics bits  */
781
    case OPTION_DYNAMIC_BASE:
782
      pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE;
783
      break;
784
    case OPTION_FORCE_INTEGRITY:
785
      pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY;
786
      break;
787
    case OPTION_NX_COMPAT:
788
      pe_dll_characteristics |= IMAGE_DLL_CHARACTERISTICS_NX_COMPAT;
789
      break;
790
    case OPTION_NO_ISOLATION:
791
      pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_ISOLATION;
792
      break;
793
    case OPTION_NO_SEH:
794
      pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_SEH;
795
      break;
796
    case OPTION_NO_BIND:
797
      pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_NO_BIND;
798
      break;
799
    case OPTION_WDM_DRIVER:
800
      pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_WDM_DRIVER;
801
      break;
802
    case OPTION_TERMINAL_SERVER_AWARE:
803
      pe_dll_characteristics |= IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE;
804
      break;
805
    }
806
807
  /*  Set DLLCharacteristics bits  */
808
  set_pe_name ("__dll_characteristics__", pe_dll_characteristics);
809
810
  return TRUE;
811
 
812

813
814
 
815
static unsigned long
816
strhash (const char *str)
817
 
818
 
819
  unsigned long hash;
820
  unsigned int c;
821
  unsigned int len;
822
823
  hash = 0;
824
  len = 0;
825
  s = (const unsigned char *) str;
826
  while ((c = *s++) != '\0')
827
 
828
      hash += c + (c << 17);
829
      hash ^= hash >> 2;
830
      ++len;
831
    }
832
  hash += len + (len << 17);
833
  hash ^= hash >> 2;
834
835
  return hash;
836
}
837
838
/* Use the output file to create a image base for relocatable DLLs.  */
839
 
840
static unsigned long
841
compute_dll_image_base (const char *ofile)
842
 
843
  unsigned long hash = strhash (ofile);
844
 
845
}
846
#endif
847
848
/* Assign values to the special symbols before the linker script is
849
   read.  */
850
851
static void
852
 
853
{
854
  /* Run through and invent symbols for all the
855
 
856
  int j;
857
858
  is_underscoring ();
859
860
  if (!init[IMAGEBASEOFF].inited)
861
    {
862
 
863
	init[IMAGEBASEOFF].value = 0;
864
 
865
	{
866
#ifdef DLL_SUPPORT
867
	  init[IMAGEBASEOFF].value = (pe_enable_auto_image_base
868
				      ? compute_dll_image_base (output_filename)
869
				      : NT_DLL_IMAGE_BASE);
870
#else
871
	  init[IMAGEBASEOFF].value = NT_DLL_IMAGE_BASE;
872
#endif
873
	}
874
      else
875
	init[IMAGEBASEOFF].value = NT_EXE_IMAGE_BASE;
876
      init[MSIMAGEBASEOFF].value = init[IMAGEBASEOFF].value;
877
    }
878
879
  /* Don't do any symbol assignments if this is a relocatable link.  */
880
  if (link_info.relocatable)
881
    return;
882
883
 
884
  push_stat_ptr (&abs_output_section->children);
885
886
  for (j = 0; init[j].ptr; j++)
887
 
888
      long val = init[j].value;
889
      lang_assignment_statement_type *rv;
890
 
891
      rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
892
					    exp_intop (val), FALSE));
893
      if (init[j].size == sizeof (short))
894
	*(short *) init[j].ptr = val;
895
 
896
	*(int *) init[j].ptr = val;
897
      else if (init[j].size == sizeof (long))
898
	*(long *) init[j].ptr = val;
899
      /* This might be a long long or other special type.  */
900
      else if (init[j].size == sizeof (bfd_vma))
901
	*(bfd_vma *) init[j].ptr = val;
902
      else	abort ();
903
      if (j == IMAGEBASEOFF)
904
	image_base_statement = rv;
905
    }
906
  /* Restore the pointer.  */
907
  pop_stat_ptr ();
908
909
  if (pe.FileAlignment > pe.SectionAlignment)
910
    {
911
      einfo (_("%P: warning, file alignment > section alignment.\n"));
912
    }
913
 
914
915
/* This is called after the linker script and the command line options
916
   have been read.  */
917
918
static void
919
 
920
{
921
  /* PR ld/6744:  Warn the user if they have used an ELF-only
922
 
923
  if (link_info.export_dynamic)
924
    einfo (_("%P: warning: --export-dynamic is not supported for PE "
925
      "targets, did you mean --export-all-symbols?\n"));
926
927
  set_entry_point ();
928
929
  after_parse_default ();
930
}
931
 
932
/* pe-dll.c directly accesses pe_data_import_dll,
933
 
934
   Note - this variable is deliberately not initialised.
935
   This allows it to be treated as a common varaible, and only
936
 
937
char * pe_data_import_dll;
938
939
#ifdef DLL_SUPPORT
940
static struct bfd_link_hash_entry *pe_undef_found_sym;
941
942
static bfd_boolean
943
 
944
{
945
  int sl;
946
 
947
  const char *hs = h->root.string;
948
949
  sl = strlen (string);
950
  if (h->type == bfd_link_hash_defined
951
      && ((*hs == '@' && *string == '_'
952
		   && strncmp (hs + 1, string + 1, sl - 1) == 0)
953
 
954
      && h->root.string[sl] == '@')
955
    {
956
      pe_undef_found_sym = h;
957
      return FALSE;
958
    }
959
  return TRUE;
960
}
961
962
static void
963
pe_fixup_stdcalls (void)
964
{
965
  static int gave_warning_message = 0;
966
 
967
968
  if (pe_dll_extra_pe_debug)
969
    printf ("%s\n", __FUNCTION__);
970
971
  for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
972
 
973
      {
974
	char* at = strchr (undef->root.string, '@');
975
 
976
	if (lead_at)
977
	  at = strchr (undef->root.string + 1, '@');
978
979
	if (at || lead_at)
980
	  {
981
	    /* The symbol is a stdcall symbol, so let's look for a
982
	       cdecl symbol with the same name and resolve to that.  */
983
 
984
985
	    if (lead_at)
986
	      *cname = '_';
987
	    at = strchr (cname, '@');
988
	    if (at)
989
 
990
	    sym = bfd_link_hash_lookup (link_info.hash, cname, 0, 0, 1);
991
992
	    if (sym && sym->type == bfd_link_hash_defined)
993
	      {
994
		undef->type = bfd_link_hash_defined;
995
		undef->u.def.value = sym->u.def.value;
996
 
997
998
		if (pe_enable_stdcall_fixup == -1)
999
		  {
1000
		    einfo (_("Warning: resolving %s by linking to %s\n"),
1001
			   undef->root.string, cname);
1002
 
1003
		      {
1004
			gave_warning_message = 1;
1005
			einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1006
			einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1007
		      }
1008
		  }
1009
	      }
1010
	  }
1011
	else
1012
	  {
1013
	    /* The symbol is a cdecl symbol, so we look for stdcall
1014
	       symbols - which means scanning the whole symbol table.  */
1015
	    pe_undef_found_sym = 0;
1016
	    bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
1017
				    (char *) undef->root.string);
1018
	    sym = pe_undef_found_sym;
1019
	    if (sym)
1020
	      {
1021
		undef->type = bfd_link_hash_defined;
1022
		undef->u.def.value = sym->u.def.value;
1023
		undef->u.def.section = sym->u.def.section;
1024
1025
		if (pe_enable_stdcall_fixup == -1)
1026
		  {
1027
		    einfo (_("Warning: resolving %s by linking to %s\n"),
1028
			   undef->root.string, sym->root.string);
1029
 
1030
		      {
1031
			gave_warning_message = 1;
1032
			einfo (_("Use --enable-stdcall-fixup to disable these warnings\n"));
1033
			einfo (_("Use --disable-stdcall-fixup to disable these fixups\n"));
1034
		      }
1035
		  }
1036
	      }
1037
	  }
1038
      }
1039
}
1040
1041
static int
1042
make_import_fixup (arelent *rel, asection *s)
1043
{
1044
  struct bfd_symbol *sym = *rel->sym_ptr_ptr;
1045
 
1046
1047
  if (pe_dll_extra_pe_debug)
1048
    printf ("arelent: %s@%#lx: add=%li\n", sym->name,
1049
	    (unsigned long) rel->address, (long) rel->addend);
1050
1051
 
1052
    einfo (_("%C: Cannot get section contents - auto-import exception\n"),
1053
	   s->owner, s, rel->address);
1054
1055
 
1056
1057
  return 1;
1058
}
1059
 
1060
static void
1061
 
1062
{
1063
  struct bfd_link_hash_entry *undef, *sym;
1064
 
1065
  if (link_info.pei386_auto_import == 0)
1066
    return;
1067
1068
  for (undef = link_info.hash->undefs; undef; undef=undef->u.undef.next)
1069
 
1070
      if (undef->type == bfd_link_hash_undefined)
1071
	{
1072
 
1073
	  char buf[4096];
1074
1075
	  if (pe_dll_extra_pe_debug)
1076
	    printf ("%s:%s\n", __FUNCTION__, undef->root.string);
1077
1078
	  sprintf (buf, "__imp_%s", undef->root.string);
1079
 
1080
	  sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
1081
1082
 
1083
	    {
1084
 
1085
	      asymbol **symbols;
1086
 
1087
1088
	      if (link_info.pei386_auto_import == -1)
1089
		{
1090
		  static bfd_boolean warned = FALSE;
1091
1092
 
1093
			    undef->root.string, buf);
1094
1095
		  /* PR linker/4844.  */
1096
 
1097
		    {
1098
		      warned = TRUE;
1099
 
1100
		    }
1101
		}
1102
1103
	      if (!bfd_generic_link_read_symbols (b))
1104
		{
1105
		  einfo (_("%B%F: could not read symbols: %E\n"), b);
1106
		  return;
1107
 
1108
1109
	      symbols = bfd_get_outsymbols (b);
1110
	      nsyms = bfd_get_symcount (b);
1111
1112
	      for (i = 0; i < nsyms; i++)
1113
 
1114
		  if (! CONST_STRNEQ (symbols[i]->name,
1115
				      U ("_head_")))
1116
 
1117
1118
		  if (pe_dll_extra_pe_debug)
1119
		    printf ("->%s\n", symbols[i]->name);
1120
1121
		  pe_data_import_dll = (char *) (symbols[i]->name
1122
 
1123
		  break;
1124
		}
1125
 
1126
	      pe_walk_relocs_of_symbol (&link_info, undef->root.string,
1127
					make_import_fixup);
1128
1129
	      /* Let's differentiate it somehow from defined.  */
1130
 
1131
	      /* We replace original name with __imp_ prefixed, this
1132
		 1) may trash memory 2) leads to duplicate symbol generation.
1133
 
1134
	      undef->root.string = sym->root.string;
1135
	      undef->u.def.value = sym->u.def.value;
1136
	      undef->u.def.section = sym->u.def.section;
1137
	    }
1138
	}
1139
    }
1140
}
1141
1142
static bfd_boolean
1143
pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
1144
{
1145
  printf ("+%s\n", h->string);
1146
 
1147
  return TRUE;
1148
}
1149
#endif /* DLL_SUPPORT */
1150
1151
 
1152
debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
1153
{
1154
  int *found = (int *) obj;
1155
 
1156
    *found = 1;
1157
}
1158
1159
static void
1160
gld_i386pe_after_open (void)
1161
{
1162
  after_open_default ();
1163
 
1164
#ifdef DLL_SUPPORT
1165
  if (pe_dll_extra_pe_debug)
1166
    {
1167
      bfd *a;
1168
 
1169
1170
      printf ("%s()\n", __FUNCTION__);
1171
1172
      for (sym = link_info.hash->undefs; sym; sym=sym->u.undef.next)
1173
	printf ("-%s\n", sym->root.string);
1174
 
1175
1176
 
1177
	printf ("*%s\n",a->filename);
1178
    }
1179
#endif
1180
 
1181
  /* Pass the wacky PE command line options into the output bfd.
1182
     FIXME: This should be done via a function, rather than by
1183
     including an internal BFD header.  */
1184
1185
 
1186
      || coff_data (link_info.output_bfd)->pe == 0)
1187
    einfo (_("%F%P: cannot perform PE operations on non PE output file '%B'.\n"),
1188
	   link_info.output_bfd);
1189
 
1190
  pe_data (link_info.output_bfd)->pe_opthdr = pe;
1191
  pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
1192
  pe_data (link_info.output_bfd)->real_flags |= real_flags;
1193
  pe_data (link_info.output_bfd)->insert_timestamp = insert_timestamp;
1194
 
1195
  /* At this point we must decide whether to use long section names
1196
     in the output or not.  If the user hasn't explicitly specified
1197
     on the command line, we leave it to the default for the format
1198
     (object files yes, image files no), except if there is debug
1199
 
1200
     find it, so enable it in that case.  */
1201
  if (pe_use_coff_long_section_names < 0 && link_info.strip == strip_none)
1202
    {
1203
      /* Iterate over all sections of all input BFDs, checking
1204
         for any that begin 'debug_' and are long names.  */
1205
      LANG_FOR_EACH_INPUT_STATEMENT (is)
1206
	{
1207
	  int found_debug = 0;
1208
	  bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
1209
	  if (found_debug)
1210
	    {
1211
	      pe_use_coff_long_section_names = 1;
1212
	      break;
1213
	    }
1214
	}
1215
    }
1216
1217
  pe_output_file_set_long_section_names (link_info.output_bfd);
1218
1219
#ifdef DLL_SUPPORT
1220
  if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
1221
 
1222
1223
 
1224
1225
  pe_find_data_imports ();
1226
1227
 
1228
     stdcall/fastcall fixup here.  */
1229
 
1230
    pe_fixup_stdcalls ();
1231
 
1232
#if defined (TARGET_IS_i386pe)     || defined (TARGET_IS_armpe)     || defined (TARGET_IS_arm_epoc_pe)     || defined (TARGET_IS_arm_wince_pe)
1233
  if (!link_info.relocatable)
1234
    pe_dll_build_sections (link_info.output_bfd, &link_info);
1235
#else
1236
 
1237
    pe_dll_build_sections (link_info.output_bfd, &link_info);
1238
  else
1239
    pe_exe_build_sections (link_info.output_bfd, &link_info);
1240
#endif
1241
#endif /* DLL_SUPPORT */
1242
1243
#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) || defined(TARGET_IS_arm_wince_pe)
1244
  if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL)
1245
    {
1246
      /* The arm backend needs special fields in the output hash structure.
1247
 
1248
	 hence we do not support linking and changing output formats at the
1249
	 same time.  Use a link followed by objcopy to change output formats.  */
1250
      einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
1251
      return;
1252
    }
1253
  {
1254
    /* Find a BFD that can hold the interworking stubs.  */
1255
    LANG_FOR_EACH_INPUT_STATEMENT (is)
1256
      {
1257
	if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
1258
	  break;
1259
      }
1260
  }
1261
#endif
1262
1263
  {
1264
    /* This next chunk of code tries to detect the case where you have
1265
       two import libraries for the same DLL (specifically,
1266
       symbolically linking libm.a and libc.a in cygwin to
1267
 
1268
       thunks from the second implib to be used but without the
1269
       head/tail objects, causing an improper import table.  We detect
1270
       those cases and rename the "other" import libraries to match
1271
       the one the head/tail come from, so that the linker will sort
1272
       things nicely and produce a valid import table.  */
1273
1274
    LANG_FOR_EACH_INPUT_STATEMENT (is)
1275
      {
1276
	if (is->the_bfd->my_archive)
1277
	  {
1278
 
1279
	    asection *sec;
1280
1281
	    /* See if this is an import library thunk.  */
1282
	    for (sec = is->the_bfd->sections; sec; sec = sec->next)
1283
	      {
1284
		if (strcmp (sec->name, ".idata$2") == 0)
1285
 
1286
		if (CONST_STRNEQ (sec->name, ".idata$"))
1287
		  is_imp = 1;
1288
		reloc_count += sec->reloc_count;
1289
	      }
1290
1291
	    if (is_imp && !idata2 && reloc_count)
1292
	      {
1293
		/* It is, look for the reference to head and see if it's
1294
		   from our own library.  */
1295
 
1296
		  {
1297
		    int i;
1298
		    long relsize;
1299
		    asymbol **symbols;
1300
		    arelent **relocs;
1301
		    int nrelocs;
1302
1303
		    relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
1304
		    if (relsize < 1)
1305
		      break;
1306
1307
 
1308
		      {
1309
			einfo (_("%B%F: could not read symbols: %E\n"),
1310
			       is->the_bfd);
1311
 
1312
		      }
1313
		    symbols = bfd_get_outsymbols (is->the_bfd);
1314
1315
		    relocs = xmalloc ((size_t) relsize);
1316
		    nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
1317
						      relocs, symbols);
1318
		    if (nrelocs < 0)
1319
 
1320
			free (relocs);
1321
			einfo ("%X%P: unable to process relocs: %E\n");
1322
			return;
1323
		      }
1324
1325
		    for (i = 0; i < nrelocs; i++)
1326
		      {
1327
			struct bfd_symbol *s;
1328
			struct bfd_link_hash_entry * blhe;
1329
 
1330
			char *n;
1331
1332
			s = (relocs[i]->sym_ptr_ptr)[0];
1333
1334
			if (s->flags & BSF_LOCAL)
1335
			  continue;
1336
 
1337
			/* Thunk section with reloc to another bfd.  */
1338
 
1339
						     s->name,
1340
						     FALSE, FALSE, TRUE);
1341
 
1342
			if (blhe == NULL
1343
			    || blhe->type != bfd_link_hash_defined)
1344
			  continue;
1345
1346
 
1347
			  = blhe->u.def.section->owner->my_archive
1348
			    ? bfd_get_filename (blhe->u.def.section->owner->my_archive)
1349
			    : bfd_get_filename (blhe->u.def.section->owner);
1350
 
1351
			if (filename_cmp (bfd_get_filename
1352
					    (is->the_bfd->my_archive),
1353
					  other_bfd_filename) == 0)
1354
			  continue;
1355
 
1356
			/* Rename this implib to match the other one.  */
1357
			n = xmalloc (strlen (other_bfd_filename) + 1);
1358
			strcpy (n, other_bfd_filename);
1359
			is->the_bfd->my_archive->filename = n;
1360
 
1361
1362
		    free (relocs);
1363
		    /* Note - we do not free the symbols,
1364
		       they are now cached in the BFD.  */
1365
		  }
1366
 
1367
	  }
1368
      }
1369
  }
1370
1371
  {
1372
    int is_ms_arch = 0;
1373
    bfd *cur_arch = 0;
1374
    lang_input_statement_type *is2;
1375
 
1376
1377
    /* Careful - this is a shell script.  Watch those dollar signs! */
1378
    /* Microsoft import libraries have every member named the same,
1379
       and not in the right order for us to link them correctly.  We
1380
       must detect these and rename the members so that they'll link
1381
 
1382
       thunks, and the sentinel(s).  The head is easy; it's the one
1383
       with idata2.  We assume that the sentinels won't have relocs,
1384
       and the thunks will.  It's easier than checking the symbol
1385
       table for external references.  */
1386
    LANG_FOR_EACH_INPUT_STATEMENT (is)
1387
      {
1388
	if (is->the_bfd->my_archive)
1389
	  {
1390
	    char *pnt;
1391
	    bfd *arch = is->the_bfd->my_archive;
1392
1393
	    if (cur_arch != arch)
1394
	      {
1395
		cur_arch = arch;
1396
		is_ms_arch = 1;
1397
 
1398
		for (is3 = is;
1399
		     is3 && is3->the_bfd->my_archive == arch;
1400
		     is3 = (lang_input_statement_type *) is3->next)
1401
		  {
1402
 
1403
		       members, so look for the first element with a .dll
1404
		       extension, and use that for the remainder of the
1405
		       comparisons.  */
1406
		    pnt = strrchr (is3->the_bfd->filename, '.');
1407
		    if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
1408
		      break;
1409
		  }
1410
1411
		if (is3 == NULL)
1412
		  is_ms_arch = 0;
1413
		else
1414
		  {
1415
 
1416
		       (dynamic import) members use the same name.  */
1417
		    for (is2 = is;
1418
			 is2 && is2->the_bfd->my_archive == arch;
1419
			 is2 = (lang_input_statement_type *) is2->next)
1420
		      {
1421
			/* Skip static members, ie anything with a .obj
1422
			   extension.  */
1423
			pnt = strrchr (is2->the_bfd->filename, '.');
1424
			if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
1425
			  continue;
1426
1427
			if (filename_cmp (is3->the_bfd->filename,
1428
					  is2->the_bfd->filename))
1429
			  {
1430
			    is_ms_arch = 0;
1431
 
1432
			  }
1433
		      }
1434
		  }
1435
	      }
1436
1437
	    /* This fragment might have come from an .obj file in a Microsoft
1438
	       import, and not an actual import record. If this is the case,
1439
	       then leave the filename alone.  */
1440
	    pnt = strrchr (is->the_bfd->filename, '.');
1441
 
1442
	    if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
1443
	      {
1444
		int idata2 = 0, reloc_count=0;
1445
		asection *sec;
1446
 
1447
1448
		for (sec = is->the_bfd->sections; sec; sec = sec->next)
1449
		  {
1450
		    if (strcmp (sec->name, ".idata$2") == 0)
1451
		      idata2 = 1;
1452
 
1453
		  }
1454
1455
		if (idata2) /* .idata2 is the TOC */
1456
		  seq = 'a';
1457
		else if (reloc_count > 0) /* thunks */
1458
		  seq = 'b';
1459
 
1460
		  seq = 'c';
1461
1462
		new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
1463
		sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
1464
		is->the_bfd->filename = new_name;
1465
1466
 
1467
		sprintf (new_name, "%s.%c", is->filename, seq);
1468
		is->filename = new_name;
1469
	      }
1470
 
1471
      }
1472
  }
1473
1474
  {
1475
    /* The following chunk of code tries to identify jump stubs in
1476
       import libraries which are dead code and eliminates them
1477
       from the final link. For each exported symbol , there
1478
 
1479
       and several .idata$* sections. The .text section contains the
1480
       symbol definition for  which is a jump stub of the form
1481
       jmp *__imp_. The .idata$5 contains the symbol definition
1482
       for __imp_ which is the address of the slot for  in
1483
       the import address table. When a symbol is imported explicitly
1484
       using __declspec(dllimport) declaration, the compiler generates
1485
       a reference to __imp_ which directly resolves to the
1486
       symbol in .idata$5, in which case the jump stub code is not
1487
       needed. The following code tries to identify jump stub sections
1488
       in import libraries which are not referred to by anyone and
1489
       marks them for exclusion from the final link.  */
1490
    LANG_FOR_EACH_INPUT_STATEMENT (is)
1491
      {
1492
	if (is->the_bfd->my_archive)
1493
	  {
1494
	    int is_imp = 0;
1495
	    asection *sec, *stub_sec = NULL;
1496
1497
	    /* See if this is an import library thunk.  */
1498
	    for (sec = is->the_bfd->sections; sec; sec = sec->next)
1499
	      {
1500
		if (strncmp (sec->name, ".idata$", 7) == 0)
1501
 
1502
		/* The section containing the jmp stub has code
1503
		   and has a reloc.  */
1504
		if ((sec->flags & SEC_CODE) && sec->reloc_count)
1505
		  stub_sec = sec;
1506
	      }
1507
1508
	    if (is_imp && stub_sec)
1509
	      {
1510
		asymbol **symbols;
1511
		long nsyms, src_count;
1512
 
1513
1514
		if (!bfd_generic_link_read_symbols (is->the_bfd))
1515
		  {
1516
		    einfo (_("%B%F: could not read symbols: %E\n"),
1517
			   is->the_bfd);
1518
 
1519
		  }
1520
		symbols = bfd_get_outsymbols (is->the_bfd);
1521
		nsyms = bfd_get_symcount (is->the_bfd);
1522
1523
		for (src_count = 0; src_count < nsyms; src_count++)
1524
		  {
1525
		    if (symbols[src_count]->section->id == stub_sec->id)
1526
		      {
1527
 
1528
			   the stub.  */
1529
			blhe = bfd_link_hash_lookup (link_info.hash,
1530
						     symbols[src_count]->name,
1531
						     FALSE, FALSE, TRUE);
1532
			/* If the symbol in the stub section has no other
1533
			   undefined references, exclude the stub section
1534
			   from the final link.  */
1535
			if (blhe != NULL
1536
			    && blhe->type == bfd_link_hash_defined
1537
			    && blhe->u.undef.next == NULL
1538
			    && blhe != link_info.hash->undefs_tail)
1539
			  stub_sec->flags |= SEC_EXCLUDE;
1540
		      }
1541
		  }
1542
	      }
1543
	  }
1544
      }
1545
  }
1546
}
1547

1548
static void
1549
gld_i386pe_before_allocation (void)
1550
{
1551
#ifdef TARGET_IS_ppcpe
1552
 
1553
  {
1554
    LANG_FOR_EACH_INPUT_STATEMENT (is)
1555
      {
1556
	if (!ppc_process_before_allocation (is->the_bfd, &link_info))
1557
	  {
1558
	    /* xgettext:c-format */
1559
	    einfo (_("Errors encountered processing file %s\n"), is->filename);
1560
	  }
1561
      }
1562
  }
1563
1564
  /* We have seen it all. Allocate it, and carry on.  */
1565
  ppc_allocate_toc_section (&link_info);
1566
#endif /* TARGET_IS_ppcpe */
1567
1568
 
1569
  /* FIXME: we should be able to set the size of the interworking stub
1570
     section.
1571
1572
 
1573
     information.  FIXME: should this be based on a command line
1574
     option?  krk@cygnus.com.  */
1575
  {
1576
 
1577
      {
1578
	if (! bfd_arm_process_before_allocation
1579
	    (is->the_bfd, & link_info, support_old_code))
1580
	  {
1581
	    /* xgettext:c-format */
1582
	    einfo (_("Errors encountered processing file %s for interworking\n"),
1583
		   is->filename);
1584
	  }
1585
      }
1586
  }
1587
1588
  /* We have seen it all. Allocate it, and carry on.  */
1589
  bfd_arm_allocate_interworking_sections (& link_info);
1590
#endif /* TARGET_IS_armpe || TARGET_IS_arm_epoc_pe || TARGET_IS_arm_wince_pe */
1591
1592
 
1593
}
1594

1595
#ifdef DLL_SUPPORT
1596
 
1597
   check here for .DEF files and pull them in automatically.  */
1598
1599
 
1600
saw_option (char *option)
1601
{
1602
  int i;
1603
 
1604
  for (i = 0; init[i].ptr; i++)
1605
    if (strcmp (GET_INIT_SYMBOL_NAME (i), option) == 0)
1606
      return init[i].inited;
1607
  return 0;
1608
 
1609
#endif /* DLL_SUPPORT */
1610
1611
static bfd_boolean
1612
gld_i386pe_unrecognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1613
{
1614
#ifdef DLL_SUPPORT
1615
 
1616
1617
  if (filename_cmp (ext, ".def") == 0 || filename_cmp (ext, ".DEF") == 0)
1618
    {
1619
      pe_def_file = def_file_parse (entry->filename, pe_def_file);
1620
1621
 
1622
	{
1623
	  int i, buflen=0, len;
1624
	  char *buf;
1625
 
1626
	  for (i = 0; i < pe_def_file->num_exports; i++)
1627
	    {
1628
	      len = strlen (pe_def_file->exports[i].internal_name);
1629
	      if (buflen < len + 2)
1630
 
1631
	    }
1632
1633
	  buf = xmalloc (buflen);
1634
1635
	  for (i = 0; i < pe_def_file->num_exports; i++)
1636
	    {
1637
 
1638
1639
 
1640
	               pe_def_file->exports[i].internal_name);
1641
1642
	      h = bfd_link_hash_lookup (link_info.hash, buf, TRUE, TRUE, TRUE);
1643
 
1644
		einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1645
	      if (h->type == bfd_link_hash_new)
1646
 
1647
		  h->type = bfd_link_hash_undefined;
1648
		  h->u.undef.abfd = NULL;
1649
		  bfd_link_add_undef (link_info.hash, h);
1650
		}
1651
	    }
1652
	  free (buf);
1653
1654
	  /* def_file_print (stdout, pe_def_file); */
1655
	  if (pe_def_file->is_dll == 1)
1656
	    link_info.shared = 1;
1657
1658
 
1659
	    {
1660
	      pe.ImageBase
1661
		= pe_data (link_info.output_bfd)->pe_opthdr.ImageBase
1662
 
1663
		= pe_def_file->base_address;
1664
	      init[IMAGEBASEOFF].inited = 1;
1665
	      if (image_base_statement)
1666
		image_base_statement->exp
1667
		  = exp_assign ("__image_base__", exp_intop (pe.ImageBase),
1668
				FALSE);
1669
	    }
1670
1671
	  if (pe_def_file->stack_reserve != -1
1672
	      && ! saw_option ("__size_of_stack_reserve__"))
1673
	    {
1674
	      pe.SizeOfStackReserve = pe_def_file->stack_reserve;
1675
 
1676
		pe.SizeOfStackCommit = pe_def_file->stack_commit;
1677
	    }
1678
	  if (pe_def_file->heap_reserve != -1
1679
	      && ! saw_option ("__size_of_heap_reserve__"))
1680
	    {
1681
	      pe.SizeOfHeapReserve = pe_def_file->heap_reserve;
1682
	      if (pe_def_file->heap_commit != -1)
1683
		pe.SizeOfHeapCommit = pe_def_file->heap_commit;
1684
	    }
1685
	  return TRUE;
1686
	}
1687
    }
1688
#endif
1689
  return FALSE;
1690
}
1691
1692
static bfd_boolean
1693
gld_i386pe_recognized_file (lang_input_statement_type *entry ATTRIBUTE_UNUSED)
1694
{
1695
#ifdef DLL_SUPPORT
1696
 
1697
  pe_dll_id_target ("pei-i386");
1698
#endif
1699
#ifdef TARGET_IS_shpe
1700
  pe_dll_id_target ("pei-shl");
1701
#endif
1702
#ifdef TARGET_IS_armpe
1703
  pe_dll_id_target ("pei-arm-little");
1704
#endif
1705
#ifdef TARGET_IS_arm_epoc_pe
1706
  pe_dll_id_target ("epoc-pei-arm-little");
1707
#endif
1708
#ifdef TARGET_IS_arm_wince_pe
1709
  pe_dll_id_target ("pei-arm-wince-little");
1710
#endif
1711
  if (pe_bfd_is_dll (entry->the_bfd))
1712
    return pe_implied_import_dll (entry->filename);
1713
#endif
1714
  return FALSE;
1715
}
1716
1717
static void
1718
gld_i386pe_finish (void)
1719
{
1720
#if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) || defined(TARGET_IS_arm_wince_pe)
1721
 
1722
1723
  if (thumb_entry_symbol != NULL)
1724
    {
1725
      h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
1726
				FALSE, FALSE, TRUE);
1727
 
1728
      if (h != (struct bfd_link_hash_entry *) NULL
1729
	  && (h->type == bfd_link_hash_defined
1730
	      || h->type == bfd_link_hash_defweak)
1731
	  && h->u.def.section->output_section != NULL)
1732
 
1733
	  static char buffer[32];
1734
	  bfd_vma val;
1735
1736
	  /* Special procesing is required for a Thumb entry symbol.  The
1737
	     bottom bit of its address must be set.  */
1738
	  val = (h->u.def.value
1739
		 + bfd_get_section_vma (link_info.output_bfd,
1740
 
1741
		 + h->u.def.section->output_offset);
1742
1743
	  val |= 1;
1744
1745
	  /* Now convert this value into a string and store it in entry_symbol
1746
	     where the lang_finish() function will pick it up.  */
1747
 
1748
	  buffer[1] = 'x';
1749
 
1750
	  sprintf_vma (buffer + 2, val);
1751
1752
	  if (entry_symbol.name != NULL && entry_from_cmdline)
1753
	    einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
1754
 
1755
	  entry_symbol.name = buffer;
1756
 
1757
      else
1758
	einfo (_("%P: warning: cannot find thumb start symbol %s\n"), thumb_entry_symbol);
1759
    }
1760
#endif /* defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_epoc_pe) || defined(TARGET_IS_arm_wince_pe) */
1761
1762
  finish_default ();
1763
1764
#ifdef DLL_SUPPORT
1765
  if (link_info.shared
1766
 
1767
      || (!link_info.relocatable && pe_def_file->num_exports != 0)
1768
 
1769
    )
1770
    {
1771
      pe_dll_fill_sections (link_info.output_bfd, &link_info);
1772
      if (pe_implib_filename)
1773
	pe_dll_generate_implib (pe_def_file, pe_implib_filename, &link_info);
1774
    }
1775
#if defined(TARGET_IS_shpe)
1776
  /* ARM doesn't need relocs.  */
1777
  else
1778
    {
1779
      pe_exe_fill_sections (link_info.output_bfd, &link_info);
1780
    }
1781
#endif
1782
1783
  if (pe_out_def_filename)
1784
    pe_dll_generate_def_file (pe_out_def_filename);
1785
#endif /* DLL_SUPPORT */
1786
1787
 
1788
  {
1789
    asection *asec = bfd_get_section_by_name (link_info.output_bfd, ".idata");
1790
1791
 
1792
      {
1793
	asec->flags &= ~SEC_CODE;
1794
	asec->flags |= SEC_DATA;
1795
 
1796
  }
1797
}
1798
1799

1800
/* Place an orphan section.
1801
1802
   We use this to put sections in a reasonable place in the file, and
1803
 
1804
 
1805
   We handle grouped sections here as well.  A section named .foo$nn
1806
 
1807
   by name.
1808
1809
 
1810
   default linker script using wildcards, and are sorted by
1811
   sort_sections.  */
1812
1813
 
1814
gld_i386pe_place_orphan (asection *s,
1815
				    const char *secname,
1816
				    int constraint)
1817
 
1818
  const char *orig_secname = secname;
1819
  char *dollar = NULL;
1820
  lang_output_section_statement_type *os;
1821
  lang_statement_list_type add_child;
1822
  lang_output_section_statement_type *match_by_name = NULL;
1823
  lang_statement_union_type **pl;
1824
1825
  /* Look through the script to see where to place this section.  */
1826
  if (!link_info.relocatable
1827
      && (dollar = strchr (secname, '$')) != NULL)
1828
    {
1829
 
1830
      char *newname = xmalloc (len + 1);
1831
      memcpy (newname, secname, len);
1832
      newname[len] = '\0';
1833
      secname = newname;
1834
    }
1835
1836
  lang_list_init (&add_child);
1837
1838
  os = NULL;
1839
  if (constraint == 0)
1840
 
1841
	 os != NULL;
1842
 
1843
      {
1844
	/* If we don't match an existing output section, tell
1845
	   lang_insert_orphan to create a new output section.  */
1846
	constraint = SPECIAL;
1847
1848
	if (os->bfd_section != NULL
1849
	    && (os->bfd_section->flags == 0
1850
		|| ((s->flags ^ os->bfd_section->flags)
1851
		    & (SEC_LOAD | SEC_ALLOC)) == 0))
1852
 
1853
	    /* We already have an output section statement with this
1854
	       name, and its bfd section has compatible flags.
1855
	       If the section already exists but does not have any flags set,
1856
	       then it has been created by the linker, probably as a result of
1857
	       a --section-start command line switch.  */
1858
	    lang_add_section (&add_child, s, NULL, os);
1859
	    break;
1860
	  }
1861
1862
	/* Save unused output sections in case we can match them
1863
	   against orphans later.  */
1864
	if (os->bfd_section == NULL)
1865
	  match_by_name = os;
1866
 
1867
1868
  /* If we didn't match an active output section, see if we matched an
1869
     unused one and use that.  */
1870
  if (os == NULL && match_by_name)
1871
    {
1872
 
1873
      return match_by_name;
1874
    }
1875
1876
  if (os == NULL)
1877
    {
1878
      static struct orphan_save hold[] =
1879
	{
1880
 
1881
	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1882
	    0, 0, 0, 0 },
1883
	  { ".idata",
1884
	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1885
	    0, 0, 0, 0 },
1886
	  { ".rdata",
1887
	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1888
	    0, 0, 0, 0 },
1889
	  { ".data",
1890
	    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1891
	    0, 0, 0, 0 },
1892
	  { ".bss",
1893
	    SEC_ALLOC,
1894
	    0, 0, 0, 0 }
1895
	};
1896
      enum orphan_save_index
1897
	{
1898
	  orphan_text = 0,
1899
	  orphan_idata,
1900
	  orphan_rodata,
1901
	  orphan_data,
1902
	  orphan_bss
1903
	};
1904
      static int orphan_init_done = 0;
1905
      struct orphan_save *place;
1906
      lang_output_section_statement_type *after;
1907
      etree_type *address;
1908
1909
      if (!orphan_init_done)
1910
	{
1911
	  struct orphan_save *ho;
1912
	  for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
1913
 
1914
	      {
1915
		ho->os = lang_output_section_find (ho->name);
1916
		if (ho->os != NULL && ho->os->flags == 0)
1917
		  ho->os->flags = ho->flags;
1918
	      }
1919
	  orphan_init_done = 1;
1920
	}
1921
1922
      /* Try to put the new output section in a reasonable place based
1923
	 on the section name and section flags.  */
1924
1925
      place = NULL;
1926
 
1927
	;
1928
      else if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
1929
 
1930
      else if ((s->flags & SEC_READONLY) == 0)
1931
	place = &hold[orphan_data];
1932
      else if ((s->flags & SEC_CODE) == 0)
1933
	{
1934
	  place = (!strncmp (secname, ".idata$", 7) ? &hold[orphan_idata]
1935
						     : &hold[orphan_rodata]);
1936
	}
1937
      else
1938
	place = &hold[orphan_text];
1939
1940
      after = NULL;
1941
      if (place != NULL)
1942
	{
1943
	  if (place->os == NULL)
1944
 
1945
	  after = place->os;
1946
	  if (after == NULL)
1947
	    after = lang_output_section_find_by_flags (s, &place->os, NULL);
1948
	  if (after == NULL)
1949
	    /* *ABS* is always the first output section statement.  */
1950
	    after = (&lang_output_section_statement.head
1951
		     ->output_section_statement);
1952
	}
1953
1954
      /* All sections in an executable must be aligned to a page boundary.
1955
	 In a relocatable link, just preserve the incoming alignment; the
1956
	 address is discarded by lang_insert_orphan in that case, anyway.  */
1957
      address = exp_unop (ALIGN_K, exp_nameop (NAME, "__section_alignment__"));
1958
 
1959
			       &add_child);
1960
      if (link_info.relocatable)
1961
	{
1962
	  os->section_alignment = s->alignment_power;
1963
	  os->bfd_section->alignment_power = s->alignment_power;
1964
	}
1965
    }
1966
1967
  /* If the section name has a '$', sort it with the other '$'
1968
     sections.  */
1969
  for (pl = &os->children.head; *pl != NULL; pl = &(*pl)->header.next)
1970
    {
1971
 
1972
      const char *lname;
1973
1974
      if ((*pl)->header.type != lang_input_section_enum)
1975
	continue;
1976
1977
      ls = &(*pl)->input_section;
1978
 
1979
      lname = bfd_get_section_name (ls->section->owner, ls->section);
1980
      if (strchr (lname, '$') != NULL
1981
 
1982
	break;
1983
 
1984
1985
  if (add_child.head != NULL)
1986
    {
1987
      *add_child.tail = *pl;
1988
      *pl = add_child.head;
1989
 
1990
1991
  return os;
1992
}
1993
1994
static bfd_boolean
1995
 
1996
  (const char *arch ATTRIBUTE_UNUSED,
1997
   search_dirs_type *search,
1998
 
1999
{
2000
  static const struct
2001
    {
2002
      const char * format;
2003
      bfd_boolean use_prefix;
2004
    }
2005
  libname_fmt [] =
2006
    {
2007
      /* Preferred explicit import library for dll's.  */
2008
      { "lib%s.dll.a", FALSE },
2009
      /* Alternate explicit import library for dll's.  */
2010
      { "%s.dll.a", FALSE },
2011
      /* "libfoo.a" could be either an import lib or a static lib.
2012
          For backwards compatibility, libfoo.a needs to precede
2013
          libfoo.dll and foo.dll in the search.  */
2014
      { "lib%s.a", FALSE },
2015
      /* The 'native' spelling of an import lib name is "foo.lib".  */
2016
      { "%s.lib", FALSE },
2017
#ifdef DLL_SUPPORT
2018
      /* Try "foo.dll" (preferred dll name, if specified).  */
2019
      {	"%s%s.dll", TRUE },
2020
#endif
2021
      /* Try "libfoo.dll" (default preferred dll name).  */
2022
      {	"lib%s.dll", FALSE },
2023
      /* Finally try 'native' dll name "foo.dll".  */
2024
      {  "%s.dll", FALSE },
2025
      /* Note: If adding more formats to this table, make sure to check to
2026
	 see if their length is longer than libname_fmt[0].format, and if
2027
	 so, update the call to xmalloc() below.  */
2028
      { NULL, FALSE }
2029
    };
2030
  static unsigned int format_max_len = 0;
2031
  const char * filename;
2032
  char * full_string;
2033
  char * base_string;
2034
  unsigned int i;
2035
2036
2037
  if (! entry->flags.maybe_archive)
2038
    return FALSE;
2039
2040
 
2041
 
2042
  if (format_max_len == 0)
2043
    /* We need to allow space in the memory that we are going to allocate
2044
 
2045
       static we only need to calculate this information once.  In theory
2046
 
2047
       the possibility for a discrepancy and hence a possible memory
2048
       corruption.  The lengths we compute here will be too long because
2049
       they will include any formating characters (%s) in the strings, but
2050
       this will not matter.  */
2051
    for (i = 0; libname_fmt[i].format; i++)
2052
      if (format_max_len < strlen (libname_fmt[i].format))
2053
	format_max_len = strlen (libname_fmt[i].format);
2054
2055
  full_string = xmalloc (strlen (search->name)
2056
			 + strlen (filename)
2057
			 + format_max_len
2058
#ifdef DLL_SUPPORT
2059
 
2060
			    ? strlen (pe_dll_search_prefix) : 0)
2061
#endif
2062
			 /* Allow for the terminating NUL and for the path
2063
			    separator character that is inserted between
2064
			    search->name and the start of the format string.  */
2065
			 + 2);
2066
2067
  sprintf (full_string, "%s/", search->name);
2068
  base_string = full_string + strlen (full_string);
2069
2070
  for (i = 0; libname_fmt[i].format; i++)
2071
 
2072
#ifdef DLL_SUPPORT
2073
      if (libname_fmt[i].use_prefix)
2074
 
2075
	  if (!pe_dll_search_prefix)
2076
	    continue;
2077
	  sprintf (base_string, libname_fmt[i].format, pe_dll_search_prefix, filename);
2078
	}
2079
      else
2080
#endif
2081
	sprintf (base_string, libname_fmt[i].format, filename);
2082
2083
      if (ldfile_try_open_bfd (full_string, entry))
2084
	break;
2085
    }
2086
2087
 
2088
    {
2089
      free (full_string);
2090
      return FALSE;
2091
 
2092
2093
  entry->filename = full_string;
2094
2095
  return TRUE;
2096
}
2097
 
2098
static int
2099
 
2100
  (char *name, lang_input_statement_type *entry)
2101
{
2102
 
2103
}
2104

2105
static char *
2106
gld_i386pe_get_script (int *isfile)
2107
{
2108
  *isfile = 0;
2109
 
2110
  if (link_info.relocatable && config.build_constructors)
2111
    return
2112
"/* Script for ld -Ur: link w/out relocation, do create constructors */\n\
2113
OUTPUT_FORMAT(pe-i386)\n\
2114
 
2115
SECTIONS\n\
2116
{\n\
2117
  .text  :\n\
2118
  {\n\
2119
    *(.text)\n\
2120
    *(.glue_7t)\n\
2121
    *(.glue_7)\n\
2122
     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;\n\
2123
			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);\n\
2124
     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;\n\
2125
			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);\n\
2126
    /* ??? Why is .gcc_exc here?  */\n\
2127
  }\n\
2128
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
2129
     on fork.  This used to be named \".data\".  The linker used\n\
2130
     to include this between __data_start__ and __data_end__, but that\n\
2131
     breaks building the cygwin32 dll.  Instead, we name the section\n\
2132
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
2133
  .data  :\n\
2134
  {\n\
2135
    *(.data)\n\
2136
    *(.data2)\n"
2137
"    *(.jcr)\n\
2138
  }\n\
2139
  .rdata  :\n\
2140
  {\n\
2141
    *(.rdata)\n\
2142
    *(.rdata_runtime_pseudo_reloc)\n\
2143
  }\n\
2144
  .eh_frame  :\n\
2145
  {\n\
2146
    *(.eh_frame*)\n\
2147
  }\n\
2148
  .pdata  :\n\
2149
  {\n\
2150
    *(.pdata)\n\
2151
  }\n\
2152
  .bss  :\n\
2153
  {\n\
2154
    *(.bss)\n\
2155
    *(COMMON)\n\
2156
  }\n\
2157
  .edata  :\n\
2158
  {\n\
2159
    *(.edata)\n\
2160
  }\n\
2161
  /DISCARD/ :\n"
2162
"  {\n\
2163
    *(.debug$S)\n\
2164
    *(.debug$T)\n\
2165
    *(.debug$F)\n\
2166
    *(.drectve)\n\
2167
  }\n\
2168
  .idata  :\n\
2169
  {\n\
2170
    /* This cannot currently be handled with grouped sections.\n\
2171
	See pe.em:sort_sections.  */\n\
2172
  }\n\
2173
  .CRT  :\n\
2174
  {\n\
2175
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
2176
  }\n\
2177
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
2178
     at the end of section.  This is important because _tls_start MUST\n\
2179
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
2180
     data.  */\n\
2181
  .tls  :\n\
2182
  {\n\
2183
  }\n\
2184
  .endjunk  :\n\
2185
  {\n\
2186
    /* end is deprecated, don't use it */\n"
2187
"  }\n\
2188
  .rsrc  :\n\
2189
  {\n\
2190
    *(.rsrc)\n\
2191
  }\n\
2192
  .reloc  :\n\
2193
  {\n\
2194
    *(.reloc)\n\
2195
  }\n\
2196
  .stab   :\n\
2197
  {\n\
2198
    *(.stab)\n\
2199
  }\n\
2200
  .stabstr   :\n\
2201
  {\n\
2202
    *(.stabstr)\n\
2203
  }\n\
2204
  /* DWARF debug sections.\n\
2205
     Symbols in the DWARF debugging sections are relative to the beginning\n\
2206
     of the section.  Unlike other targets that fake this by putting the\n\
2207
     section VMA at 0, the PE format will not allow it.  */\n\
2208
  /* DWARF 1.1 and DWARF 2.  */\n\
2209
  .debug_aranges   :\n\
2210
  {\n\
2211
    *(.debug_aranges)\n"
2212
"  }\n\
2213
  .zdebug_aranges   :\n\
2214
  {\n\
2215
    *(.zdebug_aranges)\n\
2216
  }\n\
2217
  .debug_pubnames   :\n\
2218
  {\n\
2219
    *(.debug_pubnames)\n\
2220
  }\n\
2221
  .zdebug_pubnames   :\n\
2222
  {\n\
2223
    *(.zdebug_pubnames)\n\
2224
  }\n\
2225
  .debug_pubtypes   :\n\
2226
  {\n\
2227
    *(.debug_pubtypes)\n\
2228
  }\n\
2229
  .zdebug_pubtypes   :\n\
2230
  {\n\
2231
    *(.zdebug_pubtypes)\n\
2232
  }\n\
2233
  /* DWARF 2.  */\n\
2234
  .debug_info   :\n\
2235
  {\n\
2236
    *(.debug_info)\n\
2237
  }\n\
2238
  .zdebug_info   :\n\
2239
  {\n\
2240
    *(.zdebug_info)\n\
2241
  }\n\
2242
  .debug_abbrev   :\n\
2243
  {\n\
2244
    *(.debug_abbrev)\n\
2245
  }\n\
2246
  .zdebug_abbrev   :\n\
2247
  {\n\
2248
    *(.zdebug_abbrev)\n\
2249
  }\n\
2250
  .debug_line   :\n\
2251
  {\n\
2252
    *(.debug_line)\n\
2253
  }\n\
2254
  .zdebug_line   :\n\
2255
  {\n\
2256
    *(.zdebug_line)\n\
2257
  }\n\
2258
  .debug_frame   :\n\
2259
  {\n\
2260
    *(.debug_frame*)\n\
2261
  }\n\
2262
  .zdebug_frame   :\n\
2263
  {\n\
2264
    *(.zdebug_frame*)\n\
2265
  }\n\
2266
  .debug_str   :\n\
2267
  {\n\
2268
    *(.debug_str)\n\
2269
  }\n\
2270
  .zdebug_str   :\n\
2271
  {\n\
2272
    *(.zdebug_str)\n\
2273
  }\n\
2274
  .debug_loc   :\n\
2275
  {\n\
2276
    *(.debug_loc)\n\
2277
  }\n\
2278
  .zdebug_loc   :\n\
2279
  {\n\
2280
    *(.zdebug_loc)\n\
2281
  }\n\
2282
  .debug_macinfo   :\n\
2283
  {\n\
2284
    *(.debug_macinfo)\n\
2285
  }\n\
2286
  .zdebug_macinfo   :\n\
2287
  {\n\
2288
    *(.zdebug_macinfo)\n\
2289
  }\n\
2290
  /* SGI/MIPS DWARF 2 extensions.  */\n\
2291
  .debug_weaknames   :\n\
2292
  {\n\
2293
    *(.debug_weaknames)\n\
2294
  }\n\
2295
  .zdebug_weaknames   :\n\
2296
  {\n\
2297
    *(.zdebug_weaknames)\n\
2298
  }\n\
2299
  .debug_funcnames   :\n\
2300
  {\n\
2301
    *(.debug_funcnames)\n\
2302
  }\n\
2303
  .zdebug_funcnames   :\n\
2304
  {\n\
2305
    *(.zdebug_funcnames)\n\
2306
  }\n\
2307
  .debug_typenames   :\n\
2308
  {\n\
2309
    *(.debug_typenames)\n\
2310
  }\n\
2311
  .zdebug_typenames   :\n\
2312
  {\n\
2313
    *(.zdebug_typenames)\n\
2314
  }\n\
2315
  .debug_varnames   :\n\
2316
  {\n\
2317
    *(.debug_varnames)\n\
2318
  }\n\
2319
  .zdebug_varnames   :\n\
2320
  {\n\
2321
    *(.zdebug_varnames)\n\
2322
  }\n\
2323
  .debug_macro   :\n\
2324
  {\n\
2325
    *(.debug_macro)\n\
2326
  }\n\
2327
  .zdebug_macro   :\n\
2328
  {\n\
2329
    *(.zdebug_macro)\n\
2330
  }\n\
2331
  /* DWARF 3.  */\n\
2332
  .debug_ranges   :\n\
2333
  {\n\
2334
    *(.debug_ranges)\n\
2335
  }\n\
2336
  .zdebug_ranges   :\n\
2337
  {\n\
2338
    *(.zdebug_ranges)\n\
2339
  }\n\
2340
  /* DWARF 4.  */\n\
2341
  .debug_types   :\n\
2342
  {\n\
2343
    *(.debug_types)\n\
2344
  }\n\
2345
  .zdebug_types   :\n\
2346
  {\n\
2347
    *(.zdebug_types)\n\
2348
  }\n\
2349
}\n\n"
2350
  ; else if (link_info.relocatable) return
2351
"/* Script for ld -r: link without relocation */\n\
2352
OUTPUT_FORMAT(pe-i386)\n\
2353
SEARCH_DIR(\"=/usr/local/lib\"); SEARCH_DIR(\"=/lib\"); SEARCH_DIR(\"=/usr/lib\");\n\
2354
SECTIONS\n\
2355
{\n\
2356
  .text  :\n\
2357
  {\n\
2358
    *(.text)\n\
2359
    *(.glue_7t)\n\
2360
    *(.glue_7)\n\
2361
    /* ??? Why is .gcc_exc here?  */\n\
2362
  }\n\
2363
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
2364
     on fork.  This used to be named \".data\".  The linker used\n\
2365
     to include this between __data_start__ and __data_end__, but that\n\
2366
     breaks building the cygwin32 dll.  Instead, we name the section\n\
2367
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
2368
  .data  :\n\
2369
  {\n\
2370
    *(.data)\n\
2371
    *(.data2)\n\
2372
    *(.jcr)\n\
2373
  }\n\
2374
  .rdata  :\n\
2375
  {\n"
2376
"    *(.rdata)\n\
2377
    *(.rdata_runtime_pseudo_reloc)\n\
2378
  }\n\
2379
  .eh_frame  :\n\
2380
  {\n\
2381
    *(.eh_frame*)\n\
2382
  }\n\
2383
  .pdata  :\n\
2384
  {\n\
2385
    *(.pdata)\n\
2386
  }\n\
2387
  .bss  :\n\
2388
  {\n\
2389
    *(.bss)\n\
2390
    *(COMMON)\n\
2391
  }\n\
2392
  .edata  :\n\
2393
  {\n\
2394
    *(.edata)\n\
2395
  }\n\
2396
  /DISCARD/ :\n\
2397
  {\n\
2398
    *(.debug$S)\n\
2399
    *(.debug$T)\n\
2400
    *(.debug$F)\n"
2401
"    *(.drectve)\n\
2402
  }\n\
2403
  .idata  :\n\
2404
  {\n\
2405
    /* This cannot currently be handled with grouped sections.\n\
2406
	See pe.em:sort_sections.  */\n\
2407
  }\n\
2408
  .CRT  :\n\
2409
  {\n\
2410
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
2411
  }\n\
2412
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
2413
     at the end of section.  This is important because _tls_start MUST\n\
2414
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
2415
     data.  */\n\
2416
  .tls  :\n\
2417
  {\n\
2418
  }\n\
2419
  .endjunk  :\n\
2420
  {\n\
2421
    /* end is deprecated, don't use it */\n\
2422
  }\n\
2423
  .rsrc  :\n\
2424
  {\n\
2425
    *(.rsrc)\n"
2426
"  }\n\
2427
  .reloc  :\n\
2428
  {\n\
2429
    *(.reloc)\n\
2430
  }\n\
2431
  .stab   :\n\
2432
  {\n\
2433
    *(.stab)\n\
2434
  }\n\
2435
  .stabstr   :\n\
2436
  {\n\
2437
    *(.stabstr)\n\
2438
  }\n\
2439
  /* DWARF debug sections.\n\
2440
     Symbols in the DWARF debugging sections are relative to the beginning\n\
2441
     of the section.  Unlike other targets that fake this by putting the\n\
2442
     section VMA at 0, the PE format will not allow it.  */\n\
2443
  /* DWARF 1.1 and DWARF 2.  */\n\
2444
  .debug_aranges   :\n\
2445
  {\n\
2446
    *(.debug_aranges)\n\
2447
  }\n\
2448
  .zdebug_aranges   :\n\
2449
  {\n\
2450
    *(.zdebug_aranges)\n"
2451
"  }\n\
2452
  .debug_pubnames   :\n\
2453
  {\n\
2454
    *(.debug_pubnames)\n\
2455
  }\n\
2456
  .zdebug_pubnames   :\n\
2457
  {\n\
2458
    *(.zdebug_pubnames)\n\
2459
  }\n\
2460
  .debug_pubtypes   :\n\
2461
  {\n\
2462
    *(.debug_pubtypes)\n\
2463
  }\n\
2464
  .zdebug_pubtypes   :\n\
2465
  {\n\
2466
    *(.zdebug_pubtypes)\n\
2467
  }\n\
2468
  /* DWARF 2.  */\n\
2469
  .debug_info   :\n\
2470
  {\n\
2471
    *(.debug_info)\n\
2472
  }\n\
2473
  .zdebug_info   :\n\
2474
  {\n\
2475
    *(.zdebug_info)\n\
2476
  }\n\
2477
  .debug_abbrev   :\n\
2478
  {\n\
2479
    *(.debug_abbrev)\n\
2480
  }\n\
2481
  .zdebug_abbrev   :\n\
2482
  {\n\
2483
    *(.zdebug_abbrev)\n\
2484
  }\n\
2485
  .debug_line   :\n\
2486
  {\n\
2487
    *(.debug_line)\n\
2488
  }\n\
2489
  .zdebug_line   :\n\
2490
  {\n\
2491
    *(.zdebug_line)\n\
2492
  }\n\
2493
  .debug_frame   :\n\
2494
  {\n\
2495
    *(.debug_frame*)\n\
2496
  }\n\
2497
  .zdebug_frame   :\n\
2498
  {\n\
2499
    *(.zdebug_frame*)\n\
2500
  }\n\
2501
  .debug_str   :\n\
2502
  {\n\
2503
    *(.debug_str)\n\
2504
  }\n\
2505
  .zdebug_str   :\n\
2506
  {\n\
2507
    *(.zdebug_str)\n\
2508
  }\n\
2509
  .debug_loc   :\n\
2510
  {\n\
2511
    *(.debug_loc)\n\
2512
  }\n\
2513
  .zdebug_loc   :\n\
2514
  {\n\
2515
    *(.zdebug_loc)\n\
2516
  }\n\
2517
  .debug_macinfo   :\n\
2518
  {\n\
2519
    *(.debug_macinfo)\n\
2520
  }\n\
2521
  .zdebug_macinfo   :\n\
2522
  {\n\
2523
    *(.zdebug_macinfo)\n\
2524
  }\n\
2525
  /* SGI/MIPS DWARF 2 extensions.  */\n\
2526
  .debug_weaknames   :\n\
2527
  {\n\
2528
    *(.debug_weaknames)\n\
2529
  }\n\
2530
  .zdebug_weaknames   :\n\
2531
  {\n\
2532
    *(.zdebug_weaknames)\n\
2533
  }\n\
2534
  .debug_funcnames   :\n\
2535
  {\n\
2536
    *(.debug_funcnames)\n\
2537
  }\n\
2538
  .zdebug_funcnames   :\n\
2539
  {\n\
2540
    *(.zdebug_funcnames)\n\
2541
  }\n\
2542
  .debug_typenames   :\n\
2543
  {\n\
2544
    *(.debug_typenames)\n\
2545
  }\n\
2546
  .zdebug_typenames   :\n\
2547
  {\n\
2548
    *(.zdebug_typenames)\n\
2549
  }\n\
2550
  .debug_varnames   :\n\
2551
  {\n\
2552
    *(.debug_varnames)\n\
2553
  }\n\
2554
  .zdebug_varnames   :\n\
2555
  {\n\
2556
    *(.zdebug_varnames)\n\
2557
  }\n\
2558
  .debug_macro   :\n\
2559
  {\n\
2560
    *(.debug_macro)\n\
2561
  }\n\
2562
  .zdebug_macro   :\n\
2563
  {\n\
2564
    *(.zdebug_macro)\n\
2565
  }\n\
2566
  /* DWARF 3.  */\n\
2567
  .debug_ranges   :\n\
2568
  {\n\
2569
    *(.debug_ranges)\n\
2570
  }\n\
2571
  .zdebug_ranges   :\n\
2572
  {\n\
2573
    *(.zdebug_ranges)\n\
2574
  }\n\
2575
  /* DWARF 4.  */\n\
2576
  .debug_types   :\n\
2577
  {\n\
2578
    *(.debug_types)\n\
2579
  }\n\
2580
  .zdebug_types   :\n\
2581
  {\n\
2582
    *(.zdebug_types)\n\
2583
  }\n\
2584
}\n\n"
2585
  ; else if (!config.text_read_only) return
2586
"/* Script for -N: mix text and data on same page; don't align data */\n\
2587
OUTPUT_FORMAT(pei-i386)\n\
2588
SEARCH_DIR(\"=/usr/local/lib\"); SEARCH_DIR(\"=/lib\"); SEARCH_DIR(\"=/usr/lib\");\n\
2589
SECTIONS\n\
2590
{\n\
2591
  /* Make the virtual address and file offset synced if the alignment is\n\
2592
     lower than the target page size. */\n\
2593
  . = SIZEOF_HEADERS;\n\
2594
  . = ALIGN(__section_alignment__);\n\
2595
  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :\n\
2596
  {\n\
2597
     *(.init)\n\
2598
    *(.text)\n\
2599
    *(SORT(.text$*))\n\
2600
     *(.text.*)\n\
2601
     *(.gnu.linkonce.t.*)\n\
2602
    *(.glue_7t)\n\
2603
    *(.glue_7)\n\
2604
     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;\n\
2605
			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);\n\
2606
     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;\n\
2607
			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);\n\
2608
     *(.fini)\n\
2609
    /* ??? Why is .gcc_exc here?  */\n\
2610
     *(.gcc_exc)\n"
2611
"    PROVIDE (etext = .);\n\
2612
    PROVIDE (_etext = .);\n\
2613
     *(.gcc_except_table)\n\
2614
  }\n\
2615
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
2616
     on fork.  This used to be named \".data\".  The linker used\n\
2617
     to include this between __data_start__ and __data_end__, but that\n\
2618
     breaks building the cygwin32 dll.  Instead, we name the section\n\
2619
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
2620
  .data BLOCK(__section_alignment__) :\n\
2621
  {\n\
2622
    __data_start__ = . ;\n\
2623
    *(.data)\n\
2624
    *(.data2)\n\
2625
    *(SORT(.data$*))\n\
2626
    *(.jcr)\n\
2627
    __data_end__ = . ;\n\
2628
    *(.data_cygwin_nocopy)\n\
2629
  }\n\
2630
  .rdata BLOCK(__section_alignment__) :\n\
2631
  {\n\
2632
    *(.rdata)\n\
2633
             *(SORT(.rdata$*))\n\
2634
    __rt_psrelocs_start = .;\n\
2635
    *(.rdata_runtime_pseudo_reloc)\n"
2636
"    __rt_psrelocs_end = .;\n\
2637
  }\n\
2638
  __rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;\n\
2639
  ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
2640
  __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
2641
  ___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
2642
  __RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
2643
  .eh_frame BLOCK(__section_alignment__) :\n\
2644
  {\n\
2645
    *(.eh_frame*)\n\
2646
  }\n\
2647
  .pdata BLOCK(__section_alignment__) :\n\
2648
  {\n\
2649
    *(.pdata)\n\
2650
  }\n\
2651
  .bss BLOCK(__section_alignment__) :\n\
2652
  {\n\
2653
    __bss_start__ = . ;\n\
2654
    *(.bss)\n\
2655
    *(COMMON)\n\
2656
    __bss_end__ = . ;\n\
2657
  }\n\
2658
  .edata BLOCK(__section_alignment__) :\n\
2659
  {\n\
2660
    *(.edata)\n"
2661
"  }\n\
2662
  /DISCARD/ :\n\
2663
  {\n\
2664
    *(.debug$S)\n\
2665
    *(.debug$T)\n\
2666
    *(.debug$F)\n\
2667
    *(.drectve)\n\
2668
     *(.note.GNU-stack)\n\
2669
     *(.gnu.lto_*)\n\
2670
  }\n\
2671
  .idata BLOCK(__section_alignment__) :\n\
2672
  {\n\
2673
    /* This cannot currently be handled with grouped sections.\n\
2674
	See pe.em:sort_sections.  */\n\
2675
    SORT(*)(.idata$2)\n\
2676
    SORT(*)(.idata$3)\n\
2677
    /* These zeroes mark the end of the import list.  */\n\
2678
    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);\n\
2679
    SORT(*)(.idata$4)\n\
2680
    __IAT_start__ = .;\n\
2681
    SORT(*)(.idata$5)\n\
2682
    __IAT_end__ = .;\n\
2683
    SORT(*)(.idata$6)\n\
2684
    SORT(*)(.idata$7)\n\
2685
  }\n"
2686
"  .CRT BLOCK(__section_alignment__) :\n\
2687
  {\n\
2688
    ___crt_xc_start__ = . ;\n\
2689
    *(SORT(.CRT$XC*))  /* C initialization */\n\
2690
    ___crt_xc_end__ = . ;\n\
2691
    ___crt_xi_start__ = . ;\n\
2692
    *(SORT(.CRT$XI*))  /* C++ initialization */\n\
2693
    ___crt_xi_end__ = . ;\n\
2694
    ___crt_xl_start__ = . ;\n\
2695
    *(SORT(.CRT$XL*))  /* TLS callbacks */\n\
2696
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
2697
    ___crt_xp_start__ = . ;\n\
2698
    *(SORT(.CRT$XP*))  /* Pre-termination */\n\
2699
    ___crt_xp_end__ = . ;\n\
2700
    ___crt_xt_start__ = . ;\n\
2701
    *(SORT(.CRT$XT*))  /* Termination */\n\
2702
    ___crt_xt_end__ = . ;\n\
2703
  }\n\
2704
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
2705
     at the end of section.  This is important because _tls_start MUST\n\
2706
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
2707
     data.  */\n\
2708
  .tls BLOCK(__section_alignment__) :\n\
2709
  {\n\
2710
    ___tls_start__ = . ;\n\
2711
    *(.tls$AAA)\n\
2712
    *(.tls)\n\
2713
    *(.tls$)\n\
2714
    *(SORT(.tls$*))\n\
2715
    *(.tls$ZZZ)\n\
2716
    ___tls_end__ = . ;\n\
2717
  }\n\
2718
  .endjunk BLOCK(__section_alignment__) :\n\
2719
  {\n\
2720
    /* end is deprecated, don't use it */\n\
2721
    PROVIDE (end = .);\n\
2722
    PROVIDE ( _end = .);\n\
2723
     __end__ = .;\n\
2724
  }\n\
2725
  .rsrc BLOCK(__section_alignment__) :\n\
2726
  {\n\
2727
    *(.rsrc)\n\
2728
    *(SORT(.rsrc$*))\n\
2729
  }\n\
2730
  .reloc BLOCK(__section_alignment__) :\n\
2731
  {\n\
2732
    *(.reloc)\n\
2733
  }\n\
2734
  .stab BLOCK(__section_alignment__) (NOLOAD) :\n\
2735
  {\n\
2736
    *(.stab)\n\
2737
  }\n\
2738
  .stabstr BLOCK(__section_alignment__) (NOLOAD) :\n\
2739
  {\n\
2740
    *(.stabstr)\n\
2741
  }\n\
2742
  /* DWARF debug sections.\n\
2743
     Symbols in the DWARF debugging sections are relative to the beginning\n\
2744
     of the section.  Unlike other targets that fake this by putting the\n\
2745
     section VMA at 0, the PE format will not allow it.  */\n\
2746
  /* DWARF 1.1 and DWARF 2.  */\n\
2747
  .debug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
2748
  {\n\
2749
    *(.debug_aranges)\n\
2750
  }\n\
2751
  .zdebug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
2752
  {\n\
2753
    *(.zdebug_aranges)\n\
2754
  }\n\
2755
  .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2756
  {\n\
2757
    *(.debug_pubnames)\n\
2758
  }\n\
2759
  .zdebug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2760
  {\n\
2761
    *(.zdebug_pubnames)\n\
2762
  }\n\
2763
  .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
2764
  {\n\
2765
    *(.debug_pubtypes)\n\
2766
  }\n\
2767
  .zdebug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
2768
  {\n\
2769
    *(.zdebug_pubtypes)\n\
2770
  }\n\
2771
  /* DWARF 2.  */\n\
2772
  .debug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
2773
  {\n\
2774
    *(.debug_info .gnu.linkonce.wi.*)\n\
2775
  }\n\
2776
  .zdebug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
2777
  {\n\
2778
    *(.zdebug_info .zdebug.gnu.linkonce.wi.*)\n\
2779
  }\n\
2780
  .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
2781
  {\n\
2782
    *(.debug_abbrev)\n\
2783
  }\n\
2784
  .zdebug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
2785
  {\n\
2786
    *(.zdebug_abbrev)\n\
2787
  }\n\
2788
  .debug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
2789
  {\n\
2790
    *(.debug_line)\n\
2791
  }\n\
2792
  .zdebug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
2793
  {\n\
2794
    *(.zdebug_line)\n\
2795
  }\n\
2796
  .debug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
2797
  {\n\
2798
    *(.debug_frame*)\n\
2799
  }\n\
2800
  .zdebug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
2801
  {\n\
2802
    *(.zdebug_frame*)\n\
2803
  }\n\
2804
  .debug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
2805
  {\n\
2806
    *(.debug_str)\n\
2807
  }\n\
2808
  .zdebug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
2809
  {\n\
2810
    *(.zdebug_str)\n\
2811
  }\n\
2812
  .debug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
2813
  {\n\
2814
    *(.debug_loc)\n\
2815
  }\n\
2816
  .zdebug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
2817
  {\n\
2818
    *(.zdebug_loc)\n\
2819
  }\n\
2820
  .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
2821
  {\n\
2822
    *(.debug_macinfo)\n\
2823
  }\n\
2824
  .zdebug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
2825
  {\n\
2826
    *(.zdebug_macinfo)\n\
2827
  }\n\
2828
  /* SGI/MIPS DWARF 2 extensions.  */\n\
2829
  .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
2830
  {\n\
2831
    *(.debug_weaknames)\n\
2832
  }\n\
2833
  .zdebug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
2834
  {\n\
2835
    *(.zdebug_weaknames)\n\
2836
  }\n\
2837
  .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2838
  {\n\
2839
    *(.debug_funcnames)\n\
2840
  }\n\
2841
  .zdebug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2842
  {\n\
2843
    *(.zdebug_funcnames)\n\
2844
  }\n\
2845
  .debug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
2846
  {\n\
2847
    *(.debug_typenames)\n\
2848
  }\n\
2849
  .zdebug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
2850
  {\n\
2851
    *(.zdebug_typenames)\n\
2852
  }\n\
2853
  .debug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2854
  {\n\
2855
    *(.debug_varnames)\n\
2856
  }\n\
2857
  .zdebug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
2858
  {\n\
2859
    *(.zdebug_varnames)\n\
2860
  }\n\
2861
  .debug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
2862
  {\n\
2863
    *(.debug_macro)\n\
2864
  }\n\
2865
  .zdebug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
2866
  {\n\
2867
    *(.zdebug_macro)\n\
2868
  }\n\
2869
  /* DWARF 3.  */\n\
2870
  .debug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
2871
  {\n\
2872
    *(.debug_ranges)\n\
2873
  }\n\
2874
  .zdebug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
2875
  {\n\
2876
    *(.zdebug_ranges)\n\
2877
  }\n\
2878
  /* DWARF 4.  */\n\
2879
  .debug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
2880
  {\n\
2881
    *(.debug_types .gnu.linkonce.wt.*)\n\
2882
  }\n\
2883
  .zdebug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
2884
  {\n\
2885
    *(.zdebug_types .gnu.linkonce.wt.*)\n\
2886
  }\n\
2887
}\n\n"
2888
  ; else if (!config.magic_demand_paged) return
2889
"/* Script for -n: mix text and data on same page */\n\
2890
OUTPUT_FORMAT(pei-i386)\n\
2891
SEARCH_DIR(\"=/usr/local/lib\"); SEARCH_DIR(\"=/lib\"); SEARCH_DIR(\"=/usr/lib\");\n\
2892
SECTIONS\n\
2893
{\n\
2894
  /* Make the virtual address and file offset synced if the alignment is\n\
2895
     lower than the target page size. */\n\
2896
  . = SIZEOF_HEADERS;\n\
2897
  . = ALIGN(__section_alignment__);\n\
2898
  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :\n\
2899
  {\n\
2900
     *(.init)\n\
2901
    *(.text)\n\
2902
    *(SORT(.text$*))\n\
2903
     *(.text.*)\n\
2904
     *(.gnu.linkonce.t.*)\n\
2905
    *(.glue_7t)\n\
2906
    *(.glue_7)\n\
2907
     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;\n\
2908
			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);\n\
2909
     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;\n\
2910
			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);\n\
2911
     *(.fini)\n\
2912
    /* ??? Why is .gcc_exc here?  */\n\
2913
     *(.gcc_exc)\n"
2914
"    PROVIDE (etext = .);\n\
2915
    PROVIDE (_etext = .);\n\
2916
     *(.gcc_except_table)\n\
2917
  }\n\
2918
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
2919
     on fork.  This used to be named \".data\".  The linker used\n\
2920
     to include this between __data_start__ and __data_end__, but that\n\
2921
     breaks building the cygwin32 dll.  Instead, we name the section\n\
2922
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
2923
  .data BLOCK(__section_alignment__) :\n\
2924
  {\n\
2925
    __data_start__ = . ;\n\
2926
    *(.data)\n\
2927
    *(.data2)\n\
2928
    *(SORT(.data$*))\n\
2929
    *(.jcr)\n\
2930
    __data_end__ = . ;\n\
2931
    *(.data_cygwin_nocopy)\n\
2932
  }\n\
2933
  .rdata BLOCK(__section_alignment__) :\n\
2934
  {\n\
2935
    *(.rdata)\n\
2936
             *(SORT(.rdata$*))\n\
2937
    __rt_psrelocs_start = .;\n\
2938
    *(.rdata_runtime_pseudo_reloc)\n"
2939
"    __rt_psrelocs_end = .;\n\
2940
  }\n\
2941
  __rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;\n\
2942
  ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
2943
  __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
2944
  ___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
2945
  __RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
2946
  .eh_frame BLOCK(__section_alignment__) :\n\
2947
  {\n\
2948
    *(.eh_frame*)\n\
2949
  }\n\
2950
  .pdata BLOCK(__section_alignment__) :\n\
2951
  {\n\
2952
    *(.pdata)\n\
2953
  }\n\
2954
  .bss BLOCK(__section_alignment__) :\n\
2955
  {\n\
2956
    __bss_start__ = . ;\n\
2957
    *(.bss)\n\
2958
    *(COMMON)\n\
2959
    __bss_end__ = . ;\n\
2960
  }\n\
2961
  .edata BLOCK(__section_alignment__) :\n\
2962
  {\n\
2963
    *(.edata)\n"
2964
"  }\n\
2965
  /DISCARD/ :\n\
2966
  {\n\
2967
    *(.debug$S)\n\
2968
    *(.debug$T)\n\
2969
    *(.debug$F)\n\
2970
    *(.drectve)\n\
2971
     *(.note.GNU-stack)\n\
2972
     *(.gnu.lto_*)\n\
2973
  }\n\
2974
  .idata BLOCK(__section_alignment__) :\n\
2975
  {\n\
2976
    /* This cannot currently be handled with grouped sections.\n\
2977
	See pe.em:sort_sections.  */\n\
2978
    SORT(*)(.idata$2)\n\
2979
    SORT(*)(.idata$3)\n\
2980
    /* These zeroes mark the end of the import list.  */\n\
2981
    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);\n\
2982
    SORT(*)(.idata$4)\n\
2983
    __IAT_start__ = .;\n\
2984
    SORT(*)(.idata$5)\n\
2985
    __IAT_end__ = .;\n\
2986
    SORT(*)(.idata$6)\n\
2987
    SORT(*)(.idata$7)\n\
2988
  }\n"
2989
"  .CRT BLOCK(__section_alignment__) :\n\
2990
  {\n\
2991
    ___crt_xc_start__ = . ;\n\
2992
    *(SORT(.CRT$XC*))  /* C initialization */\n\
2993
    ___crt_xc_end__ = . ;\n\
2994
    ___crt_xi_start__ = . ;\n\
2995
    *(SORT(.CRT$XI*))  /* C++ initialization */\n\
2996
    ___crt_xi_end__ = . ;\n\
2997
    ___crt_xl_start__ = . ;\n\
2998
    *(SORT(.CRT$XL*))  /* TLS callbacks */\n\
2999
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
3000
    ___crt_xp_start__ = . ;\n\
3001
    *(SORT(.CRT$XP*))  /* Pre-termination */\n\
3002
    ___crt_xp_end__ = . ;\n\
3003
    ___crt_xt_start__ = . ;\n\
3004
    *(SORT(.CRT$XT*))  /* Termination */\n\
3005
    ___crt_xt_end__ = . ;\n\
3006
  }\n\
3007
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
3008
     at the end of section.  This is important because _tls_start MUST\n\
3009
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
3010
     data.  */\n\
3011
  .tls BLOCK(__section_alignment__) :\n\
3012
  {\n\
3013
    ___tls_start__ = . ;\n\
3014
    *(.tls$AAA)\n\
3015
    *(.tls)\n\
3016
    *(.tls$)\n\
3017
    *(SORT(.tls$*))\n\
3018
    *(.tls$ZZZ)\n\
3019
    ___tls_end__ = . ;\n\
3020
  }\n\
3021
  .endjunk BLOCK(__section_alignment__) :\n\
3022
  {\n\
3023
    /* end is deprecated, don't use it */\n\
3024
    PROVIDE (end = .);\n\
3025
    PROVIDE ( _end = .);\n\
3026
     __end__ = .;\n\
3027
  }\n\
3028
  .rsrc BLOCK(__section_alignment__) :\n\
3029
  {\n\
3030
    *(.rsrc)\n\
3031
    *(SORT(.rsrc$*))\n\
3032
  }\n\
3033
  .reloc BLOCK(__section_alignment__) :\n\
3034
  {\n\
3035
    *(.reloc)\n\
3036
  }\n\
3037
  .stab BLOCK(__section_alignment__) (NOLOAD) :\n\
3038
  {\n\
3039
    *(.stab)\n\
3040
  }\n\
3041
  .stabstr BLOCK(__section_alignment__) (NOLOAD) :\n\
3042
  {\n\
3043
    *(.stabstr)\n\
3044
  }\n\
3045
  /* DWARF debug sections.\n\
3046
     Symbols in the DWARF debugging sections are relative to the beginning\n\
3047
     of the section.  Unlike other targets that fake this by putting the\n\
3048
     section VMA at 0, the PE format will not allow it.  */\n\
3049
  /* DWARF 1.1 and DWARF 2.  */\n\
3050
  .debug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3051
  {\n\
3052
    *(.debug_aranges)\n\
3053
  }\n\
3054
  .zdebug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3055
  {\n\
3056
    *(.zdebug_aranges)\n\
3057
  }\n\
3058
  .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3059
  {\n\
3060
    *(.debug_pubnames)\n\
3061
  }\n\
3062
  .zdebug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3063
  {\n\
3064
    *(.zdebug_pubnames)\n\
3065
  }\n\
3066
  .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3067
  {\n\
3068
    *(.debug_pubtypes)\n\
3069
  }\n\
3070
  .zdebug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3071
  {\n\
3072
    *(.zdebug_pubtypes)\n\
3073
  }\n\
3074
  /* DWARF 2.  */\n\
3075
  .debug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3076
  {\n\
3077
    *(.debug_info .gnu.linkonce.wi.*)\n\
3078
  }\n\
3079
  .zdebug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3080
  {\n\
3081
    *(.zdebug_info .zdebug.gnu.linkonce.wi.*)\n\
3082
  }\n\
3083
  .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3084
  {\n\
3085
    *(.debug_abbrev)\n\
3086
  }\n\
3087
  .zdebug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3088
  {\n\
3089
    *(.zdebug_abbrev)\n\
3090
  }\n\
3091
  .debug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3092
  {\n\
3093
    *(.debug_line)\n\
3094
  }\n\
3095
  .zdebug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3096
  {\n\
3097
    *(.zdebug_line)\n\
3098
  }\n\
3099
  .debug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3100
  {\n\
3101
    *(.debug_frame*)\n\
3102
  }\n\
3103
  .zdebug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3104
  {\n\
3105
    *(.zdebug_frame*)\n\
3106
  }\n\
3107
  .debug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3108
  {\n\
3109
    *(.debug_str)\n\
3110
  }\n\
3111
  .zdebug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3112
  {\n\
3113
    *(.zdebug_str)\n\
3114
  }\n\
3115
  .debug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3116
  {\n\
3117
    *(.debug_loc)\n\
3118
  }\n\
3119
  .zdebug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3120
  {\n\
3121
    *(.zdebug_loc)\n\
3122
  }\n\
3123
  .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3124
  {\n\
3125
    *(.debug_macinfo)\n\
3126
  }\n\
3127
  .zdebug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3128
  {\n\
3129
    *(.zdebug_macinfo)\n\
3130
  }\n\
3131
  /* SGI/MIPS DWARF 2 extensions.  */\n\
3132
  .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3133
  {\n\
3134
    *(.debug_weaknames)\n\
3135
  }\n\
3136
  .zdebug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3137
  {\n\
3138
    *(.zdebug_weaknames)\n\
3139
  }\n\
3140
  .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3141
  {\n\
3142
    *(.debug_funcnames)\n\
3143
  }\n\
3144
  .zdebug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3145
  {\n\
3146
    *(.zdebug_funcnames)\n\
3147
  }\n\
3148
  .debug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3149
  {\n\
3150
    *(.debug_typenames)\n\
3151
  }\n\
3152
  .zdebug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3153
  {\n\
3154
    *(.zdebug_typenames)\n\
3155
  }\n\
3156
  .debug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3157
  {\n\
3158
    *(.debug_varnames)\n\
3159
  }\n\
3160
  .zdebug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3161
  {\n\
3162
    *(.zdebug_varnames)\n\
3163
  }\n\
3164
  .debug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3165
  {\n\
3166
    *(.debug_macro)\n\
3167
  }\n\
3168
  .zdebug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3169
  {\n\
3170
    *(.zdebug_macro)\n\
3171
  }\n\
3172
  /* DWARF 3.  */\n\
3173
  .debug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3174
  {\n\
3175
    *(.debug_ranges)\n\
3176
  }\n\
3177
  .zdebug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3178
  {\n\
3179
    *(.zdebug_ranges)\n\
3180
  }\n\
3181
  /* DWARF 4.  */\n\
3182
  .debug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3183
  {\n\
3184
    *(.debug_types .gnu.linkonce.wt.*)\n\
3185
  }\n\
3186
  .zdebug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3187
  {\n\
3188
    *(.zdebug_types .gnu.linkonce.wt.*)\n\
3189
  }\n\
3190
}\n\n"
3191
  ; else if (link_info.pei386_auto_import == 1 && (MERGE_RDATA_V2 || link_info.pei386_runtime_pseudo_reloc != 2)) return
3192
"/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data  */\n\
3193
OUTPUT_FORMAT(pei-i386)\n\
3194
SEARCH_DIR(\"=/usr/local/lib\"); SEARCH_DIR(\"=/lib\"); SEARCH_DIR(\"=/usr/lib\");\n\
3195
SECTIONS\n\
3196
{\n\
3197
  /* Make the virtual address and file offset synced if the alignment is\n\
3198
     lower than the target page size. */\n\
3199
  . = SIZEOF_HEADERS;\n\
3200
  . = ALIGN(__section_alignment__);\n\
3201
  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :\n\
3202
  {\n\
3203
     *(.init)\n\
3204
    *(.text)\n\
3205
    *(SORT(.text$*))\n\
3206
     *(.text.*)\n\
3207
     *(.gnu.linkonce.t.*)\n\
3208
    *(.glue_7t)\n\
3209
    *(.glue_7)\n\
3210
     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;\n\
3211
			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);\n\
3212
     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;\n\
3213
			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);\n\
3214
     *(.fini)\n\
3215
    /* ??? Why is .gcc_exc here?  */\n\
3216
     *(.gcc_exc)\n"
3217
"    PROVIDE (etext = .);\n\
3218
    PROVIDE (_etext = .);\n\
3219
     *(.gcc_except_table)\n\
3220
  }\n\
3221
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
3222
     on fork.  This used to be named \".data\".  The linker used\n\
3223
     to include this between __data_start__ and __data_end__, but that\n\
3224
     breaks building the cygwin32 dll.  Instead, we name the section\n\
3225
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
3226
  .data BLOCK(__section_alignment__) :\n\
3227
  {\n\
3228
    __data_start__ = . ;\n\
3229
    *(.data)\n\
3230
    *(.data2)\n\
3231
    *(SORT(.data$*))\n\
3232
            *(.rdata)\n\
3233
	    *(SORT(.rdata$*))\n\
3234
    *(.jcr)\n\
3235
    __data_end__ = . ;\n\
3236
    *(.data_cygwin_nocopy)\n\
3237
  }\n\
3238
  .rdata BLOCK(__section_alignment__) :\n\
3239
  {\n\
3240
    __rt_psrelocs_start = .;\n\
3241
    *(.rdata_runtime_pseudo_reloc)\n"
3242
"    __rt_psrelocs_end = .;\n\
3243
  }\n\
3244
  __rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;\n\
3245
  ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
3246
  __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
3247
  ___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
3248
  __RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
3249
  .eh_frame BLOCK(__section_alignment__) :\n\
3250
  {\n\
3251
    *(.eh_frame*)\n\
3252
  }\n\
3253
  .pdata BLOCK(__section_alignment__) :\n\
3254
  {\n\
3255
    *(.pdata)\n\
3256
  }\n\
3257
  .bss BLOCK(__section_alignment__) :\n\
3258
  {\n\
3259
    __bss_start__ = . ;\n\
3260
    *(.bss)\n\
3261
    *(COMMON)\n\
3262
    __bss_end__ = . ;\n\
3263
  }\n\
3264
  .edata BLOCK(__section_alignment__) :\n\
3265
  {\n\
3266
    *(.edata)\n"
3267
"  }\n\
3268
  /DISCARD/ :\n\
3269
  {\n\
3270
    *(.debug$S)\n\
3271
    *(.debug$T)\n\
3272
    *(.debug$F)\n\
3273
    *(.drectve)\n\
3274
     *(.note.GNU-stack)\n\
3275
     *(.gnu.lto_*)\n\
3276
  }\n\
3277
  .idata BLOCK(__section_alignment__) :\n\
3278
  {\n\
3279
    /* This cannot currently be handled with grouped sections.\n\
3280
	See pe.em:sort_sections.  */\n\
3281
    SORT(*)(.idata$2)\n\
3282
    SORT(*)(.idata$3)\n\
3283
    /* These zeroes mark the end of the import list.  */\n\
3284
    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);\n\
3285
    SORT(*)(.idata$4)\n\
3286
    __IAT_start__ = .;\n\
3287
    SORT(*)(.idata$5)\n\
3288
    __IAT_end__ = .;\n\
3289
    SORT(*)(.idata$6)\n\
3290
    SORT(*)(.idata$7)\n\
3291
  }\n"
3292
"  .CRT BLOCK(__section_alignment__) :\n\
3293
  {\n\
3294
    ___crt_xc_start__ = . ;\n\
3295
    *(SORT(.CRT$XC*))  /* C initialization */\n\
3296
    ___crt_xc_end__ = . ;\n\
3297
    ___crt_xi_start__ = . ;\n\
3298
    *(SORT(.CRT$XI*))  /* C++ initialization */\n\
3299
    ___crt_xi_end__ = . ;\n\
3300
    ___crt_xl_start__ = . ;\n\
3301
    *(SORT(.CRT$XL*))  /* TLS callbacks */\n\
3302
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
3303
    ___crt_xp_start__ = . ;\n\
3304
    *(SORT(.CRT$XP*))  /* Pre-termination */\n\
3305
    ___crt_xp_end__ = . ;\n\
3306
    ___crt_xt_start__ = . ;\n\
3307
    *(SORT(.CRT$XT*))  /* Termination */\n\
3308
    ___crt_xt_end__ = . ;\n\
3309
  }\n\
3310
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
3311
     at the end of section.  This is important because _tls_start MUST\n\
3312
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
3313
     data.  */\n\
3314
  .tls BLOCK(__section_alignment__) :\n\
3315
  {\n\
3316
    ___tls_start__ = . ;\n\
3317
    *(.tls$AAA)\n\
3318
    *(.tls)\n\
3319
    *(.tls$)\n\
3320
    *(SORT(.tls$*))\n\
3321
    *(.tls$ZZZ)\n\
3322
    ___tls_end__ = . ;\n\
3323
  }\n\
3324
  .endjunk BLOCK(__section_alignment__) :\n\
3325
  {\n\
3326
    /* end is deprecated, don't use it */\n\
3327
    PROVIDE (end = .);\n\
3328
    PROVIDE ( _end = .);\n\
3329
     __end__ = .;\n\
3330
  }\n\
3331
  .rsrc BLOCK(__section_alignment__) :\n\
3332
  {\n\
3333
    *(.rsrc)\n\
3334
    *(SORT(.rsrc$*))\n\
3335
  }\n\
3336
  .reloc BLOCK(__section_alignment__) :\n\
3337
  {\n\
3338
    *(.reloc)\n\
3339
  }\n\
3340
  .stab BLOCK(__section_alignment__) (NOLOAD) :\n\
3341
  {\n\
3342
    *(.stab)\n\
3343
  }\n\
3344
  .stabstr BLOCK(__section_alignment__) (NOLOAD) :\n\
3345
  {\n\
3346
    *(.stabstr)\n\
3347
  }\n\
3348
  /* DWARF debug sections.\n\
3349
     Symbols in the DWARF debugging sections are relative to the beginning\n\
3350
     of the section.  Unlike other targets that fake this by putting the\n\
3351
     section VMA at 0, the PE format will not allow it.  */\n\
3352
  /* DWARF 1.1 and DWARF 2.  */\n\
3353
  .debug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3354
  {\n\
3355
    *(.debug_aranges)\n\
3356
  }\n\
3357
  .zdebug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3358
  {\n\
3359
    *(.zdebug_aranges)\n\
3360
  }\n\
3361
  .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3362
  {\n\
3363
    *(.debug_pubnames)\n\
3364
  }\n\
3365
  .zdebug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3366
  {\n\
3367
    *(.zdebug_pubnames)\n\
3368
  }\n\
3369
  .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3370
  {\n\
3371
    *(.debug_pubtypes)\n\
3372
  }\n\
3373
  .zdebug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3374
  {\n\
3375
    *(.zdebug_pubtypes)\n\
3376
  }\n\
3377
  /* DWARF 2.  */\n\
3378
  .debug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3379
  {\n\
3380
    *(.debug_info .gnu.linkonce.wi.*)\n\
3381
  }\n\
3382
  .zdebug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3383
  {\n\
3384
    *(.zdebug_info .zdebug.gnu.linkonce.wi.*)\n\
3385
  }\n\
3386
  .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3387
  {\n\
3388
    *(.debug_abbrev)\n\
3389
  }\n\
3390
  .zdebug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3391
  {\n\
3392
    *(.zdebug_abbrev)\n\
3393
  }\n\
3394
  .debug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3395
  {\n\
3396
    *(.debug_line)\n\
3397
  }\n\
3398
  .zdebug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3399
  {\n\
3400
    *(.zdebug_line)\n\
3401
  }\n\
3402
  .debug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3403
  {\n\
3404
    *(.debug_frame*)\n\
3405
  }\n\
3406
  .zdebug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3407
  {\n\
3408
    *(.zdebug_frame*)\n\
3409
  }\n\
3410
  .debug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3411
  {\n\
3412
    *(.debug_str)\n\
3413
  }\n\
3414
  .zdebug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3415
  {\n\
3416
    *(.zdebug_str)\n\
3417
  }\n\
3418
  .debug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3419
  {\n\
3420
    *(.debug_loc)\n\
3421
  }\n\
3422
  .zdebug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3423
  {\n\
3424
    *(.zdebug_loc)\n\
3425
  }\n\
3426
  .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3427
  {\n\
3428
    *(.debug_macinfo)\n\
3429
  }\n\
3430
  .zdebug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3431
  {\n\
3432
    *(.zdebug_macinfo)\n\
3433
  }\n\
3434
  /* SGI/MIPS DWARF 2 extensions.  */\n\
3435
  .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3436
  {\n\
3437
    *(.debug_weaknames)\n\
3438
  }\n\
3439
  .zdebug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3440
  {\n\
3441
    *(.zdebug_weaknames)\n\
3442
  }\n\
3443
  .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3444
  {\n\
3445
    *(.debug_funcnames)\n\
3446
  }\n\
3447
  .zdebug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3448
  {\n\
3449
    *(.zdebug_funcnames)\n\
3450
  }\n\
3451
  .debug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3452
  {\n\
3453
    *(.debug_typenames)\n\
3454
  }\n\
3455
  .zdebug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3456
  {\n\
3457
    *(.zdebug_typenames)\n\
3458
  }\n\
3459
  .debug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3460
  {\n\
3461
    *(.debug_varnames)\n\
3462
  }\n\
3463
  .zdebug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3464
  {\n\
3465
    *(.zdebug_varnames)\n\
3466
  }\n\
3467
  .debug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3468
  {\n\
3469
    *(.debug_macro)\n\
3470
  }\n\
3471
  .zdebug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3472
  {\n\
3473
    *(.zdebug_macro)\n\
3474
  }\n\
3475
  /* DWARF 3.  */\n\
3476
  .debug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3477
  {\n\
3478
    *(.debug_ranges)\n\
3479
  }\n\
3480
  .zdebug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3481
  {\n\
3482
    *(.zdebug_ranges)\n\
3483
  }\n\
3484
  /* DWARF 4.  */\n\
3485
  .debug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3486
  {\n\
3487
    *(.debug_types .gnu.linkonce.wt.*)\n\
3488
  }\n\
3489
  .zdebug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3490
  {\n\
3491
    *(.zdebug_types .gnu.linkonce.wt.*)\n\
3492
  }\n\
3493
}\n\n"
3494
  ; else return
3495
"/* Default linker script, for normal executables */\n\
3496
OUTPUT_FORMAT(pei-i386)\n\
3497
SEARCH_DIR(\"=/usr/local/lib\"); SEARCH_DIR(\"=/lib\"); SEARCH_DIR(\"=/usr/lib\");\n\
3498
SECTIONS\n\
3499
{\n\
3500
  /* Make the virtual address and file offset synced if the alignment is\n\
3501
     lower than the target page size. */\n\
3502
  . = SIZEOF_HEADERS;\n\
3503
  . = ALIGN(__section_alignment__);\n\
3504
  .text  __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :\n\
3505
  {\n\
3506
     *(.init)\n\
3507
    *(.text)\n\
3508
    *(SORT(.text$*))\n\
3509
     *(.text.*)\n\
3510
     *(.gnu.linkonce.t.*)\n\
3511
    *(.glue_7t)\n\
3512
    *(.glue_7)\n\
3513
     ___CTOR_LIST__ = .; __CTOR_LIST__ = . ;\n\
3514
			LONG (-1);*(.ctors); *(.ctor); *(SORT(.ctors.*));  LONG (0);\n\
3515
     ___DTOR_LIST__ = .; __DTOR_LIST__ = . ;\n\
3516
			LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*));  LONG (0);\n\
3517
     *(.fini)\n\
3518
    /* ??? Why is .gcc_exc here?  */\n\
3519
     *(.gcc_exc)\n"
3520
"    PROVIDE (etext = .);\n\
3521
    PROVIDE (_etext = .);\n\
3522
     *(.gcc_except_table)\n\
3523
  }\n\
3524
  /* The Cygwin32 library uses a section to avoid copying certain data\n\
3525
     on fork.  This used to be named \".data\".  The linker used\n\
3526
     to include this between __data_start__ and __data_end__, but that\n\
3527
     breaks building the cygwin32 dll.  Instead, we name the section\n\
3528
     \".data_cygwin_nocopy\" and explicitly include it after __data_end__. */\n\
3529
  .data BLOCK(__section_alignment__) :\n\
3530
  {\n\
3531
    __data_start__ = . ;\n\
3532
    *(.data)\n\
3533
    *(.data2)\n\
3534
    *(SORT(.data$*))\n\
3535
    *(.jcr)\n\
3536
    __data_end__ = . ;\n\
3537
    *(.data_cygwin_nocopy)\n\
3538
  }\n\
3539
  .rdata BLOCK(__section_alignment__) :\n\
3540
  {\n\
3541
    *(.rdata)\n\
3542
             *(SORT(.rdata$*))\n\
3543
    __rt_psrelocs_start = .;\n\
3544
    *(.rdata_runtime_pseudo_reloc)\n"
3545
"    __rt_psrelocs_end = .;\n\
3546
  }\n\
3547
  __rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;\n\
3548
  ___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
3549
  __RUNTIME_PSEUDO_RELOC_LIST_END__ = .;\n\
3550
  ___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
3551
  __RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;\n\
3552
  .eh_frame BLOCK(__section_alignment__) :\n\
3553
  {\n\
3554
    *(.eh_frame*)\n\
3555
  }\n\
3556
  .pdata BLOCK(__section_alignment__) :\n\
3557
  {\n\
3558
    *(.pdata)\n\
3559
  }\n\
3560
  .bss BLOCK(__section_alignment__) :\n\
3561
  {\n\
3562
    __bss_start__ = . ;\n\
3563
    *(.bss)\n\
3564
    *(COMMON)\n\
3565
    __bss_end__ = . ;\n\
3566
  }\n\
3567
  .edata BLOCK(__section_alignment__) :\n\
3568
  {\n\
3569
    *(.edata)\n"
3570
"  }\n\
3571
  /DISCARD/ :\n\
3572
  {\n\
3573
    *(.debug$S)\n\
3574
    *(.debug$T)\n\
3575
    *(.debug$F)\n\
3576
    *(.drectve)\n\
3577
     *(.note.GNU-stack)\n\
3578
     *(.gnu.lto_*)\n\
3579
  }\n\
3580
  .idata BLOCK(__section_alignment__) :\n\
3581
  {\n\
3582
    /* This cannot currently be handled with grouped sections.\n\
3583
	See pe.em:sort_sections.  */\n\
3584
    SORT(*)(.idata$2)\n\
3585
    SORT(*)(.idata$3)\n\
3586
    /* These zeroes mark the end of the import list.  */\n\
3587
    LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);\n\
3588
    SORT(*)(.idata$4)\n\
3589
    __IAT_start__ = .;\n\
3590
    SORT(*)(.idata$5)\n\
3591
    __IAT_end__ = .;\n\
3592
    SORT(*)(.idata$6)\n\
3593
    SORT(*)(.idata$7)\n\
3594
  }\n"
3595
"  .CRT BLOCK(__section_alignment__) :\n\
3596
  {\n\
3597
    ___crt_xc_start__ = . ;\n\
3598
    *(SORT(.CRT$XC*))  /* C initialization */\n\
3599
    ___crt_xc_end__ = . ;\n\
3600
    ___crt_xi_start__ = . ;\n\
3601
    *(SORT(.CRT$XI*))  /* C++ initialization */\n\
3602
    ___crt_xi_end__ = . ;\n\
3603
    ___crt_xl_start__ = . ;\n\
3604
    *(SORT(.CRT$XL*))  /* TLS callbacks */\n\
3605
    /* ___crt_xl_end__ is defined in the TLS Directory support code */\n\
3606
    ___crt_xp_start__ = . ;\n\
3607
    *(SORT(.CRT$XP*))  /* Pre-termination */\n\
3608
    ___crt_xp_end__ = . ;\n\
3609
    ___crt_xt_start__ = . ;\n\
3610
    *(SORT(.CRT$XT*))  /* Termination */\n\
3611
    ___crt_xt_end__ = . ;\n\
3612
  }\n\
3613
  /* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be\n\
3614
     at the end of section.  This is important because _tls_start MUST\n\
3615
     be at the beginning of the section to enable SECREL32 relocations with TLS\n\
3616
     data.  */\n\
3617
  .tls BLOCK(__section_alignment__) :\n\
3618
  {\n\
3619
    ___tls_start__ = . ;\n\
3620
    *(.tls$AAA)\n\
3621
    *(.tls)\n\
3622
    *(.tls$)\n\
3623
    *(SORT(.tls$*))\n\
3624
    *(.tls$ZZZ)\n\
3625
    ___tls_end__ = . ;\n\
3626
  }\n\
3627
  .endjunk BLOCK(__section_alignment__) :\n\
3628
  {\n\
3629
    /* end is deprecated, don't use it */\n\
3630
    PROVIDE (end = .);\n\
3631
    PROVIDE ( _end = .);\n\
3632
     __end__ = .;\n\
3633
  }\n\
3634
  .rsrc BLOCK(__section_alignment__) :\n\
3635
  {\n\
3636
    *(.rsrc)\n\
3637
    *(SORT(.rsrc$*))\n\
3638
  }\n\
3639
  .reloc BLOCK(__section_alignment__) :\n\
3640
  {\n\
3641
    *(.reloc)\n\
3642
  }\n\
3643
  .stab BLOCK(__section_alignment__) (NOLOAD) :\n\
3644
  {\n\
3645
    *(.stab)\n\
3646
  }\n\
3647
  .stabstr BLOCK(__section_alignment__) (NOLOAD) :\n\
3648
  {\n\
3649
    *(.stabstr)\n\
3650
  }\n\
3651
  /* DWARF debug sections.\n\
3652
     Symbols in the DWARF debugging sections are relative to the beginning\n\
3653
     of the section.  Unlike other targets that fake this by putting the\n\
3654
     section VMA at 0, the PE format will not allow it.  */\n\
3655
  /* DWARF 1.1 and DWARF 2.  */\n\
3656
  .debug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3657
  {\n\
3658
    *(.debug_aranges)\n\
3659
  }\n\
3660
  .zdebug_aranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3661
  {\n\
3662
    *(.zdebug_aranges)\n\
3663
  }\n\
3664
  .debug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3665
  {\n\
3666
    *(.debug_pubnames)\n\
3667
  }\n\
3668
  .zdebug_pubnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3669
  {\n\
3670
    *(.zdebug_pubnames)\n\
3671
  }\n\
3672
  .debug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3673
  {\n\
3674
    *(.debug_pubtypes)\n\
3675
  }\n\
3676
  .zdebug_pubtypes BLOCK(__section_alignment__) (NOLOAD) :\n\
3677
  {\n\
3678
    *(.zdebug_pubtypes)\n\
3679
  }\n\
3680
  /* DWARF 2.  */\n\
3681
  .debug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3682
  {\n\
3683
    *(.debug_info .gnu.linkonce.wi.*)\n\
3684
  }\n\
3685
  .zdebug_info BLOCK(__section_alignment__) (NOLOAD) :\n\
3686
  {\n\
3687
    *(.zdebug_info .zdebug.gnu.linkonce.wi.*)\n\
3688
  }\n\
3689
  .debug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3690
  {\n\
3691
    *(.debug_abbrev)\n\
3692
  }\n\
3693
  .zdebug_abbrev BLOCK(__section_alignment__) (NOLOAD) :\n\
3694
  {\n\
3695
    *(.zdebug_abbrev)\n\
3696
  }\n\
3697
  .debug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3698
  {\n\
3699
    *(.debug_line)\n\
3700
  }\n\
3701
  .zdebug_line BLOCK(__section_alignment__) (NOLOAD) :\n\
3702
  {\n\
3703
    *(.zdebug_line)\n\
3704
  }\n\
3705
  .debug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3706
  {\n\
3707
    *(.debug_frame*)\n\
3708
  }\n\
3709
  .zdebug_frame BLOCK(__section_alignment__) (NOLOAD) :\n\
3710
  {\n\
3711
    *(.zdebug_frame*)\n\
3712
  }\n\
3713
  .debug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3714
  {\n\
3715
    *(.debug_str)\n\
3716
  }\n\
3717
  .zdebug_str BLOCK(__section_alignment__) (NOLOAD) :\n\
3718
  {\n\
3719
    *(.zdebug_str)\n\
3720
  }\n\
3721
  .debug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3722
  {\n\
3723
    *(.debug_loc)\n\
3724
  }\n\
3725
  .zdebug_loc BLOCK(__section_alignment__) (NOLOAD) :\n\
3726
  {\n\
3727
    *(.zdebug_loc)\n\
3728
  }\n\
3729
  .debug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3730
  {\n\
3731
    *(.debug_macinfo)\n\
3732
  }\n\
3733
  .zdebug_macinfo BLOCK(__section_alignment__) (NOLOAD) :\n\
3734
  {\n\
3735
    *(.zdebug_macinfo)\n\
3736
  }\n\
3737
  /* SGI/MIPS DWARF 2 extensions.  */\n\
3738
  .debug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3739
  {\n\
3740
    *(.debug_weaknames)\n\
3741
  }\n\
3742
  .zdebug_weaknames BLOCK(__section_alignment__) (NOLOAD) :\n\
3743
  {\n\
3744
    *(.zdebug_weaknames)\n\
3745
  }\n\
3746
  .debug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3747
  {\n\
3748
    *(.debug_funcnames)\n\
3749
  }\n\
3750
  .zdebug_funcnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3751
  {\n\
3752
    *(.zdebug_funcnames)\n\
3753
  }\n\
3754
  .debug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3755
  {\n\
3756
    *(.debug_typenames)\n\
3757
  }\n\
3758
  .zdebug_typenames BLOCK(__section_alignment__) (NOLOAD) :\n\
3759
  {\n\
3760
    *(.zdebug_typenames)\n\
3761
  }\n\
3762
  .debug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3763
  {\n\
3764
    *(.debug_varnames)\n\
3765
  }\n\
3766
  .zdebug_varnames BLOCK(__section_alignment__) (NOLOAD) :\n\
3767
  {\n\
3768
    *(.zdebug_varnames)\n\
3769
  }\n\
3770
  .debug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3771
  {\n\
3772
    *(.debug_macro)\n\
3773
  }\n\
3774
  .zdebug_macro BLOCK(__section_alignment__) (NOLOAD) :\n\
3775
  {\n\
3776
    *(.zdebug_macro)\n\
3777
  }\n\
3778
  /* DWARF 3.  */\n\
3779
  .debug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3780
  {\n\
3781
    *(.debug_ranges)\n\
3782
  }\n\
3783
  .zdebug_ranges BLOCK(__section_alignment__) (NOLOAD) :\n\
3784
  {\n\
3785
    *(.zdebug_ranges)\n\
3786
  }\n\
3787
  /* DWARF 4.  */\n\
3788
  .debug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3789
  {\n\
3790
    *(.debug_types .gnu.linkonce.wt.*)\n\
3791
  }\n\
3792
  .zdebug_types BLOCK(__section_alignment__) (NOLOAD) :\n\
3793
  {\n\
3794
    *(.zdebug_types .gnu.linkonce.wt.*)\n\
3795
  }\n\
3796
}\n\n"
3797
; }
3798
3799
3800
struct ld_emulation_xfer_struct ld_i386pe_emulation =
3801
{
3802
  gld_i386pe_before_parse,
3803
 
3804
 
3805
  gld_i386pe_after_parse,
3806
  gld_i386pe_after_open,
3807
  after_allocation_default,
3808
  set_output_arch_default,
3809
  ldemul_default_target,
3810
  gld_i386pe_before_allocation,
3811
  gld_i386pe_get_script,
3812
  "i386pe",
3813
  "pei-i386",
3814
  gld_i386pe_finish,
3815
  NULL, /* Create output section statements.  */
3816
  gld_i386pe_open_dynamic_archive,
3817
  gld_i386pe_place_orphan,
3818
  gld_i386pe_set_symbols,
3819
  NULL, /* parse_args */
3820
  gldi386pe_add_options,
3821
  gldi386pe_handle_option,
3822
  gld_i386pe_unrecognized_file,
3823
  gld_i386pe_list_options,
3824
  gld_i386pe_recognized_file,
3825
  gld_i386pe_find_potential_libraries,
3826
  NULL	/* new_vers_pattern.  */
3827
};
3828