From a716763772b00fffab1b310d1dc3619e03675e73 Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Fri, 4 Oct 2024 23:16:19 +0800 Subject: [PATCH] Remove the linkage feature usage for `ostd::main` --- kernel/src/lib.rs | 1 - osdk/src/commands/new/kernel.template | 2 -- .../work_in_workspace_templates/myos/src/lib.rs | 1 - .../write_a_kernel_in_100_lines_templates/lib.rs | 3 +-- ostd/libs/ostd-macros/src/lib.rs | 10 +++------- ostd/src/panic.rs | 2 +- 6 files changed, 5 insertions(+), 14 deletions(-) diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 25126a22..99bf8065 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -15,7 +15,6 @@ #![feature(format_args_nl)] #![feature(int_roundings)] #![feature(let_chains)] -#![feature(linkage)] #![feature(linked_list_remove)] #![feature(negative_impls)] #![feature(register_tool)] diff --git a/osdk/src/commands/new/kernel.template b/osdk/src/commands/new/kernel.template index c92050d1..bb5486ad 100644 --- a/osdk/src/commands/new/kernel.template +++ b/osdk/src/commands/new/kernel.template @@ -1,6 +1,4 @@ #![no_std] -// The feature `linkage` is required for `ostd::main` to work. -#![feature(linkage)] #![deny(unsafe_code)] use ostd::prelude::*; diff --git a/osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs b/osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs index a5cd52cd..a8fc07f1 100644 --- a/osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs +++ b/osdk/tests/examples_in_book/work_in_workspace_templates/myos/src/lib.rs @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #![no_std] -#![feature(linkage)] #![deny(unsafe_code)] use ostd::prelude::*; diff --git a/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs b/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs index 06e0d728..1fc4bc79 100644 --- a/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs +++ b/osdk/tests/examples_in_book/write_a_kernel_in_100_lines_templates/lib.rs @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 #![no_std] -// The feature `linkage` is required for `ostd::main` to work. -#![feature(linkage)] +#![deny(unsafe_code)] extern crate alloc; diff --git a/ostd/libs/ostd-macros/src/lib.rs b/ostd/libs/ostd-macros/src/lib.rs index 7c5c57c9..91b031c0 100644 --- a/ostd/libs/ostd-macros/src/lib.rs +++ b/ostd/libs/ostd-macros/src/lib.rs @@ -13,7 +13,6 @@ use syn::{parse_macro_input, Expr, Ident, ItemFn}; /// /// ```ignore /// #![no_std] -/// #![feature(linkage)] /// /// use ostd::prelude::*; /// @@ -28,13 +27,14 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream { let main_fn_name = &main_fn.sig.ident; quote!( + #[cfg(not(ktest))] #[no_mangle] - #[linkage = "weak"] extern "Rust" fn __ostd_main() -> ! { #main_fn_name(); ostd::prelude::abort(); } + #[allow(unused)] #main_fn ) .into() @@ -44,10 +44,6 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream { /// /// This macro is used for internal OSDK implementation. Do not use it /// directly. -/// -/// It is a strong version of the `main` macro attribute. So if it exists ( -/// which means the unit test kernel is linked to perform testing), the actual -/// kernel entry point will be replaced by this one. #[proc_macro_attribute] pub fn test_main(_attr: TokenStream, item: TokenStream) -> TokenStream { let main_fn = parse_macro_input!(item as ItemFn); @@ -82,7 +78,7 @@ pub fn panic_handler(_attr: TokenStream, item: TokenStream) -> TokenStream { #handler_fn_name(info); } - #[cfg(not(ktest))] + #[allow(unused)] #handler_fn ) .into() diff --git a/ostd/src/panic.rs b/ostd/src/panic.rs index a9ca9183..a25eec2d 100644 --- a/ostd/src/panic.rs +++ b/ostd/src/panic.rs @@ -25,7 +25,7 @@ use unwinding::abi::{ /// /// The user can override it by defining their own panic handler with the macro /// `#[ostd::panic_handler]`. -#[cfg(not(ktest))] +#[linkage = "weak"] #[no_mangle] pub fn __ostd_panic_handler(info: &core::panic::PanicInfo) -> ! { let _irq_guard = crate::trap::disable_local();