1 /* Bug 11941: Improper assert map->l_init_called in dlclose.
2 Copyright (C) 2016-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/>. */
19 /* This is the primary DSO that is loaded by the appliation. This DSO
20 then loads a plugin with RTLD_NODELETE. This plugin depends on this
21 DSO. This dependency chain means that at application shutdown the
22 plugin will be destructed first. Thus by the time this DSO is
23 destructed we will be calling dlclose on an object that has already
24 been destructed. It is allowed to call dlclose in this way and
31 static void *plugin_lib
= NULL
;
32 /* Plugin function. */
33 static void (*plugin_func
) (void);
34 #define LIB_PLUGIN "tst-nodelete-dlclose-plugin.so"
36 /* This function is never called but the plugin references it.
37 We do this to avoid any future --as-needed from removing the
38 plugin's DT_NEEDED on this DSO (required for the test). */
40 primary_reference (void)
42 printf ("INFO: Called primary_reference function.\n");
50 plugin_lib
= dlopen (LIB_PLUGIN
, RTLD_NOW
| RTLD_LOCAL
| RTLD_NODELETE
);
51 if (plugin_lib
== NULL
)
53 printf ("ERROR: Unable to load plugin library.\n");
58 plugin_func
= (void (*) (void)) dlsym (plugin_lib
, "plugin_func");
62 printf ("ERROR: Unable to find symbol with error \"%s\".",
70 __attribute__ ((destructor
))
76 printf ("INFO: Calling primary destructor.\n");
78 /* The destructor runs in the test driver also, which
79 hasn't called primary, in that case do nothing. */
80 if (plugin_lib
== NULL
)
83 ret
= dlclose (plugin_lib
);
86 printf ("ERROR: Calling dlclose failed with \"%s\"\n",