Skip to content

Commit

Permalink
deps: V8: cherry-pick 2db93c023379
Browse files Browse the repository at this point in the history
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 <ishell@chromium.org>
    Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#67116}

Refs: v8/v8@2db93c0

PR-URL: #32885
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
  • Loading branch information
addaleax authored and BethGriggs committed Apr 20, 2020
1 parent 122937f commit 1b78785
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Expand Up @@ -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 #####

Expand Down
4 changes: 4 additions & 0 deletions deps/v8/include/v8-internal.h
Expand Up @@ -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<kApiInt32Size>;
#else
Expand Down
18 changes: 17 additions & 1 deletion deps/v8/include/v8.h
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion deps/v8/src/api/api.cc
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1b78785

Please sign in to comment.