Compare commits
10 Commits
15cdcd3453
...
66e1b44474
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66e1b44474 | ||
|
|
105c4f6580 | ||
|
|
7018c24462 | ||
|
|
64656eb354 | ||
|
|
c2856ca815 | ||
|
|
86373b1822 | ||
|
|
9897505f8b | ||
|
|
7f25904f2e | ||
|
|
574617b890 | ||
|
|
4b2f1f5aaf |
@ -0,0 +1,27 @@
|
||||
From 135a062d6eda37ac56eb00e3dd11de7e241d619b Mon Sep 17 00:00:00 2001
|
||||
From: wangqiang <wangqiang1@kylinos.cn>
|
||||
Date: Fri, 27 Sep 2024 15:21:19 +0800
|
||||
Subject: [PATCH] Add support for loongarch64 architecture in ld.hugetlbfs
|
||||
|
||||
- Added alignment configuration for loongarch64 architecture in the `ld.hugetlbfs` script.
|
||||
- Set `HPAGE_SIZE` to 32MB and `SLICE_SIZE` to match `HPAGE_SIZE` for loongarch64.
|
||||
- This ensures correct alignment and hugepage usage for binaries targeting loongarch64 systems.
|
||||
|
||||
Fix: https://github.com/libhugetlbfs/libhugetlbfs/issues/91
|
||||
Referenc: https://github.com/llvm/llvm-project/blob/main/lld/ELF/Driver.cpp#L217
|
||||
---
|
||||
ld.hugetlbfs | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/ld.hugetlbfs b/ld.hugetlbfs
|
||||
index 5e4e4974..1028d8e2 100755
|
||||
--- a/ld.hugetlbfs
|
||||
+++ b/ld.hugetlbfs
|
||||
@@ -117,6 +117,7 @@ elf64ppc|elf64lppc)
|
||||
fi ;;
|
||||
elf_i386|elf_x86_64) HPAGE_SIZE=$((4*$MB)) SLICE_SIZE=$HPAGE_SIZE ;;
|
||||
elf_s390|elf64_s390) HPAGE_SIZE=$((1*$MB)) SLICE_SIZE=$HPAGE_SIZE ;;
|
||||
+elf64loongarch) HPAGE_SIZE=$((32*$MB)) SLICE_SIZE=$HPAGE_SIZE ;;
|
||||
armelf*_linux_eabi|aarch64elf*|aarch64linux*|sw_64elf*|sw_64linux*)
|
||||
hpage_kb=$(cat /proc/meminfo | grep Hugepagesize: | awk '{print $2}')
|
||||
HPAGE_SIZE=$((hpage_kb * 1024))
|
||||
65
add-loongarch-support.patch
Normal file
65
add-loongarch-support.patch
Normal file
@ -0,0 +1,65 @@
|
||||
diff --git a/Makefile b/Makefile
|
||||
index 6ab7ae2..7c0ca79 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -123,6 +123,12 @@ ELF64 = elf_riscv64
|
||||
TMPLIB64 = lib64
|
||||
CUSTOM_LDSCRIPTS = no
|
||||
else
|
||||
+ifeq ($(ARCH),loongarch64)
|
||||
+CC64 = $(CC)
|
||||
+ELF64 = elf_loongarch
|
||||
+TMPLIB64 = lib64
|
||||
+CUSTOM_LDSCRIPTS = no
|
||||
+else
|
||||
$(error "Unrecognized architecture ($(ARCH))")
|
||||
endif
|
||||
endif
|
||||
@@ -137,6 +143,7 @@ endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
+endif
|
||||
|
||||
ifdef CC32
|
||||
OBJDIRS += obj32
|
||||
diff --git a/sys-elf_loongarch.S b/sys-elf_loongarch.S
|
||||
new file mode 100644
|
||||
index 0000000..47fde55
|
||||
--- /dev/null
|
||||
+++ b/sys-elf_loongarch.S
|
||||
@@ -0,0 +1,20 @@
|
||||
+/*
|
||||
+ * libhugetlbfs - direct system call for LoongArch
|
||||
+ *
|
||||
+ * Author(s): Wenlong Zhang
|
||||
+ */
|
||||
+ .text
|
||||
+
|
||||
+ .globl direct_syscall
|
||||
+direct_syscall:
|
||||
+ move $a7, $a0
|
||||
+ move $a0, $a1
|
||||
+ move $a1, $a2
|
||||
+ move $a2, $a3
|
||||
+ move $a3, $a4
|
||||
+ syscall 0
|
||||
+ jr $ra
|
||||
+
|
||||
+#if defined(__linux__) && defined(__ELF__)
|
||||
+ .section .note.GNU-stack,"",%progbits
|
||||
+#endif
|
||||
diff --git a/tests/icache-hygiene.c b/tests/icache-hygiene.c
|
||||
index 5b4b8db..98522bb 100644
|
||||
--- a/tests/icache-hygiene.c
|
||||
+++ b/tests/icache-hygiene.c
|
||||
@@ -88,7 +88,8 @@ static void sig_handler(int signum, siginfo_t *si, void *uc)
|
||||
{
|
||||
#if defined(__powerpc__) || defined(__powerpc64__) || defined(__ia64__) || \
|
||||
defined(__s390__) || defined(__s390x__) || defined(__sparc__) || \
|
||||
- defined(__aarch64__) || defined(__sw_64__) || (defined(__riscv) && __riscv_xlen == 64)
|
||||
+ defined(__aarch64__) || defined(__sw_64__) || (defined(__riscv) && __riscv_xlen == 64) || \
|
||||
+ defined(__loongarch__)
|
||||
/* On powerpc, ia64, s390 and Aarch64, 0 bytes are an illegal
|
||||
* instruction, so, if the icache is cleared properly, we SIGILL
|
||||
* as soon as we jump into the cleared page */
|
||||
@ -1,42 +0,0 @@
|
||||
diff -Naur libhugetlbfs-2.16/elflink.c libhugetlbfs-2.16.new//elflink.c
|
||||
--- libhugetlbfs-2.16/elflink.c 2017-11-09 20:30:38.000000000 -0500
|
||||
+++ libhugetlbfs-2.16.new//elflink.c 2017-11-09 22:36:56.000000000 -0500
|
||||
@@ -1131,7 +1131,10 @@
|
||||
start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size);
|
||||
offset = (unsigned long)(seg[i].vaddr - start);
|
||||
mapsize = ALIGN(offset + seg[i].memsz, hpage_size);
|
||||
- mmap_flags = MAP_SHARED|MAP_FIXED;
|
||||
+ if(__hugetlb_opts.share_mapping)
|
||||
+ mmap_flags = MAP_SHARED|MAP_FIXED;
|
||||
+ else
|
||||
+ mmap_flags = MAP_PRIVATE|MAP_FIXED;
|
||||
|
||||
/* If requested, make no reservations */
|
||||
if (__hugetlb_opts.no_reserve)
|
||||
diff -Naur libhugetlbfs-2.16/hugeutils.c libhugetlbfs-2.16.new//hugeutils.c
|
||||
--- libhugetlbfs-2.16/hugeutils.c 2013-03-09 21:59:52.000000000 -0500
|
||||
+++ libhugetlbfs-2.16.new//hugeutils.c 2017-11-09 22:36:45.000000000 -0500
|
||||
@@ -387,6 +387,12 @@
|
||||
env = getenv("HUGETLB_NO_RESERVE");
|
||||
if (env && !strcasecmp(env, "yes"))
|
||||
__hugetlb_opts.no_reserve = true;
|
||||
+
|
||||
+ /* Determine if data segment share memory mapping */
|
||||
+ __hugetlb_opts.share_mapping = false;
|
||||
+ env = getenv("HUGETLB_SHAREMAPPING");
|
||||
+ if (env && !strcasecmp(env, "yes"))
|
||||
+ __hugetlb_opts.share_mapping = true;
|
||||
}
|
||||
|
||||
void hugetlbfs_setup_kernel_page_size()
|
||||
diff -Naur libhugetlbfs-2.16/libhugetlbfs_internal.h libhugetlbfs-2.16.new//libhugetlbfs_internal.h
|
||||
--- libhugetlbfs-2.16/libhugetlbfs_internal.h 2013-03-09 21:59:52.000000000 -0500
|
||||
+++ libhugetlbfs-2.16.new//libhugetlbfs_internal.h 2017-11-09 22:35:53.000000000 -0500
|
||||
@@ -73,6 +73,7 @@
|
||||
char *def_page_size;
|
||||
char *morecore;
|
||||
char *heapbase;
|
||||
+ bool share_mapping;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -1,31 +0,0 @@
|
||||
From 7c371e7de53554166711e0bcc37df94d0a78edd3 Mon Sep 17 00:00:00 2001
|
||||
From: sangyan <sangyan@huawei.com>
|
||||
Date: Fri, 21 Apr 2017 14:35:03 +0800
|
||||
Subject: [PATCH] elflink.c: remap segments with MAP_SHARED flag
|
||||
|
||||
Mmapping segment with MAP_PRIVATE will create a private
|
||||
copy-on-write mapping, as a result updates to the mapping
|
||||
will cost extra pages. It will cost double number of pages
|
||||
in the worst case, so we change to MAP_SHARED flag.
|
||||
|
||||
It is also safe to mmap a unlinked file or a read-only file.
|
||||
---
|
||||
elflink.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/elflink.c b/elflink.c
|
||||
index b746b26..8187ee0 100644
|
||||
--- a/elflink.c
|
||||
+++ b/elflink.c
|
||||
@@ -1131,7 +1131,7 @@ static void remap_segments(struct seg_info *seg, int num)
|
||||
start = ALIGN_DOWN((unsigned long)seg[i].vaddr, hpage_size);
|
||||
offset = (unsigned long)(seg[i].vaddr - start);
|
||||
mapsize = ALIGN(offset + seg[i].memsz, hpage_size);
|
||||
- mmap_flags = MAP_PRIVATE|MAP_FIXED;
|
||||
+ mmap_flags = MAP_SHARED|MAP_FIXED;
|
||||
|
||||
/* If requested, make no reservations */
|
||||
if (__hugetlb_opts.no_reserve)
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
26
libhugetlbfs-sw_64-package-library-files-to-usr-lib64.patch
Normal file
26
libhugetlbfs-sw_64-package-library-files-to-usr-lib64.patch
Normal file
@ -0,0 +1,26 @@
|
||||
From 107e7cab6824ed78f6cb62c9b44d6ab466a26eba Mon Sep 17 00:00:00 2001
|
||||
From: yueyuankun <yueyuankun@kylinos.cn>
|
||||
Date: Wed, 19 Mar 2025 20:05:58 +0800
|
||||
Subject: [PATCH] sw_64: package library files to /usr/lib64, consistent with
|
||||
libdir macros
|
||||
|
||||
---
|
||||
Makefile.in | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Makefile b/Makefile
|
||||
index 7c0ca79..f63ef04 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -66,7 +66,7 @@ else
|
||||
ifneq (,$(findstring sw_64,$(ARCH)))
|
||||
CC64 = $(CC)
|
||||
ELF64 = sw_64elf
|
||||
-TMPLIB64 = lib
|
||||
+TMPLIB64 = lib64
|
||||
CUSTOM_LDSCRIPTS = no
|
||||
else
|
||||
ifneq (,$(findstring aarch64,$(ARCH)))
|
||||
--
|
||||
2.43.0
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
Name: libhugetlbfs
|
||||
Version: 2.23
|
||||
Release: 2
|
||||
Release: 7
|
||||
Summary: A library which provides easy access to huge pages of memory
|
||||
License: LGPLv2+
|
||||
URL: https://github.com/libhugetlbfs/libhugetlbfs
|
||||
@ -11,11 +11,12 @@ Source0: https://github.com/libhugetlbfs/libhugetlbfs/releases/download/%{versi
|
||||
Patch0: 0000-build_flags.patch
|
||||
Patch1: Disable-hugepage-backed-malloc-if-__morecore-is-not-.patch
|
||||
Patch2: libhugetlbfs-2.23-sw.patch
|
||||
Patch3: add-loongarch-support.patch
|
||||
Patch4: Add-support-for-loongarch64-architecture-in-ld.hugetlbfs.patch
|
||||
Patch5: libhugetlbfs-sw_64-package-library-files-to-usr-lib64.patch
|
||||
|
||||
#Patch9000:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED.patch
|
||||
#Patch9001:libhugetlbfs-2.16-remap_segments_with_MAP_SHARED-2.patch
|
||||
Patch9002:libhugetlbfs-make-cflags.patch
|
||||
#Patch9003:libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch
|
||||
Patch9001:libhugetlbfs-make-cflags.patch
|
||||
Patch9002:libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch
|
||||
|
||||
BuildRequires: gcc glibc-devel glibc-static
|
||||
|
||||
@ -59,9 +60,9 @@ touch $RPM_BUILD_ROOT%{_sysconfdir}/security/limits.d/hugepages.conf
|
||||
%files
|
||||
%license LGPL-2.1
|
||||
%{_libdir}/libhugetlbfs.so*
|
||||
%{_libdir}/libhugetlbfs_privutils.so*
|
||||
%{_datadir}/%{name}/
|
||||
%ghost %config(noreplace) %{_sysconfdir}/security/limits.d/hugepages.conf
|
||||
%exclude %{_libdir}/libhugetlbfs_privutils.so
|
||||
%exclude %{_libdir}/*.a
|
||||
|
||||
%files devel
|
||||
@ -87,6 +88,21 @@ touch $RPM_BUILD_ROOT%{_sysconfdir}/security/limits.d/hugepages.conf
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Mar 19 2025 yueyuankun <yueyuankun@kylinos.cn> - 2.23-7
|
||||
- sw_64: move library files to /usr/lib64, consistent with libdir macros
|
||||
|
||||
* Tue Oct 29 2024 wangqiang <wangqiang1@kylinos.cn> - 2.23-6
|
||||
- Add support for loongarch64 architecture in ld.hugetlbfs
|
||||
|
||||
* Fri Sep 27 2024 wangqiang <wangqiang1@kylinos.cn> - 2.23-5
|
||||
- Re-enable patch libhugetlbfs-fix-max-segment-cannot-adopt-the-x86.patch
|
||||
|
||||
* Mon May 6 2024 yueyaoqiang <yueyaoqiang@kylinos.cn> - 2.23-4
|
||||
- add libhugetlbfs_privutils.so for libhugetlbfs test
|
||||
|
||||
* Fri Dec 2 2022 huajingyun<huajingyun@loongson.cn> - 2.23-3
|
||||
- add loongarch support
|
||||
|
||||
* Fri Oct 21 2022 wuzx<wuzx1226@qq.com> - 2.23-2
|
||||
- add sw64 patch
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user