glibc/0003-elf-ld.so-remove-_mmap_hole-when-ld.so-mmap-PT_LOAD-.patch
shixuantong 5e5f573b1a enable share library use huge page for aarch architecture
(cherry picked from commit 2291cb16841ea15ab298859a3175b6b65f65ea48)
2024-08-21 09:05:52 +08:00

85 lines
3.3 KiB
Diff

From 117a913e7b1c380bb99796588b266547de959de9 Mon Sep 17 00:00:00 2001
From: Lv Ying <lvying6@huawei.com>
Date: Thu, 23 Feb 2023 22:15:06 +0800
Subject: [PATCH 3/3] elf/ld.so: remove _mmap_hole when ld.so mmap PT_LOAD
segment try to use hugepage
When ld.so mmap PT_LOAD segment try to use hugepage, it's unnecessary to
remap hole area, becasue __mmap_reserved_area already mmap reserved area
as PROT_NONE. Besides _mmap_hole may mmap hole area from 4KB page
misaligned addresses which will cause mmap faiure(invalid argument).
Signed-off-by: Lv Ying <lvying6@huawei.com>
---
elf/dl-load.h | 2 --
elf/dl-map-segments-hugepage.h | 26 --------------------------
2 files changed, 28 deletions(-)
diff --git a/elf/dl-load.h b/elf/dl-load.h
index 3edb4b70..ad6760fa 100644
--- a/elf/dl-load.h
+++ b/elf/dl-load.h
@@ -139,8 +139,6 @@ static const char *_dl_map_segments (struct link_map *l, int fd,
N_("failed to read shared object file")
#define DL_MAP_SEGMENTS_ERROR_ARRANGE \
N_("shared object's PT_LOAD segment in wrong arrange")
-#define DL_MAP_SEGMENTS_ERROR_MAP_HOLE_FILL \
- N_("failed to mmap shared object's hole part of PT_LOAD")
#define DL_MAP_RESERVED_HUGEPAGE_AREA_ERROR \
N_("failed to map reserved 2MB contiguous hugepage va space")
#define DL_FIND_EXEC_SEGMENT_ERROR \
diff --git a/elf/dl-map-segments-hugepage.h b/elf/dl-map-segments-hugepage.h
index ced011f4..437baf5a 100644
--- a/elf/dl-map-segments-hugepage.h
+++ b/elf/dl-map-segments-hugepage.h
@@ -505,19 +505,6 @@ _mmap_segment(struct link_map *l, const struct loadcmd loadcmds[], size_t nloadc
return NULL;
}
-static __always_inline void *
-_mmap_hole(const struct loadcmd *current, const struct loadcmd *next,
- ElfW(Addr) mapstart, size_t mapseglen, int fd)
-{
- if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
- _dl_debug_printf("\tmmap hole area:[%lx-%lx)\n", mapstart + mapseglen,
- mapstart + (next->mapstart - current->mapstart));
- return __mmap((void *)(mapstart + mapseglen),
- next->mapstart - (current->mapstart + mapseglen),
- PROT_NONE, MAP_FILE|MAP_PRIVATE|MAP_FIXED,
- fd, current->mapoff + mapseglen);
-}
-
static __always_inline const char *
_dl_map_segments_largein (struct link_map *l, int fd,
const ElfW(Ehdr) *header, int type,
@@ -560,13 +547,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
goto unmap_reserved_area;
}
- if (prev->mapstart + mapseglen < c->mapstart &&
- _mmap_hole(prev, c, map_addr, mapseglen, fd) == MAP_FAILED)
- {
- errstring = DL_MAP_SEGMENTS_ERROR_MAP_HOLE_FILL;
- goto unmap_reserved_area;
- }
-
map_addr += c->mapstart - prev->mapstart;
errstring = _mmap_segment(l, loadcmds, nloadcmds, c, map_addr, fd,
&mapseglen, hp_bitmap);
@@ -601,12 +581,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
goto unmap_reserved_area;
}
- if (c->mapstart + mapseglen < prev->mapstart &&
- _mmap_hole(c, prev, map_addr, mapseglen, fd) == MAP_FAILED)
- {
- errstring = DL_MAP_SEGMENTS_ERROR_MAP_HOLE_FILL;
- goto unmap_reserved_area;
- }
prev = c;
--c;
}
--
2.27.0