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

crypto/x509: cgo errors when compiling with gcc on Darwin #24437

Closed
avinashrd opened this issue Mar 18, 2018 · 6 comments
Closed

crypto/x509: cgo errors when compiling with gcc on Darwin #24437

avinashrd opened this issue Mar 18, 2018 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Milestone

Comments

@avinashrd
Copy link

avinashrd commented Mar 18, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.10

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN="/Users/xxx/Downloads/projects/golang/bin"
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/Downloads/projects/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="/usr/local/Cellar/gcc/7.3.0_1/bin/gcc-7"
CXX="/usr/local/Cellar/gcc/7.3.0_1/bin/g++-7"
CGO_ENABLED="1"
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 -fmessage-length=0 -fdebug-prefix-map=/var/folders/w8/y97pxwvj35xcsw9vmh2s3gzr0000gn/T/go-build575805343=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

ran a simple program

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

func main() {
	urls := make([]string, 3)
	urls[0] = "https://www.usa.gov/"
	urls[1] = "https://www.gov.uk/"
	urls[2] = "//www.gouvernement.fr/"

	for _, u := range urls {
		responseTime(u)
	}
}

func responseTime(url string) {
	start := time.Now()

	res, err := http.Get(url)

	if err != nil {
		log.Fatal(err)
	}

	defer res.Body.Close()

	elapsed := time.Since(start).Seconds()

	fmt.Printf("%s took %v seconds \n", url, elapsed)
}

What did you expect to see?

expected output

What did you see instead?

# crypto/x509
In file included from /System/Library/Frameworks/Security.framework/Headers/AuthSession.h:32:0,
                 from /System/Library/Frameworks/Security.framework/Headers/Security.h:43,
                 from /usr/local/Cellar/go/1.10/libexec/src/crypto/x509/root_cgo_darwin.go:17:
/System/Library/Frameworks/Security.framework/Headers/Authorization.h:193:7: error: variably modified 'bytes' at file scope
  char bytes[kAuthorizationExternalFormLength];
       ^~~~~
@avinashrd
Copy link
Author

solved this issues by using clang as the compiler instead of gcc

@ALTree ALTree changed the title Error on running a Simple Go Program crypto/x509: cgo errors when compiling on Darwin Mar 18, 2018
@ALTree ALTree added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin labels Mar 18, 2018
@ALTree ALTree changed the title crypto/x509: cgo errors when compiling on Darwin crypto/x509: cgo errors when compiling with gcc on Darwin Mar 18, 2018
@odeke-em
Copy link
Member

@avinashrd what version of gcc is this?

/cc @ianlancetaylor @FiloSottile

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Mar 20, 2018
@adamdecaf
Copy link
Contributor

It sounds like gcc 7.3 from the previous issue #24425 (comment)

@admercs
Copy link

admercs commented May 11, 2018

I had this issue with both gcc 7.3 and 8.1. The issue was resolved by changing the C/C++ compiler environmental variables to Apple clang before running go get commands:

CC="clang" && CXX="clang++"
go get <yourpackagename>

That way, you don't have to modify your bashrc or bash_profile. Defining an alias would also work. The issue appears to be the same as #24425 as mentioned.

@bradfitz
Copy link
Contributor

bradfitz commented Jun 7, 2018

There's nothing Go-specific here. I see this problem all over the web with different projects.

The code in question is Apple's, and not in Go's codebase anywhere.

At best we could make cmd/go detect this case (on failure, check if using gcc) and then recommend using clang. Might be overkill. @ianlancetaylor?

@ianlancetaylor
Copy link
Contributor

Honestly I think that is overkill. I agree that I don't think there is anything we can reasonably change to make this work, so closing the issue. Please comment if you disagree.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
None yet
Development

No branches or pull requests

8 participants