Fix failing nss/tst-nss-files-hosts-long with local resolver
[glibc.git] / elf / tst-dlopen-self.c
bloba9978264772959385be2a7ed0a2b2811fb2ead4f
1 /* Check that dlopen'ing the executable itself fails (bug 24900).
2 Copyright (C) 2014-2021 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 <stdlib.h>
21 #include <string.h>
22 #include <support/check.h>
24 /* Call dlopen and check that fails with an error message indicating
25 an attempt to open an ET_EXEC or PIE object. */
26 static void
27 check_dlopen_failure (const char *path)
29 void *handle = dlopen (path, RTLD_LAZY);
30 if (handle != NULL)
31 FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", path);
33 const char *message = dlerror ();
34 TEST_VERIFY_EXIT (message != NULL);
35 if ((strstr (message,
36 "cannot dynamically load position-independent executable")
37 == NULL)
38 && strstr (message, "cannot dynamically load executable") == NULL)
39 FAIL_EXIT1 ("invalid dlopen error message: \"%s\"", message);
42 static int
43 do_test (int argc, char *argv[])
45 check_dlopen_failure (argv[0]);
47 char *full_path = realpath (argv[0], NULL);
48 check_dlopen_failure (full_path);
49 free (full_path);
51 return 0;
54 #define TEST_FUNCTION_ARGV do_test
55 #include <support/test-driver.c>