aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>2022-12-27 18:11:42 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-03-27 13:57:55 -0300
commit88677348b4de73874ca7d5a47451f42880f65f07 (patch)
tree9ebe22b88c2487331521737dfdf089f9e3e2439f
parente4d336f1ace7c7ca535f7f85485373752bc76ed5 (diff)
downloadglibc-88677348b4de73874ca7d5a47451f42880f65f07.tar.xz
glibc-88677348b4de73874ca7d5a47451f42880f65f07.zip
Move libc_freeres_ptrs and libc_subfreeres to hidden/weak functions
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>
-rw-r--r--Makerules7
-rw-r--r--crypt/md5-crypt.c7
-rw-r--r--crypt/sha256-crypt.c7
-rw-r--r--crypt/sha512-crypt.c7
-rw-r--r--dlfcn/dlerror.h1
-rw-r--r--elf/dl-libc.c5
-rw-r--r--grp/fgetgrent.c5
-rw-r--r--gshadow/fgetsgent.c5
-rw-r--r--iconv/gconv_cache.c3
-rw-r--r--iconv/gconv_conf.c3
-rw-r--r--iconv/gconv_db.c6
-rw-r--r--iconv/gconv_dl.c5
-rw-r--r--include/libc-symbols.h73
-rw-r--r--include/set-freeres.h142
-rw-r--r--inet/getnameinfo.c5
-rw-r--r--inet/getnetgrent.c5
-rw-r--r--inet/rcmd.c5
-rw-r--r--inet/rexec.c5
-rw-r--r--intl/dcigettext.c3
-rw-r--r--intl/finddomain.c2
-rw-r--r--intl/loadmsgcat.c1
-rw-r--r--intl/localealias.c15
-rw-r--r--libio/fcloseall.c1
-rw-r--r--libio/genops.c8
-rw-r--r--libio/libioP.h1
-rw-r--r--locale/loadarchive.c2
-rw-r--r--locale/localeinfo.h4
-rw-r--r--locale/setlocale.c4
-rw-r--r--login/getutent.c5
-rw-r--r--login/getutid.c6
-rw-r--r--login/getutline.c5
-rw-r--r--malloc/set-freeres.c156
-rw-r--r--malloc/thread-freeres.c9
-rw-r--r--misc/efgcvt-template.c5
-rw-r--r--misc/efgcvt.c1
-rw-r--r--misc/fstab.c3
-rw-r--r--misc/hsearch.c4
-rw-r--r--misc/mntent.c5
-rw-r--r--misc/qefgcvt.c1
-rw-r--r--misc/unwind-link.c2
-rw-r--r--nptl/nptlfreeres.c1
-rw-r--r--nscd/nscd_getgr_r.c3
-rw-r--r--nscd/nscd_gethst_r.c3
-rw-r--r--nscd/nscd_getpw_r.c3
-rw-r--r--nscd/nscd_getserv_r.c3
-rw-r--r--nscd/nscd_netgroup.c3
-rw-r--r--nss/getXXbyYY.c7
-rw-r--r--nss/getXXent.c7
-rw-r--r--nss/nss_action.c2
-rw-r--r--nss/nss_action.h3
-rw-r--r--nss/nss_database.c2
-rw-r--r--nss/nss_database.h3
-rw-r--r--nss/nss_module.c2
-rw-r--r--nss/nss_module.h3
-rw-r--r--posix/regcomp.c3
-rw-r--r--posix/register-atfork.c3
-rw-r--r--pwd/fgetpwent.c5
-rw-r--r--resolv/gai_misc.c6
-rw-r--r--resolv/res-close.c2
-rw-r--r--resolv/res_hconf.c16
-rw-r--r--resolv/resolv-internal.h14
-rw-r--r--resolv/resolv_conf.c3
-rw-r--r--resolv/tst-leaks2.c2
-rw-r--r--rt/aio_misc.c6
-rw-r--r--shadow/fgetspent.c5
-rw-r--r--stdio-common/reg-modifier.c3
-rw-r--r--stdio-common/reg-printf.c6
-rw-r--r--stdio-common/reg-type.c6
-rw-r--r--stdlib/exit.c2
-rw-r--r--stdlib/fmtmsg.c3
-rw-r--r--stdlib/setenv.c3
-rw-r--r--sunrpc/clnt_perr.c4
-rw-r--r--sunrpc/rpc_thread.c1
-rw-r--r--sunrpc/tst-svc_register.c6
-rw-r--r--sysdeps/generic/set-freeres-fp.h19
-rw-r--r--sysdeps/generic/set-freeres-os.h19
-rw-r--r--sysdeps/generic/set-freeres-system.h27
-rw-r--r--sysdeps/ieee754/ldbl-128ibm-compat/ieee128-qefgcvt.c1
-rw-r--r--sysdeps/ieee754/ldbl-128ibm-compat/set-freeres-fp.h22
-rw-r--r--sysdeps/mach/hurd/bits/errno.h1
-rw-r--r--sysdeps/posix/getaddrinfo.c5
-rw-r--r--sysdeps/posix/ttyname.c4
-rw-r--r--sysdeps/unix/sysv/linux/check_pf.c3
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/getutent.c1
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/getutid.c1
-rw-r--r--sysdeps/unix/sysv/linux/s390/s390-32/getutline.c1
-rw-r--r--sysdeps/unix/sysv/linux/set-freeres-os.h24
-rw-r--r--sysdeps/unix/sysv/linux/ttyname.c8
-rw-r--r--time/tzfile.c5
-rw-r--r--time/tzset.c3
90 files changed, 584 insertions, 243 deletions
diff --git a/Makerules b/Makerules
index fae6b626e6..f6071eab50 100644
--- 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 = .);\
diff --git a/crypt/md5-crypt.c b/crypt/md5-crypt.c
index 0cc597a7f2..4e4760545a 100644
--- a/crypt/md5-crypt.c
+++ b/crypt/md5-crypt.c
@@ -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
diff --git a/crypt/sha256-crypt.c b/crypt/sha256-crypt.c
index 1ef16af80f..e90eb590bb 100644
--- a/