-
Notifications
You must be signed in to change notification settings - Fork 15k
/
chore_add_v8_apple_silicon_patches.patch
134 lines (127 loc) · 6.06 KB
/
chore_add_v8_apple_silicon_patches.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <marshallofsound@electronjs.org>
Date: Mon, 6 Jul 2020 20:47:43 -0700
Subject: chore: add v8 apple silicon patches
Once these are available upstream we can remove this patch.
diff --git a/src/codegen/arm64/macro-assembler-arm64.cc b/src/codegen/arm64/macro-assembler-arm64.cc
index fef1758aaa81a85009461839ec9aa816e7d196a6..c0f7a1cf5fd4787896b06bce911aabf17b290e88 100644
--- a/src/codegen/arm64/macro-assembler-arm64.cc
+++ b/src/codegen/arm64/macro-assembler-arm64.cc
@@ -2975,6 +2975,35 @@ void TurboAssembler::PrintfNoPreserve(const char* format,
int arg_count = kPrintfMaxArgCount;
+#if V8_OS_MACOSX && !USE_SIMULATOR
+ CPURegList tmp_list = kCallerSaved;
+ tmp_list.Remove(x0); // Used to pass the format string.
+ tmp_list.Remove(arg0, arg1, arg2, arg3);
+
+ // Override the MacroAssembler's scratch register list. The lists will be
+ // reset automatically at the end of the UseScratchRegisterScope.
+ UseScratchRegisterScope temps(this);
+ TmpList()->set_list(tmp_list.list());
+
+ VRegister temp_D = temps.AcquireD();
+
+ // https://developer.apple.com/library/archive/documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARM64FunctionCallingConventions.html#//apple_ref/doc/uid/TP40013702-SW1
+ Claim(kPrintfMaxArgCount, 8);
+ int64_t offset = 0;
+ for (unsigned i = 0; i < kPrintfMaxArgCount; i++) {
+ CPURegister arg = args[i];
+ if (arg.IsNone()) {
+ break;
+ }
+ if (arg.IsS()) {
+ fcvt(temp_D, arg.S());
+ arg = temp_D;
+ }
+ // FIXME: Use stp.
+ str(arg, MemOperand(sp, offset, Offset));
+ offset += 8;
+ }
+#else
// The PCS varargs registers for printf. Note that x0 is used for the printf
// format string.
static const CPURegList kPCSVarargs =
@@ -3085,7 +3114,7 @@ void TurboAssembler::PrintfNoPreserve(const char* format,
}
#endif
}
-
+#endif
// Load the format string into x0, as per the procedure-call standard.
//
// To make the code as portable as possible, the format string is encoded
@@ -3107,6 +3136,10 @@ void TurboAssembler::PrintfNoPreserve(const char* format,
}
CallPrintf(arg_count, pcs);
+
+#if V8_OS_MACOSX && !USE_SIMULATOR
+ Drop(kPrintfMaxArgCount, 8);
+#endif
}
void TurboAssembler::CallPrintf(int arg_count, const CPURegister* args) {
diff --git a/src/compiler/backend/arm64/instruction-selector-arm64.cc b/src/compiler/backend/arm64/instruction-selector-arm64.cc
index fac7f9c1d1146b36b57aa70565fc86a1604887c8..6c13a0747009e38fd574ba94d38b6654fdd70edf 100644
--- a/src/compiler/backend/arm64/instruction-selector-arm64.cc
+++ b/src/compiler/backend/arm64/instruction-selector-arm64.cc
@@ -1898,6 +1898,7 @@ void InstructionSelector::EmitPrepareArguments(
// Poke the arguments into the stack.
while (slot >= 0) {
+ // FIXME: In the Apple ARM64 ABI parameters should be packed on the stack.
PushParameter input0 = (*arguments)[slot];
PushParameter input1 = slot > 0 ? (*arguments)[slot - 1] : PushParameter();
// Emit a poke-pair if consecutive parameters have the same type.
diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.h
index ab689283e970a79bc02dbeee7a4a74720265fcd7..12e54765d316f97297ad0a999ca32c5d07872580 100644
--- a/src/flags/flag-definitions.h
+++ b/src/flags/flag-definitions.h
@@ -763,7 +763,12 @@ DEFINE_INT(wasm_num_compilation_tasks, 128,
"maximum number of parallel compilation tasks for wasm")
DEFINE_DEBUG_BOOL(trace_wasm_native_heap, false,
"trace wasm native heap events")
-DEFINE_BOOL(wasm_write_protect_code_memory, false,
+#if V8_OS_MACOSX && V8_TARGET_ARCH_ARM64
+#define V8_DEFAULT_WASM_WRITE_PROTECT_CODE_MEMORY true
+#else
+#define V8_DEFAULT_WASM_WRITE_PROTECT_CODE_MEMORY false
+#endif
+DEFINE_BOOL(wasm_write_protect_code_memory, V8_DEFAULT_WASM_WRITE_PROTECT_CODE_MEMORY,
"write protect code memory on the wasm native heap")
DEFINE_DEBUG_BOOL(trace_wasm_serialization, false,
"trace serialization/deserialization")
diff --git a/src/wasm/function-compiler.cc b/src/wasm/function-compiler.cc
index 8b41a90992f58c535df285e7fa569b51ae31f85d..1ff813abf44d25e8f2fd84b236623b74913684fb 100644
--- a/src/wasm/function-compiler.cc
+++ b/src/wasm/function-compiler.cc
@@ -258,6 +258,7 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
isolate->counters(), detected);
if (result.succeeded()) {
WasmCodeRefScope code_ref_scope;
+ NativeModuleModificationScope native_module_modification_scope(native_module);
native_module->PublishCode(
native_module->AddCompiledCode(std::move(result)));
} else {
diff --git a/src/wasm/wasm-code-manager.h b/src/wasm/wasm-code-manager.h
index 5e8ed5475bb064cb657069242ce7517de7f5f8e2..5652bb407da3646e55c42492b3e9facec4556367 100644
--- a/src/wasm/wasm-code-manager.h
+++ b/src/wasm/wasm-code-manager.h
@@ -886,7 +886,7 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
// and even if we did, the resulting set of pages may be fragmented.
// Currently, we try and keep the number of syscalls low.
// - similar argument for debug time.
-class NativeModuleModificationScope final {
+class V8_EXPORT_PRIVATE NativeModuleModificationScope final {
public:
explicit NativeModuleModificationScope(NativeModule* native_module);
~NativeModuleModificationScope();
diff --git a/src/wasm/wasm-objects.cc b/src/wasm/wasm-objects.cc
index cf78ab5ff3286d6c07527a323eac4213255fe825..b89433d445f46110ba6cacfc6ec930d31171fd1f 100644
--- a/src/wasm/wasm-objects.cc
+++ b/src/wasm/wasm-objects.cc
@@ -1512,6 +1512,7 @@ void WasmInstanceObject::ImportWasmJSFunctionIntoTable(
wasm::WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
isolate->wasm_engine(), &env, kind, sig, false,
shared.internal_formal_parameter_count());
+ wasm::NativeModuleModificationScope native_module_modification_scope(native_module);
std::unique_ptr<wasm::WasmCode> wasm_code = native_module->AddCode(
result.func_index, result.code_desc, result.frame_slot_count,
result.tagged_parameter_slots,