mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
elf: Add test case for [BZ #19329]
Test concurrent dlopen and pthread_create when the loaded modules have TLS. This triggers dl-tls assertion failures more reliably than the nptl/tst-stack4 test. The dlopened module has 100 DT_NEEDED dependencies with TLS, they were reused from an existing TLS test. The number of created threads during dlopen depends on filesystem speed and hardware, but at most 3 threads are alive at a time to limit resource usage. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
parent
f4f8f4d4e0
commit
9d0e30329c
@ -224,7 +224,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
|
|||||||
tst-single_threaded tst-single_threaded-pthread \
|
tst-single_threaded tst-single_threaded-pthread \
|
||||||
tst-tls-ie tst-tls-ie-dlmopen argv0test \
|
tst-tls-ie tst-tls-ie-dlmopen argv0test \
|
||||||
tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \
|
tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \
|
||||||
tst-tls20 tst-dlmopen-dlerror
|
tst-tls20 tst-tls21 tst-dlmopen-dlerror
|
||||||
# reldep9
|
# reldep9
|
||||||
tests-internal += loadtest unload unload2 circleload1 \
|
tests-internal += loadtest unload unload2 circleload1 \
|
||||||
neededtest neededtest2 neededtest3 neededtest4 \
|
neededtest neededtest2 neededtest3 neededtest4 \
|
||||||
@ -346,7 +346,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
|
|||||||
libmarkermod2-1 libmarkermod2-2 \
|
libmarkermod2-1 libmarkermod2-2 \
|
||||||
libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \
|
libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \
|
||||||
libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \
|
libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \
|
||||||
tst-tls20mod-bad tst-dlmopen-dlerror-mod \
|
tst-tls20mod-bad tst-tls21mod tst-dlmopen-dlerror-mod \
|
||||||
|
|
||||||
# Most modules build with _ISOMAC defined, but those filtered out
|
# Most modules build with _ISOMAC defined, but those filtered out
|
||||||
# depend on internal headers.
|
# depend on internal headers.
|
||||||
@ -1939,3 +1939,8 @@ tst-tls20mod-bad.so-no-z-defs = yes
|
|||||||
$(objpfx)tst-tls20: $(libdl) $(shared-thread-library)
|
$(objpfx)tst-tls20: $(libdl) $(shared-thread-library)
|
||||||
$(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \
|
$(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \
|
||||||
$(tst-tls-many-dynamic-modules:%=$(objpfx)%.so)
|
$(tst-tls-many-dynamic-modules:%=$(objpfx)%.so)
|
||||||
|
|
||||||
|
# Reuses tst-tls-many-dynamic-modules
|
||||||
|
$(objpfx)tst-tls21: $(libdl) $(shared-thread-library)
|
||||||
|
$(objpfx)tst-tls21.out: $(objpfx)tst-tls21mod.so
|
||||||
|
$(objpfx)tst-tls21mod.so: $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so)
|
||||||
|
68
elf/tst-tls21.c
Normal file
68
elf/tst-tls21.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* Test concurrent dlopen and pthread_create: BZ 19329.
|
||||||
|
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
|
||||||
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#include <support/xdlfcn.h>
|
||||||
|
#include <support/xthread.h>
|
||||||
|
|
||||||
|
#define THREADS 10000
|
||||||
|
|
||||||
|
static atomic_int done;
|
||||||
|
|
||||||
|
static void *
|
||||||
|
start (void *a)
|
||||||
|
{
|
||||||
|
/* Load a module with many dependencies that each have TLS. */
|
||||||
|
xdlopen ("tst-tls21mod.so", RTLD_LAZY);
|
||||||
|
atomic_store_explicit (&done, 1, memory_order_release);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
|
nop (void *a)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
pthread_t t1, t2;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Load a module with lots of dependencies and TLS. */
|
||||||
|
t1 = xpthread_create (0, start, 0);
|
||||||
|
|
||||||
|
/* Concurrently create lots of threads until dlopen is observably done. */
|
||||||
|
for (i = 0; i < THREADS; i++)
|
||||||
|
{
|
||||||
|
if (atomic_load_explicit (&done, memory_order_acquire) != 0)
|
||||||
|
break;
|
||||||
|
t2 = xpthread_create (0, nop, 0);
|
||||||
|
xpthread_join (t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
xpthread_join (t1);
|
||||||
|
printf ("threads created during dlopen: %d\n", i);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <support/test-driver.c>
|
1
elf/tst-tls21mod.c
Normal file
1
elf/tst-tls21mod.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
int __thread x;
|
Loading…
Reference in New Issue
Block a user