blob: 939af33bd50dd75001b97f122f9cae8f19264ec0 [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###################################
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070038include $(BUILD_SYSTEM)/use_lld_setup.mk
The Android Open Source Project88b60792009-03-03 19:28:42 -080039include $(BUILD_SYSTEM)/binary.mk
40###################################
41
The Android Open Source Project88b60792009-03-03 19:28:42 -080042###########################################################
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070043## Pack relocation tables
44###########################################################
45relocation_packer_input := $(linked_module)
46relocation_packer_output := $(intermediates)/PACKED/$(my_built_module_stem)
47
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070048include $(BUILD_SYSTEM)/pack_dyn_relocs_setup.mk
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070049
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070050# Stand-alone relocation_packer does not work with LLD output,
51# but it can be replaced by lld's --pack-dyn-relocs=android.
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070052ifeq (true,$(my_pack_module_relocations))
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070053ifeq (false,$(my_use_clang_lld))
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070054# Pack relocations
Dan Willemsen7f016152016-02-29 17:52:39 -080055$(relocation_packer_output): $(relocation_packer_input)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070056 $(pack-elf-relocations)
57else
Chih-Hung Hsieh9020c232018-06-01 14:11:15 -070058relocation_packer_output := $(relocation_packer_input)
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070059endif # my_use_clang_lld
60else
Chih-Hung Hsieh9020c232018-06-01 14:11:15 -070061relocation_packer_output := $(relocation_packer_input)
Chih-Hung Hsieh289e8d62018-05-24 15:13:19 -070062endif # my_pack_module_relocations
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070063
64###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070065## Store a copy with symbols for symbolic debugging
66###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080067ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080068my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
69else
70my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080071endif
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070072symbolic_input := $(relocation_packer_output)
Ying Wang966c1e02014-05-20 14:43:51 -070073symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Dan Willemsen7f016152016-02-29 17:52:39 -080074$(symbolic_output) : $(symbolic_input)
Ying Wang374b3252011-03-14 11:44:57 -070075 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
76 $(copy-file-to-target)
77
Steve Fungcb2e67f2015-09-24 01:40:52 -070078###########################################################
79## Store breakpad symbols
80###########################################################
81
82ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070083my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Steve Fungcb2e67f2015-09-24 01:40:52 -070084breakpad_input := $(relocation_packer_output)
85breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -070086$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -070087 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
88 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -070089 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \
90 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \
91 else \
92 echo "skipped for non-elf file."; \
93 touch $@; \
94 fi
Steve Fungcb2e67f2015-09-24 01:40:52 -070095$(LOCAL_BUILT_MODULE) : $(breakpad_output)
96endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080097
98###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080099## Strip
100###########################################################
Ying Wang374b3252011-03-14 11:44:57 -0700101strip_input := $(symbolic_output)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -0700102strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800103
Ying Wang6efe88b2016-03-01 20:14:52 -0800104my_strip_module := $(firstword \
105 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
106 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -0700107ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -0700108 my_strip_module := mini-debug-info
109endif
110
111ifeq ($(my_strip_module),mini-debug-info)
112# Don't use mini-debug-info on mips (both 32-bit and 64-bit). objcopy checks that all
113# SH_MIPS_DWARF sections having name prefix .debug_ or .zdebug_, so there seems no easy
114# way using objcopy to remove all debug sections except .debug_frame on mips.
115ifneq ($(filter mips mips64,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
Yabin Cui3aa7df52016-04-19 03:38:34 +0000116 my_strip_module := true
The Android Open Source Project88b60792009-03-03 19:28:42 -0800117endif
Yabin Cui700883e2016-04-26 16:08:00 -0700118endif
The Android Open Source Project88b60792009-03-03 19:28:42 -0800119
Chih-Hung Hsieh9546d672018-06-01 14:07:52 -0700120ifeq ($(my_use_clang_lld),true)
121 # b/80093681: GNU strip and objcopy --{add,remove}-section have bug in handling
122 # GNU_RELRO segment of files lnked by clang lld; so they are replaced
123 # by llvm-strip and llvm-objcopy here.
124 $(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $(LLVM_OBJCOPY)
125 $(strip_output): PRIVATE_STRIP := $(LLVM_STRIP)
126 $(strip_output): PRIVATE_STRIP_O_FLAG :=
127 # GNU strip keeps .ARM.attributes section even with -strip-all,
128 # so here pass -keep=.ARM.attributes to llvm-strip.
129 $(strip_output): PRIVATE_STRIP_ALL_FLAGS := -strip-all -keep=.ARM.attributes
130else
131 $(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
132 $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
133 $(strip_output): PRIVATE_STRIP_O_FLAG := -o
134 $(strip_output): PRIVATE_STRIP_ALL_FLAGS := --strip-all
135endif
136# PRIVATE_OBJCOPY is not changed to llvm-objcopy yet.
137# It is used even when my_use_clang_lld is true,
138# because some objcopy flags are not supported by llvm-objcopy yet.
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700139$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
Yabin Cuifab79952016-03-29 12:22:20 -0700140$(strip_output): PRIVATE_NM := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700141$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
Ying Wangc1729f32014-08-20 17:12:32 -0700142ifeq ($(my_strip_module),no_debuglink)
143$(strip_output): PRIVATE_NO_DEBUGLINK := true
144else
145$(strip_output): PRIVATE_NO_DEBUGLINK :=
146endif
147
Yabin Cuifab79952016-03-29 12:22:20 -0700148ifeq ($(my_strip_module),mini-debug-info)
149# Strip the binary, but keep debug frames and symbol table in a compressed .gnu_debugdata section.
Dan Willemsen89385952018-03-09 10:56:02 -0800150$(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 Cuifab79952016-03-29 12:22:20 -0700151 $(transform-to-stripped-keep-mini-debug-info)
152else ifneq ($(filter true no_debuglink,$(my_strip_module)),)
Ying Wangc1729f32014-08-20 17:12:32 -0700153# Strip the binary
Dan Willemsen89385952018-03-09 10:56:02 -0800154$(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
Ying Wangc1729f32014-08-20 17:12:32 -0700155 $(transform-to-stripped)
156else ifeq ($(my_strip_module),keep_symbols)
157# Strip only the debug frames, but leave the symbol table.
Dan Willemsen89385952018-03-09 10:56:02 -0800158$(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700159 $(transform-to-stripped-keep-symbols)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700160
161# A product may be configured to strip everything in some build variants.
162# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
163# is still with the symbols and we don't need to clean it (and relink) when
164# you switch build variant.
165ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
166$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
167 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
168endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700169else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800170# Don't strip the binary, just copy it. We can't skip this step
171# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
Dan Willemsen7f016152016-02-29 17:52:39 -0800172$(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800173 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
174 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700175endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800176
Ying Wangeda6ac22013-01-28 10:58:01 -0800177$(cleantarget): PRIVATE_CLEAN_FILES += \
178 $(linked_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700179 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700180 $(symbolic_output) \
181 $(strip_output)