brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · d469b98 Raw
48 lines · cpp
1// Regression test for2// https://code.google.com/p/address-sanitizer/issues/detail?id=1783 4// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so5// RUN: %clangxx_asan -O0 %s %libdl -Wl,--export-dynamic -o %t6// RUN: %env_asan_opts=strict_init_order=true %run %t 2>&17 8// dlopen() can not be intercepted on Android, making strict_init_order nearly9// useless there.10// UNSUPPORTED: android11 12#if defined(SHARED_LIB)13#include <stdio.h>14 15struct Bar {16  Bar(int val) : val(val) { printf("Bar::Bar(%d)\n", val); }17  int val;18};19 20int get_foo_val();21Bar global_bar(get_foo_val());22#else  // SHARED LIB23#include <dlfcn.h>24#include <stdio.h>25#include <string>26struct Foo {27  Foo() : val(42) { printf("Foo::Foo()\n"); }28  int val;29};30 31Foo global_foo;32 33int get_foo_val() {34  return global_foo.val;35}36 37int main(int argc, char *argv[]) {38  std::string path = std::string(argv[0]) + "-so.so";39  void *handle = dlopen(path.c_str(), RTLD_NOW);40  if (!handle) {41    printf("error in dlopen(): %s\n", dlerror());42    return 1;43  }44  printf("%d\n", get_foo_val());45  return 0;46}47#endif  // SHARED_LIB48