summaryrefslogtreecommitdiff
path: root/test/scudo
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-11-01 15:28:20 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-11-01 15:28:20 +0000
commit60ec9d032df6ac22be15ee06e1559c73cffc22ea (patch)
treec366d3f0eda8d10afd6ace12178786989c47833e /test/scudo
parente8c4cd327a7e9d9f3d9bac156f887d5664384d63 (diff)
[scudo] Implement stricter separation of C vs C++
Summary: Initially, Scudo had a monolithic design where both C and C++ functions were living in the same library. This was not necessarily ideal, and with the work on -fsanitize=scudo, it became more apparent that this needed to change. We are splitting the new/delete interceptor in their own C++ library. This allows more flexibility, notably with regard to std::bad_alloc when the work is done. This also allows us to not link new & delete when using pure C. Additionally, we add the UBSan runtimes with Scudo, in order to be able to have a -fsanitize=scudo,undefined in Clang (see work in D39334). The changes in this patch: - split the cxx specific code in the scudo cmake file into a new library; (remove the spurious foreach loop, that was not necessary) - add the UBSan runtimes (both C and C++); - change the test cmake file to allow for specific C & C++ tests; - make C tests pure C, rename their extension accordingly. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: srhines, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D39461 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317097 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/scudo')
-rw-r--r--test/scudo/alignment.c (renamed from test/scudo/alignment.cpp)2
-rw-r--r--test/scudo/double-free.cpp2
-rw-r--r--test/scudo/interface.cpp2
-rw-r--r--test/scudo/lit.cfg10
-rw-r--r--test/scudo/malloc.cpp2
-rw-r--r--test/scudo/memalign.c (renamed from test/scudo/memalign.cpp)4
-rw-r--r--test/scudo/mismatch.cpp2
-rw-r--r--test/scudo/options.cpp2
-rw-r--r--test/scudo/overflow.c (renamed from test/scudo/overflow.cpp)0
-rw-r--r--test/scudo/preinit.c (renamed from test/scudo/preinit.cpp)2
-rw-r--r--test/scudo/preload.cpp10
-rw-r--r--test/scudo/quarantine.c (renamed from test/scudo/quarantine.cpp)2
-rw-r--r--test/scudo/random_shuffle.cpp2
-rw-r--r--test/scudo/realloc.cpp2
-rw-r--r--test/scudo/secondary.c (renamed from test/scudo/secondary.cpp)2
-rw-r--r--test/scudo/sized-delete.cpp2
-rw-r--r--test/scudo/sizes.cpp2
-rw-r--r--test/scudo/threads.c (renamed from test/scudo/threads.cpp)4
-rw-r--r--test/scudo/tsd_destruction.c (renamed from test/scudo/tsd_destruction.cpp)0
-rw-r--r--test/scudo/valloc.c (renamed from test/scudo/valloc.cpp)2
20 files changed, 30 insertions, 26 deletions
diff --git a/test/scudo/alignment.cpp b/test/scudo/alignment.c
index 125ad8cbe..6235d5060 100644
--- a/test/scudo/alignment.cpp
+++ b/test/scudo/alignment.c
@@ -15,7 +15,7 @@ int main(int argc, char **argv)
if (!strcmp(argv[1], "pointers")) {
void *p = malloc(1U << 16);
assert(p);
- free(reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(p) | 1));
+ free((void *)((uintptr_t)p | 1));
}
return 0;
}
diff --git a/test/scudo/double-free.cpp b/test/scudo/double-free.cpp
index ddc520505..56118038c 100644
--- a/test/scudo/double-free.cpp
+++ b/test/scudo/double-free.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clangxx_scudo %s -o %t
// RUN: not %run %t malloc 2>&1 | FileCheck %s
// RUN: not %run %t new 2>&1 | FileCheck %s
// RUN: not %run %t newarray 2>&1 | FileCheck %s
diff --git a/test/scudo/interface.cpp b/test/scudo/interface.cpp
index e9575adf3..16523bfe3 100644
--- a/test/scudo/interface.cpp
+++ b/test/scudo/interface.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -lstdc++ -o %t
+// RUN: %clangxx_scudo %s -lstdc++ -o %t
// RUN: %run %t ownership 2>&1
// RUN: %run %t ownership-and-size 2>&1
// RUN: %run %t heap-size 2>&1
diff --git a/test/scudo/lit.cfg b/test/scudo/lit.cfg
index f4b864777..0113bf0e7 100644
--- a/test/scudo/lit.cfg
+++ b/test/scudo/lit.cfg
@@ -11,21 +11,24 @@ config.test_source_root = os.path.dirname(__file__)
# Path to the shared & static libraries
shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.so" % config.target_arch)
static_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.a" % config.target_arch)
+static_libscudo_cxx = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo_cxx-%s.a" % config.target_arch)
+
whole_archive = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % static_libscudo
+whole_archive_cxx = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % static_libscudo_cxx
# Test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
-# C flags.
+# C & CXX flags.
c_flags = ([config.target_cflags] +
- ["-std=c++11",
- "-pthread",
+ ["-pthread",
"-fPIE",
"-pie",
"-O0",
"-UNDEBUG",
"-ldl",
"-Wl,--gc-sections"])
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
# Android doesn't want -lrt.
if not config.android:
@@ -37,6 +40,7 @@ def build_invocation(compile_flags):
# Add clang substitutions.
config.substitutions.append(("%clang ", build_invocation(c_flags)))
config.substitutions.append(("%clang_scudo ", build_invocation(c_flags) + whole_archive))
+config.substitutions.append(("%clangxx_scudo ", build_invocation(cxx_flags) + whole_archive + whole_archive_cxx))
config.substitutions.append(("%shared_libscudo", shared_libscudo))
# Platform-specific default SCUDO_OPTIONS for lit tests.
diff --git a/test/scudo/malloc.cpp b/test/scudo/malloc.cpp
index 50e52590f..6c6a6c464 100644
--- a/test/scudo/malloc.cpp
+++ b/test/scudo/malloc.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -lstdc++ -o %t
+// RUN: %clangxx_scudo %s -lstdc++ -o %t
// RUN: %run %t 2>&1
// Tests that a regular workflow of allocation, memory fill and free works as
diff --git a/test/scudo/memalign.cpp b/test/scudo/memalign.c
index fece04dfc..1fe6e3ec7 100644
--- a/test/scudo/memalign.cpp
+++ b/test/scudo/memalign.c
@@ -15,11 +15,11 @@
#include <unistd.h>
// Sometimes the headers may not have this...
-extern "C" void *aligned_alloc(size_t alignment, size_t size);
+void *aligned_alloc(size_t alignment, size_t size);
int main(int argc, char **argv)
{
- void *p = nullptr;
+ void *p = NULL;
size_t alignment = 1U << 12;
size_t size = 1U << 12;
int err;
diff --git a/test/scudo/mismatch.cpp b/test/scudo/mismatch.cpp
index 538c8e6de..b49e0ea46 100644
--- a/test/scudo/mismatch.cpp
+++ b/test/scudo/mismatch.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clangxx_scudo %s -o %t
// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t mallocdel 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s
// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t mallocdel 2>&1
// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t newfree 2>&1 | FileCheck --check-prefix=CHECK-dealloc %s
diff --git a/test/scudo/options.cpp b/test/scudo/options.cpp
index 6464bc65b..605b63241 100644
--- a/test/scudo/options.cpp
+++ b/test/scudo/options.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clangxx_scudo %s -o %t
// RUN: %run %t 2>&1
// RUN: %env_scudo_opts=DeallocationTypeMismatch=0 %run %t 2>&1
// RUN: %env_scudo_opts=DeallocationTypeMismatch=1 not %run %t 2>&1 | FileCheck %s
diff --git a/test/scudo/overflow.cpp b/test/scudo/overflow.c
index c5a58f87f..c5a58f87f 100644
--- a/test/scudo/overflow.cpp
+++ b/test/scudo/overflow.c
diff --git a/test/scudo/preinit.cpp b/test/scudo/preinit.c
index f904c6c2d..792b2368e 100644
--- a/test/scudo/preinit.cpp
+++ b/test/scudo/preinit.c
@@ -12,7 +12,7 @@
#include <stdlib.h>
#include <string.h>
-static void *global_p = nullptr;
+static void *global_p = NULL;
void __init(void) {
global_p = malloc(1);
diff --git a/test/scudo/preload.cpp b/test/scudo/preload.cpp
index 0da507b3c..b41a70e47 100644
--- a/test/scudo/preload.cpp
+++ b/test/scudo/preload.cpp
@@ -1,19 +1,19 @@
// Test that the preloaded runtime works without linking the static library.
-// RUN: %clang %s -o %t
+// RUN: %clang %s -lstdc++ -o %t
// RUN: env LD_PRELOAD=%shared_libscudo not %run %t 2>&1 | FileCheck %s
// This way of setting LD_PRELOAD does not work with Android test runner.
// REQUIRES: !android
#include <assert.h>
-#include <stdlib.h>
int main(int argc, char *argv[]) {
- void *p = malloc(sizeof(int));
+ int *p = new int;
assert(p);
- free(p);
- free(p);
+ *p = 0;
+ delete p;
+ delete p;
return 0;
}
diff --git a/test/scudo/quarantine.cpp b/test/scudo/quarantine.c
index 8872fe688..ddbb92005 100644
--- a/test/scudo/quarantine.cpp
+++ b/test/scudo/quarantine.c
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
free(p);
// Eventually the chunk should become available again.
- bool found = false;
+ char found = 0;
for (int i = 0; i < 0x200 && !found; i++) {
p = malloc(size);
assert(p);
diff --git a/test/scudo/random_shuffle.cpp b/test/scudo/random_shuffle.cpp
index 54768a578..f886cb150 100644
--- a/test/scudo/random_shuffle.cpp
+++ b/test/scudo/random_shuffle.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -o %t
+// RUN: %clangxx_scudo %s -o %t
// RUN: rm -rf %T/random_shuffle_tmp_dir
// RUN: mkdir %T/random_shuffle_tmp_dir
// RUN: %run %t 100 > %T/random_shuffle_tmp_dir/out1
diff --git a/test/scudo/realloc.cpp b/test/scudo/realloc.cpp
index 01149670e..254c67a2c 100644
--- a/test/scudo/realloc.cpp
+++ b/test/scudo/realloc.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -lstdc++ -o %t
+// RUN: %clangxx_scudo %s -lstdc++ -o %t
// RUN: %run %t pointers 2>&1
// RUN: %run %t contents 2>&1
// RUN: %run %t usablesize 2>&1
diff --git a/test/scudo/secondary.cpp b/test/scudo/secondary.c
index dc14f8ca8..b770ca076 100644
--- a/test/scudo/secondary.cpp
+++ b/test/scudo/secondary.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
assert(p);
memset(p, 'A', size); // This should not trigger anything.
// Set up the SIGSEGV handler now, as the rest should trigger an AV.
- sigaction(SIGSEGV, &a, nullptr);
+ sigaction(SIGSEGV, &a, NULL);
if (!strcmp(argv[1], "after")) {
for (int i = 0; i < page_size; i++)
p[size + i] = 'A';
diff --git a/test/scudo/sized-delete.cpp b/test/scudo/sized-delete.cpp
index 9c3a2c596..85df05e2f 100644
--- a/test/scudo/sized-delete.cpp
+++ b/test/scudo/sized-delete.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo -fsized-deallocation %s -o %t
+// RUN: %clangxx_scudo -fsized-deallocation %s -o %t
// RUN: %env_scudo_opts=DeleteSizeMismatch=1 %run %t gooddel 2>&1
// RUN: %env_scudo_opts=DeleteSizeMismatch=1 not %run %t baddel 2>&1 | FileCheck %s
// RUN: %env_scudo_opts=DeleteSizeMismatch=0 %run %t baddel 2>&1
diff --git a/test/scudo/sizes.cpp b/test/scudo/sizes.cpp
index 8f147b708..73fc71f25 100644
--- a/test/scudo/sizes.cpp
+++ b/test/scudo/sizes.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_scudo %s -lstdc++ -o %t
+// RUN: %clangxx_scudo %s -lstdc++ -o %t
// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t malloc 2>&1 | FileCheck %s
// RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t malloc 2>&1
// RUN: %env_scudo_opts=allocator_may_return_null=0 not %run %t calloc 2>&1 | FileCheck %s
diff --git a/test/scudo/threads.cpp b/test/scudo/threads.c
index 643eda77d..b34e6f0f7 100644
--- a/test/scudo/threads.cpp
+++ b/test/scudo/threads.c
@@ -20,7 +20,7 @@ pthread_t tid[kMaxNumThreads];
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-bool go = false;
+char go = 0;
void *thread_fun(void *arg) {
pthread_mutex_lock(&mutex);
@@ -51,7 +51,7 @@ int main(int argc, char** argv) {
for (int i = 0; i < num_threads; i++)
pthread_create(&tid[i], 0, thread_fun, 0);
pthread_mutex_lock(&mutex);
- go = true;
+ go = 1;
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
for (int i = 0; i < num_threads; i++)
diff --git a/test/scudo/tsd_destruction.cpp b/test/scudo/tsd_destruction.c
index 1b0d0eff9..1b0d0eff9 100644
--- a/test/scudo/tsd_destruction.cpp
+++ b/test/scudo/tsd_destruction.c
diff --git a/test/scudo/valloc.cpp b/test/scudo/valloc.c
index 514a88449..132c4f280 100644
--- a/test/scudo/valloc.cpp
+++ b/test/scudo/valloc.c
@@ -19,7 +19,7 @@ size_t round_up_to(size_t size, size_t alignment) {
int main(int argc, char **argv)
{
- void *p = nullptr;
+ void *p = NULL;
size_t size, page_size;
assert(argc == 2);