diff --git a/modules/axhal/linker.lds.S b/modules/axhal/linker.lds.S index 841000976d..00c4a9f09b 100644 --- a/modules/axhal/linker.lds.S +++ b/modules/axhal/linker.lds.S @@ -10,10 +10,14 @@ SECTIONS .text : ALIGN(4K) { _stext = .; + ; for unwind + __executable_start = .; *(.text.boot) *(.text .text.*) . = ALIGN(4K); _etext = .; + ; for unwind + __etext = .; } _srodata = .; @@ -23,6 +27,20 @@ SECTIONS *(.sdata2 .sdata2.*) } + .gcc_except_table : ALIGN(4K){ + *(.gcc_except_table .gcc_except_table.*) + } + + .eh_frame_hdr : ALIGN(4K){ + PROVIDE(__GNU_EH_FRAME_HDR = .); + KEEP(*(.eh_frame_hdr .eh_frame_hdr.*)) + } + + .eh_frame : ALIGN(4K){ + PROVIDE(__eh_frame = .); + KEEP(*(.eh_frame .eh_frame.*)) + } + .init_array : ALIGN(0x10) { __init_array_start = .; *(.init_array .init_array.*) diff --git a/modules/axruntime/Cargo.toml b/modules/axruntime/Cargo.toml index 25216be460..f91c606fa3 100644 --- a/modules/axruntime/Cargo.toml +++ b/modules/axruntime/Cargo.toml @@ -29,7 +29,6 @@ rtc = ["dep:chrono"] [dependencies] axalloc = { workspace = true, optional = true } -axbacktrace = { workspace = true } axconfig = { workspace = true } axdisplay = { workspace = true, optional = true } axinput = { workspace = true, optional = true } diff --git a/modules/axruntime/src/lang_items.rs b/modules/axruntime/src/lang_items.rs index 158c14834c..23fd42967d 100644 --- a/modules/axruntime/src/lang_items.rs +++ b/modules/axruntime/src/lang_items.rs @@ -1,8 +1,21 @@ use core::panic::PanicInfo; #[panic_handler] -fn panic(info: &PanicInfo) -> ! { +fn panic(info: &core::panic::PanicInfo) -> ! { + unsafe extern "Rust" { + pub fn __arceos_panic_handler(info: &core::panic::PanicInfo) -> !; + } + unsafe { + __arceos_panic_handler(info); + } +} + +/// The default panic handler for ArceOS based kernels. +/// +/// The user can override it by defining their own panic handler with the macro +/// `#[axmacros::panic_handler]`. +#[linkage = "weak"] +fn __arceos_panic_handler(info: &PanicInfo) -> ! { ax_println!("{}", info); - ax_println!("{}", axbacktrace::Backtrace::capture()); axhal::power::system_off() } diff --git a/modules/axruntime/src/lib.rs b/modules/axruntime/src/lib.rs index 8609d09e2b..2a74b029de 100644 --- a/modules/axruntime/src/lib.rs +++ b/modules/axruntime/src/lib.rs @@ -18,7 +18,7 @@ #![cfg_attr(not(test), no_std)] #![feature(doc_auto_cfg)] - +#![feature(linkage)] #[macro_use] extern crate axlog; @@ -122,7 +122,6 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { target = {} build_mode = {} log_level = {} - backtrace = {} smp = {} "}, axconfig::ARCH, @@ -130,7 +129,6 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { option_env!("AX_TARGET").unwrap_or(""), option_env!("AX_MODE").unwrap_or(""), option_env!("AX_LOG").unwrap_or(""), - axbacktrace::is_enabled(), axconfig::plat::CPU_NUM, ); #[cfg(feature = "rtc")] @@ -159,28 +157,6 @@ pub fn rust_main(cpu_id: usize, arg: usize) -> ! { #[cfg(feature = "alloc")] init_allocator(); - { - use core::ops::Range; - - unsafe extern "C" { - safe static _stext: [u8; 0]; - safe static _etext: [u8; 0]; - safe static _edata: [u8; 0]; - } - - let ip_range = Range { - start: _stext.as_ptr() as usize, - end: _etext.as_ptr() as usize, - }; - - let fp_range = Range { - start: _edata.as_ptr() as usize, - end: usize::MAX, - }; - - axbacktrace::init(ip_range, fp_range); - } - #[cfg(feature = "paging")] axmm::init_memory_management(); diff --git a/scripts/make/build.mk b/scripts/make/build.mk index 35334dee38..7a342cf165 100644 --- a/scripts/make/build.mk +++ b/scripts/make/build.mk @@ -33,8 +33,8 @@ else ifneq ($(filter $(or $(MAKECMDGOALS), $(.DEFAULT_GOAL)), all build run just $(if $(V), $(info CFLAGS: "$(CFLAGS)") $(info LDFLAGS: "$(LDFLAGS)")) else ifeq ($(APP_TYPE), rust) RUSTFLAGS += $(RUSTFLAGS_LINK_ARGS) - ifeq ($(BACKTRACE), y) - RUSTFLAGS += -C force-frame-pointers -C debuginfo=2 -C strip=none + ifneq ($(ARCH), loongarch64) + RUSTFLAGS += -Cforce-unwind-tables=yes -Cpanic=unwind -Clink-arg=--eh-frame-hdr endif ifeq ($(MYPLAT), axplat-loongarch64-2k1000la) RUSTFLAGS += -C target-feature=-ual @@ -56,9 +56,6 @@ ifeq ($(APP_TYPE), rust) else ifeq ($(APP_TYPE), c) $(call cargo_build,ulib/axlibc,$(AX_FEAT) $(LIB_FEAT)) endif -ifeq ($(BACKTRACE), y) - $(call run_cmd,./scripts/make/dwarf.sh,$(OUT_ELF) $(OBJCOPY)) -endif $(OUT_DIR): $(call run_cmd,mkdir,-p $@)