Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions objdiff-core/src/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::{
},
obj::{
FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation,
RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet,
SymbolKind,
RelocationFlags, ResolvedInstructionRef, ResolvedRelocation, ResolvedSymbol, Section,
Symbol, SymbolFlagSet, SymbolKind,
},
util::ReallySigned,
};
Expand Down Expand Up @@ -464,12 +464,17 @@ pub trait Arch: Any + Debug + Send + Sync {

fn guess_data_type(
&self,
_resolved: ResolvedInstructionRef,
_ins: Option<ResolvedInstructionRef>,
_reloc: Option<ResolvedRelocation>,
_bytes: &[u8],
) -> Option<DataType> {
None
}

fn guess_ins_data_type(&self, ins: ResolvedInstructionRef, bytes: &[u8]) -> Option<DataType> {
self.guess_data_type(Some(ins), ins.relocation, bytes)
}

fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec<HoverItem> { Vec::new() }

fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec<ContextItem> { Vec::new() }
Expand Down
19 changes: 13 additions & 6 deletions objdiff-core/src/arch/ppc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,13 @@ impl Arch for ArchPpc {
}
}

fn guess_data_type(&self, resolved: ResolvedInstructionRef, bytes: &[u8]) -> Option<DataType> {
if resolved.relocation.is_some_and(|r| {
fn guess_data_type(
&self,
ins: Option<ResolvedInstructionRef>,
reloc: Option<ResolvedRelocation>,
bytes: &[u8],
) -> Option<DataType> {
if reloc.is_some_and(|r| {
r.symbol.name.starts_with("@stringBase")
|| r.symbol.name.starts_with("@wstringBase")
|| r.symbol.name.starts_with("$SG")
Expand All @@ -367,10 +372,12 @@ impl Arch for ArchPpc {
// Compiler-generated symbol name for a string or a pool of strings.
return Some(DataType::String);
}
let opcode = powerpc::Opcode::from(resolved.ins_ref.opcode);
if let Some(ty) = flow_analysis::guess_data_type_from_load_store_inst_op(opcode) {
// Numeric type.
return Some(ty);
if let Some(ins) = ins {
let opcode = powerpc::Opcode::from(ins.ins_ref.opcode);
if let Some(ty) = flow_analysis::guess_data_type_from_load_store_inst_op(opcode) {
// Numeric type.
return Some(ty);
}
}
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) {
// It may be an unpooled string if the symbol contains exactly one null byte at the end of the symbol.
Expand Down
43 changes: 25 additions & 18 deletions objdiff-core/src/diff/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,18 +499,16 @@ pub fn relocation_context(
) -> Vec<ContextItem> {
let mut out = Vec::new();
out.append(&mut symbol_context(obj, reloc.relocation.target_symbol));
if let Some(ins) = ins {
let mut literals = display_ins_data_literals(obj, ins);
literals.retain(|lit_info| !lit_info.hidden(diff_config));
if !literals.is_empty() {
out.push(ContextItem::Separator);
for lit_info in literals {
out.push(ContextItem::Copy {
value: lit_info.literal,
label: lit_info.label_override,
copy_string: lit_info.copy_string,
});
}
let mut literals = display_data_literals(obj, ins, Some(reloc));
literals.retain(|lit_info| !lit_info.hidden(diff_config));
if !literals.is_empty() {
out.push(ContextItem::Separator);
for lit_info in literals {
out.push(ContextItem::Copy {
value: lit_info.literal,
label: lit_info.label_override,
copy_string: lit_info.copy_string,
});
}
}
out
Expand Down Expand Up @@ -563,6 +561,7 @@ pub fn data_row_context(obj: &Object, diff_row: &DataDiffRow) -> Vec<ContextItem

let reloc = resolve_relocation(&obj.symbols, reloc);
out.append(&mut relocation_context(obj, reloc, None, None));
out.push(ContextItem::Separator);
}
out
}
Expand Down Expand Up @@ -695,7 +694,7 @@ pub fn instruction_hover(
out.push(HoverItem::Separator);
out.append(&mut relocation_hover(obj, reloc, None));
let bytes = obj.symbol_data(reloc.relocation.target_symbol).unwrap_or(&[]);
if let Some(ty) = obj.arch.guess_data_type(resolved, bytes) {
if let Some(ty) = obj.arch.guess_ins_data_type(resolved, bytes) {
let mut literals = display_ins_data_literals(obj, resolved);
literals.retain(|lit_info| !lit_info.hidden(Some(diff_config)));
if !literals.is_empty() {
Expand Down Expand Up @@ -882,16 +881,17 @@ pub fn display_ins_data_labels(obj: &Object, resolved: ResolvedInstructionRef) -
};
let bytes = &data[reloc.relocation.addend as usize..];
obj.arch
.guess_data_type(resolved, bytes)
.guess_ins_data_type(resolved, bytes)
.map(|ty| ty.display_labels(obj.endianness, bytes))
.unwrap_or_default()
}

pub fn display_ins_data_literals(
pub fn display_data_literals(
obj: &Object,
resolved: ResolvedInstructionRef,
resolved: Option<ResolvedInstructionRef>,
reloc: Option<ResolvedRelocation>,
) -> Vec<LiteralInfo> {
let Some(reloc) = resolved.relocation else {
let Some(reloc) = reloc else {
return Vec::new();
};
if reloc.relocation.addend < 0 || reloc.relocation.addend as u64 >= reloc.symbol.size {
Expand All @@ -902,7 +902,14 @@ pub fn display_ins_data_literals(
};
let bytes = &data[reloc.relocation.addend as usize..];
obj.arch
.guess_data_type(resolved, bytes)
.guess_data_type(resolved, Some(reloc), bytes)
.map(|ty| ty.display_literals(obj.endianness, bytes))
.unwrap_or_default()
}

pub fn display_ins_data_literals(
obj: &Object,
resolved: ResolvedInstructionRef,
) -> Vec<LiteralInfo> {
display_data_literals(obj, Some(resolved), resolved.relocation)
}
Loading