[PATCH, V2 11/14] libsframe: refactor sframe_decoder_add_funcdesc for internal use

Indu Bhagat indu.bhagat@oracle.com
Tue Dec 9 08:59:22 GMT 2025


sframe_encoder_add_funcdesc () was added for SFRAME_VERSION_1.  This has
since been obsoleted by introduction of SFRAME_VERSION_2 and its
corresponding sframe_decoder_add_funcdesc_v2 API.

Refactor the functionality into an internal-only API:
sframe_encoder_add_funcdesc_internal (). Ensure it returns the error
code for the caller to take necessary action or pass to user.

Keep only two args for sframe_encoder_add_funcdesc: function size and
function start addr.  This simple barebone API will be used in a
subsequent commit to adjust the link-time behaviour of SFrame sections.

libsframe/
	* sframe.c (sframe_encoder_add_funcdesc): Refactor out into
	sframe_encoder_add_funcdesc_internal.  Change args.
	(sframe_encoder_add_funcdesc_v2): Use the new internal API.

---
[Changes in V2]
  - Use only two args for the sframe_encoder_add_funcdesc_internal
[End of changes in V2]
---
 include/sframe-api.h |  8 +++----
 libsframe/sframe.c   | 50 ++++++++++++++++++++++++++------------------
 2 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/include/sframe-api.h b/include/sframe-api.h
index 79a748f9e3b..ed2e10a4b3c 100644
--- a/include/sframe-api.h
+++ b/include/sframe-api.h
@@ -288,14 +288,12 @@ sframe_encoder_add_fre (sframe_encoder_ctx *ectx,
 			unsigned int func_idx,
 			sframe_frame_row_entry *frep);
 
-/* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE and
-   FUNC_INFO to the encoder context ECTX.  */
+/* Add a new SFrame function descriptor entry with START_ADDR and FUNC_SIZE to
+   the encoder context ECTX.  */
 extern int
 sframe_encoder_add_funcdesc (sframe_encoder_ctx *ectx,
 			     int32_t start_addr,
-			     uint32_t func_size,
-			     unsigned char func_info,
-			     uint32_t num_fres);
+			     uint32_t func_size);
 
 /* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE,
    FUNC_INFO and REP_BLOCK_SIZE to the encoder context ECTX.  This API is valid
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index 16fc3a3f11b..757b56a69cd 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1783,24 +1783,19 @@ bad:
 }
 
 /* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE and
-   FUNC_INFO to the encoder context ECTX.  */
+   FUNC_INFO to the encoder context ECTX.  Caller must make sure that ECTX
+   exists.  */
 
-int
-sframe_encoder_add_funcdesc (sframe_encoder_ctx *ectx,
-			     int32_t start_addr,
-			     uint32_t func_size,
-			     unsigned char func_info,
-			     uint32_t num_fres ATTRIBUTE_UNUSED)
+static int
+sframe_encoder_add_funcdesc_internal (sframe_encoder_ctx *ectx,
+				      int32_t start_addr,
+				      uint32_t func_size)
 {
   sframe_header *ehp;
   sf_fde_tbl *fd_info;
   size_t fd_tbl_sz;
   int err = 0;
 
-  /* FIXME book-keep num_fres for error checking.  */
-  if (ectx == NULL)
-    return sframe_set_errno (&err, SFRAME_ERR_INVAL);
-
   fd_info = ectx->sfe_funcdesc;
   ehp = sframe_encoder_get_header (ectx);
 
@@ -1846,7 +1841,6 @@ sframe_encoder_add_funcdesc (sframe_encoder_ctx *ectx,
   fd_info->entry[fd_info->count].sfde_func_info
     = sframe_fde_func_info (fre_type);
 #endif
-  fd_info->entry[fd_info->count].func_info = func_info;
   fd_info->count++;
   ectx->sfe_funcdesc = fd_info;
   ehp->sfh_num_fdes++;
@@ -1857,7 +1851,25 @@ bad:
     free (fd_info);
   ectx->sfe_funcdesc = NULL;
   ehp->sfh_num_fdes = 0;
-  return -1;
+  return err;
+}
+
+/* Add a new SFrame function descriptor entry with START_ADDR and FUNC_SIZE to
+   the encoder context ECTX.  */
+
+int
+sframe_encoder_add_funcdesc (sframe_encoder_ctx *ectx, int32_t start_addr,
+			     uint32_t func_size)
+{
+  int err = 0;
+  if (ectx == NULL || sframe_encoder_get_version (ectx) != SFRAME_VERSION_3)
+    return sframe_set_errno (&err, SFRAME_ERR_INVAL);
+
+  err = sframe_encoder_add_funcdesc_internal (ectx, start_addr, func_size);
+  if (err)
+    return err;
+
+  return 0;
 }
 
 /* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE,
@@ -1872,18 +1884,16 @@ sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *ectx,
 				uint8_t rep_block_size,
 				uint32_t num_fres ATTRIBUTE_UNUSED)
 {
-  sf_fde_tbl *fd_info;
-  int err;
-
+  int err = 0;
   if (ectx == NULL || sframe_encoder_get_version (ectx) == SFRAME_VERSION_1)
     return sframe_set_errno (&err, SFRAME_ERR_INVAL);
 
-  err = sframe_encoder_add_funcdesc (ectx, start_addr, func_size, func_info,
-				     num_fres);
+  err = sframe_encoder_add_funcdesc_internal (ectx, start_addr, func_size);
   if (err)
-    return SFRAME_ERR;
+    return err;
 
-  fd_info = ectx->sfe_funcdesc;
+  sf_fde_tbl *fd_info = ectx->sfe_funcdesc;
+  fd_info->entry[fd_info->count-1].func_info = func_info;
   fd_info->entry[fd_info->count-1].func_rep_size = rep_block_size;
 
   return 0;
-- 
2.43.0



More information about the Binutils mailing list