[binutils-gdb] ld/PE: respect --enable-reloc-section even when .reloc isn't created by default

Jan Beulich jbeulich@sourceware.org
Fri Oct 10 14:05:23 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2817be508d422a9e534d5cc03077be501794148b

commit 2817be508d422a9e534d5cc03077be501794148b
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Oct 10 16:00:04 2025 +0200

    ld/PE: respect --enable-reloc-section even when .reloc isn't created by default
    
    Even when !DLL_SUPPORT, an executable may still want to have base
    relocations created. Avoid doing so by default, though, to not alter
    prior behavior.
    
    With this, an xfail can (and actually should) go away (or else we end up
    with an XPASS).

Diff:
---
 ld/emultempl/pe.em         | 8 ++++++++
 ld/emultempl/pep.em        | 8 ++++++++
 ld/pe-dll.c                | 7 +++++--
 ld/testsuite/ld-pe/reloc.d | 1 -
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index b522687c1d5..c66c75fb06d 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -228,6 +228,8 @@ fragment <<EOF
   link_info.pei386_auto_import = ${default_auto_import};
   /* Use by default version.  */
   link_info.pei386_runtime_pseudo_reloc = DEFAULT_PSEUDO_RELOC_VERSION;
+#else
+  pe_dll_enable_reloc_section = 0;
 #endif
 }
 

@@ -1594,6 +1596,9 @@ gld${EMULATION_NAME}_after_open (void)
   else
     pe_exe_build_sections (link_info.output_bfd, &link_info);
 #endif
+#else /* !DLL_SUPPORT */
+  if (!bfd_link_relocatable (&link_info))
+    pe_exe_build_sections (link_info.output_bfd, &link_info);
 #endif /* DLL_SUPPORT */
 
 #if defined(TARGET_IS_armpe) || defined(TARGET_IS_arm_wince_pe)
@@ -2104,6 +2109,9 @@ gld${EMULATION_NAME}_finish (void)
 
   if (pe_out_def_filename)
     pe_dll_generate_def_file (pe_out_def_filename);
+#else /* !DLL_SUPPORT */
+  if (!bfd_link_relocatable (&link_info))
+    pe_exe_fill_sections (link_info.output_bfd, &link_info);
 #endif /* DLL_SUPPORT */
 
   /* I don't know where .idata gets set as code, but it shouldn't be.  */
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 60a833947bd..0d059fb6400 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -246,6 +246,8 @@ gld${EMULATION_NAME}_before_parse (void)
   config.has_shared = 1;
   link_info.pei386_auto_import = 1;
   link_info.pei386_runtime_pseudo_reloc = 2; /* Use by default version 2.  */
+#else
+  pep_dll_enable_reloc_section = 0;
 #endif
 }
 

@@ -1602,6 +1604,9 @@ gld${EMULATION_NAME}_after_open (void)
   else
     pep_exe_build_sections (link_info.output_bfd, &link_info);
 #endif
+#else /* !DLL_SUPPORT */
+  if (!bfd_link_relocatable (&link_info))
+    pep_exe_build_sections (link_info.output_bfd, &link_info);
 #endif /* DLL_SUPPORT */
 
   {
@@ -1944,6 +1949,9 @@ gld${EMULATION_NAME}_finish (void)
 
   if (pep_out_def_filename)
     pep_dll_generate_def_file (pep_out_def_filename);
+#else /* !DLL_SUPPORT */
+  if (!bfd_link_relocatable (&link_info))
+    pep_exe_fill_sections (link_info.output_bfd, &link_info);
 #endif /* DLL_SUPPORT */
 
   /* I don't know where .idata gets set as code, but it shouldn't be.  */
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 6fb45f0d6aa..bbf16e71397 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -3738,8 +3738,11 @@ pe_exe_build_sections (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   pe_dll_id_target (bfd_get_target (abfd));
   pe_output_file_set_long_section_names (abfd);
-  build_filler_bfd (0);
-  pe_output_file_set_long_section_names (filler_bfd);
+  if (pe_dll_enable_reloc_section)
+    {
+      build_filler_bfd (false);
+      pe_output_file_set_long_section_names (filler_bfd);
+    }
 }
 
 void
diff --git a/ld/testsuite/ld-pe/reloc.d b/ld/testsuite/ld-pe/reloc.d
index eab8dfb9b02..55888c3bdf1 100644
--- a/ld/testsuite/ld-pe/reloc.d
+++ b/ld/testsuite/ld-pe/reloc.d
@@ -1,7 +1,6 @@
 #name: PE base relocations
 #ld: --enable-reloc-section
 #objdump: -p
-#xfail: mcore-*-*
 
 .*:     file format .*


More information about the Binutils-cvs mailing list