Skip to content

Commit 1cb3a7a

Browse files
committed
Combine "relax reloc diffs" with other reloc diff options
1 parent 5726997 commit 1cb3a7a

File tree

5 files changed

+43
-44
lines changed

5 files changed

+43
-44
lines changed

objdiff-cli/src/cmd/report.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ fn report_object(
169169
}
170170
_ => {}
171171
}
172-
let diff_config = diff::DiffObjConfig { relax_reloc_diffs: true, ..Default::default() };
172+
let diff_config = diff::DiffObjConfig {
173+
function_reloc_diffs: diff::FunctionRelocDiffs::None,
174+
..Default::default()
175+
};
173176
let mapping_config = diff::MappingConfig::default();
174177
let target = object
175178
.target_path

objdiff-cli/src/views/function_diff.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton,
33
use objdiff_core::{
44
diff::{
55
display::{display_diff, DiffText, HighlightKind},
6-
FunctionDataDiffs, ObjDiff, ObjInsDiffKind, ObjSymbolDiff,
6+
FunctionRelocDiffs, ObjDiff, ObjInsDiffKind, ObjSymbolDiff,
77
},
88
obj::{ObjInfo, ObjSectionKind, ObjSymbol, SymbolRef},
99
};
@@ -368,20 +368,14 @@ impl UiView for FunctionDiffUi {
368368
self.scroll_x = self.scroll_x.saturating_sub(1);
369369
result.redraw = true;
370370
}
371-
// Toggle relax relocation diffs
371+
// Cycle through function relocation diff mode
372372
KeyCode::Char('x') => {
373-
state.diff_obj_config.relax_reloc_diffs =
374-
!state.diff_obj_config.relax_reloc_diffs;
375-
result.redraw = true;
376-
return EventControlFlow::Reload;
377-
}
378-
// Cycle through function data diff mode
379-
KeyCode::Char('s') => {
380-
state.diff_obj_config.function_data_diffs =
381-
match state.diff_obj_config.function_data_diffs {
382-
FunctionDataDiffs::AddressOnly => FunctionDataDiffs::ValueOnly,
383-
FunctionDataDiffs::ValueOnly => FunctionDataDiffs::All,
384-
FunctionDataDiffs::All => FunctionDataDiffs::AddressOnly,
373+
state.diff_obj_config.function_reloc_diffs =
374+
match state.diff_obj_config.function_reloc_diffs {
375+
FunctionRelocDiffs::None => FunctionRelocDiffs::NameAddress,
376+
FunctionRelocDiffs::NameAddress => FunctionRelocDiffs::DataValue,
377+
FunctionRelocDiffs::DataValue => FunctionRelocDiffs::All,
378+
FunctionRelocDiffs::All => FunctionRelocDiffs::None,
385379
};
386380
result.redraw = true;
387381
return EventControlFlow::Reload;

objdiff-core/config-schema.json

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
{
22
"properties": [
33
{
4-
"id": "relaxRelocDiffs",
5-
"type": "boolean",
6-
"default": false,
7-
"name": "Relax relocation diffs",
8-
"description": "Ignores differences in relocation targets. (Address, name, etc)"
9-
},
10-
{
11-
"id": "functionDataDiffs",
4+
"id": "functionRelocDiffs",
125
"type": "choice",
13-
"default": "address_only",
14-
"name": "Function data diffs",
15-
"description": "How data relocations will be diffed in the function view.",
6+
"default": "name_address",
7+
"name": "Function relocation diffs",
8+
"description": "How relocation targets will be diffed in the function view.",
169
"items": [
1710
{
18-
"value": "address_only",
19-
"name": "Address only"
11+
"value": "none",
12+
"name": "None"
13+
},
14+
{
15+
"value": "name_address",
16+
"name": "Name or address"
2017
},
2118
{
22-
"value": "value_only",
23-
"name": "Value only"
19+
"value": "data_value",
20+
"name": "Data value"
2421
},
2522
{
2623
"value": "all",
27-
"name": "Value and address"
24+
"name": "Name or address, data value"
2825
}
2926
]
3027
},
@@ -214,8 +211,7 @@
214211
"id": "general",
215212
"name": "General",
216213
"properties": [
217-
"relaxRelocDiffs",
218-
"functionDataDiffs",
214+
"functionRelocDiffs",
219215
"spaceBetweenArgs",
220216
"combineDataSections"
221217
]

objdiff-core/src/diff/code.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cmp::max, collections::BTreeMap};
33
use anyhow::{anyhow, Result};
44
use similar::{capture_diff_slices_deadline, Algorithm};
55

6-
use super::FunctionDataDiffs;
6+
use super::FunctionRelocDiffs;
77
use crate::{
88
arch::ProcessCodeResult,
99
diff::{
@@ -231,7 +231,7 @@ fn reloc_eq(
231231
if left.flags != right.flags {
232232
return false;
233233
}
234-
if config.relax_reloc_diffs {
234+
if config.function_reloc_diffs == FunctionRelocDiffs::None {
235235
return true;
236236
}
237237

@@ -240,10 +240,10 @@ fn reloc_eq(
240240
(Some(sl), Some(sr)) => {
241241
// Match if section and name or address match
242242
section_name_eq(left_obj, right_obj, *sl, *sr)
243-
&& (symbol_name_matches
244-
|| address_eq(left, right)
245-
|| config.function_data_diffs == FunctionDataDiffs::ValueOnly)
246-
&& (config.function_data_diffs == FunctionDataDiffs::AddressOnly
243+
&& (config.function_reloc_diffs == FunctionRelocDiffs::DataValue
244+
|| symbol_name_matches
245+
|| address_eq(left, right))
246+
&& (config.function_reloc_diffs == FunctionRelocDiffs::NameAddress
247247
|| left.target.kind != ObjSymbolKind::Object
248248
|| left_obj.arch.display_ins_data(left_ins)
249249
== left_obj.arch.display_ins_data(right_ins))
@@ -275,7 +275,7 @@ fn arg_eq(
275275
ObjInsArg::Arg(r) => l.loose_eq(r),
276276
// If relocations are relaxed, match if left is a constant and right is a reloc
277277
// Useful for instances where the target object is created without relocations
278-
ObjInsArg::Reloc => config.relax_reloc_diffs,
278+
ObjInsArg::Reloc => config.function_reloc_diffs == FunctionRelocDiffs::None,
279279
_ => false,
280280
},
281281
ObjInsArg::Reloc => {
@@ -296,7 +296,7 @@ fn arg_eq(
296296
}
297297
// If relocations are relaxed, match if left is a constant and right is a reloc
298298
// Useful for instances where the target object is created without relocations
299-
ObjInsArg::Reloc => config.relax_reloc_diffs,
299+
ObjInsArg::Reloc => config.function_reloc_diffs == FunctionRelocDiffs::None,
300300
_ => false,
301301
},
302302
}

objdiff-gui/src/app_config.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use eframe::Storage;
44
use globset::Glob;
55
use objdiff_core::{
66
config::ScratchConfig,
7-
diff::{ArmArchVersion, ArmR9Usage, DiffObjConfig, MipsAbi, MipsInstrCategory, X86Formatter},
7+
diff::{
8+
ArmArchVersion, ArmR9Usage, DiffObjConfig, FunctionRelocDiffs, MipsAbi, MipsInstrCategory,
9+
X86Formatter,
10+
},
811
};
912

1013
use crate::app::{AppConfig, ObjectConfig, CONFIG_KEY};
@@ -147,7 +150,11 @@ impl Default for DiffObjConfigV1 {
147150
impl DiffObjConfigV1 {
148151
fn into_config(self) -> DiffObjConfig {
149152
DiffObjConfig {
150-
relax_reloc_diffs: self.relax_reloc_diffs,
153+
function_reloc_diffs: if self.relax_reloc_diffs {
154+
FunctionRelocDiffs::None
155+
} else {
156+
FunctionRelocDiffs::default()
157+
},
151158
space_between_args: self.space_between_args,
152159
combine_data_sections: self.combine_data_sections,
153160
x86_formatter: self.x86_formatter,
@@ -160,7 +167,6 @@ impl DiffObjConfigV1 {
160167
arm_sl_usage: self.arm_sl_usage,
161168
arm_fp_usage: self.arm_fp_usage,
162169
arm_ip_usage: self.arm_ip_usage,
163-
..Default::default()
164170
}
165171
}
166172
}

0 commit comments

Comments
 (0)