From 1b7878558a74efa7a8dcd8b90c4e4a464a5afd8a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 16 Apr 2020 17:47:07 +0200 Subject: [PATCH] deps: V8: cherry-pick 2db93c023379 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [api] Add embedder-vs-V8 build configuration compatibility check v8::V8::Initialize() will fail with meaningful error upon build configuration mismatch. Bug: v8:10041 Change-Id: Ic69ba68ef1764b356beef0f204fe58b45bae3c49 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2144953 Commit-Queue: Igor Sheludko Reviewed-by: Ulan Degenbaev Cr-Commit-Position: refs/heads/master@{#67116} Refs: https://github.com/v8/v8/commit/2db93c0233790b2cfb9e80fa1fa89dee18c7109f PR-URL: https://github.com/nodejs/node/pull/32885 Reviewed-By: Michaël Zasso Reviewed-By: Ujjwal Sharma Reviewed-By: Gerhard Stöbich Reviewed-By: Beth Griggs --- common.gypi | 2 +- deps/v8/include/v8-internal.h | 4 ++++ deps/v8/include/v8.h | 18 +++++++++++++++++- deps/v8/src/api/api.cc | 20 +++++++++++++++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/common.gypi b/common.gypi index b23898301a4898..4dfbdfac061887 100644 --- a/common.gypi +++ b/common.gypi @@ -35,7 +35,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.13', + 'v8_embedder_string': '-node.14', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/include/v8-internal.h b/deps/v8/include/v8-internal.h index 876408ebba98f9..52ee403f526d06 100644 --- a/deps/v8/include/v8-internal.h +++ b/deps/v8/include/v8-internal.h @@ -106,6 +106,10 @@ const int kApiTaggedSize = kApiInt32Size; const int kApiTaggedSize = kApiSystemPointerSize; #endif +constexpr bool PointerCompressionIsEnabled() { + return kApiTaggedSize != kApiSystemPointerSize; +} + #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH using PlatformSmiTagging = SmiTagging; #else diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 13724930103db1..9a58ef8720c4b4 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -9530,7 +9530,12 @@ class V8_EXPORT V8 { * Initializes V8. This function needs to be called before the first Isolate * is created. It always returns true. */ - static bool Initialize(); + V8_INLINE static bool Initialize() { + const int kBuildConfiguration = + (internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) | + (internal::SmiValuesAre31Bits() ? k31BitSmis : 0); + return Initialize(kBuildConfiguration); + } /** * Allows the host application to provide a callback which can be used @@ -9664,6 +9669,17 @@ class V8_EXPORT V8 { private: V8(); + enum BuildConfigurationFeatures { + kPointerCompression = 1 << 0, + k31BitSmis = 1 << 1, + }; + + /** + * Checks that the embedder build configuration is compatible with + * the V8 binary and if so initializes V8. + */ + static bool Initialize(int build_config); + static internal::Address* GlobalizeReference(internal::Isolate* isolate, internal::Address* handle); static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate, diff --git a/deps/v8/src/api/api.cc b/deps/v8/src/api/api.cc index 7fe974de24e8db..dac9e97b1ba121 100644 --- a/deps/v8/src/api/api.cc +++ b/deps/v8/src/api/api.cc @@ -5652,7 +5652,25 @@ void v8::V8::InitializePlatform(Platform* platform) { void v8::V8::ShutdownPlatform() { i::V8::ShutdownPlatform(); } -bool v8::V8::Initialize() { +bool v8::V8::Initialize(const int build_config) { + const bool kEmbedderPointerCompression = + (build_config & kPointerCompression) != 0; + if (kEmbedderPointerCompression != COMPRESS_POINTERS_BOOL) { + FATAL( + "Embedder-vs-V8 build configuration mismatch. On embedder side " + "pointer compression is %s while on V8 side it's %s.", + kEmbedderPointerCompression ? "ENABLED" : "DISABLED", + COMPRESS_POINTERS_BOOL ? "ENABLED" : "DISABLED"); + } + + const int kEmbedderSmiValueSize = (build_config & k31BitSmis) ? 31 : 32; + if (kEmbedderSmiValueSize != internal::kSmiValueSize) { + FATAL( + "Embedder-vs-V8 build configuration mismatch. On embedder side " + "Smi value size is %d while on V8 side it's %d.", + kEmbedderSmiValueSize, internal::kSmiValueSize); + } + i::V8::Initialize(); return true; }