Porting for riscv64

228 views
Skip to first unread message

Chang Rebecca Swee Fun

unread,
Jan 14, 2022, 5:51:02 PM1/14/22
to Chromium-dev
Hi,

I am working on porting chromium browser to riscv64.
I have the following args.gn:
current_cpu="riscv64"
target_os="linux"
target_cpu="riscv64"
is_component_build = true
is_debug = false
symbol_level=0
v8_symbol_level=0
blink_symbol_level=0

# Disable broken features
use_gnome_keyring=false
enable_nacl = false
treat_warnings_as_errors = false
fatal_linker_warnings=false
enable_dav1d_decoder = false
enable_reading_list=false
enable_vr=false
enable_swiftshader=false
enable_libaom=false

# For custom clang
is_clang = true
clang_base_path = getenv("HOME") + "/riscv/_install"
clang_use_chrome_plugins = false
use_lld = false

I have added riscv64 into compiler gn:
+++ b/build/config/compiler/BUILD.gn
@@ -1163,6 +1163,12 @@ config("compiler_cpu_abi") {
         cflags += [ "-m64" ]
         ldflags += [ "-m64" ]
       }
+    } else if (current_cpu == "riscv64") {
+      cflags += [
+        "-m64",
+        "-march=rv64gc",
+        "-mabi=lp64d",
+      ]
     } else if (current_cpu == "s390x") {

I have also build a local copy of sysroot for riscv64 using debian port.

However, the build command was not taking my configurations and it is building for x86-64 (my host CPU) some how.

I would like to know how the cflags was passed within the build as some of the components did successfully build while now i'm getting error from borringssl.

FAILED: clang_x64_v8_riscv64/obj/third_party/boringssl/boringssl/ssl_cipher.o
../../../../riscv/_install/bin/clang++ -MMD -MF clang_x64_v8_riscv64/obj/third_party/boringssl/boringssl/ssl_cipher.o.d -DDCHECK_A
LWAYS_ON=1 -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARG
EFILE64_SOURCE -D_GNU_SOURCE -DCOMPONENT_BUILD -D_LIBCPP_ABI_UNSTABLE -D_LIBCPP_ABI_VERSION=Cr -D_LIBCPP_ENABLE_NODISCARD -D_LIBCP
P_DEBUG=0 -DCR_LIBCXX_REVISION=79a2e924d96e2fc1e4b937c42efd08898fa472d7 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DBOR
INGSSL_IMPLEMENTATION -DBORINGSSL_ALLOW_CXX_RUNTIME -DBORINGSSL_NO_STATIC_INITIALIZER -DOPENSSL_SMALL -DBORINGSSL_SHARED_LIBRARY -
I../.. -Iclang_x64_v8_riscv64/gen -I../../buildtools/third_party/libc++ -I../../third_party/boringssl/src/include -fno-delete-null
-pointer-checks -fno-ident -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -pthread -fcolo$
-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -mllvm -instcombine-lower-dbg-declare=0
-ffp-contract=off -fcomplete-member-pointers -m64 -march=x86-64 -msse3 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TI
MESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes -fno-omit-frame-pointer -g0 -ftrivial-auto-var-init=pattern -fvisibilit
y=hidden -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wall -Wno-unused-variable -Wno-c++11-narrowing -Wno-
unused-but-set-variable -Wno-misleading-indentation -Wno-missing-field-initializers -Wno-unused-parameter -Wloop-analysis -Wno-unn
eeded-internal-declaration -Wenum-compare-conditional -Wno-psabi -Wno-ignored-pragma-optimize -O2 -fdata-sections -ffunction-secti
ons -fno-unique-section-names -std=c++17 -Wno-trigraphs -fno-aligned-new -fno-exceptions -fno-rtti -nostdinc++ -isystem../../build
tools/third_party/libc++/trunk/include -isystem../../buildtools/third_party/libc++abi/trunk/include --sysroot=../../build/linux/de
bian_sid_amd64-sysroot -fvisibility-inlines-hidden -c ../../third_party/boringssl/src/ssl/ssl_cipher.cc -o clang_x64_v8_riscv64/ob
j/third_party/boringssl/boringssl/ssl_cipher.o
clang++: error: invalid arch name 'x86-64', string must begin with rv32{i,e,g} or rv64{i,g}

Dirk Pranke

unread,
Jan 14, 2022, 8:50:33 PM1/14/22
to rebecc...@starfivetech.com, Chromium-dev
When you're building for a target architecture that is different from the host architecture, we still need to build some things for the host architecture. Some of these things are for tools (like protoc) that run on the host, and some of them have to do with Chromium itself. 

In particular, there's something called the "v8 snapshot" which is built on the host using the same bit-width as the target architecture to set up various v8 data structures that will then be used during the target build (I'm hand-waving here because I'm not really a v8 dev and so don't fully understand the details). You're hitting this, which we can tell from the 'clang_x64_v8_riscv64" part of your target paths, which is set here.

But, what this means is that you have to have a host toolchain installed as well, i.e., either have a version of clang that supports both x64 and and rv64, or set things up to use two different clang binaries, one for the target toolchain and one for the host.

Hope this helps,

-- Dirk

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/ac2b9288-8d65-420a-b75e-25e6059cd60an%40chromium.org.

Torne (Richard Coles)

unread,
Jan 18, 2022, 11:21:13 AM1/18/22
to Dirk Pranke, rebecc...@starfivetech.com, Chromium-dev
Also you should not be setting current_cpu explicitly - this gets set automatically during the build to target_cpu when building binaries for the target, and host_cpu when building binaries for the host. Setting it to your target CPU means it will try to build and run host tools for the target CPU which won't work.

Roger Tawa

unread,
Jan 18, 2022, 1:36:15 PM1/18/22
to to...@chromium.org, Dirk Pranke, rebecc...@starfivetech.com, Chromium-dev
Hi Rebecca,

I'm interested in your changes.  Are you planning to upstream once you get it working?

Thanks,
Roger

-


Chang Rebecca Swee Fun

unread,
Jan 21, 2022, 12:54:10 AM1/21/22
to Chromium-dev, to...@chromium.org, Chang Rebecca Swee Fun, Chromium-dev, Dirk Pranke
Thanks for the guidance. I shall update my build configurations in args.gn and try again.
So far, I hit into some third_party components in which they do not have support on riscv64 arch yet.
I am in the midst of disabling them temporarily so i will be able to gauge how much porting work required.

Chang Rebecca Swee Fun

unread,
Feb 15, 2022, 4:39:53 AM2/15/22
to Chromium-dev, Chang Rebecca Swee Fun, to...@chromium.org, Chromium-dev, Dirk Pranke
Hi all, just like Dirk mentioned before, I need to rebuild protoc before i could proceed anywhere else.

I have been stuck with this for a week and not sure how to proceed with protoc compilation.

So, what i did was: 
$ cd third_party/protobuf
$ ./autogen.sh
$ ./configure --prefix=$RISCV --target=riscv64-unknown-linux-gnu --host=x86_64-pc-linux-gnu
$ make -j16

Here, I am able to compile and generated the protoc bin.

Now, when I go back to chromium build and ran $ autoninja -C out/riscv64 chrome
I got the error below stored in gist:

Need help on this part as I wasn't sure what to configure for protoc from the top level BUILD.gn.
Many thank in advance.

Rebecca
Reply all
Reply to author
Forward
0 new messages