]> git.ipfire.org Git - thirdparty/glibc.git/blame - dlfcn/tst-dladdr.c
* dlfcn/dlmopen.c (dlmopen_doit): Don't allow RTLD_GLOBAL to be
[thirdparty/glibc.git] / dlfcn / tst-dladdr.c
CommitLineData
00213fe4 1/* Test for dladdr.
131fd00f 2 Copyright (C) 2000, 2001 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
AJ
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
00213fe4
AJ
20
21#include <dlfcn.h>
22#include <errno.h>
23#include <error.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27
131fd00f
UD
28#include <ldsodefs.h>
29
00213fe4
AJ
30
31#define TEST_FUNCTION do_test ()
ed073f0e 32extern int do_test (void);
00213fe4
AJ
33
34int
35do_test (void)
36{
37 void *handle;
38 int (*sym) (void); /* We load ref1 from glreflib1.c. */
39 Dl_info info;
40 int ret;
41
42
43 handle = dlopen ("glreflib1.so", RTLD_NOW);
44 if (handle == NULL)
45 error (EXIT_FAILURE, 0, "cannot load: glreflib1.so");
46
47 sym = dlsym (handle, "ref1");
48 if (sym == NULL)
49 error (EXIT_FAILURE, 0, "dlsym failed");
50
51 memset (&info, 0, sizeof (info));
52 ret = dladdr (sym, &info);
53
54 if (ret == 0)
55 error (EXIT_FAILURE, 0, "dladdr failed");
56
131fd00f
UD
57 printf ("address of ref1 = %lx\n",
58 (unsigned long int) DL_LOOKUP_ADDRESS (sym));
00213fe4
AJ
59 printf ("ret = %d\n", ret);
60 printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname);
61 printf ("info.dli_fbase = %p\n", info.dli_fbase);
62 printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname);
63 printf ("info.dli_saddr = %p\n", info.dli_saddr);
64
65 if (info.dli_fname == NULL)
66 error (EXIT_FAILURE, 0, "dli_fname is NULL");
67 if (info.dli_fbase == NULL)
68 error (EXIT_FAILURE, 0, "dli_fbase is NULL");
69 if (info.dli_sname == NULL)
70 error (EXIT_FAILURE, 0, "dli_sname is NULL");
71 if (info.dli_saddr == NULL)
72 error (EXIT_FAILURE, 0, "dli_saddr is NULL");
73
74 dlclose (handle);
75
76 return 0;
77}
78
79
80#include "../test-skeleton.c"