Navigation Menu

Skip to content
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

runtime: some Go executables broken with macOS 10.12.4 / Xcode 8.3 but fine with Xcode 8.2 #19734

Closed
dmaclach opened this issue Mar 28, 2017 · 66 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dmaclach
Copy link

See couchbase/sync_gateway#2417 for repro steps.

System:

MacBook Pro (x86_64)
macOS 10.12.3 (Sierra)
go version go1.8 darwin/amd64
Xcode 8.3; clang -v
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.4.0
Thread model: posix

What did you do?

See description at
couchbase/sync_gateway#2417

I also found this with some code I am unable to share.

My code does work fine with Xcode 8.2:
clang -v
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix

and from reading the bug linked above it works fine there as well.

@favadi
Copy link

favadi commented Mar 28, 2017

I have the same problem as OP but only for some binaries, not all. When trying to start, it is killed instantly.

$ ./test
Killed: 9

I can't figure out the common pattern for broken programs.

@ALTree ALTree changed the title Some Go executables broken with macOS 10.12.4 / Xcode 8.3 but fine with Xcode 8.2 runtime: some Go executables broken with macOS 10.12.4 / Xcode 8.3 but fine with Xcode 8.2 Mar 28, 2017
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 28, 2017
@rasky
Copy link
Member

rasky commented Mar 28, 2017

Reproduction:

package main

import (
	"fmt"

	_ "github.com/veandco/go-sdl2/sdl"
)

func init() {
	fmt.Println("init")
}

func main() {
	fmt.Println("Hello, world")
}
 $ ./testx
 fish: './testx' terminated by signal SIGKILL (Forced quit)

Importing go-sdl2 is enough to make it crash, the prints are just to show that the runtime is unable to get to main.init. go-sdl2 has a single init() function, but commenting it out doesn't change anything, it still crashes right away.

I installed SDL itself via homebrew, the bottled version, a few weeks ago.

@rasky
Copy link
Member

rasky commented Mar 28, 2017

Basically, just using cgo and linking against sdl2 causes the crash:

package sdl

// #cgo linux freebsd darwin pkg-config: sdl2
import "C"

If you make the above file the whole go-sdl package, the binary will still crash.

@rasky
Copy link
Member

rasky commented Mar 28, 2017

Uhm it looks like lldb is even unable to spawn the binary:

(lldb) run
error: error: ::posix_spawnp ( pid => 24893, path = '/Users/rasky/Sources/go/src/ndsemu/testx/testx', file_actions = 0x7fff555225e8, attr = 0x7fff555225f8, argv = 0x7fd1e92a8150, envp = 0x7fd1e92ad520 ) err = Cannot allocate memory (0x0000000c)

so it seems like the binary is being linked in a way that the OS refuses to run it.

/cc @ianlancetaylor

@fighterlyt
Copy link

just the same, cgo make it crash

@crazytyper
Copy link

same here but with github.com/shirou/gopsutil/cpu instead of sdl2.

trying to run the binary with dtruss gives Unknown error.

@dmoklaf
Copy link

dmoklaf commented Mar 28, 2017

Same here, very simple to reproduce:

$ go test github.com/blevesearch/cld2
signal: killed
FAIL	github.com/blevesearch/cld2	0.003s

Investigating the MacOS system logs, it seems to be an issue with taskgated:
taskgated MacOS error: -67062
taskgated no signature for pid=4766 (cannot make code: UNIX[No such process])

Maybe a code signature issue around cgo...

@rasky
Copy link
Member

rasky commented Mar 28, 2017

I'll notice that all Go binaries (including working ones) generate the -67062 error, but I think that's normal because they are not codesigned. The errors I get only when running these crashing cgo binaries are:

default	14:32:47.099750 +0200	taskgated	UNIX error exception: 3
default	14:32:47.099853 +0200	taskgated	no signature for pid=28180 (cannot make code: UNIX[No such process])

@dmoklaf
Copy link

dmoklaf commented Mar 28, 2017

@rasky
On my environment (MacOS 10.12.14, Xcode8.3), non-cgo go programs do not generate -67062 errors. In my tests I performed, this error was strictly correlated to (1) crashes with the "signal: killed" message (2) cgo programs.
Additionally, I also get the "UNIX error exception: 3" message in the system logs

@margerum
Copy link

getting signal: killed when trying to use go run *.go

go build works, but then i get "Killed: 9" when I try to run the app

@aprilchild
Copy link

same here, dowloaded Xcode 8.2.1, replaced in /Applications and it works again..

@bradfitz bradfitz added this to the Go1.8.1 milestone Mar 28, 2017
@repustate
Copy link

For everyone running into this issue, I've been able to build binaries by adding -ldflags -s during the go build phase.

@ianlancetaylor
Copy link
Contributor

By default on Darwin the linker will invoke dsymutil to put the debug info directly into the executable. This invocation of dsymutil is disabled by the linker's -s option. Perhaps this is really a bug in dsymutil, or in how dsymutil deals with files created by the Go linker. Could somebody with an affected system please try modifying the code in Link.hostlink in cmd/link/internal/ld/lib.go to skip invoking dsymutil, and see if that fixes the problem? Thanks.

@josharian
Copy link
Contributor

josharian commented Mar 28, 2017

@ianlancetaylor that does fix the problem. Tested on 1.8.

@ianlancetaylor
Copy link
Contributor

The call to dsymutil was added to fix #8973. I suppose the next question is: if we don't call dsymutil, what happens when you try to debug a Go program built with cgo?

@cosnicolaou
Copy link
Contributor

I'm seeing this without using cgo, what's the suggested work around - use xcode 8.2?

@bradfitz
Copy link
Contributor

@cosnicolaou, see above (#19734 (comment)). Does that not work for you?

@cosnicolaou
Copy link
Contributor

thanks, it works, from reading the comments I thought this was a cgo only problem/fix. It's also painful for our build/automation for obvious reasons.

@travissanderson-wf
Copy link

would adding these flags to build scripts have any negative repercussions that you're aware of? performance implications or anything like that?

kcking added a commit to kcking/homebrew-kr that referenced this issue Mar 28, 2017
@cosnicolaou
Copy link
Contributor

no, it's just a pain to find all of the invocations etc.

@travissanderson-wf
Copy link

agreed :) thanks for verifying they are safe to add though

@bradfitz
Copy link
Contributor

bradfitz commented Apr 7, 2017

Er, build, not run. Maybe that's okay.

@rsc
Copy link
Contributor

rsc commented Apr 7, 2017

Right, build, and even then only build with newer Xcode. It's not like the gettimeofday crashes.

@bradfitz
Copy link
Contributor

bradfitz commented Apr 7, 2017

This may impact their point release builds, but I'm not sure how Kubernetes does their releases (on an actual Mac, or cross-compiled).

Running file on https://storage.googleapis.com/kubernetes-release/release/v1.6.1/bin/darwin/amd64/kubectl just says kubectl: Mach-O 64-bit executable x86_64. (no ldd... I don't know Mac tools)

@rsc
Copy link
Contributor

rsc commented Apr 7, 2017

They can always add -ldflags=-s or update to Go 1.8.1 like everyone else. Also, kubectl at least doesn't appear to have any cgo code in it (otool -l kubectl | grep nundefsym).

@abh
Copy link

abh commented Apr 8, 2017

Yeah, kubectl seems to be cross compiled (it doesn't use the macOS DNS resolver).

@vyorkin
Copy link

vyorkin commented Apr 11, 2017

none of the above workarounds worked for me :(

mac os x sierra 10.12.4
xcode 8.2 (8C38)
command line tools: http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_macOS_10.12_for_Xcode_8.2/Command_Line_Tools_macOS_10.12_for_Xcode_8.2.dmg

before installing command line tools I've removed /Library/Developer/CommandLineTools directory

UPD: it works now! after uninstalling the previous version with brew uninstall ethereum and installing a new one from the develop branch with brew install ethereum --devel

@pawelkowalak
Copy link

Update to Go 1.8.1, it is fixed now.

@rodrigo-brito
Copy link

Go 1.8.1 Works! 🎉

lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
Might as well provide a way around the mach-o munging
that doesn't require stripping all symbols.
After all, -w does mean no DWARF.

For golang#11887, golang#19734, and anyone else that needs to disable
this code path without losing the symbol table.

Change-Id: I254b7539f97fb9211fa90f446264b383e7f3980f
Reviewed-on: https://go-review.googlesource.com/38853
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
lparth pushed a commit to lparth/go that referenced this issue Apr 13, 2017
Without this, the load fails during kernel exec, which results in the
mysterious and completely uninformative "Killed: 9" error.

It appears that the stars (or at least the inputs) were properly aligned
with earlier versions of Xcode so that this happened accidentally.
Make it happen on purpose.

Gregory Man bisected the breakage to this change in LLVM,
which fits the theory nicely:
llvm-mirror/llvm@9a41e59c

Fixes golang#19734.

Change-Id: Ice67a09af2de29d3c0d5e3fcde6a769580897c95
Reviewed-on: https://go-review.googlesource.com/38854
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
ns-codereview pushed a commit to couchbase/indexing that referenced this issue Apr 20, 2017
OSX 10.12.4 debug symbols breaks go 1.7.3 binaries. Temporarily add
-s flag to strip debug info.

Revert this commit when we move to 1.8.1

See golang/go#19734

Change-Id: I8d777c82841c75c6b1b28f6b7d69690b93e5fb87
harshavardhana added a commit to harshavardhana/mc that referenced this issue Apr 20, 2017
harshavardhana added a commit to harshavardhana/mc that referenced this issue Apr 20, 2017
vadmeste pushed a commit to minio/mc that referenced this issue Apr 20, 2017
@OSMeteor
Copy link

use go1.8.1 fixed it good

@golang golang locked and limited conversation to collaborators Apr 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests