Refactor MKSANITIZER flags in mk rules

Introduce a new variable SANITIZERFLAGS that contains all the sanitizer
specific flags. These flags are designed to be passed to CFLAGS, CXXFLAGS
and LDFLAGS.

Pass SANITIZERFLAGS in bsd.prog.mk rules to CFLAGS, CXXFLAGS and LDFLAGS.

Pass SANITIZERFLAGS in bsd.lib.mk rules to *_pic.a build flags. The *_pic.a
libraries are designed to construct .so libraries. All .so libraries with
few exceptions are expected to be prebuilt with a sanitizer. Another
purpuse of *_pic.a files can be constructing static PIE programs, however
they are not supported as of now and there is no sanitization of static
programs either.

Once MKSTATICPIE will be supported, it will be initially incompatible with
MKSANITIZER.

This change also makes it easier to build other targets like kernel and
kernel modules without userland sanitizers.

No functional change intended for MKSANITIZER=no users.
This commit is contained in:
kamil 2018-06-21 11:24:38 +00:00
parent 69ca0c2f24
commit 64a497de12
3 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.lib.mk,v 1.374 2018/06/05 15:37:52 christos Exp $
# $NetBSD: bsd.lib.mk,v 1.375 2018/06/21 11:24:38 kamil Exp $
# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
.include <bsd.init.mk>
@ -149,7 +149,7 @@ SHLIB_FULLVERSION=${SHLIB_MAJOR}
PICFLAGS ?= -fPIC
.if ${MKPICLIB} != "no"
CSHLIBFLAGS+= ${PICFLAGS}
CSHLIBFLAGS+= ${PICFLAGS} ${SANITIZERFLAGS}
.endif
.if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
@ -171,6 +171,7 @@ CFLAGS+= -g
# Platform-independent linker flags for ELF shared libraries
SHLIB_SOVERSION= ${SHLIB_MAJOR}
SHLIB_SHFLAGS= -Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
SHLIB_SHFLAGS+= ${SANITIZERFLAGS}
.if !defined(SHLIB_WARNTEXTREL) || ${SHLIB_WARNTEXTREL} != "no"
SHLIB_SHFLAGS+= -Wl,--warn-shared-textrel
.endif

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.prog.mk,v 1.313 2018/06/02 15:19:45 christos Exp $
# $NetBSD: bsd.prog.mk,v 1.314 2018/06/21 11:24:38 kamil Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.ifndef HOSTPROG
@ -7,6 +7,12 @@
.include <bsd.shlib.mk>
.include <bsd.gcc.mk>
##### Sanitizer specific flags.
CFLAGS+= ${SANITIZERFLAGS}
CXXFLAGS+= ${SANITIZERFLAGS}
LDFLAGS+= ${SANITIZERFLAGS}
#
# Definitions and targets shared among all programs built by a single
# Makefile.

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.sys.mk,v 1.282 2018/06/17 23:37:22 christos Exp $
# $NetBSD: bsd.sys.mk,v 1.283 2018/06/21 11:24:38 kamil Exp $
#
# Build definitions used for NetBSD source tree builds.
@ -141,9 +141,9 @@ LDFLAGS+= -Wl,-z,now
.endif
.if ${MKSANITIZER:Uno} == "yes"
CFLAGS+= -fsanitize=${USE_SANITIZER}
CXXFLAGS+= -fsanitize=${USE_SANITIZER}
LDFLAGS+= -fsanitize=${USE_SANITIZER}
SANITIZERFLAGS+= -fsanitize=${USE_SANITIZER}
.else
SANITIZERFLAGS+= # empty
.endif