[08/12] bfd: linker: generate SFrame sections with version SFRAME_VERSION_2

Message ID 20230627212028.2138604-9-indu.bhagat@oracle.com
State Unresolved
Headers
Series SFrame Version 2 - definition and support |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Indu Bhagat June 27, 2023, 9:20 p.m. UTC
  The linker will generate the output SFrame sections in the
SFRAME_VERSION_2 format.  If the input sections offered to the linker
are not all in the SFRAME_VERSION_2 format, the linker issues an error
to the user.

bfd/
	* elf-sframe.c (_bfd_elf_merge_section_sframe): Generate an
	output SFrame section with version SFRAME_VERSION_2.  Also,
	error out if the SFrame sections do not all have
	SFRAME_VERSION_2.
	* elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Generate SFrame
	section for plt entries with version SFRAME_VERSION_2.

ld/testsuite/
	* ld-aarch64/sframe-simple-1.d: Adjust for SFRAME_VERSION_2.
	* ld-x86-64/sframe-plt-1.d: Likewise.
	* ld-x86-64/sframe-simple-1.d: Likewise.
---
 bfd/elf-sframe.c                          | 16 +++++++++++++++-
 bfd/elfxx-x86.c                           |  2 +-
 ld/testsuite/ld-aarch64/sframe-simple-1.d |  4 ++--
 ld/testsuite/ld-x86-64/sframe-plt-1.d     |  2 +-
 ld/testsuite/ld-x86-64/sframe-simple-1.d  |  4 ++--
 5 files changed, 21 insertions(+), 7 deletions(-)
  

Patch

diff --git a/bfd/elf-sframe.c b/bfd/elf-sframe.c
index c09822a5503..1b38768ec71 100644
--- a/bfd/elf-sframe.c
+++ b/bfd/elf-sframe.c
@@ -328,6 +328,8 @@  _bfd_elf_merge_section_sframe (bfd *abfd,
   uint8_t sfd_ctx_abi_arch;
   int8_t sfd_ctx_fixed_fp_offset;
   int8_t sfd_ctx_fixed_ra_offset;
+  uint8_t dctx_version;
+  uint8_t ectx_version;
   int encerr = 0;
 
   struct elf_link_hash_table *htab;
@@ -361,7 +363,7 @@  _bfd_elf_merge_section_sframe (bfd *abfd,
       if (!sfd_ctx_abi_arch)
 	return false;
 
-      htab->sfe_info.sfe_ctx = sframe_encode (SFRAME_VERSION_1,
+      htab->sfe_info.sfe_ctx = sframe_encode (SFRAME_VERSION_2,
 					      0, /* SFrame flags.  */
 					      sfd_ctx_abi_arch,
 					      sfd_ctx_fixed_fp_offset,
@@ -400,6 +402,18 @@  _bfd_elf_merge_section_sframe (bfd *abfd,
       return false;
     }
 
+  /* Check that all .sframe sections being linked have the same version.  */
+  dctx_version = sframe_decoder_get_version (sfd_ctx);
+  ectx_version = sframe_encoder_get_version (sfe_ctx);
+  if (dctx_version != SFRAME_VERSION_2 || dctx_version != ectx_version)
+    {
+      _bfd_error_handler
+	(_("input SFrame sections with different format versions prevent"
+	  " .sframe generation"));
+      return false;
+    }
+
+
   /* Iterate over the function descriptor entries and the FREs of the
      function from the decoder context.  Add each of them to the encoder
      context, if suitable.  */
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index b6512c9c49c..f224e8f1354 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -1883,7 +1883,7 @@  _bfd_x86_elf_create_sframe_plt (bfd *output_bfd,
       break;
     }
 
-  *ectx = sframe_encode (SFRAME_VERSION_1,
+  *ectx = sframe_encode (SFRAME_VERSION_2,
 			 0,
 			 SFRAME_ABI_AMD64_ENDIAN_LITTLE,
 			 SFRAME_CFA_FIXED_FP_INVALID,
diff --git a/ld/testsuite/ld-aarch64/sframe-simple-1.d b/ld/testsuite/ld-aarch64/sframe-simple-1.d
index 6f617153a35..6ab8c2ab46a 100644
--- a/ld/testsuite/ld-aarch64/sframe-simple-1.d
+++ b/ld/testsuite/ld-aarch64/sframe-simple-1.d
@@ -3,14 +3,14 @@ 
 #source: sframe-bar.s
 #objdump: --sframe=.sframe
 #ld: -shared
-#name: SFrame Simple link
+#name: SFrame simple link
 
 .*:     file format .*
 
 Contents of the SFrame section .sframe:
   Header :
 
-    Version: SFRAME_VERSION_1
+    Version: SFRAME_VERSION_2
     Flags: SFRAME_F_FDE_SORTED
     Num FDEs: 2
     Num FREs: 2
diff --git a/ld/testsuite/ld-x86-64/sframe-plt-1.d b/ld/testsuite/ld-x86-64/sframe-plt-1.d
index 06bb16bd482..5e734610b97 100644
--- a/ld/testsuite/ld-x86-64/sframe-plt-1.d
+++ b/ld/testsuite/ld-x86-64/sframe-plt-1.d
@@ -10,7 +10,7 @@ 
 Contents of the SFrame section .sframe:
   Header :
 
-    Version: SFRAME_VERSION_1
+    Version: SFRAME_VERSION_2
     Flags: SFRAME_F_FDE_SORTED
 #...
 
diff --git a/ld/testsuite/ld-x86-64/sframe-simple-1.d b/ld/testsuite/ld-x86-64/sframe-simple-1.d
index afc0006112e..7f4db31fe1b 100644
--- a/ld/testsuite/ld-x86-64/sframe-simple-1.d
+++ b/ld/testsuite/ld-x86-64/sframe-simple-1.d
@@ -3,14 +3,14 @@ 
 #source: sframe-bar.s
 #objdump: --sframe=.sframe
 #ld: -shared
-#name: SFrame Simple link
+#name: SFrame simple link
 
 .*: +file format .*
 
 Contents of the SFrame section .sframe:
   Header :
 
-    Version: SFRAME_VERSION_1
+    Version: SFRAME_VERSION_2
     Flags: SFRAME_F_FDE_SORTED
 #...