[PATCH 1/3] libsframe: fix issue in finding FRE in SFRAME_FDE_TYPE_PCMASK type SFrame FDEs
Jan Beulich
jbeulich@suse.com
Wed May 21 06:15:25 GMT 2025
On 20.05.2025 21:03, Indu Bhagat wrote:
> Lookup of information from SFrame FDEs of type SFRAME_FDE_TYPE_PCMASK,
> typically used for pltN entries had an issue: the current code will only
> work for certain placements of .plt and .sframe. Fix it, and add a
> testcase.
>
> Make the testcase itself easier to follow by adding appropriate vars
> where applicable.
>
> libsframe/
> * sframe.c (sframe_fre_check_range_p): Fix logic for
> SFRAME_FDE_TYPE_PCMASK type FDE.
> libsframe/testsuite/
> * libsframe.find/plt-findfre-1.c: Adjust the test for a variety
> of placements of .sframe and .plt.
> ---
> libsframe/sframe.c | 11 ++--
> .../testsuite/libsframe.find/plt-findfre-1.c | 59 ++++++++++++-------
> 2 files changed, 45 insertions(+), 25 deletions(-)
>
> diff --git a/libsframe/sframe.c b/libsframe/sframe.c
> index c2693b978ec..85457e4d660 100644
> --- a/libsframe/sframe.c
> +++ b/libsframe/sframe.c
> @@ -398,10 +398,13 @@ sframe_fre_check_range_p (sframe_func_desc_entry *fdep,
> }
> else
> {
> - /* For FDEs for repetitive pattern of insns, we need to return the FRE
> - where pc % rep_block_size is between start_ip_offset and
> - end_ip_offset. */
> - masked_pc = pc % rep_block_size;
> + /* For SFrame FDEs encoding information for repetitive pattern of insns,
> + masking with the rep_block_size is necessary to find the matching FRE.
> + start_ip_offset and end_ip_offset are _unsigned_values_ identifying
> + the SFrame FRE. So, perform a calculation to first get the distance
> + between the pc and func_start_addr, followed by modulo to find the
> + fitting range. */
> + masked_pc = (pc - func_start_addr) % rep_block_size;
> ret = ((start_ip_offset <= masked_pc) && (end_ip_offset >= masked_pc));
> }
Sadly the description only says that there was an issue, but not what that issue
was. The comment and code change here leaves me guessing, too: Is the problem
with the block of repetitive patterns not being aligned to a multiple of the
block size? Contextual information may also be necessary (I'm sorry for my
continued lack of SFram knowledge): Such a block (PLT being an example) is all
covered by a single FDE? Rather than each PLT entry having its own? That's kind
of unexpected considering that the first 2(?) PLT entries can be slightly
different from the rest, iirc.
> +int main (void)
> +{
> + unsigned int sframe_vaddr = 0x402220;
> + unsigned int plt_vaddr = 0x401020;
> + printf ("Testing with plt_vaddr = 0x%x; sframe_vaddr = 0x%x\n", plt_vaddr,
> + sframe_vaddr);
> + test_plt_findfre (plt_vaddr, sframe_vaddr);
> +
> + sframe_vaddr = 0x401020;
> + plt_vaddr = 0x402220;
> + printf ("Testing with plt_vaddr = 0x%x; sframe_vaddr = 0x%x\n", plt_vaddr,
> + sframe_vaddr);
> + test_plt_findfre (plt_vaddr, sframe_vaddr);
> }
While in a testcase it doesn't matter as much, I think it is generally a good
idea to prefer %#x and alike over 0x%x even there, just to be consistent
throughout.
Jan
More information about the Binutils
mailing list