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

cmd/cgo: "could not determine kind of name" for const int when using clang #21668

Closed
ianthehat opened this issue Aug 28, 2017 · 12 comments
Closed
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge release-blocker
Milestone

Comments

@ianthehat
Copy link

Compiling a trivial cgo program fails only with go1.9 on mac. It compiles on go1.8.3 for all platforms, and compiles for go1.9 on linux.

There are two files:
foo.go

package cgo_sys_hdr

/*
#include <foo.h>
*/
import "C"

var x = int(C.x)

foo.h

const int x = 42;

Note that if you change foo.h removing const it works.

What did you do?

$go build ./

What did you expect to see?

A successful build (or a more useful error message if you are not allowed to reference C.x, and preferably one that was consistent across platforms)

What did you see instead?

# _/Users/iancottrell/temp/broken_cgo_test/src
./foo.go:8:13: could not determine kind of name for C.x

System details

go version go1.9 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/iancottrell/temp/broken_cgo_test"
GORACE=""
GOROOT="/Users/iancottrell/go/current"
GOTOOLDIR="/Users/iancottrell/go/current/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/x3/tx8v101d3ygbfpd0p7vt7pcm003y_c/T/go-build136094710=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
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"
GOROOT/bin/go version: go version go1.9 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.9
uname -v: Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.12.6
BuildVersion:	16G29
lldb --version: lldb-370.0.42
  Swift-3.1
@ianlancetaylor ianlancetaylor changed the title Change in cgo behaviour for 1.9 cmd/cgo: could not determine kind of name when using clang Aug 28, 2017
@ianlancetaylor
Copy link
Contributor

What does clang --version print?

@ianlancetaylor
Copy link
Contributor

I can reproduce this using clang 3.6.

@ianlancetaylor
Copy link
Contributor

CC @hirochachacha

@ianlancetaylor
Copy link
Contributor

No need for foo.h, by the way, this suffices:

package p

// const int x = 42;
import "C"

var X = int(C.x)

@ianlancetaylor ianlancetaylor changed the title cmd/cgo: could not determine kind of name when using clang cmd/cgo: "could not determine kind of name" for const int when using clang Aug 28, 2017
@ianthehat
Copy link
Author

$clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@hirochachacha
Copy link
Contributor

Sorry about the stupid bug. I sent the fix.

@gopherbot
Copy link

Change https://golang.org/cl/59710 mentions this issue: cmd/cgo: avoid using common names for sniff variables

@ianlancetaylor
Copy link
Contributor

Reopen to commit to 1.9 branch.

@gopherbot
Copy link

Change https://golang.org/cl/59730 mentions this issue: [release-branch.go1.9] cmd/cgo: avoid using common names for sniffing

gopherbot pushed a commit that referenced this issue Aug 29, 2017
Current code uses names like "x" and "s" which can conflict with user's
code easily. Use cryptographic names.

Fixes #21668

Change-Id: Ib6d3d6327aa5b92d95c71503d42e3a79d96c8e15
Reviewed-on: https://go-review.googlesource.com/59710
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/59730
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
@rsc rsc modified the milestones: Go1.9.1, Go1.9.2 Oct 4, 2017
@rsc
Copy link
Contributor

rsc commented Oct 13, 2017

CL 59710 OK for Go 1.9.2.
CL 70849 OK for Go 1.9.2.

(CL 59710 was already cherry-picked as CL 59730, but then we wiped that out for the Go 1.9.1 security release behind Gerrit's back, and so Gerrit refuses to believe that we could possibly need a second cherry-pick of the same CL. CL 70849 is a cherry-pick but with the Change-Id incremented to break the Gerrit correspondence.)

@rsc rsc added the CherryPickApproved Used during the release process for point releases label Oct 14, 2017
@gopherbot
Copy link

Change https://golang.org/cl/70849 mentions this issue: [release-branch.go1.9] cmd/cgo: avoid using common names for sniffing

gopherbot pushed a commit that referenced this issue Oct 25, 2017
Current code uses names like "x" and "s" which can conflict with user's
code easily. Use cryptographic names.

Fixes #21668

Change-Id: Ib6d3d6327aa5b92d95c71503d42e3a79d96c8e16
Reviewed-on: https://go-review.googlesource.com/59710
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/59730
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
Reviewed-on: https://go-review.googlesource.com/70849
Run-TryBot: Russ Cox <rsc@golang.org>
@rsc
Copy link
Contributor

rsc commented Oct 26, 2017

go1.9.2 has been packaged and includes:

The release is posted at golang.org/dl.

— golang.org/x/build/cmd/releasebot, Oct 26 21:09:11 UTC

@rsc rsc closed this as completed Oct 26, 2017
@golang golang locked and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants