1 /* Check that dlopen'ing the executable itself fails (bug 24900).
2 Copyright (C) 2014-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/>. */
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. */
27 check_dlopen_failure (const char *path)
29 void *handle = dlopen (path, RTLD_LAZY);
31 FAIL_EXIT1 ("dlopen succeeded unexpectedly: %s", path);
33 const char *message = dlerror ();
34 TEST_VERIFY_EXIT (message != NULL);
36 "cannot dynamically load position-independent executable")
38 && strstr (message, "cannot dynamically load executable") == NULL)
39 FAIL_EXIT1 ("invalid dlopen error message: \"%s\"", message);
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);
54 #define TEST_FUNCTION_ARGV do_test
55 #include <support/test-driver.c>