mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-24 13:13:24 +00:00
patch add mini backtrace (#416)
* support rust panic backtrace mini-backtrace has llvm's unwind cpp source to support backtrace/unwind. as unwind/backtrace needs dynamically allocates memory, mini-backtrace uses stack memory to capture fixed number of backtrace to avoid heap allocation. as unwind library needed, it needs to turn on eh_frame_hdr * 修改忘了生成kernel.elf的问题 * 设置backtrace是默认的feature --------- Co-authored-by: Yao Zhao <dragonlinux@gmail.com>
This commit is contained in:
@ -10,7 +10,19 @@ LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
|
||||
|
||||
# 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
|
||||
PIC := _INTR_APIC_
|
||||
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie -D $(PIC) -I $(shell pwd) -I $(shell pwd)/include -I $(shell pwd)/arch/x86_64/include
|
||||
|
||||
# unwind/backtrace related
|
||||
UNWIND_ENABLE ?= yes
|
||||
CFLAGS_UNWIND =
|
||||
LDFLAGS_UNWIND =
|
||||
RUSTFLAGS_UNWIND =
|
||||
ifeq ($(UNWIND_ENABLE), yes)
|
||||
CFLAGS_UNWIND = -funwind-tables
|
||||
LDFLAGS_UNWIND = --eh-frame-hdr
|
||||
RUSTFLAGS_UNWIND = -Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld
|
||||
endif
|
||||
|
||||
CFLAGS = $(GLOBAL_CFLAGS) -fno-pie $(CFLAGS_UNWIND) -D $(PIC) -I $(shell pwd) -I $(shell pwd)/include -I $(shell pwd)/arch/x86_64/include
|
||||
|
||||
export ASFLAGS := --64
|
||||
|
||||
@ -32,12 +44,12 @@ main.o: main.c
|
||||
|
||||
kernel_rust:
|
||||
rustup default nightly
|
||||
cargo +nightly-2023-01-21 build --release --target ./arch/x86_64/x86_64-unknown-none.json
|
||||
|
||||
RUSTFLAGS="$(RUSTFLAGS_UNWIND)" cargo +nightly-2023-01-21 build --release --target ./arch/x86_64/x86_64-unknown-none.json
|
||||
all: kernel
|
||||
|
||||
@echo "Linking kernel..."
|
||||
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds --no-relax
|
||||
# 生成kallsyms
|
||||
current_dir=$(pwd)
|
||||
|
||||
@ -51,11 +63,14 @@ all: kernel
|
||||
# 重新链接
|
||||
@echo "Re-Linking kernel..."
|
||||
@echo $(shell find . -name "*.o")
|
||||
$(LD) -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds --no-relax
|
||||
$(LD) -b elf64-x86-64 -z muldefs $(LDFLAGS_UNWIND) -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a ./debug/kallsyms.o -T link.lds --no-relax
|
||||
@echo "Generating kernel ELF file..."
|
||||
# 生成内核文件
|
||||
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 kernel ../../bin/kernel/kernel.elf
|
||||
# $(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
||||
ifeq ($(UNWIND_ENABLE), yes)
|
||||
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 kernel ../../bin/kernel/kernel.elf
|
||||
else
|
||||
$(OBJCOPY) -I elf64-x86-64 -O elf64-x86-64 -R ".eh_frame" kernel ../../bin/kernel/kernel.elf
|
||||
endif
|
||||
@echo "Kernel Build Done."
|
||||
|
||||
ECHO:
|
||||
@ -76,4 +91,4 @@ clean:
|
||||
echo "Clean in dir: $$subdir";\
|
||||
cd $$subdir && $(MAKE) clean;\
|
||||
cd .. ;\
|
||||
done
|
||||
done
|
||||
|
Reference in New Issue
Block a user