1#include <dlfcn.h>
2#include <stdio.h>
3#include <string.h>
4
5
6extern int test_in_mod1 (void *);
7extern int test_in_mod2 (void *);
8
9
10int
11main (int argc, char *argv[])
12{
13 int (*ifp) (void);
14 void *p;
15 int result = 0;
16 Dl_info info;
17
18 dladdr(address: main, info: &info);
19 if (info.dli_fname == NULL)
20 {
21 printf (format: "%s: dladdr returns NULL dli_fname\n", __FILE__);
22 result = 1;
23 }
24 else if (strcmp (info.dli_fname, argv[0]))
25 {
26 printf (format: "%s: dladdr returned '%s' as dli_fname\n", __FILE__, info.dli_fname);
27 result = 1;
28 }
29 else
30 printf (format: "%s: dladdr returned correct dli_fname\n", __FILE__);
31
32 /* Find function `main'. */
33 p = dlsym (RTLD_DEFAULT, name: "main");
34 if (p == NULL)
35 {
36 printf (format: "%s: main not found\n", __FILE__);
37 result = 1;
38 }
39 else if ((int (*)(int, char **))p != main)
40 {
41 printf (format: "%s: wrong address returned for main\n", __FILE__);
42 result = 1;
43 }
44 else
45 printf (format: "%s: main correctly found\n", __FILE__);
46
47 ifp = dlsym (RTLD_DEFAULT, name: "found_in_mod1");
48 if ((void *) ifp == NULL)
49 {
50 printf (format: "%s: found_in_mod1 not found\n", __FILE__);
51 result = 1;
52 }
53 else if (ifp () != 1)
54 {
55 printf (format: "%s: wrong address returned for found_in_mod1\n", __FILE__);
56 result = 1;
57 }
58 else
59 printf (format: "%s: found_in_mod1 correctly found\n", __FILE__);
60
61 ifp = dlsym (RTLD_DEFAULT, name: "found_in_mod2");
62 if ((void *) ifp == NULL)
63 {
64 printf (format: "%s: found_in_mod2 not found\n", __FILE__);
65 result = 1;
66 }
67 else if (ifp () != 2)
68 {
69 printf (format: "%s: wrong address returned for found_in_mod2\n", __FILE__);
70 result = 1;
71 }
72 else
73 printf (format: "%s: found_in_mod2 correctly found\n", __FILE__);
74
75 result |= test_in_mod1 (main);
76
77 result |= test_in_mod2 (main);
78
79 return result;
80}
81

source code of glibc/dlfcn/default.c