-
Notifications
You must be signed in to change notification settings - Fork 98
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
Support linker scripts in Cargo.toml / build.rs #432
Comments
Big 👍 from me, but this should probably be filed as a Cargo issue at https://github.com/rust-lang/cargo |
I'm probably misunderstanding something, but it's absolutely possible to check in I'm 100% on board with a build-script mechanism to set linker flags though. |
My understanding is that, you need to check in
Setting the architecture to |
I created an issue in the cargo repository: rust-lang/cargo#7984 |
As per #24 (comment)_, I'm opening a new issue.
The current recommendation for making custom linker scripts is to create a
.cargo/config
file and add a reference to the linker script there. The previous discussion identified a number of issues with this:Additionally, I would like to add some more issues I see with it, particularly with workspaces:
$ cargo build -p kernel --target riscv32imac-unknown-none-elf $ riscv64-unknown-elf-readelf -S target/riscv32imac-unknown-none-elf/debug/kernel There are 24 section headers, starting at offset 0x117724: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .rodata PROGBITS 000100e0 0000e0 002f38 00 AM 0 0 16 [ 2] .text PROGBITS 00014000 004000 00ebe2 00 AX 0 0 2 [ 3] .trap PROGBITS 00022be2 012be2 000104 00 AX 0 0 1 [ 4] .data PROGBITS 00023000 013000 002bc8 00 WA 0 0 4 [ 5] .sdata PROGBITS 00025bc8 015bc8 000004 00 WA 0 0 4 ... $ cd kernel $ cargo build -p kernel --target riscv32imac-unknown-none-elf $ riscv64-unknown-elf-readelf -S ../target/riscv32imac-unknown-none-elf/debug/kernel There are 21 section headers, starting at offset 0xfd404: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS ffd00000 001000 00c0c0 00 AX 0 0 4 [ 2] .rodata PROGBITS ffd0c0c0 00d0c0 002f34 00 AM 0 0 16 [ 3] .data PROGBITS ffd80000 010000 002bcc 00 WA 0 0 4096 [ 4] .bss NOBITS ffd82bcc 012bcc 000210 00 WA 0 0 4 ... $
riscv32imac-unknown-none-elf
andriscv32i-unknown-none-elf
, even though they're identical.cargo build --target riscv32imac-unknown-none
from the root, since cargo appears to ignore the.cargo/config
setting.Some of these could be fixed if cargo read
.cargo/config
from the crate root, which may be an acceptible workaround, however it seems to me that's just working around the problem.I think it would be much better if cargo supported setting the linker flags from e.g.
build.rs
so they can be set on a per-crate basis, possibly based on the build environment in something like a CI infrastructure.The text was updated successfully, but these errors were encountered: