gerge branch 'main' into experimental

This commit is contained in:
Luke Street 2023-01-19 12:54:52 -05:00
commit 827e0806be
5 changed files with 13 additions and 15 deletions

View File

@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "GameCube/Wii decompilation project tools." description = "GameCube/Wii decompilation project tools."
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.2.2" version = "0.2.3"
edition = "2021" edition = "2021"
publish = false publish = false
build = "build.rs" build = "build.rs"

View File

@ -45,9 +45,8 @@ fn create(args: CreateArgs) -> Result<()> {
// Process response files (starting with '@') // Process response files (starting with '@')
let mut files = Vec::with_capacity(args.files.len()); let mut files = Vec::with_capacity(args.files.len());
for path in args.files { for path in args.files {
let path_str = path let path_str =
.to_str() path.to_str().ok_or_else(|| anyhow!("'{}' is not valid UTF-8", path.display()))?;
.ok_or_else(|| anyhow!("'{}' is not valid UTF-8", path.display()))?;
match path_str.strip_prefix('@') { match path_str.strip_prefix('@') {
Some(rsp_file) => { Some(rsp_file) => {
let reader = BufReader::new( let reader = BufReader::new(
@ -71,18 +70,14 @@ fn create(args: CreateArgs) -> Result<()> {
let mut identifiers = Vec::with_capacity(files.len()); let mut identifiers = Vec::with_capacity(files.len());
let mut symbol_table = BTreeMap::new(); let mut symbol_table = BTreeMap::new();
for path in &files { for path in &files {
let file_name = path let path_str =
.file_name() path.to_str().ok_or_else(|| anyhow!("'{}' is not valid UTF-8", path.display()))?;
.ok_or_else(|| anyhow!("'{}' is not a file path", path.display()))?; let identifier = path_str.as_bytes().to_vec();
let file_name = file_name
.to_str()
.ok_or_else(|| anyhow!("'{}' is not valid UTF-8", file_name.to_string_lossy()))?;
let identifier = file_name.as_bytes().to_vec();
identifiers.push(identifier.clone()); identifiers.push(identifier.clone());
let entries = match symbol_table.entry(identifier) { let entries = match symbol_table.entry(identifier) {
Entry::Vacant(e) => e.insert(Vec::new()), Entry::Vacant(e) => e.insert(Vec::new()),
Entry::Occupied(_) => bail!("Duplicate file name '{file_name}'"), Entry::Occupied(_) => bail!("Duplicate file name '{path_str}'"),
}; };
let object_file = File::open(path) let object_file = File::open(path)
.with_context(|| format!("Failed to open object file '{}'", path.display()))?; .with_context(|| format!("Failed to open object file '{}'", path.display()))?;
@ -101,7 +96,10 @@ fn create(args: CreateArgs) -> Result<()> {
let mut builder = let mut builder =
ar::GnuBuilder::new(out, identifiers, ar::GnuSymbolTableFormat::Size32, symbol_table)?; ar::GnuBuilder::new(out, identifiers, ar::GnuSymbolTableFormat::Size32, symbol_table)?;
for path in files { for path in files {
builder.append_path(path)?; let path_str =
path.to_str().ok_or_else(|| anyhow!("'{}' is not valid UTF-8", path.display()))?;
let mut file = File::open(&path)?;
builder.append_file(path_str.as_bytes(), &mut file)?;
} }
builder.into_inner()?.flush()?; builder.into_inner()?.flush()?;
Ok(()) Ok(())

View File

@ -144,7 +144,7 @@ fn disasm(args: DisasmArgs) -> Result<()> {
let asm_dir = args.out.join("asm"); let asm_dir = args.out.join("asm");
let include_dir = args.out.join("include"); let include_dir = args.out.join("include");
DirBuilder::new().recursive(true).create(&include_dir)?; DirBuilder::new().recursive(true).create(&include_dir)?;
fs::write(&include_dir.join("macros.inc"), include_bytes!("../../assets/macros.inc"))?; fs::write(include_dir.join("macros.inc"), include_bytes!("../../assets/macros.inc"))?;
let mut files_out = File::create(args.out.join("link_order.txt"))?; let mut files_out = File::create(args.out.join("link_order.txt"))?;
for (unit, split_obj) in obj.link_order.iter().zip(&split_objs) { for (unit, split_obj) in obj.link_order.iter().zip(&split_objs) {

View File

@ -378,6 +378,7 @@ fn write_symbol_entry<W: Write>(
Ok(()) Ok(())
} }
#[allow(clippy::too_many_arguments)]
fn write_data<W: Write>( fn write_data<W: Write>(
w: &mut W, w: &mut W,
symbols: &[ObjSymbol], symbols: &[ObjSymbol],

View File

@ -105,7 +105,6 @@ pub fn process_elf<P: AsRef<Path>>(path: P) -> Result<ObjInfo> {
relocations: vec![], relocations: vec![],
original_address: 0, // TODO load from abs symbol original_address: 0, // TODO load from abs symbol
file_offset: section.file_range().map(|(v, _)| v).unwrap_or_default(), file_offset: section.file_range().map(|(v, _)| v).unwrap_or_default(),
section_known: true,
}); });
} }