Skip to content

Commit

Permalink
Fix lcf generation for missing .sbss2
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Aug 3, 2023
1 parent bd0422e commit 26a3021
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions assets/ldscript.lcf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ SECTIONS
.stack ALIGN(0x100):{}
} > text

_stack_addr = (_f_sbss2 + SIZEOF(.sbss2) + $STACKSIZE + 0x7) & ~0x7;
_stack_end = _f_sbss2 + SIZEOF(.sbss2);
_stack_end = $LAST_SECTION_SYMBOL + SIZEOF($LAST_SECTION_NAME);
_stack_addr = (_stack_end + $STACKSIZE + 0x7) & ~0x7;
_db_stack_addr = (_stack_addr + 0x2000);
_db_stack_end = _stack_addr;
__ArenaLo = (_db_stack_addr + 0x1f) & ~0x1f;
Expand Down
6 changes: 6 additions & 0 deletions src/util/lcf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ pub fn generate_ldscript(obj: &ObjInfo) -> Result<String> {
force_files.push(obj_path.file_name().unwrap().to_str().unwrap().to_string());
}

// Hack to handle missing .sbss2 section... what's the proper way?
let last_section_name = obj.sections.last().unwrap().name.clone();
let last_section_symbol = format!("_f_{}", last_section_name.trim_start_matches('.'));

let out = include_str!("../../assets/ldscript.lcf")
.replacen("$SECTIONS", &section_defs, 1)
.replace("$LAST_SECTION_SYMBOL", &last_section_symbol)
.replace("$LAST_SECTION_NAME", &last_section_name)
.replacen("$STACKSIZE", &format!("{:#X}", stack_size), 1)
.replacen("$FORCEFILES", &force_files.join("\n "), 1);
Ok(out)
Expand Down

0 comments on commit 26a3021

Please sign in to comment.