Skip to content

cmd/go: -trimpath should respect replace statements #75198

@florianl

Description

@florianl

Go version

go version go1.25.0 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/flo/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/flo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build965605651=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/flo/tmp/go-panic-print/go.mod'
GOMODCACHE='/home/flo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/flo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/flo/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Reproducer:

package main

import "github.com/florianl/foo"

func main() {
	foo.Bar()
}
module github.com/florianl/issue-75198

go 1.25.0

require github.com/florianl/foo v0.0.0-20250830101743-a8ea00ca555f

replace github.com/florianl/foo => github.com/florianl/bar v0.0.0-20250830103411-1f7d777651a2

What did you see happen?

When building the reproducer with -trimpath the following stack will be printed as triggered by the panic():

$ go clean
$ go build -trimpath ./...
$ ./issue-75198 
panic: from bar

goroutine 1 [running]:
github.com/florianl/foo.bar()
	github.com/florianl/foo@v0.0.0-20250830101743-a8ea00ca555f/bar.go:9 +0x25
github.com/florianl/foo.Bar(...)
	github.com/florianl/foo@v0.0.0-20250830101743-a8ea00ca555f/bar.go:4
main.main()
	github.com/florianl/issue-75198/main.go:6 +0x10

Please note that the file paths in the stack frames still reference github.com/florianl/foo@v0.0.0-20250830101743-a8ea00ca555f.

When building the reproducer without -trimpath the correct paths are shown in the stacktrace:

$ go clean
$ go build ./...
$ ./issue-75198 
panic: from bar

goroutine 1 [running]:
github.com/florianl/foo.bar()
	/home/user/go/pkg/mod/github.com/florianl/bar@v0.0.0-20250830103411-1f7d777651a2/bar.go:9 +0x25
github.com/florianl/foo.Bar(...)
	/home/user/go/pkg/mod/github.com/florianl/bar@v0.0.0-20250830103411-1f7d777651a2/bar.go:4
main.main()
	/home/user/issue-75198/main.go:6 +0x10

What did you expect to see?

The expected stacktrace should look like this:

$ go clean
$ go build -trimpath ./...
$ ./issue-75198 
panic: from bar

goroutine 1 [running]:
github.com/florianl/bar.bar()
	github.com/florianl/bar@v0.0.0-20250830103411-1f7d777651a2/bar.go:9 +0x25
github.com/florianl/bar.Bar(...)
	github.com/florianl/bar@v0.0.0-20250830103411-1f7d777651a2/bar.go:4

main.main()
	github.com/florianl/issue-75198/main.go:6 +0x10

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions