-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow adding a linker script in build.rs #7984
Comments
The easiest way to support this would be to allow passing arbitrary rustc flags via
This is not really something we need since linker scripts are a GNU LD invention anyways, so linkers supporting them mimic GNU LD's command line options as well.
Note that we do this by having |
I've created a repository to demonstrate that this does make things work: https://github.com/xobs/rust-extra-link-arg-test What is the process now? Should this issue be closed, or should it stay until it's stabilized? |
I could not figure out for the life of me why I couldn't get the GitHub Actions CI to build a project that I could replicate everywhere else, until today I happened upon this thread with this detail. I had |
We need this functionality in order to add a link statement to the end of the linker invocation for building a crate that links against libstdc++ on CentOS 7 using devtoolset. Does anyone know when this might be stabilised? |
This now has an issue tracking stabilization: #9426 |
I tried this today, and it didn't work using a very recent cargo build. |
It looks like it will be part of Rust 1.56: https://github.com/rust-lang/cargo/blob/rust-1.56.0/src/cargo/core/features.rs#L879 |
I guess this can be closed now? |
Yea, seems like this is addressed via |
Some kinds of targets such as embedded devices have special requirements when it comes to linking. On these devices, a linker script is required in order to load various classes of memory at specific offsets. Without this value, a default linker script is used, which very rarely works on embedded targets.
The current approach (decided in rust-embedded/wg#24 (comment)) is to create a per-project
.cargo/config
file to pass flags to rustc, however this suffers from a number of drawbacks:RUSTFLAGS
variable is setcargo build --target riscv32imac-unknown-none-elf -p kernel
can pick up different linker scripts depending on the current directory (Support linker scripts in Cargo.toml / build.rs rust-embedded/wg#432 (comment))-rt
crate.It would be nice to be able to include a linker script as an artifact from
build.rs
by echoing a path to stdout. All of the current examples require users to manually copy this file (e.g. cortex-m-rt or riscv-rt), and the end result of not including this file is either a broken binary or a failed build.By allowing
build.rs
to specify additional linker files, we solve several problems:cortex-m-rt
orriscv-rt
can bundle their own linker scripts using their own naming convention for e.g..bss
or.data
.cargo/config
fileAppending linker flags to the output seems like it should be similar to how library crates can append libraries to the output, and it shouldn't be considered an error if multiple linker files are included. In fact, the approach that is taken by the current
-rt
libraries is to include an mcu-specific linker script alongside an arch-specific crate.Disadvantages I can see from this approach are:
/REBASE
, not full scripts.The text was updated successfully, but these errors were encountered: