Skip to content

cmd/cgo: wrong parse cgo overlay file #66142

Open
@ser-mk

Description

@ser-mk

Go version

go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/tmp/.cache/go-build'
GOENV='/tmp/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/tmp/go/pkg/mod'
GOOS='linux'
GOPATH='/tmp/go'
GOPROXY='direct'
GOROOT='/snap/go/10535'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10535/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/GolandProjects/extt/go.mod'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1187410756=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Go code:
example.go

package go_issue

/*
void f(){}
*/
import "C"

func example() {
	C.f()
}

I run cgo:

# go tool cgo example.go 
# ls _obj/_cgo_gotypes.go 
_obj/_cgo_gotypes.go

next I build go file with -overlay option
overlay.json:

{
  "Replace":
  {
    "example_cgo.go": "_obj/_cgo_gotypes.go"
  }
}

go build -overlay=overlay.json example_cgo.go

What did you see happen?

errors:

# go build -overlay=overlay.json example_cgo.go
# command-line-arguments
./_obj/_cgo_gotypes.go:34:3: //go:cgo_import_static _cgo_2ae947966da8_Cfunc_f only allowed in cgo-generated code
./_obj/_cgo_gotypes.go:39:3: //go:cgo_unsafe_args only allowed in cgo-generated code

What did you expect to see?

nothing/no error, because
_obj/_cgo_gotypes.go is a cgo-generated file

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions