1########################################################### 2## Standard rules for building any target-side binaries 3## with dynamic linkage (dynamic libraries or executables 4## that link with dynamic libraries) 5## 6## Files including this file must define a rule to build 7## the target $(linked_module). 8########################################################### 9 10# This constraint means that we can hard-code any $(TARGET_*) variables. 11ifdef LOCAL_IS_HOST_MODULE 12$(error This file should not be used to build host binaries. Included by (or near) $(lastword $(filter-out config/%,$(MAKEFILE_LIST)))) 13endif 14 15# The name of the target file, without any path prepended. 16# This duplicates logic from base_rules.mk because we need to 17# know its results before base_rules.mk is included. 18include $(BUILD_SYSTEM)/configure_module_stem.mk 19 20intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) 21 22# Define the target that is the unmodified output of the linker. 23# The basename of this target must be the same as the final output 24# binary name, because it's used to set the "soname" in the binary. 25# The includer of this file will define a rule to build this target. 26linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem)) 27 28# This tells binary.make to explicitly define the PRIVATE_ variables for 29# linked_module as well as for LOCAL_BUILT_MODULE. 30LOCAL_INTERMEDIATE_TARGETS := $(linked_module) 31 32################################### 33include $(BUILD_SYSTEM)/use_lld_setup.mk 34include $(BUILD_SYSTEM)/binary.mk 35################################### 36 37ifdef LOCAL_INJECT_BSSL_HASH 38inject_module := $(intermediates)/INJECT_BSSL_HASH/$(notdir $(my_installed_module_stem)) 39LOCAL_INTERMEDIATE_TARGETS += $(inject_module) 40$(inject_module): $(SOONG_HOST_OUT)/bin/bssl_inject_hash 41$(inject_module): $(linked_module) 42 @echo "target inject BSSL hash: $(PRIVATE_MODULE) ($@)" 43 $(SOONG_HOST_OUT)/bin/bssl_inject_hash -in-object $< -o $@ 44else 45inject_module := $(linked_module) 46endif 47 48########################################################### 49## Store a copy with symbols for symbolic debugging 50########################################################### 51ifeq ($(LOCAL_UNSTRIPPED_PATH),) 52my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 53else 54my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) 55endif 56symbolic_input := $(inject_module) 57symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 58elf_mapping_path := $(patsubst $(TARGET_OUT_UNSTRIPPED)/%,$(call intermediates-dir-for,PACKAGING,elf_symbol_mapping)/%,$(symbolic_output).textproto) 59 60ALL_MODULES.$(my_register_name).SYMBOLIC_OUTPUT_PATH := $(symbolic_output) 61ALL_MODULES.$(my_register_name).ELF_SYMBOL_MAPPING_PATH := $(elf_mapping_path) 62 63$(eval $(call copy-unstripped-elf-file-with-mapping,$(symbolic_input),$(symbolic_output),$(elf_mapping_path))) 64 65########################################################### 66## Store breakpad symbols 67########################################################### 68 69ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 70my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 71breakpad_input := $(inject_module) 72breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 73$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) 74 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 75 @mkdir -p $(dir $@) 76 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ 77 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ 78 else \ 79 echo "skipped for non-elf file."; \ 80 touch $@; \ 81 fi 82$(LOCAL_BUILT_MODULE) : $(breakpad_output) 83endif 84 85########################################################### 86## Strip 87########################################################### 88strip_input := $(inject_module) 89strip_output := $(LOCAL_BUILT_MODULE) 90 91# Use an order-only dependency to ensure the unstripped file in the symbols 92# directory is copied when the module is built, but does not force the 93# module to be rebuilt when the symbols directory is cleaned by installclean. 94$(strip_output): | $(symbolic_output) 95 96my_strip_module := $(firstword \ 97 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ 98 $(LOCAL_STRIP_MODULE)) 99ifeq ($(my_strip_module),) 100 my_strip_module := mini-debug-info 101endif 102 103ifeq ($(my_strip_module),false) 104 my_strip_module := 105endif 106 107my_strip_args := 108ifeq ($(my_strip_module),mini-debug-info) 109 my_strip_args += --keep-mini-debug-info 110else ifeq ($(my_strip_module),keep_symbols) 111 my_strip_args += --keep-symbols 112endif 113 114ifeq (,$(filter no_debuglink mini-debug-info,$(my_strip_module))) 115 ifneq ($(TARGET_BUILD_VARIANT),user) 116 my_strip_args += --add-gnu-debuglink 117 endif 118endif 119 120ifeq ($($(my_prefix)OS),darwin) 121 # llvm-strip does not support Darwin Mach-O yet. 122 my_strip_args += --use-gnu-strip 123endif 124 125valid_strip := mini-debug-info keep_symbols true no_debuglink 126ifneq (,$(filter-out $(valid_strip),$(my_strip_module))) 127 $(call pretty-error,Invalid strip value $(my_strip_module), only one of $(valid_strip) allowed) 128endif 129 130ifneq (,$(my_strip_module)) 131 $(strip_output): PRIVATE_STRIP_ARGS := $(my_strip_args) 132 $(strip_output): PRIVATE_TOOLS_PREFIX := $($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)TOOLS_PREFIX) 133 $(strip_output): $(strip_input) $(SOONG_STRIP_PATH) $(XZ) 134 @echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)" 135 CLANG_BIN=$(LLVM_PREBUILTS_PATH) \ 136 CROSS_COMPILE=$(PRIVATE_TOOLS_PREFIX) \ 137 XZ=$(XZ) \ 138 CREATE_MINIDEBUGINFO=${CREATE_MINIDEBUGINFO} \ 139 $(SOONG_STRIP_PATH) -i $< -o $@ -d $@.strip.d $(PRIVATE_STRIP_ARGS) 140 ifneq ($(HOST_OS),darwin) 141 $(strip_output): $(CREATE_MINIDEBUGINFO) 142 endif 143 $(call include-depfile,$(strip_output).strip.d,$(strip_output)) 144else 145 # Don't strip the binary, just copy it. We can't skip this step 146 # because a copy of the binary must appear at LOCAL_BUILT_MODULE. 147 $(strip_output): $(strip_input) 148 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 149 $(copy-file-to-target) 150endif # my_strip_module 151 152$(cleantarget): PRIVATE_CLEAN_FILES += \ 153 $(linked_module) \ 154 $(inject_module) \ 155 $(breakpad_output) \ 156 $(symbolic_output) \ 157 $(strip_output) 158