Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Enhance the support of LLVM sanitizers



details:   https://anonhg.NetBSD.org/src/rev/4b5548940c81
branches:  trunk
changeset: 459158:4b5548940c81
user:      kamil <kamil%NetBSD.org@localhost>
date:      Tue Aug 27 22:48:53 2019 +0000

description:
Enhance the support of LLVM sanitizers

Define _REENTRANT for MKSANITIZER build. This is needed for at least stdio
code. This caused new build issued with duplicated symbols in few places
and rump kernel code picking different code paths borrowed from libc.
Handle all this in one go.

Add bsd.sanitizer.mk to share common code used by programs and libraries.

Switch from realall to beforeinstall target in .syms files. This is more
reliable in MKSANITIZER.

diffstat:

 Makefile                                                                        |   4 +-
 common/lib/libc/gmon/mcount.c                                                   |   8 +-
 distrib/sets/lists/base/mi                                                      |   3 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/asan-m64/Makefile                 |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/asan_cxx-m64/Makefile             |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/msan-m64/Makefile                 |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/msan_cxx-m64/Makefile             |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan-m64/Makefile                 |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan_cxx-m64/Makefile             |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_minimal-m64/Makefile        |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone-m64/Makefile     |   4 +-
 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone_cxx-m64/Makefile |   4 +-
 external/bsd/fetch/lib/Makefile                                                 |   6 +-
 external/gpl2/lvm2/lvm2tools.mk                                                 |   6 +-
 lib/libc/gen/sysctlgetmibinfo.c                                                 |  12 ++--
 share/mk/Makefile                                                               |   5 +-
 share/mk/bsd.lib.mk                                                             |  10 +--
 share/mk/bsd.prog.mk                                                            |  20 +------
 share/mk/bsd.sanitizer.mk                                                       |  27 ++++++++++
 tests/lib/libc/net/Makefile                                                     |   6 +-
 20 files changed, 81 insertions(+), 62 deletions(-)

diffs (truncated from 446 to 300 lines):

diff -r 86b878ef68b7 -r 4b5548940c81 Makefile
--- a/Makefile  Tue Aug 27 21:11:26 2019 +0000
+++ b/Makefile  Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.330 2019/08/26 04:49:45 kamil Exp $
+#      $NetBSD: Makefile,v 1.331 2019/08/27 22:48:54 kamil Exp $
 
 #
 # This is the top-level makefile for building NetBSD. For an outline of
@@ -481,7 +481,7 @@
        ${MAKEDIRTARGET} compat build_install BOOTSTRAP_SUBDIRS="../../../lib"
 
 do-sanitizer: .PHONY .MAKE
-       ${MAKEDIRTARGET} external/bsd/compiler_rt all
+       ${MAKEDIRTARGET} external/bsd/compiler_rt build_install
 
 do-sanitizer-tools: .PHONY .MAKE
 .if !exists(${TOOLDIR}/lib/clang) && ${HAVE_LLVM:Uno} == "yes"
diff -r 86b878ef68b7 -r 4b5548940c81 common/lib/libc/gmon/mcount.c
--- a/common/lib/libc/gmon/mcount.c     Tue Aug 27 21:11:26 2019 +0000
+++ b/common/lib/libc/gmon/mcount.c     Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mcount.c,v 1.13 2016/02/28 02:56:39 christos Exp $     */
+/*     $NetBSD: mcount.c,v 1.14 2019/08/27 22:48:53 kamil Exp $        */
 
 /*
  * Copyright (c) 2003, 2004 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)mcount.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: mcount.c,v 1.13 2016/02/28 02:56:39 christos Exp $");
+__RCSID("$NetBSD: mcount.c,v 1.14 2019/08/27 22:48:53 kamil Exp $");
 #endif
 #endif
 
@@ -88,7 +88,7 @@
 #include "reentrant.h"
 #endif
 
-#ifdef _REENTRANT
+#if defined(_REENTRANT) && !defined(_RUMPKERNEL)
 extern thread_key_t _gmonkey;
 extern struct gmonparam _gmondummy;
 struct gmonparam *_m_gmon_alloc(void);
@@ -143,7 +143,7 @@
        int s;
 #endif
 
-#if defined(_REENTRANT) && !defined(_KERNEL)
+#if defined(_REENTRANT) && !defined(_KERNEL) && !defined(_RUMPKERNEL)
        if (__isthreaded) {
                /* prevent re-entry via thr_getspecific */
                if (_gmonparam.state != GMON_PROF_ON)
diff -r 86b878ef68b7 -r 4b5548940c81 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Tue Aug 27 21:11:26 2019 +0000
+++ b/distrib/sets/lists/base/mi        Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1212 2019/08/27 12:45:04 msaitoh Exp $
+# $NetBSD: mi,v 1.1213 2019/08/27 22:48:54 kamil Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -4907,6 +4907,7 @@
 ./usr/share/mk/bsd.port.subdir.mk              base-obsolete           obsolete
 ./usr/share/mk/bsd.prog.mk                     base-mk-share           share
 ./usr/share/mk/bsd.rpc.mk                      base-mk-share           share
+./usr/share/mk/bsd.sanitizer.mk                        base-mk-share           share
 ./usr/share/mk/bsd.shlib.mk                    base-mk-share           share
 ./usr/share/mk/bsd.subdir.mk                   base-mk-share           share
 ./usr/share/mk/bsd.sys.mk                      base-mk-share           share
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/asan-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/asan-m64/Makefile   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/asan-m64/Makefile   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:45 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:54 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -56,7 +56,7 @@
 
 SYMS=          libclang_rt.asan-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/asan_cxx-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/asan_cxx-m64/Makefile       Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/asan_cxx-m64/Makefile       Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:54 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -39,7 +39,7 @@
 
 SYMS=  libclang_rt.asan_cxx-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/msan-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/msan-m64/Makefile   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/msan-m64/Makefile   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:54 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -51,7 +51,7 @@
 
 SYMS=          libclang_rt.msan-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/msan_cxx-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/msan_cxx-m64/Makefile       Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/msan_cxx-m64/Makefile       Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:54 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -40,7 +40,7 @@
 
 SYMS=          libclang_rt.msan_cxx-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan-m64/Makefile   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan-m64/Makefile   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:54 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -51,7 +51,7 @@
 
 SYMS=          libclang_rt.tsan-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan_cxx-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan_cxx-m64/Makefile       Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/tsan_cxx-m64/Makefile       Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:55 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -39,7 +39,7 @@
 
 SYMS=          libclang_rt.tsan_cxx-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_minimal-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_minimal-m64/Makefile  Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_minimal-m64/Makefile  Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:55 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -35,7 +35,7 @@
 
 SYMS=          libclang_rt.ubsan_minimal-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone-m64/Makefile       Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone-m64/Makefile       Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:55 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -49,7 +49,7 @@
 
 SYMS=          libclang_rt.ubsan_standalone-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone_cxx-m64/Makefile
--- a/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone_cxx-m64/Makefile   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/compiler_rt/lib/clang/lib/netbsd/ubsan_standalone_cxx-m64/Makefile   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2019/08/26 04:49:46 kamil Exp $
+#      $NetBSD: Makefile,v 1.3 2019/08/27 22:48:55 kamil Exp $
 
 NOSANITIZER=    # defined
 
@@ -35,7 +35,7 @@
 
 SYMS=          libclang_rt.ubsan_standalone_cxx-x86_64.a.syms
 
-realall: ${SYMS}
+beforeinstall: ${SYMS}
 
 CLEANFILES+=   ${SYMS}
 FILES=         ${SYMS}
diff -r 86b878ef68b7 -r 4b5548940c81 external/bsd/fetch/lib/Makefile
--- a/external/bsd/fetch/lib/Makefile   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/bsd/fetch/lib/Makefile   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.11 2018/02/04 03:19:52 christos Exp $
+# $NetBSD: Makefile,v 1.12 2019/08/27 22:48:53 kamil Exp $
 
 LIB=           fetch
 SRCS=          fetch.c common.c ftp.c http.c file.c
@@ -32,4 +32,8 @@
        ${HOST_SH} ${LIBFETCHDIR}/errlist.sh http_errlist HTTP \
            ${LIBFETCHDIR}/http.errors > ${.TARGET}
 
+.if ${MKSANITIZER:Uno} == "yes"
+CFLAGS+=       -Wno-macro-redefined # _REENTRANT redefined
+.endif
+
 .include <bsd.lib.mk>
diff -r 86b878ef68b7 -r 4b5548940c81 external/gpl2/lvm2/lvm2tools.mk
--- a/external/gpl2/lvm2/lvm2tools.mk   Tue Aug 27 21:11:26 2019 +0000
+++ b/external/gpl2/lvm2/lvm2tools.mk   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: lvm2tools.mk,v 1.4 2011/03/04 22:48:29 matt Exp $
+#      $NetBSD: lvm2tools.mk,v 1.5 2019/08/27 22:48:53 kamil Exp $
 
 .include <bsd.own.mk>
 
@@ -24,3 +24,7 @@
 #.endif
 #
 #LVM2.liblvm=  ${LVM2OBJDIR.liblvm}/liblvm.a
+
+.if ${MKSANITIZER:Uno} == "yes"
+CFLAGS+=       -Wno-macro-redefined # _REENTRANT redefined in lib.h
+.endif
diff -r 86b878ef68b7 -r 4b5548940c81 lib/libc/gen/sysctlgetmibinfo.c
--- a/lib/libc/gen/sysctlgetmibinfo.c   Tue Aug 27 21:11:26 2019 +0000
+++ b/lib/libc/gen/sysctlgetmibinfo.c   Tue Aug 27 22:48:53 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctlgetmibinfo.c,v 1.13 2016/09/30 06:22:21 dholland Exp $ */
+/*     $NetBSD: sysctlgetmibinfo.c,v 1.14 2019/08/27 22:48:53 kamil Exp $ */
 
 /*-
  * Copyright (c) 2003,2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.13 2016/09/30 06:22:21 dholland Exp $");
+__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.14 2019/08/27 22:48:53 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -386,16 +386,16 @@
  * the mib while parsing, and you should try again.  in the case of an
  * invalid node name, cname will be set to contain the offending name.
  */
-#ifdef _REENTRANT
+#if defined(_REENTRANT) && !defined(RUMP_ACTION)
 static mutex_t sysctl_mutex = MUTEX_INITIALIZER;
 static int sysctlgetmibinfo_unlocked(const char *, int *, u_int *, char *,
                                     size_t *, struct sysctlnode **, int);
-#endif /* __REENTRANT */
+#endif /* __REENTRANT && !RUMP_ACTION */
 
 int
 sysctlgetmibinfo(const char *gname, int *iname, u_int *namelenp,



Home | Main Index | Thread Index | Old Index