]>
Commit | Line | Data |
---|---|---|
b2964eb1 | 1 | /* Check that dlfcn errors are reported properly after dlmopen. Test module. |
6d7e8eda | 2 | Copyright (C) 2021-2023 Free Software Foundation, Inc. |
b2964eb1 FW |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #include <dlfcn.h> | |
20 | #include <stddef.h> | |
fada9018 FW |
21 | #include <stdio.h> |
22 | #include <string.h> | |
b2964eb1 FW |
23 | #include <support/check.h> |
24 | ||
25 | /* Note: This object is not linked into the main program, so we cannot | |
26 | use delayed test failure reporting via TEST_VERIFY etc., and have | |
27 | to use FAIL_EXIT1 (or something else that calls exit). */ | |
28 | ||
29 | void | |
fada9018 | 30 | call_dlsym (const char *name) |
b2964eb1 | 31 | { |
fada9018 | 32 | void *ptr = dlsym (NULL, name); |
b2964eb1 | 33 | if (ptr != NULL) |
fada9018 FW |
34 | FAIL_EXIT1 ("dlsym did not fail as expected for: %s", name); |
35 | const char *message = dlerror (); | |
36 | if (strstr (message, ": undefined symbol: does not exist X") == NULL) | |
37 | FAIL_EXIT1 ("invalid dlsym error message for [[%s]]: %s", name, message); | |
38 | message = dlerror (); | |
39 | if (message != NULL) | |
40 | FAIL_EXIT1 ("second dlsym for [[%s]]: %s", name, message); | |
b2964eb1 FW |
41 | } |
42 | ||
43 | void | |
fada9018 | 44 | call_dlopen (const char *name) |
b2964eb1 | 45 | { |
fada9018 | 46 | void *handle = dlopen (name, RTLD_NOW); |
b2964eb1 | 47 | if (handle != NULL) |
fada9018 FW |
48 | FAIL_EXIT1 ("dlopen did not fail as expected for: %s", name); |
49 | const char *message = dlerror (); | |
50 | if (strstr (message, "X: cannot open shared object file:" | |
51 | " No such file or directory") == NULL | |
52 | && strstr (message, "X: cannot open shared object file:" | |
53 | " File name too long") == NULL) | |
54 | FAIL_EXIT1 ("invalid dlopen error message for [[%s]]: %s", name, message); | |
55 | message = dlerror (); | |
56 | if (message != NULL) | |
57 | FAIL_EXIT1 ("second dlopen for [[%s]]: %s", name, message); | |
b2964eb1 | 58 | } |