git: 5e9226f063bc - main - Fix build of stand/ when building world with ASAN
Alex Richardson
arichardson at FreeBSD.org
Mon Aug 2 13:35:09 UTC 2021
The branch main has been updated by arichardson:
URL: https://cgit.FreeBSD.org/src/commit/?id=5e9226f063bc43574e2168b4aafad8232f08002a
commit 5e9226f063bc43574e2168b4aafad8232f08002a
Author: Alex Richardson <arichardson at FreeBSD.org>
AuthorDate: 2021-08-02 08:50:16 +0000
Commit: Alex Richardson <arichardson at FreeBSD.org>
CommitDate: 2021-08-02 13:33:24 +0000
Fix build of stand/ when building world with ASAN
The userboot/test program links against the default userspace libraries
(e.g. shared libgcc_s.so) 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: https://reviews.freebsd.org/D31047
---
stand/defs.mk | 6 ++++++
stand/userboot/userboot/Makefile | 5 +++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/stand/defs.mk b/stand/defs.mk
index d50c89879613..02a03b92577e 100644
--- a/stand/defs.mk
+++ b/stand/defs.mk
@@ -24,6 +24,12 @@ INTERNALLIB=
# enough to make that hassle worth chasing.
_CPUCFLAGS=
+.if ${LDFLAGS:M-nostdlib}
+# Sanitizers won't work unless we link against libc (e.g. in userboot/test).
+MK_ASAN:= no
+MK_UBSAN:= no
+.endif
+
.include <src.opts.mk>
.include <bsd.linker.mk>
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
LOADER_EXT2FS_SUPPORT?= no
PIC=yes
+# Note: -nostdlib needs to be added to LDFLAGS before including defs.mk
+LDFLAGS+= -nostdlib -Wl,-Bsymbolic
+
.include <bsd.init.mk>
SHLIB_NAME= userboot_${LOADER_INTERP}.so
@@ -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
-
NEWVERSWHAT= "User boot ${LOADER_INTERP}" ${MACHINE_CPUARCH}
VERSION_FILE= ${.CURDIR}/../userboot/version
More information about the dev-commits-src-main
mailing list