Skip to content

Commit

Permalink
sys/conf: Support building kasan with gcc on arm64
Browse files Browse the repository at this point in the history
 - Remove -mllvm flags that don't exist in gcc
 - Set the shadow offset with -fasan-shadow-offset
 - Remove this when kasan is disabled as it's an error to use this
   when not building for kasan under gcc

This allows the arm64 GENERIC-KASAN kernel to build with gcc13.

Reviewed by:	brooks
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45300
  • Loading branch information
zxombie committed Oct 1, 2024
1 parent 2bc08f2 commit 9838caf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sys/conf/kern.pre.mk
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ COMPAT_FREEBSD32_ENABLED!= grep COMPAT_FREEBSD32 opt_global.h || true ; echo
KASAN_ENABLED!= grep KASAN opt_global.h || true ; echo
.if !empty(KASAN_ENABLED)
SAN_CFLAGS+= -DSAN_NEEDS_INTERCEPTORS -DSAN_INTERCEPTOR_PREFIX=kasan \
-fsanitize=kernel-address \
-mllvm -asan-stack=true \
-fsanitize=kernel-address
.if ${COMPILER_TYPE} == "clang"
SAN_CFLAGS+= -mllvm -asan-stack=true \
-mllvm -asan-instrument-dynamic-allocas=true \
-mllvm -asan-globals=true \
-mllvm -asan-use-after-scope=true \
-mllvm -asan-instrumentation-with-call-threshold=0 \
-mllvm -asan-instrument-byval=false
.endif

.if ${MACHINE_CPUARCH} == "aarch64"
# KASAN/ARM64 TODO: -asan-mapping-offset is calculated from:
Expand All @@ -111,7 +113,11 @@ SAN_CFLAGS+= -DSAN_NEEDS_INTERCEPTORS -DSAN_INTERCEPTOR_PREFIX=kasan \
# KASAN_MIN_ADDRESS, and this offset value should eventually be
# upstreamed similar to: https://reviews.llvm.org/D98285
#
.if ${COMPILER_TYPE} == "clang"
SAN_CFLAGS+= -mllvm -asan-mapping-offset=0xdfff208000000000
.else
SAN_CFLAGS+= -fasan-shadow-offset=0xdfff208000000000
.endif
.elif ${MACHINE_CPUARCH} == "amd64" && \
${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000
# Work around https://github.com/llvm/llvm-project/issues/87923, which leads to
Expand Down

0 comments on commit 9838caf

Please sign in to comment.