Skip to content

Commit 1b78785

Browse files
addaleaxBethGriggs
authored andcommitted
deps: V8: cherry-pick 2db93c023379
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>
1 parent 122937f commit 1b78785

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Reset this number to 0 on major V8 upgrades.
3737
# Increment by one for each non-official patch applied to deps/v8.
38-
'v8_embedder_string': '-node.13',
38+
'v8_embedder_string': '-node.14',
3939

4040
##### V8 defaults for Node.js #####
4141

deps/v8/include/v8-internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ const int kApiTaggedSize = kApiInt32Size;
106106
const int kApiTaggedSize = kApiSystemPointerSize;
107107
#endif
108108

109+
constexpr bool PointerCompressionIsEnabled() {
110+
return kApiTaggedSize != kApiSystemPointerSize;
111+
}
112+
109113
#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
110114
using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
111115
#else

deps/v8/include/v8.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9530,7 +9530,12 @@ class V8_EXPORT V8 {
95309530
* Initializes V8. This function needs to be called before the first Isolate
95319531
* is created. It always returns true.
95329532
*/
9533-
static bool Initialize();
9533+
V8_INLINE static bool Initialize() {
9534+
const int kBuildConfiguration =
9535+
(internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
9536+
(internal::SmiValuesAre31Bits() ? k31BitSmis : 0);
9537+
return Initialize(kBuildConfiguration);
9538+
}
95349539

95359540
/**
95369541
* Allows the host application to provide a callback which can be used
@@ -9664,6 +9669,17 @@ class V8_EXPORT V8 {
96649669
private:
96659670
V8();
96669671

9672+
enum BuildConfigurationFeatures {
9673+
kPointerCompression = 1 << 0,
9674+
k31BitSmis = 1 << 1,
9675+
};
9676+
9677+
/**
9678+
* Checks that the embedder build configuration is compatible with
9679+
* the V8 binary and if so initializes V8.
9680+
*/
9681+
static bool Initialize(int build_config);
9682+
96679683
static internal::Address* GlobalizeReference(internal::Isolate* isolate,
96689684
internal::Address* handle);
96699685
static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate,

deps/v8/src/api/api.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5652,7 +5652,25 @@ void v8::V8::InitializePlatform(Platform* platform) {
56525652

56535653
void v8::V8::ShutdownPlatform() { i::V8::ShutdownPlatform(); }
56545654

5655-
bool v8::V8::Initialize() {
5655+
bool v8::V8::Initialize(const int build_config) {
5656+
const bool kEmbedderPointerCompression =
5657+
(build_config & kPointerCompression) != 0;
5658+
if (kEmbedderPointerCompression != COMPRESS_POINTERS_BOOL) {
5659+
FATAL(
5660+
"Embedder-vs-V8 build configuration mismatch. On embedder side "
5661+
"pointer compression is %s while on V8 side it's %s.",
5662+
kEmbedderPointerCompression ? "ENABLED" : "DISABLED",
5663+
COMPRESS_POINTERS_BOOL ? "ENABLED" : "DISABLED");
5664+
}
5665+
5666+
const int kEmbedderSmiValueSize = (build_config & k31BitSmis) ? 31 : 32;
5667+
if (kEmbedderSmiValueSize != internal::kSmiValueSize) {
5668+
FATAL(
5669+
"Embedder-vs-V8 build configuration mismatch. On embedder side "
5670+
"Smi value size is %d while on V8 side it's %d.",
5671+
kEmbedderSmiValueSize, internal::kSmiValueSize);
5672+
}
5673+
56565674
i::V8::Initialize();
56575675
return true;
56585676
}

0 commit comments

Comments
 (0)