Get rid of Versions.def source file
[glibc.git] / dlfcn / tststatic3.c
bloba12c80eeb46a77f4c1aafada82030e2a503847c6
1 /* Global-scope DSO mapping test with a static executable (BZ #15022).
2 Copyright (C) 2013-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <dlfcn.h>
20 #include <stddef.h>
21 #include <stdio.h>
23 #define MAGIC0 0
24 #define MAGIC1 0x5500ffaa
25 #define MAGIC2 0xaaff0055
27 /* Mapping a DSO into the global scope used to crash in static
28 executables. Check that it succeeds and then that symbols from
29 the DSO can be accessed and operate as expected. */
30 static int
31 do_test (void)
33 unsigned int (*getfoo) (void);
34 void (*setfoo) (unsigned int);
35 unsigned int *foop;
36 unsigned int foo;
37 void *handle;
39 /* Try to map a module into the global scope. */
40 handle = dlopen ("modstatic3.so", RTLD_LAZY | RTLD_GLOBAL);
41 if (handle == NULL)
43 printf ("dlopen (modstatic3.so): %s\n", dlerror ());
44 return 1;
47 /* Get at its symbols. */
48 foop = dlsym (handle, "foo");
49 if (foop == NULL)
51 printf ("dlsym (foo): %s\n", dlerror ());
52 return 1;
55 getfoo = dlsym (handle, "getfoo");
56 if (getfoo == NULL)
58 printf ("dlsym (getfoo): %s\n", dlerror ());
59 return 1;
62 setfoo = dlsym (handle, "setfoo");
63 if (setfoo == NULL)
65 printf ("dlsym (setfoo): %s\n", dlerror ());
66 return 1;
69 /* Make sure the view of the initial state is consistent. */
70 foo = *foop;
71 if (foo != MAGIC0)
73 printf ("*foop: got %#x, expected %#x\n", foo, MAGIC0);
74 return 1;
77 foo = getfoo ();
78 if (foo != MAGIC0)
80 printf ("getfoo: got %#x, expected %#x\n", foo, MAGIC0);
81 return 1;
84 /* Likewise with one change to its state. */
85 setfoo (MAGIC1);
87 foo = *foop;
88 if (foo != MAGIC1)
90 printf ("*foop: got %#x, expected %#x\n", foo, MAGIC1);
91 return 1;
94 foo = getfoo ();
95 if (foo != MAGIC1)
97 printf ("getfoo: got %#x, expected %#x\n", foo, MAGIC1);
98 return 1;
101 /* And with another. */
102 setfoo (MAGIC2);
104 foo = *foop;
105 if (foo != MAGIC2)
107 printf ("*foop: got %#x, expected %#x\n", foo, MAGIC2);
108 return 1;
111 foo = getfoo ();
112 if (foo != MAGIC2)
114 printf ("getfoo: got %#x, expected %#x\n", foo, MAGIC2);
115 return 1;
118 /* All done, clean up. */
119 getfoo = NULL;
120 setfoo = NULL;
121 foop = NULL;
122 dlclose (handle);
124 return 0;
127 #define TEST_FUNCTION do_test ()
128 #include "../test-skeleton.c"