Creating golang binary with the .interp section set to /lib64/ld-linux.so.2

Hello, I would like to build binary that have a “standard” interp section to be able to deploy them in a docker container / AWS Lambda instance.

For now, I have tried static build (but I use MySQL so my binary fails to run) and I have also tried to build inside an FHS user env.

This is what look like an ldd output of my binary:

	linux-vdso.so.1 (0x00007ffd13929000)
	libpthread.so.0 => /nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/libpthread.so.0 (0x00007f186ef88000)
	libc.so.6 => /nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/libc.so.6 (0x00007f186edd2000)
	/nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/ld-linux-x86-64.so.2 => /nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007f186efab000)

I would like to replace /nix/store/pnd2kl27sag76h23wa5kl95a76n3k9i3-glibc-2.27/lib/ld-linux-x86-64.so.2 to /lib/ld-linux-x86-64.so.2 and I can’t use patchelf as it doesn’t work on Go binaries.

My goal is to make a Go binary that can be executed on other Linux distribution.

Thanks in advance

OK, I have found a solution. You just need to pass this flag to Go:
-ldflags “-I=/lib64/ld-linux-x86-64.so.2”