Skip to content

Commit

Permalink
Check for existing function with bl
Browse files Browse the repository at this point in the history
Ensures that the analyzer won't
create a function when the target
is already contained within a
function. Useful with manual asm
that would otherwise trip up the
analyzer.

Partial work for #56
  • Loading branch information
encounter committed Jun 4, 2024
1 parent 6b60c13 commit 4701de3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/analysis/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
vm::{section_address_for, BranchTarget, GprValue, StepResult, VM},
RelocationTarget,
},
obj::{ObjInfo, ObjKind, ObjSection},
obj::{ObjInfo, ObjKind, ObjSection, ObjSymbolKind},
};

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -375,7 +375,24 @@ impl FunctionSlices {
}
}
if branch.link {
self.function_references.insert(addr);
// See if any existing functions contain this address,
// since this could be a label inside a larger function.
let last_function = obj
.symbols
.for_section_range(addr.section, ..addr.address)
.rfind(|(_, symbol)| symbol.kind == ObjSymbolKind::Function);
match last_function {
Some((_, symbol))
if symbol.address + symbol.size > addr.address as u64 =>
{
// Set the function reference to the start of the function
self.function_references.insert(SectionAddress::new(
addr.section,
symbol.address as u32,
))
}
_ => self.function_references.insert(addr),
};
} else {
out_branches.push(addr);
if self.add_block_start(addr) {
Expand Down

0 comments on commit 4701de3

Please sign in to comment.