From 6a228650af24b4d2fc45c0a96bcdedde3de766fe Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 5 Aug 2021 15:03:53 +0200 Subject: go-patches: add exception search fix, CL340070 https://go-review.googlesource.com/c/go/+/340070 Also, move to using `git format-patch --no-numbered --zero-commit` so that there's less churn when adding patches. Signed-off-by: Jason A. Donenfeld --- ...ow-builtin-write-function-to-be-redirecte.patch | 2 +- ...ow-arm64-SEH-to-be-called-if-illegal-inst.patch | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 go-patches/0002-runtime-allow-arm64-SEH-to-be-called-if-illegal-inst.patch diff --git a/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch b/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch index d6a1ac65..c2a5dd52 100644 --- a/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch +++ b/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch @@ -1,4 +1,4 @@ -From 1c566ea2420f0503c8494e361bccb943d83c135c Mon Sep 17 00:00:00 2001 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 3 Dec 2020 13:29:58 +0100 Subject: [PATCH] runtime: allow builtin write function to be redirected with diff --git a/go-patches/0002-runtime-allow-arm64-SEH-to-be-called-if-illegal-inst.patch b/go-patches/0002-runtime-allow-arm64-SEH-to-be-called-if-illegal-inst.patch new file mode 100644 index 00000000..3537f493 --- /dev/null +++ b/go-patches/0002-runtime-allow-arm64-SEH-to-be-called-if-illegal-inst.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" +Date: Thu, 5 Aug 2021 13:37:29 +0200 +Subject: [PATCH] runtime: allow arm64 SEH to be called if illegal instruction + +DLLs built with recent Microsoft toolchains for ARM64 test for ARMv8.1 +atomics by potentially calling an illegal instruction, and then trapping +the exception to disable use of them by way of a structured exception +handler. However, vectored exception handlers are always called before +structured exception handlers. When LoadLibrary-ing DLLs that do this +probing during initialization, our lastcontinuehandler winds up being +called, and then crashing, but actually it should give execution back to +the library to handle the exception and fix up the state. So special +case this for arm64 with illegal instructions, and hope that we're not +masking other things in external DLLs that might more fatally trigger an +illegal instruction exception. + +Change-Id: I341ab99cd8d513ae999b75596749d49779072022 +--- + src/runtime/signal_windows.go | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/src/runtime/signal_windows.go b/src/runtime/signal_windows.go +index f2ce24d735..b720ddcf16 100644 +--- a/src/runtime/signal_windows.go ++++ b/src/runtime/signal_windows.go +@@ -183,6 +183,17 @@ func lastcontinuehandler(info *exceptionrecord, r *context, gp *g) int32 { + return _EXCEPTION_CONTINUE_SEARCH + } + ++ // VEH is called before SEH, but arm64 MSVC DLLs use SEH to trap ++ // illegal instructions during runtime initialization to determine ++ // CPU features, so if we make it to the last handler and we're ++ // arm64 and it's an illegal instruction and this is coming from ++ // non-Go code, then assume it's this runtime probing happen, and ++ // pass that onward to SEH. ++ if GOARCH == "arm64" && info.exceptioncode == _EXCEPTION_ILLEGAL_INSTRUCTION && ++ (r.ip() < firstmoduledata.text || firstmoduledata.etext < r.ip()) { ++ return _EXCEPTION_CONTINUE_SEARCH ++ } ++ + winthrow(info, r, gp) + return 0 // not reached + } +-- +2.32.0 + -- cgit v1.2.3-59-g8ed1b