libio: Remove unused pragma weak on vtable
[glibc.git] / elf / dl-call_fini.c
blob7376546ae0f5cd63dc6b82ed497cab3b924643d1
1 /* Invoke DT_FINI and DT_FINI_ARRAY callbacks.
2 Copyright (C) 1996-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 #include <ldsodefs.h>
20 #include <sysdep.h>
22 void
23 _dl_call_fini (void *closure_map)
25 struct link_map *map = closure_map;
27 /* When debugging print a message first. */
28 if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_IMPCALLS))
29 _dl_debug_printf ("\ncalling fini: %s [%lu]\n\n", map->l_name, map->l_ns);
31 /* Make sure nothing happens if we are called twice. */
32 map->l_init_called = 0;
34 ElfW(Dyn) *fini_array = map->l_info[DT_FINI_ARRAY];
35 if (fini_array != NULL)
37 ElfW(Addr) *array = (ElfW(Addr) *) (map->l_addr
38 + fini_array->d_un.d_ptr);
39 size_t sz = (map->l_info[DT_FINI_ARRAYSZ]->d_un.d_val
40 / sizeof (ElfW(Addr)));
42 while (sz-- > 0)
43 ((fini_t) array[sz]) ();
46 /* Next try the old-style destructor. */
47 ElfW(Dyn) *fini = map->l_info[DT_FINI];
48 if (fini != NULL)
49 DL_CALL_DT_FINI (map, ((void *) map->l_addr + fini->d_un.d_ptr));