Blame elf/tst-initfinilazyfail.c

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