Search code examples
gocompilationstack-trace

Go compiler flag -trimpath not working completely


I have an issue where the -trimpath is not removing the GOPATH from the last line of the stacktrace. Below is the snapshot of the stacktrace:

Apr 15 09:56:59 10-79-108-22 system-health[3923528]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x144efd2]
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: goroutine 1 [running]:
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: github.com/go-redis/redis.(*cmdable).HGetAll(0xc002cc78b0, 0x0, 0x0, 0x0)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: github.com/go-redis/redis.(*cmdable).HGetAll(0xc002cc78b0, 0x0, 0x0, 0x0)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         github.com/go-redis/[email protected]+incompatible/commands.go:923 +0xd2
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.someOtherFunc(...)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:676
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.someFunction(...)
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:680
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: controller/systemhealth.ServiceInitialize()
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         controller/systemhealth/system_health.go:685 +0x6b
Apr 15 09:56:59 10-79-108-22 system-health[3923528]: main.main()
Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         /home/hemant/dev/go/src/controller/go-controller.go:743 +0x231e

My GOPATH = /home/hemant/dev/go/src

My compiler flags while building are: -gcflags=-trimpath=$GOPATH -trimpath -asmflags=-trimpath=$GOPATH -trimpath

GOPATH should have been removed from the last line also.

Also side question: Is it possible to NOT expose directory path also and have mere filename ?


Solution

  • As per the comments, setting just -trimpath without -gcflags=... and -asmflags=.... fixed the issue (which was probably due to a mix-up with GOPATH).