[compiler-rt] r322635 - [Sanitizers, test] Fix sanitizer tests on Solaris (PR 33274)

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 04:26:04 PST 2018


Author: kamil
Date: Wed Jan 17 04:26:04 2018
New Revision: 322635

URL: http://llvm.org/viewvc/llvm-project?rev=322635&view=rev
Log:
[Sanitizers, test] Fix sanitizer tests on Solaris (PR 33274)

Summary:
This patch (on top of the previous two (https://reviews.llvm.org/D40898 and
https://reviews.llvm.org/D40899) complete the compiler-rt side of the the Solaris
sanitizer port.

It contains the following sets of changes:

* For the time being, the port is for 32-bit x86 only, so reject the various tests on
  x86_64.

* When compiling as C++, <setjmp.h> resp. <iso/setjmp_iso.h> only declares
  _setjmp and _longjmp inside namespace std.

* MAP_FILE is a Windows feature.  While e.g. Linux <sys/mman.h> provides a
  no-op compat define, Solaris does not.

* test/asan/TestCases/Posix/coverage.cc was initially failing like this:

/vol/gcc/src/llvm/llvm/local/projects/compiler-rt/lib/sanitizer_common/scripts/sancov.py: 4 files merged; 2 PCs total
rm: cannot remove '/var/gcc/llvm/local/projects/compiler-rt/test/asan/I386SunOSConfig/TestCases/Posix/Output/coverage': Invalid argument

  Further digging revealed that the rm was trying to remove the running test's working
  directory which failed as observed.  cd'ing out of the dir before let the test pass.

* Two tests needed a declaration of alloca. I've now copied the existing code from
  test/asan/TestCases/alloca_constant_size.cc, but it may be more profitable and
  maintainable to have a common testsuite header where such code is collected.

* Similarly, Solaris' printf %p format doesn't include the leading 0x.

* In test/asan/TestCases/malloc-no-intercept.c, I had to undef __EXTENSIONS__
  (predefined by clang for no apparent reason) to avoid conflicting declarations
  for memalign.

* test/ubsan/TestCases/Float/cast-overflow.cpp has different platform dependent
  ways to define BYTE_ORDER and friends.  Why not just use __BYTE_ORDER__ and
  friends as predefined by clang and gcc?

Patch by Rainer Orth.

Reviewers: kcc, alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, kubamracek, mgorny, krytarowski, fedor.sergeev, JDevlieghere, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D40900

Modified:
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/asan/tests/asan_test.cc
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_utils.h
    compiler-rt/trunk/test/asan/CMakeLists.txt
    compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp
    compiler-rt/trunk/test/asan/TestCases/Posix/coverage.cc
    compiler-rt/trunk/test/asan/TestCases/Posix/ioctl.cc
    compiler-rt/trunk/test/asan/TestCases/alloca_constant_size.cc
    compiler-rt/trunk/test/asan/TestCases/alloca_loop_unpoisoning.cc
    compiler-rt/trunk/test/asan/TestCases/alloca_vla_interact.cc
    compiler-rt/trunk/test/asan/TestCases/debug_double_free.cc
    compiler-rt/trunk/test/asan/TestCases/debug_report.cc
    compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c
    compiler-rt/trunk/test/asan/lit.cfg
    compiler-rt/trunk/test/lit.common.cfg
    compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp
    compiler-rt/trunk/test/ubsan/lit.common.cfg
    compiler-rt/trunk/test/ubsan_minimal/CMakeLists.txt

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Wed Jan 17 04:26:04 2018
@@ -237,6 +237,9 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT
   if(APPLE)
     darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
   endif()
+  if(OS_NAME MATCHES "SunOS")
+    list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
+  endif()
 
   foreach(arch ${ASAN_TEST_ARCH})
 

Modified: compiler-rt/trunk/lib/asan/tests/asan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc Wed Jan 17 04:26:04 2018
@@ -25,6 +25,11 @@
 #endif
 #endif
 
+#if defined(__sun__) && defined(__svr4__)
+using std::_setjmp;
+using std::_longjmp;
+#endif
+
 NOINLINE void *malloc_fff(size_t size) {
   void *res = malloc/**/(size); break_optimization(0); return res;}
 NOINLINE void *malloc_eee(size_t size) {

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_utils.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_utils.h?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_utils.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_test_utils.h Wed Jan 17 04:26:04 2018
@@ -104,10 +104,16 @@ static inline uint32_t my_rand() {
 #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__ANDROID__) && \
     !defined(__NetBSD__) && !defined(_WIN32)
 # define SANITIZER_TEST_HAS_MEMALIGN 1
+#else
+# define SANITIZER_TEST_HAS_MEMALIGN 0
+#endif
+
+#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__ANDROID__) && \
+    !defined(__NetBSD__) && !defined(_WIN32) && \
+    !(defined(__sun__) && defined(__svr4__))
 # define SANITIZER_TEST_HAS_PVALLOC 1
 # define SANITIZER_TEST_HAS_MALLOC_USABLE_SIZE 1
 #else
-# define SANITIZER_TEST_HAS_MEMALIGN 0
 # define SANITIZER_TEST_HAS_PVALLOC 0
 # define SANITIZER_TEST_HAS_MALLOC_USABLE_SIZE 0
 #endif

Modified: compiler-rt/trunk/test/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/CMakeLists.txt?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/asan/CMakeLists.txt Wed Jan 17 04:26:04 2018
@@ -40,6 +40,9 @@ set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH
 if(APPLE)
   darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
 endif()
+if(OS_NAME MATCHES "SunOS")
+  list(REMOVE_ITEM ASAN_TEST_ARCH x86_64)
+endif()
 
 foreach(arch ${ASAN_TEST_ARCH})
   if(ANDROID)

Modified: compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/asan-sigbus.cpp Wed Jan 17 04:26:04 2018
@@ -14,6 +14,10 @@
 #include <unistd.h>
 #include <string>
 
+#ifndef MAP_FILE
+#define MAP_FILE 0
+#endif
+
 char array[4096];
 int main(int argc, char **argv) {
   int fd = open((std::string(argv[0]) + ".m").c_str(), O_RDWR | O_CREAT, 0700);

Modified: compiler-rt/trunk/test/asan/TestCases/Posix/coverage.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/coverage.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/coverage.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/coverage.cc Wed Jan 17 04:26:04 2018
@@ -14,7 +14,7 @@
 // RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
 // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4    2>&1 | FileCheck %s --check-prefix=CHECK-report
 // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5  2>&1 | FileCheck %s --check-prefix=CHECK-segv
-// RUN: rm -r %T/coverage
+// RUN: cd .. && rm -r %T/coverage
 //
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // XFAIL: android

Modified: compiler-rt/trunk/test/asan/TestCases/Posix/ioctl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Posix/ioctl.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Posix/ioctl.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Posix/ioctl.cc Wed Jan 17 04:26:04 2018
@@ -10,6 +10,10 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
+#if defined(__sun__) && defined(__svr4__)
+#include <sys/filio.h>
+#endif
+
 int main(int argc, char **argv) {
   int fd = socket(AF_INET, SOCK_DGRAM, 0);
 

Modified: compiler-rt/trunk/test/asan/TestCases/alloca_constant_size.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/alloca_constant_size.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/alloca_constant_size.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/alloca_constant_size.cc Wed Jan 17 04:26:04 2018
@@ -6,13 +6,13 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 
 // MSVC provides _alloca instead of alloca.
 #if defined(_MSC_VER) && !defined(alloca)
 # define alloca _alloca
-#elif defined(__FreeBSD__) || defined(__NetBSD__)
-#include <stdlib.h>
-#else
+
+#if defined(__sun__) && defined(__svr4__)
 #include <alloca.h>
 #endif
 

Modified: compiler-rt/trunk/test/asan/TestCases/alloca_loop_unpoisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/alloca_loop_unpoisoning.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/alloca_loop_unpoisoning.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/alloca_loop_unpoisoning.cc Wed Jan 17 04:26:04 2018
@@ -15,6 +15,10 @@
 # define alloca _alloca
 #endif
 
+#if defined(__sun__) && defined(__svr4__)
+#include <alloca.h>
+#endif
+
 void *top, *bot;
 
 __attribute__((noinline)) void foo(int len) {

Modified: compiler-rt/trunk/test/asan/TestCases/alloca_vla_interact.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/alloca_vla_interact.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/alloca_vla_interact.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/alloca_vla_interact.cc Wed Jan 17 04:26:04 2018
@@ -15,6 +15,10 @@
 # define alloca _alloca
 #endif
 
+#if defined(__sun__) && defined(__svr4__)
+#include <alloca.h>
+#endif
+
 #define RZ 32
 
 __attribute__((noinline)) void foo(int len) {

Modified: compiler-rt/trunk/test/asan/TestCases/debug_double_free.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/debug_double_free.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/debug_double_free.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/debug_double_free.cc Wed Jan 17 04:26:04 2018
@@ -15,6 +15,9 @@
 # else
 #  define PTR_FMT "0x%08x"
 # endif
+// Solaris libc omits the leading 0x.
+#elif defined(__sun__) && defined(__svr4__)
+# define PTR_FMT "0x%p"
 #else
 # define PTR_FMT "%p"
 #endif

Modified: compiler-rt/trunk/test/asan/TestCases/debug_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/debug_report.cc?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/debug_report.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/debug_report.cc Wed Jan 17 04:26:04 2018
@@ -30,6 +30,9 @@ int main() {
 # else
 #  define PTR_FMT "0x%08x"
 # endif
+// Solaris libc omits the leading 0x.
+#elif defined(__sun__) && defined(__svr4__)
+# define PTR_FMT "0x%p"
 #else
 # define PTR_FMT "%p"
 #endif

Modified: compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c Wed Jan 17 04:26:04 2018
@@ -10,6 +10,11 @@
 // Conflicts with BIONIC declarations.
 // UNSUPPORTED: android
 
+// Inhibit conflicting declaration of memalign on Solaris.
+#if defined(__sun__) && defined(__svr4__)
+#undef __EXTENSIONS__
+#endif
+
 #include <stdlib.h>
 
 // For glibc, cause link failures by referencing a nonexistent function.

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Jan 17 04:26:04 2018
@@ -209,7 +209,7 @@ else:
   config.substitutions.append(('%pie', '-pie'))
 
 # Only run the tests on supported OSs.
-if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows']:
+if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'SunOS', 'Windows']:
   config.unsupported = True
 
 if config.host_os == 'Darwin' and config.target_arch in ["x86_64", "x86_64h"]:

Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Wed Jan 17 04:26:04 2018
@@ -300,6 +300,9 @@ elif config.host_os == 'FreeBSD':
 elif config.host_os == 'Linux':
   config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
   config.substitutions.append( ("%ld_flags_rpath_so", '') )
+elif config.host_os == 'SunOS':
+  config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-R\$ORIGIN -L%T -l%xdynamiclib_namespec") )
+  config.substitutions.append( ("%ld_flags_rpath_so", '') )
 
 # Must be defined after the substitutions that use %dynamiclib.
 config.substitutions.append( ("%dynamiclib", '%T/%xdynamiclib_filename') )

Modified: compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt Wed Jan 17 04:26:04 2018
@@ -4,7 +4,7 @@ set(SANITIZER_COMMON_TEST_DEPS ${SANITIZ
 set(SANITIZER_COMMON_TESTSUITES)
 
 set(SUPPORTED_TOOLS)
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD")
+if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|SunOS")
   list(APPEND SUPPORTED_TOOLS asan)
 endif()
 if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Wed Jan 17 04:26:04 2018
@@ -38,6 +38,9 @@ set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_AR
 if(APPLE)
   darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
 endif()
+if(OS_NAME MATCHES "SunOS")
+  list(REMOVE_ITEM UBSAN_TEST_ARCH x86_64)
+endif()
 
 foreach(arch ${UBSAN_TEST_ARCH})
   set(UBSAN_TEST_TARGET_ARCH ${arch})

Modified: compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp Wed Jan 17 04:26:04 2018
@@ -29,6 +29,16 @@
 # ifndef LITTLE_ENDIAN
 #  define LITTLE_ENDIAN _LITTLE_ENDIAN
 # endif
+#elif defined(__sun__) && defined(__svr4__)
+// Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h.
+# include <sys/types.h>
+# define BIG_ENDIAN 4321
+# define LITTLE_ENDIAN 1234
+# if defined(_BIG_ENDIAN)
+#  define BYTE_ORDER BIG_ENDIAN
+# else
+#  define BYTE_ORDER LITTLE_ENDIAN
+# endif
 #elif defined(_WIN32)
 # define BYTE_ORDER 0
 # define BIG_ENDIAN 1

Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Wed Jan 17 04:26:04 2018
@@ -68,7 +68,7 @@ config.substitutions.append( ("%gmlt ",
 config.suffixes = ['.c', '.cc', '.cpp']
 
 # Check that the host supports UndefinedBehaviorSanitizer tests
-if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD']:
+if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD', 'SunOS']:
   config.unsupported = True
 
 config.available_features.add('arch=' + config.target_arch)

Modified: compiler-rt/trunk/test/ubsan_minimal/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan_minimal/CMakeLists.txt?rev=322635&r1=322634&r2=322635&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan_minimal/CMakeLists.txt Wed Jan 17 04:26:04 2018
@@ -4,6 +4,9 @@ set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_AR
 if(APPLE)
   darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
 endif()
+if(OS_NAME MATCHES "SunOS")
+  list(REMOVE_ITEM UBSAN_TEST_ARCH x86_64)
+endif()
 
 set(UBSAN_TESTSUITES)
 set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})




More information about the llvm-commits mailing list