summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2017-11-10 22:09:37 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2017-11-10 22:09:37 +0000
commit55dee3e7a884bf78e0f8932ff7eaac6f614866fa (patch)
tree33edd0726c17688d572fed22cd2bfabd4076743f /test
parent206e78aa8cafe99214e591d19a8c4a7254f1a2ed (diff)
sanitizer_common: Try looking up symbols with RTLD_DEFAULT if RTLD_NEXT does not work.
If the lookup using RTLD_NEXT failed, the sanitizer runtime library is later in the library search order than the DSO that we are trying to intercept, which means that we cannot intercept this function. We still want the address of the real definition, though, so look it up using RTLD_DEFAULT. Differential Revision: https://reviews.llvm.org/D39779 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/ubsan/TestCases/Misc/Inputs/no-interception-dso.c3
-rw-r--r--test/ubsan/TestCases/Misc/no-interception.cpp20
-rw-r--r--test/ubsan/lit.common.cfg2
3 files changed, 25 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Misc/Inputs/no-interception-dso.c b/test/ubsan/TestCases/Misc/Inputs/no-interception-dso.c
new file mode 100644
index 000000000..5ccc9b63d
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/Inputs/no-interception-dso.c
@@ -0,0 +1,3 @@
+int dso_function(int i) {
+ return i + 1;
+}
diff --git a/test/ubsan/TestCases/Misc/no-interception.cpp b/test/ubsan/TestCases/Misc/no-interception.cpp
new file mode 100644
index 000000000..c82fed3bf
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/no-interception.cpp
@@ -0,0 +1,20 @@
+// REQUIRES: android
+
+// Tests that ubsan can detect errors on Android if libc appears before the
+// runtime in the library search order, which means that we cannot intercept
+// symbols.
+
+// RUN: %clangxx %p/Inputs/no-interception-dso.c -fsanitize=undefined -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
+
+// Make sure that libc is first in DT_NEEDED.
+// RUN: %clangxx %s -lc -o %t %ld_flags_rpath_exe
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <limits.h>
+
+int dso_function(int);
+
+int main(int argc, char **argv) {
+ // CHECK: signed integer overflow
+ dso_function(INT_MAX);
+}
diff --git a/test/ubsan/lit.common.cfg b/test/ubsan/lit.common.cfg
index f34d5867d..e1bd349af 100644
--- a/test/ubsan/lit.common.cfg
+++ b/test/ubsan/lit.common.cfg
@@ -74,3 +74,5 @@ if config.host_os not in ['Linux', 'Darwin', 'FreeBSD', 'Windows', 'NetBSD']:
config.unsupported = True
config.available_features.add('arch=' + config.target_arch)
+
+config.excludes = ['Inputs']