Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / init-order-dlopen.cpp
blobd469b98089fe8faf9f2fae1bc74369166c868baa
1 // Regression test for
2 // https://code.google.com/p/address-sanitizer/issues/detail?id=178
4 // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
5 // RUN: %clangxx_asan -O0 %s %libdl -Wl,--export-dynamic -o %t
6 // RUN: %env_asan_opts=strict_init_order=true %run %t 2>&1
8 // dlopen() can not be intercepted on Android, making strict_init_order nearly
9 // useless there.
10 // UNSUPPORTED: android
12 #if defined(SHARED_LIB)
13 #include <stdio.h>
15 struct Bar {
16 Bar(int val) : val(val) { printf("Bar::Bar(%d)\n", val); }
17 int val;
20 int get_foo_val();
21 Bar global_bar(get_foo_val());
22 #else // SHARED LIB
23 #include <dlfcn.h>
24 #include <stdio.h>
25 #include <string>
26 struct Foo {
27 Foo() : val(42) { printf("Foo::Foo()\n"); }
28 int val;
31 Foo global_foo;
33 int get_foo_val() {
34 return global_foo.val;
37 int 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;
44 printf("%d\n", get_foo_val());
45 return 0;
47 #endif // SHARED_LIB