localedata: fix weekdays in mdf_RU locale
[glibc.git] / elf / tst-tlsgap.c
blob4bf97cde1a912cd90b5588d41382fa20e812b2ee
1 /* TLS modid gap reuse regression test for bug 29039.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stdio.h>
20 #include <dlfcn.h>
21 #include <pthread.h>
22 #include <support/xdlfcn.h>
23 #include <support/xthread.h>
24 #include <support/check.h>
26 static void *mod[3];
27 #define MOD(i) "tst-tlsgap-mod" #i ".so"
28 static const char *modname[3] = { MOD(0), MOD(1), MOD(2) };
29 #undef MOD
31 static void
32 open_mod (int i)
34 mod[i] = xdlopen (modname[i], RTLD_LAZY);
35 printf ("open %s\n", modname[i]);
38 static void
39 close_mod (int i)
41 xdlclose (mod[i]);
42 mod[i] = NULL;
43 printf ("close %s\n", modname[i]);
46 static void
47 access_mod (int i, const char *sym)
49 int *(*f) (void) = xdlsym (mod[i], sym);
50 int *p = f ();
51 printf ("access %s: %s() = %p\n", modname[i], sym, p);
52 TEST_VERIFY_EXIT (p != NULL);
53 ++*p;
56 static void *
57 start (void *arg)
59 /* The DTV generation is at the last dlopen of mod0 and the
60 entry for mod1 is NULL. */
62 open_mod (1); /* Reuse modid of mod1. Uses dynamic TLS. */
64 /* DTV is unchanged: dlopen only updates the DTV to the latest
65 generation if static TLS is allocated for a loaded module.
67 With bug 29039, the TLSDESC relocation in mod1 uses the old
68 dlclose generation of mod1 instead of the new dlopen one so
69 DTV is not updated on TLS access. */
71 access_mod (1, "f1");
73 return arg;
76 static int
77 do_test (void)
79 open_mod (0);
80 open_mod (1);
81 open_mod (2);
82 close_mod (0);
83 close_mod (1); /* Create modid gap at mod1. */
84 open_mod (0); /* Reuse modid of mod0, bump generation count. */
86 /* Create a thread where DTV of mod1 is NULL. */
87 pthread_t t = xpthread_create (NULL, start, NULL);
88 xpthread_join (t);
89 return 0;
92 #include <support/test-driver.c>