Skip to content

Commit a625a98

Browse files
StefanStojanovictargos
authored andcommitted
deps: patch V8 13.4 to support compilation with MSVC
1 parent 2025345 commit a625a98

File tree

16 files changed

+129
-52
lines changed

16 files changed

+129
-52
lines changed

common.gypi

+1-1
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.9',
41+
'v8_embedder_string': '-node.10',
4242

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

deps/v8/src/base/fpu.cc

+14-2
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

+2-6
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/backend/instruction-selector.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,8 @@ struct InstructionSelectorT<Adapter>::CachedStateValues : public ZoneObject {
10091009

10101010
template <>
10111011
class InstructionSelectorT<TurbofanAdapter>::CachedStateValuesBuilder {
1012+
using StateObjectDeduplicator = InstructionSelectorT<TurbofanAdapter>::StateObjectDeduplicator;
1013+
10121014
public:
10131015
explicit CachedStateValuesBuilder(StateValueList* values,
10141016
InstructionOperandVector* inputs,
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/maglev/maglev-graph-builder.cc

+9-3
Original file line numberDiff line numberDiff line change
@@ -10206,13 +10206,19 @@ MaybeReduceResult MaglevGraphBuilder::TryReduceCallForNewClosure(
1020610206
return BuildCallRuntime(Runtime::kThrowConstructorNonCallableError,
1020710207
{target_node});
1020810208
}
10209-
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
10209+
10210+
#ifdef V8_ENABLE_LEAPTIERING
10211+
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
1021010212
target_context, target_node,
1021110213
GetRootConstant(RootIndex::kUndefinedValue),
10212-
#ifdef V8_ENABLE_LEAPTIERING
1021310214
dispatch_handle,
10214-
#endif
1021510215
shared, feedback_vector, args, feedback_source));
10216+
#else
10217+
RETURN_IF_DONE(TryBuildCallKnownJSFunction(
10218+
target_context, target_node,
10219+
GetRootConstant(RootIndex::kUndefinedValue),
10220+
shared, feedback_vector, args, feedback_source));
10221+
#endif
1021610222
}
1021710223
return BuildGenericCall(target_node, Call::TargetType::kJSFunction, args);
1021810224
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ HEAP_OBJECT_TYPE_LIST(DECL_TYPE)
3939
// Instance types which are associated with one unique map.
4040

4141
template <class type>
42-
V8_INLINE consteval std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
42+
V8_INLINE constexpr std::optional<RootIndex> UniqueMapOfInstanceTypeCheck() {
4343
return {};
4444
}
4545

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

deps/v8/src/runtime/runtime-test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,8 @@ RUNTIME_FUNCTION(Runtime_SetAllocationTimeout) {
11971197
namespace {
11981198

11991199
int FixedArrayLenFromSize(int size) {
1200-
return std::min({(size - OFFSET_OF_DATA_START(FixedArray)) / kTaggedSize,
1201-
FixedArray::kMaxRegularLength});
1200+
return std::min<int>((size - OFFSET_OF_DATA_START(FixedArray)) / kTaggedSize,
1201+
static_cast<int>(FixedArray::kMaxRegularLength));
12021202
}
12031203

12041204
void FillUpOneNewSpacePage(Isolate* isolate, Heap* heap,

deps/v8/third_party/rapidhash-v8/rapidhash.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ struct PlainHashReader {
153153
/*
154154
* Likely and unlikely macros.
155155
*/
156-
#define _likely_(x) __builtin_expect(x, 1)
157-
#define _unlikely_(x) __builtin_expect(x, 0)
156+
#if defined(_MSC_VER) && !defined(__clang__)
157+
#define _likely_(x) (x)
158+
#define _unlikely_(x) (x)
159+
#else
160+
#define _likely_(x) __builtin_expect(x, 1)
161+
#define _unlikely_(x) __builtin_expect(x, 0)
162+
#endif
158163

159164
/*
160165
* Default seed.

test/addons/esm-export/binding.gyp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding-export-default',
5+
'sources': [ 'binding-export-default.cc' ],
6+
'includes': ['../common.gypi'],
7+
},
8+
{
9+
'target_name': 'binding-export-primitive',
10+
'sources': [ 'binding-export-primitive.cc' ],
11+
'includes': ['../common.gypi'],
12+
},
13+
]
14+
}

test/addons/esm-export/test-esm.mjs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* This file is supposed to be loaded by `test-import.js` and `test-require.js`
3+
* to verify that `import('*.node')` is working properly either been loaded with
4+
* the ESM loader or the CJS loader.
5+
*/
6+
7+
import { buildType } from '../../common/index.mjs';
8+
import assert from 'node:assert';
9+
import { createRequire } from 'node:module';
10+
import { pathToFileURL } from 'node:url';
11+
12+
const require = createRequire(import.meta.url);
13+
14+
export async function run() {
15+
// binding-export-default.node
16+
{
17+
const bindingPath = require.resolve(`./build/${buildType}/binding-export-default.node`);
18+
// Test with order of require+import
19+
const bindingRequire = require(bindingPath);
20+
const ns = await import(pathToFileURL(bindingPath));
21+
assert.strictEqual(ns.default, bindingRequire);
22+
23+
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
24+
assert.strictEqual(ns.default, ns['module.exports']);
25+
assert.strictEqual(ns.default.default(), 'hello world');
26+
}
27+
28+
// binding-export-primitive.node
29+
{
30+
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
31+
const ns = await import(pathToFileURL(bindingPath));
32+
33+
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
34+
assert.strictEqual(ns.default, ns['module.exports']);
35+
assert.strictEqual(ns.default, 'hello world');
36+
}
37+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Flags: --experimental-addon-modules
2+
'use strict';
3+
const common = require('../../common');
4+
5+
require('./test-esm.mjs')
6+
.run().then(common.mustCall());

test/addons/esm/binding.gyp

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
{
22
'variables': {
3-
'source_dir': '<!(<(python) -c "import os; print(os.getcwd())")',
3+
'source_dir': '<!("<(python)" -c "import os; print(os.getcwd())")',
44
},
55
'targets': [
66
{
77
'target_name': 'binding',
88
'sources': [ 'binding.cc' ],
99
'includes': ['../common.gypi'],
1010
},
11-
{
12-
'target_name': 'binding-export-default',
13-
'sources': [ 'binding-export-default.cc' ],
14-
'includes': ['../common.gypi'],
15-
},
16-
{
17-
'target_name': 'binding-export-primitive',
18-
'sources': [ 'binding-export-primitive.cc' ],
19-
'includes': ['../common.gypi'],
20-
},
2111
{
2212
'target_name': 'node_modules',
2313
'type': 'none',

test/addons/esm/test-esm.mjs

-23
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,4 @@ export async function run() {
3131
assert.strictEqual(rebinding.hello(), 'world');
3232
assert.strictEqual(binding.hello, rebinding.hello);
3333
}
34-
35-
// binding-export-default.node
36-
{
37-
const bindingPath = require.resolve(`./build/${buildType}/binding-export-default.node`);
38-
// Test with order of require+import
39-
const bindingRequire = require(bindingPath);
40-
const ns = await import(pathToFileURL(bindingPath));
41-
assert.strictEqual(ns.default, bindingRequire);
42-
43-
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
44-
assert.strictEqual(ns.default, ns['module.exports']);
45-
assert.strictEqual(ns.default.default(), 'hello world');
46-
}
47-
48-
// binding-export-primitive.node
49-
{
50-
const bindingPath = require.resolve(`./build/${buildType}/binding-export-primitive.node`);
51-
const ns = await import(pathToFileURL(bindingPath));
52-
53-
// As same as ESM-import-CJS, the default export is the value of `module.exports`.
54-
assert.strictEqual(ns.default, ns['module.exports']);
55-
assert.strictEqual(ns.default, 'hello world');
56-
}
5734
}

0 commit comments

Comments
 (0)