summaryrefslogtreecommitdiff
path: root/elf/tst-tls20.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2020-12-31 12:24:38 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-04-15 09:30:43 +0100
commit8f85075a2e9c26ff7486d4bbaf358999807d215c (patch)
tree02f2f750220acc24e6a57f886167aba51b118917 /elf/tst-tls20.c
parentd2b997c7172e9a00895a9deb379f8782fbd2e36f (diff)
downloadglibc-8f85075a2e9c26ff7486d4bbaf358999807d215c.tar.gz
elf: Add a DTV setup test [BZ #27136]
The test dlopens a large number of modules with TLS, they are reused from an existing test. The test relies on the reuse of slotinfo entries after dlclose, without bug 27135 fixed this needs a failing dlopen. With a slotinfo list that has non-monotone increasing generation counters, bug 27136 can trigger. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'elf/tst-tls20.c')
-rw-r--r--elf/tst-tls20.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/elf/tst-tls20.c b/elf/tst-tls20.c
new file mode 100644
index 0000000000..ac5f8c8d39
--- /dev/null
+++ b/elf/tst-tls20.c
@@ -0,0 +1,98 @@
+/* Test dtv setup if entries don't have monotone increasing generation.
+ 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 <stdlib.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+#include <support/xthread.h>
+
+#define NMOD 100
+static void *mod[NMOD];
+
+static void
+load_fail (void)
+{
+ /* Expected to fail because of a missing symbol. */
+ void *m = dlopen ("tst-tls20mod-bad.so", RTLD_NOW);
+ if (m != NULL)
+ FAIL_EXIT1 ("dlopen of tst-tls20mod-bad.so succeeded\n");
+}
+
+static void
+load_mod (int i)
+{
+ char *buf = xasprintf ("tst-tls-manydynamic%02dmod.so", i);
+ mod[i] = xdlopen (buf, RTLD_LAZY);
+ free (buf);
+}
+
+static void
+unload_mod (int i)
+{
+ if (mod[i] != NULL)
+ xdlclose (mod[i]);
+ mod[i] = NULL;
+}
+
+static void
+access (int i)
+{
+ char *buf = xasprintf ("tls_global_%02d", i);
+ dlerror ();
+ int *p = dlsym (mod[i], buf);
+ printf ("mod[%d]: &tls = %p\n", i, p);
+ if (p == NULL)
+ FAIL_EXIT1 ("dlsym failed: %s\n", dlerror ());
+ ++*p;
+ free (buf);
+}
+
+static void *
+start (void *a)
+{
+ for (int i = 0; i < NMOD; i++)
+ if (mod[i] != NULL)
+ access (i);
+ return 0;
+}
+
+static int
+do_test (void)
+{
+ int i;
+
+ for (i = 0; i < NMOD; i++)
+ {
+ load_mod (i);
+ /* Bump the generation of mod[0] without using new dtv slot. */
+ unload_mod (0);
+ load_fail (); /* Ensure GL(dl_tls_dtv_gaps) is true: see bug 27135. */
+ load_mod (0);
+ /* Access TLS in all loaded modules. */
+ pthread_t t = xpthread_create (0, start, 0);
+ xpthread_join (t);
+ }
+ for (i = 0; i < NMOD; i++)
+ unload_mod (i);
+ return 0;
+}
+
+#include <support/test-driver.c>