hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame elf/tst-initfinilazyfail.c

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