elf: Do not duplicate the GLIBC_TUNABLES string
[platform/upstream/glibc.git] / elf / tst-noload.c
1 /* Verify that RTLD_NOLOAD works as expected.
2
3    Copyright (C) 2016-2023 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <https://www.gnu.org/licenses/>.  */
19
20 #include <dlfcn.h>
21 #include <stdio.h>
22 #include <gnu/lib-names.h>
23
24 static int
25 do_test (void)
26 {
27   /* Test that no object is loaded with RTLD_NOLOAD.  */
28   void *h1 = dlopen (LIBM_SO, RTLD_LAZY | RTLD_NOLOAD);
29   if (h1 != NULL)
30     {
31       printf ("h1: DSO has been loaded while it should have not\n");
32       return 1;
33     }
34
35   /* This used to segfault in some glibc versions.  */
36   void *h2 = dlopen (LIBM_SO, RTLD_LAZY | RTLD_NOLOAD | RTLD_NODELETE);
37   if (h2 != NULL)
38     {
39       printf ("h2: DSO has been loaded while it should have not\n");
40       return 1;
41     }
42
43   /* Test that loading an already loaded object returns the same.  */
44   void *h3 = dlopen (LIBM_SO, RTLD_LAZY);
45   if (h3 == NULL)
46     {
47       printf ("h3: failed to open DSO: %s\n", dlerror ());
48       return 1;
49     }
50   void *h4 = dlopen (LIBM_SO, RTLD_LAZY | RTLD_NOLOAD);
51   if (h4 == NULL)
52     {
53       printf ("h4: failed to open DSO: %s\n", dlerror ());
54       return 1;
55     }
56   if (h4 != h3)
57     {
58       printf ("h4: should return the same object\n");
59       return 1;
60     }
61
62   /* Cleanup */
63   if (dlclose (h3) != 0)
64     {
65       printf ("h3: dlclose failed: %s\n", dlerror ());
66       return 1;
67     }
68
69   return 0;
70 }
71
72 #include <support/test-driver.c>