diff --git a/dependency/masstree/0002-add-support-for-riscv64.patch b/dependency/masstree/0002-add-support-for-riscv64.patch new file mode 100644 index 0000000000000000000000000000000000000000..911d2cfc49d432b086e82e014fcfb69a4defafb7 --- /dev/null +++ b/dependency/masstree/0002-add-support-for-riscv64.patch @@ -0,0 +1,54 @@ +From ea5237f9124cec1ccf4175647c7475f3b5b1dd0a Mon Sep 17 00:00:00 2001 +From: huangji +Date: Sat, 18 Jan 2025 17:27:44 +0000 +Subject: [PATCH 1/2] add support for riscv64 + +Signed-off-by: huangji +--- + Makefile | 2 ++ + compiler.hh | 2 +- + string.cpp | 2 +- + 3 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/Makefile b/Makefile +index f47c8a2..923892b 100644 +--- a/Makefile ++++ b/Makefile +@@ -18,6 +18,8 @@ CXXFLAGS = -g -W -O3 -std=gnu++11 -Wextra -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -W + + ifeq ($(shell uname -p),aarch64) + CXXFLAGS += -march=armv8-a+crc ++else ifeq ($(shell uname -p),riscv64) ++ CXXFLAGS += -march=rv64gc + else + CXXFLAGS += -mcx16 + endif +diff --git a/compiler.hh b/compiler.hh +index 10fbd86..f7a5293 100644 +--- a/compiler.hh ++++ b/compiler.hh +@@ -55,7 +55,7 @@ + #define PREFER_X86 1 + #define ALLOW___SYNC_BUILTINS 1 + +-#if !defined(HAVE_INDIFFERENT_ALIGMENT) && (__i386__ || __x86_64__ || __arch_um__) ++#if !defined(HAVE_INDIFFERENT_ALIGMENT) && (__i386__ || __x86_64__ || __arch_um__ || __riscv) + # define HAVE_INDIFFERENT_ALIGNMENT 1 + #endif + +diff --git a/string.cpp b/string.cpp +index 1ddaf58..8f56b2d 100644 +--- a/string.cpp ++++ b/string.cpp +@@ -282,7 +282,7 @@ String_generic::hashcode(const char *s, int len) + #undef get16 + #if !HAVE_INDIFFERENT_ALIGNMENT + } else { +-# if !__i386__ && !__x86_64__ && !__arch_um__ ++# if !__i386__ && !__x86_64__ && !__arch_um__ && !__riscv + # define get16(p) (((unsigned char) (p)[0] << 8) + (unsigned char) (p)[1]) + # else + # define get16(p) ((unsigned char) (p)[0] + ((unsigned char) (p)[1] << 8)) +-- +2.33.0 + diff --git a/dependency/masstree/0003-fix-gcc-build-error.patch b/dependency/masstree/0003-fix-gcc-build-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..20f49a158ce4fafdeaef388d0f9d92fbdf4f5aa1 --- /dev/null +++ b/dependency/masstree/0003-fix-gcc-build-error.patch @@ -0,0 +1,53 @@ +From 0f53d73bfac34d2092dfc3859f1f2d7307256a4c Mon Sep 17 00:00:00 2001 +From: huangji +Date: Sat, 18 Jan 2025 17:36:11 +0000 +Subject: [PATCH 2/2] fix gcc build error + +Signed-off-by: huangji +--- + Makefile | 2 +- + string_base.hh | 8 ++++++++ + 2 files changed, 9 insertions(+), 1 deletion(-) + +diff --git a/Makefile b/Makefile +index 923892b..786df2f 100644 +--- a/Makefile ++++ b/Makefile +@@ -19,7 +19,7 @@ CXXFLAGS = -g -W -O3 -std=gnu++11 -Wextra -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC -g -W + ifeq ($(shell uname -p),aarch64) + CXXFLAGS += -march=armv8-a+crc + else ifeq ($(shell uname -p),riscv64) +- CXXFLAGS += -march=rv64gc ++ CXXFLAGS += -march=rv64gc -mno-strict-align + else + CXXFLAGS += -mcx16 + endif +diff --git a/string_base.hh b/string_base.hh +index adcd717..601cc2d 100644 +--- a/string_base.hh ++++ b/string_base.hh +@@ -513,6 +513,7 @@ inline typename T::substring_type String_generic::trim(const T &str) { + } + + #if HAVE_STD_HASH ++#if __GNUC__ <= 10 + # define LCDF_MAKE_STRING_HASH(type) \ + namespace std { template <> struct hash \ + : public unary_function { \ +@@ -520,6 +521,13 @@ inline typename T::substring_type String_generic::trim(const T &str) { + return x.hashcode(); \ + } }; } + #else ++# define LCDF_MAKE_STRING_HASH(type) \ ++ namespace std { template <> struct hash { \ ++ size_t operator()(const type& x) const noexcept { \ ++ return x.hashcode(); \ ++ } }; } ++#endif ++#else + # define LCDF_MAKE_STRING_HASH(type) + #endif + +-- +2.33.0 + diff --git a/dependency/masstree/build.sh b/dependency/masstree/build.sh index 2459377750e4512575fd51ccb2d7b6a36538adaf..eef99cd06d6ba86600548b874804fc7a5b998c26 100644 --- a/dependency/masstree/build.sh +++ b/dependency/masstree/build.sh @@ -25,6 +25,8 @@ tar -zxf $MASSTREE_PACKAGE -C $MASSTREE_MEGRED_SOURCES_DIR --strip-components 1 cd $MASSTREE_MEGRED_SOURCES_DIR patch -p1 < ../0001-Masstree-v1.0.1-MOT.patch +patch -p1 < ../0002-add-support-for-riscv64.patch +patch -p1 < ../0003-fix-gcc-build-error.patch sed -i "s/LDFLAGS =/LDFLAGS = -fstack-protector-all -z,now/g" Makefile sed -i "s/\$(CXX) -shared/\$(CXX) -fstack-protector-all -Wl,-z,relro,-z,now -shared/g" Makefile