Skip to content

Commit d2b7a9e

Browse files
committed
Fix missing common BSS symbols
Resolves #128
1 parent 2cf9cf2 commit d2b7a9e

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ strip = "debuginfo"
1313
codegen-units = 1
1414

1515
[workspace.package]
16-
version = "2.3.3"
16+
version = "2.3.4"
1717
authors = ["Luke Street <luke@street.dev>"]
1818
edition = "2021"
1919
license = "MIT OR Apache-2.0"

objdiff-core/src/diff/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
diff_generic_section, no_diff_symbol,
1212
},
1313
},
14-
obj::{ObjInfo, ObjIns, ObjSection, ObjSectionKind, ObjSymbol, SymbolRef},
14+
obj::{ObjInfo, ObjIns, ObjSection, ObjSectionKind, ObjSymbol, SymbolRef, SECTION_COMMON},
1515
};
1616

1717
pub mod code;
@@ -340,7 +340,7 @@ impl ObjDiff {
340340
}
341341
for (symbol_idx, _) in obj.common.iter().enumerate() {
342342
result.common.push(ObjSymbolDiff {
343-
symbol_ref: SymbolRef { section_idx: obj.sections.len(), symbol_idx },
343+
symbol_ref: SymbolRef { section_idx: SECTION_COMMON, symbol_idx },
344344
target_symbol: None,
345345
instructions: vec![],
346346
match_percent: None,
@@ -361,7 +361,7 @@ impl ObjDiff {
361361

362362
#[inline]
363363
pub fn symbol_diff(&self, symbol_ref: SymbolRef) -> &ObjSymbolDiff {
364-
if symbol_ref.section_idx == self.sections.len() {
364+
if symbol_ref.section_idx == SECTION_COMMON {
365365
&self.common[symbol_ref.symbol_idx]
366366
} else {
367367
&self.section_diff(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx]
@@ -370,7 +370,7 @@ impl ObjDiff {
370370

371371
#[inline]
372372
pub fn symbol_diff_mut(&mut self, symbol_ref: SymbolRef) -> &mut ObjSymbolDiff {
373-
if symbol_ref.section_idx == self.sections.len() {
373+
if symbol_ref.section_idx == SECTION_COMMON {
374374
&mut self.common[symbol_ref.symbol_idx]
375375
} else {
376376
&mut self.section_diff_mut(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx]
@@ -758,7 +758,7 @@ fn matching_symbols(
758758
}
759759
}
760760
for (symbol_idx, symbol) in left.common.iter().enumerate() {
761-
let symbol_ref = SymbolRef { section_idx: left.sections.len(), symbol_idx };
761+
let symbol_ref = SymbolRef { section_idx: SECTION_COMMON, symbol_idx };
762762
if left_used.contains(&symbol_ref) {
763763
continue;
764764
}
@@ -790,7 +790,7 @@ fn matching_symbols(
790790
}
791791
}
792792
for (symbol_idx, symbol) in right.common.iter().enumerate() {
793-
let symbol_ref = SymbolRef { section_idx: right.sections.len(), symbol_idx };
793+
let symbol_ref = SymbolRef { section_idx: SECTION_COMMON, symbol_idx };
794794
if right_used.contains(&symbol_ref) {
795795
continue;
796796
}
@@ -883,7 +883,7 @@ fn find_common_symbol(obj: Option<&ObjInfo>, in_symbol: &ObjSymbol) -> Option<Sy
883883
let obj = obj?;
884884
for (symbol_idx, symbol) in obj.common.iter().enumerate() {
885885
if symbol.name == in_symbol.name {
886-
return Some(SymbolRef { section_idx: obj.sections.len(), symbol_idx });
886+
return Some(SymbolRef { section_idx: SECTION_COMMON, symbol_idx });
887887
}
888888
}
889889
None

objdiff-core/src/obj/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,11 @@ pub struct SymbolRef {
164164
pub symbol_idx: usize,
165165
}
166166

167+
pub const SECTION_COMMON: usize = usize::MAX - 1;
168+
167169
impl ObjInfo {
168170
pub fn section_symbol(&self, symbol_ref: SymbolRef) -> (Option<&ObjSection>, &ObjSymbol) {
169-
if symbol_ref.section_idx == self.sections.len() {
171+
if symbol_ref.section_idx == SECTION_COMMON {
170172
let symbol = &self.common[symbol_ref.symbol_idx];
171173
return (None, symbol);
172174
}

objdiff-gui/src/views/symbol_diff.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use egui::{
77
use objdiff_core::{
88
arch::ObjArch,
99
diff::{display::HighlightKind, ObjDiff, ObjSymbolDiff},
10-
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags, SymbolRef},
10+
obj::{
11+
ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags, SymbolRef, SECTION_COMMON,
12+
},
1113
};
1214
use regex::{Regex, RegexBuilder};
1315

@@ -651,11 +653,11 @@ pub fn symbol_list_ui(
651653
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
652654

653655
// Skip sections with all symbols filtered out
654-
if mapping.keys().any(|symbol_ref| symbol_ref.section_idx == usize::MAX) {
656+
if mapping.keys().any(|symbol_ref| symbol_ref.section_idx == SECTION_COMMON) {
655657
CollapsingHeader::new(".comm").default_open(true).show(ui, |ui| {
656658
for (symbol_ref, symbol_diff) in mapping
657659
.iter()
658-
.filter(|(symbol_ref, _)| symbol_ref.section_idx == usize::MAX)
660+
.filter(|(symbol_ref, _)| symbol_ref.section_idx == SECTION_COMMON)
659661
{
660662
let symbol = ctx.obj.section_symbol(*symbol_ref).1;
661663
if let Some(result) = symbol_ui(

0 commit comments

Comments
 (0)