120 lines
3.8 KiB
Diff
120 lines
3.8 KiB
Diff
commit f1d333b5bfdb3561c93feb4b5653d051c3258c59
|
|
Author: Florian Weimer <fweimer@redhat.com>
|
|
Date: Wed Nov 17 12:20:29 2021 +0100
|
|
|
|
elf: Introduce GLRO (dl_libc_freeres), called from __libc_freeres
|
|
|
|
This will be used to deallocate memory allocated using the non-minimal
|
|
malloc.
|
|
|
|
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
|
Conflicts:
|
|
elf/Makefile
|
|
Updated for change of layout
|
|
sysdeps/generic/ldsodefs.h
|
|
Updated for minor context changes
|
|
|
|
diff --git a/elf/Makefile b/elf/Makefile
|
|
index 3eac746d21042ec9..f5c9b6df9a8f9acd 100644
|
|
--- a/elf/Makefile
|
|
+++ b/elf/Makefile
|
|
@@ -133,6 +133,7 @@ rtld-routines = \
|
|
dl-hwcaps \
|
|
dl-hwcaps-subdirs \
|
|
dl-hwcaps_split \
|
|
+ dl-libc_freeres \
|
|
dl-minimal \
|
|
dl-mutex \
|
|
dl-sysdep \
|
|
diff --git a/elf/dl-libc_freeres.c b/elf/dl-libc_freeres.c
|
|
new file mode 100644
|
|
index 0000000000000000..68f305a6f98aac0c
|
|
--- /dev/null
|
|
+++ b/elf/dl-libc_freeres.c
|
|
@@ -0,0 +1,24 @@
|
|
+/* Deallocating malloc'ed memory from the dynamic loader.
|
|
+ Copyright (C) 2021 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/>. */
|
|
+
|
|
+#include <ldsodefs.h>
|
|
+
|
|
+void
|
|
+__rtld_libc_freeres (void)
|
|
+{
|
|
+}
|
|
diff --git a/elf/rtld.c b/elf/rtld.c
|
|
index dac827e249b2fe14..fd70c4c3528cda2d 100644
|
|
--- a/elf/rtld.c
|
|
+++ b/elf/rtld.c
|
|
@@ -380,6 +380,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
|
|
._dl_catch_error = _dl_catch_error,
|
|
._dl_error_free = _dl_error_free,
|
|
._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
|
|
+ ._dl_libc_freeres = __rtld_libc_freeres,
|
|
#ifdef HAVE_DL_DISCOVER_OSVERSION
|
|
._dl_discover_osversion = _dl_discover_osversion
|
|
#endif
|
|
diff --git a/malloc/set-freeres.c b/malloc/set-freeres.c
|
|
index 5c19a2725cdb61e7..856ff7831f84d07c 100644
|
|
--- a/malloc/set-freeres.c
|
|
+++ b/malloc/set-freeres.c
|
|
@@ -21,6 +21,7 @@
|
|
#include <libc-internal.h>
|
|
#include <unwind-link.h>
|
|
#include <dlfcn/dlerror.h>
|
|
+#include <ldsodefs.h>
|
|
|
|
#include "../nss/nsswitch.h"
|
|
#include "../libio/libioP.h"
|
|
@@ -67,6 +68,10 @@ __libc_freeres (void)
|
|
|
|
call_function_static_weak (__libc_dlerror_result_free);
|
|
|
|
+#ifdef SHARED
|
|
+ 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);
|
|
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
|
|
index 484893c2928db8e7..9142bc8f493bce64 100644
|
|
--- a/sysdeps/generic/ldsodefs.h
|
|
+++ b/sysdeps/generic/ldsodefs.h
|
|
@@ -713,6 +713,10 @@ struct rtld_global_ro
|
|
namespace. */
|
|
void (*_dl_error_free) (void *);
|
|
void *(*_dl_tls_get_addr_soft) (struct link_map *);
|
|
+
|
|
+ /* Called from __libc_shared to deallocate malloc'ed memory. */
|
|
+ void (*_dl_libc_freeres) (void);
|
|
+
|
|
#ifdef HAVE_DL_DISCOVER_OSVERSION
|
|
int (*_dl_discover_osversion) (void);
|
|
#endif
|
|
@@ -1503,6 +1507,9 @@ __rtld_mutex_init (void)
|
|
}
|
|
#endif /* !PTHREAD_IN_LIBC */
|
|
|
|
+/* Implementation of GL (dl_libc_freeres). */
|
|
+void __rtld_libc_freeres (void) attribute_hidden;
|
|
+
|
|
#if THREAD_GSCOPE_IN_TCB
|
|
void __thread_gscope_wait (void) attribute_hidden;
|
|
# define THREAD_GSCOPE_WAIT() __thread_gscope_wait ()
|