xref: /llvm-project/offload/test/offloading/dynamic_module_load.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compile-generic -DSHARED -fPIC -shared -o %t.so && %clang %flags %s -o %t -ldl && %libomptarget-run-generic %t.so 2>&1 | %fcheck-generic
2 
3 #ifdef SHARED
4 #include <stdio.h>
foo()5 int foo() {
6 #pragma omp target
7   ;
8   printf("%s\n", "DONE.");
9   return 0;
10 }
11 #else
12 #include <dlfcn.h>
13 #include <stdio.h>
main(int argc,char ** argv)14 int main(int argc, char **argv) {
15 #pragma omp target
16   ;
17 
18   void *Handle = dlopen(argv[1], RTLD_NOW);
19   int (*Foo)(void);
20 
21   if (Handle == NULL) {
22     printf("dlopen() failed: %s\n", dlerror());
23     return 1;
24   }
25   Foo = (int (*)(void))dlsym(Handle, "foo");
26   if (Handle == NULL) {
27     printf("dlsym() failed: %s\n", dlerror());
28     return 1;
29   }
30   // CHECK: DONE.
31   // CHECK-NOT: {{abort|fault}}
32   return Foo();
33 }
34 #endif
35