Blame elf/tst-initfinilazyfail.c

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