cmd/go: cgo functions rewritten only with -gcflags=-L #67741
Labels
BugReport
Issues describing a possible bug in the Go implementation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
tip
Output of
go env
in your module/workspace:What did you do?
Build this package:
What did you see happen?
With no
-gcflags
option:With
-gcflags=-L
:What did you expect to see?
I don't expect
-gcflags=L
to change the function name reported by the compiler. The-L
option is documented as "Show complete file path in error messages." Why should that change the function name?This turns out to happen because of some code in cmd/go/internal/work/shell.go. That code looks for lines that match the regexp
\[[^\[\]]+\.(cgo1|cover)\.go:[0-9]+(:[0-9]+)?\]
. With-gcflags=-L
, the compiler emits lines likeThat matches the regexp. In that case cmd/go strips the line in square brackets, and then translates
_C2func_
toC.
. That was introduced in https://go.dev/cl/7231075 for the Go 1.1 release. From looking at the source code, it does appear that at that time the compiler always printed the original file name in square brackets if a//line
directive had been used. Today that only happens if the-L
option has been used.The text was updated successfully, but these errors were encountered: