[binutils-gdb] ld/PE: adjust .reloc and .edata section flags

Jan Beulich jbeulich@sourceware.org
Fri Oct 10 14:04:51 GMT 2025


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

commit 3f80863fbf9b8dfb70c8dbf1f71220c4910318f9
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Oct 10 15:57:36 2025 +0200

    ld/PE: adjust .reloc and .edata section flags
    
    Both really want to be SEC_DATA, even if _bfd_XXi_swap_scnhdr_out()
    makes sure that IMAGE_SCN_CNT_INITIALIZED_DATA is set in the final
    section header. Otoh, .reloc - being IMAGE_SCN_MEM_DISCARDABLE at least
    by default - shouldn't have SEC_ALLOC set.
    
    In an early form of the patch I also dropped SEC_ALLOC for .reloc. While
    I've undone that, I think the then necessary testsuite adjustments still
    want retaining:
    
    1) I can't explain why the removal of _both_ SEC_ALLOC and SEC_LOAD for
    .reloc causes ld-scripts/provide-8 to XPASS on PE targets. Placing a
    symbol outside of the image isn't well-defined in PE anyway though, so
    convert the xfail-s to notarget-s.
    
    2) The ld-pe/pe-aarch64 fragility is now dealt with in a separate patch.

Diff:
---
 ld/pe-dll.c                         | 3 ++-
 ld/testsuite/ld-scripts/provide-8.d | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index c730b547502..2ce8ac5c817 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -1081,6 +1081,7 @@ build_filler_bfd (bool include_edata)
       edata_s = bfd_make_section_old_way (filler_bfd, ".edata");
       if (edata_s == NULL
 	  || !bfd_set_section_flags (edata_s, (SEC_HAS_CONTENTS
+					       | SEC_DATA
 					       | SEC_ALLOC
 					       | SEC_LOAD
 					       | SEC_KEEP
@@ -1095,7 +1096,7 @@ build_filler_bfd (bool include_edata)
   reloc_s = bfd_make_section_old_way (filler_bfd, ".reloc");
   if (reloc_s == NULL
       || !bfd_set_section_flags (reloc_s, (SEC_HAS_CONTENTS
-					   | SEC_ALLOC
+					   | SEC_DATA
 					   | SEC_LOAD
 					   | SEC_KEEP
 					   | SEC_IN_MEMORY)))
diff --git a/ld/testsuite/ld-scripts/provide-8.d b/ld/testsuite/ld-scripts/provide-8.d
index 1dd5553ed32..250b0441479 100644
--- a/ld/testsuite/ld-scripts/provide-8.d
+++ b/ld/testsuite/ld-scripts/provide-8.d
@@ -1,7 +1,9 @@
 #source: provide-5.s
 #ld: -T provide-8.t
 #nm: -B
-#xfail: mmix-*-* *-*-pe spu-*-* *-*-mingw* *-*-cygwin
+#xfail: mmix-*-* spu-*-*
+# Placing a symbol outside of the image isn't well-defined in PE.
+#notarget: *-*-pe *-*-mingw* *-*-cygwin
 
 #...
 0+4000 D __FOO


More information about the Binutils-cvs mailing list