Clang KASAN unsupported option '-fsanitize=kernel-address' for target 'x86_64-pc-none-elf'

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
songziming
Member
Member
Posts: 71
Joined: Fri Jun 28, 2013 1:48 am
Contact:

Clang KASAN unsupported option '-fsanitize=kernel-address' for target 'x86_64-pc-none-elf'

Post by songziming »

Hi,

I want to add KASAN to my kernel, the compiling command line is

Code: Select all

clang -DC_FILE -std=c11 -c -Ikernel_new -Ikernel_new/arch_x86_64 -ffunction-sections -fdata-sections -target x86_64-pc-none-elf -flto -Wall -Wextra -Wshadow -Werror=implicit -g -gdwarf-5 -DDEBUG -fstack-protector -fno-omit-frame-pointer -fsanitize=undefined -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -mno-fma -fsanitize=kernel-address -mllvm -asan-mapping-offset=0xdfffe00000000000 -mllvm -asan-globals=false -ffreestanding -fno-builtin -MT build/kernel_new/arch_x86_64/apic/apic_init.c.ko -MMD -MP -MF build/kernel_new/arch_x86_64/apic/apic_init.c.ko.d -o build/kernel_new/arch_x86_64/apic/apic_init.c.ko kernel_new/arch_x86_64/apic/apic_init.c
But I got an error:

Code: Select all

clang: error: unsupported option '-fsanitize=kernel-address' for target 'x86_64-pc-none-elf'
If I remove `-target x86_64-pc-none-elf`, kernel compiles without problem, but hangs during boot (page fault, im still working on it).

Is it safe to remove target triplet? What if I want to cross compile my kernel for another arch?

My kernel is 64-bit, the compiler clang is built from source using default settings.

Code: Select all

cmake ../llvm-project/llvm \
    -DCMAKE_INSTALL_PREFIX=/opt/llvm \
    -DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt" \
    -DLLVM_TARGETS_TO_BUILD=X86 \
    -DCMAKE_BUILD_TYPE=Release
Reinventing the Wheel, code: https://github.com/songziming/wheel
Post Reply