1// Test that __orc_rt_macho_jit_dlopen and __orc_rt_macho_jit_dlclose work as
2// expected for a dlopen; dlclose; dlopen; dlclose; sequence: the first dlclose
3// should run destructors, and the second dlopen should re-run initializers.
4//
5// RUN: %clang -c -o %t.inits.o %p/Inputs/standalone-ctor-and-cxa-atexit-dtor.S
6// RUN: %clang -c -o %t.test.o %s
7// RUN: %llvm_jitlink \
8// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
9// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
10// RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
11
12// CHECK: entering main
13// CHECK-NEXT: first dlopen
14// CHECK-NEXT: constructor
15// CHECK-NEXT: second dlopen
16// CHECK-NEXT: first dlclose
17// CHECK-NEXT: second dlclose
18// CHECK-NEXT: destructor
19// CHECK-NEXT: leaving main
20
21int printf(const char * restrict format, ...);
22void *dlopen(const char* path, int mode);
23int dlclose(void *handle);
24
25int main(int argc, char *argv[]) {
26 printf(restrict: "entering main\n");
27 printf(restrict: "first dlopen\n");
28 void *H = dlopen(path: "inits", mode: 0);
29 if (!H) {
30 printf(restrict: "failed\n");
31 return -1;
32 }
33 printf(restrict: "second dlopen\n");
34 void *I = dlopen(path: "inits", mode: 0);
35 if (!I) {
36 printf(restrict: "failed\n");
37 return -1;
38 }
39 if (I != H) {
40 printf(restrict: "handles do not match\n");
41 return -1;
42 }
43 printf(restrict: "first dlclose\n");
44 if (dlclose(handle: I) == -1) {
45 printf(restrict: "failed\n");
46 return -1;
47 }
48 printf(restrict: "second dlclose\n");
49 if (dlclose(handle: H) == -1) {
50 printf(restrict: "failed\n");
51 return -1;
52 }
53 printf(restrict: "leaving main\n");
54 return 0;
55}
56

source code of compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-dlopen-nested.c