1 /* Global-scope DSO mapping test with a static executable (BZ #15022).
2 Copyright (C) 2013-2021 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 <https://www.gnu.org/licenses/>. */
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. */
33 unsigned int (*getfoo
) (void);
34 void (*setfoo
) (unsigned int);
39 /* Try to map a module into the global scope. */
40 handle
= dlopen ("modstatic3.so", RTLD_LAZY
| RTLD_GLOBAL
);
43 printf ("dlopen (modstatic3.so): %s\n", dlerror ());
47 /* Get at its symbols. */
48 foop
= dlsym (handle
, "foo");
51 printf ("dlsym (foo): %s\n", dlerror ());
55 getfoo
= dlsym (handle
, "getfoo");
58 printf ("dlsym (getfoo): %s\n", dlerror ());
62 setfoo
= dlsym (handle
, "setfoo");
65 printf ("dlsym (setfoo): %s\n", dlerror ());
69 /* Make sure the view of the initial state is consistent. */
73 printf ("*foop: got %#x, expected %#x\n", foo
, MAGIC0
);
80 printf ("getfoo: got %#x, expected %#x\n", foo
, MAGIC0
);
84 /* Likewise with one change to its state. */
90 printf ("*foop: got %#x, expected %#x\n", foo
, MAGIC1
);
97 printf ("getfoo: got %#x, expected %#x\n", foo
, MAGIC1
);
101 /* And with another. */
107 printf ("*foop: got %#x, expected %#x\n", foo
, MAGIC2
);
114 printf ("getfoo: got %#x, expected %#x\n", foo
, MAGIC2
);
118 /* All done, clean up. */
127 #define TEST_FUNCTION do_test ()
128 #include "../test-skeleton.c"