Go 1.18.4 Created static binary, but Go 1.19.1 binary is dynamic

On my Ubuntu 22.04 platform, a binary that used to be static (compiled with Go v1.18.4) now says dynamic (when checked with file command), using Go v1.19.1. I created the binary with:

$go build -ldflags -extldflags=-static

Has something changed with Go v1.19.1? The ldd command shows dependency on

 linux-vdso.so.1
 libpthread.so.0
 libc.so.6
 /lib64/ld-linux-x86-64.so.2

The difference in binary sizes is < 3%, so there isn’t a huge difference in binary sizes. My preference is to compile a static binary, if possible.

I searched online, and someone suggested that I should build with:

$go build -ldflags "-linkmode external -extldflags=-static"

With the linkmode option, i get a bunch of warnings about using ‘getgrouplist’/‘mygetgrgid_r’/‘mygetgrnam_r’/‘mygetpwuid_r’/‘cgo_*_getaddrinfo’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking. But the resulting binary is static!

Will this program crash when it tries to use those libraries? Or will it simply pull in the necessary dynamic library?

My ideal is to ship a static binary. But given the migration to Go v1.19.1, should I just ship the dynamic version, and hope there’s no compatibility issues, or should I build with -linkmode external, and hope everything would just work?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.