Skip to content

Commit

Permalink
Rework .splitmeta, now .note.split
Browse files Browse the repository at this point in the history
Uses actual ELF .note format, which is
more standard and handled better by mwld.
  • Loading branch information
encounter committed Mar 5, 2024
1 parent 96b13be commit b829e15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <[email protected]>"]
license = "MIT OR Apache-2.0"
version = "0.7.4"
version = "0.7.5"
edition = "2021"
publish = false
repository = "https://github.com/encounter/decomp-toolkit"
Expand Down Expand Up @@ -47,7 +47,8 @@ memmap2 = "0.9.0"
multimap = "0.9.1"
nintendo-lz = "0.1.3"
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 }
once_cell = "1.18.0"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
Expand Down
12 changes: 9 additions & 3 deletions src/cmd/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,18 @@ fn info(args: InfoArgs) -> Result<()> {
let data = split_meta_section.uncompressed_data()?;
if !data.is_empty() {
let meta =
SplitMeta::from_reader(&mut data.as_ref(), in_file.endianness(), in_file.is_64())
.context("While reading .splitmeta section")?;
println!("\nSplit metadata (.splitmeta):");
SplitMeta::from_section(split_meta_section, in_file.endianness(), in_file.is_64())
.context("While reading .note.split section")?;
println!("\nSplit metadata (.note.split):");
if let Some(generator) = &meta.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 {
println!("\tVirtual addresses:");
println!("\t{: >10} | {: <10}", "Addr", "Symbol");
Expand Down
30 changes: 14 additions & 16 deletions src/util/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,13 @@ where P: AsRef<Path> {
if data.is_empty() {
None
} else {
let mut reader = Cursor::new(&*data);
let metadata =
SplitMeta::from_reader(&mut reader, obj_file.endianness(), obj_file.is_64())
.context("While reading .splitmeta section")?;
log::debug!("Loaded .splitmeta section");
ensure!(
data.len() - reader.position() as usize == 0,
".splitmeta section data not fully read"
);
let metadata = SplitMeta::from_section(
split_meta_section,
obj_file.endianness(),
obj_file.is_64(),
)
.context("While reading .note.split section")?;
log::debug!("Loaded .note.split section");
Some(metadata)
}
} else {
Expand Down Expand Up @@ -456,7 +454,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
None
};

// Generate .splitmeta section
// Generate .note.split section
let mut split_meta = if let Some(metadata) = &obj.split_meta {
// Reserve section
let name = writer.add_section_name(SPLITMETA_SECTION.as_bytes());
Expand All @@ -472,7 +470,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
virtual_address: None,
});

// Generate .splitmeta data
// Generate .note.split data
let mut out = metadata.clone();
out.virtual_addresses = Some(vec![
0, // Null symbol
Expand Down Expand Up @@ -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);
}

// Reserve .splitmeta section
// Reserve .note.split section
if let Some((metadata, idx)) = &split_meta {
let out_section = &mut out_sections[*idx];
out_section.offset = writer.reserve(metadata.write_size(false), 32);
Expand Down Expand Up @@ -786,7 +784,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
writer.write(comment_data);
}

// Write .splitmeta section
// Write .note.split section
if let Some((metadata, idx)) = &split_meta {
let out_section = &out_sections[*idx];
writer.write_align(32);
Expand Down Expand Up @@ -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 {
let out_section = &out_sections[*idx];
writer.write_section_header(&SectionHeader {
Expand All @@ -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_link: 0,
sh_info: 0,
sh_addralign: 1,
sh_entsize: 1,
sh_addralign: 4,
sh_entsize: 0,
});
}

Expand Down

0 comments on commit b829e15

Please sign in to comment.