Blame dlfcn/tst-dlinfo.c

Packit 6c4009
/* Test for dlinfo.
Packit 6c4009
   Copyright (C) 2003-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 <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <error.h>
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int status = 0;
Packit 6c4009
Packit 6c4009
  void *handle = dlopen ("glreflib3.so", RTLD_NOW);
Packit 6c4009
  if (handle == NULL)
Packit 6c4009
    error (EXIT_FAILURE, 0, "cannot load: glreflib1.so: %s", dlerror ());
Packit 6c4009
Packit 6c4009
#define TRY(req, arg)							      \
Packit 6c4009
  if (dlinfo (handle, req, arg) != 0)					      \
Packit 6c4009
    {									      \
Packit 6c4009
      printf ("dlinfo failed for %s: %s\n", #req, dlerror ());		      \
Packit 6c4009
      status = 1;							      \
Packit 6c4009
    }									      \
Packit 6c4009
  else
Packit 6c4009
Packit 6c4009
  struct link_map *l;
Packit 6c4009
  TRY (RTLD_DI_LINKMAP, &l)
Packit 6c4009
    {
Packit 6c4009
      if (l != handle)
Packit 6c4009
	{
Packit 6c4009
	  printf ("bogus link_map? %p != %p\n", l, handle);
Packit 6c4009
	  status = 1;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  char origin[8192];		/* >= PATH_MAX, in theory */
Packit 6c4009
  TRY (RTLD_DI_ORIGIN, origin)
Packit 6c4009
    {
Packit 6c4009
      printf ("origin: %s\n", origin);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  Dl_serinfo counts;
Packit 6c4009
  TRY (RTLD_DI_SERINFOSIZE, &counts)
Packit 6c4009
    {
Packit 6c4009
      Dl_serinfo *buf = alloca (counts.dls_size);
Packit 6c4009
      buf->dls_cnt = counts.dls_cnt;
Packit 6c4009
      buf->dls_size = counts.dls_size;
Packit 6c4009
      printf ("%u library directories\n", buf->dls_cnt);
Packit 6c4009
      TRY (RTLD_DI_SERINFO, buf)
Packit 6c4009
	{
Packit 6c4009
	  if (counts.dls_cnt != buf->dls_cnt)
Packit 6c4009
	    {
Packit 6c4009
	      printf ("??? became %u library directories\n", buf->dls_cnt);
Packit 6c4009
	      status = 1;
Packit 6c4009
	    }
Packit 6c4009
	  for (unsigned int i = 0; i < buf->dls_cnt; ++i)
Packit 6c4009
	    printf ("\t%#02x\t%s\n",
Packit 6c4009
		    buf->dls_serpath[i].dls_flags,
Packit 6c4009
		    buf->dls_serpath[i].dls_name);
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  unsigned long int lmid = 0xdeadbeefUL;
Packit 6c4009
  if (dlinfo (handle, RTLD_DI_LMID, &lmid) != 0)
Packit 6c4009
    printf ("dlinfo refuses RTLD_DI_LMID: %s\n", dlerror ());
Packit 6c4009
  else
Packit 6c4009
    {
Packit 6c4009
      printf ("dlinfo RTLD_DI_LMID worked? %#lx\n", lmid);
Packit 6c4009
      status = lmid == 0xdeadbeefUL;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
#undef TRY
Packit 6c4009
  dlclose (handle);
Packit 6c4009
Packit 6c4009
  return status;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#include "../test-skeleton.c"