1 #include <dlfcn.h>
2 #include <stdio.h>
3
4 extern int found_in_mod1 (void);
5 int
found_in_mod1(void)6 found_in_mod1 (void)
7 {
8 return 1;
9 }
10
11
12 extern int test_in_mod1 (int (*mainp)(int, char **));
13 int
test_in_mod1(int (* mainp)(int,char **))14 test_in_mod1 (int (*mainp)(int, char **))
15 {
16 int (*ifp) (void);
17 void *p;
18 int result = 0;
19
20 /* Find function `main'. */
21 p = dlsym (RTLD_DEFAULT, "main");
22 if (p == NULL)
23 {
24 printf ("%s: main not found\n", __FILE__);
25 result = 1;
26 }
27 else if ((int (*)(int, char **))p != mainp)
28 {
29 printf ("%s: wrong address returned for main\n", __FILE__);
30 result = 1;
31 }
32 else
33 printf ("%s: main correctly found\n", __FILE__);
34
35 ifp = dlsym (RTLD_DEFAULT, "found_in_mod1");
36 if ((void *) ifp == NULL)
37 {
38 printf ("%s: found_in_mod1 not found\n", __FILE__);
39 result = 1;
40 }
41 else if (ifp () != 1)
42 {
43 printf ("%s: wrong address returned for found_in_mod1\n", __FILE__);
44 result = 1;
45 }
46 else
47 printf ("%s: found_in_mod1 correctly found\n", __FILE__);
48
49 ifp = dlsym (RTLD_DEFAULT, "found_in_mod2");
50 if ((void *) ifp == NULL)
51 {
52 printf ("%s: found_in_mod2 not found\n", __FILE__);
53 result = 1;
54 }
55 else if (ifp () != 2)
56 {
57 printf ("%s: wrong address returned for found_in_mod2\n", __FILE__);
58 result = 1;
59 }
60 else
61 printf ("%s: found_in_mod2 correctly found\n", __FILE__);
62
63 return result;
64 }
65