aboutsummaryrefslogtreecommitdiff
path: root/elf/tst-tls21.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2016-12-13 12:28:41 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-05-11 17:16:37 +0100
commit9d0e30329c23b5ad736fda3f174208c25970dbce (patch)
tree884dd5a22724d0bacbeeb921313c371b2ccbd02f /elf/tst-tls21.c
parentf4f8f4d4e0f92488431b268c8cd9555730b9afe9 (diff)
downloadglibc-9d0e30329c23b5ad736fda3f174208c25970dbce.tar
glibc-9d0e30329c23b5ad736fda3f174208c25970dbce.tar.gz
glibc-9d0e30329c23b5ad736fda3f174208c25970dbce.tar.bz2
glibc-9d0e30329c23b5ad736fda3f174208c25970dbce.zip
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>
Diffstat (limited to 'elf/tst-tls21.c')
-rw-r--r--elf/tst-tls21.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/elf/tst-tls21.c b/elf/tst-tls21.c
new file mode 100644
index 0000000000..560bf5813a
--- /dev/null
+++ b/elf/tst-tls21.c
@@ -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>