[Rust] Linker error when using loops

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
asdfasdfasdf
Posts: 2
Joined: Sun Nov 29, 2020 8:49 am

[Rust] Linker error when using loops

Post by asdfasdfasdf »

I've been trying to fix this for hours now and I'm not sure where to go from here. I'm working on an OS for an aarch64-unknown-none target, and whenever I put code in any sort of loop, the code compiles then I get an undefined reference. The symbol it gives is mangled, but I think it's

Code: Select all

core::panicking::panic_bounds_check
.
Here's my full build script:

Code: Select all

aarch64-elf-as -c boot.S -o boot.o
cargo build --target aarch64-unknown-none
aarch64-elf-gcc -T linker.ld -o os.elf -ffreestanding -O2 -nostdlib boot.o $HOME/Documents/os/kernel/target/aarch64-unknown-none/debug/libkernel.rlib
qemu-system-aarch64 -m 1024 -M raspi3 -kernel os.elf -serial stdio
If I remove the loop, it runs fine. Any insights into why this could be happening?
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: [Rust] Linker error when using loops

Post by Octocontrabass »

asdfasdfasdf wrote:Any insights into why this could be happening?
You're not linking against the Rust core library. You probably need to do that, since the core library provides several language features. I'm not all that familiar with Rust, but I found this page which might help.
User avatar
eekee
Member
Member
Posts: 891
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: [Rust] Linker error when using loops

Post by eekee »

What Octocontrabass said, but there's a clue in the error message that it may not be the loop itself.
asdfasdfasdf wrote:core::panicking::panic_bounds_check
"Bounds checking" is the classic term for making sure an array index isn't outside the array. It also applies to strings (which I mention in case Rust pretends they're not arrays), and may apply to some other data types too. It takes a little bit of code to do the bounds checking, and it's likely Rust keeps this code in a core library. If you have some difficulty including the core library at this stage, you might be able to avoid the issue by working directly with memory rather than an array... unless Rust also bounds-checks all pointer dereferences. :)
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Post Reply