In Go 1.15, the linker now defaults to internal linking mode for
-buildmode=pie on amd64 and arm64[1], however this results in go tool
binaries with the wrong dynamic linker/interpreter.
External linking is still used when PIE is enabled for other platforms,
whereas internal linking is used when PIE is not enabled.
This changes target Go to always use external linking, to fix PIE
binaries for amd64/arm64 and for consistency.
[1]: https://golang.org/doc/go1.15#linker
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
PKG_GO_LDFLAGS= \
-buildid '$(SOURCE_DATE_EPOCH)' \
+ -linkmode external \
+ -extldflags '$(patsubst -z%,-Wl$(comma)-z$(comma)%,$(TARGET_LDFLAGS))' \
$(if $(CONFIG_NO_STRIP)$(CONFIG_DEBUG),,-s -w)
# setting -trimpath is not necessary here because the paths inside the