]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libsframe: refactor sframe_decoder_add_funcdesc for internal use
authorIndu Bhagat <indu.bhagat@oracle.com>
Sat, 8 Nov 2025 22:02:05 +0000 (14:02 -0800)
committerIndu Bhagat <indu.bhagat@oracle.com>
Tue, 9 Dec 2025 08:26:11 +0000 (00:26 -0800)
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
libsframe/sframe.c

index 79a748f9e3b803b350228c18ad0cbd0f99345a07..ed2e10a4b3caa008d8b5b4da78e7d9329ee65ead 100644 (file)
@@ -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
index 16fc3a3f11bf25292bae8cbb7e3506daac3f731d..757b56a69cd7102c104174ecbcef0120bf81e645 100644 (file)
@@ -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;