blob: f44b8a88f2f31861f8834f43a94316df1594557e [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001###########################################################
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
The Android Open Source Project88b60792009-03-03 19:28:42 -080015# The name of the target file, without any path prepended.
Colin Cross5a9db902014-03-21 12:27:37 -070016# 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
The Android Open Source Project88b60792009-03-03 19:28:42 -080019
Ying Wang98ae7982014-12-18 14:53:52 -080020intermediates := $(call local-intermediates-dir,,$(LOCAL_2ND_ARCH_VAR_PREFIX))
The Android Open Source Project88b60792009-03-03 19:28:42 -080021
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 Willemsen50e87532017-05-19 14:20:02 -070026linked_module := $(intermediates)/LINKED/$(notdir $(my_installed_module_stem))
The Android Open Source Project88b60792009-03-03 19:28:42 -080027
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
The Android Open Source Project88b60792009-03-03 19:28:42 -080041###########################################################
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070042## Pack relocation tables
43###########################################################
44relocation_packer_input := $(linked_module)
45relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem)
46
Dan Albert52831d12015-11-12 15:27:49 -080047my_pack_module_relocations := false
48ifneq ($(DISABLE_RELOCATION_PACKER),true)
Ying Wang6efe88b2016-03-01 20:14:52 -080049 my_pack_module_relocations := $(firstword \
50 $(LOCAL_PACK_MODULE_RELOCATIONS_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
51 $(LOCAL_PACK_MODULE_RELOCATIONS))
Dan Albert52831d12015-11-12 15:27:49 -080052endif
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070053
54ifeq ($(my_pack_module_relocations),)
55 my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS)
56endif
57
Dmitriy Ivanove24b6f72015-04-29 12:13:37 -070058# Do not pack relocations for executables. Because packing results in
59# non-zero p_vaddr which causes kernel to load executables to lower
60# address (starting at 0x8000) http://b/20665974
Dan Willemsen7fe992c2016-03-02 13:54:51 -080061ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070062 my_pack_module_relocations := false
63endif
64
65# TODO (dimitry): Relocation packer is not yet available for darwin
66ifneq ($(HOST_OS),linux)
67 my_pack_module_relocations := false
68endif
69
70ifeq (true,$(my_pack_module_relocations))
71# Pack relocations
Dan Willemsen7f016152016-02-29 17:52:39 -080072$(relocation_packer_output): $(relocation_packer_input)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070073 $(pack-elf-relocations)
74else
Dan Willemsen7f016152016-02-29 17:52:39 -080075$(relocation_packer_output): $(relocation_packer_input)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070076 @echo "target Unpacked: $(PRIVATE_MODULE) ($@)"
77 $(copy-file-to-target)
78endif
79
80###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070081## Store a copy with symbols for symbolic debugging
82###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080083ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080084my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
85else
86my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080087endif
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070088symbolic_input := $(relocation_packer_output)
Ying Wang966c1e02014-05-20 14:43:51 -070089symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Dan Willemsen7f016152016-02-29 17:52:39 -080090$(symbolic_output) : $(symbolic_input)
Ying Wang374b3252011-03-14 11:44:57 -070091 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
92 $(copy-file-to-target)
93
Steve Fungcb2e67f2015-09-24 01:40:52 -070094###########################################################
95## Store breakpad symbols
96###########################################################
97
98ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070099my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Steve Fungcb2e67f2015-09-24 01:40:52 -0700100breakpad_input := $(relocation_packer_output)
101breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -0700102$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -0700103 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
104 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -0700105 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \
106 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \
107 else \
108 echo "skipped for non-elf file."; \
109 touch $@; \
110 fi
Steve Fungcb2e67f2015-09-24 01:40:52 -0700111$(LOCAL_BUILT_MODULE) : $(breakpad_output)
112endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800113
114###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -0800115## Strip
116###########################################################
Ying Wang374b3252011-03-14 11:44:57 -0700117strip_input := $(symbolic_output)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -0700118strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800119
Ying Wang6efe88b2016-03-01 20:14:52 -0800120my_strip_module := $(firstword \
121 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
122 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -0700123ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -0700124 my_strip_module := mini-debug-info
125endif
126
127ifeq ($(my_strip_module),mini-debug-info)
128# Don't use mini-debug-info on mips (both 32-bit and 64-bit). objcopy checks that all
129# SH_MIPS_DWARF sections having name prefix .debug_ or .zdebug_, so there seems no easy
130# way using objcopy to remove all debug sections except .debug_frame on mips.
131ifneq ($(filter mips mips64,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
Yabin Cui3aa7df52016-04-19 03:38:34 +0000132 my_strip_module := true
The Android Open Source Project88b60792009-03-03 19:28:42 -0800133endif
Yabin Cui700883e2016-04-26 16:08:00 -0700134endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700136$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
137$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
Yabin Cuifab79952016-03-29 12:22:20 -0700138$(strip_output): PRIVATE_NM := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700139$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
Ying Wangc1729f32014-08-20 17:12:32 -0700140ifeq ($(my_strip_module),no_debuglink)
141$(strip_output): PRIVATE_NO_DEBUGLINK := true
142else
143$(strip_output): PRIVATE_NO_DEBUGLINK :=
144endif
145
Yabin Cuifab79952016-03-29 12:22:20 -0700146ifeq ($(my_strip_module),mini-debug-info)
147# Strip the binary, but keep debug frames and symbol table in a compressed .gnu_debugdata section.
148$(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)
149 $(transform-to-stripped-keep-mini-debug-info)
150else ifneq ($(filter true no_debuglink,$(my_strip_module)),)
Ying Wangc1729f32014-08-20 17:12:32 -0700151# Strip the binary
152$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
153 $(transform-to-stripped)
154else ifeq ($(my_strip_module),keep_symbols)
155# Strip only the debug frames, but leave the symbol table.
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700156$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
157 $(transform-to-stripped-keep-symbols)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700158
159# A product may be configured to strip everything in some build variants.
160# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
161# is still with the symbols and we don't need to clean it (and relink) when
162# you switch build variant.
163ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
164$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
165 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
166endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700167else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800168# Don't strip the binary, just copy it. We can't skip this step
169# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
Dan Willemsen7f016152016-02-29 17:52:39 -0800170$(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800171 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
172 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700173endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800174
Ying Wangeda6ac22013-01-28 10:58:01 -0800175$(cleantarget): PRIVATE_CLEAN_FILES += \
176 $(linked_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700177 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700178 $(symbolic_output) \
179 $(strip_output)