Skip to content

Commit a35ed2f

Browse files
committed
Use rust-lld instead of avr-gcc as the linker
This fixes the [build error] caused by the `avr-gcc` (used as linker) not being available in the Rust CI. This is a viable solution, which shows the wrong/right behavior and, since no functions from `libgcc` are called, does not produce errors. This was discussed [here]. Another small problem is, that `lld` doesn't link the correct startup-code by default. This is not a problem for this test (since it does not actually use anything the startup code is needed for (no variables, no stack, no interrupts)), but this causes the `main`-function to be removed by the default flag `--gc-sections`. Therefore the `rmake`-driver also adds the linker flag `--entry=main` to mark the `main`-function as the entry point and thus preventing it from getting removed. The code would work on a real AVR device. [build error]: #131755 (comment) [here]: #131755 (comment)
1 parent bb8db13 commit a35ed2f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/run-make/avr-rjmp-offset/rmake.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ needs-llvm-components: avr
2+
//@ needs-rust-lld
23
//! Regression test for #129301/llvm-project#106722 within `rustc`.
34
//!
45
//! Some LLVM-versions had wrong offsets in the local labels, causing the first
@@ -17,6 +18,13 @@ fn main() {
1718
.opt_level("s")
1819
.panic("abort")
1920
.target("avr-unknown-gnu-atmega328")
21+
// normally one links with `avr-gcc`, but this is not available in CI,
22+
// hence this test diverges from the default behavior to enable linking
23+
// at all, which is necessary for the test (to resolve the labels). To
24+
// not depend on a special linker script, the main-function is marked as
25+
// the entry function, causing the linker to not remove it.
26+
.linker("rust-lld")
27+
.link_arg("--entry=main")
2028
.output("compiled")
2129
.run();
2230

@@ -35,6 +43,7 @@ fn main() {
3543
// fore the relative jump has an impact on the label offset. Old versions
3644
// of the Rust compiler did produce a label `rjmp .-4` (misses the first
3745
// instruction in the loop).
46+
assert!(disassembly.contains("<main>"), "no main function in output");
3847
disassembly
3948
.trim()
4049
.lines()

0 commit comments

Comments
 (0)