string: Fix tester build with fortify enable with gcc 6
[glibc.git] / elf / tst-single_threaded-static-dlopen.c
blob7193bf52a7c4426ac6cdbeb75cde8c0f055193e8
1 /* Test support for single-thread optimizations. No threads, static dlopen.
2 Copyright (C) 2020-2023 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 <https://www.gnu.org/licenses/>. */
19 /* In a static dlopen scenario, the single-threaded optimization is
20 not possible because their is no globally shared dynamic linker
21 across all namespaces. */
23 #include <stddef.h>
24 #include <support/check.h>
25 #include <support/xdlfcn.h>
26 #include <sys/single_threaded.h>
28 static int
29 do_test (void)
31 TEST_VERIFY (__libc_single_threaded);
33 /* Defined in tst-single-threaded-mod1.o. */
34 extern _Bool single_threaded_1 (void);
35 TEST_VERIFY (single_threaded_1 ());
37 /* A failed dlopen does not change the multi-threaded status. */
38 TEST_VERIFY (dlopen ("tst-single_threaded-does-not-exist.so", RTLD_LAZY)
39 == NULL);
40 TEST_VERIFY (__libc_single_threaded);
41 TEST_VERIFY (single_threaded_1 ());
43 /* And neither does a successful dlopen for outer (static) libc. */
44 void *handle_mod2 = xdlopen ("tst-single_threaded-mod2.so", RTLD_LAZY);
45 _Bool (*single_threaded_2) (void)
46 = xdlsym (handle_mod2, "single_threaded_2");
47 TEST_VERIFY (__libc_single_threaded);
48 TEST_VERIFY (single_threaded_1 ());
49 /* The inner libc always assumes multi-threaded use. */
50 TEST_VERIFY (!single_threaded_2 ());
52 xdlclose (handle_mod2);
54 return 0;
57 #include <support/test-driver.c>