Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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