Fix missing common BSS symbols

Resolves #128
This commit is contained in:
Luke Street 2024-10-28 17:54:49 -06:00
parent 2cf9cf24d6
commit d2b7a9ef25
5 changed files with 19 additions and 15 deletions

6
Cargo.lock generated
View File

@ -2861,7 +2861,7 @@ dependencies = [
[[package]] [[package]]
name = "objdiff-cli" name = "objdiff-cli"
version = "2.3.3" version = "2.3.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argp", "argp",
@ -2883,7 +2883,7 @@ dependencies = [
[[package]] [[package]]
name = "objdiff-core" name = "objdiff-core"
version = "2.3.3" version = "2.3.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"arm-attr", "arm-attr",
@ -2923,7 +2923,7 @@ dependencies = [
[[package]] [[package]]
name = "objdiff-gui" name = "objdiff-gui"
version = "2.3.3" version = "2.3.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",

View File

@ -13,7 +13,7 @@ strip = "debuginfo"
codegen-units = 1 codegen-units = 1
[workspace.package] [workspace.package]
version = "2.3.3" version = "2.3.4"
authors = ["Luke Street <luke@street.dev>"] authors = ["Luke Street <luke@street.dev>"]
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View File

@ -11,7 +11,7 @@ use crate::{
diff_generic_section, no_diff_symbol, diff_generic_section, no_diff_symbol,
}, },
}, },
obj::{ObjInfo, ObjIns, ObjSection, ObjSectionKind, ObjSymbol, SymbolRef}, obj::{ObjInfo, ObjIns, ObjSection, ObjSectionKind, ObjSymbol, SymbolRef, SECTION_COMMON},
}; };
pub mod code; pub mod code;
@ -340,7 +340,7 @@ impl ObjDiff {
} }
for (symbol_idx, _) in obj.common.iter().enumerate() { for (symbol_idx, _) in obj.common.iter().enumerate() {
result.common.push(ObjSymbolDiff { result.common.push(ObjSymbolDiff {
symbol_ref: SymbolRef { section_idx: obj.sections.len(), symbol_idx }, symbol_ref: SymbolRef { section_idx: SECTION_COMMON, symbol_idx },
target_symbol: None, target_symbol: None,
instructions: vec![], instructions: vec![],
match_percent: None, match_percent: None,
@ -361,7 +361,7 @@ impl ObjDiff {
#[inline] #[inline]
pub fn symbol_diff(&self, symbol_ref: SymbolRef) -> &ObjSymbolDiff { pub fn symbol_diff(&self, symbol_ref: SymbolRef) -> &ObjSymbolDiff {
if symbol_ref.section_idx == self.sections.len() { if symbol_ref.section_idx == SECTION_COMMON {
&self.common[symbol_ref.symbol_idx] &self.common[symbol_ref.symbol_idx]
} else { } else {
&self.section_diff(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx] &self.section_diff(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx]
@ -370,7 +370,7 @@ impl ObjDiff {
#[inline] #[inline]
pub fn symbol_diff_mut(&mut self, symbol_ref: SymbolRef) -> &mut ObjSymbolDiff { pub fn symbol_diff_mut(&mut self, symbol_ref: SymbolRef) -> &mut ObjSymbolDiff {
if symbol_ref.section_idx == self.sections.len() { if symbol_ref.section_idx == SECTION_COMMON {
&mut self.common[symbol_ref.symbol_idx] &mut self.common[symbol_ref.symbol_idx]
} else { } else {
&mut self.section_diff_mut(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx] &mut self.section_diff_mut(symbol_ref.section_idx).symbols[symbol_ref.symbol_idx]
@ -758,7 +758,7 @@ fn matching_symbols(
} }
} }
for (symbol_idx, symbol) in left.common.iter().enumerate() { for (symbol_idx, symbol) in left.common.iter().enumerate() {
let symbol_ref = SymbolRef { section_idx: left.sections.len(), symbol_idx }; let symbol_ref = SymbolRef { section_idx: SECTION_COMMON, symbol_idx };
if left_used.contains(&symbol_ref) { if left_used.contains(&symbol_ref) {
continue; continue;
} }
@ -790,7 +790,7 @@ fn matching_symbols(
} }
} }
for (symbol_idx, symbol) in right.common.iter().enumerate() { for (symbol_idx, symbol) in right.common.iter().enumerate() {
let symbol_ref = SymbolRef { section_idx: right.sections.len(), symbol_idx }; let symbol_ref = SymbolRef { section_idx: SECTION_COMMON, symbol_idx };
if right_used.contains(&symbol_ref) { if right_used.contains(&symbol_ref) {
continue; continue;
} }
@ -883,7 +883,7 @@ fn find_common_symbol(obj: Option<&ObjInfo>, in_symbol: &ObjSymbol) -> Option<Sy
let obj = obj?; let obj = obj?;
for (symbol_idx, symbol) in obj.common.iter().enumerate() { for (symbol_idx, symbol) in obj.common.iter().enumerate() {
if symbol.name == in_symbol.name { if symbol.name == in_symbol.name {
return Some(SymbolRef { section_idx: obj.sections.len(), symbol_idx }); return Some(SymbolRef { section_idx: SECTION_COMMON, symbol_idx });
} }
} }
None None

View File

@ -164,9 +164,11 @@ pub struct SymbolRef {
pub symbol_idx: usize, pub symbol_idx: usize,
} }
pub const SECTION_COMMON: usize = usize::MAX - 1;
impl ObjInfo { impl ObjInfo {
pub fn section_symbol(&self, symbol_ref: SymbolRef) -> (Option<&ObjSection>, &ObjSymbol) { pub fn section_symbol(&self, symbol_ref: SymbolRef) -> (Option<&ObjSection>, &ObjSymbol) {
if symbol_ref.section_idx == self.sections.len() { if symbol_ref.section_idx == SECTION_COMMON {
let symbol = &self.common[symbol_ref.symbol_idx]; let symbol = &self.common[symbol_ref.symbol_idx];
return (None, symbol); return (None, symbol);
} }

View File

@ -7,7 +7,9 @@ use egui::{
use objdiff_core::{ use objdiff_core::{
arch::ObjArch, arch::ObjArch,
diff::{display::HighlightKind, ObjDiff, ObjSymbolDiff}, diff::{display::HighlightKind, ObjDiff, ObjSymbolDiff},
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags, SymbolRef}, obj::{
ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags, SymbolRef, SECTION_COMMON,
},
}; };
use regex::{Regex, RegexBuilder}; use regex::{Regex, RegexBuilder};
@ -651,11 +653,11 @@ pub fn symbol_list_ui(
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend); ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
// Skip sections with all symbols filtered out // Skip sections with all symbols filtered out
if mapping.keys().any(|symbol_ref| symbol_ref.section_idx == usize::MAX) { if mapping.keys().any(|symbol_ref| symbol_ref.section_idx == SECTION_COMMON) {
CollapsingHeader::new(".comm").default_open(true).show(ui, |ui| { CollapsingHeader::new(".comm").default_open(true).show(ui, |ui| {
for (symbol_ref, symbol_diff) in mapping for (symbol_ref, symbol_diff) in mapping
.iter() .iter()
.filter(|(symbol_ref, _)| symbol_ref.section_idx == usize::MAX) .filter(|(symbol_ref, _)| symbol_ref.section_idx == SECTION_COMMON)
{ {
let symbol = ctx.obj.section_symbol(*symbol_ref).1; let symbol = ctx.obj.section_symbol(*symbol_ref).1;
if let Some(result) = symbol_ui( if let Some(result) = symbol_ui(