Fix MIPS relocation addends; update cwdemangle, ppc750cl

This commit is contained in:
Luke Street 2022-11-05 13:16:44 -04:00
parent d04838fe4e
commit ff9b378445
6 changed files with 14 additions and 29 deletions

6
Cargo.lock generated
View File

@ -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",

View File

@ -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"] }

View File

@ -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<Vec<ObjSection>> {
let mut result = Vec::<ObjSection>::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!(),
}

View File

@ -133,7 +133,6 @@ pub enum ObjRelocKind {
// PpcAddr14,
PpcRel14,
PpcEmbSda21,
Mips32,
Mips26,
MipsHi16,
MipsLo16,

View File

@ -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 =

View File

@ -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};