Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions .github/workflows/release.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
name: Release dsd
name: Build

on:
pull_request:
workflow_dispatch:

env:
RUSTFLAGS: -D warnings

jobs:
build:
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache Rust workspace
uses: Swatinem/rust-cache@v2

- name: Clippy
run: cargo clippy

fmt:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: Format
run: cargo fmt --all --check

build-cli:
name: Build dsd
strategy:
matrix:
include:
Expand All @@ -18,7 +56,7 @@ jobs:
target: aarch64-apple-darwin
file: dsd-macos-arm64

- os: macos-13
- os: macos-latest
name: macos-x86_64
target: x86_64-apple-darwin
file: dsd-macos-x86_64
Expand All @@ -27,7 +65,6 @@ jobs:
name: linux-x86_64
target: x86_64-unknown-linux-gnu
file: dsd-linux-x86_64

runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand Down Expand Up @@ -64,9 +101,11 @@ jobs:
name: dsd-${{ matrix.name }}
path: ${{ matrix.file }}
if-no-files-found: error

release:
needs: build
name: Release
needs: build-cli
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
3 changes: 2 additions & 1 deletion cli/src/analysis/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ fn add_function_calls_as_relocations(
if called_function.address != symbol.addr {
log::warn!(
"Local function call from {:#010x} in {} to {:#010x} goes to middle of function '{}' at {:#010x}, adding an external label symbol",
address, module_kind,
address,
module_kind,
called_function.address,
symbol.name,
symbol.addr
Expand Down
2 changes: 1 addition & 1 deletion cli/src/analysis/functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use anyhow::{bail, Result};
use anyhow::{Result, bail};
use ds_decomp::analysis::functions::Function;
use unarm::{ArmVersion, DisplayOptions, Endian, ParseFlags, ParseMode, Parser, RegNames};

Expand Down
2 changes: 1 addition & 1 deletion cli/src/analysis/overlay_groups.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{bail, Result};
use anyhow::{Result, bail};
use ds_rom::rom::Overlay;

pub struct OverlayGroups {
Expand Down
5 changes: 2 additions & 3 deletions cli/src/cmd/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod modules;
mod symbols;

pub use modules::*;
pub use symbols::*;

use anyhow::Result;
use clap::{Args, Subcommand};
pub use modules::*;
pub use symbols::*;

/// Subcommands for checking/verifying build output.
#[derive(Args)]
Expand Down
4 changes: 2 additions & 2 deletions cli/src/cmd/check/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::{bail, Context, Result};
use anyhow::{Context, Result, bail};
use clap::Args;
use ds_decomp::config::{
config::{Config, ConfigModule},
module::ModuleKind,
};

use crate::util::io::{read_file, FileError};
use crate::util::io::{FileError, read_file};

/// Verifies that built modules are matching the base ROM.
#[derive(Args)]
Expand Down
77 changes: 37 additions & 40 deletions cli/src/cmd/delink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ds_decomp::config::{
use ds_rom::rom::{Rom, RomLoadOptions, raw::AutoloadKind};
use object::{Architecture, BinaryFormat, Endianness, RelocationFlags};

use super::Lcf;
use crate::{
config::{
delinks::DelinksExt,
Expand All @@ -27,8 +28,6 @@ use crate::{
util::io::{create_dir_all, create_file},
};

use super::Lcf;

/// Delinks an extracted ROM into relocatable ELF files.
#[derive(Args)]
pub struct Delink {
Expand Down Expand Up @@ -57,17 +56,14 @@ impl Delink {
let config_path = self.config_path.parent().unwrap().to_path_buf();

let symbol_maps = SymbolMaps::from_config(&config_path, &config)?;
let rom = Rom::load(
config_path.join(&config.rom_config),
RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
},
)?;
let rom = Rom::load(config_path.join(&config.rom_config), RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
})?;
let dtcm_end = rom
.arm9()
.autoloads()?
Expand Down Expand Up @@ -119,22 +115,21 @@ impl<'a> Delinker<'a> {
(symbol_map, module_section.end_address())
};

if let Some((symbol, size)) = symbol_map.get_symbol_containing(section.end_address() - 1, section_end)? {
if symbol.addr >= section.start_address()
&& symbol.addr < section.end_address()
&& symbol.addr + size > section.end_address()
{
bail!(
"Last symbol '{}' in section '{}' of file '{}' has the range {:#010x}..{:#010x} but is not contained within the file's section range ({:#010x}..{:#010x})",
symbol.name,
section.name(),
file.name,
symbol.addr,
symbol.addr + size,
section.start_address(),
section.end_address(),
);
}
if let Some((symbol, size)) = symbol_map.get_symbol_containing(section.end_address() - 1, section_end)?
&& symbol.addr >= section.start_address()
&& symbol.addr < section.end_address()
&& symbol.addr + size > section.end_address()
{
bail!(
"Last symbol '{}' in section '{}' of file '{}' has the range {:#010x}..{:#010x} but is not contained within the file's section range ({:#010x}..{:#010x})",
symbol.name,
section.name(),
file.name,
symbol.addr,
symbol.addr + size,
section.start_address(),
section.end_address(),
);
}
}

Expand All @@ -158,7 +153,12 @@ impl<'a> Delinker<'a> {
Ok(())
}

fn delink(&self, symbol_maps: &SymbolMaps, module: &Module, delink_file: &DelinkFile) -> Result<object::write::Object> {
fn delink(
&self,
symbol_maps: &SymbolMaps,
module: &Module,
delink_file: &DelinkFile,
) -> Result<object::write::Object<'_>> {
let symbol_map = symbol_maps.get(module.kind()).unwrap();
let dtcm_symbol_map = symbol_maps.get(ModuleKind::Autoload(AutoloadKind::Dtcm)).unwrap();
let mut object = object::write::Object::new(BinaryFormat::Elf, Architecture::Arm, Endianness::Little);
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'a> Delinker<'a> {
name, // same name as section
value: 0,
size: 0,
kind: object::SymbolKind::Label,
kind: object::SymbolKind::Section,
scope: object::SymbolScope::Compilation,
weak: false,
section: object::write::SymbolSection::Section(obj_section_id),
Expand Down Expand Up @@ -365,15 +365,12 @@ impl<'a> Delinker<'a> {
// Create relocation
let r_type = relocation.kind().as_elf_relocation_type();
let addend = relocation.addend();
object.add_relocation(
obj_section_id,
object::write::Relocation {
offset: offset as u64,
symbol: symbol_id,
addend,
flags: RelocationFlags::Elf { r_type },
},
)?;
object.add_relocation(obj_section_id, object::write::Relocation {
offset: offset as u64,
symbol: symbol_id,
addend,
flags: RelocationFlags::Elf { r_type },
})?;
}
}

Expand Down
19 changes: 8 additions & 11 deletions cli/src/cmd/dis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@ impl Disassemble {
let config_path = self.config_path.parent().unwrap();

let rom_config_path = config_path.join(&config.rom_config);
let rom = Rom::load(
&rom_config_path,
RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
},
)?;
let rom = Rom::load(&rom_config_path, RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
})?;

let mut symbol_maps = SymbolMaps::from_config(config_path, &config)?;

Expand Down
3 changes: 1 addition & 2 deletions cli/src/cmd/dump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ mod ambig_relocs;
mod elf_symbols;

use ambig_relocs::*;
use elf_symbols::*;

use clap::{Args, Subcommand};
use elf_symbols::*;

/// Subcommands for dumping information from a dsd project.
#[derive(Args)]
Expand Down
22 changes: 10 additions & 12 deletions cli/src/cmd/fix/ctor_symbols.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::util::bytes::FromSlice;
use std::path::PathBuf;

use anyhow::{Result, bail};
Expand All @@ -14,6 +13,8 @@ use ds_decomp::{
};
use ds_rom::rom::{Rom, RomLoadOptions};

use crate::util::bytes::FromSlice;

/// Adds missing symbols in the .init and .ctor sections.
#[derive(Args, Clone)]
pub struct FixCtorSymbols {
Expand All @@ -33,17 +34,14 @@ impl FixCtorSymbols {

let mut symbol_maps = SymbolMaps::from_config(config_path, &config)?;

let rom = Rom::load(
config_path.join(&config.rom_config),
RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
},
)?;
let rom = Rom::load(config_path.join(&config.rom_config), RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
})?;

self.fix_module(&config.main_module, ModuleKind::Arm9, &mut symbol_maps, &rom)?;
for autoload in &config.autoloads {
Expand Down
3 changes: 1 addition & 2 deletions cli/src/cmd/fix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
mod ctor_symbols;
mod thumb_nop;

use clap::{Args, Subcommand};
use ctor_symbols::*;
use thumb_nop::*;

use clap::{Args, Subcommand};

/// Subcommands for retroactively fixing already initialized dsd projects.
#[derive(Args)]
pub struct FixArgs {
Expand Down
19 changes: 8 additions & 11 deletions cli/src/cmd/fix/thumb_nop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ impl FixThumbNop {

let mut symbol_maps = SymbolMaps::from_config(config_path, &config)?;

let rom = Rom::load(
config_path.join(&config.rom_config),
RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
},
)?;
let rom = Rom::load(config_path.join(&config.rom_config), RomLoadOptions {
key: None,
compress: false,
encrypt: false,
load_files: false,
load_header: false,
load_banner: false,
})?;

let mut num_changes = 0;
num_changes += self.fix_module(&config, ModuleKind::Arm9, &rom, &mut symbol_maps)?;
Expand Down
3 changes: 1 addition & 2 deletions cli/src/cmd/import/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod symbols;

use symbols::*;

use anyhow::Result;
use clap::{Args, Subcommand};
use symbols::*;

/// Subcommands for importing config data from existing builds.
#[derive(Args)]
Expand Down
Loading