Make build-many-glibcs.py track component versions requested and used.
[glibc.git] / dlfcn / bug-dl-leaf-lib.c
blob105ab244f38529e333ca2c8b292e7268d435966e
1 /* Make sure dlopen/dlclose are not marked as leaf functions.
3 Copyright (C) 2013-2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Mike Frysinger <vapier@gentoo.org>
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
21 /* The bug-dl-leaf.c file will call our lib_main directly. We do this to
22 keep things simple -- no need to use --export-dynamic with the linker
23 or build the main ELF as a PIE.
25 The lib_main func will modify some of its state while dlopening and
26 dlclosing the bug-dl-leaf-lib-cb.so library. The constructors and
27 destructors in that library will call back into this library to also
28 muck with state (the check_val_xxx funcs).
30 If dlclose/dlopen are marked as "leaf" functions, then with newer
31 versions of gcc, the state modification won't work correctly. */
33 #include <assert.h>
34 #include <dlfcn.h>
36 static int val = 1;
37 static int called = 0;
39 void check_val_init (void)
41 called = 1;
42 assert (val == 2);
45 void check_val_fini (void)
47 called = 2;
48 assert (val == 4);
51 int lib_main (void)
53 int ret __attribute__ ((unused));
54 void *hdl;
56 /* Make sure the constructor sees the updated val. */
57 val = 2;
58 hdl = dlopen ("bug-dl-leaf-lib-cb.so", RTLD_GLOBAL | RTLD_LAZY);
59 val = 3;
60 assert (hdl);
61 assert (called == 1);
63 /* Make sure the destructor sees the updated val. */
64 val = 4;
65 ret = dlclose (hdl);
66 val = 5;
67 assert (ret == 0);
68 assert (called == 2);
70 return !val;