Search code examples
google-chromev8

How to Build Chrome V8 on Linux ARM64?


I'm trying to build V8 on Ubuntu 22.04 ARM64. I've tried building via the convenience scripts i.e. tools/dev/gm.py arm64.release, as well as tools/dev/v8gen.py arm64.release but to no success (clang errors), for example multiple of the following:

FAILED: obj/cppgc_base/free-list.o 
/usr/bin/clang++ -MMD -MF obj/cppgc_base/free-list.o.d -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -DCR_LIBCXX_REVISION=0c90b8212cbb8a4c6dc78537813118fceea8265d -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DENABLE_DISASSEMBLER -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DOBJECT_PRINT -DVERIFY_HEAP -DV8_INTL_SUPPORT -DV8_USE_EXTERNAL_STARTUP_DATA -DV8_ATOMIC_OBJECT_FIELD_WRITES -DV8_ENABLE_LAZY_SOURCE_POSITIONS -DV8_SHARED_RO_HEAP -DV8_WIN64_UNWINDING_INFO -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_ENABLE_CONTROL_FLOW_INTEGRITY -DV8_ENABLE_FUZZTEST -DV8_SHORT_BUILTIN_CALLS -DV8_EXTERNAL_CODE_SPACE -DV8_ENABLE_SPARKPLUG -DV8_ENABLE_MAGLEV -DV8_ENABLE_TURBOFAN -DV8_ENABLE_WEBASSEMBLY -DV8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA -DV8_ALLOCATION_FOLDING -DV8_ALLOCATION_SITE_TRACKING -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_STATIC_ROOTS -DV8_USE_ZLIB -DV8_USE_LIBM_TRIG_FUNCTIONS -DV8_ENABLE_MAGLEV_GRAPH_PRINTER -DV8_ENABLE_EXTENSIBLE_RO_SNAPSHOT -DV8_COMPRESS_POINTERS -DV8_COMPRESS_POINTERS_IN_SHARED_CAGE -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_SANDBOX -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DCPPGC_CAGED_HEAP -DCPPGC_YOUNG_GENERATION -DCPPGC_POINTER_COMPRESSION -DCPPGC_SLIM_WRITE_BARRIER -DV8_TARGET_ARCH_ARM64 -DV8_HAVE_TARGET_OS -DV8_TARGET_OS_LINUX -DV8_RUNTIME_CALL_STATS -I../.. -Igen -I../../buildtools/third_party/libc++ -I../../include -Wall -Wextra -Wimplicit-fallthrough -Wextra-semi -Wunreachable-code-aggressive -Wthread-safety -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -Wloop-analysis -Wno-unneeded-internal-declaration -Wno-cast-function-type -Wno-ignored-pragma-optimize -Wno-deprecated-builtins -Wno-bitfield-constant-conversion -Wno-deprecated-this-capture -Wno-invalid-offsetof -Wno-vla-extension -Wno-thread-safety-reference-return -Wshadow -Werror -fno-delete-null-pointer-checks -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pthread -fcolor-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -mllvm -instcombine-lower-dbg-declare=0 -mllvm -split-threshold-for-reg-with-hint=0 -ffp-contract=off -fcomplete-member-pointers -mbranch-protection=standard --target=aarch64-linux-gnu -mno-outline -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes -fno-omit-frame-pointer -g0 -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wunreachable-code -Wno-shadow -Wctad-maybe-unsupported -Wno-invalid-offsetof -Wshorten-64-to-32 -Wmissing-field-initializers -O3 -fdata-sections -ffunction-sections -fno-unique-section-names -fno-math-errno -fvisibility=default -Wexit-time-destructors -Wenum-compare-conditional -Wno-c++11-narrowing-const-reference -std=c++20 -Wno-trigraphs -gsimple-template-names -fno-exceptions -fno-rtti -nostdinc++ -isystem../../third_party/libc++/src/include -isystem../../third_party/libc++abi/src/include --sysroot=../../build/linux/debian_bullseye_arm64-sysroot -c ../../src/heap/cppgc/free-list.cc -o obj/cppgc_base/free-list.o
error: unknown warning option '-Wno-deprecated-builtins' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wno-thread-safety-reference-return'; did you mean '-Wno-thread-safety-reference'? [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wno-c++11-narrowing-const-reference'; did you mean '-Wno-uninitialized-const-reference'? [-Werror,-Wunknown-warning-option]
clang (LLVM option parsing): Unknown command line argument '-split-threshold-for-reg-with-hint=0'.  Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '--unroll-threshold-aggressive=0'?
ninja: build stopped: subcommand failed.

I've then tried building/using the upstream clang build bundled with fetch v8 which even after export VPYTHON_BYPASS="manually managed python not supported by chrome operations" I get the following:

Building final compiler.
Traceback (most recent call last):
  File "/home/v8user/Desktop/v8/tools/clang/scripts/get_tensorflow.py", line 178, in <module>
    print(os.path.dirname(spec.origin))
AttributeError: 'NoneType' object has no attribute 'origin'
Traceback (most recent call last):
  File "/home/v8user/Desktop/v8/tools/clang/scripts/build.py", line 1539, in <module>
    sys.exit(main())
  File "/home/v8user/Desktop/v8/tools/clang/scripts/build.py", line 1379, in main
    tf_path = subprocess.check_output(
  File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['vpython3', '/home/v8user/Desktop/v8/tools/clang/scripts/get_tensorflow.py']' returned non-zero exit status 1.

I've then tried the following recent approach:

Clone V8 Repository: Cloning the V8 repository using Git:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:/home/v8user/Desktop/depot_tools
fetch v8

Bypass VPYTHON: Bypassing vpython by setting the environment variable:

export VPYTHON_BYPASS="manually managed python not supported by chrome operations"

Set Up GN Arguments: Setting up GN arguments manually for the desired configurations:

gn args out.gn/arm64.release

In the editor that opens, I paste the following for a release build:

is_debug=false
target_cpu="arm64" 
v8_target_cpu="arm64"
is_clang=false
treat_warnings_as_errors=false
use_custom_libcxx=false
use_custom_libcxx_for_host=false

Followed by:

ninja -C out.gn/arm64.release

This at least begins building, however the build terminates with the following:

ninja: Entering directory `out.gn/arm64.release'
[1084/3863] CXX obj/test/cctest/cctest_sources/test-code-stub-assembler.o
FAILED: obj/test/cctest/cctest_sources/test-code-stub-assembler.o 
aarch64-linux-gnu-g++ -MMD -MF obj/test/cctest/cctest_sources/test-code-stub-assembler.o.d -DV8_INTL_SUPPORT -DUSE_UDEV -DUSE_AURA=1 -DUSE_GLIB=1 -DUSE_OZONE=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE -D_GLIBCXX_ASSERTIONS=1 -DCR_SYSROOT_KEY=20230611T210420Z-2 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DV8_USE_EXTERNAL_STARTUP_DATA -DV8_ATOMIC_OBJECT_FIELD_WRITES -DV8_ENABLE_LAZY_SOURCE_POSITIONS -DV8_SHARED_RO_HEAP -DV8_WIN64_UNWINDING_INFO -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_ENABLE_CONTROL_FLOW_INTEGRITY -DV8_SHORT_BUILTIN_CALLS -DV8_EXTERNAL_CODE_SPACE -DV8_ENABLE_SPARKPLUG -DV8_ENABLE_MAGLEV -DV8_ENABLE_TURBOFAN -DV8_ENABLE_WEBASSEMBLY -DV8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA -DV8_ALLOCATION_FOLDING -DV8_ALLOCATION_SITE_TRACKING -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_STATIC_ROOTS -DV8_USE_ZLIB -DV8_ENABLE_MAGLEV_GRAPH_PRINTER -DV8_ENABLE_EXTENSIBLE_RO_SNAPSHOT -DV8_COMPRESS_POINTERS -DV8_COMPRESS_POINTERS_IN_SHARED_CAGE -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_SANDBOX -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DCPPGC_CAGED_HEAP -DCPPGC_YOUNG_GENERATION -DCPPGC_POINTER_COMPRESSION -DCPPGC_SLIM_WRITE_BARRIER -DV8_TARGET_ARCH_ARM64 -DV8_HAVE_TARGET_OS -DV8_TARGET_OS_LINUX -DV8_RUNTIME_CALL_STATS -DABSL_ALLOCATOR_NOTHROW=1 -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DUSE_CHROMIUM_ICU=1 -DU_ENABLE_TRACING=1 -DU_ENABLE_RESOURCE_TRACING=0 -DU_STATIC_IMPLEMENTATION -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -I../.. -Igen -I../../include -I../../third_party/abseil-cpp -Igen/include -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../third_party/fp16/src/include -ffp-contract=off -Wall -Wno-unused-local-typedefs -Wno-maybe-uninitialized -Wno-deprecated-declarations -Wno-comments -Wno-packed-not-aligned -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -fno-ident -fno-strict-aliasing -fstack-protector -funwind-tables -fPIC -pipe -pthread -mbranch-protection=standard -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -fno-omit-frame-pointer -g0 -fvisibility=hidden -Wno-invalid-offsetof -Wno-strict-overflow -Wno-return-type -Wno-int-in-bool-context -Wno-deprecated -Wno-stringop-overflow -Wno-stringop-overread -Wno-restrict -Wno-array-bounds -Wno-nonnull -Wno-dangling-pointer -O3 -fdata-sections -ffunction-sections -fno-math-errno -Wno-narrowing -Wno-class-memaccess -std=gnu++2a -fno-exceptions -fno-rtti --sysroot=../../build/linux/debian_bullseye_arm64-sysroot -fvisibility-inlines-hidden -c ../../test/cctest/test-code-stub-assembler.cc -o obj/test/cctest/cctest_sources/test-code-stub-assembler.o
{standard input}: Assembler messages:
{standard input}:117: Error: invalid addressing mode at operand 2 -- `str x16,x0'
[1089/3863] CXX obj/test/cctest/cctest_sources/test-assembler-arm64.o
ninja: build stopped: subcommand failed.

May someone please assist with how I can build V8 here, I have had no issues building on x86_64 Linux and Mac, similarly I can build on ARM64 Mac (M3 Max) by following this. Though for whatever reason I'm having a really hard time building on my ARM64 Linux.

I appreciate any assistance here. Thanks for your help and looking forward to getting this up and running! :)


Solution

  • Here is a document describing how to do this in 2021: https://docs.google.com/document/d/1u-HAFfjWIH3WY3xajuGxGii-lWi1rpf16hVmB-mRdTA/edit

    Some parts are almost certainly outdated by now, such as the python2 requirement. But the key idea to replace bundled tools with system-installed ninja/clang/... probably still applies.

    You could add comments to that document for any steps that need updating. Or you could make a copy, update that as necessary, and post it here to let others follow in your footsteps.

    Also note the summary at the top: cross-compiling is probably more practical (unless your arm64 device is significantly more powerful than a Raspberry Pi).