Subversion Repositories Kolibri OS

Rev

Rev 5199 | Details | Compare with Previous | Last modification | View Log | RSS feed

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