[PATCH 3/4] dl-sysdep: disable remaining calls to sbrk()

Topi Miettinen toiwoton@gmail.com
Sat Nov 28 11:59:44 GMT 2020


When sbrk() is not used for memory allocations, there's no need to
initialize the break anymore.

--
v2: use tunable
---
 elf/dl-sysdep.c                     | 11 ++++++++++-
 sysdeps/unix/sysv/linux/dl-sysdep.c | 10 ++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/elf/dl-sysdep.c b/elf/dl-sysdep.c
index 854570821c..406b3a3809 100644
--- a/elf/dl-sysdep.c
+++ b/elf/dl-sysdep.c
@@ -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
diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c
index 90c9b1db2d..625e6cb759 100644
--- a/sysdeps/unix/sysv/linux/dl-sysdep.c
+++ b/sysdeps/unix/sysv/linux/dl-sysdep.c
@@ -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
-- 
2.29.2



More information about the Libc-alpha mailing list