intermezzOS / kernel

A hobby operating system, in Rust
http://intermezzos.github.io/
Apache License 2.0
1.39k stars 91 forks source link

Call to rust_begin_unwind despite panic=abort #119

Closed ketsuban closed 6 years ago

ketsuban commented 6 years ago

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 commented 6 years ago

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.