[PATCH 3/3] libsframe: correct binary search for SFrame FDE
Jens Remus
jremus@linux.ibm.com
Wed May 21 08:30:59 GMT 2025
sframe_get_funcdesc_with_addr_internal erroneously returns the last
FDE of the .sframe FDE subsection, if its function start address is
lower than the searched for address.
Simplify the binary search for a SFrame FDE for a given address. Only
return a FDE, if the searched for address is within the bounds of the
FDE function start address and function size.
libsframe/
* sframe.c (sframe_get_funcdesc_with_addr_internal): Correct
binary search for SFrame FDE.
libsframe/testsuite/
* libsframe.find/plt-findfre-1.c: Add test for out of range
PLT6.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
libsframe/sframe.c | 15 +++++----------
.../testsuite/libsframe.find/plt-findfre-1.c | 5 +++++
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index a4dd58adb621..50a450ee2517 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1023,7 +1023,7 @@ sframe_get_funcdesc_with_addr_internal (sframe_decoder_ctx *ctx, int32_t addr,
{
sframe_header *dhp;
sframe_func_desc_entry *fdp;
- int low, high, cnt;
+ int low, high;
if (ctx == NULL)
return sframe_ret_set_errno (errp, SFRAME_ERR_INVAL);
@@ -1041,22 +1041,17 @@ sframe_get_funcdesc_with_addr_internal (sframe_decoder_ctx *ctx, int32_t addr,
fdp = (sframe_func_desc_entry *) ctx->sfd_funcdesc;
low = 0;
high = dhp->sfh_num_fdes;
- cnt = high;
while (low <= high)
{
int mid = low + (high - low) / 2;
- if (fdp[mid].sfde_func_start_address == addr)
+ if (fdp[mid].sfde_func_start_address <= addr
+ && addr < (int32_t) (fdp[mid].sfde_func_start_address
+ + fdp[mid].sfde_func_size))
return fdp + mid;
if (fdp[mid].sfde_func_start_address < addr)
- {
- if (mid == (cnt - 1)) /* Check if it's the last one. */
- return fdp + (cnt - 1);
- else if (fdp[mid+1].sfde_func_start_address > addr)
- return fdp + mid;
- low = mid + 1;
- }
+ low = mid + 1;
else
high = mid - 1;
}
diff --git a/libsframe/testsuite/libsframe.find/plt-findfre-1.c b/libsframe/testsuite/libsframe.find/plt-findfre-1.c
index a1e9d15b5eec..604c5fe0b995 100644
--- a/libsframe/testsuite/libsframe.find/plt-findfre-1.c
+++ b/libsframe/testsuite/libsframe.find/plt-findfre-1.c
@@ -124,6 +124,11 @@ void test_plt_findfre (unsigned int plt_vaddr, unsigned int sframe_vaddr)
TEST ("plt-findfre-1: Find last FRE in PLT4",
((err == 0) && (sframe_fre_get_cfa_offset (dctx, &frep, &err) == 0x3)));
+ /* Find no FRE for out of range PLT6. */
+ err = sframe_find_fre (dctx, (0x1000 + 16*5 + 0x0), &frep);
+ TEST("plt-findfre-1: Find no FRE for out of range PLT6",
+ (err != 0));
+
sframe_encoder_free (&ectx);
sframe_decoder_free (&dctx);
}
--
2.45.2
More information about the Binutils
mailing list