Page MenuHomeFreeBSD

mk: Add compiler features for asan and msan
Needs ReviewPublic

Authored by des on Jun 25 2025, 8:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 23, 10:11 PM
Unknown Object (File)
Sat, Sep 20, 4:02 PM
Unknown Object (File)
Tue, Sep 16, 5:18 PM
Unknown Object (File)
Sat, Sep 13, 4:18 PM
Unknown Object (File)
Fri, Sep 12, 9:24 AM
Unknown Object (File)
Thu, Sep 11, 8:29 AM
Unknown Object (File)
Sun, Sep 7, 10:57 PM
Unknown Object (File)
Sat, Sep 6, 12:09 PM

Details

Reviewers
jhb
Group Reviewers
Klara
Summary

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65086
Build 61969: arc lint + arc unit

Event Timeline

des requested review of this revision.Jun 25 2025, 8:09 PM
share/mk/bsd.compiler.mk
302

I think this catches powerpc64, not just the 32-bit powerpc architectures, but powerpc64 does have ASAN.

306

This also blocks msan on powerpc64 incorrectly. It needs to also be disabled for riscv64 which does not have msan support.

share/mk/bsd.compiler.mk
301–304

Might be easier to spell this as opt-in rather than opt-out. I think this is also correct now (aarch64, amd64, powerpc64, powerpc64le, riscv64, and i386 all support ASAN).

306–310
share/mk/bsd.compiler.mk
302

No, I'd have to use :Mpowerpc* to catch both.

I've had a chance to test this while cross-building an aarch64 world and the build failed because it tries to look for the aarch64 address sanitizer library on the host instead of in the object tree:

cc -target aarch64-unknown-freebsd15.0 --sysroot=/usr/obj/usr/src/arm64.aarch64/tmp -B/usr/obj/usr/src/arm64.aarch64/tmp/usr/bin -O2 -pipe -fno-common -DTEST_LONG_DOUBLE -D__HAVE_LONG_DOUBLE -I/usr/src/lib/libc/tests/gen -fPIE -g -gz=zlib -std=gnu17 -Wno-format-zero-length -fstack-protector-strong -Wsystem-headers -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign -Wdate-time -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-error=unused-but-set-parameter -Wno-error=cast-function-type-mismatch -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Qunused-arguments  -fsanitize=address -Wl,-zrelro -pie   -o realpath2_test.full realpath2_test.pieo  -lprivateatf-c
ld: error: cannot open /usr/lib/clang/19/lib/aarch64-unknown-freebsd15.0/libclang_rt.asan_static.a: No such file or directory
ld: error: cannot open /usr/lib/clang/19/lib/aarch64-unknown-freebsd15.0/libclang_rt.asan.a: No such file or directory
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.

The library does exist (with a different name and in a different location) in the cross-toolchain:

% find /usr/obj/usr/src/arm64.aarch64/tmp -name '*asan*.a'
/usr/obj/usr/src/arm64.aarch64/tmp/usr/lib/clang/19/lib/freebsd/libclang_rt.asan-preinit-aarch64.a
/usr/obj/usr/src/arm64.aarch64/tmp/usr/lib/clang/19/lib/freebsd/libclang_rt.asan_cxx-aarch64.a
/usr/obj/usr/src/arm64.aarch64/tmp/usr/lib/clang/19/lib/freebsd/libclang_rt.asan-aarch64.a
/usr/obj/usr/src/arm64.aarch64/tmp/usr/lib/clang/19/lib/freebsd/libclang_rt.asan_static-aarch64.a
des retitled this revision from mk: Add compiler features for asan and msan. to mk: Add compiler features for asan and msan.Aug 2 2025, 1:52 PM

For the cross-build error, it seems like clang isn't honoring --sysroot when looking for the libraries. This can be correct in some cases (it would be correct for the LLVM port cross-building a binary as the port should use the sanitizer libs shipped as part of the port). We may want a local patch for the version of LLVM in the base system to honor --sysroot for the sanitizer runtimes though. Perhaps @dim has thoughts?

share/mk/bsd.compiler.mk
302

Hmm, then the check for 32-bit arm is wrong (MACHINE_ARCH is armv7). Probably want to test MACHINE_CPUARCH instead for arm. For powerpc you need to also omit powerpcspe, not just plain "powerpc".