Closed mollybuild closed 2 years ago
what is your gcc_toolchain("riscv64") ?
what is your gcc_toolchain("riscv64") ?
gcc_toolchain("riscv64") {
toolprefix = "riscv64-unknown-linux-gnu"
cc = "${toolprefix}-gcc"
cxx = "${toolprefix}-g++"
readelf = "${toolprefix}-readelf"
nm = "${toolprefix}-nm"
ar = "${toolprefix}-ar"
ld = cxx
toolchain_args = {
current_cpu = "riscv64"
current_os = "linux"
is_clang = false
}
}
This issue caused by build/config/compiler/BUILD.gn,delete these two lines will fix:
Then encounter this error: This error appears when using riscv gcc 10.2.0. riscv gcc 11.1 doesn't have this issue.
compile obj/v8_compiler/pipeline.o failed when using GCC11.1:
From 9e5ff0da991cac280c91cc6cfe3e1cca9471fd47 Mon Sep 17 00:00:00 2001
From: Lu Yahan <yahan@iscas.ac.cn>
Date: Thu, 23 Jun 2022 10:12:21 +0800
Subject: [PATCH] support clang
---
build_config.h | 5 +++++
config/compiler/BUILD.gn | 26 +++++++++++++++++++++-----
config/riscv.gni | 18 ++++++++++++++++++
toolchain/linux/BUILD.gn | 35 +++++++++++++++++++++++++++++++++++
4 files changed, 79 insertions(+), 5 deletions(-)
create mode 100644 config/riscv.gni
diff --git a/build_config.h b/build_config.h
index a993e1e44..f1d852c74 100644
--- a/build_config.h
+++ b/build_config.h
@@ -341,6 +341,11 @@
#define ARCH_CPU_RISCV64 1
#define ARCH_CPU_64_BITS 1
#define ARCH_CPU_LITTLE_ENDIAN 1
+#elif defined(__riscv) && (__riscv_xlen == 32)
+#define ARCH_CPU_RISCV_FAMILY 1
+#define ARCH_CPU_RISCV32 1
+#define ARCH_CPU_32_BITS 1
+#define ARCH_CPU_LITTLE_ENDIAN 1
#else
#error Please add support for your architecture in build/build_config.h
#endif
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
index 676efeddd..471507e3a 100644
--- a/config/compiler/BUILD.gn
+++ b/config/compiler/BUILD.gn
@@ -30,6 +30,9 @@ if (current_cpu == "mipsel" || current_cpu == "mips64el" ||
current_cpu == "mips" || current_cpu == "mips64") {
import("//build/config/mips.gni")
}
+if (current_cpu == "riscv32") {
+ import("//build/config/riscv.gni")
+}
if (is_mac) {
import("//build/config/apple/symbols.gni")
}
@@ -935,6 +938,19 @@ config("compiler_cpu_abi") {
# Outline atomics crash on Exynos 9810. http://crbug.com/1272795
cflags += [ "-mno-outline-atomics" ]
}
+ } else if (current_cpu == "riscv32") {
+ if (is_clang) {
+ cflags += [ "--target=riscv32-unknown-linux-gnu" ]
+ ldflags += [ "--target=riscv32-unknown-linux-gnu" ]
+ if (riscv_gcc_toolchain_path != "") {
+ cflags += [ "--gcc-toolchain=$riscv_gcc_toolchain_path" ]
+ ldflags += [ "--gcc-toolchain=$riscv_gcc_toolchain_path" ]
+ }
+ if (riscv_sysroot != "") {
+ cflags += [ "--sysroot=$riscv_sysroot" ]
+ ldflags += [ "--sysroot=$riscv_sysroot" ]
+ }
+ }
} else if (current_cpu == "mipsel" && !is_nacl) {
ldflags += [ "-Wl,--hash-style=sysv" ]
if (custom_toolchain == "") {
@@ -1176,12 +1192,12 @@ config("compiler_cpu_abi") {
ldflags += [ "-m64" ]
}
} else if (current_cpu == "riscv64") {
+ if(is_clang) {
+ cflags += [ "--target=mips64-linux-gnuabi64" ]
+ ldflags += [ "--target=mips64-linux-gnuabi64" ]
+ }
cflags += [
- "-mabi=lp64d",
- "--target=riscv64-linux-gnu",
- ]
- ldflags += [
- "--target=riscv64-linux-gnu",
+ "-mabi=lp64d"
]
} else if (current_cpu == "s390x") {
cflags += [ "-m64" ]
diff --git a/config/riscv.gni b/config/riscv.gni
new file mode 100644
index 000000000..9c3397d2a
--- /dev/null
+++ b/config/riscv.gni
@@ -0,0 +1,18 @@
+# Copyright 2022 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/config/v8_target_cpu.gni")
+
+# These are primarily relevant in current_cpu == "riscv*" contexts, where
+# RISCV code is being compiled. But they can also be relevant in the
+# other contexts when the code will change its behavior based on the
+# cpu it wants to generate code for.
+declare_args() {
+ # riscv64 clang need the gcc toolchain to link
+ riscv_gcc_toolchain_path = ""
+ # riscv64 sysroot, clang may be need
+ riscv_sysroot = ""
+
+ use_relax = true
+}
\ No newline at end of file
diff --git a/toolchain/linux/BUILD.gn b/toolchain/linux/BUILD.gn
index e67f09f27..672271275 100644
--- a/toolchain/linux/BUILD.gn
+++ b/toolchain/linux/BUILD.gn
@@ -164,6 +164,13 @@ clang_v8_toolchain("clang_x64_v8_mips64") {
}
}
+clang_v8_toolchain("clang_x86_v8_riscv32") {
+ toolchain_args = {
+ current_cpu = "x86"
+ v8_current_cpu = "riscv32"
+ }
+}
+
clang_v8_toolchain("clang_x64_v8_riscv64") {
toolchain_args = {
current_cpu = "x64"
@@ -301,6 +308,16 @@ clang_toolchain("clang_riscv64") {
}
}
+clang_toolchain("clang_riscv32") {
+ enable_linker_map = true
+ toolchain_args = {
+ current_cpu = "riscv32"
+ current_os = "linux"
+ is_clang = true
+ }
+}
+
+
gcc_toolchain("riscv64") {
toolprefix = "riscv64-linux-gnu"
@@ -319,6 +336,24 @@ gcc_toolchain("riscv64") {
}
}
+gcc_toolchain("riscv32") {
+ toolprefix = "riscv32-unknown-linux-gnu"
+
+ cc = "${toolprefix}-gcc"
+ cxx = "${toolprefix}-g++"
+
+ readelf = "${toolprefix}-readelf"
+ nm = "${toolprefix}-nm"
+ ar = "${toolprefix}-ar"
+ ld = cxx
+
+ toolchain_args = {
+ current_cpu = "riscv32"
+ current_os = "linux"
+ is_clang = false
+ }
+}
+
clang_toolchain("clang_s390x") {
toolchain_args = {
current_cpu = "s390x"
--
2.25.1
I build v8 for riscv64 like bellow:
Error information:
OS: Ubuntu 20.04 GCC version : 10.2.0