brintos

brintos / llvm-project-archived public Read only

0
0
Text · 984 B · 111b6f0 Raw
48 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>&1 | FileCheck %s4 5   REQUIRES: glibc{{.*}}6*/7 8#define _GNU_SOURCE9 10#ifndef BUILD_SO11#include <assert.h>12#include <dlfcn.h>13#include <stdio.h>14#include <stdlib.h>15 16typedef volatile long *(* get_t)();17get_t GetTls;18 19int main(int argc, char *argv[]) {20  char path[4096];21  snprintf(path, sizeof(path), "%s-so.so", argv[0]);22  int i;23 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);29 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);37 38  // CHECK: sname: GetTls39 40  return 0;41}42#else  // BUILD_SO43long var;44long *GetTls() {45  return &var;46}47#endif48