fix FDE binary search for case where PC is not exactly on first instruction

This commit is contained in:
Nikita Smith
2025-11-07 14:39:45 -08:00
committed by Ryan Fleury
parent d44efc15c8
commit 821af9b104
+6 -8
View File
@@ -340,7 +340,6 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
goto exit; goto exit;
} }
if (first <= pc && pc < last) {
U64 l = 0; U64 l = 0;
U64 r = header.fde_count - 1; U64 r = header.fde_count - 1;
while (l <= r) { while (l <= r) {
@@ -349,18 +348,17 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
U64 m_pc = 0; U64 m_pc = 0;
U64 m_pc_size = eh_parse_ptr(header.table, m_pc_off, ptr_ctx->pc_vaddr + m_pc_off, ptr_ctx, header.table_enc, &m_pc); U64 m_pc_size = eh_parse_ptr(header.table, m_pc_off, ptr_ctx->pc_vaddr + m_pc_off, ptr_ctx, header.table_enc, &m_pc);
Assert(m_pc_size); Assert(m_pc_size);
if (m_pc > pc) {
if (m_pc == pc) { r = m - 1;
fde_idx = m;
goto exit;
} else if (m_pc < pc) { } else if (m_pc < pc) {
l = m + 1; l = m + 1;
} else { } else {
r = m - 1; fde_idx = m;
goto exit;
} }
} }
fde_idx = l;
} fde_idx = l > 0 ? l-1 : 0;
} }
} }