[PATCH v3] Add asan and ubsan support on NetBSD/amd64

Kamil Rytarowski n54@gmx.com
Thu Oct 26 20:05:00 GMT 2017


Tested on:

$ uname -rms
NetBSD 8.99.4 amd64

The NetBSD support has been developed directly in the compiler-rt upstream
source.

Testing against the LLVM+Clang+compiler-rt (2017-10-25 snapshot from HEAD):

$ make check-asan
Failing Tests (2):
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Test/AddressSanitizerInterface.ManyThreadsWithStatsStressTest
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Test/AddressSanitizerInterface.ManyThreadsWithStatsStressTest

  Expected Passes    : 436
  Unsupported Tests  : 822
  Unexpected Failures: 2

$ make check-asan-dynamic
Failing Tests (2):
    AddressSanitizer-Unit :: ./Asan-x86_64-calls-Dynamic-Test/AddressSanitizerInterface.ManyThreadsWithStatsStressTest
    AddressSanitizer-Unit :: ./Asan-x86_64-inline-Dynamic-Test/AddressSanitizerInterface.ManyThreadsWithStatsStressTest

  Expected Passes    : 372
  Unsupported Tests  : 822
  Unexpected Failures: 2

$ make check-ubsan
Failing Tests (44):
    UBSan-ASan-i386 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
    UBSan-ASan-x86_64 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
    UBSan-MSan-x86_64 :: TestCases/Float/cast-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/add-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/div-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/div-zero.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/incdec-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/mul-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/negate-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/no-recover.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/shift.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/sub-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/suppressions.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/uadd-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/uincdec-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/umul-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Integer/usub-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/bool.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/bounds.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/builtins.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/coverage-levels.cc
    UBSan-MSan-x86_64 :: TestCases/Misc/deduplication.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/enum.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/log-path_test.cc
    UBSan-MSan-x86_64 :: TestCases/Misc/missing_return.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/nonnull-arg.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/nonnull.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/nullability.c
    UBSan-MSan-x86_64 :: TestCases/Misc/unreachable.cpp
    UBSan-MSan-x86_64 :: TestCases/Misc/vla.c
    UBSan-MSan-x86_64 :: TestCases/Pointer/index-overflow.cpp
    UBSan-MSan-x86_64 :: TestCases/Pointer/unsigned-index-expression.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/Function/function.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/PR33221.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/misaligned.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/null.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/vptr-virtual-base-construction.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/vptr-virtual-base.cpp
    UBSan-MSan-x86_64 :: TestCases/TypeCheck/vptr.cpp
    UBSan-Standalone-i386 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
    UBSan-Standalone-x86_64 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp
    UBSan-TSan-x86_64 :: TestCases/TypeCheck/vptr-non-unique-typeinfo.cpp

  Expected Passes    : 187
  Expected Failures  : 1
  Unsupported Tests  : 26
  Unexpected Failures: 44

UBsan tests contain ASan, TSan and MSan tests; perhaps more of them.
TSan/NetBSD is work-in-progress.
MSan/NetBSD is in early development on NetBSD.
vptr-non-unique-typeinfo.cpp failures are caused by environment issue in the
test-suite, as the NetBSD loader does not support reliably $ORIGIN.

The GCC patch has been tested in the context of pkgsrc in
pkgsrc-wip/gcc8snapshot (upstream snapshot 20171022).

$ uname -rms
NetBSD 8.99.4 amd64
$ cat u.c
int main(int argc, char **argv) {
  int k = 0x7fffffff;
  k += argc;
  return 0;
}
$ /usr/pkg/gcc8snapshot/bin/gcc -fsanitize=undefined u.c -o u
$ ./u
u.c:3:5: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
chieftec$ cat a.c
int main(int argc, char **argv)
{
        char a[10];
        argv[argc + 10] = 0;
        return 0;
}
$ /usr/pkg/gcc8snapshot/bin/gcc -fsanitize=address a.c -o a
$ ./a
AddressSanitizer:DEADLYSIGNAL
=================================================================
==20441==ERROR: AddressSanitizer: SEGV on unknown address 0x0ff07fff7cf0 (pc 0x000000400a8f bp 0x7f7fffffe7f0 sp 0x7f7fffffe770 T0)
==20441==The signal is caused by a WRITE memory access.
    #0 0x400a8e in main (/tmp/a+0x400a8e)
    #1 0x40090a in ___start (/tmp/a+0x40090a)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/tmp/a+0x400a8e) in main
==20441==ABORTING

There is lack of additional info in asan when used with .so. This bug is not
a show-stopper because a user still can get backtrace under debugger in the
point of detected failure. This bug will be fixed in upstream LLVM sources
and merged back to GCC in future merges from LLVM.

2017-10-26  Kamil Rytarowski  <n54@gmx.com>

	* sanitizer_common/Makefile.am (sanitizer_common_files): Add
	sanitizer_platform_limits_netbsd.cc.
	* sanitizer_common/Makefile.in: Regenerated.
	* configure.tgt: Enable asan and ubsan on x86_64-*-netbsd*.
---
 libsanitizer/ChangeLog                    | 7 +++++++
 libsanitizer/configure.tgt                | 4 ++++
 libsanitizer/sanitizer_common/Makefile.am | 2 +-
 libsanitizer/sanitizer_common/Makefile.in | 5 ++++-
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog
index 63e71317cbf..097230ac5cf 100644
--- a/libsanitizer/ChangeLog
+++ b/libsanitizer/ChangeLog
@@ -1,3 +1,10 @@
+2017-10-26  Kamil Rytarowski  <n54@gmx.com>
+
+	* sanitizer_common/Makefile.am (sanitizer_common_files): Add
+	sanitizer_platform_limits_netbsd.cc.
+	* sanitizer_common/Makefile.in: Regenerated.
+	* configure.tgt: Enable asan and ubsan on x86_64-*-netbsd*.
+
 2017-10-20  Jakub Jelinek  <jakub@redhat.com>
 
 	PR sanitizer/82595
diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index 573e3b482e9..4c1f8e0bb27 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -55,6 +55,10 @@ case "${target}" in
   x86_64-*-darwin[1]* | i?86-*-darwin[1]*)
 	TSAN_SUPPORTED=no
 	;;
+  x86_64-*-netbsd*)
+	TSAN_SUPPORTED=no
+	LSAN_SUPPORTED=no
+	;;
   *)
 	UNSUPPORTED=1
 	;;
diff --git a/libsanitizer/sanitizer_common/Makefile.am b/libsanitizer/sanitizer_common/Makefile.am
index adaab4cee54..70563eded36 100644
--- a/libsanitizer/sanitizer_common/Makefile.am
+++ b/libsanitizer/sanitizer_common/Makefile.am
@@ -41,6 +41,7 @@ sanitizer_common_files = \
 	sanitizer_persistent_allocator.cc \
 	sanitizer_platform_limits_linux.cc \
 	sanitizer_platform_limits_posix.cc \
+	sanitizer_platform_limits_netbsd.cc \
 	sanitizer_posix.cc \
 	sanitizer_posix_libcdep.cc \
 	sanitizer_printf.cc \
@@ -114,4 +115,3 @@ AM_MAKEFLAGS = \
 MAKEOVERRIDES=
 
 ## ################################################################
-
diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in
index b2acc5caf56..f05c181f0b1 100644
--- a/libsanitizer/sanitizer_common/Makefile.in
+++ b/libsanitizer/sanitizer_common/Makefile.in
@@ -91,7 +91,8 @@ am__objects_1 = sancov_flags.lo sanitizer_allocator.lo \
 	sanitizer_mac.lo sanitizer_mac_libcdep.lo \
 	sanitizer_persistent_allocator.lo \
 	sanitizer_platform_limits_linux.lo \
-	sanitizer_platform_limits_posix.lo sanitizer_posix.lo \
+	sanitizer_platform_limits_posix.lo \
+	sanitizer_platform_limits_netbsd.lo sanitizer_posix.lo \
 	sanitizer_posix_libcdep.lo sanitizer_printf.lo \
 	sanitizer_procmaps_common.lo sanitizer_procmaps_freebsd.lo \
 	sanitizer_procmaps_linux.lo sanitizer_procmaps_mac.lo \
@@ -323,6 +324,7 @@ sanitizer_common_files = \
 	sanitizer_persistent_allocator.cc \
 	sanitizer_platform_limits_linux.cc \
 	sanitizer_platform_limits_posix.cc \
+	sanitizer_platform_limits_netbsd.cc \
 	sanitizer_posix.cc \
 	sanitizer_posix_libcdep.cc \
 	sanitizer_printf.cc \
@@ -468,6 +470,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_mac_libcdep.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_persistent_allocator.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_linux.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_netbsd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_platform_limits_posix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_posix.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sanitizer_posix_libcdep.Plo@am__quote@
-- 
2.14.2



More information about the Gcc-patches mailing list