Skip to content

Commit

Permalink
Fix hang in V8 debug builds
Browse files Browse the repository at this point in the history
This is a partial cherry-pick of upstream commit v8/v8@8953e49478.

Shows up in debug builds because of a buggy sanity check when computing
relationships between command line flags.

Example of the hang:

    #include "v8.h"
    #include "libplatform/libplatform.h"
    int main(void) {
      // works: v8::V8::SetFlagsFromString("--gc-global --noincremental-marking");
      v8::V8::SetFlagsFromString("--gc-global");
      v8::V8::SetFlagsFromString("--noincremental-marking");
      v8::V8::InitializePlatform(v8::platform::NewDefaultPlatform().release());
      v8::V8::Initialize(); // hangs in ComputeFlagListHash when defined(DEBUG)
    }
  • Loading branch information
bnoordhuis committed Oct 7, 2024
1 parent 309d2ef commit 5a35928
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions libexec/extract-node
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ cd "${src}/node-v${version}"
patch -p1 < "${top}"/patch/v8-std-is-trivially-destructible.patch
patch -p1 < "${top}"/patch/v8-disable-madv-dontfork.patch
patch -p1 < "${top}"/patch/v8-disable-pkey.patch
patch -p1 < "${top}"/patch/v8-debug-flags-hang.patch
26 changes: 26 additions & 0 deletions patch/v8-debug-flags-hang.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/deps/v8/src/flags/flags-impl.h b/deps/v8/src/flags/flags-impl.h
index d2d440c026..111b9b5b9c 100644
--- a/deps/v8/src/flags/flags-impl.h
+++ b/deps/v8/src/flags/flags-impl.h
@@ -5,6 +5,8 @@
#ifndef V8_FLAGS_FLAGS_IMPL_H_
#define V8_FLAGS_FLAGS_IMPL_H_

+#include <unordered_set>
+
#include "src/base/macros.h"
#include "src/base/optional.h"
#include "src/base/vector.h"
@@ -91,9 +93,12 @@ struct Flag {
#ifdef DEBUG
bool ImpliedBy(const void* ptr) const {
const Flag* current = this->implied_by_ptr_;
+ std::unordered_set<const Flag*> visited_flags;
while (current != nullptr) {
+ visited_flags.insert(current);
if (current->PointsTo(ptr)) return true;
current = current->implied_by_ptr_;
+ if (visited_flags.contains(current)) break;
}
return false;
}

0 comments on commit 5a35928

Please sign in to comment.