Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/ld.elf_so _rtld_map_object(): no need to mmap an emp...



details:   https://anonhg.NetBSD.org/src/rev/dfa91f96b0d4
branches:  trunk
changeset: 364575:dfa91f96b0d4
user:      hannken <hannken%NetBSD.org@localhost>
date:      Wed Mar 30 08:26:45 2022 +0000

description:
_rtld_map_object(): no need to mmap an empty bss segment.

diffstat:

 libexec/ld.elf_so/map_object.c |  16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diffs (37 lines):

diff -r e632e4b2c10d -r dfa91f96b0d4 libexec/ld.elf_so/map_object.c
--- a/libexec/ld.elf_so/map_object.c    Wed Mar 30 02:45:14 2022 +0000
+++ b/libexec/ld.elf_so/map_object.c    Wed Mar 30 08:26:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: map_object.c,v 1.61 2020/03/04 01:21:17 thorpej Exp $   */
+/*     $NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $   */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.61 2020/03/04 01:21:17 thorpej Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $");
 #endif /* not lint */
 
 #include <errno.h>
@@ -371,11 +371,13 @@
        }
 
        /* Overlay the bss segment onto the proper region. */
-       if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit,
-           data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) ==
-           MAP_FAILED) {
-               _rtld_error("mmap of bss failed: %s", xstrerror(errno));
-               goto bad;
+       if (base_vlimit > data_vlimit) {
+               if (mmap(mapbase + data_vlimit - base_vaddr,
+                   base_vlimit - data_vlimit, data_flags,
+                   MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) == MAP_FAILED) {
+                       _rtld_error("mmap of bss failed: %s", xstrerror(errno));
+                       goto bad;
+               }
        }
 
        /* Unmap the gap between the text and data. */



Home | Main Index | Thread Index | Old Index