|
Packit Service |
97055e |
/* Test dlopen rollback after failures involving NODELETE objects (bug 20839).
|
|
Packit Service |
97055e |
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
Packit Service |
97055e |
This file is part of the GNU C Library.
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
97055e |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
97055e |
License as published by the Free Software Foundation; either
|
|
Packit Service |
97055e |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
97055e |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
97055e |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
97055e |
Lesser General Public License for more details.
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
97055e |
License along with the GNU C Library; if not, see
|
|
Packit Service |
97055e |
<https://www.gnu.org/licenses/>. */
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
#include <dlfcn.h>
|
|
Packit Service |
97055e |
#include <errno.h>
|
|
Packit Service |
97055e |
#include <gnu/lib-names.h>
|
|
Packit Service |
97055e |
#include <stddef.h>
|
|
Packit Service |
97055e |
#include <stdio.h>
|
|
Packit Service |
97055e |
#include <string.h>
|
|
Packit Service |
97055e |
#include <support/check.h>
|
|
Packit Service |
97055e |
#include <support/xdlfcn.h>
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
static int
|
|
Packit Service |
97055e |
do_test (void)
|
|
Packit Service |
97055e |
{
|
|
Packit Service |
97055e |
/* This test uses libpthread as the canonical NODELETE module. If
|
|
Packit Service |
97055e |
libpthread is no longer NODELETE because it has been merged into
|
|
Packit Service |
97055e |
libc, the test needs to be updated. */
|
|
Packit Service |
97055e |
TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL);
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* This is expected to fail because of the missing dependency. */
|
|
Packit Service |
97055e |
puts ("info: attempting to load tst-dlopenfailmod1.so");
|
|
Packit Service |
97055e |
TEST_VERIFY (dlopen ("tst-dlopenfailmod1.so", RTLD_LAZY) == NULL);
|
|
Packit Service |
97055e |
const char *message = dlerror ();
|
|
Packit Service |
97055e |
TEST_COMPARE_STRING (message,
|
|
Packit Service |
97055e |
"tst-dlopenfail-missingmod.so:"
|
|
Packit Service |
97055e |
" cannot open shared object file:"
|
|
Packit Service |
97055e |
" No such file or directory");
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* Do not probe for the presence of libpthread at this point because
|
|
Packit Service |
97055e |
that might trigger relocation if bug 20839 is present, obscuring
|
|
Packit Service |
97055e |
a subsequent crash. */
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* This is expected to succeed. */
|
|
Packit Service |
97055e |
puts ("info: loading tst-dlopenfailmod2.so");
|
|
Packit Service |
97055e |
void *handle = xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW);
|
|
Packit Service |
97055e |
xdlclose (handle);
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* libpthread should remain loaded. */
|
|
Packit Service |
97055e |
TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_NOLOAD) != NULL);
|
|
Packit Service |
97055e |
TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL);
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* We can make libpthread global, and then the symbol should become
|
|
Packit Service |
97055e |
available. */
|
|
Packit Service |
97055e |
TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_GLOBAL) != NULL);
|
|
Packit Service |
97055e |
TEST_VERIFY (dlsym (NULL, "pthread_create") != NULL);
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
/* sem_open is sufficiently complex to depend on relocations. */
|
|
Packit Service |
97055e |
void *(*sem_open_ptr) (const char *, int flag, ...)
|
|
Packit Service |
97055e |
= dlsym (NULL, "sem_open");
|
|
Packit Service |
97055e |
if (sem_open_ptr == NULL)
|
|
Packit Service |
97055e |
/* Hurd does not implement sem_open. */
|
|
Packit Service |
97055e |
puts ("warning: sem_open not found, further testing not possible");
|
|
Packit Service |
97055e |
else
|
|
Packit Service |
97055e |
{
|
|
Packit Service |
97055e |
errno = 0;
|
|
Packit Service |
97055e |
TEST_VERIFY (sem_open_ptr ("/", 0) == NULL);
|
|
Packit Service |
97055e |
TEST_COMPARE (errno, EINVAL);
|
|
Packit Service |
97055e |
}
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
return 0;
|
|
Packit Service |
97055e |
}
|
|
Packit Service |
97055e |
|
|
Packit Service |
97055e |
#include <support/test-driver.c>
|