Add auto extab dtor renaming (#123)

* Add auto extab dtor renaming

* Remove whitespace

* Update cwextab

* Only rename unnamed functions

* Create separate name creation function/use is_auto_symbol

* Make fmt shut up
This commit is contained in:
Amber Brault
2025-11-22 05:35:43 +01:00
committed by GitHub
parent a2568b5b80
commit f8f69e2cfd
4 changed files with 33 additions and 7 deletions

4
Cargo.lock generated
View File

@@ -333,9 +333,9 @@ checksum = "c2e06f9bce634a3c898eb1e5cb949ff63133cbb218af93cc9b38b31d6f3ea285"
[[package]]
name = "cwextab"
version = "1.1.6"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d21b94648643c61e1b5cef71e8d3a9f89350397ac2b0fe42890edbc94757b18"
checksum = "e23dadbc8945746c361e3967336075be7281a5455c06f5c5a17fddca4e7d2175"
dependencies = [
"thiserror 2.0.17",
]

View File

@@ -20,6 +20,7 @@ use crate::{
ObjInfo, ObjSectionKind, ObjSymbol, ObjSymbolFlagSet, ObjSymbolFlags, ObjSymbolKind,
SectionIndex,
},
util::config::create_auto_symbol_name,
};
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -143,11 +144,7 @@ impl AnalyzerState {
section.address,
section.address + section.size
);
let name = if obj.module_id == 0 {
format!("fn_{:08X}", start.address)
} else {
format!("fn_{}_{:X}", obj.module_id, start.address)
};
let name = create_auto_symbol_name("fn", obj.module_id, start.address);
obj.add_symbol(
ObjSymbol {
name,

View File

@@ -21,6 +21,7 @@ use crate::{
ObjDataKind, ObjInfo, ObjKind, ObjReloc, ObjRelocKind, ObjSection, ObjSectionKind,
ObjSymbol, ObjSymbolFlagSet, ObjSymbolFlags, ObjSymbolKind, SectionIndex, SymbolIndex,
},
util::config::{create_auto_symbol_name, is_auto_symbol},
};
#[derive(Debug, Copy, Clone)]
@@ -822,6 +823,23 @@ impl Tracker {
}
}
}
// Rename all discovered extab dtors from extab relocations
if let Some((_, extab_section)) = obj.sections.by_name("extab")? {
for (_, reloc) in extab_section.relocations.iter() {
let symbol = &obj.symbols[reloc.target_symbol];
// Only rename auto symbols
if is_auto_symbol(symbol) {
let mut new_symbol = symbol.clone();
let name =
create_auto_symbol_name("dtor", obj.module_id, symbol.address as u32);
new_symbol.name = name;
obj.symbols.replace(reloc.target_symbol, new_symbol)?;
}
}
}
Ok(())
}
}

View File

@@ -176,6 +176,16 @@ pub fn parse_symbol_line(line: &str, obj: &mut ObjInfo) -> Result<Option<ObjSymb
}
}
pub fn create_auto_symbol_name(prefix: &str, module_id: u32, address: u32) -> String {
let name = if module_id == 0 {
format!("{}_{:08X}", prefix, address)
} else {
format!("{}_{}_{:X}", prefix, module_id, address)
};
name
}
pub fn is_skip_symbol(symbol: &ObjSymbol) -> bool {
if symbol.flags.is_no_write() {
return true;
@@ -194,6 +204,7 @@ pub fn is_auto_symbol(symbol: &ObjSymbol) -> bool {
|| symbol.name.starts_with("jumptable_")
|| symbol.name.starts_with("gap_")
|| symbol.name.starts_with("pad_")
|| symbol.name.starts_with("dtor_")
}
pub fn is_auto_label(symbol: &ObjSymbol) -> bool { symbol.name.starts_with("lbl_") }