mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-09 05:27:47 +00:00
Diff cleanup & fixes
This commit is contained in:
@@ -10,10 +10,10 @@ use similar::{capture_diff_slices_deadline, Algorithm};
|
||||
use crate::{
|
||||
arch::ProcessCodeResult,
|
||||
diff::{
|
||||
get_symbol, DiffObjConfig, ObjInsArgDiff, ObjInsBranchFrom, ObjInsBranchTo, ObjInsDiff,
|
||||
ObjInsDiffKind, ObjSymbolDiff, SymbolRef,
|
||||
DiffObjConfig, ObjInsArgDiff, ObjInsBranchFrom, ObjInsBranchTo, ObjInsDiff, ObjInsDiffKind,
|
||||
ObjSymbolDiff,
|
||||
},
|
||||
obj::{ObjInfo, ObjInsArg, ObjReloc, ObjSymbol, ObjSymbolFlags},
|
||||
obj::{ObjInfo, ObjInsArg, ObjReloc, ObjSymbol, ObjSymbolFlags, SymbolRef},
|
||||
};
|
||||
|
||||
pub fn no_diff_code(
|
||||
@@ -21,8 +21,7 @@ pub fn no_diff_code(
|
||||
symbol_ref: SymbolRef,
|
||||
config: &DiffObjConfig,
|
||||
) -> Result<ObjSymbolDiff> {
|
||||
let section = &obj.sections[symbol_ref.section_idx];
|
||||
let symbol = §ion.symbols[symbol_ref.symbol_idx];
|
||||
let (section, symbol) = obj.section_symbol(symbol_ref);
|
||||
let code = §ion.data
|
||||
[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
|
||||
let out = obj.arch.process_code(
|
||||
@@ -48,8 +47,8 @@ pub fn diff_code(
|
||||
right_symbol_ref: SymbolRef,
|
||||
config: &DiffObjConfig,
|
||||
) -> Result<(ObjSymbolDiff, ObjSymbolDiff)> {
|
||||
let (left_section, left_symbol) = get_symbol(left_obj, left_symbol_ref);
|
||||
let (right_section, right_symbol) = get_symbol(right_obj, right_symbol_ref);
|
||||
let (left_section, left_symbol) = left_obj.section_symbol(left_symbol_ref);
|
||||
let (right_section, right_symbol) = right_obj.section_symbol(right_symbol_ref);
|
||||
let left_code = &left_section.data[left_symbol.section_address as usize
|
||||
..(left_symbol.section_address + left_symbol.size) as usize];
|
||||
let right_code = &right_section.data[right_symbol.section_address as usize
|
||||
|
||||
@@ -7,9 +7,10 @@ use anyhow::Result;
|
||||
use similar::{capture_diff_slices_deadline, Algorithm};
|
||||
|
||||
use crate::{
|
||||
diff::{get_symbol, ObjDataDiff, ObjDataDiffKind, ObjSectionDiff, ObjSymbolDiff, SymbolRef},
|
||||
diff::{ ObjDataDiff, ObjDataDiffKind, ObjSectionDiff, ObjSymbolDiff},
|
||||
obj::{ObjInfo, ObjSection},
|
||||
};
|
||||
use crate::obj::SymbolRef;
|
||||
|
||||
pub fn diff_bss_symbol(
|
||||
left_obj: &ObjInfo,
|
||||
@@ -17,8 +18,8 @@ pub fn diff_bss_symbol(
|
||||
left_symbol_ref: SymbolRef,
|
||||
right_symbol_ref: SymbolRef,
|
||||
) -> Result<(ObjSymbolDiff, ObjSymbolDiff)> {
|
||||
let (_, left_symbol) = get_symbol(left_obj, left_symbol_ref);
|
||||
let (_, right_symbol) = get_symbol(right_obj, right_symbol_ref);
|
||||
let (_, left_symbol) = left_obj.section_symbol(left_symbol_ref);
|
||||
let (_, right_symbol) = right_obj.section_symbol(right_symbol_ref);
|
||||
let percent = if left_symbol.size == right_symbol.size { 100.0 } else { 50.0 };
|
||||
Ok((
|
||||
ObjSymbolDiff {
|
||||
|
||||
@@ -2,6 +2,8 @@ mod code;
|
||||
mod data;
|
||||
pub mod display;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{
|
||||
@@ -9,7 +11,7 @@ use crate::{
|
||||
code::{diff_code, no_diff_code},
|
||||
data::{diff_bss_symbol, diff_data, no_diff_bss_symbol},
|
||||
},
|
||||
obj::{ObjInfo, ObjIns, ObjSection, ObjSectionKind, ObjSymbol},
|
||||
obj::{ObjInfo, ObjIns, ObjSectionKind, SymbolRef},
|
||||
};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
@@ -313,19 +315,6 @@ pub fn diff_objs(
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct SymbolRef {
|
||||
pub section_idx: usize,
|
||||
pub symbol_idx: usize,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_symbol(obj: &ObjInfo, ref_: SymbolRef) -> (&ObjSection, &ObjSymbol) {
|
||||
let section = &obj.sections[ref_.section_idx];
|
||||
let symbol = §ion.symbols[ref_.symbol_idx];
|
||||
(section, symbol)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
struct SymbolMatch {
|
||||
left: Option<SymbolRef>,
|
||||
@@ -348,7 +337,7 @@ fn matching_symbols(
|
||||
prev: Option<&ObjInfo>,
|
||||
) -> Result<Vec<SymbolMatch>> {
|
||||
let mut matches = Vec::new();
|
||||
let mut right_used = Vec::new();
|
||||
let mut right_used = HashSet::new();
|
||||
if let Some(left) = left {
|
||||
for (section_idx, section) in left.sections.iter().enumerate() {
|
||||
for (symbol_idx, symbol) in section.symbols.iter().enumerate() {
|
||||
@@ -360,7 +349,7 @@ fn matching_symbols(
|
||||
};
|
||||
matches.push(symbol_match);
|
||||
if let Some(right) = symbol_match.right {
|
||||
right_used.push(right);
|
||||
right_used.insert(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,7 +358,7 @@ fn matching_symbols(
|
||||
for (section_idx, section) in right.sections.iter().enumerate() {
|
||||
for (symbol_idx, symbol) in section.symbols.iter().enumerate() {
|
||||
let symbol_ref = SymbolRef { section_idx, symbol_idx };
|
||||
if right_used.binary_search(&symbol_ref).is_ok() {
|
||||
if right_used.contains(&symbol_ref) {
|
||||
continue;
|
||||
}
|
||||
matches.push(SymbolMatch {
|
||||
|
||||
@@ -139,3 +139,17 @@ pub struct ObjReloc {
|
||||
pub target: ObjSymbol,
|
||||
pub target_section: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct SymbolRef {
|
||||
pub section_idx: usize,
|
||||
pub symbol_idx: usize,
|
||||
}
|
||||
|
||||
impl ObjInfo {
|
||||
pub fn section_symbol(&self, symbol_ref: SymbolRef) -> (&ObjSection, &ObjSymbol) {
|
||||
let section = &self.sections[symbol_ref.section_idx];
|
||||
let symbol = §ion.symbols[symbol_ref.symbol_idx];
|
||||
(section, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user