From ff9b3784456142b8bd0c726b59e9eb01b070caed Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sat, 5 Nov 2022 13:16:44 -0400 Subject: [PATCH] Fix MIPS relocation addends; update cwdemangle, ppc750cl --- Cargo.lock | 6 +++--- Cargo.toml | 4 ++-- src/obj/elf.rs | 26 +++++++------------------- src/obj/mod.rs | 1 - src/views/function_diff.rs | 3 +-- src/views/symbol_diff.rs | 3 +-- 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0ff3269..1263353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -520,8 +520,8 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "cwdemangle" -version = "0.1.2" -source = "git+https://github.com/encounter/cwdemangle?rev=ba448f403320f32b808e0dcf3040c6424664acab#ba448f403320f32b808e0dcf3040c6424664acab" +version = "0.1.3" +source = "git+https://github.com/encounter/cwdemangle?rev=64e8b3e083343783c5b3b6329ea940f375b057b3#64e8b3e083343783c5b3b6329ea940f375b057b3" dependencies = [ "argh", ] @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "ppc750cl" version = "0.2.0" -source = "git+https://github.com/encounter/ppc750cl?rev=4d8e4733319312abf47cde193d7386e55744bdf8#4d8e4733319312abf47cde193d7386e55744bdf8" +source = "git+https://github.com/encounter/ppc750cl?rev=aa631a33de7882c679afca89350898b87cb3ba3f#aa631a33de7882c679afca89350898b87cb3ba3f" dependencies = [ "num-traits", "serde", diff --git a/Cargo.toml b/Cargo.toml index f00f412..c2fc6e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,11 +20,11 @@ thiserror = "1.0.33" flagset = "0.4.3" object = "0.29.0" notify = "5.0.0" -cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "ba448f403320f32b808e0dcf3040c6424664acab" } +cwdemangle = { git = "https://github.com/encounter/cwdemangle", rev = "64e8b3e083343783c5b3b6329ea940f375b057b3" } log = "0.4.17" rfd = { version = "0.10.0" } # , default-features = false, features = ['xdg-portal'] egui_extras = "0.19.0" -ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "4d8e4733319312abf47cde193d7386e55744bdf8" } +ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" } rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" } time = { version = "0.3.14", features = ["formatting", "local-offset"] } diff --git a/src/obj/elf.rs b/src/obj/elf.rs index c4f2592..8bd0b87 100644 --- a/src/obj/elf.rs +++ b/src/obj/elf.rs @@ -4,6 +4,10 @@ use anyhow::{Context, Result}; use cwdemangle::demangle; use flagset::Flags; use object::{ + elf::{ + R_MIPS_26, R_MIPS_HI16, R_MIPS_LO16, R_PPC_ADDR16_HA, R_PPC_ADDR16_HI, R_PPC_ADDR16_LO, + R_PPC_EMB_SDA21, R_PPC_REL14, R_PPC_REL24, + }, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget, SectionKind, Symbol, SymbolKind, SymbolSection, }; @@ -50,7 +54,7 @@ fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> R }; Ok(ObjSymbol { name: name.to_string(), - demangled_name: demangle(name), + demangled_name: demangle(name, &Default::default()), address: symbol.address(), section_address, size: symbol.size(), @@ -63,18 +67,6 @@ fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> R }) } -const R_PPC_ADDR16_LO: u32 = 4; -const R_PPC_ADDR16_HI: u32 = 5; -const R_PPC_ADDR16_HA: u32 = 6; -const R_PPC_REL24: u32 = 10; -const R_PPC_REL14: u32 = 11; -const R_PPC_EMB_SDA21: u32 = 109; - -const R_MIPS_32: u32 = 2; -const R_MIPS_26: u32 = 4; -const R_MIPS_HI16: u32 = 5; -const R_MIPS_LO16: u32 = 6; - fn filter_sections(obj_file: &File<'_>) -> Result> { let mut result = Vec::::new(); for section in obj_file.sections() { @@ -232,7 +224,6 @@ fn relocations_by_section( } }, ObjArchitecture::Mips => match kind { - R_MIPS_32 => ObjRelocKind::Mips32, R_MIPS_26 => ObjRelocKind::Mips26, R_MIPS_HI16 => ObjRelocKind::MipsHi16, R_MIPS_LO16 => ObjRelocKind::MipsLo16, @@ -269,11 +260,8 @@ fn relocations_by_section( section.data[address as usize..address as usize + 4].try_into()?, ); match kind { - ObjRelocKind::Absolute => addend * 4, - ObjRelocKind::MipsHi16 | ObjRelocKind::MipsLo16 => { - (addend & 0x0000FFFF) * 4 - } - ObjRelocKind::Mips32 => addend * 4, + ObjRelocKind::Absolute => addend, + ObjRelocKind::MipsHi16 | ObjRelocKind::MipsLo16 => addend & 0x0000FFFF, ObjRelocKind::Mips26 => (addend & 0x03FFFFFF) * 4, _ => todo!(), } diff --git a/src/obj/mod.rs b/src/obj/mod.rs index 9b32de8..89521a2 100644 --- a/src/obj/mod.rs +++ b/src/obj/mod.rs @@ -133,7 +133,6 @@ pub enum ObjRelocKind { // PpcAddr14, PpcRel14, PpcEmbSda21, - Mips32, Mips26, MipsHi16, MipsLo16, diff --git a/src/views/function_diff.rs b/src/views/function_diff.rs index 983ac2d..f93548c 100644 --- a/src/views/function_diff.rs +++ b/src/views/function_diff.rs @@ -55,7 +55,6 @@ fn write_reloc(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob) { ObjRelocKind::Absolute | ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 - | ObjRelocKind::Mips32 | ObjRelocKind::Mips26 => { write_reloc_name(reloc, color, job); } @@ -361,7 +360,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool { }); strip.strip(|builder| { builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { - let demangled = demangle(selected_symbol); + let demangled = demangle(selected_symbol, &Default::default()); strip.cell(|ui| { ui.scope(|ui| { ui.style_mut().override_text_style = diff --git a/src/views/symbol_diff.rs b/src/views/symbol_diff.rs index dee4c85..a4ed1d8 100644 --- a/src/views/symbol_diff.rs +++ b/src/views/symbol_diff.rs @@ -1,6 +1,5 @@ use egui::{ - text::LayoutJob, CollapsingHeader, Color32, Rgba, ScrollArea, - SelectableLabel, Ui, Widget, + text::LayoutJob, CollapsingHeader, Color32, Rgba, ScrollArea, SelectableLabel, Ui, Widget, }; use egui_extras::{Size, StripBuilder};