Tuesday, January 21, 2025
HomeGolangSudden facet impact of -trimpath for go model -m - Getting Assist

Sudden facet impact of -trimpath for go model -m – Getting Assist


Hello all,

We wished to place a (not very) secret into our executable at construct time utilizing -ldflags -X. However then we realised that the ldflags are printed out if you happen to simply use go model -m yourexe.

After we add the -trimpath flag to the construct the ldflags disappear from go model which is tremendous however this isn’t the documented behaviour of this flag.

Is that this anticipated or a bug within the instruments and/or may this function disappear in future go model?

Thanks on your assist.

E.g.

package deal primary
import "fmt"
var ASecret = ""

func primary() {
   fmt.Println(ASecret)
}
jonrichards@UNKNOWN Downloads % go construct -ldflags="-X primary.ASecret=123"  primary.go
jonrichards@UNKNOWN Downloads % ./primary 
123
jonrichards@UNKNOWN Downloads % go model -m primary                              
primary: go1.23.3
	path	command-line-arguments
	construct	-buildmode=exe
	construct	-compiler=gc
	construct	-ldflags="-X primary.ASecret=123"
	construct	CGO_ENABLED=1
	construct	CGO_CFLAGS=
	construct	CGO_CPPFLAGS=
	construct	CGO_CXXFLAGS=
	construct	CGO_LDFLAGS=
	construct	GOARCH=arm64
	construct	GOOS=darwin
	construct	GOARM64=v8.0
jonrichards@UNKNOWN Downloads % go construct -trimpath -ldflags="-X primary.ASecret=123"  primary.go
jonrichards@UNKNOWN Downloads % go model -m primary                                        
primary: go1.23.3
	path	command-line-arguments
	construct	-buildmode=exe
	construct	-compiler=gc
	construct	-trimpath=true
	construct	CGO_ENABLED=1
	construct	GOARCH=arm64
	construct	GOOS=darwin
	construct	GOARM64=v8.0

Hey there, it’s a bug and it’s tracked right here

So it’s. Thanks on your immediate response.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments