git: 4f2e5793d753 - stable/13 - Fix build of stand/ when building world with ASAN

From: Warner Losh <>
Date: Tue, 24 Jan 2023 22:09:52 UTC
The branch stable/13 has been updated by imp:


commit 4f2e5793d753cdd2e5625fc292a9d8e1ab4dfa39
Author:     Alex Richardson <>
AuthorDate: 2021-08-02 08:50:16 +0000
Commit:     Warner Losh <>
CommitDate: 2023-01-24 21:49:17 +0000

    Fix build of stand/ when building world with ASAN
    The userboot/test  program links against the default userspace libraries
    (e.g. shared that will be instrumented if WITH_ASAN is set.
    All other programs link against libsa instead of libc and therefore can't
    use the sanitizer runtime library. To fix the stand/ build with
    sanitizers, we disable MK_ASAN/MK_UBSAN if -nostdlib is found in the
    LDFLAGS (i.e. we are using libsa instead of libc).
    Reviewed By:    imp, tsoome
    Differential Revision:
    (cherry picked from commit 5e9226f063bc43574e2168b4aafad8232f08002a)
 stand/                    | 6 ++++++
 stand/userboot/userboot/Makefile | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/stand/ b/stand/
index bbebf270c7ef..765fd046a879 100644
--- a/stand/
+++ b/stand/
@@ -25,6 +25,12 @@ INTERNALLIB=
 # enough to make that hassle worth chasing.
+.if ${LDFLAGS:M-nostdlib}
+# Sanitizers won't work unless we link against libc (e.g. in userboot/test).
+MK_ASAN:=	no
+MK_UBSAN:=	no
 .include <>
 .include <>
diff --git a/stand/userboot/userboot/Makefile b/stand/userboot/userboot/Makefile
index 767840101200..60fcf57d9697 100644
--- a/stand/userboot/userboot/Makefile
+++ b/stand/userboot/userboot/Makefile
@@ -6,6 +6,9 @@ LOADER_CD9660_SUPPORT?=	no
+# Note: -nostdlib needs to be added to LDFLAGS before including
+LDFLAGS+=	-nostdlib -Wl,-Bsymbolic
 .include <>
@@ -39,8 +42,6 @@ CFLAGS.main.c+=	-I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs
 CFLAGS.gfx_fb.c+= -I$(SRCTOP)/sys/teken -I${SRCTOP}/contrib/pnglite
 CWARNFLAGS.main.c += -Wno-implicit-function-declaration
-LDFLAGS+=	-nostdlib -Wl,-Bsymbolic
 VERSION_FILE=	${.CURDIR}/../userboot/version