[binutils-gdb] include: libsframe: add APIs for offsetof FDE func start addr field

Indu Bhagat ibhagat@sourceware.org
Sun Jul 6 19:54:25 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=72dac98050ee1a8333ec03c9f60e68e327913ec2

commit 72dac98050ee1a8333ec03c9f60e68e327913ec2
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Sun Jul 6 12:46:33 2025 -0700

    include: libsframe: add APIs for offsetof FDE func start addr field
    
    These APIs will be later used by the linker to arrange SFrame FDEs in
    the output SFrame section.
    
    include/
            * sframe-api.h (sframe_decoder_get_offsetof_fde_start_addr): New
            declaration.
            (sframe_encoder_get_offsetof_fde_start_addr): Likewise.
    
    libsframe/
            * libsframe.ver: List the new APIs.
            * sframe.c (sframe_decoder_get_offsetof_fde_start_addr): New
            definition.
            (sframe_encoder_get_offsetof_fde_start_addr): Likewise.

Diff:
---
 include/sframe-api.h    | 24 ++++++++++++++++++++++++
 libsframe/libsframe.ver |  2 ++
 libsframe/sframe.c      | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)

diff --git a/include/sframe-api.h b/include/sframe-api.h
index e5262ae6251..3dc18b6ad39 100644
--- a/include/sframe-api.h
+++ b/include/sframe-api.h
@@ -128,6 +128,18 @@ sframe_decoder_get_version (sframe_decoder_ctx *dctx);
 extern uint8_t
 sframe_decoder_get_flags (sframe_decoder_ctx *dctx);
 
+/* Get the offset of the sfde_func_start_address field (from the start of the
+   on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the decoder
+   context DCTX.
+
+   If FUNC_IDX is more than the number of SFrame FDEs in the section, sets
+   error code in ERRP, but returns the (hypothetical) offset.  This is useful
+   for the linker when arranging input FDEs into the output section to be
+   emitted.  */
+uint32_t
+sframe_decoder_get_offsetof_fde_start_addr (sframe_decoder_ctx *dctx,
+					    uint32_t func_idx, int *errp);
+
 /* Return the number of function descriptor entries in the SFrame decoder
    DCTX.  */
 extern uint32_t
@@ -246,6 +258,18 @@ sframe_encoder_get_version (sframe_encoder_ctx *encoder);
 extern uint8_t
 sframe_encoder_get_flags (sframe_encoder_ctx *encoder);
 
+/* Get the offset of the sfde_func_start_address field (from the start of the
+   on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the encoder
+   context ENCODER.
+
+   If FUNC_IDX is more than the number of SFrame FDEs in the section, sets
+   error code in ERRP, but returns the (hypothetical) offset.  This is useful
+   for the linker when arranging input FDEs into the output section to be
+   emitted.  */
+uint32_t
+sframe_encoder_get_offsetof_fde_start_addr (sframe_encoder_ctx *encoder,
+					    uint32_t func_idx, int *errp);
+
 /* Return the number of function descriptor entries in the SFrame encoder
    ENCODER.  */
 extern uint32_t
diff --git a/libsframe/libsframe.ver b/libsframe/libsframe.ver
index 7038d694704..06324eecfc5 100644
--- a/libsframe/libsframe.ver
+++ b/libsframe/libsframe.ver
@@ -41,5 +41,7 @@ LIBSFRAME_1.0 {
 
 LIBSFRAME_1.1 {
     sframe_decoder_get_flags;
+    sframe_decoder_get_offsetof_fde_start_addr;
     sframe_encoder_get_flags;
+    sframe_encoder_get_offsetof_fde_start_addr;
 } LIBSFRAME_1.0;
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index fcc266006c0..963c343ea46 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <stddef.h>
 #include "sframe-impl.h"
 #include "swap.h"
 
@@ -1015,6 +1016,29 @@ sframe_decoder_get_fixed_ra_offset (sframe_decoder_ctx *ctx)
   return dhp->sfh_cfa_fixed_ra_offset;
 }
 
+/* Get the offset of the sfde_func_start_address field (from the start of the
+   on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the decoder
+   context DCTX.
+
+   If FUNC_IDX is more than the number of SFrame FDEs in the section, sets
+   error code in ERRP, but returns the (hypothetical) offset.  This is useful
+   for the linker when arranging input FDEs into the output section to be
+   emitted.  */
+
+uint32_t
+sframe_decoder_get_offsetof_fde_start_addr (sframe_decoder_ctx *dctx,
+					    uint32_t func_idx, int *errp)
+{
+  if (func_idx >= sframe_decoder_get_num_fidx (dctx))
+    sframe_ret_set_errno (errp, SFRAME_ERR_FDE_NOTFOUND);
+  else if (errp)
+    *errp = 0;
+
+  return (sframe_decoder_get_hdr_size (dctx)
+	  + func_idx * sizeof (sframe_func_desc_entry)
+	  + offsetof (sframe_func_desc_entry, sfde_func_start_address));
+}
+
 /* Find the function descriptor entry which contains the specified address
    ADDR.
    This function is deprecated and will be removed from libsframe.so.2.  */
@@ -1434,6 +1458,29 @@ sframe_encoder_get_num_fidx (sframe_encoder_ctx *encoder)
   return num_fdes;
 }
 
+/* Get the offset of the sfde_func_start_address field (from the start of the
+   on-disk layout of the SFrame section) of the FDE at FUNC_IDX in the encoder
+   context ENCODER.
+
+   If FUNC_IDX is more than the number of SFrame FDEs in the section, sets
+   error code in ERRP, but returns the (hypothetical) offset.  This is useful
+   for the linker when arranging input FDEs into the output section to be
+   emitted.  */
+
+uint32_t
+sframe_encoder_get_offsetof_fde_start_addr (sframe_encoder_ctx *encoder,
+					    uint32_t func_idx, int *errp)
+{
+  if (func_idx >= sframe_encoder_get_num_fidx (encoder))
+    sframe_ret_set_errno (errp, SFRAME_ERR_FDE_INVAL);
+  else if (errp)
+    *errp = 0;
+
+  return (sframe_encoder_get_hdr_size (encoder)
+	  + func_idx * sizeof (sframe_func_desc_entry)
+	  + offsetof (sframe_func_desc_entry, sfde_func_start_address));
+}
+
 /* Add an FRE to function at FUNC_IDX'th function descriptor entry in
    the encoder context.  */


More information about the Binutils-cvs mailing list