blob: 57c8c5dd13243d9c1044892bbf7ba48e5efee616 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#include <fcntl.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include <dlfcn.h>
5#include <stdint.h>
6
7#define LIBNAME "libstatic.so"
8
9int load_and_test(void)
10{
11 void *handle;
12 int (*mystatic)(void);
13
14 handle = dlopen(LIBNAME, RTLD_LAZY);
15 if (!handle) {
16 fprintf(stderr, "Could not open ./%s: %s\n", LIBNAME, dlerror());
17 return 1;
18 }
19
20 mystatic = dlsym(handle, "static_test");
21 if (mystatic == NULL) {
22 fprintf(stderr, "Could not locate symbol 'static_test': %s\n", dlerror());
23 return 1;
24 }
25
26 if (!mystatic()) {
27 fprintf(stderr, "mystatic() failed: static vars were not setup properly\n");
28 return 1;
29 }
30
31 dlclose(handle);
32
33 return 0;
34}
35
36int main(int argc, char **argv)
37{
38 int count = 5;
39 while (count-- > 0)
40 if (load_and_test())
41 return EXIT_FAILURE;
42 return EXIT_SUCCESS;
43}