Blame elf/tst-dlopenfail-2.c

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