[PATCH 7/7] s390: handle a local IFUNC referenced only from a non-alloc section
Harshit Kumar
harshit7kr@gmail.com
Wed Nov 11 11:03:50 GMT 2026
A local STT_GNU_IFUNC symbol gets its PLT slot from the relocation scan,
which skips non-SEC_ALLOC sections (PR ld/26080). When only such a
section refers to it, elf_s390_relocate_section fails the link with no
diagnostic, or uses the unallocated -1 slot offset when another local
IFUNC in the object has a slot. A global symbol without a PLT slot is
relocated against itself there, for R_390_32 and R_390_64 in any
non-alloc section; do the same for the local one, in the 31-bit and
64-bit backends. Since s390 does not distinguish the section kind, it
does not use _bfd_elf_ifunc_nonalloc_reloc.
bfd/
PR ld/34988
* elf32-s390.c (elf_s390_local_ifunc_plt_p): New function.
(elf_s390_relocate_section): Relocate a reference from a
non-SEC_ALLOC section to a local STT_GNU_IFUNC symbol without a
PLT slot against the symbol itself.
* elf64-s390.c (elf_s390_local_ifunc_plt_p): New function.
(elf_s390_relocate_section): Likewise.
ld/
PR ld/34988
* testsuite/ld-s390/ifunc-skip-nonalloc.d: New test.
* testsuite/ld-s390/ifunc-skip-nonalloc.s: New file.
* testsuite/ld-s390/ifunc-note-nonalloc.d: New test.
* testsuite/ld-s390/ifunc-note-nonalloc.s: New file.
* testsuite/ld-s390/ifunc-skip-nonalloc-31.d: New test.
* testsuite/ld-s390/ifunc-skip-nonalloc-31.s: New file.
* testsuite/ld-s390/ifunc-note-nonalloc-31.d: New test.
* testsuite/ld-s390/ifunc-note-nonalloc-31.s: New file.
* testsuite/ld-s390/s390.exp: Run them.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elf32-s390.c | 20 ++++++++++++++++++-
bfd/elf64-s390.c | 20 ++++++++++++++++++-
ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d | 8 ++++++++
ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s | 11 ++++++++++
ld/testsuite/ld-s390/ifunc-note-nonalloc.d | 8 ++++++++
ld/testsuite/ld-s390/ifunc-note-nonalloc.s | 11 ++++++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d | 8 ++++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s | 11 ++++++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc.d | 8 ++++++++
ld/testsuite/ld-s390/ifunc-skip-nonalloc.s | 11 ++++++++++
ld/testsuite/ld-s390/s390.exp | 4 ++++
11 files changed, 118 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-note-nonalloc.s
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-skip-nonalloc.s
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 1f2e94aa94..2cd8f77938 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -1998,6 +1998,22 @@ invalid_tls_insn (bfd *input_bfd,
bfd_set_error (bfd_error_bad_value);
}
+/* Return TRUE if the local STT_GNU_IFUNC symbol R_SYMNDX of ABFD has a
+ PLT slot. The relocation scan creates the slot, so there is none when
+ only a non-SEC_ALLOC section, which the scan skips, refers to the
+ symbol. elf_s390_relocate_section then relocates the reference
+ against the symbol itself, as it does for a global STT_GNU_IFUNC
+ symbol without a PLT slot. */
+
+static bool
+elf_s390_local_ifunc_plt_p (bfd *abfd, unsigned long r_symndx)
+{
+ struct plt_entry *local_plt = elf_s390_local_plt (abfd);
+
+ return (local_plt != NULL
+ && local_plt[r_symndx].plt.offset != (bfd_vma) -1);
+}
+
/* Relocate a 390 ELF section. */
static int
@@ -2067,7 +2083,9 @@ elf_s390_relocate_section (struct bfd_link_info *info,
{
sym = local_syms + r_symndx;
sec = local_sections[r_symndx];
- if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
+ && ((input_section->flags & SEC_ALLOC) != 0
+ || elf_s390_local_ifunc_plt_p (input_bfd, r_symndx)))
{
struct plt_entry *local_plt = elf_s390_local_plt (input_bfd);
if (local_plt == NULL)
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 23482e2646..ce23fa2971 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2285,6 +2285,22 @@ invalid_tls_insn (bfd *input_bfd,
bfd_set_error (bfd_error_bad_value);
}
+/* Return TRUE if the local STT_GNU_IFUNC symbol R_SYMNDX of ABFD has a
+ PLT slot. The relocation scan creates the slot, so there is none when
+ only a non-SEC_ALLOC section, which the scan skips, refers to the
+ symbol. elf_s390_relocate_section then relocates the reference
+ against the symbol itself, as it does for a global STT_GNU_IFUNC
+ symbol without a PLT slot. */
+
+static bool
+elf_s390_local_ifunc_plt_p (bfd *abfd, unsigned long r_symndx)
+{
+ struct plt_entry *local_plt = elf_s390_local_plt (abfd);
+
+ return (local_plt != NULL
+ && local_plt[r_symndx].plt.offset != (bfd_vma) -1);
+}
+
/* Relocate a 390 ELF section. */
static int
@@ -2357,7 +2373,9 @@ elf_s390_relocate_section (struct bfd_link_info *info,
sym = local_syms + r_symndx;
sec = local_sections[r_symndx];
- if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
+ && ((input_section->flags & SEC_ALLOC) != 0
+ || elf_s390_local_ifunc_plt_p (input_bfd, r_symndx)))
{
struct plt_entry *local_plt = elf_s390_local_plt (input_bfd);
if (local_plt == NULL)
diff --git a/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d b/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d
new file mode 100644
index 0000000000..136803a803
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a non-alloc note section (31-bit)
+#as: -m31
+#ld: -e _start -Ttext=0x10000 -melf_s390
+#objdump: -s -j .note.probe
+#...
+Contents of section .note.probe:
+ 0000 00010000 +.*
+#pass
diff --git a/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s b/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s
new file mode 100644
index 0000000000..416de5ef3b
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .section .note.probe,"",@note
+ .long ifn
diff --git a/ld/testsuite/ld-s390/ifunc-note-nonalloc.d b/ld/testsuite/ld-s390/ifunc-note-nonalloc.d
new file mode 100644
index 0000000000..1c4fd67e8f
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-note-nonalloc.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a non-alloc note section
+#as: -m64
+#ld: -e _start -Ttext=0x10000 -melf64_s390
+#objdump: -s -j .note.probe
+#...
+Contents of section .note.probe:
+ 0000 00000000 00010000 +.*
+#pass
diff --git a/ld/testsuite/ld-s390/ifunc-note-nonalloc.s b/ld/testsuite/ld-s390/ifunc-note-nonalloc.s
new file mode 100644
index 0000000000..226bca0e67
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-note-nonalloc.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .section .note.probe,"",@note
+ .quad ifn
diff --git a/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d b/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d
new file mode 100644
index 0000000000..8f68965904
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a debugging section (31-bit)
+#as: -m31
+#ld: -e _start -Ttext=0x10000 -melf_s390
+#objdump: -s -j .debug_info
+#...
+Contents of section .debug_info:
+ 0000 00010000 +.*
+#pass
diff --git a/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s b/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s
new file mode 100644
index 0000000000..1cfb2f10d8
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-skip-nonalloc-31.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .section .debug_info,"",@progbits
+ .long ifn
diff --git a/ld/testsuite/ld-s390/ifunc-skip-nonalloc.d b/ld/testsuite/ld-s390/ifunc-skip-nonalloc.d
new file mode 100644
index 0000000000..8c2647fff2
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-skip-nonalloc.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a debugging section
+#as: -m64
+#ld: -e _start -Ttext=0x10000 -melf64_s390
+#objdump: -s -j .debug_info
+#...
+Contents of section .debug_info:
+ 0000 00000000 00010000 +.*
+#pass
diff --git a/ld/testsuite/ld-s390/ifunc-skip-nonalloc.s b/ld/testsuite/ld-s390/ifunc-skip-nonalloc.s
new file mode 100644
index 0000000000..d36d3c5118
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-skip-nonalloc.s
@@ -0,0 +1,11 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .section .debug_info,"",@progbits
+ .quad ifn
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index 80536e2e39..56631fd3b2 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -180,6 +180,8 @@ if { [istarget "s390-*-*"] || [istarget "s390x-*-*"] } {
run_dump_test "pr26918-1"
run_dump_test "reloccheck-1"
run_dump_test "reloctlsle-1"
+ run_dump_test "ifunc-skip-nonalloc-31"
+ run_dump_test "ifunc-note-nonalloc-31"
}
@@ -188,6 +190,8 @@ if [istarget "s390x-*-*"] {
run_dump_test "weakundef-1b"
run_dump_test "weakundef-2b"
+ run_dump_test "ifunc-skip-nonalloc"
+ run_dump_test "ifunc-note-nonalloc"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
--
2.55.0
More information about the Binutils
mailing list