Commit 2db93c02 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[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: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67116}
parent e0433f7d
......@@ -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
......
......@@ -9610,7 +9610,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
......@@ -9744,6 +9749,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,
......
......@@ -5722,7 +5722,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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment