about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJulian Frimmel <julian@fri-me.de>2024-10-15 23:07:00 +0200
committerJulian Frimmel <julian@fri-me.de>2024-10-17 09:00:08 +0200
commita35ed2f9eb52176b14e27f0f39229015cf035a30 (patch)
tree6c83868444796c5c2eb9b8ab76fa9d084f0eb267
parentbb8db13892ced757faf1c0206c70f313cd4b23c0 (diff)
downloadrust-a35ed2f9eb52176b14e27f0f39229015cf035a30.tar.gz
rust-a35ed2f9eb52176b14e27f0f39229015cf035a30.zip
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]: https://github.com/rust-lang/rust/pull/131755#issuecomment-2415127952
[here]: https://github.com/rust-lang/rust/pull/131755#issuecomment-2416469675
-rw-r--r--tests/run-make/avr-rjmp-offset/rmake.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/run-make/avr-rjmp-offset/rmake.rs b/tests/run-make/avr-rjmp-offset/rmake.rs
index 28018f59c5b..89cbca309be 100644
--- a/tests/run-make/avr-rjmp-offset/rmake.rs
+++ b/tests/run-make/avr-rjmp-offset/rmake.rs
@@ -1,4 +1,5 @@
 //@ needs-llvm-components: avr
+//@ needs-rust-lld
 //! Regression test for #129301/llvm-project#106722 within `rustc`.
 //!
 //! Some LLVM-versions had wrong offsets in the local labels, causing the first
@@ -17,6 +18,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("rust-lld")
+        .link_arg("--entry=main")
         .output("compiled")
         .run();
 
@@ -35,6 +43,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()