Skip to content

Commit

Permalink
Use lld instead of avr-gcc as the linker
Browse files Browse the repository at this point in the history
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]: rust-lang#131755 (comment)
[here]: rust-lang#131755 (comment)
  • Loading branch information
jfrimmel committed Oct 16, 2024
1 parent 1d16289 commit 4920c6a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/run-make/avr-rjmp-offset/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ fn main() {
.opt_level("s")
.panic("abort")
.target("avr-unknown-gnu-atmega328")
// normally one links with `avr-gcc`, but this is not available in CI,
// hence this test diverges from the default behavior to enable linking
// at all, which is necessary for the test (to resolve the labels). To
// not depend on a special linker script, the main-function is marked as
// the entry function, causing the linker to not remove it.
.linker("lld")
.link_arg("--entry=main")
.output("compiled")
.run();

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

0 comments on commit 4920c6a

Please sign in to comment.