Skip to content

Commit eabc4fb

Browse files
deps: patch V8 to support compilation with MSVC
Co-Authored-By: Michaël Zasso <[email protected]>
1 parent ca3fffb commit eabc4fb

File tree

21 files changed

+147
-60
lines changed

21 files changed

+147
-60
lines changed

common.gypi

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

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.8',
41+
'v8_embedder_string': '-node.9',
4242

4343
##### V8 defaults for Node.js #####
4444

deps/v8/src/base/fpu.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ void FPU::SetFlushDenormals(bool value) {
5757
#elif defined(V8_HOST_ARCH_ARM64) || defined(V8_HOST_ARCH_ARM)
5858

5959
namespace {
60+
#if defined(V8_HOST_ARCH_ARM64) && defined(_MSC_VER) && !defined(__clang__)
61+
#include <intrin.h>
62+
#endif
63+
6064
// Bit 24 is the flush-to-zero mode control bit. Setting it to 1 flushes
6165
// denormals to 0.
6266
constexpr int kFlushDenormToZeroBit = (1 << 24);
6367
int GetStatusWord() {
6468
int result;
6569
#if defined(V8_HOST_ARCH_ARM64)
66-
asm volatile("mrs %x[result], FPCR" : [result] "=r"(result));
70+
# if defined(_MSC_VER) && !defined(__clang__)
71+
result = _ReadStatusReg(ARM64_FPCR);
72+
# else
73+
asm volatile("mrs %x[result], FPCR" : [result] "=r"(result));
74+
# endif
6775
#else
6876
asm volatile("vmrs %[result], FPSCR" : [result] "=r"(result));
6977
#endif
@@ -72,7 +80,11 @@ int GetStatusWord() {
7280

7381
void SetStatusWord(int a) {
7482
#if defined(V8_HOST_ARCH_ARM64)
75-
asm volatile("msr FPCR, %x[src]" : : [src] "r"(a));
83+
# if defined(_MSC_VER) && !defined(__clang__)
84+
_WriteStatusReg(ARM64_FPCR, a);
85+
# else
86+
asm volatile("msr FPCR, %x[src]" : : [src] "r"(a));
87+
# endif
7688
#else
7789
asm volatile("vmsr FPSCR, %[src]" : : [src] "r"(a));
7890
#endif

deps/v8/src/codegen/arm64/assembler-arm64.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,10 @@ class AssemblerZone {
168168
public:
169169
explicit AssemblerZone(const MaybeAssemblerZone& zone)
170170
// Create a fresh Zone unless one is already provided.
171-
: maybe_local_zone_(
172-
std::holds_alternative<Zone*>(zone)
173-
? std::nullopt
174-
: std::make_optional<Zone>(std::get<AccountingAllocator*>(zone),
175-
ZONE_NAME)),
171+
: maybe_local_zone_(),
176172
zone_(std::holds_alternative<Zone*>(zone)
177173
? std::get<Zone*>(zone)
178-
: &maybe_local_zone_.value()) {}
174+
: &maybe_local_zone_.emplace(std::get<AccountingAllocator*>(zone), ZONE_NAME)) {}
179175

180176
Zone* get() const { return zone_; }
181177

deps/v8/src/compiler/js-heap-broker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ ElementAccessFeedback const& JSHeapBroker::ProcessFeedbackMapsForElementAccess(
879879
Tagged<Map> transition_target;
880880

881881
// Don't generate elements kind transitions from stable maps.
882-
if (!map.is_stable()) {
882+
if (!map.is_stable() && possible_transition_targets.begin() != possible_transition_targets.end()) {
883883
// The lock is needed for UnusedPropertyFields (called deep inside
884884
// FindElementsKindTransitionedMap).
885885
MapUpdaterGuardIfNeeded mumd_scope(this);

deps/v8/src/execution/frames.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,11 +1292,11 @@ class WasmFrame : public TypedFrame {
12921292
FrameSummaries Summarize() const override;
12931293

12941294
static WasmFrame* cast(StackFrame* frame) {
1295-
DCHECK(frame->is_wasm()
12961295
#ifdef V8_ENABLE_DRUMBRAKE
1297-
&& !frame->is_wasm_interpreter_entry()
1296+
DCHECK(frame->is_wasm() && !frame->is_wasm_interpreter_entry());
1297+
#else
1298+
DCHECK(frame->is_wasm());
12981299
#endif // V8_ENABLE_DRUMBRAKE
1299-
);
13001300
return static_cast<WasmFrame*>(frame);
13011301
}
13021302

deps/v8/src/execution/isolate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,14 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
574574
#define THREAD_LOCAL_TOP_ADDRESS(type, name) \
575575
inline type* name##_address() { return &thread_local_top()->name##_; }
576576

577+
#if defined(_MSC_VER)
578+
extern thread_local Isolate* g_current_isolate_ V8_CONSTINIT;
579+
#else
577580
// Do not use this variable directly, use Isolate::Current() instead.
578581
// Defined outside of Isolate because Isolate uses V8_EXPORT_PRIVATE.
579582
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local Isolate*
580583
g_current_isolate_ V8_CONSTINIT;
584+
#endif // defined(_MSC_VER)
581585

582586
// HiddenFactory exists so Isolate can privately inherit from it without making
583587
// Factory's members available to Isolate directly.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; Copyright 2020 the V8 project authors. All rights reserved.
2+
; Use of this source code is governed by a BSD-style license that can be
3+
; found in the LICENSE file.
4+
5+
; This file is exactly the same as push_registers_asm.cc, just formatted for
6+
; the Microsoft Arm Assembler.
7+
8+
AREA |.text|, CODE, ALIGN=4, READONLY
9+
EXPORT PushAllRegistersAndIterateStack
10+
PushAllRegistersAndIterateStack
11+
; x19-x29 are callee-saved
12+
STP x19, x20, [sp, #-16]!
13+
STP x21, x22, [sp, #-16]!
14+
STP x23, x24, [sp, #-16]!
15+
STP x25, x26, [sp, #-16]!
16+
STP x27, x28, [sp, #-16]!
17+
STP fp, lr, [sp, #-16]!
18+
; Maintain frame pointer
19+
MOV fp, sp
20+
; Pass 1st parameter (x0) unchanged (Stack*).
21+
; Pass 2nd parameter (x1) unchanged (StackVisitor*).
22+
; Save 3rd parameter (x2; IterateStackCallback)
23+
MOV x7, x2
24+
; Pass 3rd parameter as sp (stack pointer)
25+
MOV x2, sp
26+
BLR x7
27+
; Load return address
28+
LDR lr, [sp, #8]
29+
; Restore frame pointer and pop all callee-saved registers.
30+
LDR fp, [sp], #96
31+
RET
32+
END

deps/v8/src/heap/local-heap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ class MarkingBarrier;
3333
class MutablePageMetadata;
3434
class Safepoint;
3535

36+
#if defined(_MSC_VER)
37+
extern thread_local LocalHeap* g_current_local_heap_ V8_CONSTINIT;
38+
#else
3639
// Do not use this variable directly, use LocalHeap::Current() instead.
3740
// Defined outside of LocalHeap because LocalHeap uses V8_EXPORT_PRIVATE.
3841
__attribute__((tls_model(V8_TLS_MODEL))) extern thread_local LocalHeap*
3942
g_current_local_heap_ V8_CONSTINIT;
43+
#endif // defined(_MSC_VER)
4044

4145
// LocalHeap is used by the GC to track all threads with heap access in order to
4246
// stop them before performing a collection. LocalHeaps can be either Parked or

deps/v8/src/maglev/maglev-graph-builder.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11003,13 +11003,19 @@ MaybeReduceResult MaglevGraphBuilder::TryReduceCallForNewClosure(
1100311003
return BuildCallRuntime(Runtime::kThrowConstructorNonCallableError,
1100411004
{target_node});
1100511005
}
11006-
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
11006+
11007+
#ifdef V8_ENABLE_LEAPTIERING
11008+
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
1100711009
target_context, target_node,
1100811010
GetRootConstant(RootIndex::kUndefinedValue),
11009-
#ifdef V8_ENABLE_LEAPTIERING
1101011011
dispatch_handle,
11011-
#endif
1101211012
shared, feedback_cell, args, feedback_source));
11013+
#else
11014+
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
11015+
target_context, target_node,
11016+
GetRootConstant(RootIndex::kUndefinedValue),
11017+
shared, feedback_cell, args, feedback_source));
11018+
#endif
1101311019
}
1101411020
return BuildGenericCall(target_node, Call::TargetType::kJSFunction, args);
1101511021
}

deps/v8/src/objects/instance-type-inl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ HEAP_OBJECT_TYPE_LIST(DECL_TYPE)
4242
// Instance types which are associated with one unique map.
4343

4444
template <class type>
45-
V8_INLINE consteval std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
45+
V8_INLINE constexpr std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
4646
return {};
4747
}
4848

4949
#define INSTANCE_TYPE_MAP(V, rootIndexName, rootAccessorName, class_name) \
5050
template <> \
51-
V8_INLINE consteval std::optional<RootIndex> \
51+
V8_INLINE constexpr std::optional<RootIndex> \
5252
UniqueMapOfInstanceTypeCheck<InstanceTypeTraits::class_name>() { \
5353
return {RootIndex::k##rootIndexName}; \
5454
}

0 commit comments

Comments
 (0)