dynamic_binary.mk revision 52831d118c7c1b449b6d919dd87e55c423c6bca6
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/$(my_built_module_stem) 27 28ALL_ORIGINAL_DYNAMIC_BINARIES += $(linked_module) 29 30# Because TARGET_SYMBOL_FILTER_FILE depends on ALL_ORIGINAL_DYNAMIC_BINARIES, 31# the linked_module rules won't necessarily inherit the PRIVATE_ 32# variables from LOCAL_BUILT_MODULE. This tells binary.make to explicitly 33# define the PRIVATE_ variables for linked_module as well as for 34# LOCAL_BUILT_MODULE. 35LOCAL_INTERMEDIATE_TARGETS := $(linked_module) 36 37################################### 38include $(BUILD_SYSTEM)/binary.mk 39################################### 40 41########################################################### 42## Pack relocation tables 43########################################################### 44relocation_packer_input := $(linked_module) 45relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem) 46 47my_pack_module_relocations := false 48ifneq ($(DISABLE_RELOCATION_PACKER),true) 49 my_pack_module_relocations := $(LOCAL_PACK_MODULE_RELOCATIONS) 50endif 51 52ifeq ($(my_pack_module_relocations),) 53 my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS) 54endif 55 56# Do not pack relocations for executables. Because packing results in 57# non-zero p_vaddr which causes kernel to load executables to lower 58# address (starting at 0x8000) http://b/20665974 59ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) 60 my_pack_module_relocations := false 61endif 62 63# TODO (dimitry): Relocation packer is not yet available for darwin 64ifneq ($(HOST_OS),linux) 65 my_pack_module_relocations := false 66endif 67 68ifeq (true,$(my_pack_module_relocations)) 69# Pack relocations 70$(relocation_packer_output): $(relocation_packer_input) | $(ACP) 71 $(pack-elf-relocations) 72else 73$(relocation_packer_output): $(relocation_packer_input) | $(ACP) 74 @echo "target Unpacked: $(PRIVATE_MODULE) ($@)" 75 $(copy-file-to-target) 76endif 77 78########################################################### 79## Store a copy with symbols for symbolic debugging 80########################################################### 81ifeq ($(LOCAL_UNSTRIPPED_PATH),) 82my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 83else 84my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) 85endif 86symbolic_input := $(relocation_packer_output) 87symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) 88$(symbolic_output) : $(symbolic_input) | $(ACP) 89 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" 90 $(copy-file-to-target) 91 92########################################################### 93## Store breakpad symbols 94########################################################### 95 96ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) 97my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) 98breakpad_input := $(relocation_packer_output) 99breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym 100$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) 101 @echo "target breakpad: $(PRIVATE_MODULE) ($@)" 102 @mkdir -p $(dir $@) 103 $(hide) $(BREAKPAD_DUMP_SYMS) -c $< > $@ 104$(LOCAL_BUILT_MODULE) : $(breakpad_output) 105endif 106 107########################################################### 108## Strip 109########################################################### 110strip_input := $(symbolic_output) 111strip_output := $(LOCAL_BUILT_MODULE) 112 113my_strip_module := $(LOCAL_STRIP_MODULE) 114ifeq ($(my_strip_module),) 115 my_strip_module := true 116endif 117 118$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) 119$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) 120$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) 121ifeq ($(my_strip_module),no_debuglink) 122$(strip_output): PRIVATE_NO_DEBUGLINK := true 123else 124$(strip_output): PRIVATE_NO_DEBUGLINK := 125endif 126 127ifneq ($(filter true no_debuglink,$(my_strip_module)),) 128# Strip the binary 129$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) 130 $(transform-to-stripped) 131else ifeq ($(my_strip_module),keep_symbols) 132# Strip only the debug frames, but leave the symbol table. 133$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) 134 $(transform-to-stripped-keep-symbols) 135 136# A product may be configured to strip everything in some build variants. 137# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE 138# is still with the symbols and we don't need to clean it (and relink) when 139# you switch build variant. 140ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) 141$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ 142 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) 143endif 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# 148# If the binary we're copying is acp or a prerequisite, 149# use cp(1) instead. 150ifneq ($(LOCAL_ACP_UNAVAILABLE),true) 151$(strip_output): $(strip_input) | $(ACP) 152 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 153 $(copy-file-to-target) 154else 155$(strip_output): $(strip_input) 156 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" 157 $(copy-file-to-target-with-cp) 158endif 159endif # my_strip_module 160 161$(cleantarget): PRIVATE_CLEAN_FILES += \ 162 $(linked_module) \ 163 $(breakpad_output) \ 164 $(symbolic_output) \ 165 $(strip_output) 166