diff options
author | Kamil Rytarowski <n54@gmx.com> | 2018-01-17 12:26:04 +0000 |
---|---|---|
committer | Kamil Rytarowski <n54@gmx.com> | 2018-01-17 12:26:04 +0000 |
commit | c91431d33cee551f97693cee3f1dcb1158ea8a1b (patch) | |
tree | 0d911a470b1c4f2a43a231ae7872c0073a100771 /test | |
parent | ff43dd5fc957bb4082338b3b1fa3f9385a9ded43 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@322635 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/asan/CMakeLists.txt | 3 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/asan-sigbus.cpp | 4 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/coverage.cc | 2 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/ioctl.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/alloca_constant_size.cc | 6 | ||||
-rw-r--r-- | test/asan/TestCases/alloca_loop_unpoisoning.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/alloca_vla_interact.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/debug_double_free.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/debug_report.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/malloc-no-intercept.c | 5 | ||||
-rw-r--r-- | test/asan/lit.cfg | 2 | ||||
-rw-r--r-- | test/lit.common.cfg | 3 | ||||
-rw-r--r-- | test/sanitizer_common/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/ubsan/CMakeLists.txt | 3 | ||||
-rw-r--r-- | test/ubsan/TestCases/Float/cast-overflow.cpp | 10 | ||||
-rw-r--r-- | test/ubsan/lit.common.cfg | 2 | ||||
-rw-r--r-- | test/ubsan_minimal/CMakeLists.txt | 3 |
17 files changed, 56 insertions, 7 deletions
diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt index 6bfaa6a0e..78e081a92 100644 --- a/test/asan/CMakeLists.txt +++ b/test/asan/CMakeLists.txt @@ -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) diff --git a/test/asan/TestCases/Posix/asan-sigbus.cpp b/test/asan/TestCases/Posix/asan-sigbus.cpp index c91ecbd75..1418dc446 100644 --- a/test/asan/TestCases/Posix/asan-sigbus.cpp +++ b/test/asan/TestCases/Posix/asan-sigbus.cpp @@ -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); diff --git a/test/asan/TestCases/Posix/coverage.cc b/test/asan/TestCases/Posix/coverage.cc index a78560a72..570cd6650 100644 --- a/test/asan/TestCases/Posix/coverage.cc +++ b/test/asan/TestCases/Posix/coverage.cc @@ -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 diff --git a/test/asan/TestCases/Posix/ioctl.cc b/test/asan/TestCases/Posix/ioctl.cc index 6cf9fa8e3..7269dfddb 100644 --- a/test/asan/TestCases/Posix/ioctl.cc +++ b/test/asan/TestCases/Posix/ioctl.cc @@ -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); diff --git a/test/asan/TestCases/alloca_constant_size.cc b/test/asan/TestCases/alloca_constant_size.cc index 57aa31570..4fb0ee58e 100644 --- a/test/asan/TestCases/alloca_constant_size.cc +++ b/test/asan/TestCases/alloca_constant_size.cc @@ -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 diff --git a/test/asan/TestCases/alloca_loop_unpoisoning.cc b/test/asan/TestCases/alloca_loop_unpoisoning.cc index 1efada109..f9d32aafd 100644 --- a/test/asan/TestCases/alloca_loop_unpoisoning.cc +++ b/test/asan/TestCases/alloca_loop_unpoisoning.cc @@ -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) { diff --git a/test/asan/TestCases/alloca_vla_interact.cc b/test/asan/TestCases/alloca_vla_interact.cc index 4717c9d97..92b0afafc 100644 --- a/test/asan/TestCases/alloca_vla_interact.cc +++ b/test/asan/TestCases/alloca_vla_interact.cc @@ -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) { diff --git a/test/asan/TestCases/debug_double_free.cc b/test/asan/TestCases/debug_double_free.cc index c3699b976..44c820b63 100644 --- a/test/asan/TestCases/debug_double_free.cc +++ b/test/asan/TestCases/debug_double_free.cc @@ -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 diff --git a/test/asan/TestCases/debug_report.cc b/test/asan/TestCases/debug_report.cc index 34bc06eba..14bb70e9f 100644 --- a/test/asan/TestCases/debug_report.cc +++ b/test/asan/TestCases/debug_report.cc @@ -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 diff --git a/test/asan/TestCases/malloc-no-intercept.c b/test/asan/TestCases/malloc-no-intercept.c index c1442e6cf..ca98febed 100644 --- a/test/asan/TestCases/malloc-no-intercept.c +++ b/test/asan/TestCases/malloc-no-intercept.c @@ -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. diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg index 4a08a7b47..dd2776d7f 100644 --- a/test/asan/lit.cfg +++ b/test/asan/lit.cfg @@ -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"]: diff --git a/test/lit.common.cfg b/test/lit.common.cfg index 0840f65a7..fee66028a 100644 --- a/test/lit.common.cfg +++ b/test/lit.common.cfg @@ -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') ) diff --git a/test/sanitizer_common/CMakeLists.txt b/test/sanitizer_common/CMakeLists.txt index 8b210a08a..237f87b84 100644 --- a/test/sanitizer_common/CMakeLists.txt +++ b/test/sanitizer_common/CMakeLists.txt @@ -4,7 +4,7 @@ set(SANITIZER_COMMON_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS}) 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) diff --git a/test/ubsan/CMakeLists.txt b/test/ubsan/CMakeLists.txt index 779168147..fa8b16b80 100644 --- a/test/ubsan/CMakeLists.txt +++ b/test/ubsan/CMakeLists.txt @@ -38,6 +38,9 @@ set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH}) 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}) diff --git a/test/ubsan/TestCases/Float/cast-overflow.cpp b/test/ubsan/TestCases/Float/cast-overflow.cpp index a53c663b1..460150aa3 100644 --- a/test/ubsan/TestCases/Float/cast-overflow.cpp +++ b/test/ubsan/TestCases/Float/cast-overflow.cpp @@ -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 diff --git a/test/ubsan/lit.common.cfg b/test/ubsan/lit.common.cfg index 83475a2dc..851c7fbbc 100644 --- a/test/ubsan/lit.common.cfg +++ b/test/ubsan/lit.common.cfg @@ -68,7 +68,7 @@ config.substitutions.append( ("%gmlt ", " ".join(config.debug_info_flags) + " ") 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) diff --git a/test/ubsan_minimal/CMakeLists.txt b/test/ubsan_minimal/CMakeLists.txt index 712654e94..5da5fcd02 100644 --- a/test/ubsan_minimal/CMakeLists.txt +++ b/test/ubsan_minimal/CMakeLists.txt @@ -4,6 +4,9 @@ set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH}) 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}) |