rtt-target
rtt-target copied to clipboard
Problem with linking
Hello!
I have a problem with linking (rtt-target = "0.4.0").
rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/mhanusek/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.66.0-arm-unknown-linux-gnueabihf
1.66.0-x86_64-unknown-linux-gnu
1.68.0-x86_64-unknown-linux-gnu
1.70.0-x86_64-unknown-linux-gnu
1.72.0-x86_64-unknown-linux-gnu (default)
installed targets for active toolchain
--------------------------------------
thumbv7m-none-eabi
x86_64-unknown-linux-gnu
active toolchain
----------------
1.72.0-x86_64-unknown-linux-gnu (default)
rustc 1.72.0 (5680fa18f 2023-08-23)
File .cargo/config:
[target.thumbv7m-none-eabi]
rustflags = ["-C", "link-arg=-Tlink.x"]
[build]
target = "thumbv7m-none-eabi"
File Cargo.toml:
[package]
name = "stm32-rusty-blink"
version = "0.1.0"
edition = "2021"
[profile.release]
opt-level = 'z'
lto = true
[dependencies]
cortex-m = "0.7.7"
cortex-m-rt = "0.7.3"
cortex-m-semihosting = "0.5.0"
embedded-hal = "^0.2.4"
panic-halt = "^0.2.0"
nb = "1.1.0"
stm32f1xx-hal = {version = "0.10.0", features = ["stm32f103", "rt", "medium"]}
bxcan = "0.7.0"
rtt-target = "0.4.0"
File main.rs:
#![no_std]
#![no_main]
#[allow(unused_imports)]
use cortex_m_rt::entry;
use rtt_target::{rtt_init_print, rprintln};
#[entry]
fn main() -> !
{
rtt_init_print!();
rprintln!("Hello, world!");
loop{}
}
Error:
error: linking with `rust-lld` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/home/mhanusek/.rustup/toolchains/1.72.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/mhanusek/.cargo/bin:/home/mhanusek/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/mhanusek/.local/share/JetBrains/Toolbox/scripts" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/tmp/rustcNhRSCR/symbols.o" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o" "--as-needed" "-L" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps" "-L" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/release/deps" "-L" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/build/cortex-m-5b09c5c145a61aea/out" "-L" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/build/cortex-m-rt-0e68da2e87ee149f/out" "-L" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/build/stm32f1-de1efe8cb9fdac47/out" "-L" "/home/mhanusek/.rustup/toolchains/1.72.0-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "-Bstatic" "/tmp/rustcNhRSCR/libcortex_m-a452532e7fb43f0e.rlib" "/home/mhanusek/.rustup/toolchains/1.72.0-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib/libcompiler_builtins-43037175e8f55de9.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/home/mhanusek/.rustup/toolchains/1.72.0-x86_64-unknown-linux-gnu/lib/rustlib/thumbv7m-none-eabi/lib" "-o" "/home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de" "--gc-sections" "-Tlink.x"
= note: rust-lld: warning: section type mismatch for .got
>>> <internal>:(.got): SHT_PROGBITS
>>> output section .got: SHT_NOBITS
rust-lld: warning: section type mismatch for .got.plt
>>> <internal>:(.got.plt): SHT_PROGBITS
>>> output section .got: SHT_NOBITS
rust-lld: warning: section type mismatch for .got
>>> <internal>:(.got): SHT_PROGBITS
>>> output section .got: SHT_NOBITS
rust-lld: error: undefined symbol: _critical_section_1_0_acquire
>>> referenced by stm32_rusty_blink.148cf5a1acb5b73f-cgu.0
>>> /home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o:(stm32_rusty_blink::__cortex_m_rt_main::h832f58195322a9fb)
>>> referenced by stm32_rusty_blink.148cf5a1acb5b73f-cgu.0
>>> /home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o:(stm32_rusty_blink::__cortex_m_rt_main::h832f58195322a9fb)
>>> referenced by stm32_rusty_blink.148cf5a1acb5b73f-cgu.0
>>> /home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o:(stm32_rusty_blink::__cortex_m_rt_main::h832f58195322a9fb)
rust-lld: error: undefined symbol: _critical_section_1_0_release
>>> referenced by stm32_rusty_blink.148cf5a1acb5b73f-cgu.0
>>> /home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o:(stm32_rusty_blink::__cortex_m_rt_main::h832f58195322a9fb)
>>> referenced by stm32_rusty_blink.148cf5a1acb5b73f-cgu.0
>>> /home/mhanusek/work/code/sandbox/stm32-rusty-blink/target/thumbv7m-none-eabi/release/deps/stm32_rusty_blink-4ed02ea7e0d778de.stm32_rusty_blink.148cf5a1acb5b73f-cgu.0.rcgu.o:(OUTLINED_FUNCTION_0)
error: aborting due to previous error; 4 warnings emitted
Error Failed to run cargo build: exit code = Some(101).
OS: Ubuntu 22.04 LTS
The error undefined symbol: _critical_section_1_0_acquire refers to the https://crates.io/crates/critical-section crate; you need to enable a critical-section implementation because rtt-target uses critical-section. Try enabling critical-section-single-core for cortex-m:
[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"] }
Your rust-lld command use "-Tlink.x" as its argument (see at the last of the first = note: ... line) . Try edit build.rs in your project directory and comment out the corresponding line.
For example, change
println!("cargo:rustc-link-arg=-Tlink.x");
or any similar line containing -Tlink.x into
// println!("cargo:rustc-link-arg=-Tlink.x");
edit 1:
If cannot find in build.rs, it may locate at .cargo/config.toml.
edit 2:
After the first successful cargo build, it is OK to uncomment back the -Tlink.x argument. It is strange, but it works for me anyway.
This https://github.com/probe-rs/rtt-target/issues/39#issuecomment-1703510321 and adding use cortex_m as _; to main.rs seems to have solved the problem for me
Here's my main.rs
#![no_std]
#![no_main]
use cortex_m as _;
use cortex_m_rt::entry;
use panic_halt as _;
use rtt_target::{rtt_init_print, rprintln};
#[entry]
fn main() -> ! {
rtt_init_print!();
rprintln!("Hello, world!");
loop {
rprintln!("loop...");
}
}