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.
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 _dlopen=___orc_rt_macho_jit_dlopen \
9 // RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
10 // RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
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
21 int printf(const char * restrict format
, ...);
22 void *dlopen(const char* path
, int mode
);
23 int dlclose(void *handle
);
25 int main(int argc
, char *argv
[]) {
26 printf("entering main\n");
27 printf("first dlopen\n");
28 void *H
= dlopen("inits", 0);
33 printf("second dlopen\n");
34 void *I
= dlopen("inits", 0);
40 printf("handles do not match\n");
43 printf("first dlclose\n");
44 if (dlclose(I
) == -1) {
48 printf("second dlclose\n");
49 if (dlclose(H
) == -1) {
53 printf("leaving main\n");