aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffery To <jeffery.to@gmail.com>2020-01-14 22:17:21 +0800
committerJeffery To <jeffery.to@gmail.com>2020-01-14 22:17:21 +0800
commitc18adadd9186af0897a49e99c290b32553e529aa (patch)
tree9c96f14e7962900c680c3d1560b0ec3f715aa5b3
parentb36f27716f63c04d654e46dd115d5195f0c7cbba (diff)
golang: Add support for ASLR/PIE for Go packages
This adds support to compile position-independent executables for packages that use golang-package.mk. Go packages will have PIE enabled if: * Go supports PIE on the target platform; * CONFIG_PKG_ASLR_PIE is selected; and * PKG_ASLR_PIE (for the package) is not set to 0 Go 1.13 supports PIE for x86 and arm targets; mips support is in progress[1]. [1]: https://github.com/golang/go/issues/21222#issuecomment-542064462 Signed-off-by: Jeffery To <jeffery.to@gmail.com>
-rw-r--r--lang/golang/golang-package.mk9
1 files changed, 9 insertions, 0 deletions
diff --git a/lang/golang/golang-package.mk b/lang/golang/golang-package.mk
index ec7b0e99b..235585b20 100644
--- a/lang/golang/golang-package.mk
+++ b/lang/golang/golang-package.mk
@@ -120,6 +120,14 @@ GO_PKG_BUILD_BIN_DIR:=$(GO_PKG_BUILD_DIR)/bin$(if $(GO_HOST_TARGET_DIFFERENT),/$
GO_PKG_BUILD_DEPENDS_SRC:=$(STAGING_DIR)$(GO_PKG_PATH)/src
+ifeq ($(CONFIG_PKG_ASLR_PIE),y)
+ ifeq ($(strip $(PKG_ASLR_PIE)),1)
+ ifeq ($(GO_TARGET_PIE_SUPPORTED),1)
+ GO_PKG_ENABLE_PIE:=1
+ endif
+ endif
+endif
+
# sstrip causes corrupted section header size
ifneq ($(CONFIG_USE_SSTRIP),)
ifneq ($(CONFIG_DEBUG),)
@@ -281,6 +289,7 @@ define GoPackage/Build/Compile
pkg_ldflags="$$$$pkg_ldflags -X $$$$def" ; \
done ; \
go install \
+ $(if $(GO_PKG_ENABLE_PIE),-buildmode pie) \
$$$${installsuffix:+-installsuffix $$$$installsuffix} \
-trimpath \
-ldflags "all=$$$$ldflags" \