[PATCH 3/3] bfd: x86: sframe: additonal check in _bfd_x86_elf_link_setup_gnu_properties

claudiu.zissulescu-ianculescu@oracle.com claudiu.zissulescu-ianculescu@oracle.com
Mon Jan 12 10:53:29 GMT 2026


From: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>

GNU ld creates SFrame stack trace info for the .plt* sections.  These
linker created sections are created in
_bfd_x86_elf_link_setup_gnu_properties (), but data is emitted into
them a bit later in _bfd_x86_elf_late_size_sections ().

With SFrame sections now marked KEEP in scripttempl/elf.sc, and the
presence of these linker created SFrame sections cause emission of an
empty .sframe for all ELF targets (IIUC), even when all input bfd's
have no .sframe section.  This patch is avoiding creation of empty
.sframe in linked objects on x86_64, when none of the inputs had
SFrame sections.

bfd/

	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Emit
	sframe section only when required.

Co-authored-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
---
 bfd/elfxx-x86.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 36ba7919f47..13e875c1ab3 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -4834,8 +4834,30 @@ _bfd_x86_elf_link_setup_gnu_properties
 	    }
 	}
 
+      bool gen_plt_sframe_p = false;
       /* .sframe sections are emitted for AMD64 ABI only.  */
       if (ABI_64_P (info->output_bfd) && !info->no_ld_generated_unwind_info)
+	{
+	  /* Find in any input file has an .sframe section.  */
+	  for (pbfd = info->input_bfds; pbfd != NULL; pbfd = pbfd->link.next)
+	    if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
+		&& bfd_count_sections (pbfd) != 0)
+	      {
+		asection *sfsec = bfd_get_section_by_name (pbfd, ".sframe");
+		if (sfsec != NULL)
+		  {
+		    gen_plt_sframe_p = true;
+		    break;
+		  }
+	      }
+	}
+
+      /* Do not make SFrame sections for dynobj unconditionally.  If there
+	 are no SFrame sections for any input files, skip creating the linker
+	 created SFrame sections too.  Since SFrame sections are marked KEEP,
+	 prohibiting these linker-created SFrame sections when unnecessary,
+	 helps avoid creating of empty SFrame sections in the output.  */
+      if (gen_plt_sframe_p)
 	{
 	  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
 			    | SEC_HAS_CONTENTS | SEC_IN_MEMORY
-- 
2.52.0



More information about the Binutils mailing list