elf: Use custom NODELETE DSO for tst-dlopenfail, tst-dlopenfail-2

Once libpthread is empty and no longer marked NODELETE, it no longer
can be used for testing.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
Florian Weimer 2021-05-21 22:35:00 +02:00
parent b8cdc3bba7
commit 7862ff8e69
5 changed files with 61 additions and 36 deletions

View File

@ -334,7 +334,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \ tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \
tst-initlazyfailmod tst-finilazyfailmod \ tst-initlazyfailmod tst-finilazyfailmod \
tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \ tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \
tst-dlopenfailmod3 tst-ldconfig-ld-mod \ tst-dlopenfailmod3 tst-dlopenfailnodelmod tst-ldconfig-ld-mod \
tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee \ tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee \
tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 \ tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 \
tst-single_threaded-mod1 tst-single_threaded-mod2 \ tst-single_threaded-mod1 tst-single_threaded-mod2 \
@ -1733,11 +1733,18 @@ LDFLAGS-tst-dlopenfailmod1.so = -Wl,--no-as-needed
$(objpfx)tst-dlopenfailmod1.so: \ $(objpfx)tst-dlopenfailmod1.so: \
$(shared-thread-library) $(objpfx)tst-dlopenfaillinkmod.so $(shared-thread-library) $(objpfx)tst-dlopenfaillinkmod.so
LDFLAGS-tst-dlopenfaillinkmod.so = -Wl,-soname,tst-dlopenfail-missingmod.so LDFLAGS-tst-dlopenfaillinkmod.so = -Wl,-soname,tst-dlopenfail-missingmod.so
$(objpfx)tst-dlopenfailmod2.so: $(shared-thread-library) $(objpfx)tst-dlopenfailmod2.so: $(objpfx)tst-dlopenfailnodelmod.so
$(objpfx)tst-dlopenfail-2: $(libdl) $(objpfx)tst-dlopenfail-2: $(libdl)
$(objpfx)tst-dlopenfail-2.out: \ $(objpfx)tst-dlopenfail-2.out: \
$(objpfx)tst-dlopenfailmod1.so $(objpfx)tst-dlopenfailmod2.so \ $(objpfx)tst-dlopenfailmod1.so $(objpfx)tst-dlopenfailmod2.so \
$(objpfx)tst-dlopenfailmod3.so $(objpfx)tst-dlopenfailmod3.so
# tst-dlopenfailnodelmod.so emulates how libpthread was linked.
$(objpfx)tst-dlopenfailnodelmod.so: $(libsupport)
LDFLAGS-tst-dlopenfailnodelmod.so = \
-Wl,--enable-new-dtags,-z,nodelete,-z,initfirst
# tst-dlopenfail should export the libsupport symbols, so that
# tst-dlopenfailnodelmod.so uses them for error reporting.
LDFLAGS-tst-dlopenfail = -Wl,-E
$(objpfx)tst-dlopen-nodelete-reloc: $(libdl) $(objpfx)tst-dlopen-nodelete-reloc: $(libdl)
$(objpfx)tst-dlopen-nodelete-reloc.out: \ $(objpfx)tst-dlopen-nodelete-reloc.out: \

View File

@ -28,10 +28,7 @@
static int static int
do_test (void) do_test (void)
{ {
/* This test uses libpthread as the canonical NODELETE module. If TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL);
libpthread is no longer NODELETE because it has been merged into
libc, the test needs to be updated. */
TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL);
/* This is expected to fail because of the missing dependency. */ /* This is expected to fail because of the missing dependency. */
puts ("info: attempting to load tst-dlopenfailmod1.so"); puts ("info: attempting to load tst-dlopenfailmod1.so");

View File

@ -18,7 +18,6 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <gnu/lib-names.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -28,10 +27,7 @@
static int static int
do_test (void) do_test (void)
{ {
/* This test uses libpthread as the canonical NODELETE module. If TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL);
libpthread is no longer NODELETE because it has been merged into
libc, the test needs to be updated. */
TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL);
/* This is expected to fail because of the missing dependency. */ /* This is expected to fail because of the missing dependency. */
puts ("info: attempting to load tst-dlopenfailmod1.so"); puts ("info: attempting to load tst-dlopenfailmod1.so");
@ -42,36 +38,32 @@ do_test (void)
" cannot open shared object file:" " cannot open shared object file:"
" No such file or directory"); " No such file or directory");
/* Do not probe for the presence of libpthread at this point because /* Do not probe for the presence of the tst-dlopenfailnodelmod.so at
that might trigger relocation if bug 20839 is present, obscuring this point because that might trigger relocation if bug 20839 is
a subsequent crash. */ present, obscuring a subsequent crash. */
/* This is expected to succeed. */ /* This is expected to succeed. */
puts ("info: loading tst-dlopenfailmod2.so"); puts ("info: loading tst-dlopenfailmod2.so");
void *handle = xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW); void *handle = xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW);
xdlclose (handle); xdlclose (handle);
/* libpthread should remain loaded. */ /* The NODELETE module should remain loaded. */
TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_NOLOAD) != NULL); TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_NOLOAD)
TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL); != NULL);
/* But the symbol is not in the global scope. */
TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL);
/* We can make libpthread global, and then the symbol should become /* We can make tst-dlopenfailnodelmod.so global, and then the symbol
available. */ should become available. */
TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_GLOBAL) != NULL); TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_GLOBAL)
TEST_VERIFY (dlsym (NULL, "pthread_create") != NULL); != NULL);
void (*no_delete_mod_function) (void)
= dlsym (NULL, "no_delete_mod_function");
TEST_VERIFY_EXIT (no_delete_mod_function != NULL);
/* sem_open is sufficiently complex to depend on relocations. */ /* Hopefully, no_delete_mod_function is sufficiently complex to
void *(*sem_open_ptr) (const char *, int flag, ...) depend on relocations. */
= dlsym (NULL, "sem_open"); no_delete_mod_function ();
if (sem_open_ptr == NULL)
/* Hurd does not implement sem_open. */
puts ("warning: sem_open not found, further testing not possible");
else
{
errno = 0;
TEST_VERIFY (sem_open_ptr ("/", 0) == NULL);
TEST_COMPARE (errno, EINVAL);
}
return 0; return 0;
} }

View File

@ -16,11 +16,11 @@
License along with the GNU C Library; if not, see License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */ <https://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <stdio.h> #include <stdio.h>
/* Force linking against libpthread. */ /* Force linking against tst-dlopenfailnodelmod.so. */
void *pthread_create_reference = pthread_create; void no_delete_mod_function (void);
void *function_reference = no_delete_mod_function;
static void __attribute__ ((constructor)) static void __attribute__ ((constructor))
init (void) init (void)

View File

@ -0,0 +1,29 @@
/* NODELETE module for tst-dlopenfail, tst-dlopenfail-2.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <support/check.h>
/* Introduce some relocation dependencies. */
const char test_string[] = "test string";
const char *test_string_ptr = test_string;
void
no_delete_mod_function (void)
{
TEST_COMPARE_STRING (test_string, test_string_ptr);
}