From 980bf68cfc7bf9a51fee8720729a9eacdb70e6b8 Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Tue, 31 Jan 2023 08:34:34 -0600 Subject: [PATCH] Workaround apple silicon codesigning cache bug This is a hack to work around a codesigning problem on Apple Silicon where overwriting a binary that has already been executed doesn't cause the corresponding codesign entry in the OS cache to update. Mac then prevents the updated binary from running because the signature doesn't match. Removing the file first clears the cache so that we don't run into "zsh: killed ..." I've updated the magefile so that when we run the install target, the original binaries are removed before we copy. I considered fixing this directly in shx.Copy but lots of people use that and this is a bug in just regular old cp too. So I don't want shx.Copy to do stuff that even cp doesn't. See: * https://stackoverflow.com/questions/67378106/mac-m1-cping-binary-over-another-results-in-crash * https://openradar.appspot.com/FB8914231 Signed-off-by: Carolyn Van Slyck --- magefile.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/magefile.go b/magefile.go index 31663d16e..89edd64de 100644 --- a/magefile.go +++ b/magefile.go @@ -519,6 +519,16 @@ func Install() { // Copy porter binaries mgx.Must(os.MkdirAll(porterHome, pkg.FileModeDirectory)) + + // HACK: Works around a codesigning problem on Apple Silicon where overwriting a binary that has already been executed doesn't cause the corresponding codesign entry in the OS cache to update + // Mac then prevents the updated binary from running because the signature doesn't match + // Removing the file first clears the cache so that we don't run into "zsh: killed porter..." + // See https://stackoverflow.com/questions/67378106/mac-m1-cping-binary-over-another-results-in-crash + // See https://openradar.appspot.com/FB8914231 + mgx.Must(os.Remove(filepath.Join(porterHome, "porter"+xplat.FileExt()))) + mgx.Must(os.RemoveAll(filepath.Join(porterHome, "runtimes"))) + + // Okay now it's safe to copy these files over mgx.Must(shx.Copy(filepath.Join("bin", "porter"+xplat.FileExt()), porterHome)) mgx.Must(shx.Copy(filepath.Join("bin", "runtimes"), porterHome, shx.CopyRecursive)) @@ -544,6 +554,14 @@ func Install() { destDir := filepath.Join(porterHome, "mixins", mixin) mgx.Must(os.MkdirAll(destDir, pkg.FileModeDirectory)) + // HACK: Works around a codesigning problem on Apple Silicon where overwriting a binary that has already been executed doesn't cause the corresponding codesign entry in the OS cache to update + // Mac then prevents the updated binary from running because the signature doesn't match + // Removing the file first clears the cache so that we don't run into "zsh: killed MIXIN..." + // See https://stackoverflow.com/questions/67378106/mac-m1-cping-binary-over-another-results-in-crash + // See https://openradar.appspot.com/FB8914231 + mgx.Must(os.Remove(filepath.Join(destDir, mixin+xplat.FileExt()))) + mgx.Must(os.RemoveAll(filepath.Join(destDir, "runtimes"))) + // Copy the mixin client binary mgx.Must(shx.Copy(filepath.Join(srcDir, mixin+xplat.FileExt()), destDir))