enable share library use huge page for aarch architecture
(cherry picked from commit 2291cb16841ea15ab298859a3175b6b65f65ea48)
This commit is contained in:
parent
962036a8d5
commit
5e5f573b1a
@ -764,7 +764,7 @@ index 00000000..cd7b6d79
|
||||
+ /* First to mmap text segment */
|
||||
+ const struct loadcmd * c = loadcmds;
|
||||
+ ElfW(Addr) text_addr = ALIGN_UP((ElfW(Addr))map_area_start + (text->mapstart - c->mapstart), SIZE_2MB);
|
||||
+ size_t mapseglen;
|
||||
+ size_t mapseglen = 0;
|
||||
+ errstring = _mmap_segment(l, loadcmds, nloadcmds, text, text_addr, fd, &mapseglen);
|
||||
+ if (__glibc_unlikely(errstring != NULL))
|
||||
+ goto unmap_reserved_area;
|
||||
|
||||
@ -159,7 +159,7 @@ index 37788ef9..e7202131 100644
|
||||
@@ -470,7 +525,8 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
const struct loadcmd * c = loadcmds;
|
||||
ElfW(Addr) text_addr = ALIGN_UP((ElfW(Addr))map_area_start + (text->mapstart - c->mapstart), SIZE_2MB);
|
||||
size_t mapseglen;
|
||||
size_t mapseglen = 0;
|
||||
- errstring = _mmap_segment(l, loadcmds, nloadcmds, text, text_addr, fd, &mapseglen);
|
||||
+ errstring = _mmap_segment(l, loadcmds, nloadcmds, text, text_addr, fd,
|
||||
+ &mapseglen, hp_bitmap);
|
||||
|
||||
@ -16,11 +16,11 @@ Signed-off-by: Lv Ying <lvying6@huawei.com>
|
||||
2 files changed, 28 deletions(-)
|
||||
|
||||
diff --git a/elf/dl-load.h b/elf/dl-load.h
|
||||
index fcf91a47..f2428165 100644
|
||||
index 3edb4b70..ad6760fa 100644
|
||||
--- a/elf/dl-load.h
|
||||
+++ b/elf/dl-load.h
|
||||
@@ -136,8 +136,6 @@ static const char *_dl_map_segments (struct link_map *l, int fd,
|
||||
N_("cannot map Non shared object file in hugepage")
|
||||
@@ -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 \
|
||||
@ -29,10 +29,10 @@ index fcf91a47..f2428165 100644
|
||||
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 e7202131..a352c903 100644
|
||||
index ced011f4..437baf5a 100644
|
||||
--- a/elf/dl-map-segments-hugepage.h
|
||||
+++ b/elf/dl-map-segments-hugepage.h
|
||||
@@ -486,19 +486,6 @@ _mmap_segment(struct link_map *l, const struct loadcmd loadcmds[], size_t nloadc
|
||||
@@ -505,19 +505,6 @@ _mmap_segment(struct link_map *l, const struct loadcmd loadcmds[], size_t nloadc
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ index e7202131..a352c903 100644
|
||||
static __always_inline const char *
|
||||
_dl_map_segments_largein (struct link_map *l, int fd,
|
||||
const ElfW(Ehdr) *header, int type,
|
||||
@@ -541,13 +528,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
@@ -560,13 +547,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
goto unmap_reserved_area;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ index e7202131..a352c903 100644
|
||||
map_addr += c->mapstart - prev->mapstart;
|
||||
errstring = _mmap_segment(l, loadcmds, nloadcmds, c, map_addr, fd,
|
||||
&mapseglen, hp_bitmap);
|
||||
@@ -582,12 +562,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
@@ -601,12 +581,6 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
goto unmap_reserved_area;
|
||||
}
|
||||
|
||||
@ -80,5 +80,5 @@ index e7202131..a352c903 100644
|
||||
--c;
|
||||
}
|
||||
--
|
||||
2.38.1
|
||||
2.27.0
|
||||
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
From 49986b3674d002c43fa09e6b777555bdc772018b Mon Sep 17 00:00:00 2001
|
||||
From: Lv Ying <lvying6@huawei.com>
|
||||
Date: Tue, 25 Jan 2022 09:29:32 +0000
|
||||
Subject: [PATCH 3/3] elf/ld.so: use special mmap for hugepage to get symbols
|
||||
|
||||
use special mmap for hugepage to get symbols in hugepage area for debug
|
||||
purpose; kernel need to support file mmap hugepage;
|
||||
---
|
||||
elf/dl-load.h | 2 --
|
||||
elf/dl-map-segments-hugepage.h | 25 +++----------------------
|
||||
2 files changed, 3 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/elf/dl-load.h b/elf/dl-load.h
|
||||
index d3f69466..fcf91a47 100644
|
||||
--- a/elf/dl-load.h
|
||||
+++ b/elf/dl-load.h
|
||||
@@ -134,8 +134,6 @@ static const char *_dl_map_segments (struct link_map *l, int fd,
|
||||
#ifdef HUGEPAGE_SHARED_LIB
|
||||
#define DL_MAP_SEGMENTS_ERROR_TYPE \
|
||||
N_("cannot map Non shared object file in hugepage")
|
||||
-#define DL_MAP_SEGMENTS_ERROR_READ_SEGMENT \
|
||||
- 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 \
|
||||
diff --git a/elf/dl-map-segments-hugepage.h b/elf/dl-map-segments-hugepage.h
|
||||
index cd7b6d79..37788ef9 100644
|
||||
--- a/elf/dl-map-segments-hugepage.h
|
||||
+++ b/elf/dl-map-segments-hugepage.h
|
||||
@@ -302,33 +302,14 @@ _mmap_segment_filesz(struct link_map *l, const struct loadcmd *c, ElfW(Addr) map
|
||||
|
||||
size_t mod = len % SIZE_2MB;
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\t\tmmap hugepage: [%lx-%lx)\n", mapstart, mapstart + len - mod);
|
||||
+ _dl_debug_printf("\t\tmmap hugepage: [%lx-%lx), mapoff = %lx\n", mapstart,
|
||||
+ mapstart + len - mod, c->mapoff + relro_len + prev_map_len);
|
||||
mapstart = (ElfW(Addr))__mmap((void *)mapstart, len - mod, c->prot,
|
||||
MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|(SHFIT_2MB << MAP_HUGE_SHIFT),
|
||||
- -1, 0);
|
||||
+ fd, c->mapoff + relro_len + prev_map_len);
|
||||
if (__glibc_unlikely ((void *)mapstart == MAP_FAILED))
|
||||
return DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT;
|
||||
|
||||
- if ((c->prot & PROT_WRITE) == 0 && __mprotect((void *)mapstart, len - mod, c->prot | PROT_WRITE) < 0)
|
||||
- {
|
||||
- return DL_MAP_SEGMENTS_ERROR_MPROTECT;
|
||||
- }
|
||||
-
|
||||
- /* Read the segment contents from the file. */
|
||||
- size_t file_len = (size_t)(c->dataend - c->mapstart) <= prev_map_len + relro_len ? 0 :
|
||||
- (size_t)(c->dataend - c->mapstart) - prev_map_len - relro_len;
|
||||
- if (file_len > 0)
|
||||
- {
|
||||
- lseek(fd, c->mapoff + relro_len + prev_map_len, SEEK_SET);
|
||||
- if ( __read(fd, (void *)mapstart, file_len < len - mod ? file_len : len - mod) < 0)
|
||||
- return DL_MAP_SEGMENTS_ERROR_READ_SEGMENT;
|
||||
- }
|
||||
-
|
||||
- if ((c->prot & PROT_WRITE) == 0 && __mprotect((void *)mapstart, len - mod, c->prot) < 0)
|
||||
- {
|
||||
- return DL_MAP_SEGMENTS_ERROR_MPROTECT;
|
||||
- }
|
||||
-
|
||||
map_addr = map_addr == 0 ? (void *)mapstart : map_addr;
|
||||
mapstart += len - mod;
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
||||
32
change-hugepageedit-from-dynamic-link-to-static-link.patch
Normal file
32
change-hugepageedit-from-dynamic-link-to-static-link.patch
Normal file
@ -0,0 +1,32 @@
|
||||
From 86794adf4fbd0433f57e54ca39a772fd08a50ddc Mon Sep 17 00:00:00 2001
|
||||
From: chenziyang <chenziyang4@huawei.com>
|
||||
Date: Wed, 24 May 2023 18:04:25 +0800
|
||||
Subject: [PATCH] hugepageedit: static-link build
|
||||
|
||||
---
|
||||
elf/Makefile | 7 +++++--
|
||||
1 file changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/elf/Makefile b/elf/Makefile
|
||||
index b5de4dd4..2b395a6f 100644
|
||||
--- a/elf/Makefile
|
||||
+++ b/elf/Makefile
|
||||
@@ -209,10 +209,13 @@ endif
|
||||
|
||||
ifeq (yes,$(enable-hugepage-shared-library))
|
||||
others += hugepageedit
|
||||
-others-pie += hugepageedit
|
||||
+others-static += hugepageedit
|
||||
install-bin += hugepageedit
|
||||
|
||||
-$(objpfx)hugepageedit: $(objpfx)hugepageedit.o
|
||||
+hugepageedit-modules := static-stubs
|
||||
+extra-objs += $(hugepageedit-modules:=.o)
|
||||
+
|
||||
+$(objpfx)hugepageedit: $(hugepageedit-modules:%=$(objpfx)%.o)
|
||||
|
||||
ifeq ($(run-built-tests),yes)
|
||||
tests-special += $(objpfx)tst-hugepageedit1.out $(objpfx)tst-ld-hugepage-env.out \
|
||||
--
|
||||
2.27.0
|
||||
|
||||
124
elf-add-some-debug-info-for-dynamic-library-hugepage.patch
Normal file
124
elf-add-some-debug-info-for-dynamic-library-hugepage.patch
Normal file
@ -0,0 +1,124 @@
|
||||
From 50c5e23ead7f0be215b8133dfa7ab6a93e60ebf7 Mon Sep 17 00:00:00 2001
|
||||
From: Lv Ying <lvying6@huawei.com>
|
||||
Date: Tue, 4 Jun 2024 01:23:09 -0400
|
||||
Subject: [PATCH 2/2] elf: add some debug info for dynamic library hugepage
|
||||
feature
|
||||
|
||||
add some debug info for dynamic library hugepage feature, use
|
||||
page-aligined address space in debug info which is actual mapped
|
||||
|
||||
Signed-off-by: Lv Ying <lvying6@huawei.com>
|
||||
---
|
||||
elf/dl-map-segments-hugepage.h | 37 ++++++++++++++++++++--------------
|
||||
1 file changed, 22 insertions(+), 15 deletions(-)
|
||||
|
||||
diff --git a/elf/dl-map-segments-hugepage.h b/elf/dl-map-segments-hugepage.h
|
||||
index 3ea52dbd..7410072c 100644
|
||||
--- a/elf/dl-map-segments-hugepage.h
|
||||
+++ b/elf/dl-map-segments-hugepage.h
|
||||
@@ -212,7 +212,7 @@ _mmap_remain_zero_page(ElfW(Addr) zeropage, ElfW(Addr) zeroend, int prot)
|
||||
}
|
||||
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\t\t\t=> mmap anonymous hugepage: [%lx-%lx)\n", hp_start, hp_start + len - mod);
|
||||
+ _dl_debug_printf("\t\t\t=> %s mmap anonymous hugepage: [%lx-%lx)\n", __func__, hp_start, hp_start + len - mod);
|
||||
mapat = __mmap((caddr_t) hp_start, len - mod, prot,
|
||||
MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|(SHFIT_2MB << MAP_HUGE_SHIFT),
|
||||
-1, 0);
|
||||
@@ -221,6 +221,9 @@ _mmap_remain_zero_page(ElfW(Addr) zeropage, ElfW(Addr) zeroend, int prot)
|
||||
|
||||
if (mod > 0)
|
||||
{
|
||||
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
+ _dl_debug_printf("\t\t\t=> %s mmap anonymous tail normal page: [%lx-%lx)\n", __func__,
|
||||
+ hp_start + len - mod, hp_start + len - mod + ALIGN_UP(mod, GLRO(dl_pagesize)));
|
||||
mapat =__mmap((caddr_t)(hp_start + len - mod), mod, prot,
|
||||
MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
|
||||
if (__glibc_unlikely (mapat == MAP_FAILED))
|
||||
@@ -301,7 +304,7 @@ _mmap_segment_memsz(struct link_map *l, const struct loadcmd * c,
|
||||
{
|
||||
*memsz_len = ALIGN_UP(zeroend, GLRO(dl_pagesize)) - zeropage;
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\t\tzero remain page [%lx-%lx)\n", zeropage, zeroend);
|
||||
+ _dl_debug_printf("\t\tmmap remain anonymous page [%lx-%lx)\n", zeropage, ALIGN_UP(zeroend, GLRO(dl_pagesize)));
|
||||
errstring = _mmap_remain_zero_page(zeropage, zeroend, c->prot);
|
||||
}
|
||||
return errstring;
|
||||
@@ -475,8 +478,8 @@ __mmap_segment_normalsz(const struct loadcmd *c, ElfW(Addr) mapstart, int fd,
|
||||
size_t *mapseglen)
|
||||
{
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\tuse normal page mmap segment:[%lx-%lx)\n", mapstart,
|
||||
- mapstart + (c->allocend - c->mapstart));
|
||||
+ _dl_debug_printf("\t\t%s mmap current segment in normal page:[%lx-%lx)\n", __func__, mapstart,
|
||||
+ mapstart + (ALIGN_UP(c->allocend, GLRO(dl_pagesize)) - c->mapstart));
|
||||
|
||||
if (c->mapend > c->mapstart &&
|
||||
(__mmap((void *)mapstart, c->mapend - c->mapstart, c->prot,
|
||||
@@ -515,7 +518,7 @@ __mmap_segment_normalsz(const struct loadcmd *c, ElfW(Addr) mapstart, int fd,
|
||||
}
|
||||
}
|
||||
|
||||
- *mapseglen = c->allocend - c->mapstart;
|
||||
+ *mapseglen = ALIGN_UP(c->allocend, GLRO(dl_pagesize)) - c->mapstart;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -534,15 +537,18 @@ _mmap_segment(struct link_map *l, const struct loadcmd loadcmds[], size_t nloadc
|
||||
const char * errstring = NULL;
|
||||
size_t extra_len, memsz_len = 0;
|
||||
|
||||
- if (!hp_bitmap[((void *)c - (void *)loadcmds) / sizeof(struct loadcmd)]) {
|
||||
- return __mmap_segment_normalsz(c, mapstart, fd, mapseglen);
|
||||
- }
|
||||
-
|
||||
- extra_len = _extra_mmap(l, loadcmds, nloadcmds, c, mapstart);
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\t%s(0x%lx): extra_len = 0x%lx\n\t{\n", __func__,
|
||||
- (unsigned long)c, extra_len);
|
||||
+ _dl_debug_printf("\t%s mmap from %lx: \n\t{\n", __func__, mapstart);
|
||||
|
||||
+ if (!hp_bitmap[((void *)c - (void *)loadcmds) / sizeof(struct loadcmd)])
|
||||
+ {
|
||||
+ errstring = __mmap_segment_normalsz(c, mapstart, fd, mapseglen);
|
||||
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
+ _dl_debug_printf("\t} => mapseglen = 0x%lx\n", *mapseglen);
|
||||
+ return errstring;
|
||||
+ }
|
||||
+
|
||||
+ extra_len = _extra_mmap(l, loadcmds, nloadcmds, c, mapstart);
|
||||
errstring = _mmap_segment_filesz(l, c, mapstart, extra_len, fd);
|
||||
if (__glibc_unlikely (errstring != NULL))
|
||||
return errstring;
|
||||
@@ -552,7 +558,8 @@ _mmap_segment(struct link_map *l, const struct loadcmd loadcmds[], size_t nloadc
|
||||
|
||||
*mapseglen = c->mapend - c->mapstart + extra_len + memsz_len;
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("\t} => mapseglen = 0x%lx, memsz_len = 0x%lx\n", *mapseglen, memsz_len);
|
||||
+ _dl_debug_printf("\t} => mapseglen = 0x%lx, extra_len = 0x%lx, memsz_len = 0x%lx\n",
|
||||
+ *mapseglen, extra_len, memsz_len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -652,7 +659,7 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
if (l->l_map_start > (ElfW(Addr))map_area_start)
|
||||
{
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("__munmap [%lx-%lx)\n", (ElfW(Addr))map_area_start, l->l_map_start);
|
||||
+ _dl_debug_printf("__munmap head reserved area [%lx-%lx)\n", (ElfW(Addr))map_area_start, l->l_map_start);
|
||||
__munmap(map_area_start, l->l_map_start - (ElfW(Addr))map_area_start);
|
||||
}
|
||||
|
||||
@@ -663,7 +670,7 @@ _dl_map_segments_largein (struct link_map *l, int fd,
|
||||
if ((ElfW(Addr))map_area_start + maparealen > l_map_end)
|
||||
{
|
||||
if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
- _dl_debug_printf("__munmap [%lx-%lx)\n", l_map_end, (ElfW(Addr))map_area_start + maparealen);
|
||||
+ _dl_debug_printf("__munmap tail reserved area [%lx-%lx)\n", l_map_end, (ElfW(Addr))map_area_start + maparealen);
|
||||
__munmap((void *)l_map_end, (ElfW(Addr))map_area_start + maparealen - l_map_end);
|
||||
}
|
||||
|
||||
--
|
||||
2.40.0
|
||||
|
||||
|
||||
137
elf-the-hugepage-feature-of-dynamic-library-keep-com.patch
Normal file
137
elf-the-hugepage-feature-of-dynamic-library-keep-com.patch
Normal file
@ -0,0 +1,137 @@
|
||||
From ec9b25736eeff0027ad771fc35b6b97d34064da7 Mon Sep 17 00:00:00 2001
|
||||
From: Lv Ying <lvying6@huawei.com>
|
||||
Date: Mon, 3 Jun 2024 00:46:30 -0400
|
||||
Subject: [PATCH 1/2] elf: the hugepage feature of dynamic library keep
|
||||
compatible with llvm lld
|
||||
|
||||
GNU LD contains RELRO and data, bss in the same PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro) .data .bss),
|
||||
so RELRO filesz == RELRO memsz to avoid _dl_protect_relro modify behind data section to R-ONLY permission.
|
||||
LLVM LLD put RELRO in the sperate PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)); PT_LOAD(.data. .bss), and
|
||||
default RELRO filesz < RELRO memsz, and LLVM can not keep compatible with GNU LD: RELRO filesz == RELRO memsz
|
||||
|
||||
hugepage feature of dynamic library is consistent with the default glibc dynamic library loading process:
|
||||
mmap file first(mmap ELF file, use PT_LOAD's offset), then anonymous map the part of memsz beyond filesz.
|
||||
hugepage feature mmap RELRO file(GNU LD) in 4KB, then try to mmap data and bss part use hugepage.
|
||||
So RELRO filesz < RELRO memsz which will cause wrong relro len caculation.
|
||||
|
||||
Signed-off-by: Lv Ying <lvying6@huawei.com>
|
||||
---
|
||||
elf/dl-load.c | 5 +++
|
||||
elf/dl-map-segments-hugepage.h | 66 ++++++++++++++++++++++++++++++++--
|
||||
2 files changed, 67 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/elf/dl-load.c b/elf/dl-load.c
|
||||
index 0c883cb0..5c63e520 100644
|
||||
--- a/elf/dl-load.c
|
||||
+++ b/elf/dl-load.c
|
||||
@@ -1137,6 +1137,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
||||
#ifdef HUGEPAGE_SHARED_LIB
|
||||
bool use_hugepage = false;
|
||||
char hp_bitmap[l->l_phnum];
|
||||
+ const ElfW(Phdr) *relro_ph = NULL;
|
||||
#endif
|
||||
|
||||
/* The struct is initialized to zero so this is not necessary:
|
||||
@@ -1259,6 +1260,9 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
||||
case PT_GNU_RELRO:
|
||||
l->l_relro_addr = ph->p_vaddr;
|
||||
l->l_relro_size = ph->p_memsz;
|
||||
+#ifdef HUGEPAGE_SHARED_LIB
|
||||
+ relro_ph = ph;
|
||||
+#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1301,6 +1305,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
||||
if ((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_LIB_LARGE_IN_FLAG) ||
|
||||
((GLRO(dl_hugepage_mask) & DL_HUGEPAGE_PROBE_FLAG) && use_hugepage))
|
||||
{
|
||||
+ _llvm_ld_relro_hp_fallback(phdr, relro_ph, l, hp_bitmap);
|
||||
errstring = _dl_map_segments_largein (l, fd, header, type, loadcmds, nloadcmds,
|
||||
maplength, hp_bitmap);
|
||||
if (__glibc_unlikely (errstring != NULL))
|
||||
diff --git a/elf/dl-map-segments-hugepage.h b/elf/dl-map-segments-hugepage.h
|
||||
index 218e93a0..0e043731 100644
|
||||
--- a/elf/dl-map-segments-hugepage.h
|
||||
+++ b/elf/dl-map-segments-hugepage.h
|
||||
@@ -88,14 +88,73 @@ unmap_reserved_area:
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * With traditionad -z nosperate-code, GNU ld defaults to a RX/R/RW program header layout,
|
||||
+ * With -z sperate-code(defallt on Linux/x86 form binutils 2.31 onwards), GNU ld defaults to a R/RX/R/RW program header layout
|
||||
+ *
|
||||
+ * ld.lld defaults to R/RX/RW(RELRO)/RW(non-RELRO), with --rosegment, ld.lld uses RX/RW(RELRO)/RW(non-RELRO)
|
||||
+ * LLVM LLD put RELRO in the sperate PT_LOAD(PT_GNU_RELRO(.data.rel.ro .bss.rel.ro)); PT_LOAD(.data. .bss)
|
||||
+ * LLVM LLD default RELRO filesz < RELRO memsz, and LLVM can not keep compatible with GNU LD: RELRO fiesz == RELRO memsz
|
||||
+ *
|
||||
+ * hugepage feature of dynamic library is consistent with the default glibc dynamic library loading process: mmap file part first, then map anonymous part
|
||||
+ * As GNU LD RELRO fiesz == RELRO memsz, treat RELRO as file part,
|
||||
+ * but RELRO filesz < RELRO memsz which will cause wrong relro len caculation
|
||||
+ * so just mmap LLVM LLD RELRO PT_LOAD as normal page to avoid GNU LD relro len caculation
|
||||
+ */
|
||||
+static __always_inline void
|
||||
+_llvm_ld_relro_hp_fallback(const ElfW(Phdr) *phdr, const ElfW(Phdr) *relro_ph,
|
||||
+ struct link_map *l, char *hp_bitmap)
|
||||
+{
|
||||
+ const ElfW(Phdr) *ph;
|
||||
+ char *hp_loadcmd;
|
||||
+ int i = 0;
|
||||
+
|
||||
+ // all the PT_LOADs do not contain RELRO, do nothing
|
||||
+ if (relro_ph == NULL)
|
||||
+ return;
|
||||
+
|
||||
+ for (ph = phdr, hp_loadcmd = hp_bitmap; ph < &phdr[l->l_phnum]; ++ph)
|
||||
+ if (ph->p_type == PT_LOAD)
|
||||
+ {
|
||||
+ // relro_ph->p_vaddr + relro_ph->p_memsz > ph->p_vaddr + ph->p_memsz
|
||||
+ // --> llvm.ld no padding bits, but will report error in _dl_protect_relro
|
||||
+ if (ph->p_vaddr <= relro_ph->p_vaddr && relro_ph->p_vaddr < ph->p_vaddr + ph->p_memsz &&
|
||||
+ relro_ph->p_filesz < relro_ph->p_memsz)
|
||||
+ {
|
||||
+ if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES))
|
||||
+ _dl_debug_printf("PT_LOAD[%d] contains LLVM LD layout style RELRO, this segment use normal page\n", i);
|
||||
+
|
||||
+ *hp_loadcmd = 0;
|
||||
+ break;
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ hp_loadcmd++;
|
||||
+ i++;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * | other sections | RELRO | non-RELRO |
|
||||
+ * If RELRO is not at the beginning of the RW segment, the beginning position
|
||||
+ * will also be mapped using 4KB page, so count the begining other sections in relro len
|
||||
+ * RELRO is default at the begining position of GNU LD and ld.lld
|
||||
+ * relro_len is GLRO(dl_pagesize) aligned
|
||||
+ */
|
||||
static __always_inline size_t
|
||||
_get_relro_len(struct link_map *l, const struct loadcmd *c)
|
||||
{
|
||||
size_t relro_len = 0;
|
||||
- if (c->mapstart == ALIGN_DOWN (l->l_relro_addr, GLRO(dl_pagesize)))
|
||||
+
|
||||
+ if (l->l_relro_size)
|
||||
{
|
||||
- relro_len = ALIGN_DOWN(l->l_relro_addr + l->l_relro_size, GLRO(dl_pagesize)) -
|
||||
- ALIGN_DOWN(l->l_relro_addr, GLRO(dl_pagesize));
|
||||
+ ElfW(Addr) relro_start = ALIGN_DOWN(l->l_relro_addr, GLRO(dl_pagesize));
|
||||
+ ElfW(Addr) relro_end = ALIGN_DOWN((l->l_relro_addr + l->l_relro_size), GLRO(dl_pagesize));
|
||||
+ if (c->mapstart <= relro_start && relro_start < c->allocend)
|
||||
+ relro_len = relro_end - c->mapstart;
|
||||
}
|
||||
return relro_len;
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
|
||||
26
glibc.spec
26
glibc.spec
@ -71,7 +71,7 @@
|
||||
##############################################################################
|
||||
Name: glibc
|
||||
Version: 2.34
|
||||
Release: 156
|
||||
Release: 157
|
||||
Summary: The GNU libc libraries
|
||||
License: %{all_license}
|
||||
URL: http://www.gnu.org/software/glibc/
|
||||
@ -327,7 +327,6 @@ Patch9015: use-region-to-instead-of-country-for-extract-timezon.patch
|
||||
Patch9016: strcmp-delete-align-for-loop_aligned.patch
|
||||
Patch9017: 0001-elf-dynamic-linker-load-shared-object-use-hugepage-a.patch
|
||||
Patch9018: 0002-elf-ld.so-add-testcase-for-ld.so-load-shared-object-.patch
|
||||
Patch9019: 0003-elf-ld.so-use-special-mmap-for-hugepage-to-get-symbo.patch
|
||||
Patch9020: malloc-use-__get_nprocs-replace-__get_nprocs_sched.patch
|
||||
Patch9021: x86-use-total-l3cache-for-non_temporal_threshold.patch
|
||||
Patch9022: login-Add-back-libutil-as-an-empty-library.patch
|
||||
@ -358,6 +357,9 @@ Patch9046: fix_nss_database_check_reload_and_get_memleak.patch
|
||||
Patch9047: inet-fix-warn-unused-result.patch
|
||||
Patch9048: LoongArch-Add-missing-relocation-type-in-elf.h.patch
|
||||
Patch9049: Check-the-validity-of-len-before-mmap.patch
|
||||
Patch9050: change-hugepageedit-from-dynamic-link-to-static-link.patch
|
||||
Patch9051: elf-the-hugepage-feature-of-dynamic-library-keep-com.patch
|
||||
Patch9052: elf-add-some-debug-info-for-dynamic-library-hugepage.patch
|
||||
|
||||
Provides: ldconfig rtld(GNU_HASH) bundled(gnulib)
|
||||
|
||||
@ -695,6 +697,9 @@ mkdir $builddir
|
||||
pushd $builddir
|
||||
../configure CC="%GCC" CXX="%GXX" CFLAGS="$BuildFlags" \
|
||||
--prefix=%{_prefix} \
|
||||
%ifarch aarch64
|
||||
--enable-hugepage-shared-library \
|
||||
%endif
|
||||
--with-headers=%{_prefix}/include $EnableKernel \
|
||||
--with-nonshared-cflags=-Wp,-D_FORTIFY_SOURCE=2 \
|
||||
--enable-bind-now \
|
||||
@ -1010,7 +1015,11 @@ echo '%{_libdir}/libpcprofile.so' >> glibc.filelist
|
||||
##############################################################################
|
||||
# glibc "common" sub-package
|
||||
##############################################################################
|
||||
%ifarch aarch64
|
||||
grep '%{_prefix}/bin' master.filelist | grep -v 'hugepageedit' > common.filelist
|
||||
%else
|
||||
grep '%{_prefix}/bin' master.filelist > common.filelist
|
||||
%endif
|
||||
grep '%{_prefix}/sbin' master.filelist \
|
||||
| grep -v '%{_prefix}/sbin/iconvconfig' \
|
||||
| grep -v 'nscd' >> common.filelist
|
||||
@ -1473,6 +1482,9 @@ fi
|
||||
%attr(0644,root,root) %{_prefix}/lib/locale/locale-archive.update
|
||||
|
||||
%files -f devel.filelist devel
|
||||
%ifarch aarch64
|
||||
%attr(500,root,root) %{_prefix}/bin/hugepageedit
|
||||
%endif
|
||||
|
||||
%files -f nscd.filelist -n nscd
|
||||
%config(noreplace) /etc/nscd.conf
|
||||
@ -1523,6 +1535,16 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Aug 20 2024 shixuantong <shixuantong1@huawei.com> - 2.34-157
|
||||
- Type:bugfix
|
||||
- ID:
|
||||
- SUG:NA
|
||||
- DESC:enable shared library use huge page for aarch64 architecture
|
||||
revert "elf/ld.so: use special mmap for hugepage to get symbols"
|
||||
hugepageedit: static-link build
|
||||
elf: the hugepage feature of dynamic library keep compatible with llvm lld
|
||||
elf: add some debug info for dynamic library hugepage feature
|
||||
|
||||
* Sat Aug 03 2024 Funda Wang <fundawang@yeah.net> - 2.34-156
|
||||
- Type:bugfix
|
||||
- ID:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user