From 5e9226f063bc43574e2168b4aafad8232f08002a Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 2 Aug 2021 09:50:16 +0100 Subject: [PATCH] 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 .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 LOADER_EXT2FS_SUPPORT?= no PIC=yes +# Note: -nostdlib needs to be added to LDFLAGS before including defs.mk +LDFLAGS+= -nostdlib -Wl,-Bsymbolic + .include 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