platform.texi: Move LAM after LAHF64_SAHF64
[glibc.git] / elf / tst-dlopen-tlsmodid.h
blob3d37a2608cdf71cafed0a3d5f2a7dfe18f1df0cf
1 /* Common code for tst-dlopen-tlsmodid, tst-dlopen-tlsmodid-pie,
2 tst-dlopen-tlsmodid-container.
4 Verify that incorrectly dlopen()ing an executable without
5 __RTLD_OPENEXEC does not cause assertion in ld.so, and that it
6 actually results in an error.
8 Copyright (C) 2014-2023 Free Software Foundation, Inc.
9 This file is part of the GNU C Library.
11 The GNU C Library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
16 The GNU C Library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with the GNU C Library; if not, see
23 <https://www.gnu.org/licenses/>. */
25 /* Before including this file, the macro TST_DLOPEN_TLSMODID_PATH must
26 be defined, to specify the path used for the open operation. */
28 #include <dlfcn.h>
29 #include <pthread.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <support/check.h>
34 #include <support/support.h>
35 #include <support/xthread.h>
37 __thread int x;
39 void *
40 fn (void *p)
42 return p;
45 /* Call dlopen and check that fails with an error message indicating
46 an attempt to open an ET_EXEC or PIE object. */
47 static void
48 check_dlopen_failure (void)
50 void *handle = dlopen (TST_DLOPEN_TLSMODID_PATH, RTLD_LAZY);
51 if (handle != NULL)
52 FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", TST_DLOPEN_TLSMODID_PATH);
54 const char *message = dlerror ();
55 TEST_VERIFY_EXIT (message != NULL);
56 if ((strstr (message,
57 "cannot dynamically load position-independent executable")
58 == NULL)
59 && strstr (message, "cannot dynamically load executable") == NULL)
60 FAIL_EXIT1 ("invalid dlopen error message: \"%s\"", message);
63 static int
64 do_test (int argc, char *argv[])
66 int j;
68 for (j = 0; j < 100; ++j)
70 pthread_t thr;
72 check_dlopen_failure ();
74 /* We create threads to force TLS allocation, which triggers
75 the original bug i.e. running out of surplus slotinfo entries
76 for TLS. */
77 thr = xpthread_create (NULL, fn, NULL);
78 xpthread_join (thr);
81 check_dlopen_failure ();
83 return 0;
86 #define TEST_FUNCTION_ARGV do_test
87 #include <support/test-driver.c>