From: Indu Bhagat Date: Wed, 13 Aug 2025 00:13:15 +0000 (-0700) Subject: [SFrame-V3] libsframe: add V3 APIs for adding and getting SFrame FDE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bb703073641008fb4f948b9802276761fcc312d;p=thirdparty%2Fbinutils-gdb.git [SFrame-V3] libsframe: add V3 APIs for adding and getting SFrame FDE (Similar to V2) Add two new APIs for adding and getting SFrame FDE: - sframe_encoder_add_funcdesc_v3 - sframe_decoder_get_funcdesc_v3 Note the argument for the function start address is int64_t instead of int32_t (the latter is used in sframe_encoder_add_funcdesc_v2 and sframe_encoder_get_funcdesc_v2). The new V3 APIs will be used in a subsequent commit to extend SFrame V3 to support text > 2 GiB by allowing int64_t offsets by default. Similar to the analogous V2 APIs, they return 0 on success and SFRAME_ERR on failure. include/ * sframe-api.h (sframe_decoder_get_funcdesc_v3): New declaration. (sframe_encoder_add_funcdesc_v3): Likewise. libsframe/ * libsframe.ver: Add the new APIs. * sframe.c (sframe_decoder_get_funcdesc_v3): New definition. (sframe_encoder_add_funcdesc_v3): Likewise. --- diff --git a/include/sframe-api.h b/include/sframe-api.h index 3521c188ec0..a4ba797794f 100644 --- a/include/sframe-api.h +++ b/include/sframe-api.h @@ -182,6 +182,18 @@ sframe_decoder_get_funcdesc_v2 (const sframe_decoder_ctx *ctx, unsigned char *func_info, uint8_t *rep_block_size); +/* Get the data (NUM_FRES, FUNC_SIZE, FUNC_START_ADDRESS, FUNC_INFO, + REP_BLOCK_SIZE) from the SFrame function descriptor entry at the I'th index + in the decoder object DCTX. If failed, return SFRAME_ERR. */ +extern int +sframe_decoder_get_funcdesc_v3 (const sframe_decoder_ctx *dctx, + unsigned int i, + uint32_t *num_fres, + uint32_t *func_size, + int64_t *func_start_address, + unsigned char *func_info, + uint8_t *rep_block_size); + /* SFrame textual dump. */ extern void dump_sframe (const sframe_decoder_ctx *decoder, uint64_t addr); @@ -295,7 +307,17 @@ sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *ectx, uint8_t rep_block_size, uint32_t num_fres); -/* Serialize the contents of the encoder context ECTX and return the buffer. +/* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE, + FUNC_INFO and REP_BLOCK_SIZE to the encoder context ECTX. */ +extern int +sframe_encoder_add_funcdesc_v3 (sframe_encoder_ctx *ectx, + int64_t start_addr, + uint32_t func_size, + unsigned char func_info, + uint8_t rep_block_size, + uint32_t num_fres); + +/* Serialize the contents of the encoder object ECTX and return the buffer. ENCODED_SIZE is updated to the size of the buffer. Sets ERRP if failure. */ extern char * diff --git a/libsframe/libsframe.ver b/libsframe/libsframe.ver index 4086a397c89..99027497486 100644 --- a/libsframe/libsframe.ver +++ b/libsframe/libsframe.ver @@ -22,6 +22,7 @@ LIBSFRAME_3.0 { sframe_find_fre; sframe_decoder_get_num_fidx; sframe_decoder_get_funcdesc_v2; + sframe_decoder_get_funcdesc_v3; sframe_decoder_get_fre; sframe_encode; sframe_encoder_free; @@ -34,6 +35,7 @@ LIBSFRAME_3.0 { sframe_encoder_add_fre; sframe_encoder_add_funcdesc; sframe_encoder_add_funcdesc_v2; + sframe_encoder_add_funcdesc_v3; sframe_encoder_write; dump_sframe; sframe_errmsg; diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 44b04d090c8..afa8923b733 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -1521,6 +1521,43 @@ sframe_decoder_get_funcdesc_v2 (const sframe_decoder_ctx *dctx, return 0; } + +/* Get the data (NUM_FRES, FUNC_SIZE, FUNC_START_ADDRESS, FUNC_INFO, + REP_BLOCK_SIZE) from the SFrame function descriptor entry at the I'th index + in the decoder object DCTX. If failed, return SFRAME_ERR. */ + +int +sframe_decoder_get_funcdesc_v3 (const sframe_decoder_ctx *dctx, + unsigned int i, + uint32_t *num_fres, + uint32_t *func_size, + int64_t *func_start_address, + unsigned char *func_info, + uint8_t *rep_block_size) +{ + int err = 0; + if (dctx == NULL || sframe_decoder_get_version (dctx) != SFRAME_VERSION_3) + return sframe_set_errno (&err, SFRAME_ERR_INVAL); + + sframe_func_desc_entry_int *fdp + = sframe_decoder_get_funcdesc_at_index (dctx, i); + if (fdp == NULL) + return sframe_set_errno (&err, SFRAME_ERR_FDE_NOTFOUND); + + if (num_fres) + *num_fres = fdp->func_num_fres; + if (func_start_address) + *func_start_address = fdp->func_start_addr; + if (func_size) + *func_size = fdp->func_size; + if (func_info) + *func_info = fdp->func_info; + if (rep_block_size) + *rep_block_size = fdp->func_rep_size; + + return 0; +} + /* Get the FRE_IDX'th FRE of the function at FUNC_IDX'th function descriptor entry in the SFrame decoder CTX. Returns error code as applicable. */ @@ -1946,6 +1983,32 @@ sframe_encoder_add_funcdesc_v2 (sframe_encoder_ctx *ectx, return 0; } +/* Add a new SFrame function descriptor entry with START_ADDR, FUNC_SIZE, + FUNC_INFO and REP_BLOCK_SIZE to the encoder context ECTX. */ + +int +sframe_encoder_add_funcdesc_v3 (sframe_encoder_ctx *ectx, + int64_t start_addr, + uint32_t func_size, + unsigned char func_info, + uint8_t rep_block_size, + uint32_t num_fres ATTRIBUTE_UNUSED) +{ + 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; + + 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; +} + static int sframe_sort_funcdesc (sframe_encoder_ctx *ectx) {