69 lines · c
1/* RUN: %clang_msan -g %s -o %t2 RUN: %clang_msan -g %s -DBUILD_SO -fPIC -o %t-so.so -shared3 RUN: %run %t 2>&14 5 Regression test for a bug in msan/glibc integration,6 see https://sourceware.org/bugzilla/show_bug.cgi?id=162917 and https://github.com/google/sanitizers/issues/5478 9 XFAIL: target={{.*freebsd.*}}10 UNSUPPORTED: target=powerpc{{.*}}11 12 // Reports use-of-uninitialized-value, not analyzed13 XFAIL: target={{.*netbsd.*}}14 UNSUPPORTED: aarch64-target-arch15 16*/17 18#ifndef BUILD_SO19#include <assert.h>20#include <dlfcn.h>21#include <stdio.h>22#include <stdlib.h>23#include <pthread.h>24 25typedef long *(* get_t)();26get_t GetTls;27void *Thread1(void *unused) {28 long uninitialized;29 long *x = GetTls();30 if (*x)31 fprintf(stderr, "bar\n");32 *x = uninitialized;33 fprintf(stderr, "stack: %p dtls: %p\n", &x, x);34 return 0;35}36 37void *Thread2(void *unused) {38 long *x = GetTls();39 fprintf(stderr, "stack: %p dtls: %p\n", &x, x);40 if (*x)41 fprintf(stderr, "foo\n"); // False negative here.42 return 0;43}44 45int main(int argc, char *argv[]) {46 char path[4096];47 snprintf(path, sizeof(path), "%s-so.so", argv[0]);48 int i;49 50 void *handle = dlopen(path, RTLD_LAZY);51 if (!handle) fprintf(stderr, "%s\n", dlerror());52 assert(handle != 0);53 GetTls = (get_t)dlsym(handle, "GetTls");54 assert(dlerror() == 0);55 56 pthread_t t;57 pthread_create(&t, 0, Thread1, 0);58 pthread_join(t, 0);59 pthread_create(&t, 0, Thread2, 0);60 pthread_join(t, 0);61 return 0;62}63#else // BUILD_SO64__thread long huge_thread_local_array[1 << 17];65long *GetTls() {66 return &huge_thread_local_array[0];67}68#endif69