[PATCH v2 6/6] s390: handle a local IFUNC referenced only from a non-alloc section
Harshit Kumar
harshit7kr@gmail.com
Sat Nov 14 09:38:29 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 (ld -r included), or uses the unallocated -1 slot offset when
another local IFUNC in the object has a slot. A global symbol is
relocated against itself there for R_390_8 to R_390_64 (up to R_390_32 in
the 31-bit backend) in any non-alloc section, whether it has a PLT slot or
not. Do the same for the local one, in the 31-bit and 64-bit backends,
including when an alloc section has given it a slot: it got the slot's
address before. Other relocations in a non-alloc section still use the
slot if there is one.
bfd/
PR ld/34988
* elf32-s390.c (elf_s390_local_ifunc_plt_p): New function.
(elf_s390_relocate_section): Use it, to relocate a reference from
a non-SEC_ALLOC section to a local STT_GNU_IFUNC symbol 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-debug-nonalloc.d: New test.
* testsuite/ld-s390/ifunc-debug-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-plt-nonalloc.d: New test.
* testsuite/ld-s390/ifunc-plt-nonalloc.s: New file.
* testsuite/ld-s390/ifunc-debug-nonalloc-31.d: New test.
* testsuite/ld-s390/ifunc-debug-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/ifunc-plt-nonalloc-31.d: New test.
* testsuite/ld-s390/ifunc-plt-nonalloc-31.s: New file.
* testsuite/ld-s390/s390.exp: Run them.
Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
bfd/elf32-s390.c | 34 +++++++++++++++++-
bfd/elf64-s390.c | 35 ++++++++++++++++++-
.../ld-s390/ifunc-debug-nonalloc-31.d | 8 +++++
.../ld-s390/ifunc-debug-nonalloc-31.s | 11 ++++++
ld/testsuite/ld-s390/ifunc-debug-nonalloc.d | 8 +++++
ld/testsuite/ld-s390/ifunc-debug-nonalloc.s | 11 ++++++
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-plt-nonalloc-31.d | 8 +++++
ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s | 13 +++++++
ld/testsuite/ld-s390/ifunc-plt-nonalloc.d | 8 +++++
ld/testsuite/ld-s390/ifunc-plt-nonalloc.s | 13 +++++++
ld/testsuite/ld-s390/s390.exp | 6 ++++
15 files changed, 191 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-debug-nonalloc.s
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-plt-nonalloc-31.d
create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s
create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc.d
create mode 100644 ld/testsuite/ld-s390/ifunc-plt-nonalloc.s
diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 1f2e94aa94..cd5bd41e88 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -1998,6 +1998,36 @@ invalid_tls_insn (bfd *input_bfd,
bfd_set_error (bfd_error_bad_value);
}
+/* Return TRUE if relocation R_TYPE in INPUT_SECTION against the local
+ STT_GNU_IFUNC symbol R_SYMNDX of ABFD goes to the symbol's PLT slot.
+ A non-SEC_ALLOC section is not loaded, so, as for a global
+ STT_GNU_IFUNC symbol, R_390_8 to R_390_32 in it are relocated against
+ the symbol itself. So are other relocations in it when there is no
+ slot: the relocation scan, which creates the slot, skips such
+ sections. */
+
+static bool
+elf_s390_local_ifunc_plt_p (const bfd *abfd, const asection *input_section,
+ unsigned long r_symndx, unsigned int r_type)
+{
+ const struct plt_entry *local_plt;
+
+ if ((input_section->flags & SEC_ALLOC) != 0)
+ return true;
+
+ switch (r_type)
+ {
+ case R_390_8:
+ case R_390_16:
+ case R_390_32:
+ return false;
+ default:
+ 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 +2097,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
+ && elf_s390_local_ifunc_plt_p (input_bfd, input_section,
+ r_symndx, r_type))
{
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..df9ca554b7 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2285,6 +2285,37 @@ invalid_tls_insn (bfd *input_bfd,
bfd_set_error (bfd_error_bad_value);
}
+/* Return TRUE if relocation R_TYPE in INPUT_SECTION against the local
+ STT_GNU_IFUNC symbol R_SYMNDX of ABFD goes to the symbol's PLT slot.
+ A non-SEC_ALLOC section is not loaded, so, as for a global
+ STT_GNU_IFUNC symbol, R_390_8 to R_390_64 in it are relocated against
+ the symbol itself. So are other relocations in it when there is no
+ slot: the relocation scan, which creates the slot, skips such
+ sections. */
+
+static bool
+elf_s390_local_ifunc_plt_p (const bfd *abfd, const asection *input_section,
+ unsigned long r_symndx, unsigned int r_type)
+{
+ const struct plt_entry *local_plt;
+
+ if ((input_section->flags & SEC_ALLOC) != 0)
+ return true;
+
+ switch (r_type)
+ {
+ case R_390_8:
+ case R_390_16:
+ case R_390_32:
+ case R_390_64:
+ return false;
+ default:
+ 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 +2388,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
+ && elf_s390_local_ifunc_plt_p (input_bfd, input_section,
+ r_symndx, r_type))
{
struct plt_entry *local_plt = elf_s390_local_plt (input_bfd);
if (local_plt == NULL)
diff --git a/ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.d b/ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.d
new file mode 100644
index 0000000000..fa84ffce4a
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a debugging section (31-bit)
+#as: -m31
+#ld: -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-debug-nonalloc-31.s b/ld/testsuite/ld-s390/ifunc-debug-nonalloc-31.s
new file mode 100644
index 0000000000..1cfb2f10d8
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-debug-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-debug-nonalloc.d b/ld/testsuite/ld-s390/ifunc-debug-nonalloc.d
new file mode 100644
index 0000000000..bd7c0207bb
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-debug-nonalloc.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol referenced only from a debugging section
+#as: -m64
+#ld: -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-debug-nonalloc.s b/ld/testsuite/ld-s390/ifunc-debug-nonalloc.s
new file mode 100644
index 0000000000..d36d3c5118
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-debug-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/ifunc-note-nonalloc-31.d b/ld/testsuite/ld-s390/ifunc-note-nonalloc-31.d
new file mode 100644
index 0000000000..c067d057c8
--- /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: -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..88e8e3e442
--- /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: -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-plt-nonalloc-31.d b/ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.d
new file mode 100644
index 0000000000..b32b79ec04
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol with a PLT slot referenced from a debugging section (31-bit)
+#as: -m31
+#ld: -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-plt-nonalloc-31.s b/ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s
new file mode 100644
index 0000000000..d252226de2
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-plt-nonalloc-31.s
@@ -0,0 +1,13 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .data
+ .long ifn
+ .section .debug_info,"",@progbits
+ .long ifn
diff --git a/ld/testsuite/ld-s390/ifunc-plt-nonalloc.d b/ld/testsuite/ld-s390/ifunc-plt-nonalloc.d
new file mode 100644
index 0000000000..03dac8f81a
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-plt-nonalloc.d
@@ -0,0 +1,8 @@
+#name: local IFUNC symbol with a PLT slot referenced from a debugging section
+#as: -m64
+#ld: -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-plt-nonalloc.s b/ld/testsuite/ld-s390/ifunc-plt-nonalloc.s
new file mode 100644
index 0000000000..8198433e89
--- /dev/null
+++ b/ld/testsuite/ld-s390/ifunc-plt-nonalloc.s
@@ -0,0 +1,13 @@
+ .text
+ .type resolver, @function
+resolver:
+ br %r14
+ .type ifn, @gnu_indirect_function
+ .set ifn, resolver
+ .globl _start
+_start:
+ br %r14
+ .data
+ .quad ifn
+ .section .debug_info,"",@progbits
+ .quad ifn
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index 80536e2e39..ea2ae2e3d7 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -180,6 +180,9 @@ if { [istarget "s390-*-*"] || [istarget "s390x-*-*"] } {
run_dump_test "pr26918-1"
run_dump_test "reloccheck-1"
run_dump_test "reloctlsle-1"
+ run_dump_test "ifunc-debug-nonalloc-31"
+ run_dump_test "ifunc-note-nonalloc-31"
+ run_dump_test "ifunc-plt-nonalloc-31"
}
@@ -188,6 +191,9 @@ if [istarget "s390x-*-*"] {
run_dump_test "weakundef-1b"
run_dump_test "weakundef-2b"
+ run_dump_test "ifunc-debug-nonalloc"
+ run_dump_test "ifunc-note-nonalloc"
+ run_dump_test "ifunc-plt-nonalloc"
if { ![skip_sframe_tests] } {
run_dump_test "sframe-simple-1"
--
2.55.0
More information about the Binutils
mailing list