[1/2] bfd: ld: sframe: skip R_*_NONE relocations from input bfds

Message ID 20251203092050.6795-2-claudiu.zissulescu-ianculescu@oracle.com
State New
Headers
Series sframe: Fix for PR 33401 |

Commit Message

claudiu.zissulescu-ianculescu--- via Binutils Dec. 3, 2025, 9:20 a.m. UTC
  From: Indu Bhagat <indu.bhagat@oracle.com>

Fix PR ld/33401 - SFrame assertion when linking gav-0.9.1

As the issue demonstrates, R_*_NONE relocations are not necessarily
at the end of .sframe section (previously thought so with PR ld/33127).
Skip over R_*_NONE relocs when they are strewn intermittently inside the
.rela.sframe section.

bfd/
	PR ld/33401
	* elf-sframe.c (sframe_decoder_init_func_bfdinfo):  Skip over
	R_*_NONE relocations.
---
 bfd/elf-sframe.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
  

Patch

diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index 8e4cfdd73d3..80043550777 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -121,13 +121,24 @@  sframe_decoder_init_func_bfdinfo (bfd *abfd,
     return true;
 
   rel = cookie->rels;
+  unsigned int reloc_index = 0;
   for (i = 0; i < fde_count; i++)
     {
       /* Bookkeep the relocation offset and relocation index of each function
-	 for later use.  */
+	 for later use.  There may be some R_*_NONE relocations intermingled
+	 (see PR ld/33401).  Skip over those.  */
+      while (rel->r_info == 0)
+	{
+	  reloc_index++;
+	  rel++;
+	}
+
+      BFD_ASSERT (reloc_index < sec->reloc_count);
+
       sframe_decoder_set_func_r_offset (sfd_info, i, rel->r_offset);
-      sframe_decoder_set_func_reloc_index (sfd_info, i, i);
+      sframe_decoder_set_func_reloc_index (sfd_info, i, reloc_index);
 
+      reloc_index++;
       rel++;
     }