From: Indu Bhagat Date: Thu, 24 Apr 2025 21:59:56 +0000 (-0700) Subject: include: libsframe: define new flag SFRAME_F_FDE_FUNC_START_ADDR_PCREL X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4880e6281f0c83df6108316f3e066d6efd1aaebe;p=thirdparty%2Fbinutils-gdb.git include: libsframe: define new flag SFRAME_F_FDE_FUNC_START_ADDR_PCREL Add a new flag SFRAME_F_FDE_FUNC_START_ADDR_PCREL to SFrame stack trace format. If set, this flag indicates that the function start address field (sfde_func_start_address) is the offset to the function start address from the SFrame FDE function start address field itself. Such an encoding is friendlier to the exisitng PC-REL relocations available in the ABIs supported in SFrame: AMD64 (R_X86_64_PC32) and AArch64 (R_AARCH64_PREL32). In subsequent patches, we will make the implementation in gas and ld to both: - emit the values in the same (above-mentioned) encoding uniformly. - set the flag SFRAME_F_FDE_FUNC_START_ADDR_PCREL in the SFrame header for consumers to be able to distinguish. include/ * sframe.h (SFRAME_F_FDE_FUNC_START_ADDR_PCREL): New definition. libsframe/ * sframe-dump.c (MAX_NUM_FLAGS, flags_helper): Update to include the new flag. * sframe.c (sframe_header_sanity_check_p): Use uint8_t. --- diff --git a/include/sframe.h b/include/sframe.h index a965e23bdd1..9f5d0e78e89 100644 --- a/include/sframe.h +++ b/include/sframe.h @@ -82,9 +82,15 @@ extern "C" /* Various flags for SFrame. */ /* Function Descriptor Entries are sorted on PC. */ -#define SFRAME_F_FDE_SORTED 0x1 +#define SFRAME_F_FDE_SORTED 0x1 /* Functions preserve frame pointer. */ -#define SFRAME_F_FRAME_POINTER 0x2 +#define SFRAME_F_FRAME_POINTER (0x1 << 1) +/* Function start address in SFrame FDE is encoded as the distance from the + location of the sfde_func_start_address to the start PC of the function. + If absent, the function start address in SFrame FDE is encoded as the + distance from the start of the SFrame FDE section to the start PC of the + function. */ +#define SFRAME_F_FDE_FUNC_START_ADDR_PCREL (0x1 << 2) #define SFRAME_CFA_FIXED_FP_INVALID 0 #define SFRAME_CFA_FIXED_RA_INVALID 0 diff --git a/libsframe/sframe-dump.c b/libsframe/sframe-dump.c index d6f838d4fc0..200530ffeb9 100644 --- a/libsframe/sframe-dump.c +++ b/libsframe/sframe-dump.c @@ -61,10 +61,11 @@ dump_sframe_header_flags (sframe_decoder_ctx *sfd_ctx) /* PS: Keep SFRAME_FLAGS_STR_MAX_LEN in sync if adding more members to this array. */ #define SFRAME_FLAGS_STR_MAX_LEN 50 -#define MAX_NUM_FLAGS 2 +#define MAX_NUM_FLAGS 3 const struct dump_flags_helper flags_helper[MAX_NUM_FLAGS] = { { SFRAME_F_FDE_SORTED, "SFRAME_F_FDE_SORTED"}, - { SFRAME_F_FRAME_POINTER, "SFRAME_F_FRAME_POINTER"} + { SFRAME_F_FRAME_POINTER, "SFRAME_F_FRAME_POINTER"}, + { SFRAME_F_FDE_FUNC_START_ADDR_PCREL, "SFRAME_F_FDE_FUNC_START_ADDR_PCREL"} }; /* Prepare SFrame section flags string. */ diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 8e9990058b6..4de4151d0b2 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -204,7 +204,8 @@ flip_fde (sframe_func_desc_entry *fdep) static bool sframe_header_sanity_check_p (sframe_header *hp) { - unsigned char all_flags = SFRAME_F_FDE_SORTED | SFRAME_F_FRAME_POINTER; + uint8_t all_flags = (SFRAME_F_FDE_SORTED | SFRAME_F_FRAME_POINTER + | SFRAME_F_FDE_FUNC_START_ADDR_PCREL); /* Check preamble is valid. */ if (hp->sfh_preamble.sfp_magic != SFRAME_MAGIC || (hp->sfh_preamble.sfp_version != SFRAME_VERSION_1