From 5db897749598723047b973336fd0d5a8927b96b5 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 15 Sep 2015 14:43:50 +0200 Subject: [PATCH 1/2] Rename main to rust_main to support testing On testing, `std` is imported, which defines an own `main` function. Thus `cargo test` fails if there alread exists one non-mangled main. --- src/arch/x86_64/long_mode_init.asm | 4 ++-- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/arch/x86_64/long_mode_init.asm b/src/arch/x86_64/long_mode_init.asm index 4a8c60e4..1dfb0186 100644 --- a/src/arch/x86_64/long_mode_init.asm +++ b/src/arch/x86_64/long_mode_init.asm @@ -13,7 +13,7 @@ ; limitations under the License. global long_mode_start -extern main +extern rust_main section .text bits 64 @@ -21,7 +21,7 @@ long_mode_start: call setup_SSE ; call rust main - call main + call rust_main .os_returned: ; rust main returned, print `OS returned!` mov rax, 0x4f724f204f534f4f diff --git a/src/lib.rs b/src/lib.rs index 1eca7342..b1984d03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ extern crate rlibc; use core::intrinsics::offset; #[no_mangle] -pub extern fn main() { +pub extern fn rust_main() { // ATTENTION: we have a very small stack and no guard page let x = ["Hello", " ", "World", "!"]; let screen_pointer = 0xb8000 as *const u16; From 9c4d057e3d64a0c59373534947df45cfdb356b12 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 15 Sep 2015 14:44:37 +0200 Subject: [PATCH 2/2] Don't implement lang items on testing The `std` library is imported on testing. It already implements all lang items. --- src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b1984d03..676ce844 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,5 +37,10 @@ pub extern fn rust_main() { loop{} } -#[lang = "eh_personality"] extern fn eh_personality() {} -#[lang = "panic_fmt"] extern fn panic_fmt() -> ! {loop{}} +#[cfg(not(test))] +#[lang = "eh_personality"] +extern fn eh_personality() {} + +#[cfg(not(test))] +#[lang = "panic_fmt"] +extern fn panic_fmt() -> ! {loop{}}