[compiler-rt] r199980 - [msan] add __libc_memalign interceptor; add a regression test for the existing bug with dtls support in msan
Kostya Serebryany
kcc at google.com
Fri Jan 24 01:14:13 PST 2014
Author: kcc
Date: Fri Jan 24 03:14:11 2014
New Revision: 199980
URL: http://llvm.org/viewvc/llvm-project?rev=199980&view=rev
Log:
[msan] add __libc_memalign interceptor; add a regression test for the existing bug with dtls support in msan
Added:
compiler-rt/trunk/lib/msan/lit_tests/dtls_test.c
Modified:
compiler-rt/trunk/lib/msan/msan_interceptors.cc
Added: compiler-rt/trunk/lib/msan/lit_tests/dtls_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/lit_tests/dtls_test.c?rev=199980&view=auto
==============================================================================
--- compiler-rt/trunk/lib/msan/lit_tests/dtls_test.c (added)
+++ compiler-rt/trunk/lib/msan/lit_tests/dtls_test.c Fri Jan 24 03:14:11 2014
@@ -0,0 +1,60 @@
+/* RUN: %clang_msan -m64 %s -o %t
+ RUN: %clang_msan -m64 %s -DBUILD_SO -fPIC -o %t-so.so -shared
+ RUN: not %t 2>&1 | FileCheck %s
+ CHECK: MemorySanitizer: use-of-uninitialized-value
+
+ This is an actual bug in msan/glibc integration,
+ see https://sourceware.org/bugzilla/show_bug.cgi?id=16291
+*/
+
+#ifndef BUILD_SO
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+
+typedef long *(* get_t)();
+get_t GetTls;
+void *Thread1(void *unused) {
+ long uninitialized;
+ long *x = GetTls();
+ if (*x)
+ fprintf(stderr, "bar\n");
+ *x = uninitialized;
+ fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
+ return 0;
+}
+
+void *Thread2(void *unused) {
+ long *x = GetTls();
+ fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
+ if (*x)
+ fprintf(stderr, "foo\n"); // False negative here.
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ char path[4096];
+ snprintf(path, sizeof(path), "%s-so.so", argv[0]);
+ int i;
+
+ void *handle = dlopen(path, RTLD_LAZY);
+ if (!handle) fprintf(stderr, "%s\n", dlerror());
+ assert(handle != 0);
+ GetTls = (get_t)dlsym(handle, "GetTls");
+ assert(dlerror() == 0);
+
+ pthread_t t;
+ pthread_create(&t, 0, Thread1, 0);
+ pthread_join(t, 0);
+ pthread_create(&t, 0, Thread2, 0);
+ pthread_join(t, 0);
+ return 0;
+}
+#else // BUILD_SO
+__thread long huge_thread_local_array[1 << 17];
+long *GetTls() {
+ return &huge_thread_local_array[0];
+}
+#endif
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=199980&r1=199979&r2=199980&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Fri Jan 24 03:14:11 2014
@@ -159,6 +159,9 @@ INTERCEPTOR(void *, memalign, SIZE_T bou
return ptr;
}
+INTERCEPTOR(void*, __libc_memalign, uptr align, uptr s)
+ ALIAS("memalign");
+
INTERCEPTOR(void *, valloc, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
void *ptr = MsanReallocate(&stack, 0, size, GetPageSizeCached(), false);
More information about the llvm-commits
mailing list