Skip to content

Instantly share code, notes, and snippets.

@evanlucas
Created July 21, 2020 13:50
Show Gist options
  • Save evanlucas/40bd76f6504a2adfe94c73a5eca32e6a to your computer and use it in GitHub Desktop.
Save evanlucas/40bd76f6504a2adfe94c73a5eca32e6a to your computer and use it in GitHub Desktop.
diff that gets tests working on arm64
diff --git a/deps/v8/src/base/platform/platform-macos.cc b/deps/v8/src/base/platform/platform-macos.cc
index bee6b30f7c..055da2605e 100644
--- a/deps/v8/src/base/platform/platform-macos.cc
+++ b/deps/v8/src/base/platform/platform-macos.cc
@@ -49,7 +49,7 @@ std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
for (unsigned int i = 0; i < images_count; ++i) {
const mach_header* header = _dyld_get_image_header(i);
if (header == nullptr) continue;
-#if V8_HOST_ARCH_X64
+#if V8_HOST_ARCH_X64 || V8_HOST_ARCH_ARM64
uint64_t size;
char* code_ptr = getsectdatafromheader_64(
reinterpret_cast<const mach_header_64*>(header), SEG_TEXT, SECT_TEXT,
diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc
index 54f72e04e6..b556357c69 100644
--- a/deps/v8/src/base/platform/platform-posix.cc
+++ b/deps/v8/src/base/platform/platform-posix.cc
@@ -147,9 +147,19 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
void* Allocate(void* hint, size_t size, OS::MemoryPermission access) {
int prot = GetProtectionFromMemoryPermission(access);
int flags = GetFlagsForMemoryPermission(access);
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM64 && defined(__x86_64__)
+ // XXX: This logic is simple and leaky as it is only used for mksnapshot.
+ size_t alignment = 16384;
+ void* result = mmap(hint, size + alignment, prot, flags, kMmapFd,
+ kMmapFdOffset);
+ if (result == MAP_FAILED) return nullptr;
+ return reinterpret_cast<void*>(
+ RoundUp(reinterpret_cast<uintptr_t>(result), alignment));
+#else
void* result = mmap(hint, size, prot, flags, kMmapFd, kMmapFdOffset);
if (result == MAP_FAILED) return nullptr;
return result;
+#endif
}
#endif // !V8_OS_FUCHSIA
@@ -206,7 +216,9 @@ void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
}
int OS::ActivationFrameAlignment() {
-#if V8_TARGET_ARCH_ARM
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM
+ return 4;
+#elif V8_TARGET_ARCH_ARM
// On EABI ARM targets this is required for fp correctness in the
// runtime system.
return 8;
@@ -226,13 +238,21 @@ int OS::ActivationFrameAlignment() {
// static
size_t OS::AllocatePageSize() {
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM64 && defined(__x86_64__)
+ return 16384;
+#else
return static_cast<size_t>(sysconf(_SC_PAGESIZE));
+#endif
}
// static
size_t OS::CommitPageSize() {
+#if defined(__APPLE__) && V8_TARGET_ARCH_ARM64 && defined(__x86_64__)
+ return 16384;
+#else
static size_t page_size = getpagesize();
return page_size;
+#endif
}
// static
diff --git a/deps/v8/src/codegen/arm64/macro-assembler-arm64.cc b/deps/v8/src/codegen/arm64/macro-assembler-arm64.cc
index 1273904c9c..f843759811 100644
--- a/deps/v8/src/codegen/arm64/macro-assembler-arm64.cc
+++ b/deps/v8/src/codegen/arm64/macro-assembler-arm64.cc
@@ -2940,6 +2940,36 @@ 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 =
@@ -3025,6 +3055,8 @@ void TurboAssembler::PrintfNoPreserve(const char* format,
}
}
+#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
@@ -3046,6 +3078,10 @@ void TurboAssembler::PrintfNoPreserve(const char* format,
}
CallPrintf(arg_count, pcs);
+
+#if V8_OS_MACOSX && !USE_SIMULATOR
+ Drop(arg_count, 8);
+#endif
}
void TurboAssembler::CallPrintf(int arg_count, const CPURegister* args) {
diff --git a/deps/v8/src/execution/frames-inl.h b/deps/v8/src/execution/frames-inl.h
index e73cca4f05..ea679d0132 100644
--- a/deps/v8/src/execution/frames-inl.h
+++ b/deps/v8/src/execution/frames-inl.h
@@ -77,6 +77,10 @@ inline Address StackFrame::callee_pc() const {
inline Address StackFrame::pc() const { return ReadPC(pc_address()); }
+inline Address StackFrame::unauthenticated_pc() const {
+ return PointerAuthentication::StripPAC(*pc_address());
+}
+
inline Address StackFrame::ReadPC(Address* pc_address) {
return PointerAuthentication::AuthenticatePC(pc_address, kSystemPointerSize);
}
diff --git a/deps/v8/src/execution/frames.cc b/deps/v8/src/execution/frames.cc
index 7d405efa5e..c67b4a470c 100644
--- a/deps/v8/src/execution/frames.cc
+++ b/deps/v8/src/execution/frames.cc
@@ -315,6 +315,7 @@ SafeStackFrameIterator::SafeStackFrameIterator(Isolate* isolate, Address pc,
// return address into the interpreter entry trampoline, then we are likely
// in a bytecode handler with elided frame. In that case, set the PC
// properly and make sure we do not drop the frame.
+ bool is_no_frame_bytecode_handler = false;
if (IsNoFrameBytecodeHandlerPc(isolate, pc, fp)) {
Address* tos_location = nullptr;
if (top_link_register_) {
@@ -326,6 +327,7 @@ SafeStackFrameIterator::SafeStackFrameIterator(Isolate* isolate, Address pc,
if (IsInterpreterFramePc(isolate, *tos_location, &state)) {
state.pc_address = tos_location;
+ is_no_frame_bytecode_handler = true;
advance_frame = false;
}
}
@@ -338,7 +340,11 @@ SafeStackFrameIterator::SafeStackFrameIterator(Isolate* isolate, Address pc,
StandardFrameConstants::kContextOffset);
Address frame_marker = fp + StandardFrameConstants::kFunctionOffset;
if (IsValidStackAddress(frame_marker)) {
- type = StackFrame::ComputeType(this, &state);
+ if (is_no_frame_bytecode_handler) {
+ type = StackFrame::INTERPRETED;
+ } else {
+ type = StackFrame::ComputeType(this, &state);
+ }
top_frame_type_ = type;
// We only keep the top frame if we believe it to be interpreted frame.
if (type != StackFrame::INTERPRETED) {
diff --git a/deps/v8/src/execution/frames.h b/deps/v8/src/execution/frames.h
index bd50cda8f8..b773dd71da 100644
--- a/deps/v8/src/execution/frames.h
+++ b/deps/v8/src/execution/frames.h
@@ -229,6 +229,11 @@ class StackFrame {
inline Address pc() const;
+ // Skip authentication of the PC, when using CFI. Used in the profiler, where
+ // in certain corner-cases we do not use an address on the stack, which would
+ // be signed, as the PC of the frame.
+ inline Address unauthenticated_pc() const;
+
Address constant_pool() const { return *constant_pool_address(); }
void set_constant_pool(Address constant_pool) {
*constant_pool_address() = constant_pool;
diff --git a/deps/v8/src/flags/flag-definitions.h b/deps/v8/src/flags/flag-definitions.h
index 2384cf4a28..3d7b3b77dc 100644
--- a/deps/v8/src/flags/flag-definitions.h
+++ b/deps/v8/src/flags/flag-definitions.h
@@ -669,8 +669,13 @@ 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")
+#if V8_OS_MACOSX && V8_TARGET_ARCH_ARM64
+DEFINE_BOOL(wasm_write_protect_code_memory, true,
+ "write protect code memory on the wasm native heap")
+#else
DEFINE_BOOL(wasm_write_protect_code_memory, false,
"write protect code memory on the wasm native heap")
+#endif
DEFINE_DEBUG_BOOL(trace_wasm_serialization, false,
"trace serialization/deserialization")
DEFINE_BOOL(wasm_async_compilation, true,
diff --git a/deps/v8/src/heap/cppgc/asm/x64/push_registers.S b/deps/v8/src/heap/cppgc/asm/x64/push_registers.S
index 018859d5c0..265b8a393b 100644
--- a/deps/v8/src/heap/cppgc/asm/x64/push_registers.S
+++ b/deps/v8/src/heap/cppgc/asm/x64/push_registers.S
@@ -10,6 +10,9 @@
.globl _PushAllRegistersAndIterateStack
_PushAllRegistersAndIterateStack:
+#if defined(__arm64__)
+.align 2
+#endif
#else // !V8_TARGET_OS_MACOSX
diff --git a/deps/v8/src/libsampler/sampler.cc b/deps/v8/src/libsampler/sampler.cc
index e2091ceb32..0443657d1e 100644
--- a/deps/v8/src/libsampler/sampler.cc
+++ b/deps/v8/src/libsampler/sampler.cc
@@ -468,7 +468,14 @@ void SignalHandler::FillRegisterState(void* context, RegisterState* state) {
state->pc = reinterpret_cast<void*>(mcontext->__ss.__eip);
state->sp = reinterpret_cast<void*>(mcontext->__ss.__esp);
state->fp = reinterpret_cast<void*>(mcontext->__ss.__ebp);
-#endif // V8_HOST_ARCH_IA32
+#elif V8_HOST_ARCH_ARM64
+ state->pc =
+ reinterpret_cast<void*>(arm_thread_state64_get_pc(mcontext->__ss));
+ state->sp =
+ reinterpret_cast<void*>(arm_thread_state64_get_sp(mcontext->__ss));
+ state->fp =
+ reinterpret_cast<void*>(arm_thread_state64_get_fp(mcontext->__ss));
+#endif // V8_HOST_ARCH_*
#elif V8_OS_FREEBSD
#if V8_HOST_ARCH_IA32
state->pc = reinterpret_cast<void*>(mcontext.mc_eip);
diff --git a/deps/v8/src/profiler/tick-sample.cc b/deps/v8/src/profiler/tick-sample.cc
index 00bff91cd0..30577db6df 100644
--- a/deps/v8/src/profiler/tick-sample.cc
+++ b/deps/v8/src/profiler/tick-sample.cc
@@ -337,7 +337,7 @@ bool TickSample::GetStackSample(Isolate* v8_isolate, RegisterState* regs,
continue;
}
}
- frames[i++] = reinterpret_cast<void*>(it.frame()->pc());
+ frames[i++] = reinterpret_cast<void*>(it.frame()->unauthenticated_pc());
}
sample_info->frames_count = i;
return true;
diff --git a/deps/v8/src/wasm/function-compiler.cc b/deps/v8/src/wasm/function-compiler.cc
index 1b6b83a3b1..45343c0b0a 100644
--- a/deps/v8/src/wasm/function-compiler.cc
+++ b/deps/v8/src/wasm/function-compiler.cc
@@ -258,6 +258,8 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
isolate->counters(), detected);
if (result.succeeded()) {
WasmCodeRefScope code_ref_scope;
+ NativeModuleModificationScope native_module_modification_scope(
+ native_module);
native_module->AddCompiledCode(std::move(result));
} else {
native_module->compilation_state()->SetError();
diff --git a/deps/v8/src/wasm/wasm-code-manager.h b/deps/v8/src/wasm/wasm-code-manager.h
index 4b176f3ba6..14654f0f15 100644
--- a/deps/v8/src/wasm/wasm-code-manager.h
+++ b/deps/v8/src/wasm/wasm-code-manager.h
@@ -830,7 +830,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/deps/v8/src/wasm/wasm-objects.cc b/deps/v8/src/wasm/wasm-objects.cc
index 41b9d50312..fcaf29ccfc 100644
--- a/deps/v8/src/wasm/wasm-objects.cc
+++ b/deps/v8/src/wasm/wasm-objects.cc
@@ -1467,6 +1467,8 @@ void WasmInstanceObject::ImportWasmJSFunctionIntoTable(
wasm::CompilationEnv env = native_module->CreateCompilationEnv();
wasm::WasmCompilationResult result = compiler::CompileWasmImportCallWrapper(
isolate->wasm_engine(), &env, kind, sig, false);
+ 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,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment