probe-rs / rtt-target

Target side implementation of the RTT (Real-Time Transfer) I/O protocol
MIT License
105 stars 28 forks source link

rust-lld error #50

Closed Admsher closed 2 weeks ago

Admsher commented 2 weeks ago

I am not sure how to describe the problem but i get this erro wheneve ri try to use rtt_target for printing statements:

note: "rust-lld" "-flavor" "gnu" "C:\\Users\\Admin\\AppData\\Local\\Temp\\rustcT3hpPl\\symbols.o" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\NXP1064_example-67f6da92d249a49b.51qu2uphtjlb2awa09goqd8n5.rcgu.o" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\NXP1064_example-67f6da92d249a49b.6e8y7mvobjrvleaur32b8h51t.rcgu.o" "--as-needed" "-L" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps" "-L" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\debug\\deps" "-L" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\build\\cortex-m-ea86d56280f051dc\\out" "-L" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\build\\cortex-m-rt-b99cc6cf1485c8e6\\out" "-L" "C:\\Users\\Admin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7em-none-eabihf\\lib" "-Bstatic" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\libcortex_m_rt-f2e9e548fce23f1b.rlib" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\libr0-0629d99891300178.rlib" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\libpanic_halt-bb95a61588caf22d.rlib" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\librtt_target-14831a2e3be057bd.rlib" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\libcritical_section-033c8713fe55df45.rlib" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\libufmt_write-974116cbc3e4a50a.rlib" "C:\\Users\\Admin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7em-none-eabihf\\lib\\librustc_std_workspace_core-c456381a8b8e35db.rlib" "C:\\Users\\Admin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7em-none-eabihf\\lib\\libcore-427ff03a8fcba738.rlib" "C:\\Users\\Admin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7em-none-eabihf\\lib\\libcompiler_builtins-44e380169a097313.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "C:\\Users\\Admin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\thumbv7em-none-eabihf\\lib" "-o" "D:\\Varad-Intern_contents\\NXP1064-example\\target\\thumbv7em-none-eabihf\\debug\\deps\\NXP1064_example-67f6da92d249a49b" "--gc-sections" "-Tlink.x"
  = note: rust-lld: error: undefined symbol: _critical_section_1_0_acquire
          >>> referenced by lib.rs:193 (C:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\critical-section-1.1.3\src\lib.rs:193)
          >>>               rtt_target-14831a2e3be057bd.rtt_target.604d19a96c7d9fff-cgu.0.rcgu.o:(critical_section::with::h6692443efe4667dd) in archive D:\Varad-Intern_contents\NXP1064-example\target\thumbv7em-none-eabihf\debug\deps\librtt_target-14831a2e3be057bd.rlib
          >>> referenced by lib.rs:193 (C:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\critical-section-1.1.3\src\lib.rs:193)
          >>>               rtt_target-14831a2e3be057bd.rtt_target.604d19a96c7d9fff-cgu.0.rcgu.o:(critical_section::with::hbd4dbc649497990e) in archive D:\Varad-Intern_contents\NXP1064-example\target\thumbv7em-none-eabihf\debug\deps\librtt_target-14831a2e3be057bd.rlib

          rust-lld: error: undefined symbol: _critical_section_1_0_release
          >>> referenced by lib.rs:210 (C:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\critical-section-1.1.3\src\lib.rs:210)
          >>>               rtt_target-14831a2e3be057bd.rtt_target.604d19a96c7d9fff-cgu.0.rcgu.o:(core::ptr::drop_in_place$LT$critical_section..with..Guard$GT$::h9724f11f5faa3ba0) in archive D:\Varad-Intern_contents\NXP1064-example\target\thumbv7em-none-eabihf\debug\deps\librtt_target-14831a2e3be057bd.rlib

this is my Cargo.toml

[package]
name = "NXP1064-example"
version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]}

cortex-m-rt = "0.6.2"
cortex-m-semihosting = "0.5.0"
critical-section = "1.1.3"
imxrt-ral = "0.5.3"
panic-halt = "0.2"
rtt-target = "0.5.0"

[build-dependencies]
bindgen = "0.65.1"

any help is appreciated

### Tasks
mvirkkunen commented 2 weeks ago

It looks like the critical-section implementation in cortex-m isn't getting linked in properly. Is your program pretty minimal, i.e. does it only log something and not do much anything else?

You could try adding this in your program, it's been a while so I'm not entirely sure anymore but this might be enough to convince the compiler to link it in:

use cortex_m as _;
Admsher commented 2 weeks ago

Yes you are right about the fact that the code is minimal just for logging function, i already have the line that you suggest and I also tried cargo clean as well, is there a problem with small code for rtt that I am unaware of?

mvirkkunen commented 2 weeks ago

It's not a problem "with small code", it's a problem with the critical-section implementation in cortex-m not being enabled properly or being dropped by the compiler. I can't immediately say why though - would you be able to publish the code as a repo?

Admsher commented 2 weeks ago

It's the code I used in from the probe-rs tutorial to print hello world, as I said nothing complex , you can find it here: https://probe.rs/docs/tools/cargo-embed/

mvirkkunen commented 2 weeks ago

What I'm specifically looking for is all your config files such as .cargo/config.toml and such which you likely have modified yourself.

Admsher commented 2 weeks ago

HI sorry for the delay, here i s the config.toml file

[build]
target="thumbv7em-none-eabihf"

rustflags=[ "-C","link-arg=-Tlink.x",]
mvirkkunen commented 2 weeks ago

I tried reproducing the problem and adding use cortex_m as _; fixed it. Please share the entirety of your code as a repository because otherwise I can only guess.

Admsher commented 2 weeks ago

You are mp right as i was suggested to fo the same on the rust forum as well , here is my code.

#![no_main]
#![no_std]

use panic_halt as _;

use cortex_m_rt::entry;
use cortex_m_semihosting::{debug, hprintln};
use MXP1064 as _;
use rtt_target::{rprintln, rtt_init_print};

#[cortex_m_rt::entry]
fn main() -> ! {
rtt_init_print!();
loop {
rprintln!("Hello, world!");
}
}
mvirkkunen commented 2 weeks ago

But that code does not have the line use cortex_m as _;...

Admsher commented 2 weeks ago

You are right , i might have missed it as it was not added in the tutorial page ,I will do this and see if anything changes. Sorry for the overlook

mvirkkunen commented 2 weeks ago

But I told you two times to add it right here!

Admsher commented 2 weeks ago

But I told you two times to add it right here!

Yep sorry for that I actually don't have access to my laptop where the code is i will close the issue as soon as I test it

Admsher commented 2 weeks ago

Adding th euse cortexm as ; helped thanks a lot :)