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
18 typedef volatile long *(* get_t
)();
21 int main(int argc
, char *argv
[]) {
23 snprintf(path
, sizeof(path
), "%s-so.so", argv
[0]);
26 void *handle
= dlopen(path
, RTLD_LAZY
);
27 if (!handle
) fprintf(stderr
, "%s\n", dlerror());
29 GetTls
= (get_t
)dlsym(handle
, "GetTls");
30 assert(dlerror() == 0);
33 printf("Testing RTLD_DL_LINKMAP\n");
37 struct link_map
*map_ptr
;
38 int ret
= dladdr1(GetTls
, &info
, (void**)(&map_ptr
), RTLD_DL_LINKMAP
);
40 printf("fname: %s\n", info
.dli_fname
);
41 printf("fbase: %p\n", info
.dli_fbase
);
42 printf("sname: %s\n", info
.dli_sname
);
43 // CHECK: sname: GetTls
44 printf("saddr: %p\n", info
.dli_saddr
);
46 assert(map_ptr
!= NULL
);
47 printf("map_ptr: %p\n", map_ptr
);
50 // Find the start of the link map
51 while(map_ptr
->l_prev
!= NULL
) {
53 map_ptr
= map_ptr
->l_prev
;
57 while(map_ptr
!= NULL
) {
58 assert(map_ptr
->l_name
!= NULL
);
59 printf("0x%lx: '%s', %p\n", map_ptr
->l_addr
, map_ptr
->l_name
, map_ptr
->l_ld
);
61 map_ptr
= map_ptr
->l_next
;
63 // CHECK: libc{{[\-]*.*}}.so
64 // CHECK: dladdr1_test
67 // Test RTLD_DL_SYMENT
70 printf("Testing RTLD_DL_SYMENT\n");
75 int ret
= dladdr1(GetTls
, &info
, (void**)(&sym
), RTLD_DL_SYMENT
);
77 printf("fname: %s\n", info
.dli_fname
);
78 printf("fbase: %p\n", info
.dli_fbase
);
79 printf("sname: %s\n", info
.dli_sname
);
80 // CHECK: sname: GetTls
81 printf("saddr: %p\n", info
.dli_saddr
);
83 printf("sym: %d %d %d %d %lu %lu\n",
84 sym
->st_name
, sym
->st_info
, sym
->st_other
,
85 sym
->st_shndx
, sym
->st_value
, sym
->st_size
);