Skip to content

Commit

Permalink
Add auto_force_active option (disable to support -code_merging)
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
encounter committed Jan 14, 2024
1 parent 5a3256b commit 968f50e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion 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.0"
version = "0.7.1"
edition = "2021"
publish = false
repository = "https://github.com/encounter/decomp-toolkit"
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/dol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ pub struct ProjectConfig {
/// and instead assumes that all symbols are known.
#[serde(default, skip_serializing_if = "is_default")]
pub symbols_known: bool,
/// Fills gaps between symbols with
/// Fills gaps between symbols to avoid linker realignment.
#[serde(default = "bool_true", skip_serializing_if = "is_true")]
pub fill_gaps: bool,
/// Marks all emitted symbols as "force active" to prevent the linker from removing them.
#[serde(default = "bool_true", skip_serializing_if = "is_true")]
pub auto_force_active: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -859,7 +862,7 @@ fn split_write_obj(
entry,
};
for (unit, split_obj) in module.obj.link_order.iter().zip(&split_objs) {
let out_obj = write_elf(split_obj)?;
let out_obj = write_elf(split_obj, config.auto_force_active)?;
let out_path = obj_dir.join(obj_path_for_unit(&unit.name));
out_config.units.push(OutputUnit {
object: out_path.clone(),
Expand Down Expand Up @@ -1763,6 +1766,7 @@ fn config(args: ConfigArgs) -> Result<()> {
common_start: None,
symbols_known: false,
fill_gaps: true,
auto_force_active: true,
};

let mut modules = Vec::<(u32, ModuleConfig)>::new();
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn split(args: SplitArgs) -> Result<()> {

let split_objs = split_obj(&obj)?;
for (unit, split_obj) in obj.link_order.iter().zip(&split_objs) {
let out_obj = write_elf(split_obj)?;
let out_obj = write_elf(split_obj, false)?;
match file_map.entry(unit.name.clone()) {
hash_map::Entry::Vacant(e) => e.insert(out_obj),
hash_map::Entry::Occupied(_) => bail!("Duplicate file {}", unit.name),
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/rel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ fn merge(args: MergeArgs) -> Result<()> {

// Write ELF
log::info!("Writing {}", args.out_file.display());
fs::write(&args.out_file, write_elf(&obj)?)?;
fs::write(&args.out_file, write_elf(&obj, false)?)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ where P: AsRef<Path> {
Ok(obj)
}

pub fn write_elf(obj: &ObjInfo) -> Result<Vec<u8>> {
pub fn write_elf(obj: &ObjInfo, force_active: bool) -> Result<Vec<u8>> {
let mut out_data = Vec::new();
let mut writer = object::write::elf::Writer::new(Endianness::Big, false, &mut out_data);

Expand Down Expand Up @@ -540,7 +540,7 @@ pub fn write_elf(obj: &ObjInfo) -> Result<Vec<u8>> {
out_symbols.push(OutSymbol { index, sym });
symbol_map[symbol_index] = Some(index.0);
if let Some(comment_data) = &mut comment_data {
CommentSym::from(symbol, true).to_writer_static(comment_data, Endian::Big)?;
CommentSym::from(symbol, force_active).to_writer_static(comment_data, Endian::Big)?;
}
}

Expand Down

0 comments on commit 968f50e

Please sign in to comment.