LoongArch: Fix LD check fails.
[binutils-gdb.git] / bfd / pe-x86_64.c
index 1c383293e115492c3fe159c680109d2d6426e664..f1e92b3c6b01a33daeaa114d6365f6de0d7229b0 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD back-end for Intel/AMD x86_64 PECOFF files.
 /* BFD back-end for Intel/AMD x86_64 PECOFF files.
-   Copyright (C) 2006-2020 Free Software Foundation, Inc.
+   Copyright (C) 2006-2022 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
 
    This file is part of BFD, the Binary File Descriptor library.
 
 
    Written by Kai Tietz, OneVision Software GmbH&CoKg.  */
 
 
    Written by Kai Tietz, OneVision Software GmbH&CoKg.  */
 
+#define PEI_HEADERS
 #include "sysdep.h"
 #include "bfd.h"
 #include "sysdep.h"
 #include "bfd.h"
+#include "libbfd.h"
+#include "libiberty.h"
+#include "coff/x86_64.h"
+#include "coff/internal.h"
+#include "coff/pe.h"
+#include "libcoff.h"
 
 #define TARGET_SYM             x86_64_pe_vec
 #define TARGET_NAME            "pe-x86-64"
 
 #define TARGET_SYM             x86_64_pe_vec
 #define TARGET_NAME            "pe-x86-64"
@@ -30,7 +37,7 @@
 #define COFF_WITH_PE
 #define COFF_WITH_pex64
 #define COFF_WITH_PE_BIGOBJ
 #define COFF_WITH_PE
 #define COFF_WITH_pex64
 #define COFF_WITH_PE_BIGOBJ
-#define PCRELOFFSET            TRUE
+#define PCRELOFFSET            true
 #if defined (USE_MINGW64_LEADING_UNDERSCORES)
 #define TARGET_UNDERSCORE      '_'
 #else
 #if defined (USE_MINGW64_LEADING_UNDERSCORES)
 #define TARGET_UNDERSCORE      '_'
 #else
 
 /* The function pex64_bfd_print_pdata is implemented in pei-x86_64.c
    source, but has be extended to also handle pe objects.  */
 
 /* The function pex64_bfd_print_pdata is implemented in pei-x86_64.c
    source, but has be extended to also handle pe objects.  */
-extern bfd_boolean pex64_bfd_print_pdata (bfd *, void *);
+extern bool pex64_bfd_print_pdata (bfd *, void *);
 
 #define bfd_pe_print_pdata   pex64_bfd_print_pdata
 
 
 #define bfd_pe_print_pdata   pex64_bfd_print_pdata
 
-#include "coff-x86_64.c"
+static bool
+pex64_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
+{
+  if (bfd_link_pde (info)
+      && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
+    {
+      /* NB: When linking Windows x86-64 relocatable object files to
+        generate ELF executable, create an indirect reference to
+        __executable_start for __ImageBase to support R_AMD64_IMAGEBASE
+        relocation which is relative to __ImageBase.  */
+      struct bfd_link_hash_entry *h, *hi;
+      hi = bfd_link_hash_lookup (info->hash, "__ImageBase", true, false,
+                                false);
+      if (hi->type == bfd_link_hash_new
+         || hi->type == bfd_link_hash_undefined
+         || hi->type == bfd_link_hash_undefweak)
+       {
+         h = bfd_link_hash_lookup (info->hash, "__executable_start",
+                                   true, false, true);
+         hi->type = bfd_link_hash_indirect;
+         hi->u.i.link = h;
+       }
+    }
+
+  return _bfd_coff_link_add_symbols (abfd, info);
+}
 
 
+#define coff_bfd_link_add_symbols pex64_link_add_symbols
+
+#include "coff-x86_64.c"