-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlsymcall.c
More file actions
29 lines (27 loc) · 806 Bytes
/
dlsymcall.c
File metadata and controls
29 lines (27 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
const char *keys[] = {"ROCM_ROOT", "HCC_PATH"};
const char *values[] = {"/opt/rocm", "/opt"};
int main(int argc, char **argv)
{
if (argc < 1) {
printf("Usage: %s <path_to_libsetpath.so>\n", argv[0]);
return 0;
}
void *dlh = dlopen(argv[1], RTLD_LAZY);
if (!dlh) {
printf("dlopen of %s failed: %s\n", argv[1], dlerror());
return -1;
}
/* look up setpath function symbol */
int (*fn)(int, const char **, const char **) = (int (*)(int, const char **, const char **))dlsym(dlh, "setpath");
if (!fn) {
printf("setpath function not found!\n");
dlclose(dlh);
return -1;
}
/* call fn */
(*fn)(sizeof(keys)/sizeof(keys[0]), keys, values);
return 0;
}