Skip to content

Commit

Permalink
Workaround apple silicon codesigning cache bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
carolynvs committed Jan 31, 2023
1 parent a7c4ee7 commit 980bf68
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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))

Expand Down

0 comments on commit 980bf68

Please sign in to comment.