已开启
提供masstree在riscv64平台上的适配 #313
提供masstree在riscv64平台上的适配 #313
已开启
MengMengDeXiaoJi创建于 2025年5月8日
3 个文件变更+109-0
@@ -0,0 +1,54 @@
1+From ea5237f9124cec1ccf4175647c7475f3b5b1dd0a Mon Sep 17 00:00:00 2001
2+From: huangji <huangji@iscas.ac.cn>
3+Date: Sat, 18 Jan 2025 17:27:44 +0000
4+Subject: [PATCH 1/2] add support for riscv64
5+ 
6+Signed-off-by: huangji <huangji@iscas.ac.cn>
7+---
8+ Makefile | 2 ++
9+ compiler.hh | 2 +-
10+ string.cpp | 2 +-
11+ 3 files changed, 4 insertions(+), 2 deletions(-)
12+ 
13+diff --git a/Makefile b/Makefile
14+index f47c8a2..923892b 100644
15+--- a/Makefile
16++++ b/Makefile
17+@@ -18,6 +18,8 @@ CXXFLAGS = -g -W -O3 -std=gnu++11 -Wextra -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -W
18+
19+ ifeq ($(shell uname -p),aarch64)
20+ CXXFLAGS += -march=armv8-a+crc
21++else ifeq ($(shell uname -p),riscv64)
22++ CXXFLAGS += -march=rv64gc
23+ else
24+ CXXFLAGS += -mcx16
25+ endif
26+diff --git a/compiler.hh b/compiler.hh
27+index 10fbd86..f7a5293 100644
28+--- a/compiler.hh
29++++ b/compiler.hh
30+@@ -55,7 +55,7 @@
31+ #define PREFER_X86 1
32+ #define ALLOW___SYNC_BUILTINS 1
33+
34+-#if !defined(HAVE_INDIFFERENT_ALIGMENT) && (__i386__ || __x86_64__ || __arch_um__)
35++#if !defined(HAVE_INDIFFERENT_ALIGMENT) && (__i386__ || __x86_64__ || __arch_um__ || __riscv)
36+ # define HAVE_INDIFFERENT_ALIGNMENT 1
37+ #endif
38+
39+diff --git a/string.cpp b/string.cpp
40+index 1ddaf58..8f56b2d 100644
41+--- a/string.cpp
42++++ b/string.cpp
43+@@ -282,7 +282,7 @@ String_generic::hashcode(const char *s, int len)
44+ #undef get16
45+ #if !HAVE_INDIFFERENT_ALIGNMENT
46+ } else {
47+-# if !__i386__ && !__x86_64__ && !__arch_um__
48++# if !__i386__ && !__x86_64__ && !__arch_um__ && !__riscv
49+ # define get16(p) (((unsigned char) (p)[0] << 8) + (unsigned char) (p)[1])
50+ # else
51+ # define get16(p) ((unsigned char) (p)[0] + ((unsigned char) (p)[1] << 8))
52+--
53+2.33.0
54+ 
@@ -0,0 +1,53 @@
1+From 0f53d73bfac34d2092dfc3859f1f2d7307256a4c Mon Sep 17 00:00:00 2001
2+From: huangji <huangji@iscas.ac.cn>
3+Date: Sat, 18 Jan 2025 17:36:11 +0000
4+Subject: [PATCH 2/2] fix gcc build error
5+ 
6+Signed-off-by: huangji <huangji@iscas.ac.cn>
7+---
8+ Makefile | 2 +-
9+ string_base.hh | 8 ++++++++
10+ 2 files changed, 9 insertions(+), 1 deletion(-)
11+ 
12+diff --git a/Makefile b/Makefile
13+index 923892b..786df2f 100644
14+--- a/Makefile
15++++ b/Makefile
16+@@ -19,7 +19,7 @@ CXXFLAGS = -g -W -O3 -std=gnu++11 -Wextra -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -W
17+ ifeq ($(shell uname -p),aarch64)
18+ CXXFLAGS += -march=armv8-a+crc
19+ else ifeq ($(shell uname -p),riscv64)
20+- CXXFLAGS += -march=rv64gc
21++ CXXFLAGS += -march=rv64gc -mno-strict-align
22+ else
23+ CXXFLAGS += -mcx16
24+ endif
25+diff --git a/string_base.hh b/string_base.hh
26+index adcd717..601cc2d 100644
27+--- a/string_base.hh
28++++ b/string_base.hh
29+@@ -513,6 +513,7 @@ inline typename T::substring_type String_generic::trim(const T &str) {
30+ }
31+
32+ #if HAVE_STD_HASH
33++#if __GNUC__ <= 10
34+ # define LCDF_MAKE_STRING_HASH(type) \
35+ namespace std { template <> struct hash<type> \
36+ : public unary_function<const type&, size_t> { \
37+@@ -520,6 +521,13 @@ inline typename T::substring_type String_generic::trim(const T &str) {
38+ return x.hashcode(); \
39+ } }; }
40+ #else
41++# define LCDF_MAKE_STRING_HASH(type) \
42++ namespace std { template <> struct hash<type> { \
43++ size_t operator()(const type& x) const noexcept { \
44++ return x.hashcode(); \
45++ } }; }
46++#endif
47++#else
48+ # define LCDF_MAKE_STRING_HASH(type)
49+ #endif
50+
51+--
52+2.33.0
53+ 
@@ -25,6 +25,8 @@ tar -zxf $MASSTREE_PACKAGE -C $MASSTREE_MEGRED_SOURCES_DIR --strip-components 1
25 25 
26cd $MASSTREE_MEGRED_SOURCES_DIR26cd $MASSTREE_MEGRED_SOURCES_DIR
27patch -p1 < ../0001-Masstree-v1.0.1-MOT.patch27patch -p1 < ../0001-Masstree-v1.0.1-MOT.patch
28+patch -p1 < ../0002-add-support-for-riscv64.patch
29+patch -p1 < ../0003-fix-gcc-build-error.patch
28sed -i "s/LDFLAGS =/LDFLAGS = -fstack-protector-all -z,now/g" Makefile30sed -i "s/LDFLAGS =/LDFLAGS = -fstack-protector-all -z,now/g" Makefile
29sed -i "s/\$(CXX) -shared/\$(CXX) -fstack-protector-all -Wl,-z,relro,-z,now -shared/g" Makefile31sed -i "s/\$(CXX) -shared/\$(CXX) -fstack-protector-all -Wl,-z,relro,-z,now -shared/g" Makefile
30 32