Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / dladdr_test.c
blob111b6f00230174a1c48c11660033a7da92893238
1 /* RUN: %clang_msan -g %s -o %t
2 RUN: %clang_msan -g %s -DBUILD_SO -fPIC -o %t-so.so -shared
3 RUN: %run %t 2>&1 | FileCheck %s
5 REQUIRES: glibc{{.*}}
6 */
8 #define _GNU_SOURCE
10 #ifndef BUILD_SO
11 #include <assert.h>
12 #include <dlfcn.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 typedef volatile long *(* get_t)();
17 get_t GetTls;
19 int main(int argc, char *argv[]) {
20 char path[4096];
21 snprintf(path, sizeof(path), "%s-so.so", argv[0]);
22 int i;
24 void *handle = dlopen(path, RTLD_LAZY);
25 if (!handle) fprintf(stderr, "%s\n", dlerror());
26 assert(handle != 0);
27 GetTls = (get_t)dlsym(handle, "GetTls");
28 assert(dlerror() == 0);
30 Dl_info info;
31 int ret = dladdr(GetTls, &info);
32 assert (ret != 0);
33 printf ("fname: %s\n", info.dli_fname);
34 printf ("fbase: %p\n", info.dli_fbase);
35 printf ("sname: %s\n", info.dli_sname);
36 printf ("saddr: %p\n", info.dli_saddr);
38 // CHECK: sname: GetTls
40 return 0;
42 #else // BUILD_SO
43 long var;
44 long *GetTls() {
45 return &var;
47 #endif