[PATCH] D67298: [ASan] Fix test case dlopen-mixed-c-cxx.c without C++ stdlib

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 12:24:45 PDT 2019


Hahnfeld created this revision.
Hahnfeld added reviewers: serge-sans-paille, uweigand, kcc, vitalybuka.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.

When building with a non-default value of `SANITIZER_CXX_ABI=libcxxabi`,
there is no full C++ stdlib linked to the shared asan runtime. This
test has been failing for me because under that configuration there is
no additional `__cxa_throw`. Provide it by wrapping the function using
dlsym in the main executable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67298

Files:
  compiler-rt/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c


Index: compiler-rt/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
===================================================================
--- compiler-rt/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
+++ compiler-rt/test/asan/TestCases/Linux/dlopen-mixed-c-cxx.c
@@ -28,9 +28,18 @@
 
 #else
 
+#define _GNU_SOURCE
 #include <assert.h>
 #include <dlfcn.h>
 
+// Wrap __cxa_throw to make sure it's defined in the main executable.
+typedef void (*cxa_throw_t)(void *, void *, void (*)(void *));
+void __cxa_throw(void *thrown_exception, void *tinfo,
+                 void (*dest)(void *)) {
+  cxa_throw_t real = dlsym(RTLD_NEXT, "__cxa_throw");
+  real(thrown_exception, tinfo, dest);
+}
+
 int main(int argc, char **argv) {
   int (*bar)(void);
   void *handle = dlopen(argv[1], RTLD_LAZY);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67298.219154.patch
Type: text/x-patch
Size: 788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190906/5b4db3d2/attachment.bin>


More information about the llvm-commits mailing list