The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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. |
| 11 | ifdef 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)))) |
| 13 | endif |
| 14 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 15 | # The name of the target file, without any path prepended. |
Colin Cross | 5a9db90 | 2014-03-21 12:27:37 -0700 | [diff] [blame] | 16 | # This duplicates logic from base_rules.mk because we need to |
| 17 | # know its results before base_rules.mk is included. |
| 18 | include $(BUILD_SYSTEM)/configure_module_stem.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 19 | |
Ying Wang | 98ae798 | 2014-12-18 14:53:52 -0800 | [diff] [blame] | 20 | intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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. |
Dan Willemsen | 50e8753 | 2017-05-19 14:20:02 -0700 | [diff] [blame] | 26 | linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 27 | |
| 28 | ALL_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. |
| 35 | LOCAL_INTERMEDIATE_TARGETS := $(linked_module) |
| 36 | |
| 37 | ################################### |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame^] | 38 | include $(BUILD_SYSTEM)/use_lld_setup.mk |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | include $(BUILD_SYSTEM)/binary.mk |
| 40 | ################################### |
| 41 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 42 | ########################################################### |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 43 | ## Pack relocation tables |
| 44 | ########################################################### |
| 45 | relocation_packer_input := $(linked_module) |
| 46 | relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem) |
| 47 | |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame^] | 48 | include $(BUILD_SYSTEM)/pack_dyn_relocs_setup.mk |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 49 | |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame^] | 50 | # Stand-alone relocation_packer does not work with LLD output, |
| 51 | # but it can be replaced by lld's --pack-dyn-relocs=android. |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 52 | ifeq (true,$(my_pack_module_relocations)) |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame^] | 53 | ifeq (false,$(my_use_clang_lld)) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 54 | # Pack relocations |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 55 | $(relocation_packer_output): $(relocation_packer_input) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 56 | $(pack-elf-relocations) |
| 57 | else |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 58 | $(relocation_packer_output): $(relocation_packer_input) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 59 | @echo "target Unpacked: $(PRIVATE_MODULE) ($@)" |
| 60 | $(copy-file-to-target) |
Chih-Hung Hsieh | 289e8d6 | 2018-05-24 15:13:19 -0700 | [diff] [blame^] | 61 | endif # my_use_clang_lld |
| 62 | else |
| 63 | $(relocation_packer_output): $(relocation_packer_input) |
| 64 | @echo "target Unpacked: $(PRIVATE_MODULE) ($@)" |
| 65 | $(copy-file-to-target) |
| 66 | endif # my_pack_module_relocations |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 67 | |
| 68 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 69 | ## Store a copy with symbols for symbolic debugging |
| 70 | ########################################################### |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 71 | ifeq ($(LOCAL_UNSTRIPPED_PATH),) |
Ying Wang | b8e0185 | 2014-01-23 15:09:04 -0800 | [diff] [blame] | 72 | my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
| 73 | else |
| 74 | my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH) |
Ying Wang | f358496 | 2013-11-13 17:56:20 -0800 | [diff] [blame] | 75 | endif |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 76 | symbolic_input := $(relocation_packer_output) |
Ying Wang | 966c1e0 | 2014-05-20 14:43:51 -0700 | [diff] [blame] | 77 | symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem) |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 78 | $(symbolic_output) : $(symbolic_input) |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 79 | @echo "target Symbolic: $(PRIVATE_MODULE) ($@)" |
| 80 | $(copy-file-to-target) |
| 81 | |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 82 | ########################################################### |
| 83 | ## Store breakpad symbols |
| 84 | ########################################################### |
| 85 | |
| 86 | ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true) |
Steve Fung | dfbab49 | 2015-09-24 18:12:33 -0700 | [diff] [blame] | 87 | my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path)) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 88 | breakpad_input := $(relocation_packer_output) |
| 89 | breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 90 | $(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF) |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 91 | @echo "target breakpad: $(PRIVATE_MODULE) ($@)" |
| 92 | @mkdir -p $(dir $@) |
Steve Fung | 445beae | 2017-08-30 14:58:33 -0700 | [diff] [blame] | 93 | $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \ |
| 94 | $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \ |
| 95 | else \ |
| 96 | echo "skipped for non-elf file."; \ |
| 97 | touch $@; \ |
| 98 | fi |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 99 | $(LOCAL_BUILT_MODULE) : $(breakpad_output) |
| 100 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 101 | |
| 102 | ########################################################### |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 103 | ## Strip |
| 104 | ########################################################### |
Ying Wang | 374b325 | 2011-03-14 11:44:57 -0700 | [diff] [blame] | 105 | strip_input := $(symbolic_output) |
Dmitriy Ivanov | 86bd653 | 2015-05-01 18:12:29 -0700 | [diff] [blame] | 106 | strip_output := $(LOCAL_BUILT_MODULE) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 107 | |
Ying Wang | 6efe88b | 2016-03-01 20:14:52 -0800 | [diff] [blame] | 108 | my_strip_module := $(firstword \ |
| 109 | $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \ |
| 110 | $(LOCAL_STRIP_MODULE)) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 111 | ifeq ($(my_strip_module),) |
Yabin Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 112 | my_strip_module := mini-debug-info |
| 113 | endif |
| 114 | |
| 115 | ifeq ($(my_strip_module),mini-debug-info) |
| 116 | # Don't use mini-debug-info on mips (both 32-bit and 64-bit). objcopy checks that all |
| 117 | # SH_MIPS_DWARF sections having name prefix .debug_ or .zdebug_, so there seems no easy |
| 118 | # way using objcopy to remove all debug sections except .debug_frame on mips. |
| 119 | ifneq ($(filter mips mips64,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
Yabin Cui | 3aa7df5 | 2016-04-19 03:38:34 +0000 | [diff] [blame] | 120 | my_strip_module := true |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 121 | endif |
Yabin Cui | 700883e | 2016-04-26 16:08:00 -0700 | [diff] [blame] | 122 | endif |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 123 | |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 124 | $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
| 125 | $(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) |
Yabin Cui | fab7995 | 2016-03-29 12:22:20 -0700 | [diff] [blame] | 126 | $(strip_output): PRIVATE_NM := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM) |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 127 | $(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF) |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 128 | ifeq ($(my_strip_module),no_debuglink) |
| 129 | $(strip_output): PRIVATE_NO_DEBUGLINK := true |
| 130 | else |
| 131 | $(strip_output): PRIVATE_NO_DEBUGLINK := |
| 132 | endif |
| 133 | |
Yabin Cui | fab7995 | 2016-03-29 12:22:20 -0700 | [diff] [blame] | 134 | ifeq ($(my_strip_module),mini-debug-info) |
| 135 | # Strip the binary, but keep debug frames and symbol table in a compressed .gnu_debugdata section. |
Dan Willemsen | 8938595 | 2018-03-09 10:56:02 -0800 | [diff] [blame] | 136 | $(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM) $(XZ) |
Yabin Cui | fab7995 | 2016-03-29 12:22:20 -0700 | [diff] [blame] | 137 | $(transform-to-stripped-keep-mini-debug-info) |
| 138 | else ifneq ($(filter true no_debuglink,$(my_strip_module)),) |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 139 | # Strip the binary |
Dan Willemsen | 8938595 | 2018-03-09 10:56:02 -0800 | [diff] [blame] | 140 | $(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
Ying Wang | c1729f3 | 2014-08-20 17:12:32 -0700 | [diff] [blame] | 141 | $(transform-to-stripped) |
| 142 | else ifeq ($(my_strip_module),keep_symbols) |
| 143 | # Strip only the debug frames, but leave the symbol table. |
Dan Willemsen | 8938595 | 2018-03-09 10:56:02 -0800 | [diff] [blame] | 144 | $(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 145 | $(transform-to-stripped-keep-symbols) |
Ying Wang | d8c5ca9 | 2014-08-10 16:19:04 -0700 | [diff] [blame] | 146 | |
| 147 | # A product may be configured to strip everything in some build variants. |
| 148 | # We do the stripping as a post-install command so that LOCAL_BUILT_MODULE |
| 149 | # is still with the symbols and we don't need to clean it (and relink) when |
| 150 | # you switch build variant. |
| 151 | ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),) |
| 152 | $(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \ |
| 153 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE) |
| 154 | endif |
Christopher Ferris | a6e2f93 | 2014-03-18 14:50:09 -0700 | [diff] [blame] | 155 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 156 | # Don't strip the binary, just copy it. We can't skip this step |
| 157 | # because a copy of the binary must appear at LOCAL_BUILT_MODULE. |
Dan Willemsen | 7f01615 | 2016-02-29 17:52:39 -0800 | [diff] [blame] | 158 | $(strip_output): $(strip_input) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 159 | @echo "target Unstripped: $(PRIVATE_MODULE) ($@)" |
| 160 | $(copy-file-to-target) |
Ying Wang | e1889af | 2014-03-16 12:43:49 -0700 | [diff] [blame] | 161 | endif # my_strip_module |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 162 | |
Ying Wang | eda6ac2 | 2013-01-28 10:58:01 -0800 | [diff] [blame] | 163 | $(cleantarget): PRIVATE_CLEAN_FILES += \ |
| 164 | $(linked_module) \ |
Steve Fung | cb2e67f | 2015-09-24 01:40:52 -0700 | [diff] [blame] | 165 | $(breakpad_output) \ |
Dmitriy Ivanov | 4c2d1a6 | 2015-04-20 16:59:05 -0700 | [diff] [blame] | 166 | $(symbolic_output) \ |
| 167 | $(strip_output) |