posix/glob.c: update from gnulib
[glibc.git] / elf / tst-dlopenfail.c
blob15dfe71ad4fb1bc8a30a743da55e0fcf448c424a
1 /* Test dlopen rollback after failures involving NODELETE objects (bug 20839).
2 Copyright (C) 2019-2022 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 #include <dlfcn.h>
20 #include <errno.h>
21 #include <stddef.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <support/check.h>
25 #include <support/xdlfcn.h>
27 static int
28 do_test (void)
30 TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL);
32 /* This is expected to fail because of the missing dependency. */
33 puts ("info: attempting to load tst-dlopenfailmod1.so");
34 TEST_VERIFY (dlopen ("tst-dlopenfailmod1.so", RTLD_LAZY) == NULL);
35 const char *message = dlerror ();
36 TEST_COMPARE_STRING (message,
37 "tst-dlopenfail-missingmod.so:"
38 " cannot open shared object file:"
39 " No such file or directory");
41 /* Do not probe for the presence of the tst-dlopenfailnodelmod.so at
42 this point because that might trigger relocation if bug 20839 is
43 present, obscuring a subsequent crash. */
45 /* This is expected to succeed. */
46 puts ("info: loading tst-dlopenfailmod2.so");
47 void *handle = xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW);
48 xdlclose (handle);
50 /* The NODELETE module should remain loaded. */
51 TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_NOLOAD)
52 != NULL);
53 /* But the symbol is not in the global scope. */
54 TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL);
56 /* We can make tst-dlopenfailnodelmod.so global, and then the symbol
57 should become available. */
58 TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_GLOBAL)
59 != NULL);
60 void (*no_delete_mod_function) (void)
61 = dlsym (NULL, "no_delete_mod_function");
62 TEST_VERIFY_EXIT (no_delete_mod_function != NULL);
64 /* Hopefully, no_delete_mod_function is sufficiently complex to
65 depend on relocations. */
66 no_delete_mod_function ();
68 return 0;
71 #include <support/test-driver.c>