[PATCH 1/2] libsframe: add new dump_sframe_reloc
Indu Bhagat
indu.bhagat@oracle.com
Mon Feb 17 16:58:21 GMT 2025
PR libsframe/32589 - function start address is zero in SFrame section dump
This new function dumps the contents of a relocated SFrame section in
human readable text.
After the section contents are relocated, there is need to fixup the
function start address, which is what sframe_fde_tbl_reloc_fixup () is
about. This is similar to the fixups done for other debug sections
before textual dump. The function sframe_fde_tbl_reloc_fixup is
libsframe internal only and is not exposed.
Some caution is necessary though in making sure
sframe_fde_tbl_reloc_fixup is done in a version aware manner, when
future versions of the SFrame format are implemented. For now, add a
version check as a reminder.
Note the new API dump_sframe_reloc (). This new API is exposed because
objdump / readelf will need it. Update the library version information:
Since new interfaces have been added, set revision to 0, bump current
and age.
libsframe/
* libtool.version: Bump current and age. Use 2:0:1.
* libsframe.ver: Add new API dump_sframe_reloc.
(dump_sframe_reloc): New definition.
* sframe-impl.h (sframe_fde_tbl_reloc_fixup): New declaration.
* sframe.c (sframe_fde_tbl_reloc_fixup): New definition.
include/
* sframe-api.h (dump_sframe_reloc): New declaration.
---
include/sframe-api.h | 5 +++++
libsframe/libsframe.ver | 1 +
libsframe/libtool-version | 2 +-
libsframe/sframe-dump.c | 13 +++++++++++++
libsframe/sframe-impl.h | 2 ++
libsframe/sframe.c | 31 +++++++++++++++++++++++++++++++
6 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/include/sframe-api.h b/include/sframe-api.h
index 77ba32b0f4b..5f13c4baf2c 100644
--- a/include/sframe-api.h
+++ b/include/sframe-api.h
@@ -189,6 +189,11 @@ sframe_decoder_get_funcdesc_v2 (sframe_decoder_ctx *ctx,
extern void
dump_sframe (sframe_decoder_ctx *decoder, uint64_t addr);
+/* SFrame textual dump - with relocation. */
+extern void
+dump_sframe_reloc (sframe_decoder_ctx *dctx, uint64_t sec_addr,
+ bool relocate_p);
+
/* Get the base reg id from the FRE info. Sets errp if fails. */
extern uint8_t
sframe_fre_get_base_reg_id (sframe_frame_row_entry *fre, int *errp);
diff --git a/libsframe/libsframe.ver b/libsframe/libsframe.ver
index 57f5fb6c378..1f794134679 100644
--- a/libsframe/libsframe.ver
+++ b/libsframe/libsframe.ver
@@ -33,6 +33,7 @@ LIBSFRAME_1.0 {
sframe_encoder_add_funcdesc_v2;
sframe_encoder_write;
dump_sframe;
+ dump_sframe_reloc;
sframe_errmsg;
local:
diff --git a/libsframe/libtool-version b/libsframe/libtool-version
index 9dcbe48e47d..5a961391f49 100644
--- a/libsframe/libtool-version
+++ b/libsframe/libtool-version
@@ -27,4 +27,4 @@
# then set age to 0.
#
# CURRENT:REVISION:AGE
-1:0:0
+2:0:1
diff --git a/libsframe/sframe-dump.c b/libsframe/sframe-dump.c
index 1fa508d9bad..a8fb132725f 100644
--- a/libsframe/sframe-dump.c
+++ b/libsframe/sframe-dump.c
@@ -218,6 +218,19 @@ dump_sframe_functions (sframe_decoder_ctx *sfd_ctx, uint64_t sec_addr)
}
}
+void
+dump_sframe_reloc (sframe_decoder_ctx *sfd_ctx, uint64_t sec_addr,
+ bool relocate_p)
+{
+ if (relocate_p && sframe_fde_tbl_reloc_fixup (sfd_ctx))
+ {
+ printf ("\n Unexpected error in processing relocations.");
+ return;
+ }
+
+ dump_sframe (sfd_ctx, sec_addr);
+}
+
void
dump_sframe (sframe_decoder_ctx *sfd_ctx, uint64_t sec_addr)
{
diff --git a/libsframe/sframe-impl.h b/libsframe/sframe-impl.h
index 1cada54ae9e..9887039c3c5 100644
--- a/libsframe/sframe-impl.h
+++ b/libsframe/sframe-impl.h
@@ -64,6 +64,8 @@ struct sframe_encoder_ctx
size_t sfe_data_size;
};
+int sframe_fde_tbl_reloc_fixup (sframe_decoder_ctx *dctx);
+
#ifdef __cplusplus
}
#endif
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index c2693b978ec..01cefa4d01c 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -102,6 +102,37 @@ sframe_ret_set_errno (int *errp, int error)
return NULL;
}
+/* If the input buffer containing the SFrame section has been relocated, there
+ will be a need to do fixups too. The fixup merely accounts for the offset
+ of the byte from the start of the section.
+
+ Currently used by dump_sframe_reloc. The caller must have decoded (and
+ hence, endian flipped) the input buffer before calling this function. */
+
+int
+sframe_fde_tbl_reloc_fixup (sframe_decoder_ctx *dctx)
+{
+ uint8_t sframe_ver = sframe_decoder_get_version (dctx);
+ uint32_t num_fdes = sframe_decoder_get_num_fidx (dctx);
+ unsigned int buf_offset = 0;
+ sframe_func_desc_entry *fde;
+ uint32_t i = 0;
+
+ if (sframe_ver != SFRAME_VERSION_2 || !dctx->sfd_funcdesc)
+ return SFRAME_ERR;
+
+ buf_offset += sframe_decoder_get_hdr_size (dctx);
+ while (i < num_fdes)
+ {
+ fde = &dctx->sfd_funcdesc[i];
+ fde->sfde_func_start_address += buf_offset;
+ buf_offset += sizeof (sframe_func_desc_entry);
+ i++;
+ }
+
+ return 0;
+}
+
/* Get the SFrame header size. */
static uint32_t
--
2.43.0
More information about the Binutils
mailing list