Skip to content

Commit fbf8563

Browse files
authored
PPC: Detect unpooled string literal references (#188)
* Update openssl and tokio for Cargo deny * PPC: Detect unpooled string literal references
1 parent 73a89d2 commit fbf8563

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objdiff-core/src/arch/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,13 @@ pub trait Arch: Send + Sync + Debug {
247247
SymbolFlagSet::default()
248248
}
249249

250-
fn guess_data_type(&self, _resolved: ResolvedInstructionRef) -> Option<DataType> { None }
250+
fn guess_data_type(
251+
&self,
252+
_resolved: ResolvedInstructionRef,
253+
_bytes: &[u8],
254+
) -> Option<DataType> {
255+
None
256+
}
251257

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

objdiff-core/src/arch/ppc.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,21 @@ impl Arch for ArchPpc {
221221
}
222222
}
223223

224-
fn guess_data_type(&self, resolved: ResolvedInstructionRef) -> Option<DataType> {
224+
fn guess_data_type(&self, resolved: ResolvedInstructionRef, bytes: &[u8]) -> Option<DataType> {
225225
if resolved.relocation.is_some_and(|r| r.symbol.name.starts_with("@stringBase")) {
226+
// Pooled string.
226227
return Some(DataType::String);
227228
}
228229
let opcode = ppc750cl::Opcode::from(resolved.ins_ref.opcode as u8);
229-
guess_data_type_from_load_store_inst_op(opcode)
230+
if let Some(ty) = guess_data_type_from_load_store_inst_op(opcode) {
231+
// Numeric type.
232+
return Some(ty);
233+
}
234+
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) {
235+
// It may be an unpooled string if the symbol contains exactly one null byte at the end of the symbol.
236+
return Some(DataType::String);
237+
}
238+
None
230239
}
231240

232241
fn symbol_hover(&self, _obj: &Object, symbol_index: usize) -> Vec<HoverItem> {

objdiff-core/src/diff/code.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ fn reloc_eq(
330330
|| address_eq(left_reloc, right_reloc))
331331
&& (diff_config.function_reloc_diffs == FunctionRelocDiffs::NameAddress
332332
|| left_reloc.symbol.kind != SymbolKind::Object
333+
|| right_reloc.symbol.size == 0 // Likely a pool symbol like ...data, don't treat this as a diff
333334
|| display_ins_data_literals(left_obj, left_ins)
334335
== display_ins_data_literals(right_obj, right_ins))
335336
}

objdiff-core/src/diff/display.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ pub fn instruction_hover(
564564
if let Some(reloc) = resolved.relocation {
565565
out.push(HoverItem::Separator);
566566
out.append(&mut relocation_hover(obj, reloc, None));
567-
if let Some(ty) = obj.arch.guess_data_type(resolved) {
567+
let bytes = obj.symbol_data(reloc.relocation.target_symbol).unwrap_or(&[]);
568+
if let Some(ty) = obj.arch.guess_data_type(resolved, bytes) {
568569
let literals = display_ins_data_literals(obj, resolved);
569570
if !literals.is_empty() {
570571
out.push(HoverItem::Separator);
@@ -758,7 +759,7 @@ pub fn display_ins_data_labels(obj: &Object, resolved: ResolvedInstructionRef) -
758759
};
759760
let bytes = &data[reloc.relocation.addend as usize..];
760761
obj.arch
761-
.guess_data_type(resolved)
762+
.guess_data_type(resolved, bytes)
762763
.map(|ty| ty.display_labels(obj.endianness, bytes))
763764
.unwrap_or_default()
764765
}
@@ -775,7 +776,7 @@ pub fn display_ins_data_literals(obj: &Object, resolved: ResolvedInstructionRef)
775776
};
776777
let bytes = &data[reloc.relocation.addend as usize..];
777778
obj.arch
778-
.guess_data_type(resolved)
779+
.guess_data_type(resolved, bytes)
779780
.map(|ty| ty.display_literals(obj.endianness, bytes))
780781
.unwrap_or_default()
781782
}

0 commit comments

Comments
 (0)