1 /* Test dlopen rollback after failures involving NODELETE objects (bug 20839).
2 Copyright (C) 2019-2020 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/>. */
21 #include <gnu/lib-names.h>
25 #include <support/check.h>
26 #include <support/xdlfcn.h>
31 /* This test uses libpthread as the canonical NODELETE module. If
32 libpthread is no longer NODELETE because it has been merged into
33 libc, the test needs to be updated. */
34 TEST_VERIFY (dlsym (NULL
, "pthread_create") == NULL
);
36 /* This is expected to fail because of the missing dependency. */
37 puts ("info: attempting to load tst-dlopenfailmod1.so");
38 TEST_VERIFY (dlopen ("tst-dlopenfailmod1.so", RTLD_LAZY
) == NULL
);
39 const char *message
= dlerror ();
40 TEST_COMPARE_STRING (message
,
41 "tst-dlopenfail-missingmod.so:"
42 " cannot open shared object file:"
43 " No such file or directory");
45 /* Do not probe for the presence of libpthread at this point because
46 that might trigger relocation if bug 20839 is present, obscuring
47 a subsequent crash. */
49 /* This is expected to succeed. */
50 puts ("info: loading tst-dlopenfailmod2.so");
51 void *handle
= xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW
);
54 /* libpthread should remain loaded. */
55 TEST_VERIFY (dlopen (LIBPTHREAD_SO
, RTLD_LAZY
| RTLD_NOLOAD
) != NULL
);
56 TEST_VERIFY (dlsym (NULL
, "pthread_create") == NULL
);
58 /* We can make libpthread global, and then the symbol should become
60 TEST_VERIFY (dlopen (LIBPTHREAD_SO
, RTLD_LAZY
| RTLD_GLOBAL
) != NULL
);
61 TEST_VERIFY (dlsym (NULL
, "pthread_create") != NULL
);
63 /* sem_open is sufficiently complex to depend on relocations. */
64 void *(*sem_open_ptr
) (const char *, int flag
, ...)
65 = dlsym (NULL
, "sem_open");
66 if (sem_open_ptr
== NULL
)
67 /* Hurd does not implement sem_open. */
68 puts ("warning: sem_open not found, further testing not possible");
72 TEST_VERIFY (sem_open_ptr ("/", 0) == NULL
);
73 TEST_COMPARE (errno
, EINVAL
);
79 #include <support/test-driver.c>