diff --git a/core/binary.mk b/core/binary.mk index 42d6f7640..beec71049 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -281,13 +281,18 @@ endif # all code is position independent, and then those warnings get promoted to # errors. ifneq ($(LOCAL_NO_PIC),true) -ifneq ($($(my_prefix)OS),windows) -ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) -my_cflags += -fPIE -else -my_cflags += -fPIC -endif -endif + ifneq ($($(my_prefix)OS),windows) + ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) + my_cflags += -fPIE + ifndef BUILD_HOST_static + ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) + my_ldflags += -pie + endif + endif + else + my_cflags += -fPIC + endif + endif endif ifdef LOCAL_IS_HOST_MODULE diff --git a/core/definitions.mk b/core/definitions.mk index 4df4bc6c2..0f9d4dd9a 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1879,11 +1879,6 @@ endef ########################################################### ## Commands for running gcc to link a host executable ########################################################### -ifdef BUILD_HOST_static -HOST_FPIE_FLAGS := -else -HOST_FPIE_FLAGS := -pie -endif ifneq ($(HOST_CUSTOM_LD_COMMAND),true) define transform-host-o-to-executable-inner diff --git a/core/host_executable.mk b/core/host_executable.mk index 324f5ffc9..a2111a1eb 100644 --- a/core/host_executable.mk +++ b/core/host_executable.mk @@ -11,10 +11,6 @@ my_module_multilib := first endif endif -ifeq ($(LOCAL_NO_FPIE),) -LOCAL_LDFLAGS += $(HOST_FPIE_FLAGS) -endif - ifeq ($(my_module_multilib),both) ifneq ($(LOCAL_MODULE_CLASS),NATIVE_TESTS) ifeq ($(LOCAL_MODULE_PATH_32)$(LOCAL_MODULE_STEM_32),) @@ -63,10 +59,6 @@ LOCAL_BUILT_MODULE := LOCAL_INSTALLED_MODULE := LOCAL_INTERMEDIATE_TARGETS := -ifeq ($(LOCAL_NO_FPIE),) -LOCAL_LDFLAGS += $(HOST_CROSS_FPIE_FLAGS) -endif - include $(BUILD_SYSTEM)/host_executable_internal.mk LOCAL_LDFLAGS := $(saved_LOCAL_LDFLAGS) LOCAL_BUILT_MODULE := $(saved_LOCAL_BUILT_MODULE) @@ -85,10 +77,6 @@ LOCAL_BUILT_MODULE := LOCAL_INSTALLED_MODULE := LOCAL_INTERMEDIATE_TARGETS := -ifeq ($(LOCAL_NO_FPIE),) -LOCAL_LDFLAGS += $(HOST_CROSS_FPIE_FLAGS) -endif - include $(BUILD_SYSTEM)/host_executable_internal.mk LOCAL_LDFLAGS := $(saved_LOCAL_LDFLAGS) LOCAL_BUILT_MODULE := $(saved_LOCAL_BUILT_MODULE)