Make creating x64 snapshots on arm64 hosts mostly work

The motivation is being able to build Chrome/Mac/Intel on an
Apple Silicon mac.

Depends on https://chromium-review.googlesource.com/c/chromium/src/+/3348020

- Correctly set v8_snapshot_toolchain when targeting x64 on an arm64
  host (always use the clang_ toolchain for now since that's all
  that's needed at the moment)

- Check V8_HOST_ARCH in immediate-crash.h. In V8 terminology, "host"
  is the machine the snapshot generation runs on, while "target" is the
  machine that V8 runs on when it JITs. IMMEDIATE_CRASH runs on the
  host. Up to now, target arch x64 implied host arch x64 so the old code
  happened to work too, but this is the correct macro (and it makes this
  cross scenario work).

- In assembler-x64.cc, only compile the code that probes the current CPU
  when running on an intel host. (There's an early return for snapshot
  generation anyways.)

Bug: chromium:1280968
Change-Id: I4821a5994de8ed5f9e4f62184dc6ab6f5223bc3f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3348040
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78417}
This commit is contained in:
Nico Weber 2021-12-17 14:58:16 -05:00 committed by V8 LUCI CQ
parent e608acf40a
commit 5f644d7e71
4 changed files with 16 additions and 5 deletions

View File

@ -70,6 +70,10 @@ if (v8_snapshot_toolchain == "") {
# therefore snapshots will need to be built using native mksnapshot # therefore snapshots will need to be built using native mksnapshot
# in combination with qemu # in combination with qemu
v8_snapshot_toolchain = current_toolchain v8_snapshot_toolchain = current_toolchain
} else if (host_cpu == "arm64" && current_cpu == "x64") {
# Cross-build from arm64 to intel (likely on an Apple Silicon mac).
v8_snapshot_toolchain =
"//build/toolchain/${host_os}:clang_arm64_v8_$v8_current_cpu"
} else if (host_cpu == "x64") { } else if (host_cpu == "x64") {
# This is a cross-compile from an x64 host to either a non-Intel target # This is a cross-compile from an x64 host to either a non-Intel target
# cpu or a different target OS. Clang will always be used by default on the # cpu or a different target OS. Clang will always be used by default on the

View File

@ -154,8 +154,8 @@
#error Target architecture ia32 is only supported on ia32 host #error Target architecture ia32 is only supported on ia32 host
#endif #endif
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \ #if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT && \
!(V8_HOST_ARCH_X64 && V8_HOST_ARCH_64_BIT)) !((V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64) && V8_HOST_ARCH_64_BIT))
#error Target architecture x64 is only supported on x64 host #error Target architecture x64 is only supported on x64 and arm64 host
#endif #endif
#if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT && \ #if (V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT && \
!(V8_HOST_ARCH_X64 && V8_HOST_ARCH_32_BIT)) !(V8_HOST_ARCH_X64 && V8_HOST_ARCH_32_BIT))

View File

@ -42,7 +42,7 @@
#if V8_CC_GNU #if V8_CC_GNU
#if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 #if V8_HOST_ARCH_X64 || V8_HOST_ARCH_IA32
// TODO(https://crbug.com/958675): In theory, it should be possible to use just // TODO(https://crbug.com/958675): In theory, it should be possible to use just
// int3. However, there are a number of crashes with SIGILL as the exception // int3. However, there are a number of crashes with SIGILL as the exception

View File

@ -32,6 +32,8 @@ namespace internal {
namespace { namespace {
#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
V8_INLINE uint64_t xgetbv(unsigned int xcr) { V8_INLINE uint64_t xgetbv(unsigned int xcr) {
#if V8_LIBC_MSVCRT #if V8_LIBC_MSVCRT
return _xgetbv(xcr); return _xgetbv(xcr);
@ -69,6 +71,8 @@ bool OSHasAVXSupport() {
return (feature_mask & 0x6) == 0x6; return (feature_mask & 0x6) == 0x6;
} }
#endif // V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
} // namespace } // namespace
bool CpuFeatures::SupportsWasmSimd128() { bool CpuFeatures::SupportsWasmSimd128() {
@ -80,12 +84,14 @@ bool CpuFeatures::SupportsWasmSimd128() {
} }
void CpuFeatures::ProbeImpl(bool cross_compile) { void CpuFeatures::ProbeImpl(bool cross_compile) {
// Only use statically determined features for cross compile (snapshot).
if (cross_compile) return;
#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
base::CPU cpu; base::CPU cpu;
CHECK(cpu.has_sse2()); // SSE2 support is mandatory. CHECK(cpu.has_sse2()); // SSE2 support is mandatory.
CHECK(cpu.has_cmov()); // CMOV support is mandatory. CHECK(cpu.has_cmov()); // CMOV support is mandatory.
// Only use statically determined features for cross compile (snapshot).
if (cross_compile) return;
if (cpu.has_sse42()) SetSupported(SSE4_2); if (cpu.has_sse42()) SetSupported(SSE4_2);
if (cpu.has_sse41()) SetSupported(SSE4_1); if (cpu.has_sse41()) SetSupported(SSE4_1);
if (cpu.has_ssse3()) SetSupported(SSSE3); if (cpu.has_ssse3()) SetSupported(SSSE3);
@ -125,6 +131,7 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
// at runtime in builtins using an extern ref. Other callers should use // at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128(). // CpuFeatures::SupportWasmSimd128().
CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128(); CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128();
#endif // V8_HOST_ARCH_X64
} }
void CpuFeatures::PrintTarget() {} void CpuFeatures::PrintTarget() {}