-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Go version
go version go1.22.2 linux/arm64
Output of go env
in your module/workspace:
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/dev/.cache/go-build'
GOENV='/home/dev/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/dev/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/dev/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.22'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.22/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/dev/repos_shared/<repo_name>/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build272344516=/tmp/go-build -gno-record-gcc-switches'
What did you do?
I am cross-compiling my project for linux/riscv64. Including -buildmode=pie wrongly strips the .gopclntab symbol.
I checked this with readelf -S <exe_name> | grep gopclntab.
Removing -buildmode=pie gives the correct symbol table.
Below is the command that gave me the correct symbol table. I had to replace a couple of paths and stuff since the repo is private.
CGO_ENABLED=1 CGO_CFLAGS="-I<lib/include> -I -Wno-incompatible-pointer-types -fstack-protector-strong -D_FORTIFY_SOURCE=2" CGO_LDFLAGS="-L<lib/include> -l<lib_binary> -Wl,-z,now,-z,relro" GOROOT_FINAL=/ \ "/usr/bin/go" build -mod=vendor -gcflags="all=-N -l -trimpath={PROJECT_DIR}" -asmflags="all=-trimpath={PROJECT_DIR}" -tags Debug -ldflags " -X main.Version=1-X main.Build=aaa -X main.Branch= -X main.ClientVersion=1 -X main.ClientBuild=aaa -extldflags '-L <lib/include> -Wl,-z,now,-z,relro'" -o bin/ ./path/to/code
What did you see happen?
.gopclntab symbol was not included in the -buildmode=pie case.
What did you expect to see?
gopclntab should be included in the symbol table when the '-buildmode=pie' flag is included in the build command.