1 /* Test dlopen rollback after failures involving NODELETE objects (bug 20839).
2 Copyright (C) 2019-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/>. */
24 #include <support/check.h>
25 #include <support/xdlfcn.h>
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
);
50 /* The NODELETE module should remain loaded. */
51 TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY
| RTLD_NOLOAD
)
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
)
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 ();
71 #include <support/test-driver.c>