]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sframe: Allow input R_*_NONE relocations
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 12 Jul 2025 20:56:16 +0000 (04:56 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 14 Jul 2025 21:35:35 +0000 (05:35 +0800)
"ld -r" generates R_*_NONE relocations in sframe section if input
relocations in sframe section are against discarded section.  Allow
input R_*_NONE relocations if there are more relocation entries than
SFrame entries, instead of assuming number of SFrame entries == number
of relocation entries.

bfd/

PR ld/33127
* elf-sframe.c (sframe_decoder_init_func_bfdinfo): Allow input
R_*_NONE relocations if there are more relocation entries than
SFrame entries.

ld/

PR ld/33127
* testsuite/ld-x86-64/sframe-reloc-2a.s: New file.
* testsuite/ld-x86-64/sframe-reloc-2b.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/33127 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elf-sframe.c
ld/testsuite/ld-x86-64/sframe-reloc-2a.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/sframe-reloc-2b.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index b709e590a2dc9240f8910046d126734f5ac90925..2cb732c3016f80c11f0bb77d1ce54ae2f3a2121d 100644 (file)
@@ -120,7 +120,6 @@ sframe_decoder_init_func_bfdinfo (bfd *abfd,
   if ((sec->flags & SEC_LINKER_CREATED) && cookie->rels == NULL)
     return true;
 
-  BFD_ASSERT (cookie->rels + fde_count == cookie->relend);
   rel = cookie->rels;
   for (i = 0; i < fde_count; i++)
     {
@@ -132,6 +131,14 @@ sframe_decoder_init_func_bfdinfo (bfd *abfd,
       rel++;
     }
 
+  /* If there are more relocation entries, they must be R_*_NONE which
+     may be generated from relocations against discarded sections by
+     ld -r.  */
+  for (; rel < cookie->relend; rel++)
+   if (rel->r_info != 0)
+     break;
+  BFD_ASSERT (rel == cookie->relend);
+
   return true;
 }
 
diff --git a/ld/testsuite/ld-x86-64/sframe-reloc-2a.s b/ld/testsuite/ld-x86-64/sframe-reloc-2a.s
new file mode 100644 (file)
index 0000000..8cd8694
--- /dev/null
@@ -0,0 +1,7 @@
+       .section        sect, "axG", @progbits, sectgroup, comdat
+       .global _start
+_start:
+       .cfi_startproc
+       call    foo
+       .cfi_endproc
+       .section        .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/sframe-reloc-2b.s b/ld/testsuite/ld-x86-64/sframe-reloc-2b.s
new file mode 100644 (file)
index 0000000..9484636
--- /dev/null
@@ -0,0 +1,31 @@
+       .section        sect, "axG", @progbits, sectgroup, comdat
+       .cfi_startproc
+# Test intention is that LSDA must be provided by the discarded FDE.
+# DW_EH_PE_udata8 = 4
+# DW_EH_PE_udata4 = 3
+       .ifdef          ELF64
+       .cfi_lsda 4, lsda
+       .else
+       .cfi_lsda 3, lsda
+       .endif
+       .skip 16
+       .cfi_endproc
+
+       .text
+       .globl  foo
+       .type   foo, @function
+foo:
+       .cfi_startproc
+       pushq   %rbp
+       .cfi_def_cfa_offset 16
+       .cfi_offset 6, -16
+       movq    %rsp, %rbp
+       .cfi_def_cfa_register 6
+       popq    %rbp
+       .cfi_def_cfa 7, 8
+       ret
+       .cfi_endproc
+
+       .section        .gcc_except_table, "a", @progbits
+lsda:
+       .section        .note.GNU-stack,"",@progbits
index a682b1374fa968f4bf876117949004e0910aacb6..3d873a79b789d9f0e01a3cb15fd74568d7f3278d 100644 (file)
@@ -572,6 +572,27 @@ if { ![skip_sframe_tests] } {
     run_dump_test "sframe-ibt-plt-1"
     run_dump_test "sframe-pltgot-1"
     run_dump_test "sframe-pltgot-2"
+
+    run_ld_link_tests [list \
+       [list \
+           "Build sframe-reloc-2.o" \
+           "-m elf_x86_64 -r" \
+           "" \
+           "--64 --gsframe" \
+           {sframe-reloc-2a.s sframe-reloc-2b.s} \
+           "" \
+           "sframe-reloc-2.o" \
+       ] \
+       [list \
+           "Build sframe-reloc-2" \
+           "-m elf_x86_64 tmpdir/sframe-reloc-2.o" \
+           "" \
+           "--64 --gsframe" \
+           {dummy.s} \
+           "" \
+           "sframe-reloc-2" \
+       ] \
+    ]
 }
 
 if ![istarget "x86_64-*-linux*"] {