Skip to content

cmd/cgo: don't accept mangled C names in Cgo programs #28721

Closed
@wzshiming

Description

@wzshiming

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

go version go1.11.2 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
GOARCH="amd64"
GOBIN="/Users/zsm/go/bin"
GOCACHE="/Users/zsm/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/zsm/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.2/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/6v/7stmg2756wlfk9c_qnv1hnbm0000gn/T/go-build905706456=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package test

/*
typedef struct a {
	int i;
} a;

a* A() {
	return NULL;
};
*/
import "C"

type a struct {
	a *_Ctype_struct_a
}

func A() *a {
	i := C.A()
	return &a{i}
}

$ gomobile bind test

What did you expect to see?

Building succeeds.

What did you see instead?

gomobile: /Users/zsm/go/bin/gobind -lang=go,java -outdir=/var/folders/6v/7stmg2756wlfk9c_qnv1hnbm0000gn/T/gomobile-work-058021600 test failed: exit status 1
type-checking package "test" failed (/Users/zsm/go/src/test/main.go:15:5: undeclared name: _Ctype_struct_a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions