1// Test that __orc_rt_macho_jit_dlsym works as expected.
2//
3// RUN: %clang -c -o %t.sym.o %p/Inputs/ret_self.S
4// RUN: %clang -c -o %t.test.o %s
5// RUN: %llvm_jitlink \
6// RUN: -alias Platform:_dlopen=___orc_rt_macho_jit_dlopen \
7// RUN: -alias Platform:_dlsym=___orc_rt_macho_jit_dlsym \
8// RUN: -alias Platform:_dlclose=___orc_rt_macho_jit_dlclose \
9// RUN: %t.test.o -lextra_sym -jd extra_sym %t.sym.o | FileCheck %s
10
11// CHECK: entering main
12// CHECK-NEXT: found "ret_self" at
13// CHECK-NEXT: address of "ret_self" is consistent
14// CHECK-NEXT: leaving main
15
16int printf(const char *restrict format, ...);
17void *dlopen(const char *path, int mode);
18void *dlsym(void *handle, const char *symbol);
19int dlclose(void *handle);
20
21int main(int argc, char *argv[]) {
22 printf(restrict: "entering main\n");
23 void *H = dlopen(path: "extra_sym", mode: 0);
24 if (!H) {
25 printf(restrict: "failed\n");
26 return -1;
27 }
28
29 void *(*ret_self)(void) = (void *(*)(void))dlsym(handle: H, symbol: "ret_self");
30 if (ret_self)
31 printf("found \"ret_self\" at %p\n", ret_self);
32 else
33 printf(restrict: "failed to find \"ret_self\" via dlsym\n");
34
35 printf("address of \"ret_self\" is %s\n",
36 ret_self() == ret_self ? "consistent" : "inconsistent");
37
38 if (dlclose(handle: H) == -1) {
39 printf(restrict: "failed\n");
40 return -1;
41 }
42 printf(restrict: "leaving main\n");
43 return 0;
44}
45

source code of compiler-rt/test/orc/TestCases/Darwin/arm64/trivial-dlsym.c