Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/build: -trimpath is ignored when forcefully passing -gcflags=-trimpath=$SOMETHING #66849

Closed
hyadav5 opened this issue Apr 16, 2024 · 5 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@hyadav5
Copy link

hyadav5 commented Apr 16, 2024

Go version

go version go1.16.15b7p1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY="gitlab.eng.company.com,github.com/google/martian"
GONOSUMDB="*.eng.company.com"
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE="gitlab.eng.company.com,github.com/google/martian"
GOPROXY="https://build-artifactory.eng.company.com/srp-mds-go-remote"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.15b7p1"
GCCGO="gccgo"
AR="ar"
CC="x86_64-vmk-linux-gnu-gcc"
CXX="/build/mts/release/bora-23244397/compcache/cayman_esx_toolchain/ob-16111630/linux-centos72-gc32/usr/bin/x86_64-vmk-linux-gnu-g++"
CGO_ENABLED="1"
GOMOD="/home/user/dev/dev/go/src/project/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2531685105=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have compiled a Go binary using the below flags and it has a runtime exception and dumped the below Stacktrace.
My GOPATH = /home/hemant/dev/go/src
My compiler flags while building are: -gcflags=-trimpath=$GOPATH -trimpath -asmflags=-trimpath=$GOPATH -trimpath
Stacktrace is below:

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/redis@v6.13.2+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

What did you see happen?

I have an issue where the -trimpath is not removing the GOPATH /home/hemant/dev/go/src/ from the last line of the stacktrace.

Apr 15 09:56:59 10-79-108-22 system-health[3923528]:         /home/hemant/dev/go/src/controller/go-controller.go:743 +0x231e

What did you expect to see?

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 ?

@Jorropo
Copy link
Member

Jorropo commented Apr 16, 2024

This is a very old version of go, does that works with one of the maintained release (1.22.2 or 1.21.9) ?

It would also help if you give a complete build command, or repro. I guess you might have pointed go build at files instead of a folder ?

@Jorropo Jorropo added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 16, 2024
@Jorropo Jorropo changed the title Go compiler flag -trimpath not working completely cmd/build: -trimpath not working completely Apr 16, 2024
@hyadav5
Copy link
Author

hyadav5 commented Apr 16, 2024

Yes @Jorropo, I have ran the go build on a file, but I think this might be same even for the folder as well.
Unfortunately, I cannot upgrade the go version as its a legacy product.

COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && env CC=gcc CXX=g++ GOPATH=${CMAKE_SOURCE_DIR}/go go build -mod vendor -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" -gcflags=-trimpath=$GOPATH -trimpath -asmflags=-trimpath=$GOPATH -trimpath go-controller.go

@Jorropo
Copy link
Member

Jorropo commented Apr 16, 2024

Ah, the problem is that you set -gcflags=-trimpath=$GOPATH and GOPATH="/home/user/go" while your project is stored at /home/hemant/dev/go I guess userhemant is not real, but $HOME/go vs $HOME/dev/go is real and because $HOME/dev is not inside $HOME/go it's not trimmed.

Everything works fine for me when I set -trimpath once (afaik you shouldn't need to set -gcflags nor -asmflags manually, nor you need to set -trimpath twice).


TL;DR try:

COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && env CC=gcc CXX=g++ GOPATH=${CMAKE_SOURCE_DIR}/go go build -mod vendor -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn" -trimpath go-controller.go

@Jorropo Jorropo closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
@Jorropo
Copy link
Member

Jorropo commented Apr 16, 2024

We might be able to error on this (-trimpath set too many times) or interpret it set multiple times as each path to be trimmed, but I don't think that worth breaking the cli here.
Can reopen if someone else feels strongly.

@Jorropo Jorropo changed the title cmd/build: -trimpath not working completely cmd/build: -trimpath is ignored when forcefully passing -gcflags=-trimpath=$SOMETHING Apr 16, 2024
@hyadav5
Copy link
Author

hyadav5 commented Apr 17, 2024

@Jorropo : just plain simple -trimpath worked. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

2 participants