]>
Commit | Line | Data |
---|---|---|
00213fe4 | 1 | /* Test for dladdr. |
2b778ceb | 2 | Copyright (C) 2000-2021 Free Software Foundation, Inc. |
41bdb6e2 | 3 | This file is part of the GNU C Library. |
00213fe4 AJ |
4 | Contributed by Volkmar Sieh <vs@caldera.de> and Andreas Jaeger <aj@suse.de>. |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
00213fe4 AJ |
10 | |
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 14 | Lesser General Public License for more details. |
00213fe4 | 15 | |
41bdb6e2 | 16 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 17 | License along with the GNU C Library; if not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
00213fe4 AJ |
19 | |
20 | #include <dlfcn.h> | |
21 | #include <errno.h> | |
22 | #include <error.h> | |
23 | #include <stdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | ||
27 | ||
28 | #define TEST_FUNCTION do_test () | |
ed073f0e | 29 | extern int do_test (void); |
00213fe4 AJ |
30 | |
31 | int | |
32 | do_test (void) | |
33 | { | |
34 | void *handle; | |
35 | int (*sym) (void); /* We load ref1 from glreflib1.c. */ | |
36 | Dl_info info; | |
37 | int ret; | |
38 | ||
39 | ||
40 | handle = dlopen ("glreflib1.so", RTLD_NOW); | |
41 | if (handle == NULL) | |
42 | error (EXIT_FAILURE, 0, "cannot load: glreflib1.so"); | |
43 | ||
44 | sym = dlsym (handle, "ref1"); | |
45 | if (sym == NULL) | |
46 | error (EXIT_FAILURE, 0, "dlsym failed"); | |
47 | ||
48 | memset (&info, 0, sizeof (info)); | |
49 | ret = dladdr (sym, &info); | |
50 | ||
51 | if (ret == 0) | |
52 | error (EXIT_FAILURE, 0, "dladdr failed"); | |
53 | ||
00213fe4 AJ |
54 | printf ("ret = %d\n", ret); |
55 | printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname); | |
56 | printf ("info.dli_fbase = %p\n", info.dli_fbase); | |
57 | printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname); | |
58 | printf ("info.dli_saddr = %p\n", info.dli_saddr); | |
59 | ||
60 | if (info.dli_fname == NULL) | |
61 | error (EXIT_FAILURE, 0, "dli_fname is NULL"); | |
62 | if (info.dli_fbase == NULL) | |
63 | error (EXIT_FAILURE, 0, "dli_fbase is NULL"); | |
64 | if (info.dli_sname == NULL) | |
65 | error (EXIT_FAILURE, 0, "dli_sname is NULL"); | |
66 | if (info.dli_saddr == NULL) | |
67 | error (EXIT_FAILURE, 0, "dli_saddr is NULL"); | |
68 | ||
69 | dlclose (handle); | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | ||
75 | #include "../test-skeleton.c" |