-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: macOS on arm64 requires codesigning #42684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@cherrymui indeed, binaries produced by the machine's
|
Actually, |
Thanks, @FiloSottile ! Interesting. The C compiler on the DTK doesn't do that... Could you try one more thing: run |
It doesn't look like the linker invocation has anything special, so I assume ld just does that (and @jedisct1 said so on Twitter as well https://twitter.com/jedisct1/status/1328862207715794946).
I expect external linking should generate codesigned binaries, but trying `go build -ldflags="-linkmode=external" fails immediately with
|
This is not a failure. It prints a message but it should successfully link the binary. |
You're right, I do get the binary. Interestingly, it comes out
|
Thanks! Interesting... I'll see if it is possible to generate LC_CODE_SIGNATURE in the linker. If that's not possible, maybe shell out Any down side for that? If the user wants to sign with a different identity, would that still be possible? |
I don't understand this. What is the point of code signing, if every execution of clang or the Go compiler produces a code signed binary? |
I guess the main problem would be with cross-compilation, but anyway I guess adhoc signatures only work on the same machine where they are generated. This would be a major pain for projects distributing binaries. I wonder how Homebrew deals with it, since by default they install pre-built "Bottles".
I don't know, but I can imagine 1) to normalize the execution path such that it always check signatures unconditionally, simplifying it and 2) to block binaries generated on other machines (and not properly signed by a trusted Developer ID) which before was sort of the role of the quarantine attributes. |
My understanding is this is a bug already reported to Apple, see Homebrew/brew#9082 (comment)
Per Homebrew/brew#7857 (comment) I don't think they're close to code signing bottles on ARM yet. |
Looks like binaries aren't required to have a signature linked to a Developer ID if they were signed elsewhere. I was able to apply an ad-hoc signature to a binary on my Intel mac and transfer it to my M1 mac and it ran just fine. Appears like binaries just need a signature, doesn't really seem to matter where it came from. |
Homebrew maintainer here:
That's indeed a bug in
Yes. If this occurs, you need to change that file's inode (so copying it someplace and back will work). Once you've done that, you can sign and it will work. See Homebrew/brew#9102 for details.
We do not distribute bottles yet, because our CI is not yet fully operational, but our codebase is otherwise ready. We apply ad-hoc signatures as part of formula installation: Homebrew/brew#9102 |
As for go, if Go uses its own linker (or anything other than Apple's |
@FiloSottile (and others): thank you for the information! 🙇 Do you know if it is possible to use I am interested in what are the options to distribute binaries for Go projects that work on Apple Silicon without having to actually compile them on Apple Silicon. |
@mislav Cross-compiling for |
This comment seems to disagree: #42684 (comment)
|
Ok, I tested it again and now cross-signing does work. I might've transferred the wrong file earlier. Whoops. |
Codesigning from cmd/link should be possible. https://github.com/isignpy/isign by @neilk does that for iOS. |
The Zig project is also working on this here: ziglang/zig#7103 (thanks @komuw). |
Thanks for the pointers. I'll look into them. |
I can confirm that a linker or other ad hoc signature is sufficient to run the binary (or shared library) on any machine. |
Fix the "build bogo_shim if it doesn't exist" logic; it was broken even on Linux as newer versions of Rust don't allow `--features` to be used at workspace level. I had to bootstrap Go on a Linux machine using the procedure at golang/go#42684 (comment): ``` git clone https://go.googlesource.com/go cd go git fetch https://go.googlesource.com/go refs/changes/58/272258/1 && git checkout FETCH_HEAD cd src GOOS=darwin GOARCH=arm64 ./bootstrap.bash ``` This version of Go required me to have a go.mod file. Change the way Bogo is downloaded from BoringSSL's repo to get this to work. The script tries to use sparse checkouts and a single-revision checkout but it is still slow so maybe one or both of those things aren't working as I expect. In particular, avoid `wget` since my Mac doesn't have `wget` available. Remove two of the patches to Bogo that seem to not be necessary if using a newer version of Go. Patch the remaining patch to work with the new directory structure. I verified that ./runme runs the tests and spits out "PASS" at the end on both macOS and Linux.
Fix the "build bogo_shim if it doesn't exist" logic; it was broken even on Linux as newer versions of Rust don't allow `--features` to be used at workspace level. I had to bootstrap Go on a Linux machine using the procedure at golang/go#42684 (comment): ``` git clone https://go.googlesource.com/go cd go git fetch https://go.googlesource.com/go refs/changes/58/272258/1 && git checkout FETCH_HEAD cd src GOOS=darwin GOARCH=arm64 ./bootstrap.bash ``` This version of Go required me to have a go.mod file. Change the way Bogo is downloaded from BoringSSL's repo to get this to work. The script now uses a sparse checkout with depth 1, which seems pretty fast. In particular, avoid `wget` since my Mac doesn't have `wget` available. Remove two of the patches to Bogo that seem to not be necessary if using a newer version of Go. Patch the remaining patch to work with the new directory structure. I verified that ./runme runs the tests and spits out "PASS" at the end on both macOS and Linux.
Fix the "build bogo_shim if it doesn't exist" logic; it was broken even on Linux as newer versions of Rust don't allow `--features` to be used at workspace level. I had to bootstrap Go on a Linux machine using the procedure at golang/go#42684 (comment): ``` git clone https://go.googlesource.com/go cd go git fetch https://go.googlesource.com/go refs/changes/58/272258/1 && git checkout FETCH_HEAD cd src GOOS=darwin GOARCH=arm64 ./bootstrap.bash ``` This version of Go required me to have a go.mod file. Change the way Bogo is downloaded from BoringSSL's repo to get this to work. The script now uses a sparse checkout with depth 1, which seems pretty fast. In particular, avoid `wget` since my Mac doesn't have `wget` available. Remove two of the patches to Bogo that seem to not be necessary if using a newer version of Go. Patch the remaining patch to work with the new directory structure. I verified that ./runme runs the tests and spits out "PASS" at the end on both macOS and Linux.
This doesn't see true. I'm on an M1 Mac mini, and these commands:
give an error:
UPDATE: Piecing together various bits and bobs above, this hung the first time, but worked the second:
|
You do need an x86_64 darwin golang to cross build for arm64. It is easiest
at this point to get that and then use gotip to build master.
…On Thu, Dec 17, 2020 at 12:31 PM jimtut ***@***.***> wrote:
You can do that all on the m1 mac by replacing the last line with
arch --x86_64 env GODEBUG=asyncpreemptoff=1 GOOS=darwin GOARCH=arm64
./bootstrap.bash
This doesn't see true. I'm on an M1 Mac mini, and these commands:
git clone https://go.googlesource.com/go cd go/src arch --x86_64 env
GODEBUG=asyncpreemptoff=1 GOOS=darwin GOARCH=arm64 ./bootstrap.bash
give an error:
ERROR: Cannot find /Users/jim/go1.4/bin/go. Set $GOROOT_BOOTSTRAP to a
working Go tree >= Go 1.4.
It doesn't seem like you can *bootstrap* on an M1 Mac (no Go installed
anywhere on this fresh Mac)?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#42684 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEKAP2BPXHPN7K3DUYJ2X3SVJTCHANCNFSM4TZJN5QA>
.
|
You can now download a native macOS ARM64 binary release from https://golang.org/dl/#go1.16beta1, as it was released today. Look for |
On the production Apple Silicon machines, Go binaries are killed at start. #38485 (comment)
It looks like all binaries need to be codesigned now, and indeed running
codesign -s -
on them lets them run correctly.This stops
go test
andgo run
from working, and requires an extra step aftergo build
to get a functional binary.This also affects the bootstrapped compiler itself.
The text was updated successfully, but these errors were encountered: