Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Call to rust_begin_unwind despite panic=abort #119

Closed
ketsuban opened this issue Dec 8, 2017 · 1 comment
Closed

Call to rust_begin_unwind despite panic=abort #119

ketsuban opened this issue Dec 8, 2017 · 1 comment

Comments

@ketsuban
Copy link

ketsuban commented Dec 8, 2017

Upon getting a successful OKAY from Rust code I took a hint from @phil-opp's guide and tried the following.

#[no_mangle]
pub fn kmain() -> ! {
    let x = ["Hello", "World", "!"];
    let y = x;
    unsafe {
        *(0xb8000 as *mut u64) = 0x2f592f412f4b2f4f;
    }
    loop {}
}

As Phil's guide suggests, this produces undefined references to memcpy, but what's stranger is what happens when I bring in rlibc to provide those symbols (and add --gc-sections to the linker call to get rid of all the compiler builtins):

ld -n --gc-sections -o target/x86_64-unknown-none/debug/finisterre -T src/arch/x86_64/linker.ld target/x86_64-unknown-none/debug/multiboot.o target/x86_64-unknown-none/debug/boot.o target/x86_64-unknown-none/debug/libfinisterre.a
target/x86_64-unknown-none/debug/libfinisterre.a(core-d2a8ed3c191e10b4.core0.rcgu.o): In function `core::panicking::panic_fmt::h35553c2ef9e37a4d':
core0-13bbbb8dfc184aa61fdc6f6336cf5056.rs:(.text.cold._ZN4core9panicking9panic_fmt17h35553c2ef9e37a4dE+0x88): undefined reference to `rust_begin_unwind'

I have "panic-strategy": "abort" in my target file, why is there a call to rust_begin_unwind from libcore?

@ketsuban ketsuban changed the title Blizzard of undefined-reference-to Call to rust_begin_unwind despite panic=abort Dec 8, 2017
@ketsuban
Copy link
Author

ketsuban commented Dec 8, 2017

Okay, clearly I had some sort of brain mystery because the solution has been semi-documented for a year now - panic_fmt needs to be both #[no_mangle] and pub.

This whole thing seems like it should be mentioned at the end of "Hello from Rust", in the same vein as the preventative setting of bit 16 (enabling write protection in ring 0) when enabling paging.

@ketsuban ketsuban closed this as completed Dec 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant