The exported _pei386_runtime_relocator function currently only exists as
a non-functional stub in the Cygwin runtime, merely to satisfy this
reference synthesized in ld [1].

The function still has contents in the MinGW runtime [2], but is already
referenced by being explcitly called at crt startup/dll load.

We'd like to drop the (slightly confusing) stub from the Cygwin runtime,
especially in possible future architectures (e.g aarch64), where
backwards compatibilty concerns don't exist.

So, for PE+ targets, stop explicitly emitting a reference to
_pei386_runtime_relocator in the linker.

(The archeological record is unclear why this functionality exists in
ld.

Since --enable-runtime-pseudo-reloc-v1 exists for 32-bit PE arches, and
out of an abundance of caution, keep emitting it for those targets (i.e.
i386) where it conceivably might still be needed or useful with an
ancient runtime.)

Cc'ed to mingw-w64-public list.

[1] 
https://cygwin.com/cgit/newlib-cygwin/tree/winsup/cygwin/lib/pseudo-reloc-dummy.c
[2] 
https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/crt/pseudo-reloc.c#l479

Signed-off-by: Jon Turney <[email protected]>
Cc: [email protected]
---
 ld/pe-dll.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index f43bd14896e..be5722fa8ad 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -170,7 +170,9 @@ static struct bfd_section *edata_s, *reloc_s;
 static unsigned char *edata_d, *reloc_d;
 static unsigned char *reloc_d = NULL;
 static size_t edata_sz, reloc_sz = 0;
+#ifndef pe_use_plus
 static int runtime_pseudo_relocs_created = 0;
+#endif
 static bool runtime_pseudp_reloc_v2_init = false;
 
 typedef struct
@@ -1773,7 +1775,7 @@ generate_reloc (bfd *abfd, struct bfd_link_info *info)
   /* This can happen for example when LTO has eliminated all code.  */
   if (total_relocs == 0)
     return;
-  
+
   /* At this point, we have total_relocs relocation addresses in
      reloc_addresses, which are all suitable for the .reloc section.
      We must now create the new sections.  */
@@ -2798,6 +2800,7 @@ make_runtime_pseudo_reloc (const char *name 
ATTRIBUTE_UNUSED,
   return abfd;
 }
 
+#ifndef pe_use_plus
 /*     .section        .rdata
        .rva            __pei386_runtime_relocator  */
 
@@ -2841,6 +2844,7 @@ pe_create_runtime_relocator_reference (bfd *parent)
   bfd_make_readable (abfd);
   return abfd;
 }
+#endif
 
 void
 pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
@@ -2894,11 +2898,15 @@ pe_create_import_fixup (arelent *rel, asection *s, 
bfd_vma addend, char *name,
                                     link_info.output_bfd);
       add_bfd_to_link (b, bfd_get_filename (b), &link_info);
 
+      /* We think this is entirely useless, but emit a reference to the
+        relocator on the i386 target, just in case. */
+#ifndef pe_use_plus
       if (runtime_pseudo_relocs_created++ == 0)
        {
          b = pe_create_runtime_relocator_reference (link_info.output_bfd);
          add_bfd_to_link (b, bfd_get_filename (b), &link_info);
        }
+#endif
     }
 
   else if (addend != 0)
-- 
2.51.0



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to