Subversion Repositories Kolibri OS

Rev

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

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