powerpc: Add hwcap2 bits for POWER9.
[glibc.git] / dlfcn / tststatic5.c
blob20bd4639b2c6d2518649705fc6468da024d7e46f
1 /* GLRO(dl_pagesize) initialization DSO test with a static executable.
2 Copyright (C) 2013-2016 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>
22 #include <unistd.h>
24 /* Check that the same page size is reported both directly and by a DSO
25 mapped from a static executable.
27 On targets that support different page sizes, the kernel communicates
28 the size currently in use via the auxiliary vector. This vector is
29 available to initial startup, but not any DSOs loaded later on. As
30 static executables do not export their symbols a DSO cannot access
31 the value obtained by initial startup and the value therefore has to
32 be passed on to the DSO and stored within its data area explicitly.
33 This is performed by a call to DL_STATIC_INIT that is defined in a
34 target-dependent way, and that on variable page size targets stores
35 it in the GLRO(dl_pagesize) variable of the DSO's dynamic linker. */
36 static int
37 do_test (void)
39 int pagesize = getpagesize ();
40 int (*my_getpagesize) (void);
41 int my_pagesize;
42 void *handle;
44 /* Try to map a module. */
45 handle = dlopen ("modstatic5.so", RTLD_LAZY | RTLD_LOCAL);
46 if (handle == NULL)
48 printf ("dlopen (modstatic5.so): %s\n", dlerror ());
49 return 1;
52 /* Get at its symbol. */
53 my_getpagesize = dlsym (handle, "my_getpagesize");
54 if (my_getpagesize == NULL)
56 printf ("dlsym (my_getpagesize): %s\n", dlerror ());
57 return 1;
60 /* Make sure the page size reported is the same either way. */
61 my_pagesize = my_getpagesize ();
62 if (my_pagesize != pagesize)
64 printf ("my_getpagesize: got %i, expected %i\n", my_pagesize, pagesize);
65 return 1;
68 /* All done, clean up. */
69 my_getpagesize = NULL;
70 dlclose (handle);
72 return 0;
75 #define TEST_FUNCTION do_test ()
76 #include "../test-skeleton.c"