[PATCH 1/7] bfd: add _bfd_elf_ifunc_nonalloc_reloc

Harshit Kumar harshit7kr@gmail.com
Wed Nov 11 11:03:44 GMT 2026


The relocation scan skips non-SEC_ALLOC sections (PR ld/26080), so an
STT_GNU_IFUNC reference there has no PLT entry.  For a global symbol,
x86, AArch64, RISC-V and SPARC handle such a reference the same way:
STT_FUNC in a SHT_NOTE section (PR ld/22929), unapplied in a debugging
section (PR ld/18808), an error elsewhere.  Put that rule in one
function, so the local-symbol fixes that follow can share it.  No
functional change.

bfd/
	PR ld/34988
	* elf-bfd.h (enum elf_ifunc_nonalloc_action): New.
	(_bfd_elf_ifunc_nonalloc_reloc): Declare.
	* elflink.c (_bfd_elf_ifunc_nonalloc_reloc): New function.

Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
 bfd/elf-bfd.h | 11 +++++++++++
 bfd/elflink.c | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index c51d41c8eb..dcc82801b5 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2936,6 +2936,17 @@ extern bool _bfd_elf_link_iterate_on_relocs
    bool (*) (bfd *, struct bfd_link_info *, asection *,
 	     const Elf_Internal_Rela *)) ATTRIBUTE_HIDDEN;
 
+/* How relocate_section handles a relocation in a non-SEC_ALLOC section
+   against an STT_GNU_IFUNC symbol.  */
+enum elf_ifunc_nonalloc_action
+{
+  elf_ifunc_nonalloc_func,	/* Relocate against the symbol itself.  */
+  elf_ifunc_nonalloc_skip,	/* Leave the relocation unapplied.  */
+  elf_ifunc_nonalloc_reject	/* Report an error.  */
+};
+extern enum elf_ifunc_nonalloc_action _bfd_elf_ifunc_nonalloc_reloc
+  (asection *) ATTRIBUTE_HIDDEN;
+
 extern bool bfd_elf_link_record_dynamic_symbol
   (struct bfd_link_info *, struct elf_link_hash_entry *);
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 1eef868be4..c595f14f9a 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4390,6 +4390,26 @@ _bfd_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
   return true;
 }
 
+/* Return how relocate_section should handle a relocation in
+   INPUT_SECTION, which is not SEC_ALLOC, against an STT_GNU_IFUNC
+   symbol.  The relocation scan skips such a section (PR ld/26080), so
+   the reference has no PLT entry or dynamic relocation.  Treat the
+   symbol as STT_FUNC in a SHT_NOTE section (PR ld/22929), leave the
+   relocation unapplied in a debugging section, which ld.so never
+   processes (PR ld/18808), and reject it in any other section.  This is
+   what x86, AArch64, RISC-V and SPARC do for a global STT_GNU_IFUNC
+   symbol there.  */
+
+enum elf_ifunc_nonalloc_action
+_bfd_elf_ifunc_nonalloc_reloc (asection *input_section)
+{
+  if (elf_section_type (input_section) == SHT_NOTE)
+    return elf_ifunc_nonalloc_func;
+  if ((input_section->flags & SEC_DEBUGGING) != 0)
+    return elf_ifunc_nonalloc_skip;
+  return elf_ifunc_nonalloc_reject;
+}
+
 /* An entry in the first definition hash table.  */
 
 struct elf_link_first_hash_entry
-- 
2.55.0




More information about the Binutils mailing list