Blame elf/tst-initfinilazyfail.c

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