Open
Fix riscv64 error #33
AtomGit-BotAdd on Sep 30, 2024
Fix riscv64 error #33
Open
AtomGit-BotAdd on Sep 30, 2024
Merged fromrefs/pull/33/headintomaster
Total: 4 files changed+104-2
@@ -0,0 +1,13 @@
1+--- a/distdir_deps.bzl 2024-07-09 14:42:34.465863400 +0800
2++++ b/distdir_deps.bzl 2024-07-09 15:18:31.432886425 +0800
3+@@ -163,6 +163,10 @@
4+ },
5+ "com_google_absl": {
6+ "archive": "20211102.0.tar.gz",
7++ "patch_args": ["-p1"],
8++ "patches": [
9++ "//third_party:abseil-cpp/abseil-cpp-riscv.patch",
10++ ],
11+ "sha256": "dcf71b9cba8dc0ca9940c4b316a0c796be8fab42b070bb6b7cab62b48f0e66c4",
12+ "urls": [
13+ "https://mirror.bazel.build/github.com/abseil/abseil-cpp/archive/refs/tags/20211102.0.tar.gz",
@@ -0,0 +1,3 @@
1+<constraints>
2+ <sandbox>chroot</sandbox>
3+</constraints>
@@ -0,0 +1,76 @@
1+From 7335a36d0b5c1c597566f9aa3f458a5b6817c3b4 Mon Sep 17 00:00:00 2001
2+From: aurel32 <aurelien@aurel32.net>
3+Date: Fri, 22 Mar 2024 14:21:13 -0700
4+Subject: [PATCH] PR #1644: unscaledcycleclock: remove RISC-V support
5+ 
6+Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1644
7+ 
8+Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on RISC-V and can't be used directly from userland. There is a sysctl option to change that as a transition period, but it will eventually disappear.
9+ 
10+The RDTIME instruction is another less accurate alternative, however its frequency varies from board to board, and there is currently now way to get its frequency from userland [2].
11+ 
12+Therefore this patch just removes the code for unscaledcycleclock on RISC-V. Without processor specific implementation, abseil relies on std::chrono::steady_clock::now().time_since_epoch() which is basically a wrapper around clock_gettime (CLOCK_MONOTONIC), which in turns use __vdso_clock_gettime(). On RISC-V this VDSO is just a wrapper around RDTIME correctly scaled to use nanoseconds units.
13+ 
14+This fixes the testsuite on riscv64, tested on a VisionFive 2 board.
15+ 
16+[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3
17+[2] https://github.com/abseil/abseil-cpp/pull/1631
18+Merge 43356a2548cfde76e164d446cb69004b488c6a71 into 76f8011beabdaee872b5fde7546e02407b220cb1
19+ 
20+Merging this change closes #1644
21+ 
22+COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1644 from aurel32:rv64-no-unscaledcycleclock 43356a2548cfde76e164d446cb69004b488c6a71
23+PiperOrigin-RevId: 618286262
24+Change-Id: Ie4120a727e7d0bb185df6e06ea145c780ebe6652
25+---
26+ absl/base/internal/unscaledcycleclock.cc | 12 ------------
27+ absl/base/internal/unscaledcycleclock.h | 8 ++++----
28+ 2 files changed, 4 insertions(+), 16 deletions(-)
29+ 
30+diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc
31+index 05e0e7ba..a0bf3a65 100644
32+--- a/absl/base/internal/unscaledcycleclock.cc
33++++ b/absl/base/internal/unscaledcycleclock.cc
34+@@ -121,18 +121,6 @@ double UnscaledCycleClock::Frequency() {
35+ return aarch64_timer_frequency;
36+ }
37+
38+-#elif defined(__riscv)
39+-
40+-int64_t UnscaledCycleClock::Now() {
41+- int64_t virtual_timer_value;
42+- asm volatile("rdcycle %0" : "=r"(virtual_timer_value));
43+- return virtual_timer_value;
44+-}
45+-
46+-double UnscaledCycleClock::Frequency() {
47+- return base_internal::NominalCPUFrequency();
48+-}
49+-
50+ #elif defined(_M_IX86) || defined(_M_X64)
51+
52+ #pragma intrinsic(__rdtsc)
53+diff --git a/absl/base/internal/unscaledcycleclock.h b/absl/base/internal/unscaledcycleclock.h
54+index 24b324ac..43a3dabe 100644
55+--- a/absl/base/internal/unscaledcycleclock.h
56++++ b/absl/base/internal/unscaledcycleclock.h
57+@@ -46,7 +46,7 @@
58+
59+ // The following platforms have an implementation of a hardware counter.
60+ #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
61+- defined(__powerpc__) || defined(__ppc__) || defined(__riscv) || \
62++ defined(__powerpc__) || defined(__ppc__) || \
63+ defined(_M_IX86) || defined(_M_X64)
64+ #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1
65+ #else
66+@@ -80,7 +80,7 @@
67+
68+ // This macro can be used to test if UnscaledCycleClock::Frequency()
69+ // is NominalCPUFrequency() on a particular platform.
70+-#if (defined(__i386__) || defined(__x86_64__) || defined(__riscv) || \
71++#if (defined(__i386__) || defined(__x86_64__) || \
72+ defined(_M_IX86) || defined(_M_X64))
73+ #define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY
74+ #endif
75+--
76+2.39.2
@@ -2,15 +2,17 @@
2 2 
3Name: bazel3Name: bazel
4Version: 5.3.04Version: 5.3.0
5-Release: 15+Release: 2
6Summary: Correct, reproducible, and fast builds for everyone.6Summary: Correct, reproducible, and fast builds for everyone.
7License: Apache License 2.07License: Apache License 2.0
8URL: http://bazel.io/8URL: http://bazel.io/
9Source0: https://github.com/bazelbuild/bazel/releases/download/%{version}/bazel-%{version}-dist.zip9Source0: https://github.com/bazelbuild/bazel/releases/download/%{version}/bazel-%{version}-dist.zip
10+Source1: abseil-cpp-riscv.patch
10Patch0: 01-fix-invalid-jni_md-select.patch11Patch0: 01-fix-invalid-jni_md-select.patch
11Patch1: 02-use-riscv64-jdk.patch12Patch1: 02-use-riscv64-jdk.patch
12Patch2: 03-set-default-nojdk.patch13Patch2: 03-set-default-nojdk.patch
13Patch3: linux-bazel-path-from-getauxval.patch14Patch3: linux-bazel-path-from-getauxval.patch
15+Patch4: 04-riscv-distdir_deps.patch
14# for folks with 'bazel' v1 package installed16# for folks with 'bazel' v1 package installed
15Conflicts: bazel17Conflicts: bazel
16Conflicts: bazel218Conflicts: bazel2
@@ -30,9 +32,14 @@ Correct, reproducible, and fast builds for everyone.
30%prep32%prep
31%setup -q -c -n bazel-%{version}33%setup -q -c -n bazel-%{version}
32%patch0 -p134%patch0 -p1
33-#%patch1 -p1
34%patch2 -p135%patch2 -p1
35%patch3 -p136%patch3 -p1
37+%ifarch riscv64
38+%patch1 -p1
39+%patch4 -p1
40+mkdir third_party/abseil-cpp
41+cp %{SOURCE1} third_party/abseil-cpp
42+%endif
36 43 
37%build44%build
38find . -type f -regextype posix-extended -iregex '.*(sh|txt|py|_stub|stub_.*|bazel|get_workspace_status|protobuf_support|_so)' -exec %{__sed} -i -e '1s|^#!/usr/bin/env python$|#!/usr/bin/env python3|' "{}" \;45find . -type f -regextype posix-extended -iregex '.*(sh|txt|py|_stub|stub_.*|bazel|get_workspace_status|protobuf_support|_so)' -exec %{__sed} -i -e '1s|^#!/usr/bin/env python$|#!/usr/bin/env python3|' "{}" \;
@@ -92,6 +99,9 @@ env ./scripts/generate_bash_completion.sh --bazel=output/bazel --output=output/b
92%attr(0755,root,root) %{bashcompdir}/bazel99%attr(0755,root,root) %{bashcompdir}/bazel
93 100 
94%changelog101%changelog
102+* Tue Jul 09 2024 laokz <zhangkai@iscas.ac.cn> - 5.3.0-2
103+- riscv64: fix 'rdcycle' SIGILL of dependency abseil-cpp
104+ 
95* Tue Sep 12 2023 Jincheng Miao <jincheng.miao@intel.com> - 5.3.0-1105* Tue Sep 12 2023 Jincheng Miao <jincheng.miao@intel.com> - 5.3.0-1
96- add bazel-%{version}-%{_os}-%{_arch} to install root path106- add bazel-%{version}-%{_os}-%{_arch} to install root path
97 107