File
Blob: patches/v8/0011-Revert-heap-Add-masm-specific-unwinding-annotations-.patch
| 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Erik Corry <erikcorry@chromium.org> |
| 3 | Date: Wed, 26 Feb 2025 18:44:05 +0100 |
| 4 | Subject: Revert "heap: Add masm-specific unwinding annotations to GC |
| 5 | |
| 6 | This reverts commit 42bc7bfdf56cc7a8cd7757d96aa70b83ce82d9ff. |
| 7 | |
| 8 | This commit broke our build, because we patch V8 to build push_registers_asm.cc |
| 9 | with clang-cl on Windows, and this commit makes it an error to compile that |
| 10 | file on Windows with any compiler. Maybe clang-cl and masm can be used |
| 11 | together? I'm not sure. In the meantime, I'm reverting this commit in the hope |
| 12 | of getting our V8 upgrade unblocked. |
| 13 | |
| 14 | Signed-off-by: James M Snell <jsnell@cloudflare.com> |
| 15 | |
| 16 | diff --git a/BUILD.gn b/BUILD.gn |
| 17 | index 382c7d3ed44eab5df1f33082d0d0ef85121bc47c..5d5320c956b322ac9beef18688c9faa0bb10477f 100644 |
| 18 | --- a/BUILD.gn |
| 19 | +++ b/BUILD.gn |
| 20 | @@ -4638,8 +4638,8 @@ v8_header_set("v8_internal_headers") { |
| 21 | "src/tasks/operations-barrier.h", |
| 22 | "src/tasks/task-utils.h", |
| 23 | "src/torque/runtime-macro-shims.h", |
| 24 | - "src/tracing/trace-event-no-perfetto.h", |
| 25 | "src/tracing/trace-event.h", |
| 26 | + "src/tracing/trace-event-no-perfetto.h", |
| 27 | "src/tracing/trace-id.h", |
| 28 | "src/tracing/traced-value.h", |
| 29 | "src/tracing/tracing-category-observer.h", |
| 30 | @@ -7560,12 +7560,7 @@ v8_source_set("v8_heap_base") { |
| 31 | ] |
| 32 | |
| 33 | if (current_cpu == "x64") { |
| 34 | - if (is_win) { |
| 35 | - # Prefer a masm version with unwind directives. |
| 36 | - sources += [ "src/heap/base/asm/x64/push_registers_masm.asm" ] |
| 37 | - } else { |
| 38 | - sources += [ "src/heap/base/asm/x64/push_registers_asm.cc" ] |
| 39 | - } |
| 40 | + sources += [ "src/heap/base/asm/x64/push_registers_asm.cc" ] |
| 41 | } else if (current_cpu == "x86") { |
| 42 | sources += [ "src/heap/base/asm/ia32/push_registers_asm.cc" ] |
| 43 | } else if (current_cpu == "arm") { |
| 44 | diff --git a/src/heap/base/asm/x64/push_registers_asm.cc b/src/heap/base/asm/x64/push_registers_asm.cc |
| 45 | index d1d79dcfd5a8fce8240d8981b25c8027e220b03b..3f17db19310ff64e9316d0bb8308e399f5ce1422 100644 |
| 46 | --- a/src/heap/base/asm/x64/push_registers_asm.cc |
| 47 | +++ b/src/heap/base/asm/x64/push_registers_asm.cc |
| 48 | @@ -14,16 +14,61 @@ |
| 49 | |
| 50 | // Do not depend on V8_TARGET_OS_* defines as some embedders may override the |
| 51 | // GN toolchain (e.g. ChromeOS) and not provide them. |
| 52 | +// _WIN64 Defined as 1 when the compilation target is 64-bit ARM or x64. |
| 53 | +// Otherwise, undefined. |
| 54 | +#ifdef _WIN64 |
| 55 | |
| 56 | // We maintain 16-byte alignment at calls. There is an 8-byte return address |
| 57 | -// on the stack and we push 56 bytes which maintains 16-byte stack alignment |
| 58 | +// on the stack and we push 232 bytes which maintains 16-byte stack alignment |
| 59 | // at the call. |
| 60 | -// Source: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf |
| 61 | +// Source: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention |
| 62 | +asm(".att_syntax \n" |
| 63 | + ".globl PushAllRegistersAndIterateStack \n" |
| 64 | + "PushAllRegistersAndIterateStack: \n" |
| 65 | + // rbp is callee-saved. Maintain proper frame pointer for debugging. |
| 66 | + " push %rbp \n" |
| 67 | + " mov %rsp, %rbp \n" |
| 68 | + // Dummy for alignment. |
| 69 | + " push $0xCDCDCD \n" |
| 70 | + " push %rsi \n" |
| 71 | + " push %rdi \n" |
| 72 | + " push %rbx \n" |
| 73 | + " push %r12 \n" |
| 74 | + " push %r13 \n" |
| 75 | + " push %r14 \n" |
| 76 | + " push %r15 \n" |
| 77 | + " sub $160, %rsp \n" |
| 78 | + // Use aligned instrs as we are certain that the stack is properly aligned. |
| 79 | + " movdqa %xmm6, 144(%rsp) \n" |
| 80 | + " movdqa %xmm7, 128(%rsp) \n" |
| 81 | + " movdqa %xmm8, 112(%rsp) \n" |
| 82 | + " movdqa %xmm9, 96(%rsp) \n" |
| 83 | + " movdqa %xmm10, 80(%rsp) \n" |
| 84 | + " movdqa %xmm11, 64(%rsp) \n" |
| 85 | + " movdqa %xmm12, 48(%rsp) \n" |
| 86 | + " movdqa %xmm13, 32(%rsp) \n" |
| 87 | + " movdqa %xmm14, 16(%rsp) \n" |
| 88 | + " movdqa %xmm15, (%rsp) \n" |
| 89 | + // Pass 1st parameter (rcx) unchanged (Stack*). |
| 90 | + // Pass 2nd parameter (rdx) unchanged (StackVisitor*). |
| 91 | + // Save 3rd parameter (r8; IterateStackCallback) |
| 92 | + " mov %r8, %r9 \n" |
| 93 | + // Pass 3rd parameter as rsp (stack pointer). |
| 94 | + " mov %rsp, %r8 \n" |
| 95 | + // Call the callback. |
| 96 | + " call *%r9 \n" |
| 97 | + // Pop the callee-saved registers. |
| 98 | + " add $224, %rsp \n" |
| 99 | + // Restore rbp as it was used as frame pointer. |
| 100 | + " pop %rbp \n" |
| 101 | + " ret \n"); |
| 102 | |
| 103 | -#ifdef _WIN64 |
| 104 | -#error "The masm based version must be used for Windows" |
| 105 | -#endif |
| 106 | +#else // !_WIN64 |
| 107 | |
| 108 | +// We maintain 16-byte alignment at calls. There is an 8-byte return address |
| 109 | +// on the stack and we push 56 bytes which maintains 16-byte stack alignment |
| 110 | +// at the call. |
| 111 | +// Source: https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf |
| 112 | asm( |
| 113 | #ifdef __APPLE__ |
| 114 | ".globl _PushAllRegistersAndIterateStack \n" |
| 115 | @@ -81,3 +126,5 @@ asm( |
| 116 | ".Lfunc_end0-PushAllRegistersAndIterateStack \n" |
| 117 | #endif // !defined(__APPLE__) |
| 118 | ".cfi_endproc \n"); |
| 119 | + |
| 120 | +#endif // !_WIN64 |
| 121 | diff --git a/src/heap/base/asm/x64/push_registers_masm.asm b/src/heap/base/asm/x64/push_registers_masm.asm |
| 122 | index d0d05632d26883316cb7b39f8e7e8143d2b24bc3..a32e193c2f132cdbe1d0730831d8659be996f8e2 100644 |
| 123 | --- a/src/heap/base/asm/x64/push_registers_masm.asm |
| 124 | +++ b/src/heap/base/asm/x64/push_registers_masm.asm |
| 125 | @@ -8,7 +8,7 @@ |
| 126 | public PushAllRegistersAndIterateStack |
| 127 | |
| 128 | .code |
| 129 | -PushAllRegistersAndIterateStack proc frame |
| 130 | +PushAllRegistersAndIterateStack: |
| 131 | ;; Push all callee-saved registers to get them on the stack for conservative |
| 132 | ;; stack scanning. |
| 133 | ;; |
| 134 | @@ -19,28 +19,16 @@ PushAllRegistersAndIterateStack proc frame |
| 135 | ;; |
| 136 | ;; rbp is callee-saved. Maintain proper frame pointer for debugging. |
| 137 | push rbp |
| 138 | - .pushreg rbp |
| 139 | mov rbp, rsp |
| 140 | - .setframe rbp, 0 |
| 141 | push 0CDCDCDh ;; Dummy for alignment. |
| 142 | - .allocstack 8 |
| 143 | push rsi |
| 144 | - .pushreg rsi |
| 145 | push rdi |
| 146 | - .pushreg rdi |
| 147 | push rbx |
| 148 | - .pushreg rbx |
| 149 | push r12 |
| 150 | - .pushreg r12 |
| 151 | push r13 |
| 152 | - .pushreg r13 |
| 153 | push r14 |
| 154 | - .pushreg r14 |
| 155 | push r15 |
| 156 | - .pushreg r15 |
| 157 | sub rsp, 160 |
| 158 | - .allocstack 160 |
| 159 | - .endprolog |
| 160 | ;; Use aligned instrs as we are certain that the stack is properly aligned. |
| 161 | movdqa xmmword ptr [rsp + 144], xmm6 |
| 162 | movdqa xmmword ptr [rsp + 128], xmm7 |
| 163 | @@ -65,6 +53,5 @@ PushAllRegistersAndIterateStack proc frame |
| 164 | ;; Restore rbp as it was used as frame pointer. |
| 165 | pop rbp |
| 166 | ret |
| 167 | - PushAllRegistersAndIterateStack endp |
| 168 | |
| 169 | end |