mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-12-12 22:56:28 +00:00
Ignore ABS symbols in ObjSymbols::for_range
- Add ObjSymbols::iter_ordered for all symbols (including ABS) - Extract duplicated logic into ObjSymbols::for_relocation
This commit is contained in:
@@ -109,7 +109,7 @@ fn info(args: InfoArgs) -> Result<()> {
|
||||
}
|
||||
println!("\nDiscovered symbols:");
|
||||
println!("\t{: >23} | {: <10} | {: <10}", "Name", "Address", "Size");
|
||||
for (_, symbol) in obj.symbols.for_range(..) {
|
||||
for (_, symbol) in obj.symbols.iter_ordered() {
|
||||
if symbol.name.starts_with('@') || symbol.name.starts_with("fn_") {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -161,67 +161,9 @@ fn merge(args: MergeArgs) -> Result<()> {
|
||||
let source_section_index = obj.section_at(source_addr)?.index;
|
||||
let target_section_index = obj.section_at(target_addr)?.index;
|
||||
|
||||
// Try to find a previous sized symbol that encompasses the target
|
||||
let target_symbol = {
|
||||
let mut result = None;
|
||||
for (_addr, symbol_idxs) in obj.symbols.indexes_for_range(..=target_addr).rev() {
|
||||
let symbol_idx = if symbol_idxs.len() == 1 {
|
||||
symbol_idxs.first().cloned().unwrap()
|
||||
} else {
|
||||
let mut symbol_idxs = symbol_idxs.to_vec();
|
||||
symbol_idxs.sort_by_key(|&symbol_idx| {
|
||||
let symbol = obj.symbols.at(symbol_idx);
|
||||
let mut rank = match symbol.kind {
|
||||
ObjSymbolKind::Function | ObjSymbolKind::Object => {
|
||||
match rel_reloc.kind {
|
||||
ObjRelocKind::PpcAddr16Hi
|
||||
| ObjRelocKind::PpcAddr16Ha
|
||||
| ObjRelocKind::PpcAddr16Lo => 1,
|
||||
ObjRelocKind::Absolute
|
||||
| ObjRelocKind::PpcRel24
|
||||
| ObjRelocKind::PpcRel14
|
||||
| ObjRelocKind::PpcEmbSda21 => 2,
|
||||
}
|
||||
}
|
||||
// Label
|
||||
ObjSymbolKind::Unknown => match rel_reloc.kind {
|
||||
ObjRelocKind::PpcAddr16Hi
|
||||
| ObjRelocKind::PpcAddr16Ha
|
||||
| ObjRelocKind::PpcAddr16Lo
|
||||
if !symbol.name.starts_with("..") =>
|
||||
{
|
||||
3
|
||||
}
|
||||
_ => 1,
|
||||
},
|
||||
ObjSymbolKind::Section => -1,
|
||||
};
|
||||
if symbol.size > 0 {
|
||||
rank += 1;
|
||||
}
|
||||
-rank
|
||||
});
|
||||
match symbol_idxs.first().cloned() {
|
||||
Some(v) => v,
|
||||
None => continue,
|
||||
}
|
||||
};
|
||||
let symbol = obj.symbols.at(symbol_idx);
|
||||
if symbol.address == target_addr as u64 {
|
||||
result = Some(symbol_idx);
|
||||
break;
|
||||
}
|
||||
if symbol.size > 0 {
|
||||
if symbol.address + symbol.size > target_addr as u64 {
|
||||
result = Some(symbol_idx);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
result
|
||||
};
|
||||
let (symbol_idx, addend) = if let Some(symbol_idx) = target_symbol {
|
||||
let symbol = obj.symbols.at(symbol_idx);
|
||||
let (symbol_idx, addend) = if let Some((symbol_idx, symbol)) =
|
||||
obj.symbols.for_relocation(target_addr, rel_reloc.kind)?
|
||||
{
|
||||
(symbol_idx, target_addr as i64 - symbol.address as i64)
|
||||
} else {
|
||||
// Create a new label
|
||||
|
||||
Reference in New Issue
Block a user