Skip to content

Commit e638d0b

Browse files
authored
Implementation of basic data flow analysis for PowerPC (#212)
* WIP implementation * * Move flow analysis to dedicated file * Show string constants inline * Handle calls to MWCC "sled" helpers which otherwise disrupt flow analysis * Run cargo insta review * Apply clippy feedback * Update more tests. * Remove std use from ppc flow analysis * Try to make wasm build work again * More test changes * Probably last wasm fix * Formatting * Fix WASM * One more clippy thing * Fixed display of float constants in a LFS or LFD instruction in case where there is a branch to the subsequent instruction with a different register value. * On lines with a reloc, only hide Symbol type data flow values rather than all data flow values. * Formatting
1 parent f58616b commit e638d0b

25 files changed

+870
-66
lines changed

objdiff-cli/src/views/function_diff.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ impl FunctionDiffUi {
570570
DiffTextColor::Normal => Color::Gray,
571571
DiffTextColor::Dim => Color::DarkGray,
572572
DiffTextColor::Bright => Color::White,
573+
DiffTextColor::DataFlow => Color::LightCyan,
573574
DiffTextColor::Replace => Color::Cyan,
574575
DiffTextColor::Delete => Color::Red,
575576
DiffTextColor::Insert => Color::Green,

objdiff-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ time = { version = "0.3", optional = true }
175175
encoding_rs = { version = "0.8.35", optional = true }
176176

177177
[target.'cfg(windows)'.dependencies]
178-
winapi = { version = "0.3", optional = true }
178+
winapi = { version = "0.3", optional = true, features = ["winbase"] }
179179

180180
# For Linux static binaries, use rustls
181181
[target.'cfg(target_os = "linux")'.dependencies]

objdiff-core/config-schema.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
}
2626
]
2727
},
28+
{
29+
"id": "analyzeDataFlow",
30+
"type": "boolean",
31+
"default": false,
32+
"name": "(Experimental) Perform data flow analysis",
33+
"description": "Use data flow analysis to display known information about register contents where possible"
34+
},
35+
{
36+
"id": "showDataFlow",
37+
"type": "boolean",
38+
"default": true,
39+
"name": "Show data flow",
40+
"description": "Show data flow analysis results in place of register name where present"
41+
},
2842
{
2943
"id": "spaceBetweenArgs",
3044
"type": "boolean",
@@ -264,7 +278,8 @@
264278
"id": "ppc",
265279
"name": "PowerPC",
266280
"properties": [
267-
"ppc.calculatePoolRelocations"
281+
"ppc.calculatePoolRelocations",
282+
"analyzeDataFlow"
268283
]
269284
},
270285
{

objdiff-core/src/arch/mod.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use alloc::{borrow::Cow, boxed::Box, format, string::String, vec::Vec};
2-
use core::{ffi::CStr, fmt, fmt::Debug};
2+
use core::{
3+
ffi::CStr,
4+
fmt::{self, Debug},
5+
};
36

47
use anyhow::{Result, bail};
58
use encoding_rs::SHIFT_JIS;
@@ -11,8 +14,9 @@ use crate::{
1114
display::{ContextItem, HoverItem, InstructionPart},
1215
},
1316
obj::{
14-
InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation, RelocationFlags,
15-
ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet, SymbolKind,
17+
FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation,
18+
RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet,
19+
SymbolKind,
1620
},
1721
util::ReallySigned,
1822
};
@@ -31,6 +35,7 @@ pub mod superh;
3135
pub mod x86;
3236

3337
/// Represents the type of data associated with an instruction
38+
#[derive(PartialEq)]
3439
pub enum DataType {
3540
Int8,
3641
Int16,
@@ -335,6 +340,17 @@ pub trait Arch: Send + Sync + Debug {
335340
Vec::new()
336341
}
337342

343+
// Perform detailed data flow analysis
344+
fn data_flow_analysis(
345+
&self,
346+
_obj: &Object,
347+
_symbol: &Symbol,
348+
_code: &[u8],
349+
_relocations: &[Relocation],
350+
) -> Option<Box<dyn FlowAnalysisResult>> {
351+
None
352+
}
353+
338354
fn implcit_addend(
339355
&self,
340356
file: &object::File<'_>,

0 commit comments

Comments
 (0)