* [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486]
@ 2020-02-08 19:00 Florian Weimer
2020-02-08 19:00 ` [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable Florian Weimer
` (5 more replies)
0 siblings, 6 replies; 12+ messages in thread
From: Florian Weimer @ 2020-02-08 19:00 UTC (permalink / raw)
To: libc-alpha
I initially wanted to close this bug, but Carlos suggested to treat it
as an RFE. The changes seem a net improvement to me.
This does not completely resolve the issue because we use symbol
interposition for other, more obscure things.
Florian Weimer (4):
elf: Introduce the rtld-stubbed-symbols makefile variable
elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c
Remove weak declaration of free from <inline-hashtab.h>
ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486]
elf/Makefile | 26 +++--
elf/Versions | 3 -
elf/dl-lookup.c | 4 +-
elf/dl-minimal.c | 96 +++++++++++++---
elf/dl-sym-post.h | 106 ++++++++++++++++++
elf/dl-sym.c | 86 +-------------
elf/rtld.c | 12 ++
include/inline-hashtab.h | 15 +--
include/libc-symbols.h | 9 +-
include/malloc.h | 2 +
include/rtld-malloc.h | 85 ++++++++++++++
include/stdlib.h | 2 +
sysdeps/generic/localplt.data | 6 -
sysdeps/mach/hurd/i386/ld.abilist | 4 -
sysdeps/mach/hurd/i386/localplt.data | 6 -
sysdeps/unix/sysv/linux/aarch64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/aarch64/localplt.data | 6 -
sysdeps/unix/sysv/linux/alpha/ld.abilist | 4 -
sysdeps/unix/sysv/linux/alpha/localplt.data | 6 -
sysdeps/unix/sysv/linux/arm/be/ld.abilist | 4 -
sysdeps/unix/sysv/linux/arm/le/ld.abilist | 4 -
sysdeps/unix/sysv/linux/arm/localplt.data | 6 -
sysdeps/unix/sysv/linux/csky/ld.abilist | 4 -
sysdeps/unix/sysv/linux/csky/localplt.data | 6 -
sysdeps/unix/sysv/linux/hppa/ld.abilist | 4 -
sysdeps/unix/sysv/linux/hppa/localplt.data | 6 -
sysdeps/unix/sysv/linux/i386/ld.abilist | 4 -
sysdeps/unix/sysv/linux/i386/localplt.data | 6 -
sysdeps/unix/sysv/linux/ia64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/ia64/localplt.data | 6 -
.../unix/sysv/linux/m68k/coldfire/ld.abilist | 4 -
.../sysv/linux/m68k/coldfire/localplt.data | 6 -
.../unix/sysv/linux/m68k/m680x0/ld.abilist | 4 -
.../unix/sysv/linux/m68k/m680x0/localplt.data | 6 -
sysdeps/unix/sysv/linux/microblaze/ld.abilist | 4 -
.../unix/sysv/linux/microblaze/localplt.data | 6 -
.../unix/sysv/linux/mips/mips32/ld.abilist | 4 -
.../sysv/linux/mips/mips64/n32/ld.abilist | 4 -
.../sysv/linux/mips/mips64/n64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/nios2/ld.abilist | 4 -
sysdeps/unix/sysv/linux/nios2/localplt.data | 6 -
.../linux/powerpc/powerpc32/fpu/localplt.data | 6 -
.../sysv/linux/powerpc/powerpc32/ld.abilist | 4 -
.../powerpc/powerpc32/nofpu/localplt.data | 6 -
.../linux/powerpc/powerpc64/be/ld.abilist | 4 -
.../linux/powerpc/powerpc64/le/ld.abilist | 4 -
.../linux/powerpc/powerpc64/localplt.data | 6 -
sysdeps/unix/sysv/linux/riscv/localplt.data | 6 -
sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/s390/localplt.data | 6 -
.../unix/sysv/linux/s390/s390-32/ld.abilist | 4 -
.../unix/sysv/linux/s390/s390-64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/be/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/le/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/localplt.data | 6 -
.../unix/sysv/linux/sparc/sparc32/ld.abilist | 4 -
.../sysv/linux/sparc/sparc32/localplt.data | 6 -
.../unix/sysv/linux/sparc/sparc64/ld.abilist | 4 -
.../sysv/linux/sparc/sparc64/localplt.data | 6 -
sysdeps/unix/sysv/linux/x86_64/64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist | 4 -
sysdeps/x86_64/localplt.data | 6 -
62 files changed, 326 insertions(+), 364 deletions(-)
create mode 100644 elf/dl-sym-post.h
create mode 100644 include/rtld-malloc.h
--
2.24.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
@ 2020-02-08 19:00 ` Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c Florian Weimer
` (4 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2020-02-08 19:00 UTC (permalink / raw)
To: libc-alpha
This generalizes a mechanism used for stack-protector support, so
that it can be applied to other symbols if required.
Tested on i686-linux-gnu without the stack protector, and on
x86_64-linux-gnu with stack-protector-strong.
---
elf/Makefile | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/elf/Makefile b/elf/Makefile
index 632a4d8b0f..60c8082d06 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -482,21 +482,25 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
# are compiled with special flags, and puts these modules into rtld-libc.a
# for us. Then we do the real link using rtld-libc.a instead of libc_pic.a.
-# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail
-# and __stack_chk_fail_local symbols defined, to prevent the real things
-# being dragged into rtld even though rtld is never built with stack-
-# protection.
+# These symbols need to be stubbed out during symbol discovery because
+# their implementation is provided differently in rtld, and the symbol
+# discovery mechanism is not compatible with the libc implementation
+# when compiled for libc.
+rtld-stubbed-symbols =
+
+# The GCC arguments that implement $(rtld-stubbed-symbols).
+rtld-stubbed-symbols-args = \
+ $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
ifeq ($(have-ssp),yes)
-dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \
- -Wl,--defsym='__stack_chk_fail_local=0'
-else
-dummy-stack-chk-fail :=
+# rtld is not built with the stack protector, so these references will
+# go away in the rebuilds.
+rtld-stubbed-symbols += __stack_chk_fail __stack_chk_fail_local
endif
$(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
@-rm -f $@T
- $(reloc-link) -o $@.o $(dummy-stack-chk-fail) \
+ $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
rm -f $@.o
mv -f $@T $@
--
2.24.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
2020-02-08 19:00 ` [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable Florian Weimer
@ 2020-02-08 19:01 ` Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h> Florian Weimer
` (3 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2020-02-08 19:01 UTC (permalink / raw)
To: libc-alpha
The definitions are moved into a new file, elf/dl-sym-post.h, so that
this code can be used by the dynamic loader as well.
---
elf/dl-sym-post.h | 106 ++++++++++++++++++++++++++++++++++++++++++++++
elf/dl-sym.c | 86 ++-----------------------------------
2 files changed, 110 insertions(+), 82 deletions(-)
create mode 100644 elf/dl-sym-post.h
diff --git a/elf/dl-sym-post.h b/elf/dl-sym-post.h
new file mode 100644
index 0000000000..4c4f574633
--- /dev/null
+++ b/elf/dl-sym-post.h
@@ -0,0 +1,106 @@
+/* Post-processing of a symbol produced by dlsym, dlvsym.
+ Copyright (C) 1999-2020 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/>. */
+
+
+/* Return the link map containing the caller address. */
+static struct link_map *
+_dl_sym_find_caller_link_map (ElfW(Addr) caller)
+{
+ struct link_map *l = _dl_find_dso_for_object (caller);
+ if (l != NULL)
+ return l;
+ else
+ /* If the address is not recognized the call comes from the main
+ program (we hope). */
+ return GL(dl_ns)[LM_ID_BASE]._ns_loaded;
+}
+
+/* Translates RESULT, *REF, VALUE into a symbol address from the point
+ of view of MATCH. Performs IFUNC resolution and auditing if
+ necessary. If MATCH is NULL, CALLER is used to determine it. */
+static void *
+_dl_sym_post (lookup_t result, const ElfW(Sym) *ref, void *value,
+ ElfW(Addr) caller, struct link_map *match)
+{
+ /* Resolve indirect function address. */
+ if (__glibc_unlikely (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC))
+ {
+ DL_FIXUP_VALUE_TYPE fixup
+ = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
+ fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
+ value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
+ }
+
+#ifdef SHARED
+ /* Auditing checkpoint: we have a new binding. Provide the
+ auditing libraries the possibility to change the value and
+ tell us whether further auditing is wanted. */
+ if (__glibc_unlikely (GLRO(dl_naudit) > 0))
+ {
+ const char *strtab = (const char *) D_PTR (result,
+ l_info[DT_STRTAB]);
+ /* Compute index of the symbol entry in the symbol table of
+ the DSO with the definition. */
+ unsigned int ndx = (ref - (ElfW(Sym) *) D_PTR (result,
+ l_info[DT_SYMTAB]));
+
+ if (match == NULL)
+ match = _dl_sym_find_caller_link_map (caller);
+
+ if ((match->l_audit_any_plt | result->l_audit_any_plt) != 0)
+ {
+ unsigned int altvalue = 0;
+ struct audit_ifaces *afct = GLRO(dl_audit);
+ /* Synthesize a symbol record where the st_value field is
+ the result. */
+ ElfW(Sym) sym = *ref;
+ sym.st_value = (ElfW(Addr)) value;
+
+ for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
+ {
+ struct auditstate *match_audit
+ = link_map_audit_state (match, cnt);
+ struct auditstate *result_audit
+ = link_map_audit_state (result, cnt);
+ if (afct->symbind != NULL
+ && ((match_audit->bindflags & LA_FLG_BINDFROM) != 0
+ || ((result_audit->bindflags & LA_FLG_BINDTO)
+ != 0)))
+ {
+ unsigned int flags = altvalue | LA_SYMB_DLSYM;
+ uintptr_t new_value
+ = afct->symbind (&sym, ndx,
+ &match_audit->cookie,
+ &result_audit->cookie,
+ &flags, strtab + ref->st_name);
+ if (new_value != (uintptr_t) sym.st_value)
+ {
+ altvalue = LA_SYMB_ALTVALUE;
+ sym.st_value = new_value;
+ }
+ }
+
+ afct = afct->next;
+ }
+
+ value = (void *) sym.st_value;
+ }
+ }
+#endif
+ return value;
+}
diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index b43a50e544..361b926ea9 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -28,6 +28,7 @@
#include <sysdep-cancel.h>
#include <dl-tls.h>
#include <dl-irel.h>
+#include <dl-sym-post.h>
#ifdef SHARED
@@ -80,19 +81,6 @@ call_dl_lookup (void *ptr)
args->flags, NULL);
}
-/* Return the link map containing the caller address. */
-static inline struct link_map *
-find_caller_link_map (ElfW(Addr) caller)
-{
- struct link_map *l = _dl_find_dso_for_object (caller);
- if (l != NULL)
- return l;
- else
- /* If the address is not recognized the call comes from the main
- program (we hope). */
- return GL(dl_ns)[LM_ID_BASE]._ns_loaded;
-}
-
static void *
do_sym (void *handle, const char *name, void *who,
struct r_found_version *vers, int flags)
@@ -106,7 +94,7 @@ do_sym (void *handle, const char *name, void *who,
if (handle == RTLD_DEFAULT)
{
- match = find_caller_link_map (caller);
+ match = _dl_sym_find_caller_link_map (caller);
/* Search the global scope. We have the simple case where
we look up in the scope of an object which was part of
@@ -140,7 +128,7 @@ do_sym (void *handle, const char *name, void *who,
}
else if (handle == RTLD_NEXT)
{
- match = find_caller_link_map (caller);
+ match = _dl_sym_find_caller_link_map (caller);
if (__glibc_unlikely (match == GL(dl_ns)[LM_ID_BASE]._ns_loaded))
{
@@ -179,73 +167,7 @@ RTLD_NEXT used in code not dynamically loaded"));
#endif
value = DL_SYMBOL_ADDRESS (result, ref);
- /* Resolve indirect function address. */
- if (__glibc_unlikely (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC))
- {
- DL_FIXUP_VALUE_TYPE fixup
- = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
- fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
- value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
- }
-
-#ifdef SHARED
- /* Auditing checkpoint: we have a new binding. Provide the
- auditing libraries the possibility to change the value and
- tell us whether further auditing is wanted. */
- if (__glibc_unlikely (GLRO(dl_naudit) > 0))
- {
- const char *strtab = (const char *) D_PTR (result,
- l_info[DT_STRTAB]);
- /* Compute index of the symbol entry in the symbol table of
- the DSO with the definition. */
- unsigned int ndx = (ref - (ElfW(Sym) *) D_PTR (result,
- l_info[DT_SYMTAB]));
-
- if (match == NULL)
- match = find_caller_link_map (caller);
-
- if ((match->l_audit_any_plt | result->l_audit_any_plt) != 0)
- {
- unsigned int altvalue = 0;
- struct audit_ifaces *afct = GLRO(dl_audit);
- /* Synthesize a symbol record where the st_value field is
- the result. */
- ElfW(Sym) sym = *ref;
- sym.st_value = (ElfW(Addr)) value;
-
- for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
- {
- struct auditstate *match_audit
- = link_map_audit_state (match, cnt);
- struct auditstate *result_audit
- = link_map_audit_state (result, cnt);
- if (afct->symbind != NULL
- && ((match_audit->bindflags & LA_FLG_BINDFROM) != 0
- || ((result_audit->bindflags & LA_FLG_BINDTO)
- != 0)))
- {
- unsigned int flags = altvalue | LA_SYMB_DLSYM;
- uintptr_t new_value
- = afct->symbind (&sym, ndx,
- &match_audit->cookie,
- &result_audit->cookie,
- &flags, strtab + ref->st_name);
- if (new_value != (uintptr_t) sym.st_value)
- {
- altvalue = LA_SYMB_ALTVALUE;
- sym.st_value = new_value;
- }
- }
-
- afct = afct->next;
- }
-
- value = (void *) sym.st_value;
- }
- }
-#endif
-
- return value;
+ return _dl_sym_post (result, ref, value, caller, match);
}
return NULL;
--
2.24.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h>
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
2020-02-08 19:00 ` [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable Florian Weimer
2020-02-08 19:01 ` [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c Florian Weimer
@ 2020-02-08 19:01 ` Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486] Florian Weimer
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Florian Weimer @ 2020-02-08 19:01 UTC (permalink / raw)
To: libc-alpha
elf/dl-minimal.c provides a definition of free, so the function
pointer is always non-null, even before the final relocation
of the loader.
---
include/inline-hashtab.h | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/include/inline-hashtab.h b/include/inline-hashtab.h
index d25bb95083..3c09978199 100644
--- a/include/inline-hashtab.h
+++ b/include/inline-hashtab.h
@@ -25,8 +25,6 @@
#ifndef INLINE_HASHTAB_H
# define INLINE_HASHTAB_H 1
-extern void weak_function free (void *ptr);
-
struct hashtab
{
/* Table itself. */
@@ -56,8 +54,7 @@ htab_create (void)
ht->free = free;
if (! ht->entries)
{
- if (ht->free)
- ht->free (ht);
+ free (ht);
return NULL;
}
@@ -78,8 +75,7 @@ htab_delete (struct hashtab *htab)
for (i = htab->size - 1; i >= 0; i--)
free (htab->entries[i]);
- if (htab->free)
- htab->free (htab->entries);
+ htab->free (htab->entries);
free (htab);
}
@@ -167,8 +163,7 @@ htab_expand (struct hashtab *htab, int (*hash_fn) (void *))
allocated early as long as there's no corresponding free(), but
this isn't so much memory as to be significant. */
- if (htab->free)
- htab->free (oentries);
+ htab->free (oentries);
/* Use the free() corresponding to the malloc() above to free this
up. */
--
2.24.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486]
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
` (2 preceding siblings ...)
2020-02-08 19:01 ` [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h> Florian Weimer
@ 2020-02-08 19:01 ` Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-24 11:53 ` Florian Weimer
2020-02-14 22:36 ` [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader " Carlos O'Donell
2020-02-17 12:25 ` Lucas A. M. Magalhaes
5 siblings, 2 replies; 12+ messages in thread
From: Florian Weimer @ 2020-02-08 19:01 UTC (permalink / raw)
To: libc-alpha
Exporting functions and relying on symbol interposition from libc.so
makes the choice of implementation dependent on DT_NEEDED order, which
is not what some compiler drivers expect.
This commit replaces one magic mechanism (symbol interposition) with
another one (preprocessor-/compiler-based redirection). This makes
the hand-over from the minimal malloc to the full malloc more
explicit.
Removing the ABI symbols is backwards-compatible because libc.so is
always in scope, and the dynamic loader will find the malloc-related
symbols there since commit f0b2132b35248c1f4a80f62a2c38cddcc802aa8c
("ld.so: Support moving versioned symbols between sonames
[BZ #24741]").
Tested on aarch64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
s390x-linux-gnu without the stack protector, and on x86_64-linux-gnu
with stack-protector-strong. Also built with build-many-glibcs.py.
---
elf/Makefile | 6 +-
elf/Versions | 3 -
elf/dl-lookup.c | 4 +-
elf/dl-minimal.c | 97 ++++++++++++++++---
elf/rtld.c | 12 +++
include/inline-hashtab.h | 4 +-
include/libc-symbols.h | 9 +-
include/malloc.h | 2 +
include/rtld-malloc.h | 85 ++++++++++++++++
include/stdlib.h | 2 +
sysdeps/generic/localplt.data | 6 --
sysdeps/mach/hurd/i386/ld.abilist | 4 -
sysdeps/mach/hurd/i386/localplt.data | 6 --
sysdeps/unix/sysv/linux/aarch64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/aarch64/localplt.data | 6 --
sysdeps/unix/sysv/linux/alpha/ld.abilist | 4 -
sysdeps/unix/sysv/linux/alpha/localplt.data | 6 --
sysdeps/unix/sysv/linux/arm/be/ld.abilist | 4 -
sysdeps/unix/sysv/linux/arm/le/ld.abilist | 4 -
sysdeps/unix/sysv/linux/arm/localplt.data | 6 --
sysdeps/unix/sysv/linux/csky/ld.abilist | 4 -
sysdeps/unix/sysv/linux/csky/localplt.data | 6 --
sysdeps/unix/sysv/linux/hppa/ld.abilist | 4 -
sysdeps/unix/sysv/linux/hppa/localplt.data | 6 --
sysdeps/unix/sysv/linux/i386/ld.abilist | 4 -
sysdeps/unix/sysv/linux/i386/localplt.data | 6 --
sysdeps/unix/sysv/linux/ia64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/ia64/localplt.data | 6 --
.../unix/sysv/linux/m68k/coldfire/ld.abilist | 4 -
.../sysv/linux/m68k/coldfire/localplt.data | 6 --
.../unix/sysv/linux/m68k/m680x0/ld.abilist | 4 -
.../unix/sysv/linux/m68k/m680x0/localplt.data | 6 --
sysdeps/unix/sysv/linux/microblaze/ld.abilist | 4 -
.../unix/sysv/linux/microblaze/localplt.data | 6 --
.../unix/sysv/linux/mips/mips32/ld.abilist | 4 -
.../sysv/linux/mips/mips64/n32/ld.abilist | 4 -
.../sysv/linux/mips/mips64/n64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/nios2/ld.abilist | 4 -
sysdeps/unix/sysv/linux/nios2/localplt.data | 6 --
.../linux/powerpc/powerpc32/fpu/localplt.data | 6 --
.../sysv/linux/powerpc/powerpc32/ld.abilist | 4 -
.../powerpc/powerpc32/nofpu/localplt.data | 6 --
.../linux/powerpc/powerpc64/be/ld.abilist | 4 -
.../linux/powerpc/powerpc64/le/ld.abilist | 4 -
.../linux/powerpc/powerpc64/localplt.data | 6 --
sysdeps/unix/sysv/linux/riscv/localplt.data | 6 --
sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/s390/localplt.data | 6 --
.../unix/sysv/linux/s390/s390-32/ld.abilist | 4 -
.../unix/sysv/linux/s390/s390-64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/be/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/le/ld.abilist | 4 -
sysdeps/unix/sysv/linux/sh/localplt.data | 6 --
.../unix/sysv/linux/sparc/sparc32/ld.abilist | 4 -
.../sysv/linux/sparc/sparc32/localplt.data | 6 --
.../unix/sysv/linux/sparc/sparc64/ld.abilist | 4 -
.../sysv/linux/sparc/sparc64/localplt.data | 6 --
sysdeps/unix/sysv/linux/x86_64/64/ld.abilist | 4 -
sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist | 4 -
sysdeps/x86_64/localplt.data | 6 --
60 files changed, 202 insertions(+), 266 deletions(-)
create mode 100644 include/rtld-malloc.h
diff --git a/elf/Makefile b/elf/Makefile
index 60c8082d06..74462a5e65 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -486,7 +486,11 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
# their implementation is provided differently in rtld, and the symbol
# discovery mechanism is not compatible with the libc implementation
# when compiled for libc.
-rtld-stubbed-symbols =
+rtld-stubbed-symbols = \
+ calloc \
+ free \
+ malloc \
+ realloc \
# The GCC arguments that implement $(rtld-stubbed-symbols).
rtld-stubbed-symbols-args = \
diff --git a/elf/Versions b/elf/Versions
index 3b09901f6c..705489fc51 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -35,9 +35,6 @@ libc {
ld {
GLIBC_2.0 {
- # Functions which are interposed from libc.so.
- calloc; free; malloc; realloc;
-
_r_debug;
}
GLIBC_2.1 {
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
index 378f28fa7d..12a229f06c 100644
--- a/elf/dl-lookup.c
+++ b/elf/dl-lookup.c
@@ -291,7 +291,7 @@ do_lookup_unique (const char *undef_name, uint_fast32_t new_hash,
tab->size = newsize;
size = newsize;
entries = tab->entries = newentries;
- tab->free = free;
+ tab->free = __rtld_free;
}
}
else
@@ -322,7 +322,7 @@ do_lookup_unique (const char *undef_name, uint_fast32_t new_hash,
tab->entries = entries;
tab->size = size;
- tab->free = free;
+ tab->free = __rtld_free;
}
if ((type_class & ELF_RTYPE_CLASS_COPY) != 0)
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 42192f8a7b..c79ce23be4 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -26,11 +26,87 @@
#include <sys/param.h>
#include <sys/types.h>
#include <ldsodefs.h>
+#include <dl-irel.h>
+#include <dl-hash.h>
+#include <dl-sym-post.h>
#include <_itoa.h>
#include <malloc/malloc-internal.h>
#include <assert.h>
+/* The rtld startup code calls __rtld_malloc_init_stubs after the
+ first self-relocation to adjust the pointers to the minimal
+ implementation below. Before the final relocation,
+ __rtld_malloc_init_real is called to replace the pointers with the
+ real implementation. */
+__typeof (calloc) *__rtld_calloc;
+__typeof (free) *__rtld_free;
+__typeof (malloc) *__rtld_malloc;
+__typeof (realloc) *__rtld_realloc;
+
+/* Defined below. */
+static __typeof (calloc) rtld_calloc attribute_relro;
+static __typeof (free) rtld_free attribute_relro;
+static __typeof (malloc) rtld_malloc attribute_relro;
+static __typeof (realloc) rtld_realloc attribute_relro;
+
+void
+__rtld_malloc_init_stubs (void)
+{
+ __rtld_calloc = &rtld_calloc;
+ __rtld_free = &rtld_free;
+ __rtld_malloc = &rtld_malloc;
+ __rtld_realloc = &rtld_realloc;
+}
+
+/* Lookup NAME at VERSION in the scope of MATCH. */
+static void *
+lookup_malloc_symbol (struct link_map *main_map, const char *name,
+ struct r_found_version *version)
+{
+
+ const ElfW(Sym) *ref = NULL;
+ lookup_t result = _dl_lookup_symbol_x (name, main_map, &ref,
+ main_map->l_scope,
+ version, 0, 0, NULL);
+
+ assert (ELFW(ST_TYPE) (ref->st_info) != STT_TLS);
+ void *value = DL_SYMBOL_ADDRESS (result, ref);
+
+ return _dl_sym_post (result, ref, value, 0, main_map);
+}
+
+void
+__rtld_malloc_init_real (struct link_map *main_map)
+{
+ /* We cannot use relocations and initializers for this because the
+ changes made by __rtld_malloc_init_stubs break REL-style
+ (non-RELA) relocations that depend on the previous pointer
+ contents. Also avoid direct relocation depedencies for the
+ malloc symbols so this function can be called before the final
+ rtld relocation (which enables RELRO, after which the pointer
+ variables cannot be written to). */
+
+ struct r_found_version version;
+ version.name = symbol_version_string (libc, GLIBC_2_0);
+ version.hidden = 0;
+ version.hash = _dl_elf_hash (version.name);
+ version.filename = NULL;
+
+ void *new_calloc = lookup_malloc_symbol (main_map, "calloc", &version);
+ void *new_free = lookup_malloc_symbol (main_map, "free", &version);
+ void *new_malloc = lookup_malloc_symbol (main_map, "malloc", &version);
+ void *new_realloc = lookup_malloc_symbol (main_map, "realloc", &version);
+
+ /* Update the pointers in one go, so that any internal allocations
+ performed by lookup_malloc_symbol see a consistent
+ implementation. */
+ __rtld_calloc = new_calloc;
+ __rtld_free = new_free;
+ __rtld_malloc = new_malloc;
+ __rtld_realloc = new_realloc;
+}
+
/* Minimal malloc allocator for used during initial link. After the
initial link, a full malloc implementation is interposed, either
the one in libc, or a different one supplied by the user through
@@ -38,14 +114,9 @@
static void *alloc_ptr, *alloc_end, *alloc_last_block;
-/* Declarations of global functions. */
-extern void weak_function free (void *ptr);
-extern void * weak_function realloc (void *ptr, size_t n);
-
-
/* Allocate an aligned memory block. */
-void * weak_function
-malloc (size_t n)
+static void *
+rtld_malloc (size_t n)
{
if (alloc_end == 0)
{
@@ -87,8 +158,8 @@ malloc (size_t n)
/* We use this function occasionally since the real implementation may
be optimized when it can assume the memory it returns already is
set to NUL. */
-void * weak_function
-calloc (size_t nmemb, size_t size)
+static void *
+rtld_calloc (size_t nmemb, size_t size)
{
/* New memory from the trivial malloc above is always already cleared.
(We make sure that's true in the rare occasion it might not be,
@@ -104,8 +175,8 @@ calloc (size_t nmemb, size_t size)
}
/* This will rarely be called. */
-void weak_function
-free (void *ptr)
+void
+rtld_free (void *ptr)
{
/* We can free only the last block allocated. */
if (ptr == alloc_last_block)
@@ -118,8 +189,8 @@ free (void *ptr)
}
/* This is only called with the most recent block returned by malloc. */
-void * weak_function
-realloc (void *ptr, size_t n)
+void *
+rtld_realloc (void *ptr, size_t n)
{
if (ptr == NULL)
return malloc (n);
diff --git a/elf/rtld.c b/elf/rtld.c
index 553cfbd1b7..51dfaf966a 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -534,6 +534,9 @@ _dl_start (void *arg)
header table in core. Put the rest of _dl_start into a separate
function, that way the compiler cannot put accesses to the GOT
before ELF_DYNAMIC_RELOCATE. */
+
+ __rtld_malloc_init_stubs ();
+
{
#ifdef DONT_USE_BOOTSTRAP_MAP
ElfW(Addr) entry = _dl_start_final (arg);
@@ -2210,6 +2213,10 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
rtld_timer_stop (&relocate_time, start);
}
+ /* The library defining malloc has already been relocated due to
+ prelinking. Resolve the malloc symbols for the dynamic
+ loader. */
+ __rtld_malloc_init_real (main_map);
/* Mark all the objects so we know they have been already relocated. */
for (struct link_map *l = main_map; l != NULL; l = l->l_next)
@@ -2310,6 +2317,11 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
re-relocation, we might call a user-supplied function
(e.g. calloc from _dl_relocate_object) that uses TLS data. */
+ /* The malloc implementation has been relocated, so resolving
+ its symbols (and potentially calling IFUNC resolvers) is safe
+ at this point. */
+ __rtld_malloc_init_real (main_map);
+
RTLD_TIMING_VAR (start);
rtld_timer_start (&start);
diff --git a/include/inline-hashtab.h b/include/inline-hashtab.h
index 3c09978199..856719cf9d 100644
--- a/include/inline-hashtab.h
+++ b/include/inline-hashtab.h
@@ -51,7 +51,7 @@ htab_create (void)
return NULL;
ht->size = 3;
ht->entries = malloc (sizeof (void *) * ht->size);
- ht->free = free;
+ ht->free = __rtld_free;
if (! ht->entries)
{
free (ht);
@@ -167,7 +167,7 @@ htab_expand (struct hashtab *htab, int (*hash_fn) (void *))
/* Use the free() corresponding to the malloc() above to free this
up. */
- htab->free = free;
+ htab->free = __rtld_free;
return 1;
}
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 685e20fdc0..33e2d34c53 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -421,7 +421,14 @@ for linking")
# define _default_symbol_version(real, name, version) \
__asm__ (".symver " #real "," #name "@@" #version)
# endif
-#else
+
+/* Evalutes to a string literal for VERSION in LIB. */
+# define symbol_version_string(lib, version) \
+ _symbol_version_stringify_1 (VERSION_##lib##_##version)
+# define _symbol_version_stringify_1(arg) _symbol_version_stringify_2 (arg)
+# define _symbol_version_stringify_2(arg) #arg
+
+#else /* !SHARED */
# define symbol_version(real, name, version)
# define default_symbol_version(real, name, version) \
strong_alias(real, name)
diff --git a/include/malloc.h b/include/malloc.h
index 70d32c7c84..0765482c51 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -1,7 +1,9 @@
#ifndef _MALLOC_H
+
#include <malloc/malloc.h>
# ifndef _ISOMAC
+# include <rtld-malloc.h>
/* In the GNU libc we rename the global variable
`__malloc_initialized' to `__libc_malloc_initialized'. */
diff --git a/include/rtld-malloc.h b/include/rtld-malloc.h
new file mode 100644
index 0000000000..b026a3270c
--- /dev/null
+++ b/include/rtld-malloc.h
@@ -0,0 +1,85 @@
+/* Redirection of malloc inside the dynamic linker.
+ Copyright (C) 2020 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/>. */
+
+/* The dynamic linker needs to use its own minimal malloc before libc
+ has been relocated, and the libc malloc afterwards. The active
+ malloc implementation is reached via the __rtld_* function pointers
+ declared below. They are initialized to the minimal malloc by
+ __rtld_malloc_init_stubs, and set to the final implementation by
+ __rtld_malloc_init_real. */
+
+#ifndef _RTLD_MALLOC_H
+#define _RTLD_MALLOC_H
+
+#if IS_IN (rtld)
+
+extern __typeof (calloc) *__rtld_calloc attribute_hidden;
+extern __typeof (free) *__rtld_free attribute_hidden;
+extern __typeof (malloc) *__rtld_malloc attribute_hidden;
+extern __typeof (realloc) *__rtld_realloc attribute_hidden;
+
+/* Wrapper functions which call through the function pointers above.
+ Note that it is not supported to take the address of those
+ functions. Instead the function pointers must be used
+ directly. */
+
+__extern_inline void *
+calloc (size_t a, size_t b)
+{
+ return __rtld_calloc (a, b);
+}
+
+__extern_inline void
+free (void *ptr)
+{
+ __rtld_free (ptr);
+}
+
+__extern_inline void *
+malloc (size_t size)
+{
+ return __rtld_malloc (size);
+}
+
+__extern_inline void *
+realloc (void *ptr, size_t size)
+{
+ return __rtld_realloc (ptr, size);
+}
+
+/* Called after the first self-relocation to activate the minimal malloc
+ implementation. */
+void __rtld_malloc_init_stubs (void) attribute_hidden;
+
+/* Called shortly before the final self-relocation (when RELRO
+ variables are still writable) to activate the real malloc
+ implementation. MAIN_MAP is the link map of the executable. */
+struct link_map;
+void __rtld_malloc_init_real (struct link_map *main_map) attribute_hidden;
+
+#else /* !IS_IN (rtld) */
+
+/* This allows static/non-rtld builds to get a pointer to the
+ functions, in the same way that is required inside rtld. */
+# define __rtld_calloc (&calloc)
+# define __rtld_free (&free)
+# define __rtld_malloc (&malloc)
+# define __rtld_realloc (&realloc)
+
+#endif /* !IS_IN (rtld) */
+#endif /* _RTLD_MALLOC_H */
diff --git a/include/stdlib.h b/include/stdlib.h
index 1fab78aa16..926f965f69 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -9,6 +9,8 @@
#if !defined _ISOMAC
# include <sys/stat.h>
+# include <rtld-malloc.h>
+
extern __typeof (strtol_l) __strtol_l;
extern __typeof (strtoul_l) __strtoul_l;
extern __typeof (strtoll_l) __strtoll_l;
diff --git a/sysdeps/generic/localplt.data b/sysdeps/generic/localplt.data
index 2d5c66ae28..e2083c0ce6 100644
--- a/sysdeps/generic/localplt.data
+++ b/sysdeps/generic/localplt.data
@@ -7,12 +7,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/mach/hurd/i386/ld.abilist b/sysdeps/mach/hurd/i386/ld.abilist
index c76b913486..6f591b2496 100644
--- a/sysdeps/mach/hurd/i386/ld.abilist
+++ b/sysdeps/mach/hurd/i386/ld.abilist
@@ -16,10 +16,6 @@ GLIBC_2.2.6 _dl_mcount F
GLIBC_2.2.6 _hurd_intr_rpc_mach_msg F
GLIBC_2.2.6 _r_debug D 0x14
GLIBC_2.2.6 abort F
-GLIBC_2.2.6 calloc F
-GLIBC_2.2.6 free F
-GLIBC_2.2.6 malloc F
-GLIBC_2.2.6 realloc F
GLIBC_2.3 ___tls_get_addr F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
index c1725d140f..102323e64f 100644
--- a/sysdeps/mach/hurd/i386/localplt.data
+++ b/sysdeps/mach/hurd/i386/localplt.data
@@ -9,12 +9,6 @@ libc.so: malloc + REL R_386_GLOB_DAT
libc.so: memalign + REL R_386_GLOB_DAT
libc.so: realloc + REL R_386_GLOB_DAT
libm.so: matherr + REL R_386_GLOB_DAT
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc + REL R_386_GLOB_DAT
-ld.so: calloc + REL R_386_GLOB_DAT
-ld.so: realloc + REL R_386_GLOB_DAT
-ld.so: free + REL R_386_GLOB_DAT
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error + REL R_386_GLOB_DAT
ld.so: _dl_catch_error + REL R_386_GLOB_DAT
diff --git a/sysdeps/unix/sysv/linux/aarch64/ld.abilist b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
index 4ffe688649..80b2fe6725 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.17 __stack_chk_guard D 0x8
GLIBC_2.17 __tls_get_addr F
GLIBC_2.17 _dl_mcount F
GLIBC_2.17 _r_debug D 0x28
-GLIBC_2.17 calloc F
-GLIBC_2.17 free F
-GLIBC_2.17 malloc F
-GLIBC_2.17 realloc F
diff --git a/sysdeps/unix/sysv/linux/aarch64/localplt.data b/sysdeps/unix/sysv/linux/aarch64/localplt.data
index a60053b914..56f362d3a7 100644
--- a/sysdeps/unix/sysv/linux/aarch64/localplt.data
+++ b/sysdeps/unix/sysv/linux/aarch64/localplt.data
@@ -9,12 +9,6 @@ libc.so: realloc
libm.so: matherr
# The dynamic loader needs __tls_get_addr for TLS.
ld.so: __tls_get_addr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/alpha/ld.abilist b/sysdeps/unix/sysv/linux/alpha/ld.abilist
index 98b66edabf..98a03f611f 100644
--- a/sysdeps/unix/sysv/linux/alpha/ld.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x28
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x8
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/alpha/localplt.data b/sysdeps/unix/sysv/linux/alpha/localplt.data
index c69eb04ce5..43f6fdaea1 100644
--- a/sysdeps/unix/sysv/linux/alpha/localplt.data
+++ b/sysdeps/unix/sysv/linux/alpha/localplt.data
@@ -26,12 +26,6 @@ libm.so: matherr + RELA R_ALPHA_GLOB_DAT
libm.so: __atan2
# The dynamic loader needs __tls_get_addr for TLS.
ld.so: __tls_get_addr ?
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc + RELA R_ALPHA_GLOB_DAT
-ld.so: calloc + RELA R_ALPHA_GLOB_DAT
-ld.so: realloc + RELA R_ALPHA_GLOB_DAT
-ld.so: free + RELA R_ALPHA_GLOB_DAT
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error + RELA R_ALPHA_GLOB_DAT
ld.so: _dl_catch_error + RELA R_ALPHA_GLOB_DAT
diff --git a/sysdeps/unix/sysv/linux/arm/be/ld.abilist b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
index a301c6ebc4..cc8825c3bc 100644
--- a/sysdeps/unix/sysv/linux/arm/be/ld.abilist
+++ b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
-GLIBC_2.4 calloc F
-GLIBC_2.4 free F
-GLIBC_2.4 malloc F
-GLIBC_2.4 realloc F
diff --git a/sysdeps/unix/sysv/linux/arm/le/ld.abilist b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
index a301c6ebc4..cc8825c3bc 100644
--- a/sysdeps/unix/sysv/linux/arm/le/ld.abilist
+++ b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
-GLIBC_2.4 calloc F
-GLIBC_2.4 free F
-GLIBC_2.4 malloc F
-GLIBC_2.4 realloc F
diff --git a/sysdeps/unix/sysv/linux/arm/localplt.data b/sysdeps/unix/sysv/linux/arm/localplt.data
index 7bd541c28a..0c3af0c64e 100644
--- a/sysdeps/unix/sysv/linux/arm/localplt.data
+++ b/sysdeps/unix/sysv/linux/arm/localplt.data
@@ -8,12 +8,6 @@ libm.so: matherr
libpthread.so: raise
# The dynamic loader needs __tls_get_addr for TLS.
ld.so: __tls_get_addr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/csky/ld.abilist b/sysdeps/unix/sysv/linux/csky/ld.abilist
index 71576160ed..564ac09737 100644
--- a/sysdeps/unix/sysv/linux/csky/ld.abilist
+++ b/sysdeps/unix/sysv/linux/csky/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.29 __stack_chk_guard D 0x4
GLIBC_2.29 __tls_get_addr F
GLIBC_2.29 _dl_mcount F
GLIBC_2.29 _r_debug D 0x14
-GLIBC_2.29 calloc F
-GLIBC_2.29 free F
-GLIBC_2.29 malloc F
-GLIBC_2.29 realloc F
diff --git a/sysdeps/unix/sysv/linux/csky/localplt.data b/sysdeps/unix/sysv/linux/csky/localplt.data
index 14c02cb2d6..0ed8650b65 100644
--- a/sysdeps/unix/sysv/linux/csky/localplt.data
+++ b/sysdeps/unix/sysv/linux/csky/localplt.data
@@ -6,12 +6,6 @@ libc.so: free
libc.so: malloc
libc.so: memalign
libc.so: realloc
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/hppa/ld.abilist b/sysdeps/unix/sysv/linux/hppa/ld.abilist
index 0387614d8f..d155a59843 100644
--- a/sysdeps/unix/sysv/linux/hppa/ld.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/ld.abilist
@@ -1,9 +1,5 @@
GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
diff --git a/sysdeps/unix/sysv/linux/hppa/localplt.data b/sysdeps/unix/sysv/linux/hppa/localplt.data
index 867413f0c5..09893d4dcf 100644
--- a/sysdeps/unix/sysv/linux/hppa/localplt.data
+++ b/sysdeps/unix/sysv/linux/hppa/localplt.data
@@ -10,12 +10,6 @@ libc.so: __sigsetjmp
libc.so: _IO_funlockfile
libc.so: __errno_location
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/i386/ld.abilist b/sysdeps/unix/sysv/linux/i386/ld.abilist
index edb7307228..0478e22071 100644
--- a/sysdeps/unix/sysv/linux/i386/ld.abilist
+++ b/sysdeps/unix/sysv/linux/i386/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 ___tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
index f6f20a5d15..5334875b4b 100644
--- a/sysdeps/unix/sysv/linux/i386/localplt.data
+++ b/sysdeps/unix/sysv/linux/i386/localplt.data
@@ -7,12 +7,6 @@ libc.so: malloc + REL R_386_GLOB_DAT
libc.so: memalign + REL R_386_GLOB_DAT
libc.so: realloc + REL R_386_GLOB_DAT
libm.so: matherr + REL R_386_GLOB_DAT
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc + REL R_386_GLOB_DAT
-ld.so: calloc + REL R_386_GLOB_DAT
-ld.so: realloc + REL R_386_GLOB_DAT
-ld.so: free + REL R_386_GLOB_DAT
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error + REL R_386_GLOB_DAT
ld.so: _dl_catch_error + REL R_386_GLOB_DAT
diff --git a/sysdeps/unix/sysv/linux/ia64/ld.abilist b/sysdeps/unix/sysv/linux/ia64/ld.abilist
index 82042472c3..33f91199bf 100644
--- a/sysdeps/unix/sysv/linux/ia64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/ia64/localplt.data b/sysdeps/unix/sysv/linux/ia64/localplt.data
index 3820e2a4e6..1c566a503e 100644
--- a/sysdeps/unix/sysv/linux/ia64/localplt.data
+++ b/sysdeps/unix/sysv/linux/ia64/localplt.data
@@ -6,12 +6,6 @@ libc.so: realloc
libm.so: matherr
libm.so: matherrf
libm.so: matherrl
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
index a301c6ebc4..cc8825c3bc 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
GLIBC_2.4 __tls_get_addr F
GLIBC_2.4 _dl_mcount F
GLIBC_2.4 _r_debug D 0x14
-GLIBC_2.4 calloc F
-GLIBC_2.4 free F
-GLIBC_2.4 malloc F
-GLIBC_2.4 realloc F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
index 4a07bf387e..3c5efb7204 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
@@ -5,12 +5,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
index c9ec45cf1c..3ba474c27f 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
index c70d6ea301..843f4e25f2 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
@@ -6,12 +6,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/microblaze/ld.abilist b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
index aa0d71150a..a4933c3541 100644
--- a/sysdeps/unix/sysv/linux/microblaze/ld.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.18 __stack_chk_guard D 0x4
GLIBC_2.18 __tls_get_addr F
GLIBC_2.18 _dl_mcount F
GLIBC_2.18 _r_debug D 0x14
-GLIBC_2.18 calloc F
-GLIBC_2.18 free F
-GLIBC_2.18 malloc F
-GLIBC_2.18 realloc F
diff --git a/sysdeps/unix/sysv/linux/microblaze/localplt.data b/sysdeps/unix/sysv/linux/microblaze/localplt.data
index 8ca23897df..0e98d5251e 100644
--- a/sysdeps/unix/sysv/linux/microblaze/localplt.data
+++ b/sysdeps/unix/sysv/linux/microblaze/localplt.data
@@ -7,12 +7,6 @@ libc.so: realloc
libm.so: matherr
# The dynamic loader needs __tls_get_addr for TLS.
ld.so: __tls_get_addr ?
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
index 55d48868e8..be09641a48 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
index 55d48868e8..be09641a48 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
index 44b345b7cf..1ea36e13f2 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x28
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/nios2/ld.abilist b/sysdeps/unix/sysv/linux/nios2/ld.abilist
index 110f1039fa..52178802dd 100644
--- a/sysdeps/unix/sysv/linux/nios2/ld.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.21 __stack_chk_guard D 0x4
GLIBC_2.21 __tls_get_addr F
GLIBC_2.21 _dl_mcount F
GLIBC_2.21 _r_debug D 0x14
-GLIBC_2.21 calloc F
-GLIBC_2.21 free F
-GLIBC_2.21 malloc F
-GLIBC_2.21 realloc F
diff --git a/sysdeps/unix/sysv/linux/nios2/localplt.data b/sysdeps/unix/sysv/linux/nios2/localplt.data
index 3805ed56b9..b37987c7c0 100644
--- a/sysdeps/unix/sysv/linux/nios2/localplt.data
+++ b/sysdeps/unix/sysv/linux/nios2/localplt.data
@@ -28,12 +28,6 @@ libc.so: __eqdf2
libc.so: __extendsfdf2
libc.so: __floatundidf ?
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
index e822e0a480..a02dd5cc24 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
@@ -5,12 +5,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
index e8b0ea3a9b..4bbfba7a61 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.22 __tls_get_addr_opt F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
index 647e735fdf..d8072597b7 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
@@ -36,12 +36,6 @@ libc.so: realloc
libm.so: copysignl ?
libm.so: fabsl
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
index edfc9ca56f..283fb4510b 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
@@ -4,7 +4,3 @@ GLIBC_2.3 __libc_stack_end D 0x8
GLIBC_2.3 __tls_get_addr F
GLIBC_2.3 _dl_mcount F
GLIBC_2.3 _r_debug D 0x28
-GLIBC_2.3 calloc F
-GLIBC_2.3 free F
-GLIBC_2.3 malloc F
-GLIBC_2.3 realloc F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
index 37c8f6684b..b1f313c7cd 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
@@ -2,9 +2,5 @@ GLIBC_2.17 __libc_stack_end D 0x8
GLIBC_2.17 __tls_get_addr F
GLIBC_2.17 _dl_mcount F
GLIBC_2.17 _r_debug D 0x28
-GLIBC_2.17 calloc F
-GLIBC_2.17 free F
-GLIBC_2.17 malloc F
-GLIBC_2.17 realloc F
GLIBC_2.22 __tls_get_addr_opt F
GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
index c1209336d2..bb498fbe3a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
@@ -4,12 +4,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
index 14c02cb2d6..0ed8650b65 100644
--- a/sysdeps/unix/sysv/linux/riscv/localplt.data
+++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
@@ -6,12 +6,6 @@ libc.so: free
libc.so: malloc
libc.so: memalign
libc.so: realloc
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
index b411871d06..845f356c3c 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
@@ -3,7 +3,3 @@ GLIBC_2.27 __stack_chk_guard D 0x8
GLIBC_2.27 __tls_get_addr F
GLIBC_2.27 _dl_mcount F
GLIBC_2.27 _r_debug D 0x28
-GLIBC_2.27 calloc F
-GLIBC_2.27 free F
-GLIBC_2.27 malloc F
-GLIBC_2.27 realloc F
diff --git a/sysdeps/unix/sysv/linux/s390/localplt.data b/sysdeps/unix/sysv/linux/s390/localplt.data
index e822e0a480..a02dd5cc24 100644
--- a/sysdeps/unix/sysv/linux/s390/localplt.data
+++ b/sysdeps/unix/sysv/linux/s390/localplt.data
@@ -5,12 +5,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
index 0576c9575e..b56f005beb 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_offset F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
index 1fbb890d1d..6f788a086d 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_offset F
diff --git a/sysdeps/unix/sysv/linux/sh/be/ld.abilist b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
index 0387614d8f..d155a59843 100644
--- a/sysdeps/unix/sysv/linux/sh/be/ld.abilist
+++ b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
@@ -1,9 +1,5 @@
GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
diff --git a/sysdeps/unix/sysv/linux/sh/le/ld.abilist b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
index 0387614d8f..d155a59843 100644
--- a/sysdeps/unix/sysv/linux/sh/le/ld.abilist
+++ b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
@@ -1,9 +1,5 @@
GLIBC_2.2 __libc_stack_end D 0x4
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x14
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_addr F
GLIBC_2.4 __stack_chk_guard D 0x4
diff --git a/sysdeps/unix/sysv/linux/sh/localplt.data b/sysdeps/unix/sysv/linux/sh/localplt.data
index babb19d717..3225177c50 100644
--- a/sysdeps/unix/sysv/linux/sh/localplt.data
+++ b/sysdeps/unix/sysv/linux/sh/localplt.data
@@ -12,12 +12,6 @@ libc.so: __errno_location
libm.so: matherr
# Generated by the compiler because there is no trap insn pattern.
libc.so: abort ?
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
index fd0b33f86d..0c6610e3c2 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.0 _r_debug D 0x14
-GLIBC_2.0 calloc F
-GLIBC_2.0 free F
-GLIBC_2.0 malloc F
-GLIBC_2.0 realloc F
GLIBC_2.1 __libc_stack_end D 0x4
GLIBC_2.1 _dl_mcount F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
index 6bf10ff858..be51efd566 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
@@ -19,12 +19,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
index 82042472c3..33f91199bf 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.2 __libc_stack_end D 0x8
GLIBC_2.2 _dl_mcount F
GLIBC_2.2 _r_debug D 0x28
-GLIBC_2.2 calloc F
-GLIBC_2.2 free F
-GLIBC_2.2 malloc F
-GLIBC_2.2 realloc F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
index b881b9096d..809062d46c 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
@@ -18,12 +18,6 @@ libc.so: malloc
libc.so: memalign
libc.so: realloc
libm.so: matherr
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc
-ld.so: calloc
-ld.so: realloc
-ld.so: free
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error
ld.so: _dl_catch_error
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
index 0dc9430611..d3cdf7611e 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
@@ -1,8 +1,4 @@
GLIBC_2.2.5 __libc_stack_end D 0x8
GLIBC_2.2.5 _dl_mcount F
GLIBC_2.2.5 _r_debug D 0x28
-GLIBC_2.2.5 calloc F
-GLIBC_2.2.5 free F
-GLIBC_2.2.5 malloc F
-GLIBC_2.2.5 realloc F
GLIBC_2.3 __tls_get_addr F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
index 80f3161586..c70bccf782 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
@@ -2,7 +2,3 @@ GLIBC_2.16 __libc_stack_end D 0x4
GLIBC_2.16 __tls_get_addr F
GLIBC_2.16 _dl_mcount F
GLIBC_2.16 _r_debug D 0x14
-GLIBC_2.16 calloc F
-GLIBC_2.16 free F
-GLIBC_2.16 malloc F
-GLIBC_2.16 realloc F
diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
index c27a02b66a..8f41e92870 100644
--- a/sysdeps/x86_64/localplt.data
+++ b/sysdeps/x86_64/localplt.data
@@ -9,12 +9,6 @@ libc.so: malloc + RELA R_X86_64_GLOB_DAT
libc.so: memalign + RELA R_X86_64_GLOB_DAT
libc.so: realloc + RELA R_X86_64_GLOB_DAT
libm.so: matherr + RELA R_X86_64_GLOB_DAT
-# The main malloc is interposed into the dynamic linker, for
-# allocations after the initial link (when dlopen is used).
-ld.so: malloc + RELA R_X86_64_GLOB_DAT
-ld.so: calloc + RELA R_X86_64_GLOB_DAT
-ld.so: realloc + RELA R_X86_64_GLOB_DAT
-ld.so: free + RELA R_X86_64_GLOB_DAT
# The TLS-enabled version of these functions is interposed from libc.so.
ld.so: _dl_signal_error + RELA R_X86_64_GLOB_DAT
ld.so: _dl_catch_error + RELA R_X86_64_GLOB_DAT
--
2.24.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486]
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
` (3 preceding siblings ...)
2020-02-08 19:01 ` [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486] Florian Weimer
@ 2020-02-14 22:36 ` Carlos O'Donell
2020-02-17 12:25 ` Lucas A. M. Magalhaes
5 siblings, 0 replies; 12+ messages in thread
From: Carlos O'Donell @ 2020-02-14 22:36 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 2/8/20 2:00 PM, Florian Weimer wrote:
> I initially wanted to close this bug, but Carlos suggested to treat it
> as an RFE. The changes seem a net improvement to me.
>
> This does not completely resolve the issue because we use symbol
> interposition for other, more obscure things.
>
> Florian Weimer (4):
> elf: Introduce the rtld-stubbed-symbols makefile variable
> elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c
> Remove weak declaration of free from <inline-hashtab.h>
> ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486]
Thank you for the cleanup and improvement!
Overall the architecture of the design looks good to me.
I really like the new explicit handover!
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable
2020-02-08 19:00 ` [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable Florian Weimer
@ 2020-02-14 22:36 ` Carlos O'Donell
0 siblings, 0 replies; 12+ messages in thread
From: Carlos O'Donell @ 2020-02-14 22:36 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 2/8/20 2:00 PM, Florian Weimer wrote:
> This generalizes a mechanism used for stack-protector support, so
> that it can be applied to other symbols if required.
>
> Tested on i686-linux-gnu without the stack protector, and on
> x86_64-linux-gnu with stack-protector-strong.
OK for master.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> elf/Makefile | 22 +++++++++++++---------
> 1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 632a4d8b0f..60c8082d06 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -482,21 +482,25 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
> # are compiled with special flags, and puts these modules into rtld-libc.a
> # for us. Then we do the real link using rtld-libc.a instead of libc_pic.a.
>
> -# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail
> -# and __stack_chk_fail_local symbols defined, to prevent the real things
> -# being dragged into rtld even though rtld is never built with stack-
> -# protection.
> +# These symbols need to be stubbed out during symbol discovery because
> +# their implementation is provided differently in rtld, and the symbol
> +# discovery mechanism is not compatible with the libc implementation
> +# when compiled for libc.
> +rtld-stubbed-symbols =
> +
> +# The GCC arguments that implement $(rtld-stubbed-symbols).
> +rtld-stubbed-symbols-args = \
> + $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
>
> ifeq ($(have-ssp),yes)
> -dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \
> - -Wl,--defsym='__stack_chk_fail_local=0'
> -else
> -dummy-stack-chk-fail :=
> +# rtld is not built with the stack protector, so these references will
> +# go away in the rebuilds.
> +rtld-stubbed-symbols += __stack_chk_fail __stack_chk_fail_local
> endif
>
> $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
> @-rm -f $@T
> - $(reloc-link) -o $@.o $(dummy-stack-chk-fail) \
> + $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
> '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
> rm -f $@.o
> mv -f $@T $@
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c
2020-02-08 19:01 ` [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c Florian Weimer
@ 2020-02-14 22:36 ` Carlos O'Donell
0 siblings, 0 replies; 12+ messages in thread
From: Carlos O'Donell @ 2020-02-14 22:36 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 2/8/20 2:01 PM, Florian Weimer wrote:
> The definitions are moved into a new file, elf/dl-sym-post.h, so that
> this code can be used by the dynamic loader as well.
OK for master. I like the cleanup.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> elf/dl-sym-post.h | 106 ++++++++++++++++++++++++++++++++++++++++++++++
> elf/dl-sym.c | 86 ++-----------------------------------
> 2 files changed, 110 insertions(+), 82 deletions(-)
> create mode 100644 elf/dl-sym-post.h
>
> diff --git a/elf/dl-sym-post.h b/elf/dl-sym-post.h
> new file mode 100644
> index 0000000000..4c4f574633
> --- /dev/null
> +++ b/elf/dl-sym-post.h
> @@ -0,0 +1,106 @@
> +/* Post-processing of a symbol produced by dlsym, dlvsym.
> + Copyright (C) 1999-2020 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/>. */
> +
> +
> +/* Return the link map containing the caller address. */
> +static struct link_map *
> +_dl_sym_find_caller_link_map (ElfW(Addr) caller)
> +{
> + struct link_map *l = _dl_find_dso_for_object (caller);
> + if (l != NULL)
> + return l;
> + else
> + /* If the address is not recognized the call comes from the main
> + program (we hope). */
> + return GL(dl_ns)[LM_ID_BASE]._ns_loaded;
> +}
OK.
> +
> +/* Translates RESULT, *REF, VALUE into a symbol address from the point
> + of view of MATCH. Performs IFUNC resolution and auditing if
> + necessary. If MATCH is NULL, CALLER is used to determine it. */
> +static void *
> +_dl_sym_post (lookup_t result, const ElfW(Sym) *ref, void *value,
> + ElfW(Addr) caller, struct link_map *match)
> +{
> + /* Resolve indirect function address. */
> + if (__glibc_unlikely (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC))
> + {
> + DL_FIXUP_VALUE_TYPE fixup
> + = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
> + fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
> + value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
> + }
> +
> +#ifdef SHARED
> + /* Auditing checkpoint: we have a new binding. Provide the
> + auditing libraries the possibility to change the value and
> + tell us whether further auditing is wanted. */
> + if (__glibc_unlikely (GLRO(dl_naudit) > 0))
> + {
> + const char *strtab = (const char *) D_PTR (result,
> + l_info[DT_STRTAB]);
> + /* Compute index of the symbol entry in the symbol table of
> + the DSO with the definition. */
> + unsigned int ndx = (ref - (ElfW(Sym) *) D_PTR (result,
> + l_info[DT_SYMTAB]));
> +
> + if (match == NULL)
> + match = _dl_sym_find_caller_link_map (caller);
> +
> + if ((match->l_audit_any_plt | result->l_audit_any_plt) != 0)
> + {
> + unsigned int altvalue = 0;
> + struct audit_ifaces *afct = GLRO(dl_audit);
> + /* Synthesize a symbol record where the st_value field is
> + the result. */
> + ElfW(Sym) sym = *ref;
> + sym.st_value = (ElfW(Addr)) value;
> +
> + for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
> + {
> + struct auditstate *match_audit
> + = link_map_audit_state (match, cnt);
> + struct auditstate *result_audit
> + = link_map_audit_state (result, cnt);
> + if (afct->symbind != NULL
> + && ((match_audit->bindflags & LA_FLG_BINDFROM) != 0
> + || ((result_audit->bindflags & LA_FLG_BINDTO)
> + != 0)))
> + {
> + unsigned int flags = altvalue | LA_SYMB_DLSYM;
> + uintptr_t new_value
> + = afct->symbind (&sym, ndx,
> + &match_audit->cookie,
> + &result_audit->cookie,
> + &flags, strtab + ref->st_name);
> + if (new_value != (uintptr_t) sym.st_value)
> + {
> + altvalue = LA_SYMB_ALTVALUE;
> + sym.st_value = new_value;
> + }
> + }
> +
> + afct = afct->next;
> + }
> +
> + value = (void *) sym.st_value;
> + }
> + }
> +#endif
> + return value;
> +}
OK.
> diff --git a/elf/dl-sym.c b/elf/dl-sym.c
> index b43a50e544..361b926ea9 100644
> --- a/elf/dl-sym.c
> +++ b/elf/dl-sym.c
> @@ -28,6 +28,7 @@
> #include <sysdep-cancel.h>
> #include <dl-tls.h>
> #include <dl-irel.h>
> +#include <dl-sym-post.h>
>
>
> #ifdef SHARED
> @@ -80,19 +81,6 @@ call_dl_lookup (void *ptr)
> args->flags, NULL);
> }
>
> -/* Return the link map containing the caller address. */
> -static inline struct link_map *
> -find_caller_link_map (ElfW(Addr) caller)
> -{
> - struct link_map *l = _dl_find_dso_for_object (caller);
> - if (l != NULL)
> - return l;
> - else
> - /* If the address is not recognized the call comes from the main
> - program (we hope). */
> - return GL(dl_ns)[LM_ID_BASE]._ns_loaded;
> -}
> -
> static void *
> do_sym (void *handle, const char *name, void *who,
> struct r_found_version *vers, int flags)
> @@ -106,7 +94,7 @@ do_sym (void *handle, const char *name, void *who,
>
> if (handle == RTLD_DEFAULT)
> {
> - match = find_caller_link_map (caller);
> + match = _dl_sym_find_caller_link_map (caller);
>
> /* Search the global scope. We have the simple case where
> we look up in the scope of an object which was part of
> @@ -140,7 +128,7 @@ do_sym (void *handle, const char *name, void *who,
> }
> else if (handle == RTLD_NEXT)
> {
> - match = find_caller_link_map (caller);
> + match = _dl_sym_find_caller_link_map (caller);
>
> if (__glibc_unlikely (match == GL(dl_ns)[LM_ID_BASE]._ns_loaded))
> {
> @@ -179,73 +167,7 @@ RTLD_NEXT used in code not dynamically loaded"));
> #endif
> value = DL_SYMBOL_ADDRESS (result, ref);
>
> - /* Resolve indirect function address. */
> - if (__glibc_unlikely (ELFW(ST_TYPE) (ref->st_info) == STT_GNU_IFUNC))
> - {
> - DL_FIXUP_VALUE_TYPE fixup
> - = DL_FIXUP_MAKE_VALUE (result, (ElfW(Addr)) value);
> - fixup = elf_ifunc_invoke (DL_FIXUP_VALUE_ADDR (fixup));
> - value = (void *) DL_FIXUP_VALUE_CODE_ADDR (fixup);
> - }
> -
> -#ifdef SHARED
> - /* Auditing checkpoint: we have a new binding. Provide the
> - auditing libraries the possibility to change the value and
> - tell us whether further auditing is wanted. */
> - if (__glibc_unlikely (GLRO(dl_naudit) > 0))
> - {
> - const char *strtab = (const char *) D_PTR (result,
> - l_info[DT_STRTAB]);
> - /* Compute index of the symbol entry in the symbol table of
> - the DSO with the definition. */
> - unsigned int ndx = (ref - (ElfW(Sym) *) D_PTR (result,
> - l_info[DT_SYMTAB]));
> -
> - if (match == NULL)
> - match = find_caller_link_map (caller);
> -
> - if ((match->l_audit_any_plt | result->l_audit_any_plt) != 0)
> - {
> - unsigned int altvalue = 0;
> - struct audit_ifaces *afct = GLRO(dl_audit);
> - /* Synthesize a symbol record where the st_value field is
> - the result. */
> - ElfW(Sym) sym = *ref;
> - sym.st_value = (ElfW(Addr)) value;
> -
> - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
> - {
> - struct auditstate *match_audit
> - = link_map_audit_state (match, cnt);
> - struct auditstate *result_audit
> - = link_map_audit_state (result, cnt);
> - if (afct->symbind != NULL
> - && ((match_audit->bindflags & LA_FLG_BINDFROM) != 0
> - || ((result_audit->bindflags & LA_FLG_BINDTO)
> - != 0)))
> - {
> - unsigned int flags = altvalue | LA_SYMB_DLSYM;
> - uintptr_t new_value
> - = afct->symbind (&sym, ndx,
> - &match_audit->cookie,
> - &result_audit->cookie,
> - &flags, strtab + ref->st_name);
> - if (new_value != (uintptr_t) sym.st_value)
> - {
> - altvalue = LA_SYMB_ALTVALUE;
> - sym.st_value = new_value;
> - }
> - }
> -
> - afct = afct->next;
> - }
> -
> - value = (void *) sym.st_value;
> - }
> - }
> -#endif
> -
> - return value;
> + return _dl_sym_post (result, ref, value, caller, match);
> }
>
> return NULL;
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h>
2020-02-08 19:01 ` [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h> Florian Weimer
@ 2020-02-14 22:36 ` Carlos O'Donell
0 siblings, 0 replies; 12+ messages in thread
From: Carlos O'Donell @ 2020-02-14 22:36 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 2/8/20 2:01 PM, Florian Weimer wrote:
> elf/dl-minimal.c provides a definition of free, so the function
> pointer is always non-null, even before the final relocation
> of the loader.
Agreed.
OK for master.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> include/inline-hashtab.h | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/include/inline-hashtab.h b/include/inline-hashtab.h
> index d25bb95083..3c09978199 100644
> --- a/include/inline-hashtab.h
> +++ b/include/inline-hashtab.h
> @@ -25,8 +25,6 @@
> #ifndef INLINE_HASHTAB_H
> # define INLINE_HASHTAB_H 1
>
> -extern void weak_function free (void *ptr);
> -
OK.
> struct hashtab
> {
> /* Table itself. */
> @@ -56,8 +54,7 @@ htab_create (void)
> ht->free = free;
> if (! ht->entries)
> {
> - if (ht->free)
> - ht->free (ht);
> + free (ht);
OK.
> return NULL;
> }
>
> @@ -78,8 +75,7 @@ htab_delete (struct hashtab *htab)
> for (i = htab->size - 1; i >= 0; i--)
> free (htab->entries[i]);
>
> - if (htab->free)
> - htab->free (htab->entries);
> + htab->free (htab->entries);
OK.
> free (htab);
> }
>
> @@ -167,8 +163,7 @@ htab_expand (struct hashtab *htab, int (*hash_fn) (void *))
> allocated early as long as there's no corresponding free(), but
> this isn't so much memory as to be significant. */
>
> - if (htab->free)
> - htab->free (oentries);
> + htab->free (oentries);
OK.
>
> /* Use the free() corresponding to the malloc() above to free this
> up. */
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486]
2020-02-08 19:01 ` [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486] Florian Weimer
@ 2020-02-14 22:36 ` Carlos O'Donell
2020-02-24 11:53 ` Florian Weimer
1 sibling, 0 replies; 12+ messages in thread
From: Carlos O'Donell @ 2020-02-14 22:36 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
On 2/8/20 2:01 PM, Florian Weimer wrote:
> Exporting functions and relying on symbol interposition from libc.so
> makes the choice of implementation dependent on DT_NEEDED order, which
> is not what some compiler drivers expect.
>
> This commit replaces one magic mechanism (symbol interposition) with
> another one (preprocessor-/compiler-based redirection). This makes
> the hand-over from the minimal malloc to the full malloc more
> explicit.
I LOVE that! Explicit hand-over is much better.
> Removing the ABI symbols is backwards-compatible because libc.so is
> always in scope, and the dynamic loader will find the malloc-related
> symbols there since commit f0b2132b35248c1f4a80f62a2c38cddcc802aa8c
> ("ld.so: Support moving versioned symbols between sonames
> [BZ #24741]").
Agreed. If anyone argues otherwise I'd like to see the use case e.g.
ld.so without libc.so.6.
> Tested on aarch64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
> s390x-linux-gnu without the stack protector, and on x86_64-linux-gnu
> with stack-protector-strong. Also built with build-many-glibcs.py.
OK for master.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> elf/Makefile | 6 +-
> elf/Versions | 3 -
> elf/dl-lookup.c | 4 +-
> elf/dl-minimal.c | 97 ++++++++++++++++---
> elf/rtld.c | 12 +++
> include/inline-hashtab.h | 4 +-
> include/libc-symbols.h | 9 +-
> include/malloc.h | 2 +
> include/rtld-malloc.h | 85 ++++++++++++++++
> include/stdlib.h | 2 +
> sysdeps/generic/localplt.data | 6 --
> sysdeps/mach/hurd/i386/ld.abilist | 4 -
> sysdeps/mach/hurd/i386/localplt.data | 6 --
> sysdeps/unix/sysv/linux/aarch64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/aarch64/localplt.data | 6 --
> sysdeps/unix/sysv/linux/alpha/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/alpha/localplt.data | 6 --
> sysdeps/unix/sysv/linux/arm/be/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/arm/le/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/arm/localplt.data | 6 --
> sysdeps/unix/sysv/linux/csky/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/csky/localplt.data | 6 --
> sysdeps/unix/sysv/linux/hppa/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/hppa/localplt.data | 6 --
> sysdeps/unix/sysv/linux/i386/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/i386/localplt.data | 6 --
> sysdeps/unix/sysv/linux/ia64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/ia64/localplt.data | 6 --
> .../unix/sysv/linux/m68k/coldfire/ld.abilist | 4 -
> .../sysv/linux/m68k/coldfire/localplt.data | 6 --
> .../unix/sysv/linux/m68k/m680x0/ld.abilist | 4 -
> .../unix/sysv/linux/m68k/m680x0/localplt.data | 6 --
> sysdeps/unix/sysv/linux/microblaze/ld.abilist | 4 -
> .../unix/sysv/linux/microblaze/localplt.data | 6 --
> .../unix/sysv/linux/mips/mips32/ld.abilist | 4 -
> .../sysv/linux/mips/mips64/n32/ld.abilist | 4 -
> .../sysv/linux/mips/mips64/n64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/nios2/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/nios2/localplt.data | 6 --
> .../linux/powerpc/powerpc32/fpu/localplt.data | 6 --
> .../sysv/linux/powerpc/powerpc32/ld.abilist | 4 -
> .../powerpc/powerpc32/nofpu/localplt.data | 6 --
> .../linux/powerpc/powerpc64/be/ld.abilist | 4 -
> .../linux/powerpc/powerpc64/le/ld.abilist | 4 -
> .../linux/powerpc/powerpc64/localplt.data | 6 --
> sysdeps/unix/sysv/linux/riscv/localplt.data | 6 --
> sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/s390/localplt.data | 6 --
> .../unix/sysv/linux/s390/s390-32/ld.abilist | 4 -
> .../unix/sysv/linux/s390/s390-64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/sh/be/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/sh/le/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/sh/localplt.data | 6 --
> .../unix/sysv/linux/sparc/sparc32/ld.abilist | 4 -
> .../sysv/linux/sparc/sparc32/localplt.data | 6 --
> .../unix/sysv/linux/sparc/sparc64/ld.abilist | 4 -
> .../sysv/linux/sparc/sparc64/localplt.data | 6 --
> sysdeps/unix/sysv/linux/x86_64/64/ld.abilist | 4 -
> sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist | 4 -
> sysdeps/x86_64/localplt.data | 6 --
> 60 files changed, 202 insertions(+), 266 deletions(-)
> create mode 100644 include/rtld-malloc.h
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 60c8082d06..74462a5e65 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -486,7 +486,11 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
> # their implementation is provided differently in rtld, and the symbol
> # discovery mechanism is not compatible with the libc implementation
> # when compiled for libc.
> -rtld-stubbed-symbols =
> +rtld-stubbed-symbols = \
> + calloc \
> + free \
> + malloc \
> + realloc \
OK.
>
> # The GCC arguments that implement $(rtld-stubbed-symbols).
> rtld-stubbed-symbols-args = \
> diff --git a/elf/Versions b/elf/Versions
> index 3b09901f6c..705489fc51 100644
> --- a/elf/Versions
> +++ b/elf/Versions
> @@ -35,9 +35,6 @@ libc {
>
> ld {
> GLIBC_2.0 {
> - # Functions which are interposed from libc.so.
> - calloc; free; malloc; realloc;
Yay!
> -
> _r_debug;
> }
> GLIBC_2.1 {
> diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
> index 378f28fa7d..12a229f06c 100644
> --- a/elf/dl-lookup.c
> +++ b/elf/dl-lookup.c
> @@ -291,7 +291,7 @@ do_lookup_unique (const char *undef_name, uint_fast32_t new_hash,
> tab->size = newsize;
> size = newsize;
> entries = tab->entries = newentries;
> - tab->free = free;
> + tab->free = __rtld_free;
OK.
> }
> }
> else
> @@ -322,7 +322,7 @@ do_lookup_unique (const char *undef_name, uint_fast32_t new_hash,
>
> tab->entries = entries;
> tab->size = size;
> - tab->free = free;
> + tab->free = __rtld_free;
OK.
> }
>
> if ((type_class & ELF_RTYPE_CLASS_COPY) != 0)
> diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
> index 42192f8a7b..c79ce23be4 100644
> --- a/elf/dl-minimal.c
> +++ b/elf/dl-minimal.c
> @@ -26,11 +26,87 @@
> #include <sys/param.h>
> #include <sys/types.h>
> #include <ldsodefs.h>
> +#include <dl-irel.h>
> +#include <dl-hash.h>
> +#include <dl-sym-post.h>
> #include <_itoa.h>
> #include <malloc/malloc-internal.h>
>
> #include <assert.h>
>
> +/* The rtld startup code calls __rtld_malloc_init_stubs after the
> + first self-relocation to adjust the pointers to the minimal
> + implementation below. Before the final relocation,
> + __rtld_malloc_init_real is called to replace the pointers with the
> + real implementation. */
> +__typeof (calloc) *__rtld_calloc;
> +__typeof (free) *__rtld_free;
> +__typeof (malloc) *__rtld_malloc;
> +__typeof (realloc) *__rtld_realloc;
> +
> +/* Defined below. */
> +static __typeof (calloc) rtld_calloc attribute_relro;
> +static __typeof (free) rtld_free attribute_relro;
> +static __typeof (malloc) rtld_malloc attribute_relro;
> +static __typeof (realloc) rtld_realloc attribute_relro;
> +
> +void
> +__rtld_malloc_init_stubs (void)
> +{
> + __rtld_calloc = &rtld_calloc;
> + __rtld_free = &rtld_free;
> + __rtld_malloc = &rtld_malloc;
> + __rtld_realloc = &rtld_realloc;
> +}
> +
> +/* Lookup NAME at VERSION in the scope of MATCH. */
> +static void *
> +lookup_malloc_symbol (struct link_map *main_map, const char *name,
> + struct r_found_version *version)
> +{
> +
> + const ElfW(Sym) *ref = NULL;
> + lookup_t result = _dl_lookup_symbol_x (name, main_map, &ref,
> + main_map->l_scope,
> + version, 0, 0, NULL);
> +
> + assert (ELFW(ST_TYPE) (ref->st_info) != STT_TLS);
> + void *value = DL_SYMBOL_ADDRESS (result, ref);
> +
> + return _dl_sym_post (result, ref, value, 0, main_map);
> +}
> +
> +void
> +__rtld_malloc_init_real (struct link_map *main_map)
> +{
> + /* We cannot use relocations and initializers for this because the
> + changes made by __rtld_malloc_init_stubs break REL-style
> + (non-RELA) relocations that depend on the previous pointer
> + contents. Also avoid direct relocation depedencies for the
> + malloc symbols so this function can be called before the final
> + rtld relocation (which enables RELRO, after which the pointer
> + variables cannot be written to). */
> +
> + struct r_found_version version;
> + version.name = symbol_version_string (libc, GLIBC_2_0);
> + version.hidden = 0;
> + version.hash = _dl_elf_hash (version.name);
> + version.filename = NULL;
> +
> + void *new_calloc = lookup_malloc_symbol (main_map, "calloc", &version);
> + void *new_free = lookup_malloc_symbol (main_map, "free", &version);
> + void *new_malloc = lookup_malloc_symbol (main_map, "malloc", &version);
> + void *new_realloc = lookup_malloc_symbol (main_map, "realloc", &version);
> +
> + /* Update the pointers in one go, so that any internal allocations
> + performed by lookup_malloc_symbol see a consistent
> + implementation. */
> + __rtld_calloc = new_calloc;
> + __rtld_free = new_free;
> + __rtld_malloc = new_malloc;
> + __rtld_realloc = new_realloc;
OK. Love this manual hand-off.
> +}
> +
> /* Minimal malloc allocator for used during initial link. After the
> initial link, a full malloc implementation is interposed, either
> the one in libc, or a different one supplied by the user through
> @@ -38,14 +114,9 @@
>
> static void *alloc_ptr, *alloc_end, *alloc_last_block;
>
> -/* Declarations of global functions. */
> -extern void weak_function free (void *ptr);
> -extern void * weak_function realloc (void *ptr, size_t n);
> -
> -
> /* Allocate an aligned memory block. */
> -void * weak_function
> -malloc (size_t n)
> +static void *
> +rtld_malloc (size_t n)
> {
> if (alloc_end == 0)
> {
> @@ -87,8 +158,8 @@ malloc (size_t n)
> /* We use this function occasionally since the real implementation may
> be optimized when it can assume the memory it returns already is
> set to NUL. */
> -void * weak_function
> -calloc (size_t nmemb, size_t size)
> +static void *
> +rtld_calloc (size_t nmemb, size_t size)
> {
> /* New memory from the trivial malloc above is always already cleared.
> (We make sure that's true in the rare occasion it might not be,
> @@ -104,8 +175,8 @@ calloc (size_t nmemb, size_t size)
> }
>
> /* This will rarely be called. */
> -void weak_function
> -free (void *ptr)
> +void
> +rtld_free (void *ptr)
> {
> /* We can free only the last block allocated. */
> if (ptr == alloc_last_block)
> @@ -118,8 +189,8 @@ free (void *ptr)
> }
>
> /* This is only called with the most recent block returned by malloc. */
> -void * weak_function
> -realloc (void *ptr, size_t n)
> +void *
> +rtld_realloc (void *ptr, size_t n)
> {
> if (ptr == NULL)
> return malloc (n);
OK.
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 553cfbd1b7..51dfaf966a 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -534,6 +534,9 @@ _dl_start (void *arg)
> header table in core. Put the rest of _dl_start into a separate
> function, that way the compiler cannot put accesses to the GOT
> before ELF_DYNAMIC_RELOCATE. */
> +
> + __rtld_malloc_init_stubs ();
OK.
> +
> {
> #ifdef DONT_USE_BOOTSTRAP_MAP
> ElfW(Addr) entry = _dl_start_final (arg);
> @@ -2210,6 +2213,10 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
> rtld_timer_stop (&relocate_time, start);
> }
>
> + /* The library defining malloc has already been relocated due to
> + prelinking. Resolve the malloc symbols for the dynamic
> + loader. */
> + __rtld_malloc_init_real (main_map);
OK.
>
> /* Mark all the objects so we know they have been already relocated. */
> for (struct link_map *l = main_map; l != NULL; l = l->l_next)
> @@ -2310,6 +2317,11 @@ ERROR: '%s': cannot process note segment.\n", _dl_argv[0]);
> re-relocation, we might call a user-supplied function
> (e.g. calloc from _dl_relocate_object) that uses TLS data. */
>
> + /* The malloc implementation has been relocated, so resolving
> + its symbols (and potentially calling IFUNC resolvers) is safe
> + at this point. */
> + __rtld_malloc_init_real (main_map);
OK.
> +
> RTLD_TIMING_VAR (start);
> rtld_timer_start (&start);
>
> diff --git a/include/inline-hashtab.h b/include/inline-hashtab.h
> index 3c09978199..856719cf9d 100644
> --- a/include/inline-hashtab.h
> +++ b/include/inline-hashtab.h
> @@ -51,7 +51,7 @@ htab_create (void)
> return NULL;
> ht->size = 3;
> ht->entries = malloc (sizeof (void *) * ht->size);
> - ht->free = free;
> + ht->free = __rtld_free;
> if (! ht->entries)
> {
> free (ht);
> @@ -167,7 +167,7 @@ htab_expand (struct hashtab *htab, int (*hash_fn) (void *))
>
> /* Use the free() corresponding to the malloc() above to free this
> up. */
> - htab->free = free;
> + htab->free = __rtld_free;
>
> return 1;
> }
> diff --git a/include/libc-symbols.h b/include/libc-symbols.h
> index 685e20fdc0..33e2d34c53 100644
> --- a/include/libc-symbols.h
> +++ b/include/libc-symbols.h
> @@ -421,7 +421,14 @@ for linking")
> # define _default_symbol_version(real, name, version) \
> __asm__ (".symver " #real "," #name "@@" #version)
> # endif
> -#else
> +
> +/* Evalutes to a string literal for VERSION in LIB. */
> +# define symbol_version_string(lib, version) \
> + _symbol_version_stringify_1 (VERSION_##lib##_##version)
> +# define _symbol_version_stringify_1(arg) _symbol_version_stringify_2 (arg)
> +# define _symbol_version_stringify_2(arg) #arg
> +
> +#else /* !SHARED */
> # define symbol_version(real, name, version)
> # define default_symbol_version(real, name, version) \
> strong_alias(real, name)
> diff --git a/include/malloc.h b/include/malloc.h
> index 70d32c7c84..0765482c51 100644
> --- a/include/malloc.h
> +++ b/include/malloc.h
> @@ -1,7 +1,9 @@
> #ifndef _MALLOC_H
> +
> #include <malloc/malloc.h>
>
> # ifndef _ISOMAC
> +# include <rtld-malloc.h>
>
> /* In the GNU libc we rename the global variable
> `__malloc_initialized' to `__libc_malloc_initialized'. */
> diff --git a/include/rtld-malloc.h b/include/rtld-malloc.h
> new file mode 100644
> index 0000000000..b026a3270c
> --- /dev/null
> +++ b/include/rtld-malloc.h
> @@ -0,0 +1,85 @@
> +/* Redirection of malloc inside the dynamic linker.
> + Copyright (C) 2020 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/>. */
> +
> +/* The dynamic linker needs to use its own minimal malloc before libc
> + has been relocated, and the libc malloc afterwards. The active
> + malloc implementation is reached via the __rtld_* function pointers
> + declared below. They are initialized to the minimal malloc by
> + __rtld_malloc_init_stubs, and set to the final implementation by
> + __rtld_malloc_init_real. */
> +
> +#ifndef _RTLD_MALLOC_H
> +#define _RTLD_MALLOC_H
> +
> +#if IS_IN (rtld)
> +
> +extern __typeof (calloc) *__rtld_calloc attribute_hidden;
> +extern __typeof (free) *__rtld_free attribute_hidden;
> +extern __typeof (malloc) *__rtld_malloc attribute_hidden;
> +extern __typeof (realloc) *__rtld_realloc attribute_hidden;
> +
> +/* Wrapper functions which call through the function pointers above.
> + Note that it is not supported to take the address of those
> + functions. Instead the function pointers must be used
> + directly. */
> +
> +__extern_inline void *
> +calloc (size_t a, size_t b)
> +{
> + return __rtld_calloc (a, b);
> +}
> +
> +__extern_inline void
> +free (void *ptr)
> +{
> + __rtld_free (ptr);
> +}
> +
> +__extern_inline void *
> +malloc (size_t size)
> +{
> + return __rtld_malloc (size);
> +}
> +
> +__extern_inline void *
> +realloc (void *ptr, size_t size)
> +{
> + return __rtld_realloc (ptr, size);
> +}
> +
> +/* Called after the first self-relocation to activate the minimal malloc
> + implementation. */
> +void __rtld_malloc_init_stubs (void) attribute_hidden;
> +
> +/* Called shortly before the final self-relocation (when RELRO
> + variables are still writable) to activate the real malloc
> + implementation. MAIN_MAP is the link map of the executable. */
> +struct link_map;
> +void __rtld_malloc_init_real (struct link_map *main_map) attribute_hidden;
> +
> +#else /* !IS_IN (rtld) */
> +
> +/* This allows static/non-rtld builds to get a pointer to the
> + functions, in the same way that is required inside rtld. */
> +# define __rtld_calloc (&calloc)
> +# define __rtld_free (&free)
> +# define __rtld_malloc (&malloc)
> +# define __rtld_realloc (&realloc)
> +
> +#endif /* !IS_IN (rtld) */
> +#endif /* _RTLD_MALLOC_H */
OK.
> diff --git a/include/stdlib.h b/include/stdlib.h
> index 1fab78aa16..926f965f69 100644
> --- a/include/stdlib.h
> +++ b/include/stdlib.h
> @@ -9,6 +9,8 @@
> #if !defined _ISOMAC
> # include <sys/stat.h>
>
> +# include <rtld-malloc.h>
> +
> extern __typeof (strtol_l) __strtol_l;
> extern __typeof (strtoul_l) __strtoul_l;
> extern __typeof (strtoll_l) __strtoll_l;
> diff --git a/sysdeps/generic/localplt.data b/sysdeps/generic/localplt.data
> index 2d5c66ae28..e2083c0ce6 100644
> --- a/sysdeps/generic/localplt.data
> +++ b/sysdeps/generic/localplt.data
> @@ -7,12 +7,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
OK.
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/mach/hurd/i386/ld.abilist b/sysdeps/mach/hurd/i386/ld.abilist
> index c76b913486..6f591b2496 100644
> --- a/sysdeps/mach/hurd/i386/ld.abilist
> +++ b/sysdeps/mach/hurd/i386/ld.abilist
> @@ -16,10 +16,6 @@ GLIBC_2.2.6 _dl_mcount F
> GLIBC_2.2.6 _hurd_intr_rpc_mach_msg F
> GLIBC_2.2.6 _r_debug D 0x14
> GLIBC_2.2.6 abort F
> -GLIBC_2.2.6 calloc F
> -GLIBC_2.2.6 free F
> -GLIBC_2.2.6 malloc F
> -GLIBC_2.2.6 realloc F
OK.
> GLIBC_2.3 ___tls_get_addr F
> GLIBC_2.3 __tls_get_addr F
> GLIBC_2.4 __stack_chk_guard D 0x4
> diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
> index c1725d140f..102323e64f 100644
> --- a/sysdeps/mach/hurd/i386/localplt.data
> +++ b/sysdeps/mach/hurd/i386/localplt.data
> @@ -9,12 +9,6 @@ libc.so: malloc + REL R_386_GLOB_DAT
> libc.so: memalign + REL R_386_GLOB_DAT
> libc.so: realloc + REL R_386_GLOB_DAT
> libm.so: matherr + REL R_386_GLOB_DAT
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc + REL R_386_GLOB_DAT
> -ld.so: calloc + REL R_386_GLOB_DAT
> -ld.so: realloc + REL R_386_GLOB_DAT
> -ld.so: free + REL R_386_GLOB_DAT
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error + REL R_386_GLOB_DAT
> ld.so: _dl_catch_error + REL R_386_GLOB_DAT
> diff --git a/sysdeps/unix/sysv/linux/aarch64/ld.abilist b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
> index 4ffe688649..80b2fe6725 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/aarch64/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.17 __stack_chk_guard D 0x8
> GLIBC_2.17 __tls_get_addr F
> GLIBC_2.17 _dl_mcount F
> GLIBC_2.17 _r_debug D 0x28
> -GLIBC_2.17 calloc F
> -GLIBC_2.17 free F
> -GLIBC_2.17 malloc F
> -GLIBC_2.17 realloc F
> diff --git a/sysdeps/unix/sysv/linux/aarch64/localplt.data b/sysdeps/unix/sysv/linux/aarch64/localplt.data
> index a60053b914..56f362d3a7 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/aarch64/localplt.data
> @@ -9,12 +9,6 @@ libc.so: realloc
> libm.so: matherr
> # The dynamic loader needs __tls_get_addr for TLS.
> ld.so: __tls_get_addr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/alpha/ld.abilist b/sysdeps/unix/sysv/linux/alpha/ld.abilist
> index 98b66edabf..98a03f611f 100644
> --- a/sysdeps/unix/sysv/linux/alpha/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/alpha/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x28
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x8
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/alpha/localplt.data b/sysdeps/unix/sysv/linux/alpha/localplt.data
> index c69eb04ce5..43f6fdaea1 100644
> --- a/sysdeps/unix/sysv/linux/alpha/localplt.data
> +++ b/sysdeps/unix/sysv/linux/alpha/localplt.data
> @@ -26,12 +26,6 @@ libm.so: matherr + RELA R_ALPHA_GLOB_DAT
> libm.so: __atan2
> # The dynamic loader needs __tls_get_addr for TLS.
> ld.so: __tls_get_addr ?
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc + RELA R_ALPHA_GLOB_DAT
> -ld.so: calloc + RELA R_ALPHA_GLOB_DAT
> -ld.so: realloc + RELA R_ALPHA_GLOB_DAT
> -ld.so: free + RELA R_ALPHA_GLOB_DAT
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error + RELA R_ALPHA_GLOB_DAT
> ld.so: _dl_catch_error + RELA R_ALPHA_GLOB_DAT
> diff --git a/sysdeps/unix/sysv/linux/arm/be/ld.abilist b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
> index a301c6ebc4..cc8825c3bc 100644
> --- a/sysdeps/unix/sysv/linux/arm/be/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/arm/be/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
> GLIBC_2.4 __tls_get_addr F
> GLIBC_2.4 _dl_mcount F
> GLIBC_2.4 _r_debug D 0x14
> -GLIBC_2.4 calloc F
> -GLIBC_2.4 free F
> -GLIBC_2.4 malloc F
> -GLIBC_2.4 realloc F
> diff --git a/sysdeps/unix/sysv/linux/arm/le/ld.abilist b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
> index a301c6ebc4..cc8825c3bc 100644
> --- a/sysdeps/unix/sysv/linux/arm/le/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/arm/le/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
> GLIBC_2.4 __tls_get_addr F
> GLIBC_2.4 _dl_mcount F
> GLIBC_2.4 _r_debug D 0x14
> -GLIBC_2.4 calloc F
> -GLIBC_2.4 free F
> -GLIBC_2.4 malloc F
> -GLIBC_2.4 realloc F
> diff --git a/sysdeps/unix/sysv/linux/arm/localplt.data b/sysdeps/unix/sysv/linux/arm/localplt.data
> index 7bd541c28a..0c3af0c64e 100644
> --- a/sysdeps/unix/sysv/linux/arm/localplt.data
> +++ b/sysdeps/unix/sysv/linux/arm/localplt.data
> @@ -8,12 +8,6 @@ libm.so: matherr
> libpthread.so: raise
> # The dynamic loader needs __tls_get_addr for TLS.
> ld.so: __tls_get_addr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/csky/ld.abilist b/sysdeps/unix/sysv/linux/csky/ld.abilist
> index 71576160ed..564ac09737 100644
> --- a/sysdeps/unix/sysv/linux/csky/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/csky/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.29 __stack_chk_guard D 0x4
> GLIBC_2.29 __tls_get_addr F
> GLIBC_2.29 _dl_mcount F
> GLIBC_2.29 _r_debug D 0x14
> -GLIBC_2.29 calloc F
> -GLIBC_2.29 free F
> -GLIBC_2.29 malloc F
> -GLIBC_2.29 realloc F
> diff --git a/sysdeps/unix/sysv/linux/csky/localplt.data b/sysdeps/unix/sysv/linux/csky/localplt.data
> index 14c02cb2d6..0ed8650b65 100644
> --- a/sysdeps/unix/sysv/linux/csky/localplt.data
> +++ b/sysdeps/unix/sysv/linux/csky/localplt.data
> @@ -6,12 +6,6 @@ libc.so: free
> libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/hppa/ld.abilist b/sysdeps/unix/sysv/linux/hppa/ld.abilist
> index 0387614d8f..d155a59843 100644
> --- a/sysdeps/unix/sysv/linux/hppa/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/hppa/ld.abilist
> @@ -1,9 +1,5 @@
> GLIBC_2.2 __libc_stack_end D 0x4
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x14
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_addr F
> GLIBC_2.4 __stack_chk_guard D 0x4
> diff --git a/sysdeps/unix/sysv/linux/hppa/localplt.data b/sysdeps/unix/sysv/linux/hppa/localplt.data
> index 867413f0c5..09893d4dcf 100644
> --- a/sysdeps/unix/sysv/linux/hppa/localplt.data
> +++ b/sysdeps/unix/sysv/linux/hppa/localplt.data
> @@ -10,12 +10,6 @@ libc.so: __sigsetjmp
> libc.so: _IO_funlockfile
> libc.so: __errno_location
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/i386/ld.abilist b/sysdeps/unix/sysv/linux/i386/ld.abilist
> index edb7307228..0478e22071 100644
> --- a/sysdeps/unix/sysv/linux/i386/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/i386/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x4
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.3 ___tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/i386/localplt.data b/sysdeps/unix/sysv/linux/i386/localplt.data
> index f6f20a5d15..5334875b4b 100644
> --- a/sysdeps/unix/sysv/linux/i386/localplt.data
> +++ b/sysdeps/unix/sysv/linux/i386/localplt.data
> @@ -7,12 +7,6 @@ libc.so: malloc + REL R_386_GLOB_DAT
> libc.so: memalign + REL R_386_GLOB_DAT
> libc.so: realloc + REL R_386_GLOB_DAT
> libm.so: matherr + REL R_386_GLOB_DAT
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc + REL R_386_GLOB_DAT
> -ld.so: calloc + REL R_386_GLOB_DAT
> -ld.so: realloc + REL R_386_GLOB_DAT
> -ld.so: free + REL R_386_GLOB_DAT
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error + REL R_386_GLOB_DAT
> ld.so: _dl_catch_error + REL R_386_GLOB_DAT
> diff --git a/sysdeps/unix/sysv/linux/ia64/ld.abilist b/sysdeps/unix/sysv/linux/ia64/ld.abilist
> index 82042472c3..33f91199bf 100644
> --- a/sysdeps/unix/sysv/linux/ia64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/ia64/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.2 __libc_stack_end D 0x8
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x28
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/ia64/localplt.data b/sysdeps/unix/sysv/linux/ia64/localplt.data
> index 3820e2a4e6..1c566a503e 100644
> --- a/sysdeps/unix/sysv/linux/ia64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/ia64/localplt.data
> @@ -6,12 +6,6 @@ libc.so: realloc
> libm.so: matherr
> libm.so: matherrf
> libm.so: matherrl
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
> index a301c6ebc4..cc8825c3bc 100644
> --- a/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.4 __stack_chk_guard D 0x4
> GLIBC_2.4 __tls_get_addr F
> GLIBC_2.4 _dl_mcount F
> GLIBC_2.4 _r_debug D 0x14
> -GLIBC_2.4 calloc F
> -GLIBC_2.4 free F
> -GLIBC_2.4 malloc F
> -GLIBC_2.4 realloc F
> diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> index 4a07bf387e..3c5efb7204 100644
> --- a/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/localplt.data
> @@ -5,12 +5,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
> index c9ec45cf1c..3ba474c27f 100644
> --- a/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x4
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> index c70d6ea301..843f4e25f2 100644
> --- a/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/localplt.data
> @@ -6,12 +6,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/microblaze/ld.abilist b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
> index aa0d71150a..a4933c3541 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/microblaze/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.18 __stack_chk_guard D 0x4
> GLIBC_2.18 __tls_get_addr F
> GLIBC_2.18 _dl_mcount F
> GLIBC_2.18 _r_debug D 0x14
> -GLIBC_2.18 calloc F
> -GLIBC_2.18 free F
> -GLIBC_2.18 malloc F
> -GLIBC_2.18 realloc F
> diff --git a/sysdeps/unix/sysv/linux/microblaze/localplt.data b/sysdeps/unix/sysv/linux/microblaze/localplt.data
> index 8ca23897df..0e98d5251e 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/localplt.data
> +++ b/sysdeps/unix/sysv/linux/microblaze/localplt.data
> @@ -7,12 +7,6 @@ libc.so: realloc
> libm.so: matherr
> # The dynamic loader needs __tls_get_addr for TLS.
> ld.so: __tls_get_addr ?
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
> index 55d48868e8..be09641a48 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips32/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.2 __libc_stack_end D 0x4
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
> index 55d48868e8..be09641a48 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.2 __libc_stack_end D 0x4
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
> index 44b345b7cf..1ea36e13f2 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x28
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.2 __libc_stack_end D 0x8
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/nios2/ld.abilist b/sysdeps/unix/sysv/linux/nios2/ld.abilist
> index 110f1039fa..52178802dd 100644
> --- a/sysdeps/unix/sysv/linux/nios2/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/nios2/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.21 __stack_chk_guard D 0x4
> GLIBC_2.21 __tls_get_addr F
> GLIBC_2.21 _dl_mcount F
> GLIBC_2.21 _r_debug D 0x14
> -GLIBC_2.21 calloc F
> -GLIBC_2.21 free F
> -GLIBC_2.21 malloc F
> -GLIBC_2.21 realloc F
> diff --git a/sysdeps/unix/sysv/linux/nios2/localplt.data b/sysdeps/unix/sysv/linux/nios2/localplt.data
> index 3805ed56b9..b37987c7c0 100644
> --- a/sysdeps/unix/sysv/linux/nios2/localplt.data
> +++ b/sysdeps/unix/sysv/linux/nios2/localplt.data
> @@ -28,12 +28,6 @@ libc.so: __eqdf2
> libc.so: __extendsfdf2
> libc.so: __floatundidf ?
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> index e822e0a480..a02dd5cc24 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/localplt.data
> @@ -5,12 +5,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
> index e8b0ea3a9b..4bbfba7a61 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x4
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.22 __tls_get_addr_opt F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> index 647e735fdf..d8072597b7 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/localplt.data
> @@ -36,12 +36,6 @@ libc.so: realloc
> libm.so: copysignl ?
> libm.so: fabsl
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
> index edfc9ca56f..283fb4510b 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/ld.abilist
> @@ -4,7 +4,3 @@ GLIBC_2.3 __libc_stack_end D 0x8
> GLIBC_2.3 __tls_get_addr F
> GLIBC_2.3 _dl_mcount F
> GLIBC_2.3 _r_debug D 0x28
> -GLIBC_2.3 calloc F
> -GLIBC_2.3 free F
> -GLIBC_2.3 malloc F
> -GLIBC_2.3 realloc F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
> index 37c8f6684b..b1f313c7cd 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/ld.abilist
> @@ -2,9 +2,5 @@ GLIBC_2.17 __libc_stack_end D 0x8
> GLIBC_2.17 __tls_get_addr F
> GLIBC_2.17 _dl_mcount F
> GLIBC_2.17 _r_debug D 0x28
> -GLIBC_2.17 calloc F
> -GLIBC_2.17 free F
> -GLIBC_2.17 malloc F
> -GLIBC_2.17 realloc F
> GLIBC_2.22 __tls_get_addr_opt F
> GLIBC_2.23 __parse_hwcap_and_convert_at_platform F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> index c1209336d2..bb498fbe3a 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/localplt.data
> @@ -4,12 +4,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/riscv/localplt.data b/sysdeps/unix/sysv/linux/riscv/localplt.data
> index 14c02cb2d6..0ed8650b65 100644
> --- a/sysdeps/unix/sysv/linux/riscv/localplt.data
> +++ b/sysdeps/unix/sysv/linux/riscv/localplt.data
> @@ -6,12 +6,6 @@ libc.so: free
> libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
> index b411871d06..845f356c3c 100644
> --- a/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/riscv/rv64/ld.abilist
> @@ -3,7 +3,3 @@ GLIBC_2.27 __stack_chk_guard D 0x8
> GLIBC_2.27 __tls_get_addr F
> GLIBC_2.27 _dl_mcount F
> GLIBC_2.27 _r_debug D 0x28
> -GLIBC_2.27 calloc F
> -GLIBC_2.27 free F
> -GLIBC_2.27 malloc F
> -GLIBC_2.27 realloc F
> diff --git a/sysdeps/unix/sysv/linux/s390/localplt.data b/sysdeps/unix/sysv/linux/s390/localplt.data
> index e822e0a480..a02dd5cc24 100644
> --- a/sysdeps/unix/sysv/linux/s390/localplt.data
> +++ b/sysdeps/unix/sysv/linux/s390/localplt.data
> @@ -5,12 +5,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
> index 0576c9575e..b56f005beb 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x4
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.3 __tls_get_offset F
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
> index 1fbb890d1d..6f788a086d 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.2 __libc_stack_end D 0x8
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x28
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_offset F
> diff --git a/sysdeps/unix/sysv/linux/sh/be/ld.abilist b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
> index 0387614d8f..d155a59843 100644
> --- a/sysdeps/unix/sysv/linux/sh/be/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/sh/be/ld.abilist
> @@ -1,9 +1,5 @@
> GLIBC_2.2 __libc_stack_end D 0x4
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x14
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_addr F
> GLIBC_2.4 __stack_chk_guard D 0x4
> diff --git a/sysdeps/unix/sysv/linux/sh/le/ld.abilist b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
> index 0387614d8f..d155a59843 100644
> --- a/sysdeps/unix/sysv/linux/sh/le/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/sh/le/ld.abilist
> @@ -1,9 +1,5 @@
> GLIBC_2.2 __libc_stack_end D 0x4
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x14
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_addr F
> GLIBC_2.4 __stack_chk_guard D 0x4
> diff --git a/sysdeps/unix/sysv/linux/sh/localplt.data b/sysdeps/unix/sysv/linux/sh/localplt.data
> index babb19d717..3225177c50 100644
> --- a/sysdeps/unix/sysv/linux/sh/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sh/localplt.data
> @@ -12,12 +12,6 @@ libc.so: __errno_location
> libm.so: matherr
> # Generated by the compiler because there is no trap insn pattern.
> libc.so: abort ?
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
> index fd0b33f86d..0c6610e3c2 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.0 _r_debug D 0x14
> -GLIBC_2.0 calloc F
> -GLIBC_2.0 free F
> -GLIBC_2.0 malloc F
> -GLIBC_2.0 realloc F
> GLIBC_2.1 __libc_stack_end D 0x4
> GLIBC_2.1 _dl_mcount F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> index 6bf10ff858..be51efd566 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/localplt.data
> @@ -19,12 +19,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
> index 82042472c3..33f91199bf 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.2 __libc_stack_end D 0x8
> GLIBC_2.2 _dl_mcount F
> GLIBC_2.2 _r_debug D 0x28
> -GLIBC_2.2 calloc F
> -GLIBC_2.2 free F
> -GLIBC_2.2 malloc F
> -GLIBC_2.2 realloc F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> index b881b9096d..809062d46c 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/localplt.data
> @@ -18,12 +18,6 @@ libc.so: malloc
> libc.so: memalign
> libc.so: realloc
> libm.so: matherr
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc
> -ld.so: calloc
> -ld.so: realloc
> -ld.so: free
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error
> ld.so: _dl_catch_error
> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
> index 0dc9430611..d3cdf7611e 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/64/ld.abilist
> @@ -1,8 +1,4 @@
> GLIBC_2.2.5 __libc_stack_end D 0x8
> GLIBC_2.2.5 _dl_mcount F
> GLIBC_2.2.5 _r_debug D 0x28
> -GLIBC_2.2.5 calloc F
> -GLIBC_2.2.5 free F
> -GLIBC_2.2.5 malloc F
> -GLIBC_2.2.5 realloc F
> GLIBC_2.3 __tls_get_addr F
> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
> index 80f3161586..c70bccf782 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/ld.abilist
> @@ -2,7 +2,3 @@ GLIBC_2.16 __libc_stack_end D 0x4
> GLIBC_2.16 __tls_get_addr F
> GLIBC_2.16 _dl_mcount F
> GLIBC_2.16 _r_debug D 0x14
> -GLIBC_2.16 calloc F
> -GLIBC_2.16 free F
> -GLIBC_2.16 malloc F
> -GLIBC_2.16 realloc F
> diff --git a/sysdeps/x86_64/localplt.data b/sysdeps/x86_64/localplt.data
> index c27a02b66a..8f41e92870 100644
> --- a/sysdeps/x86_64/localplt.data
> +++ b/sysdeps/x86_64/localplt.data
> @@ -9,12 +9,6 @@ libc.so: malloc + RELA R_X86_64_GLOB_DAT
> libc.so: memalign + RELA R_X86_64_GLOB_DAT
> libc.so: realloc + RELA R_X86_64_GLOB_DAT
> libm.so: matherr + RELA R_X86_64_GLOB_DAT
> -# The main malloc is interposed into the dynamic linker, for
> -# allocations after the initial link (when dlopen is used).
> -ld.so: malloc + RELA R_X86_64_GLOB_DAT
> -ld.so: calloc + RELA R_X86_64_GLOB_DAT
> -ld.so: realloc + RELA R_X86_64_GLOB_DAT
> -ld.so: free + RELA R_X86_64_GLOB_DAT
> # The TLS-enabled version of these functions is interposed from libc.so.
> ld.so: _dl_signal_error + RELA R_X86_64_GLOB_DAT
> ld.so: _dl_catch_error + RELA R_X86_64_GLOB_DAT
>
--
Cheers,
Carlos.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486]
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
` (4 preceding siblings ...)
2020-02-14 22:36 ` [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader " Carlos O'Donell
@ 2020-02-17 12:25 ` Lucas A. M. Magalhaes
5 siblings, 0 replies; 12+ messages in thread
From: Lucas A. M. Magalhaes @ 2020-02-17 12:25 UTC (permalink / raw)
To: Florian Weimer, libc-alpha
Hi,
I've tested this patchset on a ppc64le and result as expected. Test
io/tst-lchmod is expected to fail and is already being solved in other
patchset.
Test Summary:
XPASS: elf/tst-protected1a
XPASS: elf/tst-protected1b
FAIL: io/tst-lchmod
UNSUPPORTED: math/test-fesetexcept-traps
UNSUPPORTED: math/test-fexcept-traps
UNSUPPORTED: misc/tst-pkey
UNSUPPORTED: nptl/test-cond-printers
UNSUPPORTED: nptl/test-condattr-printers
UNSUPPORTED: nptl/test-mutex-printers
UNSUPPORTED: nptl/test-mutexattr-printers
UNSUPPORTED: nptl/test-rwlock-printers
UNSUPPORTED: nptl/test-rwlockattr-printers
UNSUPPORTED: posix/tst-spawn4-compat
Summary of test results:
1 FAIL
5127 PASS
10 UNSUPPORTED
17 XFAIL
2 XPASS
Thanks,
Lucas A. M. Magalhães
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486]
2020-02-08 19:01 ` [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486] Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
@ 2020-02-24 11:53 ` Florian Weimer
1 sibling, 0 replies; 12+ messages in thread
From: Florian Weimer @ 2020-02-24 11:53 UTC (permalink / raw)
To: libc-alpha; +Cc: mjw, Patsy Griffin, Carlos O'Donell
* Florian Weimer:
> Exporting functions and relying on symbol interposition from libc.so
> makes the choice of implementation dependent on DT_NEEDED order, which
> is not what some compiler drivers expect.
>
> This commit replaces one magic mechanism (symbol interposition) with
> another one (preprocessor-/compiler-based redirection). This makes
> the hand-over from the minimal malloc to the full malloc more
> explicit.
>
> Removing the ABI symbols is backwards-compatible because libc.so is
> always in scope, and the dynamic loader will find the malloc-related
> symbols there since commit f0b2132b35248c1f4a80f62a2c38cddcc802aa8c
> ("ld.so: Support moving versioned symbols between sonames
> [BZ #24741]").
>
> Tested on aarch64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
> s390x-linux-gnu without the stack protector, and on x86_64-linux-gnu
> with stack-protector-strong. Also built with build-many-glibcs.py.
This commit breaks valgrind because it can no longer interpose the early
malloc, leading to tons of errors on at least aarch64:
==801990== Command: /root/build/elf/ld-linux-aarch64.so.1 --library-path /root/build:/root/build/math:/root/build/elf:/root/build/dlfcn:/root/build/nss:/root/build/nis:/root/build/rt:/root/build/resolv:/root/build/mathvec:/root/build/support:/root/build/crypt:/root/build/nptl /bin/true --help
==801990==
==801990== Conditional jump or move depends on uninitialised value(s)
==801990== at 0x197EA8: ??? (in /root/build/elf/ld.so)
==801990==
And this goes on and on. There's no stack trace here, so it's difficult
to pin down. (The toolchain used for this build is supposed to build
everything with -fasynchronous-unwind-tables, so I'm not sure why
there's no backtrace.)
I believe the location is in the index function:
0000000000017e10 <index>:
17e10: mov w4, #0x401 // #1025
17e14: movk w4, #0x4010, lsl #16
17e18: dup v0.16b, w1
17e1c: and x2, x0, #0xffffffffffffffe0
17e20: dup v16.4s, w4
17e24: ands x3, x0, #0x1f
17e28: add v7.4s, v16.4s, v16.4s
17e2c: b.eq 17e80 <index+0x70> // b.none
17e30: ld1 {v1.16b, v2.16b}, [x2], #32
17e34: neg x3, x3
17e38: cmeq v3.16b, v1.16b, #0
17e3c: cmeq v5.16b, v1.16b, v0.16b
17e40: cmeq v4.16b, v2.16b, #0
17e44: cmeq v6.16b, v2.16b, v0.16b
17e48: and v3.16b, v3.16b, v7.16b
17e4c: and v4.16b, v4.16b, v7.16b
17e50: and v5.16b, v5.16b, v16.16b
17e54: and v6.16b, v6.16b, v16.16b
17e58: orr v17.16b, v3.16b, v5.16b
17e5c: orr v18.16b, v4.16b, v6.16b
17e60: lsl x3, x3, #1
17e64: addp v17.16b, v17.16b, v18.16b
17e68: mov x5, #0xffffffffffffffff // #-1
17e6c: addp v17.16b, v17.16b, v18.16b
17e70: lsr x3, x5, x3
17e74: mov x5, v17.d[0]
17e78: bic x3, x5, x3
17e7c: cbnz x3, 17ed0 <index+0xc0>
17e80: ld1 {v1.16b, v2.16b}, [x2], #32
17e84: cmeq v3.16b, v1.16b, #0
17e88: cmeq v5.16b, v1.16b, v0.16b
17e8c: cmeq v4.16b, v2.16b, #0
17e90: cmeq v6.16b, v2.16b, v0.16b
17e94: orr v17.16b, v3.16b, v5.16b
17e98: orr v18.16b, v4.16b, v6.16b
17e9c: orr v17.16b, v17.16b, v18.16b
17ea0: addp v17.2d, v17.2d, v17.2d
17ea4: mov x3, v17.d[0]
17ea8: cbz x3, 17e80 <index+0x70>
17eac: and v3.16b, v3.16b, v7.16b
17eb0: and v4.16b, v4.16b, v7.16b
17eb4: and v5.16b, v5.16b, v16.16b
17eb8: and v6.16b, v6.16b, v16.16b
17ebc: orr v17.16b, v3.16b, v5.16b
17ec0: orr v18.16b, v4.16b, v6.16b
17ec4: addp v17.16b, v17.16b, v18.16b
17ec8: addp v17.16b, v17.16b, v18.16b
17ecc: mov x3, v17.d[0]
17ed0: sub x2, x2, #0x20
17ed4: rbit x3, x3
17ed8: clz x3, x3
17edc: tst x3, #0x1
17ee0: add x0, x2, x3, lsr #1
17ee4: csel x0, x0, xzr, eq // eq = none
17ee8: ret
I don't know why valgrind would think the memory is undefined at this
point.
Thanks,
Florian
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2020-02-24 11:53 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-08 19:00 [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader [BZ #25486] Florian Weimer
2020-02-08 19:00 ` [PATCH 1/4] elf: Introduce the rtld-stubbed-symbols makefile variable Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 2/4] elf: Extract _dl_sym_post, _dl_sym_find_caller_map from elf/dl-sym.c Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 3/4] Remove weak declaration of free from <inline-hashtab.h> Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-08 19:01 ` [PATCH 4/4] ld.so: Do not export free/calloc/malloc/realloc functions [BZ #25486] Florian Weimer
2020-02-14 22:36 ` Carlos O'Donell
2020-02-24 11:53 ` Florian Weimer
2020-02-14 22:36 ` [PATCH 0/4] Avoid malloc symbol interposition in the dynamic loader " Carlos O'Donell
2020-02-17 12:25 ` Lucas A. M. Magalhaes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).