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/cgo: cgo program fails on MacOS with Go 1.20rc1 #57419

Closed
ericchiang opened this issue Dec 21, 2022 · 3 comments
Closed

runtime/cgo: cgo program fails on MacOS with Go 1.20rc1 #57419

ericchiang opened this issue Dec 21, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge OS-Darwin
Milestone

Comments

@ericchiang
Copy link
Contributor

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

% go version
go version go1.20rc1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
% go1.20rc1 env    
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/ericchiang/Library/Caches/go-build"
GOENV="/Users/ericchiang/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ericchiang/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/ericchiang/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/ericchiang/sdk/go1.20rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/ericchiang/sdk/go1.20rc1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20rc1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d1/wpvcpdrs2tlgn5xs3_xm88th0000gn/T/go-build913429993=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Ran the following program with Go 1.20rc1

package main

// #cgo darwin LDFLAGS: -framework PCSC
// #include <PCSC/winscard.h>
// #include <PCSC/wintypes.h>
import "C"
import "fmt"

func main() {
	var ctx C.SCARDCONTEXT
	rc := int64(C.SCardEstablishContext(C.SCARD_SCOPE_SYSTEM, nil, nil, &ctx))
	if rc < 0 {
		// Fix overflow.
		rc += (1 << 32)
	}
	fmt.Printf("0x%08x\n", rc)
	if rc == C.SCARD_S_SUCCESS {
		C.SCardReleaseContext(ctx)
	}
}

What did you expect to see?

% go run repro.go 
0x00000000

What did you see instead?

% go1.20rc1 run repro.go 
0x8010001d

("SCARD_E_NO_SERVICE")

This was reported at go-piv/piv-go#113 and FiloSottile/yubikey-agent#135.

This program runs successfully on Go 1.19 and older versions. While there were some cgo changes mentioned in https://tip.golang.org/doc/go1.20, it's not clear to me that those would impact this program.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 21, 2022
@cherrymui
Copy link
Member

Maybe related to #57263 ?

@ericchiang
Copy link
Contributor Author

Yep! I can confirm that CL mentioned there (#57263 (comment)) causes the issue

go.dev/cl/451735

% git checkout 1f4394a0c92697896735a5c0135dfde1be9f42bd
...
% ./all.bash
...
% /Users/ericchiang/goroot/bin/go run ~/tmp/repro.go   
0x8010001d
% git checkout 1f4394a0c92697896735a5c0135dfde1be9f42bd^1
Previous HEAD position was 1f4394a0c9 runtime: work around Apple libc bugs to make exec stop hanging
HEAD is now at 6e0e492e12 cmd/compile/internal/pgo: count only the last two frames as a call edge
% ./all.bash
...
% /Users/ericchiang/goroot/bin/go run ~/tmp/repro.go     
0x00000000

@cherrymui
Copy link
Member

Thanks. Since you've already commented on #57263 , I think we can close this as a dup.

@cherrymui cherrymui closed this as not planned Won't fix, can't repro, duplicate, stale Dec 21, 2022
@golang golang locked and limited conversation to collaborators Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge OS-Darwin
Projects
None yet
Development

No branches or pull requests

5 participants