mirror of
https://github.com/encounter/objdiff.git
synced 2025-08-12 06:59:22 +00:00
Fix data section not showing when there is no section on the other side
This commit is contained in:
parent
a015971c20
commit
34e4513c69
@ -127,6 +127,28 @@ fn diff_data_relocs_for_range<'left, 'right>(
|
|||||||
diffs
|
diffs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn no_diff_data_section(obj: &Object, section_idx: usize) -> Result<SectionDiff> {
|
||||||
|
let section = &obj.sections[section_idx];
|
||||||
|
let len = section.data.len();
|
||||||
|
let data = §ion.data[0..len];
|
||||||
|
|
||||||
|
let data_diff =
|
||||||
|
vec![DataDiff { data: data.to_vec(), kind: DataDiffKind::None, len, ..Default::default() }];
|
||||||
|
|
||||||
|
let mut reloc_diffs = Vec::new();
|
||||||
|
for reloc in section.relocations.iter() {
|
||||||
|
let reloc_len = obj.arch.data_reloc_size(reloc.flags);
|
||||||
|
let range = reloc.address as usize..reloc.address as usize + reloc_len;
|
||||||
|
reloc_diffs.push(DataRelocationDiff {
|
||||||
|
reloc: reloc.clone(),
|
||||||
|
kind: DataDiffKind::None,
|
||||||
|
range,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(SectionDiff { match_percent: Some(0.0), data_diff, reloc_diff: reloc_diffs })
|
||||||
|
}
|
||||||
|
|
||||||
/// Compare the data sections of two object files.
|
/// Compare the data sections of two object files.
|
||||||
pub fn diff_data_section(
|
pub fn diff_data_section(
|
||||||
left_obj: &Object,
|
left_obj: &Object,
|
||||||
@ -415,6 +437,10 @@ pub fn diff_generic_section(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn no_diff_bss_section() -> Result<SectionDiff> {
|
||||||
|
Ok(SectionDiff { match_percent: Some(0.0), data_diff: vec![], reloc_diff: vec![] })
|
||||||
|
}
|
||||||
|
|
||||||
/// Compare the addresses and sizes of each symbol in the BSS sections.
|
/// Compare the addresses and sizes of each symbol in the BSS sections.
|
||||||
pub fn diff_bss_section(
|
pub fn diff_bss_section(
|
||||||
left_obj: &Object,
|
left_obj: &Object,
|
||||||
|
@ -13,7 +13,7 @@ use crate::{
|
|||||||
code::{diff_code, no_diff_code},
|
code::{diff_code, no_diff_code},
|
||||||
data::{
|
data::{
|
||||||
diff_bss_section, diff_bss_symbol, diff_data_section, diff_data_symbol,
|
diff_bss_section, diff_bss_symbol, diff_data_section, diff_data_symbol,
|
||||||
diff_generic_section,
|
diff_generic_section, no_diff_bss_section, no_diff_data_section,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
obj::{InstructionRef, Object, Relocation, SectionKind, Symbol, SymbolFlag},
|
obj::{InstructionRef, Object, Relocation, SectionKind, Symbol, SymbolFlag},
|
||||||
@ -288,52 +288,84 @@ pub fn diff_objs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for section_match in section_matches {
|
for section_match in section_matches {
|
||||||
if let SectionMatch {
|
match section_match {
|
||||||
left: Some(left_section_idx),
|
SectionMatch {
|
||||||
right: Some(right_section_idx),
|
left: Some(left_section_idx),
|
||||||
section_kind,
|
right: Some(right_section_idx),
|
||||||
} = section_match
|
section_kind,
|
||||||
{
|
} => {
|
||||||
let (left_obj, left_out) = left.as_mut().unwrap();
|
let (left_obj, left_out) = left.as_mut().unwrap();
|
||||||
let (right_obj, right_out) = right.as_mut().unwrap();
|
let (right_obj, right_out) = right.as_mut().unwrap();
|
||||||
match section_kind {
|
match section_kind {
|
||||||
SectionKind::Code => {
|
SectionKind::Code => {
|
||||||
let (left_diff, right_diff) = diff_generic_section(
|
let (left_diff, right_diff) = diff_generic_section(
|
||||||
left_obj,
|
left_obj,
|
||||||
right_obj,
|
right_obj,
|
||||||
left_out,
|
left_out,
|
||||||
right_out,
|
right_out,
|
||||||
left_section_idx,
|
left_section_idx,
|
||||||
right_section_idx,
|
right_section_idx,
|
||||||
)?;
|
)?;
|
||||||
left_out.sections[left_section_idx] = left_diff;
|
left_out.sections[left_section_idx] = left_diff;
|
||||||
right_out.sections[right_section_idx] = right_diff;
|
right_out.sections[right_section_idx] = right_diff;
|
||||||
|
}
|
||||||
|
SectionKind::Data => {
|
||||||
|
let (left_diff, right_diff) = diff_data_section(
|
||||||
|
left_obj,
|
||||||
|
right_obj,
|
||||||
|
left_out,
|
||||||
|
right_out,
|
||||||
|
left_section_idx,
|
||||||
|
right_section_idx,
|
||||||
|
)?;
|
||||||
|
left_out.sections[left_section_idx] = left_diff;
|
||||||
|
right_out.sections[right_section_idx] = right_diff;
|
||||||
|
}
|
||||||
|
SectionKind::Bss | SectionKind::Common => {
|
||||||
|
let (left_diff, right_diff) = diff_bss_section(
|
||||||
|
left_obj,
|
||||||
|
right_obj,
|
||||||
|
left_out,
|
||||||
|
right_out,
|
||||||
|
left_section_idx,
|
||||||
|
right_section_idx,
|
||||||
|
)?;
|
||||||
|
left_out.sections[left_section_idx] = left_diff;
|
||||||
|
right_out.sections[right_section_idx] = right_diff;
|
||||||
|
}
|
||||||
|
SectionKind::Unknown => unreachable!(),
|
||||||
}
|
}
|
||||||
SectionKind::Data => {
|
}
|
||||||
let (left_diff, right_diff) = diff_data_section(
|
SectionMatch { left: Some(left_section_idx), right: None, section_kind } => {
|
||||||
left_obj,
|
let (left_obj, left_out) = left.as_mut().unwrap();
|
||||||
right_obj,
|
match section_kind {
|
||||||
left_out,
|
SectionKind::Code => {}
|
||||||
right_out,
|
SectionKind::Data => {
|
||||||
left_section_idx,
|
left_out.sections[left_section_idx] =
|
||||||
right_section_idx,
|
no_diff_data_section(left_obj, left_section_idx)?;
|
||||||
)?;
|
}
|
||||||
left_out.sections[left_section_idx] = left_diff;
|
SectionKind::Bss | SectionKind::Common => {
|
||||||
right_out.sections[right_section_idx] = right_diff;
|
left_out.sections[left_section_idx] = no_diff_bss_section()?;
|
||||||
|
}
|
||||||
|
SectionKind::Unknown => unreachable!(),
|
||||||
}
|
}
|
||||||
SectionKind::Bss | SectionKind::Common => {
|
}
|
||||||
let (left_diff, right_diff) = diff_bss_section(
|
SectionMatch { left: None, right: Some(right_section_idx), section_kind } => {
|
||||||
left_obj,
|
let (right_obj, right_out) = right.as_mut().unwrap();
|
||||||
right_obj,
|
match section_kind {
|
||||||
left_out,
|
SectionKind::Code => {}
|
||||||
right_out,
|
SectionKind::Data => {
|
||||||
left_section_idx,
|
right_out.sections[right_section_idx] =
|
||||||
right_section_idx,
|
no_diff_data_section(right_obj, right_section_idx)?;
|
||||||
)?;
|
}
|
||||||
left_out.sections[left_section_idx] = left_diff;
|
SectionKind::Bss | SectionKind::Common => {
|
||||||
right_out.sections[right_section_idx] = right_diff;
|
right_out.sections[right_section_idx] = no_diff_bss_section()?;
|
||||||
|
}
|
||||||
|
SectionKind::Unknown => unreachable!(),
|
||||||
}
|
}
|
||||||
SectionKind::Unknown => unreachable!(),
|
}
|
||||||
|
SectionMatch { left: None, right: None, .. } => {
|
||||||
|
// Should not happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user