mirror of
https://github.com/encounter/decomp-toolkit.git
synced 2025-12-13 07:06:16 +00:00
Update all dependencies & support new demangle flag
- Support `--mw-extensions` flag for demangle - Fix relocation handling for object crate upgrade
This commit is contained in:
@@ -12,10 +12,16 @@ pub struct Args {
|
||||
#[argp(switch)]
|
||||
/// disable replacing `(void)` with `()`
|
||||
keep_void: bool,
|
||||
/// enable Metrowerks extensions
|
||||
#[argp(switch)]
|
||||
mw_extensions: bool,
|
||||
}
|
||||
|
||||
pub fn run(args: Args) -> Result<()> {
|
||||
let options = DemangleOptions { omit_empty_parameters: !args.keep_void };
|
||||
let options = DemangleOptions {
|
||||
omit_empty_parameters: !args.keep_void,
|
||||
mw_extensions: args.mw_extensions,
|
||||
};
|
||||
match demangle(args.symbol.as_str(), &options) {
|
||||
Some(symbol) => {
|
||||
println!("{symbol}");
|
||||
|
||||
@@ -7,7 +7,10 @@ use std::{
|
||||
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use argp::FromArgs;
|
||||
use object::{elf, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget, Section};
|
||||
use object::{
|
||||
elf, Object, ObjectSection, ObjectSymbol, RelocationFlags, RelocationTarget,
|
||||
Section,
|
||||
};
|
||||
use syntect::{
|
||||
highlighting::{Color, HighlightIterator, HighlightState, Highlighter, Theme, ThemeSet},
|
||||
parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet},
|
||||
@@ -137,8 +140,8 @@ where
|
||||
|
||||
// Apply relocations to data
|
||||
for (addr, reloc) in debug_section.relocations() {
|
||||
match reloc.kind() {
|
||||
RelocationKind::Absolute | RelocationKind::Elf(elf::R_PPC_UADDR32) => {
|
||||
match reloc.flags() {
|
||||
RelocationFlags::Elf { r_type: elf::R_PPC_ADDR32 | elf::R_PPC_UADDR32 } => {
|
||||
let target = match reloc.target() {
|
||||
RelocationTarget::Symbol(symbol_idx) => {
|
||||
let symbol = obj_file.symbol_by_index(symbol_idx)?;
|
||||
@@ -148,7 +151,7 @@ where
|
||||
};
|
||||
data[addr as usize..addr as usize + 4].copy_from_slice(&target.to_be_bytes());
|
||||
}
|
||||
RelocationKind::Elf(elf::R_PPC_NONE) => {}
|
||||
RelocationFlags::Elf { r_type: elf::R_PPC_NONE } => {}
|
||||
_ => bail!("Unhandled .debug relocation type {:?}", reloc.kind()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ use objdiff_core::obj::split_meta::{SplitMeta, SPLITMETA_SECTION};
|
||||
use object::{
|
||||
elf,
|
||||
write::{Mangling, SectionId, SymbolId},
|
||||
FileFlags, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget, SectionFlags,
|
||||
SectionIndex, SectionKind, SymbolFlags, SymbolIndex, SymbolKind, SymbolScope, SymbolSection,
|
||||
FileFlags, Object, ObjectSection, ObjectSymbol,
|
||||
RelocationTarget, SectionFlags, SectionIndex, SectionKind, SymbolFlags, SymbolIndex,
|
||||
SymbolKind, SymbolScope, SymbolSection,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -374,24 +375,11 @@ fn fixup(args: FixupArgs) -> Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let kind = match reloc.kind() {
|
||||
// This is a hack to avoid replacement with a section symbol
|
||||
// See [`object::write::elf::object::elf_fixup_relocation`]
|
||||
RelocationKind::Absolute => RelocationKind::Elf(if addr & 3 == 0 {
|
||||
elf::R_PPC_ADDR32
|
||||
} else {
|
||||
elf::R_PPC_UADDR32
|
||||
}),
|
||||
other => other,
|
||||
};
|
||||
|
||||
out_file.add_relocation(section_id, object::write::Relocation {
|
||||
offset: addr,
|
||||
size: reloc.size(),
|
||||
kind,
|
||||
encoding: reloc.encoding(),
|
||||
symbol: target_symbol_id,
|
||||
addend,
|
||||
flags: reloc.flags(),
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ fn resolve_relocations(
|
||||
target_section_index.0
|
||||
} as u8;
|
||||
relocations.push(RelReloc {
|
||||
kind: to_obj_reloc_kind(reloc.kind())?,
|
||||
kind: to_obj_reloc_kind(reloc.flags())?,
|
||||
section: section_index,
|
||||
address: address as u32,
|
||||
module_id: target_module_id as u32,
|
||||
|
||||
@@ -18,7 +18,8 @@ use object::{
|
||||
StringId,
|
||||
},
|
||||
Architecture, Endianness, Object, ObjectKind, ObjectSection, ObjectSymbol, Relocation,
|
||||
RelocationKind, RelocationTarget, SectionKind, Symbol, SymbolKind, SymbolScope, SymbolSection,
|
||||
RelocationFlags, RelocationTarget, SectionKind, Symbol, SymbolKind,
|
||||
SymbolScope, SymbolSection,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -930,19 +931,19 @@ fn to_obj_symbol(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_obj_reloc_kind(kind: RelocationKind) -> Result<ObjRelocKind> {
|
||||
Ok(match kind {
|
||||
RelocationKind::Absolute => ObjRelocKind::Absolute,
|
||||
RelocationKind::Elf(kind) => match kind {
|
||||
pub fn to_obj_reloc_kind(flags: RelocationFlags) -> Result<ObjRelocKind> {
|
||||
Ok(match flags {
|
||||
RelocationFlags::Elf { r_type } => match r_type {
|
||||
elf::R_PPC_ADDR32 | elf::R_PPC_UADDR32 => ObjRelocKind::Absolute,
|
||||
elf::R_PPC_ADDR16_LO => ObjRelocKind::PpcAddr16Lo,
|
||||
elf::R_PPC_ADDR16_HI => ObjRelocKind::PpcAddr16Hi,
|
||||
elf::R_PPC_ADDR16_HA => ObjRelocKind::PpcAddr16Ha,
|
||||
elf::R_PPC_REL24 => ObjRelocKind::PpcRel24,
|
||||
elf::R_PPC_REL14 => ObjRelocKind::PpcRel14,
|
||||
elf::R_PPC_EMB_SDA21 => ObjRelocKind::PpcEmbSda21,
|
||||
_ => bail!("Unhandled ELF relocation type: {kind}"),
|
||||
kind => bail!("Unhandled ELF relocation type: {kind}"),
|
||||
},
|
||||
_ => bail!("Unhandled relocation type: {:?}", kind),
|
||||
flags => bail!("Unhandled relocation type: {:?}", flags),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -953,7 +954,7 @@ fn to_obj_reloc(
|
||||
address: u64,
|
||||
reloc: Relocation,
|
||||
) -> Result<Option<ObjReloc>> {
|
||||
let reloc_kind = to_obj_reloc_kind(reloc.kind())?;
|
||||
let reloc_kind = to_obj_reloc_kind(reloc.flags())?;
|
||||
let symbol = match reloc.target() {
|
||||
RelocationTarget::Symbol(idx) => {
|
||||
obj_file.symbol_by_index(idx).context("Failed to locate relocation target symbol")?
|
||||
|
||||
Reference in New Issue
Block a user