-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with memory.x in the project root #22
Conversation
…ng the modified linker script
Thanks for the PR! The solution looks good to me.
Yeah, I tested this out with your changes and these linker scripts in the root of the project: $ cat memory.x
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
RAM : ORIGIN = 0x20000000, LENGTH = 64K
}
INCLUDE empty.x
$ touch empty.x
$ cargo b
(..)
= note: rust-lld: error: memory.x:7: cannot find linker script empty.x The linker fails to find linker scripts that weren't modified by |
src/main.rs
Outdated
// 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.insert(3, current_dir.to_str().unwrap_or(".").to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a closer look at the surrounding code, I think we should use Command::arg
instead of pushing arguments into a Vec<String>
because Command::arg
will accept a Path
directly. That way we can about the string conversion which may be lossy. Could you please do that change as part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I was not sure myself about that part. I'll have a look later.
Awesome, thanks again! |
You are welcome! |
When the linker script with RAM location is in the root directory where you invoke
cargo
it is always used by the linker.So only the beginning of the stack is changed which leads to an invalid memory layout.
When you look at the man page for GNU
ld
it says for the-T
option:So it seems that this is also valid for included scripts.
As a first attempt to fix this problem I set the working dir for the second linker invocation to the temp dir containing the modified script. This works for my setup where I have a
memory.x
in the project root as well as for the example app in this repository.It could be a problem though when you have multiple linker scripts in project root. But maybe you could set the project root as additional
-L
directory. What do you think?