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

Jan Beulich jbeulich@suse.com
Mon Aug 4 09:19:45 GMT 2025


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).

--- 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.  */
--- 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.  */
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -3739,8 +3739,11 @@ pe_exe_build_sections (bfd *abfd, struct
 {
   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
--- 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 mailing list