# Unexpected side effect of -trimpath for go version -m

**URL:** <https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057>\
**Category:** Getting Help\
**Created:** [December 3, 2024, 1:52pm UTC](https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057 "2024-12-03T13:52:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![noj-richards](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/noj-richards/32/15869_2.png) [@noj-richards](https://forum.golangbridge.org/u/noj-richards)\
**Post date:** [December 3, 2024, 1:52pm UTC](https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057/1 "2024-12-03T13:52:36Z")

</div>

Hi all,

We wanted to put a (not very) secret into our executable at build time using -ldflags -X. But then we realised that the ldflags are printed out if you just use go version -m yourexe.

When we add the -trimpath flag to the build the ldflags disappear from go version which is super but this isn’t the documented behaviour of this flag.

Is this expected or a bug in the tools and/or might this feature disappear in future go version?

Thanks for your help.

E.g.

```auto
package main
import "fmt"
var ASecret = ""

func main() {
   fmt.Println(ASecret)
}

```

```auto
jonrichards@UNKNOWN Downloads % go build -ldflags="-X main.ASecret=123" main.go
jonrichards@UNKNOWN Downloads % ./main 
123
jonrichards@UNKNOWN Downloads % go version -m main                              
main: go1.23.3
	path	command-line-arguments
	build	-buildmode=exe
	build	-compiler=gc
	build	-ldflags="-X main.ASecret=123"
	build	CGO_ENABLED=1
	build	CGO_CFLAGS=
	build	CGO_CPPFLAGS=
	build	CGO_CXXFLAGS=
	build	CGO_LDFLAGS=
	build	GOARCH=arm64
	build	GOOS=darwin
	build	GOARM64=v8.0
jonrichards@UNKNOWN Downloads % go build -trimpath -ldflags="-X main.ASecret=123" main.go
jonrichards@UNKNOWN Downloads % go version -m main                                        
main: go1.23.3
	path	command-line-arguments
	build	-buildmode=exe
	build	-compiler=gc
	build	-trimpath=true
	build	CGO_ENABLED=1
	build	GOARCH=arm64
	build	GOOS=darwin
	build	GOARM64=v8.0

```

---

<div class="post-metadata">

**Author:** ![lemarkar](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/lemarkar/32/12652_2.png) [@lemarkar](https://forum.golangbridge.org/u/lemarkar)\
**Post date:** [December 3, 2024, 2:01pm UTC](https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057/2 "2024-12-03T14:01:53Z")

</div>

Hello there, it’s a bug and it is tracked [here](https://github.com/golang/go/issues/63432)

---

<div class="post-metadata">

**Author:** ![noj-richards](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/noj-richards/32/15869_2.png) [@noj-richards](https://forum.golangbridge.org/u/noj-richards)\
**Post date:** [December 3, 2024, 2:11pm UTC](https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057/3 "2024-12-03T14:11:27Z")

</div>

So it is. Thank you for your prompt response.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [March 3, 2025, 2:11pm UTC](https://forum.golangbridge.org/t/unexpected-side-effect-of-trimpath-for-go-version-m/37057/4 "2025-03-03T14:11:34Z")

</div>

Closed on March 3, 2025, 2:11pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
