hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame elf/tst-dlopenfail-2.c

Packit cea01e
/* Test unrelated dlopen after dlopen failure involving NODELETE.
Packit cea01e
   Copyright (C) 2019-2020 Free Software Foundation, Inc.
Packit cea01e
   This file is part of the GNU C Library.
Packit cea01e
Packit cea01e
   The GNU C Library is free software; you can redistribute it and/or
Packit cea01e
   modify it under the terms of the GNU Lesser General Public
Packit cea01e
   License as published by the Free Software Foundation; either
Packit cea01e
   version 2.1 of the License, or (at your option) any later version.
Packit cea01e
Packit cea01e
   The GNU C Library is distributed in the hope that it will be useful,
Packit cea01e
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit cea01e
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit cea01e
   Lesser General Public License for more details.
Packit cea01e
Packit cea01e
   You should have received a copy of the GNU Lesser General Public
Packit cea01e
   License along with the GNU C Library; if not, see
Packit cea01e
   <https://www.gnu.org/licenses/>.  */
Packit cea01e
Packit cea01e
#include <dlfcn.h>
Packit cea01e
#include <errno.h>
Packit cea01e
#include <gnu/lib-names.h>
Packit cea01e
#include <stddef.h>
Packit cea01e
#include <stdio.h>
Packit cea01e
#include <string.h>
Packit cea01e
#include <support/check.h>
Packit cea01e
#include <support/xdlfcn.h>
Packit cea01e
Packit cea01e
static int
Packit cea01e
do_test (void)
Packit cea01e
{
Packit cea01e
  /* This test uses libpthread as the canonical NODELETE module.  If
Packit cea01e
     libpthread is no longer NODELETE because it has been merged into
Packit cea01e
     libc, the test needs to be updated.  */
Packit cea01e
  TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL);
Packit cea01e
Packit cea01e
  /* This is expected to fail because of the missing dependency.  */
Packit cea01e
  puts ("info: attempting to load tst-dlopenfailmod1.so");
Packit cea01e
  TEST_VERIFY (dlopen ("tst-dlopenfailmod1.so", RTLD_LAZY) == NULL);
Packit cea01e
  const char *message = dlerror ();
Packit cea01e
  TEST_COMPARE_STRING (message,
Packit cea01e
                       "tst-dlopenfail-missingmod.so:"
Packit cea01e
                       " cannot open shared object file:"
Packit cea01e
                       " No such file or directory");
Packit cea01e
Packit cea01e
  /* Open a small shared object.  With a dangling GL (dl_initfirst)
Packit cea01e
     pointer, this is likely to crash because there is no longer any
Packit cea01e
     mapped text segment there (bug 25396).  */
Packit cea01e
Packit cea01e
  puts ("info: attempting to load tst-dlopenfailmod3.so");
Packit cea01e
  xdlclose (xdlopen ("tst-dlopenfailmod3.so", RTLD_NOW));
Packit cea01e
Packit cea01e
  return 0;
Packit cea01e
}
Packit cea01e
Packit cea01e
/* Do not perturb the dangling link map.  With M_PERTURB, the link map
Packit cea01e
   appears to have l_init_called set, so there are no constructor
Packit cea01e
   calls and no crashes.  */
Packit cea01e
#define TEST_NO_MALLOPT
Packit cea01e
#include <support/test-driver.c>