mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-07 13:28:05 +08:00
Rename and split elf/tst-dlopen-aout collection of tests
From the beginning, elf/tst-dlopen-aout has exercised two different bugs: (a) failure to report errors for a dlopen of the executable itself in some cases (bug 24900) and (b) incorrect rollback of the TLS modid allocation in case of a dlopen failure (bug 16634). This commit replaces the test with elf/tst-dlopen-self for (a) and elf/tst-dlopen-tlsmodid for (b). The latter tests use the elf/tst-dlopen-self binaries (or iconv) with dlopen, so they are no longer self-dlopen tests. Tested on x86_64-linux-gnu and i686-linux-gnu, with a toolchain that does not default to PIE.
This commit is contained in:
parent
eb77a1fccc
commit
7d3db434f9
32
elf/Makefile
32
elf/Makefile
@ -192,14 +192,16 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
|
|||||||
tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \
|
tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \
|
||||||
tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
|
tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
|
||||||
tst-unwind-ctor tst-unwind-main tst-audit13 \
|
tst-unwind-ctor tst-unwind-main tst-audit13 \
|
||||||
tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-aout
|
tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-tlsmodid \
|
||||||
|
tst-dlopen-self
|
||||||
# reldep9
|
# reldep9
|
||||||
tests-internal += loadtest unload unload2 circleload1 \
|
tests-internal += loadtest unload unload2 circleload1 \
|
||||||
neededtest neededtest2 neededtest3 neededtest4 \
|
neededtest neededtest2 neededtest3 neededtest4 \
|
||||||
tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \
|
tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \
|
||||||
tst-ptrguard1 tst-stackguard1 tst-libc_dlvsym \
|
tst-ptrguard1 tst-stackguard1 tst-libc_dlvsym \
|
||||||
tst-create_format1
|
tst-create_format1
|
||||||
tests-container += tst-pldd tst-dlopen-aout-container
|
tests-container += tst-pldd tst-dlopen-tlsmodid-container \
|
||||||
|
tst-dlopen-self-container
|
||||||
test-srcs = tst-pathopt
|
test-srcs = tst-pathopt
|
||||||
selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
|
selinux-enabled := $(shell cat /selinux/enforce 2> /dev/null)
|
||||||
ifneq ($(selinux-enabled),1)
|
ifneq ($(selinux-enabled),1)
|
||||||
@ -308,8 +310,9 @@ test-xfail-tst-protected1b = yes
|
|||||||
endif
|
endif
|
||||||
ifeq (yesyes,$(have-fpie)$(build-shared))
|
ifeq (yesyes,$(have-fpie)$(build-shared))
|
||||||
modules-names += tst-piemod1
|
modules-names += tst-piemod1
|
||||||
tests += tst-pie1 tst-pie2 tst-dlopen-pie tst-dlopen-aout-pie
|
tests += tst-pie1 tst-pie2 tst-dlopen-pie tst-dlopen-tlsmodid-pie \
|
||||||
tests-pie += tst-pie1 tst-pie2 tst-dlopen-aout-pie
|
tst-dlopen-self-pie
|
||||||
|
tests-pie += tst-pie1 tst-pie2 tst-dlopen-tlsmodid-pie tst-dlopen-self-pie
|
||||||
ifeq (yes,$(have-protected-data))
|
ifeq (yes,$(have-protected-data))
|
||||||
tests += vismain
|
tests += vismain
|
||||||
tests-pie += vismain
|
tests-pie += vismain
|
||||||
@ -1268,12 +1271,21 @@ $(objpfx)tst-addr1: $(libdl)
|
|||||||
|
|
||||||
$(objpfx)tst-thrlock: $(libdl) $(shared-thread-library)
|
$(objpfx)tst-thrlock: $(libdl) $(shared-thread-library)
|
||||||
|
|
||||||
tst-tst-dlopen-aout-no-pie = yes
|
tst-tst-dlopen-tlsmodid-no-pie = yes
|
||||||
$(objpfx)tst-dlopen-aout: $(libdl) $(shared-thread-library)
|
$(objpfx)tst-dlopen-tlsmodid: $(libdl) $(shared-thread-library)
|
||||||
CFLAGS-tst-dlopen-aout-pie.c += $(pie-ccflag)
|
$(objpfx)tst-dlopen-tlsmodid.out: $(objpfx)tst-dlopen-self
|
||||||
$(objpfx)tst-dlopen-aout-pie: $(libdl) $(shared-thread-library)
|
CFLAGS-tst-dlopen-tlsmodid-pie.c += $(pie-ccflag)
|
||||||
$(objpfx)tst-dlopen-aout-container: $(libdl) $(shared-thread-library)
|
$(objpfx)tst-dlopen-tlsmodid-pie: $(libdl) $(shared-thread-library)
|
||||||
LDFLAGS-tst-dlopen-aout-container += -Wl,-rpath,\$$ORIGIN
|
$(objpfx)tst-dlopen-tlsmodid-pie.out: $(objpfx)tst-dlopen-self-pie
|
||||||
|
$(objpfx)tst-dlopen-tlsmodid-container: $(libdl) $(shared-thread-library)
|
||||||
|
LDFLAGS-tst-dlopen-tlsmodid-container += -Wl,-rpath,\$$ORIGIN
|
||||||
|
|
||||||
|
tst-tst-dlopen-self-no-pie = yes
|
||||||
|
$(objpfx)tst-dlopen-self: $(libdl)
|
||||||
|
CFLAGS-tst-dlopen-self-pie.c += $(pie-ccflag)
|
||||||
|
$(objpfx)tst-dlopen-self-pie: $(libdl)
|
||||||
|
$(objpfx)tst-dlopen-self-container: $(libdl)
|
||||||
|
LDFLAGS-tst-dlopen-self-container += -Wl,-rpath,\$$ORIGIN
|
||||||
|
|
||||||
CFLAGS-ifuncmain1pic.c += $(pic-ccflag)
|
CFLAGS-ifuncmain1pic.c += $(pic-ccflag)
|
||||||
CFLAGS-ifuncmain1picstatic.c += $(pic-ccflag)
|
CFLAGS-ifuncmain1picstatic.c += $(pic-ccflag)
|
||||||
|
19
elf/tst-dlopen-self-container.c
Normal file
19
elf/tst-dlopen-self-container.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* Check dlopen'ing the executable itself fails (bug 24900); container version.
|
||||||
|
Copyright (C) 2014-2019 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 "tst-dlopen-self.c"
|
@ -1,4 +1,4 @@
|
|||||||
/* Test case for BZ #16634 and BZ#24900. Container version.
|
/* Check that dlopen'ing the executable itself fails (bug 24900); PIE version.
|
||||||
Copyright (C) 2014-2019 Free Software Foundation, Inc.
|
Copyright (C) 2014-2019 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
@ -16,4 +16,4 @@
|
|||||||
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 "tst-dlopen-aout.c"
|
#include "tst-dlopen-self.c"
|
55
elf/tst-dlopen-self.c
Normal file
55
elf/tst-dlopen-self.c
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* Check that dlopen'ing the executable itself fails (bug 24900).
|
||||||
|
Copyright (C) 2014-2019 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 <dlfcn.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <support/check.h>
|
||||||
|
|
||||||
|
/* Call dlopen and check that fails with an error message indicating
|
||||||
|
an attempt to open an ET_EXEC or PIE object. */
|
||||||
|
static void
|
||||||
|
check_dlopen_failure (const char *path)
|
||||||
|
{
|
||||||
|
void *handle = dlopen (path, RTLD_LAZY);
|
||||||
|
if (handle != NULL)
|
||||||
|
FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", path);
|
||||||
|
|
||||||
|
const char *message = dlerror ();
|
||||||
|
TEST_VERIFY_EXIT (message != NULL);
|
||||||
|
if ((strstr (message,
|
||||||
|
"cannot dynamically load position-independent executable")
|
||||||
|
== NULL)
|
||||||
|
&& strstr (message, "cannot dynamically load executable") == NULL)
|
||||||
|
FAIL_EXIT1 ("invalid dlopen error message: \"%s\"", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
check_dlopen_failure (argv[0]);
|
||||||
|
|
||||||
|
char *full_path = realpath (argv[0], NULL);
|
||||||
|
check_dlopen_failure (full_path);
|
||||||
|
free (full_path);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION_ARGV do_test
|
||||||
|
#include <support/test-driver.c>
|
39
elf/tst-dlopen-tlsmodid-container.c
Normal file
39
elf/tst-dlopen-tlsmodid-container.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Test case for BZ #16634. Container version.
|
||||||
|
Copyright (C) 2014-2019 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/>. */
|
||||||
|
|
||||||
|
/* This test uses the iconv program as the test binary. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <support/support.h>
|
||||||
|
|
||||||
|
static char *iconv_path;
|
||||||
|
|
||||||
|
static __attribute__ ((constructor)) void
|
||||||
|
iconv_path_init (void)
|
||||||
|
{
|
||||||
|
iconv_path = xasprintf ("%s/iconv", support_bindir_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static __attribute__ ((destructor)) void
|
||||||
|
iconv_path_fini (void)
|
||||||
|
{
|
||||||
|
free (iconv_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TST_DLOPEN_TLSMODID_PATH iconv_path
|
||||||
|
#include "tst-dlopen-tlsmodid.h"
|
@ -1,4 +1,4 @@
|
|||||||
/* Test case for BZ #16634 and BZ#24900. PIE version.
|
/* Test case for BZ #16634. PIE version.
|
||||||
Copyright (C) 2014-2019 Free Software Foundation, Inc.
|
Copyright (C) 2014-2019 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
@ -16,4 +16,5 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include "tst-dlopen-aout.c"
|
#define TST_DLOPEN_TLSMODID_PATH "tst-dlopen-self-pie"
|
||||||
|
#include "tst-dlopen-tlsmodid.h"
|
25
elf/tst-dlopen-tlsmodid.c
Normal file
25
elf/tst-dlopen-tlsmodid.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* Test case for BZ #16634. Non-PIE version.
|
||||||
|
|
||||||
|
Verify that incorrectly dlopen()ing an executable without
|
||||||
|
__RTLD_OPENEXEC does not cause assertion in ld.so, and that it
|
||||||
|
actually results in an error.
|
||||||
|
|
||||||
|
Copyright (C) 2014-2019 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/>. */
|
||||||
|
|
||||||
|
#define TST_DLOPEN_TLSMODID_PATH "tst-dlopen-self"
|
||||||
|
#include "tst-dlopen-tlsmodid.h"
|
@ -1,4 +1,5 @@
|
|||||||
/* Test case for BZ #16634 and BZ#24900.
|
/* Common code for tst-dlopen-tlsmodid, tst-dlopen-tlsmodid-pie,
|
||||||
|
tst-dlopen-tlsmodid-container.
|
||||||
|
|
||||||
Verify that incorrectly dlopen()ing an executable without
|
Verify that incorrectly dlopen()ing an executable without
|
||||||
__RTLD_OPENEXEC does not cause assertion in ld.so, and that it
|
__RTLD_OPENEXEC does not cause assertion in ld.so, and that it
|
||||||
@ -21,6 +22,9 @@
|
|||||||
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/>. */
|
||||||
|
|
||||||
|
/* Before including this file, the macro TST_DLOPEN_TLSMODID_PATH must
|
||||||
|
be defined, to specify the path used for the open operation. */
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -38,14 +42,14 @@ fn (void *p)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call dlopen on PATH and check that fails with an error message
|
/* Call dlopen and check that fails with an error message indicating
|
||||||
indicating an attempt to open an ET_EXEC or PIE object. */
|
an attempt to open an ET_EXEC or PIE object. */
|
||||||
static void
|
static void
|
||||||
check_dlopen_failure (const char *path)
|
check_dlopen_failure (void)
|
||||||
{
|
{
|
||||||
void *handle = dlopen (path, RTLD_LAZY);
|
void *handle = dlopen (TST_DLOPEN_TLSMODID_PATH, RTLD_LAZY);
|
||||||
if (handle != NULL)
|
if (handle != NULL)
|
||||||
FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", path);
|
FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", TST_DLOPEN_TLSMODID_PATH);
|
||||||
|
|
||||||
const char *message = dlerror ();
|
const char *message = dlerror ();
|
||||||
TEST_VERIFY_EXIT (message != NULL);
|
TEST_VERIFY_EXIT (message != NULL);
|
||||||
@ -65,7 +69,7 @@ do_test (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
pthread_t thr;
|
pthread_t thr;
|
||||||
|
|
||||||
check_dlopen_failure (argv[0]);
|
check_dlopen_failure ();
|
||||||
|
|
||||||
/* We create threads to force TLS allocation, which triggers
|
/* We create threads to force TLS allocation, which triggers
|
||||||
the original bug i.e. running out of surplus slotinfo entries
|
the original bug i.e. running out of surplus slotinfo entries
|
||||||
@ -74,9 +78,7 @@ do_test (int argc, char *argv[])
|
|||||||
xpthread_join (thr);
|
xpthread_join (thr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The elf subdirectory (or $ORIGIN in the container case) is on the
|
check_dlopen_failure ();
|
||||||
library search path. */
|
|
||||||
check_dlopen_failure ("tst-dlopen-aout");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user