Skip to content

Commit 2db93c0

Browse files
isheludkoCommit Bot
authored andcommitted
[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 <[email protected]> Reviewed-by: Ulan Degenbaev <[email protected]> Cr-Commit-Position: refs/heads/master@{#67116}
1 parent e0433f7 commit 2db93c0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

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

include/v8.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9610,7 +9610,12 @@ class V8_EXPORT V8 {
96109610
* Initializes V8. This function needs to be called before the first Isolate
96119611
* is created. It always returns true.
96129612
*/
9613-
static bool Initialize();
9613+
V8_INLINE static bool Initialize() {
9614+
const int kBuildConfiguration =
9615+
(internal::PointerCompressionIsEnabled() ? kPointerCompression : 0) |
9616+
(internal::SmiValuesAre31Bits() ? k31BitSmis : 0);
9617+
return Initialize(kBuildConfiguration);
9618+
}
96149619

96159620
/**
96169621
* Allows the host application to provide a callback which can be used
@@ -9744,6 +9749,17 @@ class V8_EXPORT V8 {
97449749
private:
97459750
V8();
97469751

9752+
enum BuildConfigurationFeatures {
9753+
kPointerCompression = 1 << 0,
9754+
k31BitSmis = 1 << 1,
9755+
};
9756+
9757+
/**
9758+
* Checks that the embedder build configuration is compatible with
9759+
* the V8 binary and if so initializes V8.
9760+
*/
9761+
static bool Initialize(int build_config);
9762+
97479763
static internal::Address* GlobalizeReference(internal::Isolate* isolate,
97489764
internal::Address* handle);
97499765
static internal::Address* GlobalizeTracedReference(internal::Isolate* isolate,

src/api/api.cc

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

57235723
void v8::V8::ShutdownPlatform() { i::V8::ShutdownPlatform(); }
57245724

5725-
bool v8::V8::Initialize() {
5725+
bool v8::V8::Initialize(const int build_config) {
5726+
const bool kEmbedderPointerCompression =
5727+
(build_config & kPointerCompression) != 0;
5728+
if (kEmbedderPointerCompression != COMPRESS_POINTERS_BOOL) {
5729+
FATAL(
5730+
"Embedder-vs-V8 build configuration mismatch. On embedder side "
5731+
"pointer compression is %s while on V8 side it's %s.",
5732+
kEmbedderPointerCompression ? "ENABLED" : "DISABLED",
5733+
COMPRESS_POINTERS_BOOL ? "ENABLED" : "DISABLED");
5734+
}
5735+
5736+
const int kEmbedderSmiValueSize = (build_config & k31BitSmis) ? 31 : 32;
5737+
if (kEmbedderSmiValueSize != internal::kSmiValueSize) {
5738+
FATAL(
5739+
"Embedder-vs-V8 build configuration mismatch. On embedder side "
5740+
"Smi value size is %d while on V8 side it's %d.",
5741+
kEmbedderSmiValueSize, internal::kSmiValueSize);
5742+
}
5743+
57265744
i::V8::Initialize();
57275745
return true;
57285746
}

0 commit comments

Comments
 (0)