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

cmd/link: broken binary when code depends on cgo on Darwin #29861

Closed
darkpssngr opened this Issue Jan 22, 2019 · 12 comments

Comments

Projects
None yet
4 participants
@darkpssngr
Copy link

darkpssngr commented Jan 22, 2019

System:
MacBook Pro (Retina, 15-inch, Mid 2015)
macOS 10.14.1 (Mojave)
go version go1.11.4 darwin/amd64
Xcode 8.3; clang -v
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin16.4.0

I'm seeing the exact same issue as #12950. Tried both -ldflags=-s and -ldflags=-v no luck.
But weirdly enough if I wait for 15-20 mins and then try to execute the file it works, not sure what is happening here.

package main

import "C" // Delete this line and the binary works.

func main() {
    println("Hello OSX.")
}

go build -ldflags=-s main.go
~/g/s/test  ./main                                                                                                                                                                
[1]    29457 killed     ./main
 
*wait for 20mins*
~/g/s/test  ./main 
Hello OSX.

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/shreyas/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shreyas/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/93/71nm0j9s12d80pxr31r1fph94cw6ph/T/go-build961481238=/tmp/go-build -gno-record-gcc-switches -fno-common"

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Jan 22, 2019

You are saying that you can't build any program that uses cgo? That seems odd; I don't recall seeing anybody else report that problem. The bit about waiting for 20 minutes doesn't make any sense to me. Does this happen on more than one machine?

@ianlancetaylor ianlancetaylor changed the title Broken binary when code depends on cgo cmd/link: broken binary when code depends on cgo on Darwin Jan 22, 2019

@ianlancetaylor ianlancetaylor added this to the Go1.13 milestone Jan 22, 2019

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

Build always succeeds. Its just when I run it, it errors out. And this seems to be happening only on my machine. Not sure how to proceed with the debugging. And yes I'm not sure how waiting for around 20 minutes changes anything, but it does.

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

it's actually 2-3 minutes, not 20 minutes

~/g/s/test ❯❯❯ go build main.go                                                                                                                                                     
~/g/s/test ❯❯❯ ./main                                                                                                                                                                
[1]    29234 killed     ./main
~/g/s/test ❯❯❯ date                                                                                                                                                                 
Tue Jan 22 12:50:31 IST 2019
~/g/s/test ❯❯❯ ./main                                                                                                                                                                
Hello OSX.
~/g/s/test ❯❯❯ date                                                                                                                                                                   
Tue Jan 22 12:54:03 IST 2019
@AlexRouSg

This comment has been minimized.

Copy link
Contributor

AlexRouSg commented Jan 22, 2019

My gut feeling says to check the antivirus or something security related.

It could be that it started scanning the executable after building and prevents it from running. So by waiting till the scan finished, it runs normally.

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

I think you are right. I'm seeing logs of the executable being scanned in the AntiVirus. I'll talk to the IT team about this. Thanks closing the issue.

@darkpssngr darkpssngr closed this Jan 22, 2019

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

just checked the detailed logs. I see this line
<Info> this file is not signed at all or not signed rightfully, no need to extract signature
any idea what it means?

@darkpssngr darkpssngr reopened this Jan 22, 2019

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

AlexRouSg commented Jan 22, 2019

See https://en.wikipedia.org/wiki/Code_signing

Usually it means "don't trust this executable" or "do extra checks"

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

Is there something that can be done to get the Antivirus to trust it. like how we need to codesign gdb for it work on mac (https://gist.github.com/hlissner/898b7dfc0a3b63824a70e15cd0180154)

@AlexRouSg

This comment has been minimized.

Copy link
Contributor

AlexRouSg commented Jan 22, 2019

Not sure if signing would change anything tbh. The quickest and surest way is to just tell the antivirus to don't scan this folder or this executable.

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 22, 2019

Okay. I'll check with my IT team then. There seems to be no way for me to add exceptions.

@agnivade

This comment has been minimized.

Copy link
Member

agnivade commented Jan 22, 2019

Seems like this is not a Go issue. Closing.

Feel free to reopen if you see the issue even after disabling the Antivirus.

@agnivade agnivade closed this Jan 22, 2019

@darkpssngr

This comment has been minimized.

Copy link
Author

darkpssngr commented Jan 24, 2019

Seems like an issue with the latest version of xcode command line tools. I downgraded the version and it works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment