[compiler-rt] r366632 - Fix asan infinite loop on undefined symbol
Serge Guelton via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 20 05:01:18 PDT 2019
Author: serge_sans_paille
Date: Sat Jul 20 05:01:18 2019
New Revision: 366632
URL: http://llvm.org/viewvc/llvm-project?rev=366632&view=rev
Log:
Fix asan infinite loop on undefined symbol
Fix llvm#39641
Recommit of r366413
Differential Revision: https://reviews.llvm.org/D63877
Added:
compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
Modified:
compiler-rt/trunk/lib/interception/interception_linux.cc
Modified: compiler-rt/trunk/lib/interception/interception_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_linux.cc?rev=366632&r1=366631&r2=366632&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_linux.cc (original)
+++ compiler-rt/trunk/lib/interception/interception_linux.cc Sat Jul 20 05:01:18 2019
@@ -33,7 +33,7 @@ static int StrCmp(const char *s1, const
}
#endif
-static void *GetFuncAddr(const char *name) {
+static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
#if SANITIZER_NETBSD
// FIXME: Find a better way to handle renames
if (StrCmp(name, "sigaction"))
@@ -47,13 +47,18 @@ static void *GetFuncAddr(const char *nam
// want the address of the real definition, though, so look it up using
// RTLD_DEFAULT.
addr = dlsym(RTLD_DEFAULT, name);
+
+ // In case `name' is not loaded, dlsym ends up finding the actual wrapper.
+ // We don't want to intercept the wrapper and have it point to itself.
+ if ((uptr)addr == wrapper_addr)
+ addr = nullptr;
}
return addr;
}
bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
uptr wrapper) {
- void *addr = GetFuncAddr(name);
+ void *addr = GetFuncAddr(name, wrapper);
*ptr_to_real = (uptr)addr;
return addr && (func == wrapper);
}
Added: compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c?rev=366632&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c Sat Jul 20 05:01:18 2019
@@ -0,0 +1,43 @@
+// RUN: %clangxx_asan -xc++ -shared -fPIC -o %t.so - < %s
+// RUN: %clang_asan %s -o %t.out -ldl
+//
+// RUN: env ASAN_OPTIONS=verbosity=1 not %t.out %t.so 2>&1 | FileCheck %s
+//
+// CHECK: {{.*}}AddressSanitizer: failed to intercept '__cxa_{{.*}}throw{{.*}}'
+//
+// REQUIRES: x86_64-target-arch && !android
+
+#ifdef __cplusplus
+
+static void foo(void) {
+ int i = 0;
+ throw(i);
+}
+
+extern "C" {
+int bar(void);
+};
+int bar(void) {
+ try {
+ foo();
+ } catch (int i) {
+ return i;
+ }
+ return -1;
+}
+
+#else
+
+#include <assert.h>
+#include <dlfcn.h>
+
+int main(int argc, char **argv) {
+ int (*bar)(void);
+ void *handle = dlopen(argv[1], RTLD_LAZY);
+ assert(handle);
+ bar = dlsym(handle, "bar");
+ assert(bar);
+ return bar();
+}
+
+#endif
More information about the llvm-commits
mailing list