[PATCH v2 2/6] aarch64: relocate IFUNC references from non-alloc sections as STT_FUNC

Harshit Kumar harshit7kr@gmail.com
Sat Nov 14 09:38:25 GMT 2026


A local STT_GNU_IFUNC symbol gets its hash entry from the relocation
scan, which skips non-SEC_ALLOC sections (PR ld/26080).  When only such
a section, for example .debug_info, refers to it,
elfNN_aarch64_relocate_section finds no entry and aborts.

A non-alloc section is not loaded and ld.so never processes it, so
relocate a reference from any non-alloc section, debugging and note
sections included, as against STT_FUNC: it gets the address of the
resolver.  This replaces the separate SHT_NOTE (PR ld/22929) and
SEC_DEBUGGING (PR ld/18808) cases for a global symbol, which left a
debugging section's field unrelocated (0, or the bare addend, in
.debug_info) and rejected or aborted on other non-alloc sections.

bfd/
	PR ld/34988
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Relocate a
	reference from a non-alloc section to a defined STT_GNU_IFUNC symbol
	as against STT_FUNC.
	(elfNN_aarch64_relocate_section): Likewise for a local
	STT_GNU_IFUNC symbol with no hash entry.
ld/
	PR ld/34988
	* testsuite/ld-aarch64/ifunc-debug-nonalloc.d: New test.
	* testsuite/ld-aarch64/ifunc-debug-nonalloc.s: New file.
	* testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d: New test.
	* testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s: New file.
	* testsuite/ld-aarch64/ifunc-note-nonalloc.d: New test.
	* testsuite/ld-aarch64/ifunc-note-nonalloc.s: New file.
	* testsuite/ld-aarch64/ifunc-plain-nonalloc.d: New test.
	* testsuite/ld-aarch64/ifunc-plain-nonalloc.s: New file.
	* testsuite/ld-aarch64/aarch64-elf.exp: Run them.

Signed-off-by: Harshit Kumar <harshit7kr@gmail.com>
---
 bfd/elfnn-aarch64.c                           | 47 +++++++------------
 ld/testsuite/ld-aarch64/aarch64-elf.exp       |  4 ++
 .../ld-aarch64/ifunc-debug-nonalloc.d         |  7 +++
 .../ld-aarch64/ifunc-debug-nonalloc.s         | 11 +++++
 .../ld-aarch64/ifunc-global-debug-nonalloc.d  |  7 +++
 .../ld-aarch64/ifunc-global-debug-nonalloc.s  | 13 +++++
 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d |  7 +++
 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s | 11 +++++
 .../ld-aarch64/ifunc-plain-nonalloc.d         |  7 +++
 .../ld-aarch64/ifunc-plain-nonalloc.s         | 11 +++++
 10 files changed, 95 insertions(+), 30 deletions(-)
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.d
 create mode 100644 ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.s

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index dbb29549df..ccf192f39b 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -5807,33 +5807,12 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
       const char *name;
       bfd_vma addend = 0;
 
+      /* A non-alloc section is not loaded, so relocate a reference
+	 from it as against STT_FUNC.  */
       if ((input_section->flags & SEC_ALLOC) == 0)
-	{
-	  /* If this is a SHT_NOTE section without SHF_ALLOC, treat
-	     STT_GNU_IFUNC symbol as STT_FUNC.  */
-	  if (elf_section_type (input_section) == SHT_NOTE)
-	    goto skip_ifunc;
-
-	  /* Dynamic relocs are not propagated for SEC_DEBUGGING
-	     sections because such sections are not SEC_ALLOC and
-	     thus ld.so will not process them.  */
-	  if ((input_section->flags & SEC_DEBUGGING) != 0)
-	    return bfd_reloc_ok;
+	goto skip_ifunc;
 
-	  if (h->root.root.string)
-	    name = h->root.root.string;
-	  else
-	    name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, NULL);
-	  _bfd_error_handler
-	    /* xgettext:c-format */
-	    (_("%pB(%pA+%#" PRIx64 "): "
-	       "unresolvable %s relocation against symbol `%s'"),
-	     input_bfd, input_section, (uint64_t) rel->r_offset,
-	     howto->name, name);
-	  bfd_set_error (bfd_error_bad_value);
-	  return bfd_reloc_notsupported;
-	}
-      else if (h->plt.offset == (bfd_vma) -1)
+      if (h->plt.offset == (bfd_vma) -1)
 	goto bad_ifunc_reloc;
 
       /* STT_GNU_IFUNC symbol must go through PLT.  */
@@ -7138,11 +7117,19 @@ elfNN_aarch64_relocate_section (struct bfd_link_info *info,
 	      h = elfNN_aarch64_get_local_sym_hash (globals, input_bfd,
 						    rel, false);
 	      if (h == NULL)
-		abort ();
-
-	      /* Set STT_GNU_IFUNC symbol value.  */
-	      h->root.u.def.value = sym->st_value;
-	      h->root.u.def.section = sec;
+		{
+		  /* Only a non-alloc section, which the relocation scan
+		     skips, refers to the symbol.  Relocate it as against
+		     STT_FUNC.  */
+		  if ((input_section->flags & SEC_ALLOC) != 0)
+		    abort ();
+		}
+	      else
+		{
+		  /* Set STT_GNU_IFUNC symbol value.  */
+		  h->root.u.def.value = sym->st_value;
+		  h->root.u.def.section = sec;
+		}
 	    }
 	}
       else
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index f4941b0151..bd60ce1890 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -373,6 +373,10 @@ run_dump_test_lp64 "ifunc-19b"
 run_dump_test_lp64 "ifunc-20"
 run_dump_test_lp64 "ifunc-21"
 run_dump_test_lp64 "ifunc-22"
+run_dump_test_lp64 "ifunc-debug-nonalloc"
+run_dump_test_lp64 "ifunc-note-nonalloc"
+run_dump_test_lp64 "ifunc-global-debug-nonalloc"
+run_dump_test_lp64 "ifunc-plain-nonalloc"
 
 run_dump_test "relasz"
 run_dump_test_lp64 "relocs-1027-symbolic-func"
diff --git a/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.d b/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.d
new file mode 100644
index 0000000000..6544172bf5
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.d
@@ -0,0 +1,7 @@
+#name: local IFUNC symbol referenced only from a debugging section
+#ld: -Ttext=0x10000
+#objdump: -s -j .debug_info
+#...
+Contents of section .debug_info:
+ 0000 (00000100 00000000|00000000 00010000) +.*
+#pass
diff --git a/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.s b/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.s
new file mode 100644
index 0000000000..250f8eeee0
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-debug-nonalloc.s
@@ -0,0 +1,11 @@
+	.text
+	.type	resolver, %function
+resolver:
+	ret
+	.type	ifn, %gnu_indirect_function
+	.set	ifn, resolver
+	.globl	_start
+_start:
+	ret
+	.section .debug_info,"",%progbits
+	.xword	ifn
diff --git a/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d b/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d
new file mode 100644
index 0000000000..3e3cca9c1b
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.d
@@ -0,0 +1,7 @@
+#name: global IFUNC symbol referenced from a debugging section
+#ld: -Ttext=0x10000
+#objdump: -s -j .debug_info
+#...
+Contents of section .debug_info:
+ 0000 (00000100 00000000|00000000 00010000) +.*
+#pass
diff --git a/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s b/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s
new file mode 100644
index 0000000000..5d5a483683
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-global-debug-nonalloc.s
@@ -0,0 +1,13 @@
+	.text
+	.type	resolver, %function
+resolver:
+	ret
+	.globl	ifn
+	.type	ifn, %gnu_indirect_function
+	.set	ifn, resolver
+	.globl	_start
+_start:
+	bl	ifn
+	ret
+	.section .debug_info,"",%progbits
+	.xword	ifn
diff --git a/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d b/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d
new file mode 100644
index 0000000000..de6c1d9830
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.d
@@ -0,0 +1,7 @@
+#name: local IFUNC symbol referenced only from a non-alloc note section
+#ld: -Ttext=0x10000
+#objdump: -s -j .note.probe
+#...
+Contents of section .note.probe:
+ 0000 (00000100 00000000|00000000 00010000) +.*
+#pass
diff --git a/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s b/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s
new file mode 100644
index 0000000000..359fb0bfb2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-note-nonalloc.s
@@ -0,0 +1,11 @@
+	.text
+	.type	resolver, %function
+resolver:
+	ret
+	.type	ifn, %gnu_indirect_function
+	.set	ifn, resolver
+	.globl	_start
+_start:
+	ret
+	.section .note.probe,"",%note
+	.xword	ifn
diff --git a/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.d b/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.d
new file mode 100644
index 0000000000..99a985d8a5
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.d
@@ -0,0 +1,7 @@
+#name: local IFUNC symbol referenced only from a plain non-alloc section
+#ld: -Ttext=0x10000
+#objdump: -s -j .probe
+#...
+Contents of section .probe:
+ 0000 (00000100 00000000|00000000 00010000) +.*
+#pass
diff --git a/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.s b/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.s
new file mode 100644
index 0000000000..9a7e133771
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/ifunc-plain-nonalloc.s
@@ -0,0 +1,11 @@
+	.text
+	.type	resolver, %function
+resolver:
+	ret
+	.type	ifn, %gnu_indirect_function
+	.set	ifn, resolver
+	.globl	_start
+_start:
+	ret
+	.section .probe,"",%progbits
+	.xword	ifn
-- 
2.55.0




More information about the Binutils mailing list