]>
Commit | Line | Data |
---|---|---|
7d3db434 FW |
1 | /* Common code for tst-dlopen-tlsmodid, tst-dlopen-tlsmodid-pie, |
2 | tst-dlopen-tlsmodid-container. | |
a42faf59 | 3 | |
55a81e3b | 4 | Verify that incorrectly dlopen()ing an executable without |
23d2e5fa FW |
5 | __RTLD_OPENEXEC does not cause assertion in ld.so, and that it |
6 | actually results in an error. | |
55a81e3b | 7 | |
2b778ceb | 8 | Copyright (C) 2014-2021 Free Software Foundation, Inc. |
a42faf59 PP |
9 | This file is part of the GNU C Library. |
10 | ||
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. | |
15 | ||
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. | |
20 | ||
21 | You should have received a copy of the GNU Lesser General Public | |
22 | License along with the GNU C Library; if not, see | |
5a82c748 | 23 | <https://www.gnu.org/licenses/>. */ |
a42faf59 | 24 | |
7d3db434 FW |
25 | /* Before including this file, the macro TST_DLOPEN_TLSMODID_PATH must |
26 | be defined, to specify the path used for the open operation. */ | |
27 | ||
a42faf59 | 28 | #include <dlfcn.h> |
a42faf59 | 29 | #include <pthread.h> |
9b9670fc FW |
30 | #include <stdio.h> |
31 | #include <stdlib.h> | |
23d2e5fa FW |
32 | #include <string.h> |
33 | #include <support/check.h> | |
9b9670fc | 34 | #include <support/support.h> |
d330f31a | 35 | #include <support/xthread.h> |
a42faf59 PP |
36 | |
37 | __thread int x; | |
38 | ||
39 | void * | |
40 | fn (void *p) | |
41 | { | |
42 | return p; | |
43 | } | |
44 | ||
7d3db434 FW |
45 | /* Call dlopen and check that fails with an error message indicating |
46 | an attempt to open an ET_EXEC or PIE object. */ | |
23d2e5fa | 47 | static void |
7d3db434 | 48 | check_dlopen_failure (void) |
23d2e5fa | 49 | { |
7d3db434 | 50 | void *handle = dlopen (TST_DLOPEN_TLSMODID_PATH, RTLD_LAZY); |
23d2e5fa | 51 | if (handle != NULL) |
7d3db434 | 52 | FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", TST_DLOPEN_TLSMODID_PATH); |
23d2e5fa FW |
53 | |
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); | |
61 | } | |
62 | ||
55a81e3b PP |
63 | static int |
64 | do_test (int argc, char *argv[]) | |
a42faf59 PP |
65 | { |
66 | int j; | |
67 | ||
68 | for (j = 0; j < 100; ++j) | |
69 | { | |
70 | pthread_t thr; | |
23d2e5fa | 71 | |
7d3db434 | 72 | check_dlopen_failure (); |
23d2e5fa | 73 | |
d330f31a CD |
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); | |
a42faf59 PP |
79 | } |
80 | ||
7d3db434 | 81 | check_dlopen_failure (); |
23d2e5fa | 82 | |
a42faf59 PP |
83 | return 0; |
84 | } | |
55a81e3b | 85 | |
12fb1801 | 86 | #define TEST_FUNCTION_ARGV do_test |
36fe25fd | 87 | #include <support/test-driver.c> |