From: Indu Bhagat Date: Fri, 16 Jan 2026 00:41:55 +0000 (-0800) Subject: [SFrame-V3] sframe: gas: libsframe: use uint16_t for num_fres of FDE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=577538426991e718564936ab8bc1d2138ce9b8b7;p=thirdparty%2Fbinutils-gdb.git [SFrame-V3] sframe: gas: libsframe: use uint16_t for num_fres of FDE Reduce the size of the num_fres field in the Function Descriptor Entry (FDE) from 32 bits to 16 bits. The number of Frame Row Entries (FREs) for a single function is extremely unlikely to exceed 65,535 in real-world scenarios. Reducing this field saves 2 bytes per FDE, contributing to a smaller overall SFrame section size. (BTW, these savings will be eaten up by a later commit which adds support for text > 2 GiB by increasing an offset from int32_t to int64_t). Safety checks are added to the assembler to warn and skip SFrame FDE generation if a function's FRE count exceeds UINT16_MAX. Note regarding alignment: With the current patch, the members of sframe_func_desc_entry_v3 are not at aligned boundaries anymore. Recall that all sframe_func_desc_entry_v3 entries are stored together in the "SFrame FDE sub-section" forming an index. Only after a later patch in the series "[29/36] [SFrame-V3] include: gas: libsframe: split FDE into desc and attr" will the alignment properties of SFrame index will be restored. include/ * sframe.h (sframe_func_desc_entry_v3): Change sfde_func_num_fres type to uint16_t. gas/ * gen-sframe.c (output_sframe_funcdesc): Write 2 bytes for num_fres and assert it fits in uint16_t. (sframe_do_fde): Add check to skip FDE emission if num_fres exceeds UINT16_MAX. libsframe/ * sframe.c (sframe_encoder_write_fde): Cast num_fres to uint16_t to ensure correctly written out data. * testsuite/libsframe.decode/DATA2: Update binary test data. --- diff --git a/gas/gen-sframe.c b/gas/gen-sframe.c index 8f4a0b10121..ce9243e99dd 100644 --- a/gas/gen-sframe.c +++ b/gas/gen-sframe.c @@ -715,8 +715,9 @@ output_sframe_funcdesc (symbolS *start_of_fre_section, sfde_func_start_fre_off)); } - /* Number of FREs. */ - out_four (sframe_fde->num_fres); + /* Number of FREs must fit uint16_t. */ + gas_assert (sframe_fde->num_fres <= UINT16_MAX); + out_two (sframe_fde->num_fres); /* SFrame FDE function info. */ unsigned char func_info; @@ -2030,6 +2031,20 @@ sframe_do_fde (struct sframe_xlate_ctx *xlate_ctx, = get_dw_fde_end_addrS (xlate_ctx->dw_fde); } + /* Number of FREs must fit uint16_t. Check now, and do not emit the SFrame + FDE if it doesnt fit (although, it is not expected to happen for + real-world, useful programs). The approach of truncating the FDE and + emitting multiple SFrame FDEs instead, is not a clearly preferable + handling either. Its a divergence from the model where an SFrame FDE + encodes stack trace data between a .cfi_startproc and .cfi_endproc pair. + Further, some components (linkers, stack tracers) want to associate the + Start PC of a function to a known symbol in the file? */ + if (xlate_ctx->num_xlate_fres > UINT16_MAX) + { + as_warn (_("no SFrame FDE emitted; Number of FREs exceeds UINT16_MAX")); + return SFRAME_XLATE_ERR_NOTREPRESENTED; + } + /* ABI/arch except s390x cannot represent FP without RA saved. */ if (sframe_ra_tracking_p () && sframe_get_abi_arch () != SFRAME_ABI_S390X_ENDIAN_BIG) diff --git a/include/sframe.h b/include/sframe.h index 7d3d9840e03..aa3c0872e0c 100644 --- a/include/sframe.h +++ b/include/sframe.h @@ -256,7 +256,7 @@ typedef struct sframe_func_desc_entry_v3 beginning of the SFrame Frame Row Entry sub-section. */ uint32_t sfde_func_start_fre_off; /* Number of frame row entries for the function. */ - uint32_t sfde_func_num_fres; + uint16_t sfde_func_num_fres; /* Additional information for stack tracing from the function: - 4-bits: Identify the FRE type used for the function. - 1-bit: Identify the PC type of the function - mask or inc. diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 7dccdc097d4..b942a2c3810 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -2140,7 +2140,7 @@ sframe_encoder_write_fde (const sframe_header *sfhp ATTRIBUTE_UNUSED, fdep->sfde_func_start_address = (int32_t)fde->func_start_pc_offset; fdep->sfde_func_size = fde->func_size; fdep->sfde_func_start_fre_off = fde->func_start_fre_off; - fdep->sfde_func_num_fres = fde->func_num_fres; + fdep->sfde_func_num_fres = (uint16_t)fde->func_num_fres; fdep->sfde_func_info = fde->func_info; fdep->sfde_func_rep_size = fde->func_rep_size; fdep->sfde_func_padding2 = 0; diff --git a/libsframe/testsuite/libsframe.decode/DATA2 b/libsframe/testsuite/libsframe.decode/DATA2 index aa62398b2ca..7a218f86bcc 100644 Binary files a/libsframe/testsuite/libsframe.decode/DATA2 and b/libsframe/testsuite/libsframe.decode/DATA2 differ