[binutils-gdb/binutils-2_45-branch] x86-64: Remove sframe relocs against discarded sections

H.J. Lu hjl@sourceware.org
Wed Jul 16 15:10:06 GMT 2025


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

commit 39363ad0a0be0f93a5acc3fcf1bd846926758f61
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Jul 15 10:41:25 2025 +0800

    x86-64: Remove sframe relocs against discarded sections
    
    Since unlike eh_frame editing code, sframe editing code keeps
    R_X86_64_NONE reloc as is, its r_offset is wrong, we must not
    generate R_X86_64_NONE reloc in sframe section against discarded
    sections for "ld -r".
    
    bfd/
    
            PR ld/33156
            * elf64-x86-64.c (elf_x86_64_relocate_section): Also remove
            sframe relocations against discarded sections for "ld -r".
    
    ld/
    
            PR ld/33156
            * testsuite/ld-elf/eh-group.exp (as_gsframe): New.
            Assemble eh-group.o with $as_gsframe.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
    (cherry picked from commit d7f343eaad3f34c76657b9996e6253b4f9a218d5)

Diff:
---
 bfd/elf64-x86-64.c               | 10 +++++++---
 ld/testsuite/ld-elf/eh-group.exp |  7 ++++++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index c40a0c5488a..ebd2eb4299f 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3268,10 +3268,14 @@ elf_x86_64_relocate_section (bfd *output_bfd,
 	  wrel->r_addend = 0;
 
 	  /* For ld -r, remove relocations in debug sections against
-	     sections defined in discarded sections.  Not done for
-	     eh_frame editing code expects to be present.  */
+	     sections defined in discarded sections, including sframe
+	     sections.  Not done for eh_frame editing code expects to
+	     be present.  NB: Since sframe code keeps R_X86_64_NONE
+	     reloc as is, its r_offset is wrong, we must not generate
+	     R_X86_64_NONE reloc in sframe section.  */
 	   if (bfd_link_relocatable (info)
-	       && (input_section->flags & SEC_DEBUGGING))
+	       && ((input_section->flags & SEC_DEBUGGING) != 0
+		   || elf_section_type (input_section) == SHT_GNU_SFRAME))
 	     wrel--;
 
 	  continue;
diff --git a/ld/testsuite/ld-elf/eh-group.exp b/ld/testsuite/ld-elf/eh-group.exp
index 1656c2ee651..c1571414e0c 100644
--- a/ld/testsuite/ld-elf/eh-group.exp
+++ b/ld/testsuite/ld-elf/eh-group.exp
@@ -40,6 +40,11 @@ if ![is_elf_format] {
     return
 }
 
+set as_gsframe ""
+if { [gas_sframe_check] } {
+    set as_gsframe "--gsframe"
+}
+
 # alpha-linux-gnu does not support 64-bit relocations:
 #   relocation truncated to fit: REFLONG against `.gcc_except_table'
 # arm-eabi does not support 64-bit relocations:
@@ -58,7 +63,7 @@ if [is_elf64 "tmpdir/eh-group1size.o"] {
 
 set build_tests_ld [list			\
   [list "Build eh-group1.o"			\
-   "-r" "" "$as_options"			\
+   "-r" "" "$as_options $as_gsframe"		\
    {eh-group1.s eh-group2.s} {} "eh-group.o"]	\
 ]


More information about the Binutils-cvs mailing list