Blame dlfcn/tststatic5.c

Packit 6c4009
/* GLRO(dl_pagesize) initialization DSO test with a static executable.
Packit 6c4009
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <dlfcn.h>
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
Packit 6c4009
/* Check that the same page size is reported both directly and by a DSO
Packit 6c4009
   mapped from a static executable.
Packit 6c4009
Packit 6c4009
   On targets that support different page sizes, the kernel communicates
Packit 6c4009
   the size currently in use via the auxiliary vector.  This vector is
Packit 6c4009
   available to initial startup, but not any DSOs loaded later on.  As
Packit 6c4009
   static executables do not export their symbols a DSO cannot access
Packit 6c4009
   the value obtained by initial startup and the value therefore has to
Packit 6c4009
   be passed on to the DSO and stored within its data area explicitly.
Packit 6c4009
   This is performed by a call to DL_STATIC_INIT that is defined in a
Packit 6c4009
   target-dependent way, and that on variable page size targets stores
Packit 6c4009
   it in the GLRO(dl_pagesize) variable of the DSO's dynamic linker.  */
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int pagesize = getpagesize ();
Packit 6c4009
  int (*my_getpagesize) (void);
Packit 6c4009
  int my_pagesize;
Packit 6c4009
  void *handle;
Packit 6c4009
Packit 6c4009
  /* Try to map a module.  */
Packit 6c4009
  handle = dlopen ("modstatic5.so", RTLD_LAZY | RTLD_LOCAL);
Packit 6c4009
  if (handle == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("dlopen (modstatic5.so): %s\n", dlerror ());
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Get at its symbol.  */
Packit 6c4009
  my_getpagesize = dlsym (handle, "my_getpagesize");
Packit 6c4009
  if (my_getpagesize == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("dlsym (my_getpagesize): %s\n", dlerror ());
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* Make sure the page size reported is the same either way.  */
Packit 6c4009
  my_pagesize = my_getpagesize ();
Packit 6c4009
  if (my_pagesize != pagesize)
Packit 6c4009
    {
Packit 6c4009
      printf ("my_getpagesize: got %i, expected %i\n", my_pagesize, pagesize);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* All done, clean up.  */
Packit 6c4009
  my_getpagesize = NULL;
Packit 6c4009
  dlclose (handle);
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"