Blame elf/tst-initfinilazyfail.c

Packit Bot 45a627
/* Test that lazy binding failures in constructors and destructors are fatal.
Packit Bot 45a627
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Bot 45a627
   This file is part of the GNU C Library.
Packit Bot 45a627
Packit Bot 45a627
   The GNU C Library is free software; you can redistribute it and/or
Packit Bot 45a627
   modify it under the terms of the GNU Lesser General Public
Packit Bot 45a627
   License as published by the Free Software Foundation; either
Packit Bot 45a627
   version 2.1 of the License, or (at your option) any later version.
Packit Bot 45a627
Packit Bot 45a627
   The GNU C Library is distributed in the hope that it will be useful,
Packit Bot 45a627
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Bot 45a627
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Bot 45a627
   Lesser General Public License for more details.
Packit Bot 45a627
Packit Bot 45a627
   You should have received a copy of the GNU Lesser General Public
Packit Bot 45a627
   License along with the GNU C Library; if not, see
Packit Bot 45a627
   <https://www.gnu.org/licenses/>.  */
Packit Bot 45a627
Packit Bot 45a627
#include <dlfcn.h>
Packit Bot 45a627
#include <string.h>
Packit Bot 45a627
#include <support/capture_subprocess.h>
Packit Bot 45a627
#include <support/check.h>
Packit Bot 45a627
#include <support/xdlfcn.h>
Packit Bot 45a627
Packit Bot 45a627
static void
Packit Bot 45a627
test_constructor (void *closure)
Packit Bot 45a627
{
Packit Bot 45a627
  void *handle = dlopen ("tst-initlazyfailmod.so", RTLD_LAZY);
Packit Bot 45a627
  if (handle == NULL)
Packit Bot 45a627
    FAIL_EXIT (2, "dlopen did not terminate the process: %s", dlerror ());
Packit Bot 45a627
  else
Packit Bot 45a627
    FAIL_EXIT (2, "dlopen did not terminate the process (%p)", handle);
Packit Bot 45a627
}
Packit Bot 45a627
Packit Bot 45a627
static void
Packit Bot 45a627
test_destructor (void *closure)
Packit Bot 45a627
{
Packit Bot 45a627
  void *handle = xdlopen ("tst-finilazyfailmod.so", RTLD_LAZY);
Packit Bot 45a627
  int ret = dlclose (handle);
Packit Bot 45a627
  const char *message = dlerror ();
Packit Bot 45a627
  if (message != NULL)
Packit Bot 45a627
    FAIL_EXIT (2, "dlclose did not terminate the process: %d, %s",
Packit Bot 45a627
               ret, message);
Packit Bot 45a627
  else
Packit Bot 45a627
    FAIL_EXIT (2, "dlopen did not terminate the process: %d", ret);
Packit Bot 45a627
}
Packit Bot 45a627
Packit Bot 45a627
static int
Packit Bot 45a627
do_test (void)
Packit Bot 45a627
{
Packit Bot 45a627
  {
Packit Bot 45a627
    struct support_capture_subprocess proc
Packit Bot 45a627
      = support_capture_subprocess (test_constructor, NULL);
Packit Bot 45a627
    support_capture_subprocess_check (&proc, "constructor", 127,
Packit Bot 45a627
                                      sc_allow_stderr);
Packit Bot 45a627
    printf ("info: constructor failure output: [[%s]]\n", proc.err.buffer);
Packit Bot 45a627
    TEST_VERIFY (strstr (proc.err.buffer,
Packit Bot 45a627
                         "tst-initfinilazyfail: symbol lookup error: ")
Packit Bot 45a627
                 != NULL);
Packit Bot 45a627
    TEST_VERIFY (strstr (proc.err.buffer,
Packit Bot 45a627
                         "tst-initlazyfailmod.so: undefined symbol:"
Packit Bot 45a627
                         " undefined_function\n") != NULL);
Packit Bot 45a627
    support_capture_subprocess_free (&proc;;
Packit Bot 45a627
  }
Packit Bot 45a627
Packit Bot 45a627
  {
Packit Bot 45a627
    struct support_capture_subprocess proc
Packit Bot 45a627
      = support_capture_subprocess (test_destructor, NULL);
Packit Bot 45a627
    support_capture_subprocess_check (&proc, "destructor", 127,
Packit Bot 45a627
                                      sc_allow_stderr);
Packit Bot 45a627
    printf ("info: destructor failure output: [[%s]]\n", proc.err.buffer);
Packit Bot 45a627
    TEST_VERIFY (strstr (proc.err.buffer,
Packit Bot 45a627
                         "tst-initfinilazyfail: symbol lookup error: ")
Packit Bot 45a627
                 != NULL);
Packit Bot 45a627
    TEST_VERIFY (strstr (proc.err.buffer,
Packit Bot 45a627
                         "tst-finilazyfailmod.so: undefined symbol:"
Packit Bot 45a627
                         " undefined_function\n") != NULL);
Packit Bot 45a627
    support_capture_subprocess_free (&proc;;
Packit Bot 45a627
  }
Packit Bot 45a627
Packit Bot 45a627
  return 0;
Packit Bot 45a627
}
Packit Bot 45a627
Packit Bot 45a627
#include <support/test-driver.c>