Files
clang-p2996/compiler-rt/test/asan/TestCases/Linux/init-order-dlopen.cc
Alexey Samsonov f535d33fee [ASan] Disable strict init-order checking if dlopen() is called.
Revise the fix to https://code.google.com/p/address-sanitizer/issues/detail?id=178:
always disable strict init-order checking the first time dlopen() is
called: at this point shared library is allowed to access globals
defined in the main executable, as they are guaranteed to be
initialized. Revise the test cases:
* simplify init-order-dlopen.cc test case: make it Linux-specific
  (there's no strict init-order checking on other platforms anyway),
  and single-threaded.
* reinforce init-order-pthread-create.cc test case: make sure that
  init-order checker would produce a false positive unless we
  turn it off at the moment we call pthread_create().

llvm-svn: 230288
2015-02-24 00:37:27 +00:00

44 lines
976 B
C++

// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=178
// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
// RUN: %clangxx_asan -O0 %s %libdl -Wl,--export-dynamic -o %t
// RUN: env ASAN_OPTIONS=strict_init_order=true %run %t 2>&1
#if defined(SHARED_LIB)
#include <stdio.h>
struct Bar {
Bar(int val) : val(val) { printf("Bar::Bar(%d)\n", val); }
int val;
};
int get_foo_val();
Bar global_bar(get_foo_val());
#else // SHARED LIB
#include <dlfcn.h>
#include <stdio.h>
#include <string>
struct Foo {
Foo() : val(42) { printf("Foo::Foo()\n"); }
int val;
};
Foo global_foo;
int get_foo_val() {
return global_foo.val;
}
int main(int argc, char *argv[]) {
std::string path = std::string(argv[0]) + "-so.so";
void *handle = dlopen(path.c_str(), RTLD_NOW);
if (!handle) {
printf("error in dlopen(): %s\n", dlerror());
return 1;
}
printf("%d\n", get_foo_val());
return 0;
}
#endif // SHARED_LIB