From 32427d6903b2a32508eb7cc76c8e83ccea126be6 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 12 Apr 2018 10:55:54 -0700 Subject: [PATCH] Add USE_CLANG_LLD and LOCAL_USE_CLANG_LLD * Current default is not using lld. * When USE_CLANG_LLD or LOCAL_USE_CLANG_LLD is true or 1, * Use *GLOBAL_LLDFLAGS instead of *GLOBAL_LDFLAGS. GLOBAL_LLDFLAGS should call lld and with correct lld flags. * set my_pack_module_relocations to false. Bug: 73768157 Test: make checkbuild Change-Id: I3e63cf8ae0865d01d2bc1f36e9304f4a5d092cb8 --- core/binary.mk | 7 ++++++- core/clear_vars.mk | 1 + core/dynamic_binary.mk | 5 +++++ core/prebuilt_internal.mk | 8 ++++++++ core/soong_config.mk | 1 + core/use_lld_setup.mk | 14 ++++++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 core/use_lld_setup.mk diff --git a/core/binary.mk b/core/binary.mk index 954df1f44..a5f46daee 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -7,6 +7,7 @@ ####################################### include $(BUILD_SYSTEM)/base_rules.mk +include $(BUILD_SYSTEM)/use_lld_setup.mk ####################################### ################################################## @@ -516,7 +517,11 @@ ifeq ($(my_clang),true) my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CFLAGS) my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags) my_target_global_cppflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_CPPFLAGS) $(my_cpp_std_cppflags) -my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS) +ifeq ($(my_use_clang_lld),true) + my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LLDFLAGS) +else + my_target_global_ldflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)CLANG_$(my_prefix)GLOBAL_LDFLAGS) +endif # my_use_clang_lld else my_target_global_cflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_CFLAGS) my_target_global_conlyflags := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)GLOBAL_CONLYFLAGS) $(my_c_std_conlyflags) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index eccaad54d..62549d97e 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -264,6 +264,7 @@ LOCAL_TIDY_FLAGS:= LOCAL_UNINSTALLABLE_MODULE:= LOCAL_UNSTRIPPED_PATH:= LOCAL_USE_AAPT2:=$(USE_AAPT2) +LOCAL_USE_CLANG_LLD:= LOCAL_USE_R8:= LOCAL_USE_VNDK:= LOCAL_VENDOR_MODULE:= diff --git a/core/dynamic_binary.mk b/core/dynamic_binary.mk index ebbe71c2d..74e0fa2de 100644 --- a/core/dynamic_binary.mk +++ b/core/dynamic_binary.mk @@ -67,6 +67,11 @@ ifneq ($(HOST_OS),linux) my_pack_module_relocations := false endif +# Relocation packer does not work with LLD yet. +ifeq ($(my_use_clang_lld),true) + my_pack_module_relocations := false +endif + ifeq (true,$(my_pack_module_relocations)) # Pack relocations $(relocation_packer_output): $(relocation_packer_input) diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index 96e26137a..a9eb29e01 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -6,6 +6,8 @@ ## ########################################################### +include $(BUILD_SYSTEM)/use_lld_setup.mk + ifneq ($(LOCAL_PREBUILT_LIBS),) $(error dont use LOCAL_PREBUILT_LIBS anymore LOCAL_PATH=$(LOCAL_PATH)) endif @@ -70,6 +72,12 @@ ifeq (SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)) ifeq ($(DISABLE_RELOCATION_PACKER),true) my_pack_module_relocations := false endif + + # Relocation packer does not work with LLD yet. + # my_use_clang_lld might be used befor set up in binary.mk + ifeq ($(my_use_clang_lld),true) + my_pack_module_relocations := false + endif endif ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES,$(LOCAL_MODULE_CLASS)),) diff --git a/core/soong_config.mk b/core/soong_config.mk index ab493d916..296d54988 100644 --- a/core/soong_config.mk +++ b/core/soong_config.mk @@ -99,6 +99,7 @@ $(call add_json_list, CFIExcludePaths, $(CFI_EXCLUDE_PATHS) $( $(call add_json_list, CFIIncludePaths, $(CFI_INCLUDE_PATHS) $(PRODUCT_CFI_INCLUDE_PATHS)) $(call add_json_list, IntegerOverflowExcludePaths, $(INTEGER_OVERFLOW_EXCLUDE_PATHS) $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS)) +$(call add_json_bool, UseClangLld, $(filter 1 true,$(USE_CLANG_LLD))) $(call add_json_bool, ClangTidy, $(filter 1 true,$(WITH_TIDY))) $(call add_json_str, TidyChecks, $(WITH_TIDY_CHECKS)) diff --git a/core/use_lld_setup.mk b/core/use_lld_setup.mk new file mode 100644 index 000000000..69ceddc53 --- /dev/null +++ b/core/use_lld_setup.mk @@ -0,0 +1,14 @@ +############################################################# +## Set up flags based on USE_CLANG_LLD and LOCAL_USE_CLANG_LLD. +## Input variables: USE_CLANG_LLD,LOCAL_USE_CLANG_LLD. +## Output variables: my_use_clang_lld +############################################################# + +# Use LLD only if it's not disabled by LOCAL_USE_CLANG_LLD, +# and enabled by LOCAL_USE_CLANG_LLD or USE_CLANG_LLD. +my_use_clang_lld := false +ifeq (,$(filter 0 false,$(LOCAL_USE_CLANG_LLD))) + ifneq (,$(filter 1 true,$(LOCAL_USE_CLANG_LLD) $(USE_CLANG_LLD))) + my_use_clang_lld := true + endif +endif