[binutils-gdb] x32: Allow R_X86_64_PC64 for SFrame V3

H.J. Lu hjl@sourceware.org
Fri Jan 23 07:02:25 GMT 2026


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

commit 7487c98ff07a7c9a865c5c8b8db62cfa6e5bd966
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Jan 18 09:24:48 2026 +0800

    x32: Allow R_X86_64_PC64 for SFrame V3
    
    SFrame V3 generates R_X86_64_PC64 relocation, instead of R_X86_64_PC32,
    in .sframe section for x86-64.  Although x32 doesn't support SFrame,
    .sframe section can be found in x32 object converted from x86-64 object
    with objcopy, which only changes the ELF file class from ELFCLASS64 to
    ELFCLASS32 with all section contents unchanged.
    
    Update elf_x86_64_scan_relocs to allow R_X86_64_PC64 for x32 so that
    x32 object file with .sframe section can be used as x32 linker input.
    
    bfd/
    
            PR ld/33807
            * elf64-x86-64.c (elf_x86_64_scan_relocs): Allow R_X86_64_PC64
            for x32.
    
    ld/
    
            PR ld/33807
            * testsuite/ld-x86-64/sframe.rd: New file.
            * testsuite/ld-x86-64/sframe.s: Likewise.
            * testsuite/ld-x86-64/x86-64.exp: Run PR ld/33807 tests.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 bfd/elf64-x86-64.c                |  1 -
 ld/testsuite/ld-x86-64/sframe.rd  | 16 ++++++++++++++++
 ld/testsuite/ld-x86-64/sframe.s   | 10 ++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp | 30 ++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 84c558fd157..55102f83365 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2629,7 +2629,6 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info,
 
 	  case R_X86_64_DTPOFF64:
 	  case R_X86_64_TPOFF64:
-	  case R_X86_64_PC64:
 	  case R_X86_64_GOTOFF64:
 	  case R_X86_64_GOT64:
 	  case R_X86_64_GOTPCREL64:
diff --git a/ld/testsuite/ld-x86-64/sframe.rd b/ld/testsuite/ld-x86-64/sframe.rd
new file mode 100644
index 00000000000..cbdec3e30e7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe.rd
@@ -0,0 +1,16 @@
+Contents of the SFrame section .sframe:
+  Header :
+
+    Version: SFRAME_VERSION_3
+    Flags: SFRAME_F_FDE_SORTED,
+           SFRAME_F_FDE_FUNC_START_PCREL
+    CFA fixed RA offset: -8
+    Num FDEs: 1
+    Num FREs: 1
+
+  Function Index :
+
+    func idx \[0\]: pc = 0x1000, size = 1 bytes
+    STARTPC         CFA       FP        RA           
+    0000000000001000  sp\+8      u         f            
+#pass
diff --git a/ld/testsuite/ld-x86-64/sframe.s b/ld/testsuite/ld-x86-64/sframe.s
new file mode 100644
index 00000000000..59eedc80f98
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/sframe.s
@@ -0,0 +1,10 @@
+	.text
+	.p2align 4
+	.globl	foo
+	.type	foo, @function
+foo:
+	.cfi_startproc
+	ret
+	.cfi_endproc
+	.size	foo, .-foo
+	.section	.note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index aa5c90f8ca2..657805d5a3a 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -651,6 +651,36 @@ if ![ld_assemble $as "--64 $srcdir/$subdir/foo.s" tmpdir/foo64.o] {
     return
 }
 
+run_ld_link_tests [list \
+    [list \
+	"Build sframe.o" \
+	"" \
+	"" \
+	"--64 --gsframe" \
+	{sframe.s} \
+    ] \
+]
+
+set cmd "$objcopy -O elf32-x86-64 tmpdir/sframe.o tmpdir/sframe-x32.o"
+send_log "$cmd\n"
+set got [remote_exec host "$cmd"]
+if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+    send_log "$got\n"
+    fail "Convert x86-64 sframe.o to x32"
+} else {
+    run_ld_link_tests [list \
+	[list \
+	    "X32 DSO from x86-64 sframe.o" \
+	    "-shared --hash-style=both --no-rosegment -melf32_x86_64" \
+	    "tmpdir/sframe-x32.o" \
+	    "--x32 -mx86-used-note=yes" \
+	    {dummy.s} \
+	    {{readelf --sframe sframe.rd}} \
+	    "sframe-x32" \
+	] \
+    ]
+}
+
 run_dump_test "compressed1"
 run_dump_test "ilp32-1"
 run_dump_test "ilp32-2"


More information about the Binutils-cvs mailing list