]> sourceware.org Git - glibc.git/commitdiff
Move libc_freeres_ptrs and libc_subfreeres to hidden/weak functions
authorAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Tue, 27 Dec 2022 21:11:42 +0000 (18:11 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 27 Mar 2023 16:57:55 +0000 (13:57 -0300)
They are both used by __libc_freeres to free all library malloc
allocated resources to help tooling like mtrace or valgrind with
memory leak tracking.

The current scheme uses assembly markers and linker script entries
to consolidate the free routine function pointers in the RELRO segment
and to be freed buffers in BSS.

This patch changes it to use specific free functions for
libc_freeres_ptrs buffers and call the function pointer array directly
with call_function_static_weak.

It allows the removal of both the internal macros and the linker
script sections.

Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
90 files changed:
Makerules
crypt/md5-crypt.c
crypt/sha256-crypt.c
crypt/sha512-crypt.c
dlfcn/dlerror.h
elf/dl-libc.c
grp/fgetgrent.c
gshadow/fgetsgent.c
iconv/gconv_cache.c
iconv/gconv_conf.c
iconv/gconv_db.c
iconv/gconv_dl.c
include/libc-symbols.h
include/set-freeres.h [new file with mode: 0644]
inet/getnameinfo.c
inet/getnetgrent.c
inet/rcmd.c
inet/rexec.c
intl/dcigettext.c
intl/finddomain.c
intl/loadmsgcat.c
intl/localealias.c
libio/fcloseall.c
libio/genops.c
libio/libioP.h
locale/loadarchive.c
locale/localeinfo.h
locale/setlocale.c
login/getutent.c
login/getutid.c
login/getutline.c
malloc/set-freeres.c
malloc/thread-freeres.c
misc/efgcvt-template.c
misc/efgcvt.c
misc/fstab.c
misc/hsearch.c
misc/mntent.c
misc/qefgcvt.c
misc/unwind-link.c
nptl/nptlfreeres.c
nscd/nscd_getgr_r.c
nscd/nscd_gethst_r.c
nscd/nscd_getpw_r.c
nscd/nscd_getserv_r.c
nscd/nscd_netgroup.c
nss/getXXbyYY.c
nss/getXXent.c
nss/nss_action.c
nss/nss_action.h
nss/nss_database.c
nss/nss_database.h
nss/nss_module.c
nss/nss_module.h
posix/regcomp.c
posix/register-atfork.c
pwd/fgetpwent.c
resolv/gai_misc.c
resolv/res-close.c
resolv/res_hconf.c
resolv/resolv-internal.h
resolv/resolv_conf.c
resolv/tst-leaks2.c
rt/aio_misc.c
shadow/fgetspent.c
stdio-common/reg-modifier.c
stdio-common/reg-printf.c
stdio-common/reg-type.c
stdlib/exit.c
stdlib/fmtmsg.c
stdlib/setenv.c
sunrpc/clnt_perr.c
sunrpc/rpc_thread.c
sunrpc/tst-svc_register.c
sysdeps/generic/set-freeres-fp.h [new file with mode: 0644]
sysdeps/generic/set-freeres-os.h [new file with mode: 0644]
sysdeps/generic/set-freeres-system.h [new file with mode: 0644]
sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c
sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h [new file with mode: 0644]
sysdeps/mach/hurd/bits/errno.h
sysdeps/posix/getaddrinfo.c
sysdeps/posix/ttyname.c
sysdeps/unix/sysv/linux/check_pf.c
sysdeps/unix/sysv/linux/s390/s390-32/getutent.c
sysdeps/unix/sysv/linux/s390/s390-32/getutid.c
sysdeps/unix/sysv/linux/s390/s390-32/getutline.c
sysdeps/unix/sysv/linux/set-freeres-os.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/ttyname.c
time/tzfile.c
time/tzset.c

index fae6b626e6615d391e34b660c9ac1cecfc8e59ee..f6071eab5050197af4b389642db38a9a3b0e5e75 100644 (file)
--- a/Makerules
+++ b/Makerules
@@ -560,14 +560,7 @@ $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
                  -Wl,--verbose 2>/dev/null | \
          sed > $@T \
              -e '/^=========/,/^=========/!d;/^=========/d' \
-             -e 's/^.*\*(\.dynbss).*$$/& \
-                PROVIDE(__start___libc_freeres_ptrs = .); \
-                *(__libc_freeres_ptrs) \
-                PROVIDE(__stop___libc_freeres_ptrs = .);/'\
              -e 's@^.*\*(\.jcr).*$$@& \
-                PROVIDE(__start___libc_subfreeres = .);\
-                __libc_subfreeres : { *(__libc_subfreeres) }\
-                PROVIDE(__stop___libc_subfreeres = .);\
                 PROVIDE(__start___libc_IO_vtables = .);\
                 __libc_IO_vtables : { *(__libc_IO_vtables) }\
                 PROVIDE(__stop___libc_IO_vtables = .);\
index 0cc597a7f2948bb76937a90ac24d5106a2386eeb..4e4760545a0aa6afcff7fdfcf7c97f64ab834d3d 100644 (file)
@@ -299,10 +299,7 @@ __md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   return buffer;
 }
 
-#ifndef _LIBC
-# define libc_freeres_ptr(decl) decl
-#endif
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 char *
 __md5_crypt (const char *key, const char *salt)
@@ -326,11 +323,9 @@ __md5_crypt (const char *key, const char *salt)
   return __md5_crypt_r (key, salt, buffer, buflen);
 }
 
-#ifndef _LIBC
 static void
 __attribute__ ((__destructor__))
 free_mem (void)
 {
   free (buffer);
 }
-#endif
index 1ef16af80f9a1d2469311f971a1323342b15e310..e90eb590bb71775b0583f9a281bed7f08ce31026 100644 (file)
@@ -386,10 +386,7 @@ __sha256_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   return buffer;
 }
 
-#ifndef _LIBC
-# define libc_freeres_ptr(decl) decl
-#endif
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* This entry point is equivalent to the `crypt' function in Unix
    libcs.  */
@@ -418,11 +415,9 @@ __sha256_crypt (const char *key, const char *salt)
   return __sha256_crypt_r (key, salt, buffer, buflen);
 }
 
-#ifndef _LIBC
 static void
 __attribute__ ((__destructor__))
 free_mem (void)
 {
   free (buffer);
 }
-#endif
index b592eb0976c40237b74f44053508e7ee2c444ce1..d9c0de14d26b061c42a5766136e7476ba9af9ca0 100644 (file)
@@ -408,10 +408,7 @@ __sha512_crypt_r (const char *key, const char *salt, char *buffer, int buflen)
   return buffer;
 }
 
-#ifndef _LIBC
-# define libc_freeres_ptr(decl) decl
-#endif
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* This entry point is equivalent to the `crypt' function in Unix
    libcs.  */
@@ -440,11 +437,9 @@ __sha512_crypt (const char *key, const char *salt)
   return __sha512_crypt_r (key, salt, buffer, buflen);
 }
 
-#ifndef _LIBC
 static void
 __attribute__ ((__destructor__))
 free_mem (void)
 {
   free (buffer);
 }
-#endif
index 999b9f26ae2fe82b0df41448c48623c3e5e4ec1c..c6697728a966dabba74abc14349d64bd89735fc6 100644 (file)
@@ -87,6 +87,5 @@ static struct dl_action_result *const dl_action_result_malloc_failed
    reporting via dlerror.  */
 extern __thread struct dl_action_result *__libc_dlerror_result
   attribute_tls_model_ie;
-void __libc_dlerror_result_free (void) attribute_hidden;
 
 #endif /* _DLERROR_H */
index 7e71bfb53409cb89d943407beea222fb97b496d0..c12e52f3303f86a4a3d1b99052a362e1ddceee38 100644 (file)
@@ -228,7 +228,7 @@ __libc_dlclose (void *map)
 }
 
 
-static bool __libc_freeres_fn_section
+static bool
 free_slotinfo (struct dtv_slotinfo_list **elemp)
 {
   size_t cnt;
@@ -256,7 +256,8 @@ free_slotinfo (struct dtv_slotinfo_list **elemp)
 }
 
 
-libc_freeres_fn (free_mem)
+void
+__dl_libc_freemem (void)
 {
   struct link_map *l;
   struct r_search_path_elem *d;
index d6ee2db65682b71d317a61b9f5d44710851cf031..2e7c7fe5fb5b5bb6899f362b54a9fa8c375f94bd 100644 (file)
 #include <libc-lock.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
 
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* Read one entry from the given stream.  */
 struct group *
@@ -82,3 +83,5 @@ fgetgrent (FILE *stream)
 
   return result;
 }
+
+weak_alias (buffer, __libc_fgetgrent_freemem_ptr)
index 68e69ef6f2580713cb52a86aea80cc42b4ea7b66..dc26b24b47ae23bc1ce558f1cd88f99573d8cf3a 100644 (file)
@@ -20,6 +20,7 @@
 #include <gshadow.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 
 /* A reasonable size for a buffer to start with.  */
@@ -28,7 +29,7 @@
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
 
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* Read one shadow entry from the given stream.  */
 struct sgrp *
@@ -85,3 +86,5 @@ fgetsgent (FILE *stream)
 
   return result;
 }
+
+weak_alias (buffer, __libc_fgetsgent_freeres_ptr);
index c13fc5ef96c3a59e269af29c95836c23df9fe7d7..f2100ca88f91c14644deb06891bb9331dca0672b 100644 (file)
@@ -449,7 +449,8 @@ __gconv_release_cache (struct __gconv_step *steps, size_t nsteps)
 
 
 /* Free all resources if necessary.  */
-libc_freeres_fn (free_mem)
+void
+__gconv_cache_freemem (void)
 {
   if (cache_malloced)
     free (gconv_cache);
index a75ac13e3f26a8a110b1f577666931a0a22a2e7b..c76011d6bc910c5c82ddb22ecdbabda0808bfd81 100644 (file)
@@ -530,7 +530,8 @@ __gconv_load_conf (void)
 
 
 /* Free all resources if necessary.  */
-libc_freeres_fn (free_mem)
+void
+__gconv_conf_freemem (void)
 {
   if (__gconv_path_elem != NULL && __gconv_path_elem != &empty_path_elem)
     free ((void *) __gconv_path_elem);
index e9b1c076203f6b6ad8523c3c7aed90393d419b35..0ee807628727a21f47bfb7d14a5e5b7b52d8b9f3 100644 (file)
@@ -169,7 +169,7 @@ add_derivation (const char *fromset, const char *toset,
      not all memory will be freed.  */
 }
 
-static void __libc_freeres_fn_section
+static void
 free_derivation (void *p)
 {
   struct known_derivation *deriv = (struct known_derivation *) p;
@@ -793,7 +793,6 @@ __gconv_close_transform (struct __gconv_step *steps, size_t nsteps)
 
 /* Free the modules mentioned.  */
 static void
-__libc_freeres_fn_section
 free_modules_db (struct gconv_module *node)
 {
   if (node->left != NULL)
@@ -812,7 +811,8 @@ free_modules_db (struct gconv_module *node)
 
 
 /* Free all resources if necessary.  */
-libc_freeres_fn (free_mem)
+void
+__gconv_db_freemem (void)
 {
   /* First free locale memory.  This needs to be done before freeing
      derivations, as ctype cleanup functions dereference steps arrays which we
index 911c2031f07127b9422a1393fc7692ce607ccff5..cb51568e4c8b83b95cb3b8beac3886dea2cec7fc 100644 (file)
@@ -184,7 +184,7 @@ __gconv_release_shlib (struct __gconv_loaded_object *handle)
 
 
 /* We run this if we debug the memory allocation.  */
-static void __libc_freeres_fn_section
+static void
 do_release_all (void *nodep)
 {
   struct __gconv_loaded_object *obj = (struct __gconv_loaded_object *) nodep;
@@ -196,7 +196,8 @@ do_release_all (void *nodep)
   free (obj);
 }
 
-libc_freeres_fn (free_mem)
+void
+__gconv_dl_freemem (void)
 {
   __tdestroy (loaded, do_release_all);
   loaded = NULL;
index 404169ce7899e902be96c68f053326311a6564b7..155781d4482003b61eac6a8240a6d20989c44d56 100644 (file)
@@ -237,79 +237,6 @@ requires at runtime the shared libraries from the glibc version used \
 for linking")
 #endif
 
-/* Resource Freeing Hooks:
-
-   Normally a process exits and the OS cleans up any allocated
-   memory.  However, when tooling like mtrace or valgrind is monitoring
-   the process we need to free all resources that are part of the
-   process in order to provide the consistency required to track
-   memory leaks.
-
-   A single public API exists and is __libc_freeres(), and this is used
-   by applications like valgrind to freee resouces.
-
-   There are 3 cases:
-
-   (a) __libc_freeres
-
-       In this case all you need to do is define the freeing routine:
-
-       foo.c:
-       libfoo_freeres_fn (foo_freeres)
-       {
-         complex_free (mem);
-       }
-
-       This ensures the function is called at the right point to free
-       resources.
-
-   (b) __libc_freeres_ptr
-
-       The framework for (a) iterates over the list of pointers-to-free
-       in (b) and frees them.
-
-       foo.c:
-       libc_freeres_ptr (static char *foo_buffer);
-
-       Freeing these resources alaways happens last and is equivalent
-       to registering a function that does 'free (foo_buffer)'.
-
-   (c) Explicit lists of free routines to call or objects to free.
-
-       It is the intended goal to remove (a) and (b) which have some
-       non-determinism based on link order, and instead use explicit
-       lists of functions and frees to resolve cleanup ordering issues
-       and make it easy to debug and maintain.
-
-       As of today the following subsystems use (c):
-
-       Per-thread cleanup:
-       * malloc/thread-freeres.c
-
-       libdl cleanup:
-       * dlfcn/dlfreeres.c
-
-       libpthread cleanup:
-       * nptl/nptlfreeres.c
-
-       So if you need any shutdown routines to run you should add them
-       directly to the appropriate subsystem's shutdown list.  */
-
-/* Resource pointers to free in libc.so.  */
-#define libc_freeres_ptr(decl) \
-  __make_section_unallocated ("__libc_freeres_ptrs, \"aw\", %nobits") \
-  decl __attribute__ ((section ("__libc_freeres_ptrs" __sec_comment)))
-
-/* Resource freeing functions from libc.so go in this section.  */
-#define __libc_freeres_fn_section \
-  __attribute__ ((__used__, section ("__libc_freeres_fn")))
-
-/* Resource freeing functions for libc.so.  */
-#define libc_freeres_fn(name) \
-  static void name (void) __attribute_used__ __libc_freeres_fn_section;        \
-  text_set_element (__libc_subfreeres, name);                          \
-  static void name (void)
-
 /* Declare SYMBOL to be TYPE (`function' or `object') of SIZE bytes
    alias to ORIGINAL, when the assembler supports such declarations
    (such as in ELF).
diff --git a/include/set-freeres.h b/include/set-freeres.h
new file mode 100644 (file)
index 0000000..b7f6651
--- /dev/null
@@ -0,0 +1,142 @@
+/* Macros for internal resource Freeing Hooks.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _SET_FREERES_H
+#define _SET_FREERES_H 1
+
+#include <shlib-compat.h>
+#include <printf.h>
+#include <time.h>
+#include <resolv/resolv-internal.h>
+
+/* Resource Freeing Hooks:
+
+   Normally a process exits and the OS cleans up any allocated
+   memory.  However, when tooling like mtrace or valgrind is monitoring
+   the process we need to free all resources that are part of the
+   process in order to provide the consistency required to track
+   memory leaks.
+
+   A single public API exists and is __libc_freeres, and this is used
+   by applications like valgrind to freee resouces.
+
+   Each free routines must be explicit listed below.  */
+
+/* From libc.so.  */
+extern void __dl_libc_freemem (void) attribute_hidden;
+extern void __hdestroy (void) attribute_hidden;
+extern void __gconv_cache_freemem (void) attribute_hidden;
+extern void __gconv_conf_freemem (void) attribute_hidden;
+extern void __gconv_db_freemem (void) attribute_hidden;
+extern void __gconv_dl_freemem (void) attribute_hidden;
+extern void __intl_freemem (void) attribute_hidden;
+extern void __libio_freemem (void) attribute_hidden;
+extern void __libc_fstab_freemem (void) attribute_hidden;
+extern void __nscd_gr_map_freemem (void) attribute_hidden;
+extern void __nscd_hst_map_freemem (void) attribute_hidden;
+extern void __nscd_pw_map_freemem (void) attribute_hidden;
+extern void __nscd_serv_map_freemem (void) attribute_hidden;
+extern void __nscd_group_map_freemem (void) attribute_hidden;
+extern void __libc_regcomp_freemem (void) attribute_hidden;
+extern void __libc_atfork_freemem (void) attribute_hidden;
+extern void __libc_resolv_conf_freemem (void) attribute_hidden;
+extern void __res_thread_freeres (void) attribute_hidden;
+extern void __libc_printf_freemem (void) attribute_hidden;
+extern void __libc_fmtmsg_freemem (void) attribute_hidden;
+extern void __libc_setenv_freemem (void) attribute_hidden;
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31)
+extern void __rpc_freemem (void) attribute_hidden;
+extern void __rpc_thread_destroy (void) attribute_hidden;
+#endif
+extern void __libc_getaddrinfo_freemem (void) attribute_hidden;
+extern void __libc_tzset_freemem (void) attribute_hidden;
+extern void __libc_localealias_freemem (void) attribute_hidden;
+extern void __libc_getutent_freemem (void) attribute_hidden;
+extern void __libc_getutline_freemem (void) attribute_hidden;
+/* From nss/nss_module.c */
+extern void __nss_module_freeres (void) attribute_hidden;
+/* From nss/nss_action.c */
+extern void __nss_action_freeres (void) attribute_hidden;
+/* From nss/nss_database.c */
+extern void __nss_database_freeres (void) attribute_hidden;
+/* From libio/genops.c */
+extern int _IO_cleanup (void) attribute_hidden;;
+/* From dlfcn/dlerror.c */
+extern void __libc_dlerror_result_free (void) attribute_hidden;
+
+/* From either libc.so or libpthread.so  */
+extern void __libpthread_freeres (void) attribute_hidden;
+/* From either libc.so or libanl.so  */
+#if PTHREAD_IN_LIBC
+extern void __gai_freemem (void) attribute_hidden;
+/* From either libc.so or librt.so  */
+extern void __aio_freemem (void) attribute_hidden;
+#endif
+
+/* From libc.so  */
+extern char * __libc_fgetgrent_freemem_ptr attribute_hidden;
+extern char * __libc_fgetsgent_freeres_ptr attribute_hidden;
+extern char * __libc_getnetgrent_freemem_ptr attribute_hidden;
+extern char * __libc_rcmd_freemem_ptr attribute_hidden;
+extern char * __libc_rexec_freemem_ptr attribute_hidden;
+extern void * __libc_mntent_freemem_ptr attribute_hidden;
+extern char * __libc_fgetpwent_freemem_ptr attribute_hidden;
+extern struct netaddr * __libc_resolv_res_hconf_freemem_ptr attribute_hidden;
+extern char * __libc_fgetspent_freemem_ptr attribute_hidden;
+extern __time64_t * __libc_tzfile_freemem_ptr attribute_hidden;
+extern char * __libc_getnameinfo_freemem_ptr attribute_hidden;
+extern struct utmp * __libc_getutent_freemem_ptr attribute_hidden;
+extern struct utmp * __libc_getutid_freemem_ptr attribute_hidden;
+extern struct utmp * __libc_getutline_freemem_ptr attribute_hidden;
+extern printf_arginfo_size_function ** __libc_reg_printf_freemem_ptr
+    attribute_hidden;
+extern printf_va_arg_function ** __libc_reg_type_freemem_ptr
+    attribute_hidden;
+/* From nss/getXXbyYY.c  */
+extern char * __libc_getgrgid_freemem_ptr attribute_hidden;
+extern char * __libc_getgrnam_freemem_ptr attribute_hidden;
+extern char * __libc_getpwnam_freemem_ptr attribute_hidden;
+extern char * __libc_getpwuid_freemem_ptr attribute_hidden;
+extern char * __libc_getspnam_freemem_ptr attribute_hidden;
+extern char * __libc_getaliasbyname_freemem_ptr attribute_hidden;
+extern char * __libc_gethostbyaddr_freemem_ptr attribute_hidden;
+extern char * __libc_gethostbyname_freemem_ptr attribute_hidden;
+extern char * __libc_gethostbyname2_freemem_ptr attribute_hidden;
+extern char * __libc_getnetbyaddr_freemem_ptr attribute_hidden;
+extern char * __libc_getnetbyname_freemem_ptr attribute_hidden;
+extern char * __libc_getprotobynumber_freemem_ptr attribute_hidden;
+extern char * __libc_getprotobyname_freemem_ptr attribute_hidden;
+extern char * __libc_getrpcbyname_freemem_ptr attribute_hidden;
+extern char * __libc_getrpcbynumber_freemem_ptr attribute_hidden;
+extern char * __libc_getservbyname_freemem_ptr attribute_hidden;
+extern char * __libc_getservbyport_freemem_ptr attribute_hidden;
+/* From nss/getXXent.c */
+extern char * __libc_getgrent_freemem_ptr attribute_hidden;
+extern char * __libc_getpwent_freemem_ptr attribute_hidden;
+extern char * __libc_getspent_freemem_ptr attribute_hidden;
+extern char * __libc_getaliasent_freemem_ptr attribute_hidden;
+extern char * __libc_gethostent_freemem_ptr attribute_hidden;
+extern char * __libc_getnetent_freemem_ptr attribute_hidden;
+extern char * __libc_getprotoent_freemem_ptr attribute_hidden;
+extern char * __libc_getrpcent_freemem_ptr attribute_hidden;
+extern char * __libc_getservent_freemem_ptr attribute_hidden;
+/* From misc/efgcvt-template.c  */
+extern char * __libc_efgcvt_freemem_ptr attribute_hidden;
+extern char * __libc_qefgcvt_freemem_ptr attribute_hidden;
+
+#endif
index 5c07b748bc32a15d4bcf18e11a97276e7eeb0235..40c20b4be6f1a9cbbe6eb8925c8b7e40884b9b62 100644 (file)
@@ -72,12 +72,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <libc-lock.h>
 #include <scratch_buffer.h>
 #include <net-internal.h>
+#include <set-freeres.h>
 
 #ifndef min
 # define min(x,y) (((x) > (y)) ? (y) : (x))
 #endif /* min */
 
-libc_freeres_ptr (static char *domain);
+static char *domain;
 
 /* Former NI_IDN_ALLOW_UNASSIGNED, NI_IDN_USE_STD3_ASCII_RULES flags,
    now ignored.  */
@@ -556,3 +557,5 @@ getnameinfo (const struct sockaddr *sa, socklen_t addrlen, char *host,
   return 0;
 }
 libc_hidden_def (getnameinfo)
+
+weak_alias (domain, __libc_getnameinfo_freemem_ptr)
index 0b689e0ab0bca4a1c2a5b226fdd11568c338613a..a7c83740a09640e2bdd5f9d5e896316418c3c49e 100644 (file)
 #include <netdb.h>
 #include <stdlib.h>
 #include <libc-lock.h>
+#include <set-freeres.h>
 
 /* Static buffer for return value.  We allocate it when needed.  */
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 /* All three strings should fit in a block of 1kB size.  */
 #define BUFSIZE 1024
 
@@ -47,3 +48,5 @@ getnetgrent (char **hostp, char **userp, char **domainp)
 
   return __getnetgrent_r (hostp, userp, domainp, buffer, BUFSIZE);
 }
+
+weak_alias (buffer, __libc_getnetgrent_freemem_ptr)
index 2b95fa11d8d762d245e12c909e3ae1fd92045e3d..ad8a89490724787c11b542a76801401ce9f07392 100644 (file)
@@ -80,6 +80,7 @@
 #include <sys/uio.h>
 #include <sigsetops.h>
 #include <shlib-compat.h>
+#include <set-freeres.h>
 
 
 int __ivaliduser (FILE *, uint32_t, const char *, const char *);
@@ -98,7 +99,7 @@ int iruserok (uint32_t raddr, int superuser, const char *ruser,
 
 libc_hidden_proto (iruserok_af)
 
-libc_freeres_ptr(static char *ahostbuf);
+static char *ahostbuf;
 
 int
 rcmd_af (char **ahost, u_short rport, const char *locuser, const char *remuser,
@@ -817,3 +818,5 @@ __validuser2_sa (FILE *hostf, struct sockaddr *ra, size_t ralen,
 
     return retval;
 }
+
+weak_alias (ahostbuf, __libc_rcmd_freemem_ptr)
index c647b7ac34e6184bbee7d045b491126f5f85832d..1985fa4418a202829c10a7a6c30d7c99d1a9a0d0 100644 (file)
 #include <string.h>
 #include <unistd.h>
 #include <sys/uio.h>
+#include <set-freeres.h>
 
 int    rexecoptions;
-libc_freeres_ptr (static char *ahostbuf);
+static char *ahostbuf;
 
 int
 rexec_af (char **ahost, int rport, const char *name, const char *pass,
@@ -196,3 +197,5 @@ rexec (char **ahost, int rport, const char *name, const char *pass,
 {
        return rexec_af(ahost, rport, name, pass, cmd, fd2p, AF_INET);
 }
+
+weak_alias (ahostbuf, __libc_rexec_freemem_ptr)
index 64de9d511ad03d627d45db45ebcb9bdcd74a0a34..7886ac9545e33367eacd8d8ba1497bc45ffbe367 100644 (file)
@@ -1667,7 +1667,8 @@ mempcpy (void *dest, const void *src, size_t n)
 #ifdef _LIBC
 /* If we want to free all resources we have to do some work at
    program's end.  */
-libc_freeres_fn (free_mem)
+void
+__intl_freemem (void)
 {
   void *old;
 
index 5f2508b2ae9237e3cc1712042fa48bab88d666bc..6a8b239a97d1cf3c9f12db880d3d14342576e081 100644 (file)
@@ -185,7 +185,7 @@ out:
 #ifdef _LIBC
 /* This is called from iconv/gconv_db.c's free_mem, as locales must
    be freed before freeing gconv steps arrays.  */
-void __libc_freeres_fn_section
+void
 _nl_finddomain_subfreeres (void)
 {
   struct loaded_l10nfile *runp = _nl_loaded_domains;
index 992489758c18e87359df4150266cdd75d1fa84be..94a362f923e697909613c8543c91bc62eb5b84d8 100644 (file)
@@ -1284,7 +1284,6 @@ _nl_load_domain (struct loaded_l10nfile *domain_file,
 
 #ifdef _LIBC
 void
-__libc_freeres_fn_section
 _nl_unload_domain (struct loaded_domain *domain)
 {
   size_t i;
index 42e4569b0aa68d1d2779cfd7be9780270015cf89..ea4f48b594fe13490f006d95b799213961146e23 100644 (file)
@@ -126,14 +126,10 @@ struct alias_map
 };
 
 
-#ifndef _LIBC
-# define libc_freeres_ptr(decl) decl
-#endif
-
-libc_freeres_ptr (static char *string_space);
+static char *string_space;
 static size_t string_space_act;
 static size_t string_space_max;
-libc_freeres_ptr (static struct alias_map *map);
+static struct alias_map *map;
 static size_t nmap;
 static size_t maxmap;
 
@@ -439,3 +435,10 @@ alias_compare (const struct alias_map *map1, const struct alias_map *map2)
   return c1 - c2;
 #endif
 }
+
+void
+__libc_localealias_freemem (void)
+{
+  free (string_space);
+  free (map);
+}
index e1e06d497b2c50f7049b87782480b695fa5d91fd..415da65c7679fc15e8082610c507a3be2c593479 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "libioP.h"
 #include <stdio.h>
+#include <set-freeres.h>
 
 int
 __fcloseall (void)
index 7c45052aa2dcb30cba29ba84d020936f1973c115..713131270474cce2e7482748e9bd143bd44982e3 100644 (file)
@@ -765,8 +765,8 @@ weak_alias (_IO_flush_all_linebuffered, _flushlbf)
    actual buffer because this will happen anyway once the program
    terminated.  If we do want to look for memory leaks we have to free
    the buffers.  Whether something is freed is determined by the
-   function sin the libc_freeres section.  Those are called as part of
-   the atexit routine, just like _IO_cleanup.  The problem is we do
+   function called by __libc_freeres (those are not called as part of
+   the atexit routine, different from  _IO_cleanup).  The problem is we do
    not know whether the freeres code is called first or _IO_cleanup.
    if the former is the case, we set the DEALLOC_BUFFER variable to
    true and _IO_unbuffer_all will take care of the rest.  If
@@ -844,8 +844,8 @@ _IO_unbuffer_all (void)
 #endif
 }
 
-
-libc_freeres_fn (buffer_free)
+void
+__libio_freemem (void)
 {
   dealloc_buffers = true;
 
index 38507388fdf89b225745620471b80aed9fffee0a..80941b763fd00c7309bcf088af67d51c90b33be0 100644 (file)
@@ -491,7 +491,6 @@ libc_hidden_proto (_IO_wdo_write)
 extern int _IO_flush_all_lockp (int);
 extern int _IO_flush_all (void);
 libc_hidden_proto (_IO_flush_all)
-extern int _IO_cleanup (void);
 extern void _IO_flush_all_linebuffered (void);
 libc_hidden_proto (_IO_flush_all_linebuffered)
 extern int _IO_new_fgetpos (FILE *, __fpos_t *);
index 454bbc7eda710ba3279807a0df9154da000c06cc..5b857d5d24437a72320076f6c055281e2fde7843 100644 (file)
@@ -498,7 +498,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
   return lia->data[category];
 }
 
-void __libc_freeres_fn_section
+void
 _nl_archive_subfreeres (void)
 {
   struct locale_in_archive *lia;
index 66cad7a83b6dd3a8234bc84075498bfb44876bb5..8bbf28142783c27dd526c1d202c46b37a98f6bd0 100644 (file)
@@ -381,10 +381,10 @@ extern struct __locale_data *_nl_load_locale_from_archive (int category,
                                                           const char **namep)
      attribute_hidden;
 
-/* Subroutine of setlocale's __libc_subfreeres hook.  */
+/* Subroutine of setlocale's free resource.  */
 extern void _nl_archive_subfreeres (void) attribute_hidden;
 
-/* Subroutine of gconv-db's __libc_subfreeres hook.  */
+/* Subroutine of gconv-db's free resource.  */
 extern void _nl_locale_subfreeres (void) attribute_hidden;
 
 /* Validate the contents of a locale file and set up the in-core
index dd73fa424881ae9cd194207a16ba0b5f56ea7421..6a902faa50dd81bc3afcf55d08f5c59010f269a0 100644 (file)
@@ -468,7 +468,7 @@ setlocale (int category, const char *locale)
 }
 libc_hidden_def (setlocale)
 
-static void __libc_freeres_fn_section
+static void
 free_category (int category,
               struct __locale_data *here, struct __locale_data *c_data)
 {
@@ -498,7 +498,7 @@ free_category (int category,
 
 /* This is called from iconv/gconv_db.c's free_mem, as locales must
    be freed before freeing gconv steps arrays.  */
-void __libc_freeres_fn_section
+void
 _nl_locale_subfreeres (void)
 {
 #ifdef NL_CURRENT_INDIRECT
index 7a49984912b50c2a031228f76c401869aa964dcb..ed8b162b8a11ef5b1829906e20d467136fe1a93f 100644 (file)
 
 #include <stdlib.h>
 #include <utmp.h>
+#include <set-freeres.h>
 
 
 /* Local buffer to store the result.  */
-libc_freeres_ptr (static struct utmp *buffer);
+static struct utmp *buffer;
 
 
 struct utmp *
@@ -42,3 +43,5 @@ __getutent (void)
 }
 libc_hidden_def (__getutent)
 weak_alias (__getutent, getutent)
+
+weak_alias (buffer, __libc_getutent_freemem_ptr)
index 7ecc93c0b779eb72abfa6b9905d0f2467048b838..658fdc08ca72bca89e6cac0d9d6fd6c4bd6edc66 100644 (file)
 
 #include <stdlib.h>
 #include <utmp.h>
-
+#include <set-freeres.h>
 
 /* Local buffer to store the result.  */
-libc_freeres_ptr (static struct utmp *buffer);
+static struct utmp *buffer;
 
 struct utmp *
 __getutid (const struct utmp *id)
@@ -40,3 +40,5 @@ __getutid (const struct utmp *id)
 }
 libc_hidden_def (__getutid)
 weak_alias (__getutid, getutid)
+
+weak_alias (buffer, __libc_getutid_freemem_ptr)
index c9dcd227a5f7b34b4255aec0f87b1dd683b9a112..a10c256c42f840b51f6986fc832b3cf2707b1288 100644 (file)
 
 #include <stdlib.h>
 #include <utmp.h>
+#include <set-freeres.h>
 
 
 /* Local buffer to store the result.  */
-libc_freeres_ptr (static struct utmp *buffer);
+static struct utmp *buffer;
 
 
 struct utmp *
@@ -41,3 +42,5 @@ __getutline (const struct utmp *line)
 }
 libc_hidden_def (__getutline)
 weak_alias (__getutline, getutline)
+
+weak_alias (buffer, __libc_getutline_freemem_ptr)
index 4a5cec5d4a578a3a8bca850fcb27f71a402bc34d..f452ff838b6e79e524cec5adebbcac09a6d4fc6c 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <array_length.h>
 #include <atomic.h>
 #include <stdlib.h>
-#include <set-hooks.h>
 #include <libc-internal.h>
 #include <unwind-link.h>
-#include <dlfcn/dlerror.h>
 #include <ldsodefs.h>
+#include <set-freeres.h>
+#include <set-freeres-system.h>
+
+#ifndef SHARED
+# pragma weak __nss_module_freeres
+# pragma weak __nss_action_freeres
+# pragma weak __nss_database_freeres
+# pragma weak __dl_libc_freemem
+# pragma weak __hdestroy
+# pragma weak __gconv_cache_freemem
+# pragma weak __gconv_conf_freemem
+# pragma weak __gconv_db_freemem
+# pragma weak __gconv_dl_freemem
+# pragma weak __intl_freemem
+# pragma weak __libio_freemem
+# pragma weak __libc_fstab_freemem
+# pragma weak __nscd_gr_map_freemem
+# pragma weak __nscd_hst_map_freemem
+# pragma weak __nscd_pw_map_freemem
+# pragma weak __nscd_serv_map_freemem
+# pragma weak __nscd_group_map_freemem
+# pragma weak __libc_regcomp_freemem
+# pragma weak __libc_atfork_freemem
+# pragma weak __res_thread_freeres
+# pragma weak __libc_resolv_conf_freemem
+# pragma weak __libc_printf_freemem
+# pragma weak __libc_fmtmsg_freemem
+# pragma weak __libc_setenv_freemem
+# pragma weak __rpc_freemem
+# pragma weak __rpc_thread_destroy
+# pragma weak __libc_getaddrinfo_freemem
+# pragma weak __libc_tzset_freemem
+# pragma weak __libc_localealias_freemem
+# pragma weak __gai_freemem
+# pragma weak __aio_freemem
+# pragma weak __libpthread_freeres
+# pragma weak __libc_dlerror_result_free
+# pragma weak __check_pf_freemem
+#endif
 
-#include "../nss/nsswitch.h"
-#include "../libio/libioP.h"
-
-DEFINE_HOOK (__libc_subfreeres, (void));
-
-symbol_set_define (__libc_freeres_ptrs);
-
-extern void __libpthread_freeres (void)
-#if PTHREAD_IN_LIBC && defined SHARED
-/* It is possible to call __libpthread_freeres directly in shared
-   builds with an integrated libpthread.  */
-  attribute_hidden
+#ifdef SHARED
+# define call_free_static_weak(__ptr)                          \
+   free (__ptr)
 #else
-  __attribute__ ((weak))
+# define call_free_static_weak(__ptr)                          \
+  if (&__ptr != NULL)                                          \
+    free (__ptr);
 #endif
-  ;
 
-void __libc_freeres_fn_section
+void
 __libc_freeres (void)
 {
   /* This function might be called from different places.  So better
@@ -49,8 +79,6 @@ __libc_freeres (void)
 
   if (!atomic_compare_and_exchange_bool_acq (&already_called, 1, 0))
     {
-      void *const *p;
-
       call_function_static_weak (__nss_module_freeres);
       call_function_static_weak (__nss_action_freeres);
       call_function_static_weak (__nss_database_freeres);
@@ -58,7 +86,43 @@ __libc_freeres (void)
       _IO_cleanup ();
 
       /* We run the resource freeing after IO cleanup.  */
-      RUN_HOOK (__libc_subfreeres, ());
+      call_function_static_weak (__dl_libc_freemem);
+      call_function_static_weak (__hdestroy);
+      call_function_static_weak (__gconv_cache_freemem);
+      call_function_static_weak (__gconv_conf_freemem);
+      call_function_static_weak (__gconv_db_freemem);
+      call_function_static_weak (__gconv_dl_freemem);
+      call_function_static_weak (__intl_freemem);
+      call_function_static_weak (__libio_freemem);
+      call_function_static_weak (__libc_fstab_freemem);
+      call_function_static_weak (__nscd_gr_map_freemem);
+      call_function_static_weak (__nscd_hst_map_freemem);
+      call_function_static_weak (__nscd_pw_map_freemem);
+      call_function_static_weak (__nscd_serv_map_freemem);
+      call_function_static_weak (__nscd_group_map_freemem);
+      call_function_static_weak (__libc_regcomp_freemem);
+      call_function_static_weak (__libc_atfork_freemem);
+      /* __res_thread_freeres deallocates the per-thread resolv_context);
+        which in turn drop the reference count of the current global object.
+        So it need to be before __libc_resolv_conf_freemem.  */
+      call_function_static_weak (__res_thread_freeres);
+      call_function_static_weak (__libc_resolv_conf_freemem);
+      call_function_static_weak (__libc_printf_freemem);
+      call_function_static_weak (__libc_fmtmsg_freemem);
+      call_function_static_weak (__libc_setenv_freemem);
+#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_31)
+      call_function_static_weak (__rpc_freemem);
+      call_function_static_weak (__rpc_thread_destroy);
+#endif
+      call_function_static_weak (__libc_getaddrinfo_freemem);
+      call_function_static_weak (__libc_tzset_freemem);
+      call_function_static_weak (__libc_localealias_freemem);
+
+#if PTHREAD_IN_LIBC
+      call_function_static_weak (__gai_freemem);
+
+      call_function_static_weak (__aio_freemem);
+#endif
 
       call_function_static_weak (__libpthread_freeres);
 
@@ -72,9 +136,55 @@ __libc_freeres (void)
       GLRO (dl_libc_freeres) ();
 #endif
 
-      for (p = symbol_set_first_element (__libc_freeres_ptrs);
-           !symbol_set_end_p (__libc_freeres_ptrs, p); ++p)
-        free (*p);
+      call_free_static_weak (__libc_fgetgrent_freemem_ptr);
+      call_free_static_weak (__libc_fgetsgent_freeres_ptr);
+      call_free_static_weak (__libc_getnetgrent_freemem_ptr);
+      call_free_static_weak (__libc_rcmd_freemem_ptr);
+      call_free_static_weak (__libc_rexec_freemem_ptr);
+      call_free_static_weak (__libc_mntent_freemem_ptr);
+      call_free_static_weak (__libc_fgetpwent_freemem_ptr);
+      call_free_static_weak (__libc_resolv_res_hconf_freemem_ptr);
+      call_free_static_weak (__libc_fgetspent_freemem_ptr);
+      call_free_static_weak (__libc_tzfile_freemem_ptr);
+      call_free_static_weak (__libc_getnameinfo_freemem_ptr);
+      call_free_static_weak (__libc_getutent_freemem_ptr);
+      call_free_static_weak (__libc_getutid_freemem_ptr);
+      call_free_static_weak (__libc_getutline_freemem_ptr);
+      call_free_static_weak (__libc_reg_printf_freemem_ptr);
+      call_free_static_weak (__libc_reg_type_freemem_ptr);
+
+      call_free_static_weak (__libc_getgrgid_freemem_ptr);
+      call_free_static_weak (__libc_getgrnam_freemem_ptr);
+      call_free_static_weak (__libc_getpwnam_freemem_ptr);
+      call_free_static_weak (__libc_getpwuid_freemem_ptr);
+      call_free_static_weak (__libc_getspnam_freemem_ptr);
+      call_free_static_weak (__libc_getaliasbyname_freemem_ptr);
+      call_free_static_weak (__libc_gethostbyaddr_freemem_ptr);
+      call_free_static_weak (__libc_gethostbyname_freemem_ptr);
+      call_free_static_weak (__libc_gethostbyname2_freemem_ptr);
+      call_free_static_weak (__libc_getnetbyaddr_freemem_ptr);
+      call_free_static_weak (__libc_getnetbyname_freemem_ptr);
+      call_free_static_weak (__libc_getprotobynumber_freemem_ptr);
+      call_free_static_weak (__libc_getprotobyname_freemem_ptr);
+      call_free_static_weak (__libc_getrpcbyname_freemem_ptr);
+      call_free_static_weak (__libc_getrpcbynumber_freemem_ptr);
+      call_free_static_weak (__libc_getservbyname_freemem_ptr);
+      call_free_static_weak (__libc_getservbyport_freemem_ptr);
+
+      call_free_static_weak (__libc_getgrent_freemem_ptr);
+      call_free_static_weak (__libc_getpwent_freemem_ptr);
+      call_free_static_weak (__libc_getspent_freemem_ptr);
+      call_free_static_weak (__libc_getaliasent_freemem_ptr);
+      call_free_static_weak (__libc_gethostent_freemem_ptr);
+      call_free_static_weak (__libc_getnetent_freemem_ptr);
+      call_free_static_weak (__libc_getprotoent_freemem_ptr);
+      call_free_static_weak (__libc_getrpcent_freemem_ptr);
+      call_free_static_weak (__libc_getservent_freemem_ptr);
+
+      call_free_static_weak (__libc_efgcvt_freemem_ptr);
+      call_free_static_weak (__libc_qefgcvt_freemem_ptr);
+
+      call_freeres_system_funcs;
     }
 }
 libc_hidden_def (__libc_freeres)
index cbb99f8bb4c285f86ba41369b46325e799ce2e0c..416d199afd634380ea2897fae10bd43d0fdb19d8 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <dlfcn/dlerror.h>
 #include <libc-internal.h>
 #include <malloc-internal.h>
-#include <resolv/resolv-internal.h>
-#include <rpc/rpc.h>
-#include <string.h>
-#include <tls-internal.h>
+#include <set-freeres.h>
 #include <shlib-compat.h>
+#include <tls-internal.h>
 
 /* Thread shutdown function.  Note that this function must be called
    for threads during shutdown for correctness reasons.  Unlike
-   __libc_subfreeres, skipping calls to it is not a valid optimization.
+   __libc_freeres, skipping calls to it is not a valid optimization.
    This is called directly from pthread_create as the thread exits.  */
 void
 __libc_thread_freeres (void)
index 27a00a3ab53871fce2de2a0c4548f6592ea740d1..00d0aa1d7e221afe5f4030b7c359b76caa7372a0 100644 (file)
@@ -22,6 +22,7 @@
 #include <sys/param.h>
 #include <libc-lock.h>
 #include <math_ldbl_opt.h>
+#include <set-freeres.h>
 
 #ifndef SPRINTF
 # define SPRINTF sprintf
@@ -38,7 +39,7 @@
 
 static char FCVT_BUFFER[MAXDIG];
 static char ECVT_BUFFER[MAXDIG];
-libc_freeres_ptr (static char *FCVT_BUFPTR);
+static char *FCVT_BUFPTR;
 
 char *
 __FCVT (FLOAT_TYPE value, int ndigit, int *decpt, int *sign)
@@ -73,3 +74,5 @@ __GCVT (FLOAT_TYPE value, int ndigit, char *buf)
   SPRINTF (buf, "%.*" FLOAT_FMT_FLAG "g", MIN (ndigit, NDIGIT_MAX), value);
   return buf;
 }
+
+weak_alias (FCVT_BUFPTR, __EFGCVT_FREEMEM_PTR);
index 53673a08fe49d35933853d07064246c2262e545c..f2a33afcdf448bc654d8054f59cafe849a8e9452 100644 (file)
@@ -24,6 +24,7 @@
 #define __GCVT __gcvt
 #define __ECVT_R __ecvt_r
 #define __FCVT_R __fcvt_r
+#define __EFGCVT_FREEMEM_PTR __libc_efgcvt_freemem_ptr
 #include <efgcvt-dbl-macros.h>
 #include <efgcvt-template.c>
 
index 0e04235a2b1175dff08df8a52b2ff2e4ea1f0319..ea4afc7d0f30dbd4a6013477575d575a6c984f99 100644 (file)
@@ -177,7 +177,8 @@ fstab_convert (struct fstab_state *state)
 
 /* Make sure the memory is freed if the programs ends while in
    memory-debugging mode and something actually was allocated.  */
-libc_freeres_fn (fstab_free)
+void
+__libc_fstab_freemem (void)
 {
   char *buffer;
 
index 615f7f08a380b01737b56d1a1c658c8e22a3094f..f9a3f9267a572fc56622f5c76d1fe65d8aca24d8 100644 (file)
@@ -46,7 +46,3 @@ __hdestroy (void)
   __hdestroy_r (&htab);
 }
 weak_alias (__hdestroy, hdestroy)
-
-/* Make sure the table is freed if we want to free everything before
-   exiting.  */
-text_set_element (__libc_subfreeres, __hdestroy);
index 4a1c5444cf8f5767680e5533566749c649e792d2..61dc63f253d965fd9867b4931c74865f65c5d4a3 100644 (file)
@@ -19,6 +19,7 @@
 #include <mntent.h>
 #include <stdlib.h>
 #include <allocate_once.h>
+#include <set-freeres.h>
 
 struct mntent_buffer
 {
@@ -28,7 +29,7 @@ struct mntent_buffer
 
 /* We don't want to allocate the static buffer all the time since it
    is not always used (in fact, rather infrequently).  */
-libc_freeres_ptr (static void *mntent_buffer);
+static void *mntent_buffer;
 
 static void *
 allocate (void *closure)
@@ -56,3 +57,5 @@ getmntent (FILE *stream)
   return __getmntent_r (stream, &buffer->m,
                        buffer->buffer, sizeof (buffer->buffer));
 }
+
+weak_alias (mntent_buffer, __libc_mntent_freemem_ptr)
index 91a3e2014a6c91d37b6ebdcb95b90daa9ca9172e..a4ea8b801e2ed4bf5cb21f9724708be655b35e59 100644 (file)
@@ -24,6 +24,7 @@
 #define __GCVT __qgcvt
 #define __ECVT_R __qecvt_r
 #define __FCVT_R __qfcvt_r
+#define __EFGCVT_FREEMEM_PTR __libc_qefgcvt_freemem_ptr
 #include <efgcvt-ldbl-macros.h>
 #include <efgcvt-template.c>
 
index 63b655949e0d1fad93ce233652f20d8878dede98..c1e971b305397fb29d5af49b48d36677e4669b08 100644 (file)
@@ -131,7 +131,7 @@ __libc_unwind_link_after_fork (void)
     }
 }
 
-void __libc_freeres_fn_section
+void
 __libc_unwind_link_freeres (void)
 {
   if (global_libgcc_handle != NULL)
index 03ee6bd31aebd5ad889ef569b8fd8c6df40fcf18..ee9bca8387faec16094b4ee91111acf9cebddbd2 100644 (file)
@@ -16,7 +16,6 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <set-hooks.h>
 #include <libc-symbols.h>
 #include <pthreadP.h>
 #include <nptl-stack.h>
index f30d99973d5048e83ffb8293982b958d46bd4ff8..07e894019a737c26f9e2ea53eca37bd8cd0033bb 100644 (file)
@@ -68,7 +68,8 @@ libc_locked_map_ptr (,__gr_map_handle) attribute_hidden;
 /* Note that we only free the structure if necessary.  The memory
    mapping is not removed since it is not visible to the malloc
    handling.  */
-libc_freeres_fn (gr_map_free)
+void
+__nscd_gr_map_freemem (void)
 {
   if (__gr_map_handle.mapped != NO_MAPPING)
     {
index ab9c9d311f29a9116f47ee3222e9d90efe041e1a..c6a6247f73a84dab03319375539f5ee7c4a9096e 100644 (file)
@@ -81,7 +81,8 @@ libc_locked_map_ptr (, __hst_map_handle) attribute_hidden;
 /* Note that we only free the structure if necessary.  The memory
    mapping is not removed since it is not visible to the malloc
    handling.  */
-libc_freeres_fn (hst_map_free)
+void
+__nscd_hst_map_freemem (void)
 {
   if (__hst_map_handle.mapped != NO_MAPPING)
     {
index 0cae7ad61c8a260831ed9fc33de0a7554b5c6a24..17d9753f8a2a7156179cc1f13471c262930dc2c3 100644 (file)
@@ -67,7 +67,8 @@ libc_locked_map_ptr (static, map_handle);
 /* Note that we only free the structure if necessary.  The memory
    mapping is not removed since it is not visible to the malloc
    handling.  */
-libc_freeres_fn (pw_map_free)
+void
+__nscd_pw_map_freemem (void)
 {
   if (map_handle.mapped != NO_MAPPING)
     {
index 6969fcb739450ec3b805fe84139c0e9099214abe..1458c6ca22c4fb710bcc2fd4eb7819975c89d0a7 100644 (file)
@@ -62,7 +62,8 @@ libc_locked_map_ptr (, __serv_map_handle) attribute_hidden;
 /* Note that we only free the structure if necessary.  The memory
    mapping is not removed since it is not visible to the malloc
    handling.  */
-libc_freeres_fn (serv_map_free)
+void
+__nscd_serv_map_freemem (void)
 {
   if (__serv_map_handle.mapped != NO_MAPPING)
     {
index 29cd3a5116d8644a04020f42486ae32aafb51e65..6f4c383ace4bde80e94b51db4fb72f6f4584cc04 100644 (file)
@@ -31,7 +31,8 @@ libc_locked_map_ptr (static, map_handle);
 /* Note that we only free the structure if necessary.  The memory
    mapping is not removed since it is not visible to the malloc
    handling.  */
-libc_freeres_fn (pw_map_free)
+void
+__nscd_group_map_freemem (void)
 {
   if (map_handle.mapped != NO_MAPPING)
     {
index 0c473a429498be14151aff8f6e00af8deb9d20f8..efb17f05718c27baf252230bfff1abc29e404ced 100644 (file)
@@ -20,6 +20,7 @@
 #include <libc-lock.h>
 #include <stdlib.h>
 #include <resolv.h>
+#include <set-freeres.h>
 
 #include "nsswitch.h"
 
@@ -58,6 +59,9 @@
 #define APPEND_R1(name) name##_r
 #define INTERNAL(name) INTERNAL1 (name)
 #define INTERNAL1(name) __##name
+#define APPEND_FREEMEM_NAME1(name) __libc_##name##_freemem_ptr
+#define APPEND_FREEMEM_NAME(name) APPEND_FREEMEM_NAME1(name)
+#define FREEMEM_NAME APPEND_FREEMEM_NAME (FUNCTION_NAME)
 
 /* Sometimes we need to store error codes in the `h_errno' variable.  */
 #ifdef NEED_H_ERRNO
@@ -86,8 +90,9 @@ extern int INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf,
 __libc_lock_define_initialized (static, lock);
 
 /* This points to the static buffer used.  */
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
+weak_alias (buffer, FREEMEM_NAME)
 
 LOOKUP_TYPE *
 FUNCTION_NAME (ADD_PARAMS)
index 7ac8379fbcf0f2437699f1dcce16e4185640ca8b..8acb6dc54fbe9fa27b47f920d9fab83e5d6bcc07 100644 (file)
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <libc-lock.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 #include "nsswitch.h"
 
@@ -43,6 +44,9 @@
 #define APPEND_R1(name) name##_r
 #define INTERNAL(name) INTERNAL1 (name)
 #define INTERNAL1(name) __##name
+#define APPEND_FREEMEM_NAME1(name) __libc_##name##_freemem_ptr
+#define APPEND_FREEMEM_NAME(name) APPEND_FREEMEM_NAME1(name)
+#define FREEMEM_NAME APPEND_FREEMEM_NAME (GETFUNC_NAME)
 
 /* Sometimes we need to store error codes in the `h_errno' variable.  */
 #ifdef NEED_H_ERRNO
@@ -62,8 +66,9 @@ extern int INTERNAL (REENTRANT_GETNAME) (LOOKUP_TYPE *resbuf, char *buffer,
 __libc_lock_define_initialized (static, lock);
 
 /* This points to the static buffer used.  */
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
+weak_alias (buffer, FREEMEM_NAME)
 
 LOOKUP_TYPE *
 GETFUNC_NAME (void)
index 8ca72546ebafb9df3e9a2c1736944c10c4ccddc4..447c219c5b0ee686161fec2c5aad07952e04959f 100644 (file)
@@ -102,7 +102,7 @@ __nss_action_allocate (struct nss_action *actions, size_t count)
   return result;
 }
 
-void __libc_freeres_fn_section
+void
 __nss_action_freeres (void)
 {
   struct nss_action_list_wrapper *current = nss_actions;
index edd84b8e8ad4b15e9caa5b2e533ec95a4a741617..7ab24154175f3d5dae7bcb256ccb9178d661998e 100644 (file)
@@ -101,8 +101,5 @@ nss_action_list __nss_action_allocate (struct nss_action *actions,
    EINVAL means that LINE is syntactically invalid.  */
 nss_action_list __nss_action_parse (const char *line);
 
-/* Called from __libc_freeres.  */
-void __nss_action_freeres (void) attribute_hidden;
-
 
 #endif /* _NSS_ACTION_H */
index 335034605fb6d92f6263c68cdda30042375c5f48..2edcab4b9d79f3801ec04280db59f656b14ec53c 100644 (file)
@@ -495,7 +495,7 @@ __nss_database_get_noreload (enum nss_database db)
   return result;
 }
 
-void __libc_freeres_fn_section
+void
 __nss_database_freeres (void)
 {
   free (global_database_state);
index 24620305116c9c74ad566997ae3dc23a5727336b..1a17261f65d223f37edb30480d60ed74d5bbe678 100644 (file)
@@ -64,9 +64,6 @@ libc_hidden_proto (__nss_database_get)
 nss_action_list __nss_database_get_noreload (enum nss_database db)
   attribute_hidden;
 
-/* Called from __libc_freeres.  */
-void __nss_database_freeres (void) attribute_hidden;
-
 /* Internal type.  Exposed only for fork handling purposes.  */
 struct nss_database_data
 {
index 8815fefc2175cf98f97c337a53c04f9017a08b30..487e513def458c07d0ce9580cf89b453af7cba4a 100644 (file)
@@ -416,7 +416,7 @@ __nss_module_disable_loading (void)
   __libc_lock_unlock (nss_module_list_lock);
 }
 
-void __libc_freeres_fn_section
+void
 __nss_module_freeres (void)
 {
   struct nss_module *current = nss_module_list;
index eda0ebc5ef3dc7c86ccf917470db35a7ab8040b4..fb30fb8b4c9d651011d3750e3ae381448328b229 100644 (file)
@@ -100,7 +100,4 @@ void *__nss_module_get_function (struct nss_module *module, const char *name)
 /* Block attempts to dlopen any module we haven't already opened.  */
 void __nss_module_disable_loading (void);
 
-/* Called from __libc_freeres.  */
-void __nss_module_freeres (void) attribute_hidden;
-
 #endif /* NSS_MODULE_H */
index c3231ea824527f072145cfe30e45eee8e089d34a..647b18ba9e6d20d8328576fdfd0ea07c3fe21940 100644 (file)
@@ -710,7 +710,8 @@ re_comp (const char *s)
 }
 
 #ifdef _LIBC
-libc_freeres_fn (free_mem)
+void
+__libc_regcomp_freemem (void)
 {
   __regfree (&re_comp_buf);
 }
index 4d89a457a0ddf7bfa996f353bd09d1ad449a4a90..14ebc2587a59dff702f8134732ff13887b318df1 100644 (file)
@@ -217,7 +217,8 @@ __run_postfork_handlers (enum __run_fork_handler_type who, _Bool do_locking,
 }
 
 
-libc_freeres_fn (free_mem)
+void
+__libc_atfork_freemem (void)
 {
   lll_lock (atfork_lock, LLL_PRIVATE);
 
index f069aa6f0c7d870028bbdb4e33c891358e515cae..b7864d263a19f33c9891f90f482c2cc94077ad75 100644 (file)
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
 
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* Read one entry from the given stream.  */
 struct passwd *
@@ -82,3 +83,5 @@ fgetpwent (FILE *stream)
 
   return result;
 }
+
+weak_alias (buffer, __libc_fgetpwent_freemem_ptr)
index dda9b47f003921bb0d972dbb20a9d4ea801d4daf..9e3b1d29b7a3f2bad921c37675752a184d1b9a38 100644 (file)
@@ -434,7 +434,11 @@ handle_requests (void *arg)
 
 
 /* Free allocated resources.  */
-libc_freeres_fn (free_res)
+#if !PTHREAD_IN_LIBC
+__attribute__ ((__destructor__)) static
+#endif
+void
+__gai_freemem (void)
 {
   size_t row;
 
index 936fd3d1ddcfa592a6cefd7f584732fc6356d6c3..8d546777c71b9fbd559108cda42b3f6e027b047c 100644 (file)
@@ -140,5 +140,3 @@ __res_thread_freeres (void)
   /* Make sure we do a full re-initialization the next time.  */
   _res.options = 0;
 }
-/* Also must be called when the main thread exits.  */
-text_set_element (__libc_subfreeres, __res_thread_freeres);
index 2c4e12b6cdcd21395474841ba4738a3adab05bce..89bd20be3802323639260549c6bbac425df15a1f 100644 (file)
@@ -42,6 +42,7 @@
 #include "res_hconf.h"
 #include <wchar.h>
 #include <atomic.h>
+#include <set-freeres.h>
 
 #if IS_IN (libc)
 # define fgets_unlocked __fgets_unlocked
@@ -330,19 +331,8 @@ _res_hconf_init (void)
 #if IS_IN (libc)
 # if defined SIOCGIFCONF && defined SIOCGIFNETMASK
 /* List of known interfaces.  */
-libc_freeres_ptr (
-static struct netaddr
-{
-  int addrtype;
-  union
-  {
-    struct
-    {
-      uint32_t addr;
-      uint32_t mask;
-    } ipv4;
-  } u;
-} *ifaddrs);
+static struct netaddr *ifaddrs;
+weak_alias (ifaddrs, __libc_resolv_res_hconf_freemem_ptr)
 # endif
 
 /* Reorder addresses returned in a hostent such that the first address
index 97812ebf6cf565f76d3d04ee261d13eb9b78176d..c55f3c03662c332f0c6286abee289ad694f2faa7 100644 (file)
    loads and stores.  */
 typedef HEADER __attribute__ ((__aligned__(1))) UHEADER;
 
+/* List of known interfaces.  */
+struct netaddr
+{
+  int addrtype;
+  union
+  {
+    struct
+    {
+      uint32_t addr;
+      uint32_t mask;
+    } ipv4;
+  } u;
+};
+
 /* Legacy function.  This needs to be removed once all NSS modules
    have been adjusted.  */
 static inline bool
index 2e561c89597efbf384a7aa512baf277c2b5d2696..0ef66d49d301bb24fb613c3a36e13bbeeb5026da 100644 (file)
@@ -654,7 +654,8 @@ __resolv_conf_detach (struct __res_state *resp)
 }
 
 /* Deallocate the global data.  */
-libc_freeres_fn (freeres)
+void
+__libc_resolv_conf_freemem (void)
 {
   /* No locking because this function is supposed to be called when
      the process has turned single-threaded.  */
index 3851ea06ce078fba7dec0593720f07e783ccda66..50a805454677d2f9e889102dced2a70f4b4a2541 100644 (file)
@@ -23,6 +23,8 @@
 #include <resolv.h>
 #include <support/check.h>
 
+void __libc_freeres (void);
+
 static int
 do_test (void)
 {
index cde3de8b7f992014bd840487b91ad975b7eaf068..49ec0aa293d8b36a16ecc951b71d3f98d5e254b1 100644 (file)
@@ -694,7 +694,11 @@ handle_fildes_io (void *arg)
 
 
 /* Free allocated resources.  */
-libc_freeres_fn (free_res)
+#if !PTHREAD_IN_LIBC
+__attribute__ ((__destructor__)) static
+#endif
+void
+__aio_freemem (void)
 {
   size_t row;
 
index 76a18bf4fb1f6d211bc6fd36286b19d511924b17..541947bad67401dbf7103446b65c74010c799b0e 100644 (file)
@@ -20,6 +20,7 @@
 #include <shadow.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 
 /* A reasonable size for a buffer to start with.  */
@@ -28,7 +29,7 @@
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
 
-libc_freeres_ptr (static char *buffer);
+static char *buffer;
 
 /* Read one shadow entry from the given stream.  */
 struct spwd *
@@ -85,3 +86,5 @@ fgetspent (FILE *stream)
 
   return result;
 }
+
+weak_alias (buffer, __libc_fgetspent_freemem_ptr);
index b911aea70389c59050445df398e1ba5883afb598..a52022d1ba583894f5d69ab36b114b01e46f9ea4 100644 (file)
@@ -183,7 +183,8 @@ __handle_registered_modifier_wc (const unsigned int **format,
 }
 
 
-libc_freeres_fn (free_mem)
+void
+__libc_printf_freemem (void)
 {
   if (__printf_modifier_table != NULL)
     {
index 3ec81e695638de87e28922d7c191bc34b3455e0c..0d14ac6afa3f38242540b980b57c63942ea556d7 100644 (file)
 #include <stddef.h>
 #include <stdlib.h>
 #include <libc-lock.h>
+#include <set-freeres.h>
 
 
 /* Array of functions indexed by format character.  */
-libc_freeres_ptr (printf_arginfo_size_function **__printf_arginfo_table)
-  attribute_hidden;
+printf_arginfo_size_function **__printf_arginfo_table attribute_hidden;
 printf_function **__printf_function_table attribute_hidden;
 
 __libc_lock_define_initialized (static, lock)
@@ -79,3 +79,5 @@ __register_printf_function (int spec, printf_function converter,
                                      (printf_arginfo_size_function*) arginfo);
 }
 weak_alias (__register_printf_function, register_printf_function)
+
+weak_alias (__printf_arginfo_table, __libc_reg_printf_freemem_ptr)
index 02edac4da3e61a1d264df00376e2d6b5b6433d73..980a911ae2354f4f6fd2d690e60c178333f385a4 100644 (file)
 #include <printf.h>
 #include <stdlib.h>
 #include <libc-lock.h>
+#include <set-freeres.h>
 
 
 /* Array of functions indexed by format character.  */
-libc_freeres_ptr (printf_va_arg_function **__printf_va_arg_table)
-  attribute_hidden;
+printf_va_arg_function **__printf_va_arg_table attribute_hidden;
 
 __libc_lock_define_initialized (static, lock);
 
@@ -59,3 +59,5 @@ __register_printf_type (printf_va_arg_function fct)
   return result;
 }
 weak_alias (__register_printf_type, register_printf_type)
+
+weak_alias (__printf_va_arg_table, __libc_reg_type_freemem_ptr)
index 1cd0bdfe948cd1a8d5f9ede23a84ba0d9b78632c..d6c188b739234fae3fb12c5211ec5864b2c5efb4 100644 (file)
@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <pointer_guard.h>
 #include <libc-lock.h>
-#include <libio/libioP.h>
+#include <set-freeres.h>
 #include "exit.h"
 
 /* Initialize the flag that indicates exit function processing
index b631ef3d01496f5dfb86964c8cac4df44306f076..3d9a0edf122d3a3f37dac0cd84a3bcb8f84ddd78 100644 (file)
@@ -361,7 +361,8 @@ __addseverity (int severity, const char *string)
 weak_alias (__addseverity, addseverity)
 
 
-libc_freeres_fn (free_mem)
+void
+__libc_fmtmsg_freemem (void)
 {
   struct severity_info *runp = severity_list;
 
index 2fa9e41e3100cc55b9316dd78d9fbf3b147e227d..ba5257d3bfafd5227ac03e09f96de5acb551f685 100644 (file)
@@ -323,7 +323,8 @@ clearenv (void)
   return 0;
 }
 #ifdef _LIBC
-libc_freeres_fn (free_mem)
+void
+__libc_setenv_freemem (void)
 {
   /* Remove all traces.  */
   clearenv ();
index 67499fd03ff0d9dc3832de7827345a9592ce2746..c3d13722df718ef0426459ad36b8be6432a3b125 100644 (file)
@@ -389,8 +389,8 @@ auth_errmsg (enum auth_stat stat)
 }
 
 
-libc_freeres_fn (free_mem)
+void
+__rpc_freemem (void)
 {
-  /* Not libc_freeres_ptr, since buf is a macro.  */
   free (buf);
 }
index 0abe6dc17204012569e49a77fab5790437ff0273..a04b7ec47fa4760cac6a635f4373405372aa1a71 100644 (file)
@@ -37,7 +37,6 @@ __rpc_thread_destroy (void)
                thread_rpc_vars = NULL;
        }
 }
-text_set_element (__libc_subfreeres, __rpc_thread_destroy);
 
 /*
  * Initialize RPC multi-threaded operation
index 542c5c2a89231d0d2c16732937d3387123c76b9c..434a5bedef982d305c46ac24926156fbb04ce1f9 100644 (file)
@@ -276,9 +276,9 @@ do_test (void)
               else
                 /* This is arguably a bug: Regular process termination
                    does not unregister the service with rpcbind.  The
-                   unset rpcbind call happens from a __libc_subfreeres
-                   callback, and this only happens when running under
-                   memory debuggers such as valgrind.  */
+                   unset rpcbind call happens from a __libc_freeres,
+                   and this only happens when running under memory debuggers
+                  such as valgrind.  */
                 TEST_VERIFY (!state.unset_called);
             }
           else
diff --git a/sysdeps/generic/set-freeres-fp.h b/sysdeps/generic/set-freeres-fp.h
new file mode 100644 (file)
index 0000000..f73ac74
--- /dev/null
@@ -0,0 +1,19 @@
+/* System specific resource deallocation.  Generic version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define call_freeres_fp_funcs
diff --git a/sysdeps/generic/set-freeres-os.h b/sysdeps/generic/set-freeres-os.h
new file mode 100644 (file)
index 0000000..6b17c83
--- /dev/null
@@ -0,0 +1,19 @@
+/* System specific resource deallocation.  Generic version.
+   Copyright (C) 2020-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define call_freeres_os_funcs
diff --git a/sysdeps/generic/set-freeres-system.h b/sysdeps/generic/set-freeres-system.h
new file mode 100644 (file)
index 0000000..88701a6
--- /dev/null
@@ -0,0 +1,27 @@
+/* System specific resource deallocation.  Generic version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* Each system may define weak functions to free any resource allocated with
+   malloc to avoid interfere with mtrace.  */
+
+#include <set-freeres-os.h>
+#include <set-freeres-fp.h>
+
+#define call_freeres_system_funcs      \
+  call_freeres_os_funcs;               \
+  call_freeres_fp_funcs
index e56e01ab2dee3a3afac8a15c296a48662bb8c3c2..18a881d4d0f6e30c7dc16ec71e2804fa2f799898 100644 (file)
@@ -42,6 +42,7 @@ typeof (qfcvt_r) ___qfcvtieee128_r;
 #define __GCVT ___qgcvtieee128
 #define __ECVT_R ___qecvtieee128_r
 #define __FCVT_R ___qfcvtieee128_r
+#define __EFGCVT_FREEMEM_PTR __libc_efgcvtieee128_freemem_ptr
 #include <efgcvt-ldbl-macros.h>
 #include <efgcvt-template.c>
 
diff --git a/sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h b/sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h
new file mode 100644 (file)
index 0000000..3f6e176
--- /dev/null
@@ -0,0 +1,22 @@
+/* System specific resource deallocation.  IBM long double 128 version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+extern char * __libc_efgcvtieee128_freemem_ptr attribute_hidden;
+
+#define call_freeres_fp_funcs \
+  call_free_static_weak (__libc_efgcvtieee128_freemem_ptr)
index 90c8897739b39e1a797069c6023cf8d54fbefe5b..0d935e724ad004f294b6846aa9e948d55308e14c 100644 (file)
@@ -9,7 +9,6 @@
      mach/boolean.h
      mach/i386/boolean.h
      mach/i386/vm_types.h
-     mach/i386/stdint.h
      mach/mig_errors.h
      device/device_types.h
      mach/std_types.h
index fd22dc4fcbc1dcd773f94e8b3202c10ab3be99fb..0356b622be6dda5e6ac9bf70c9813cc1351a0b81 100644 (file)
@@ -1761,7 +1761,8 @@ check_gaiconf_mtime (const struct __stat64_t64 *st)
 #endif
 
 
-libc_freeres_fn(fini)
+void
+__libc_getaddrinfo_freemem (void)
 {
   if (labels != default_labels)
     {
@@ -2233,7 +2234,7 @@ no_file:
 
   /* If we previously read the file but it is gone now, free the old data and
      use the builtin one.  Leave the reload flag alone.  */
-  fini ();
+  __libc_getaddrinfo_freemem ();
 }
 
 
index 2e19aff758badffda49901a7643b86d6ec65abf4..a5805cd6625eaf7ae655b85c9706273701685913 100644 (file)
@@ -24,6 +24,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
+#include <set-freeres.h>
 
 char *__ttyname;
 
@@ -31,7 +32,8 @@ static char *getttyname (int fd, dev_t mydev, ino_t myino,
                         int save, int *dostat);
 
 
-libc_freeres_ptr (static char *getttyname_name);
+static char *getttyname_name;
+weak_alias (getttyname_name, __ttyname_freemem_ptr)
 
 static char *
 getttyname (int fd, dev_t mydev, ino_t myino, int save, int *dostat)
index de207122b07b485ab8e5a378576ce9527d936e49..b157c5126cc95bee2ba1753daf6555760c57a4ad 100644 (file)
@@ -362,7 +362,8 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
 }
 
 /* Free the cache if it has been allocated.  */
-libc_freeres_fn (freecache)
+void
+__check_pf_freemem (void)
 {
   if (cache)
     __free_in6ai (cache->in6ai);
index d8188f8b5ba918f626295da252885fe1ae15023a..562495b1222019a81f7f319c096949607239bdcc 100644 (file)
@@ -25,6 +25,7 @@
 # define weak_alias(n,a)
 #endif
 #include "login/getutent.c"
+_weak_alias (buffer, __libc_getutent_freemem_ptr)
 
 #if defined SHARED
 default_symbol_version (__getutent, getutent, UTMP_COMPAT_BASE);
index cd981c72ba669d5d27ce1f7de26e988e73156188..ccdc25b2d6cab3d4dec3d6d9235a1a58a685811d 100644 (file)
@@ -25,6 +25,7 @@
 # define weak_alias(n,a)
 #endif
 #include "login/getutid.c"
+_weak_alias (buffer, __libc_getutid_freemem_ptr)
 
 #if defined SHARED
 default_symbol_version (__getutid, getutid, UTMP_COMPAT_BASE);
index 0b611619f19e07702f4a0fd4829d2db6269d884b..16e8f1791503c53ffd52e3e284cbe16e19e876e7 100644 (file)
@@ -25,6 +25,7 @@
 # define weak_alias(n,a)
 #endif
 #include "login/getutline.c"
+_weak_alias (buffer, __libc_getutline_freemem_ptr)
 
 #if defined SHARED
 default_symbol_version (__getutline, getutline, UTMP_COMPAT_BASE);
diff --git a/sysdeps/unix/sysv/linux/set-freeres-os.h b/sysdeps/unix/sysv/linux/set-freeres-os.h
new file mode 100644 (file)
index 0000000..964c9a4
--- /dev/null
@@ -0,0 +1,24 @@
+/* System specific resource deallocation.  Linux version.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+extern void __check_pf_freemem (void) attribute_hidden;
+extern char * __ttyname_freemem_ptr attribute_hidden;
+
+#define call_freeres_os_funcs                    \
+  call_function_static_weak (__check_pf_freemem); \
+  call_free_static_weak (__ttyname_freemem_ptr)
index f3870f8ec347390ecc0377b7f74db0a73f2c6715..406fbb30f2fbebc3a770d37e25baaf2a15c2ff56 100644 (file)
 #include <limits.h>
 #include <termios.h>
 #include <stdlib.h>
-
+#include <set-freeres.h>
 #include "ttyname.h"
 
 static char *ttyname_buf = NULL;
-
-libc_freeres_fn (free_mem)
-{
-  free (ttyname_buf);
-}
+weak_alias (ttyname_buf, __ttyname_freemem_ptr)
 
 /* Return the pathname of the terminal FD is open on, or NULL on errors.
    The returned storage is good only until the next call to this function.  */
index 55508c154b64313ad99700f888171aeed83cf29c..9e27eba4a7d05e94a4dde18cb2ea4e63000cebb7 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <stdint.h>
 #include <alloc_buffer.h>
+#include <set-freeres.h>
 
 #include <timezone/tzfile.h>
 
@@ -50,7 +51,7 @@ struct leap
   };
 
 static size_t num_transitions;
-libc_freeres_ptr (static __time64_t *transitions);
+static __time64_t *transitions;
 static unsigned char *type_idxs;
 static size_t num_types;
 static struct ttinfo *types;
@@ -780,3 +781,5 @@ __tzfile_compute (__time64_t timer, int use_localtime,
        }
     }
 }
+
+weak_alias (transitions, __libc_tzfile_freemem_ptr)
index 3df62106d8b1bae0577a3bfcefba7fdde3dc93c9..8c740a4e4dc10b449c21a171a0d60743df13caee 100644 (file)
@@ -610,7 +610,8 @@ __tz_convert (__time64_t timer, int use_localtime, struct tm *tp)
 }
 
 
-libc_freeres_fn (free_mem)
+void
+__libc_tzset_freemem (void)
 {
   while (tzstring_list != NULL)
     {
This page took 0.136762 seconds and 5 git commands to generate.