brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f4b49b2 Raw
56 lines · c
1// Test that __orc_rt_macho_jit_dlopen and __orc_rt_macho_jit_dlclose work as2// expected for a dlopen; dlclose; dlopen; dlclose; sequence: the first dlclose3// 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.S6// RUN: %clang -c -o %t.test.o %s7// 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 %s11 12// CHECK: entering main13// CHECK-NEXT: first dlopen14// CHECK-NEXT: constructor15// CHECK-NEXT: second dlopen16// CHECK-NEXT: first dlclose17// CHECK-NEXT: second dlclose18// CHECK-NEXT: destructor19// CHECK-NEXT: leaving main20 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("entering main\n");27  printf("first dlopen\n");28  void *H = dlopen("inits", 0);29  if (!H) {30    printf("failed\n");31    return -1;32  }33  printf("second dlopen\n");34  void *I = dlopen("inits", 0);35  if (!I) {36    printf("failed\n");37    return -1;38  }39  if (I != H) {40    printf("handles do not match\n");41    return -1;42  }43  printf("first dlclose\n");44  if (dlclose(I) == -1) {45    printf("failed\n");46    return -1;47  }48  printf("second dlclose\n");49  if (dlclose(H) == -1) {50    printf("failed\n");51    return -1;52  }53  printf("leaving main\n");54  return 0;55}56