[3/3] dl-sysdep: disable remaining calls to sbrk()
Commit Message
When sbrk() is not used for memory allocations, there's no need to
initialize the break anymore.
--
v2: use tunable
Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
---
elf/dl-sysdep.c | 11 ++++++++++-
sysdeps/unix/sysv/linux/dl-sysdep.c | 10 ++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
@@ -44,6 +44,10 @@
#include <libc-internal.h>
#include <tls.h>
+#if HAVE_TUNABLES
+# undef TUNABLE_NAMESPACE
+# define TUNABLE_NAMESPACE malloc
+#endif
#include <dl-tunables.h>
#include <dl-auxv.h>
@@ -234,7 +238,12 @@ _dl_sysdep_start (void **start_argptr,
if (GLRO(dl_platform) != NULL)
GLRO(dl_platformlen) = strlen (GLRO(dl_platform));
- if (__sbrk (0) == _end)
+ /* Tunable glibc.malloc.use_sbrk controls use of 'sbrk()'. */
+ if (
+#if HAVE_TUNABLES
+ TUNABLE_GET (use_sbrk, int32_t, NULL) &&
+#endif
+ __sbrk (0) == _end)
/* The dynamic linker was run as a program, and so the initial break
starts just after our bss, at &_end. The malloc in dl-minimal.c
will consume the rest of this page, so tell the kernel to move the
@@ -27,14 +27,24 @@
#include <ldsodefs.h>
#include <not-cancel.h>
+#if HAVE_TUNABLES
+# undef TUNABLE_NAMESPACE
+# define TUNABLE_NAMESPACE malloc
+#endif
+
#ifdef SHARED
# define DL_SYSDEP_INIT frob_brk ()
static inline void
frob_brk (void)
{
+ /* Tunable glibc.malloc.use_sbrk controls use of 'sbrk()'. */
+#if HAVE_TUNABLES
+ if (TUNABLE_GET (use_sbrk, int32_t, NULL))
+#endif
__brk (0); /* Initialize the break. */
}
+# undef TUNABLE_NAMESPACE
# include <elf/dl-sysdep.c>
#endif