[compiler-rt] r193760 - [msan] Intercept dlerror.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Oct 31 09:58:44 PDT 2013


Author: eugenis
Date: Thu Oct 31 11:58:44 2013
New Revision: 193760

URL: http://llvm.org/viewvc/llvm-project?rev=193760&view=rev
Log:
[msan] Intercept dlerror.

Added:
    compiler-rt/trunk/lib/msan/lit_tests/dlerror.cc
Modified:
    compiler-rt/trunk/lib/msan/msan_interceptors.cc

Added: compiler-rt/trunk/lib/msan/lit_tests/dlerror.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/dlerror.cc?rev=193760&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/dlerror.cc (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/dlerror.cc Thu Oct 31 11:58:44 2013
@@ -0,0 +1,14 @@
+// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <string.h>
+
+int main(void) {
+  void *p = dlopen("/bad/file/name", RTLD_NOW);
+  assert(!p);
+  char *s = dlerror();
+  printf("%s, %zu\n", s, strlen(s));
+  return 0;
+}

Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=193760&r1=193759&r2=193760&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Thu Oct 31 11:58:44 2013
@@ -896,6 +896,13 @@ INTERCEPTOR(int, dladdr, void *addr, dli
   return res;
 }
 
+INTERCEPTOR(char *, dlerror) {
+  ENSURE_MSAN_INITED();
+  char *res = REAL(dlerror)();
+  if (res != 0) __msan_unpoison(res, REAL(strlen)(res) + 1);
+  return res;
+}
+
 // dlopen() ultimately calls mmap() down inside the loader, which generally
 // doesn't participate in dynamic symbol resolution.  Therefore we won't
 // intercept its calls to mmap, and we have to hook it here.  The loader
@@ -1497,6 +1504,7 @@ void InitializeInterceptors() {
   INTERCEPT_FUNCTION(recv);
   INTERCEPT_FUNCTION(recvfrom);
   INTERCEPT_FUNCTION(dladdr);
+  INTERCEPT_FUNCTION(dlerror);
   INTERCEPT_FUNCTION(dlopen);
   INTERCEPT_FUNCTION(dl_iterate_phdr);
   INTERCEPT_FUNCTION(getrusage);





More information about the llvm-commits mailing list