Go version
1.26.5
Output of go env in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHEPROG=''
GODEBUG=''
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1018270336=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOVCS=''
GOVERSION='go1.26.5'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Trying to build a static PIE executable, using minimal main.go file:
package main
func main() {}
with this command: env CGO_ENABLED=0 go build -buildmode=pie -ldflags -d -o main main.go
What did you see happen?
The executable produced crashes with a segfault.
file ./main confirms that the executable is a ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped
readelf -r ./main gives There are no relocations in this file.
Running through gdb points the segfault here:
Program received signal SIGSEGV, Segmentation fault.
memeqbody () at go/src/internal/bytealg/equal_amd64.s:114
114 MOVQ (SI), CX
#0 memeqbody () at go/src/internal/bytealg/equal_amd64.s:114
#1 0x00007ffff7f138a7 in runtime.vdsoFindVersion (info=0x7fffffffd8a8, ver=0x7ffff7fc5cd0 <runtime[vdsoLinuxVersion]>, ~r0=<optimized out>)
at go/src/runtime/vdso_linux.go:197
#2 0x00007ffff7f13e1b in runtime.vdsoauxv (tag=<optimized out>, val=<optimized out>) at go/src/runtime/vdso_linux.go:284
#3 0x00007ffff7ee25ad in runtime.sysauxv (auxv=..., pairs=<optimized out>) at go/src/runtime/os_linux.go:322
#4 0x00007ffff7ee2305 in runtime.sysargs (argc=<optimized out>, argv=<optimized out>) at go/src/runtime/os_linux.go:251
#5 0x00007ffff7ef935c in runtime.args (c=4700277, v=0x9) at go/src/runtime/runtime1.go:70
#6 0x00007ffff7f1dc65 in runtime.args (c=1, v=0x7fffffffda18) at ./<autogenerated>:1
#7 0x00007ffff7f19cbd in runtime.rt0_go () at go/src/runtime/asm_amd64.s:371
What did you expect to see?
The executable should run fine.
Compiling with an external linker (gcc/ld on musl) produces an executable which runs correctly : go build -buildmode=pie -ldflags '-linkmode=external -extldflags=-static-pie' -o main main.go
Go version
1.26.5
Output of
go envin your module/workspace:What did you do?
Trying to build a static PIE executable, using minimal main.go file:
with this command:
env CGO_ENABLED=0 go build -buildmode=pie -ldflags -d -o main main.goWhat did you see happen?
The executable produced crashes with a segfault.
file ./mainconfirms that the executable is aELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not strippedreadelf -r ./maingivesThere are no relocations in this file.Running through gdb points the segfault here:
What did you expect to see?
The executable should run fine.
Compiling with an external linker (gcc/ld on musl) produces an executable which runs correctly :
go build -buildmode=pie -ldflags '-linkmode=external -extldflags=-static-pie' -o main main.go