Skip to content

Commit

Permalink
Merge pull request #22 from DerFetzer/fix_local_linker_script
Browse files Browse the repository at this point in the history
Problem with memory.x in the project root
  • Loading branch information
japaric committed Feb 5, 2021
2 parents 9eb1e5f + a1c9620 commit df93cb1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,18 @@ fn notmain() -> Result<i32, anyhow::Error> {
drop(new_linker_script);

// invoke the linker a second time
// we need to patch the arguments to use the new linker script
let mut args = args;
// the *hope* is that by placing our temp dir first in the search path (argument list) the
// linker will pick our override rather than the original linker script
// also add the temp dir to the search path
// HACK `-L` needs to go after `-flavor gnu`; position is currently hardcoded
args.insert(2, "-L".to_string());
args.insert(3, tempdir.path().display().to_string());
// we also need to override `_stack_start` to make the stack start below fake RAM
args.push(format!("--defsym=_stack_start={}", new_origin));

let mut c2 = Command::new(LINKER);
c2.args(&args);
// add the current dir to the linker search path to include all unmodified scripts there
// HACK `-L` needs to go after `-flavor gnu`; position is currently hardcoded
c2.args(&args[..2]);
c2.arg("-L".to_string());
c2.arg(current_dir);
c2.args(&args[2..]);
// we need to override `_stack_start` to make the stack start below fake RAM
c2.arg(format!("--defsym=_stack_start={}", new_origin));
// set working directory to temporary directory containing our new linker script
// this makes sure that it takes precedence over the original one
c2.current_dir(tempdir.path());
log::trace!("{:?}", c2);
let status = c2.status()?;
if !status.success() {
Expand Down

0 comments on commit df93cb1

Please sign in to comment.