Skip to content

cmd/cgo: rewrites file paths to absolute in godefs generated comment  #52063

Closed
@tklauser

Description

@tklauser

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

$ go version
go version go1.18 darwin/amd64

Does this issue reproduce with the latest release?

Yes, also reproduces on gotip.

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

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

What did you do?

$ cat <<EOF > defs.go
package defs

/*
struct a { int b; };
*/
import "C"

type A C.struct_a
EOF
$ go tool cgo -godefs defs.go

What did you expect to see?

// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs defs.go

package defs

type A struct {
	B int32
}

What did you see instead?

// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs /Users/tklauser/tmp/defs.go

package defs

type A struct {
	B int32
}

Note that the file path in the comment got rewritten to an absolute path, while it it was specified as a relative path on the command line.

/cc @ianlancetaylor

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions