1 /* Verify that DSO is unloaded only if its TLS objects are destroyed.
2 Copyright (C) 2013-2015 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 /* There are two tests in this test case. The first is implicit where it is
20 assumed that the destructor call on exit of the LOAD function does not
21 segfault. The other is a verification that after the thread has exited, a
22 dlclose will unload the DSO. */
32 pthread_mutex_t m
= PTHREAD_MUTEX_INITIALIZER
;
37 pthread_mutex_lock (&m
);
38 handle
= dlopen ("$ORIGIN/tst-tls-atexit-lib.so", RTLD_LAZY
);
41 printf ("Unable to load DSO: %s\n", dlerror ());
42 return (void *) (uintptr_t) 1;
45 void (*foo
) (void) = (void (*) (void)) dlsym(handle
, "do_foo");
49 printf ("Unable to find symbol: %s\n", dlerror ());
55 /* This should not unload the DSO. If it does, then the thread exit will
56 result in a segfault. */
58 pthread_mutex_unlock (&m
);
70 if ((ret
= pthread_create (&t
, NULL
, load
, NULL
)) != 0)
72 printf ("pthread_create failed: %s\n", strerror (ret
));
76 if ((ret
= pthread_join (t
, &thr_ret
)) != 0)
78 printf ("pthread_create failed: %s\n", strerror (ret
));
85 /* Now this should unload the DSO. */
88 /* Run through our maps and ensure that the DSO is unloaded. */
89 FILE *f
= fopen ("/proc/self/maps", "r");
93 perror ("Failed to open /proc/self/maps");
94 fprintf (stderr
, "Skipping verification of DSO unload\n");
100 while (getline (&line
, &s
, f
) > 0)
102 if (strstr (line
, "tst-tls-atexit-lib.so"))
104 printf ("DSO not unloaded yet:\n%s", line
);
113 #define TEST_FUNCTION do_test ()
114 #include "../test-skeleton.c"