Rework .splitmeta, now .note.split

Uses actual ELF .note format, which is
more standard and handled better by mwld.
This commit is contained in:
Luke Street 2024-03-04 18:12:20 -07:00
parent 96b13be11d
commit b829e15438
4 changed files with 28 additions and 23 deletions

4
Cargo.lock generated
View File

@ -305,7 +305,7 @@ dependencies = [
[[package]] [[package]]
name = "decomp-toolkit" name = "decomp-toolkit"
version = "0.7.4" version = "0.7.5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"ar", "ar",
@ -700,7 +700,7 @@ dependencies = [
[[package]] [[package]]
name = "objdiff-core" name = "objdiff-core"
version = "1.0.0" version = "1.0.0"
source = "git+https://github.com/encounter/objdiff?rev=5b9ac93c084bd0a9ae710e8c8195c4b0db939b8a#5b9ac93c084bd0a9ae710e8c8195c4b0db939b8a" source = "git+https://github.com/encounter/objdiff?rev=20e42a499a7af4bda4f8010c76bdf312df9bcd4c#20e42a499a7af4bda4f8010c76bdf312df9bcd4c"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"byteorder", "byteorder",

View File

@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit." description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <luke@street.dev>"] authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
version = "0.7.4" version = "0.7.5"
edition = "2021" edition = "2021"
publish = false publish = false
repository = "https://github.com/encounter/decomp-toolkit" repository = "https://github.com/encounter/decomp-toolkit"
@ -47,7 +47,8 @@ memmap2 = "0.9.0"
multimap = "0.9.1" multimap = "0.9.1"
nintendo-lz = "0.1.3" nintendo-lz = "0.1.3"
num_enum = "0.7.1" num_enum = "0.7.1"
objdiff-core = { git = "https://github.com/encounter/objdiff", rev = "5b9ac93c084bd0a9ae710e8c8195c4b0db939b8a", features = ["ppc"] } objdiff-core = { git = "https://github.com/encounter/objdiff", rev = "20e42a499a7af4bda4f8010c76bdf312df9bcd4c", features = ["ppc"] }
#objdiff-core = { path = "../objdiff/objdiff-core", features = ["ppc"] }
object = { version = "0.32.1", features = ["read_core", "std", "elf", "write_std"], default-features = false } object = { version = "0.32.1", features = ["read_core", "std", "elf", "write_std"], default-features = false }
once_cell = "1.18.0" once_cell = "1.18.0"
owo-colors = { version = "3.5.0", features = ["supports-colors"] } owo-colors = { version = "3.5.0", features = ["supports-colors"] }

View File

@ -601,12 +601,18 @@ fn info(args: InfoArgs) -> Result<()> {
let data = split_meta_section.uncompressed_data()?; let data = split_meta_section.uncompressed_data()?;
if !data.is_empty() { if !data.is_empty() {
let meta = let meta =
SplitMeta::from_reader(&mut data.as_ref(), in_file.endianness(), in_file.is_64()) SplitMeta::from_section(split_meta_section, in_file.endianness(), in_file.is_64())
.context("While reading .splitmeta section")?; .context("While reading .note.split section")?;
println!("\nSplit metadata (.splitmeta):"); println!("\nSplit metadata (.note.split):");
if let Some(generator) = &meta.generator { if let Some(generator) = &meta.generator {
println!("\tGenerator: {}", generator); println!("\tGenerator: {}", generator);
} }
if let Some(module_name) = &meta.module_name {
println!("\tModule name: {}", module_name);
}
if let Some(module_id) = meta.module_id {
println!("\tModule ID: {}", module_id);
}
if let Some(virtual_addresses) = &meta.virtual_addresses { if let Some(virtual_addresses) = &meta.virtual_addresses {
println!("\tVirtual addresses:"); println!("\tVirtual addresses:");
println!("\t{: >10} | {: <10}", "Addr", "Symbol"); println!("\t{: >10} | {: <10}", "Addr", "Symbol");

View File

@ -133,15 +133,13 @@ where P: AsRef<Path> {
if data.is_empty() { if data.is_empty() {
None None
} else { } else {
let mut reader = Cursor::new(&*data); let metadata = SplitMeta::from_section(
let metadata = split_meta_section,
SplitMeta::from_reader(&mut reader, obj_file.endianness(), obj_file.is_64()) obj_file.endianness(),
.context("While reading .splitmeta section")?; obj_file.is_64(),
log::debug!("Loaded .splitmeta section"); )
ensure!( .context("While reading .note.split section")?;
data.len() - reader.position() as usize == 0, log::debug!("Loaded .note.split section");
".splitmeta section data not fully read"
);
Some(metadata) Some(metadata)
} }
} else { } else {
@ -456,7 +454,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
None None
}; };
// Generate .splitmeta section // Generate .note.split section
let mut split_meta = if let Some(metadata) = &obj.split_meta { let mut split_meta = if let Some(metadata) = &obj.split_meta {
// Reserve section // Reserve section
let name = writer.add_section_name(SPLITMETA_SECTION.as_bytes()); let name = writer.add_section_name(SPLITMETA_SECTION.as_bytes());
@ -472,7 +470,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
virtual_address: None, virtual_address: None,
}); });
// Generate .splitmeta data // Generate .note.split data
let mut out = metadata.clone(); let mut out = metadata.clone();
out.virtual_addresses = Some(vec![ out.virtual_addresses = Some(vec![
0, // Null symbol 0, // Null symbol
@ -667,7 +665,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
out_section.offset = writer.reserve(comment_data.len(), 32); out_section.offset = writer.reserve(comment_data.len(), 32);
} }
// Reserve .splitmeta section // Reserve .note.split section
if let Some((metadata, idx)) = &split_meta { if let Some((metadata, idx)) = &split_meta {
let out_section = &mut out_sections[*idx]; let out_section = &mut out_sections[*idx];
out_section.offset = writer.reserve(metadata.write_size(false), 32); out_section.offset = writer.reserve(metadata.write_size(false), 32);
@ -786,7 +784,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
writer.write(comment_data); writer.write(comment_data);
} }
// Write .splitmeta section // Write .note.split section
if let Some((metadata, idx)) = &split_meta { if let Some((metadata, idx)) = &split_meta {
let out_section = &out_sections[*idx]; let out_section = &out_sections[*idx];
writer.write_align(32); writer.write_align(32);
@ -856,7 +854,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
}); });
} }
// Write .splitmeta section header // Write .note.split section header
if let Some((metadata, idx)) = &split_meta { if let Some((metadata, idx)) = &split_meta {
let out_section = &out_sections[*idx]; let out_section = &out_sections[*idx];
writer.write_section_header(&SectionHeader { writer.write_section_header(&SectionHeader {
@ -868,8 +866,8 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
sh_size: metadata.write_size(false) as u64, sh_size: metadata.write_size(false) as u64,
sh_link: 0, sh_link: 0,
sh_info: 0, sh_info: 0,
sh_addralign: 1, sh_addralign: 4,
sh_entsize: 1, sh_entsize: 0,
}); });
} }