blob: 2f9c8ff51e9a121d6a9ad06a5547f5078d09c957 [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###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070043## Store a copy with symbols for symbolic debugging
44###########################################################
Ying Wangf3584962013-11-13 17:56:20 -080045ifeq ($(LOCAL_UNSTRIPPED_PATH),)
Ying Wangb8e01852014-01-23 15:09:04 -080046my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
47else
48my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
Ying Wangf3584962013-11-13 17:56:20 -080049endif
Colin Cross979f9f92018-06-25 12:33:35 -070050symbolic_input := $(linked_module)
Ying Wang966c1e02014-05-20 14:43:51 -070051symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
Dan Willemsen7f016152016-02-29 17:52:39 -080052$(symbolic_output) : $(symbolic_input)
Ying Wang374b3252011-03-14 11:44:57 -070053 @echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
54 $(copy-file-to-target)
55
Steve Fungcb2e67f2015-09-24 01:40:52 -070056###########################################################
57## Store breakpad symbols
58###########################################################
59
60ifeq ($(BREAKPAD_GENERATE_SYMBOLS),true)
Steve Fungdfbab492015-09-24 18:12:33 -070061my_breakpad_path := $(TARGET_OUT_BREAKPAD)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
Colin Cross979f9f92018-06-25 12:33:35 -070062breakpad_input := $(linked_module)
Steve Fungcb2e67f2015-09-24 01:40:52 -070063breakpad_output := $(my_breakpad_path)/$(my_installed_module_stem).sym
Steve Fung445beae2017-08-30 14:58:33 -070064$(breakpad_output) : $(breakpad_input) | $(BREAKPAD_DUMP_SYMS) $(PRIVATE_READELF)
Steve Fungcb2e67f2015-09-24 01:40:52 -070065 @echo "target breakpad: $(PRIVATE_MODULE) ($@)"
66 @mkdir -p $(dir $@)
Steve Fung445beae2017-08-30 14:58:33 -070067 $(hide) if $(PRIVATE_READELF) -S $< > /dev/null 2>&1 ; then \
68 $(BREAKPAD_DUMP_SYMS) -c $< > $@ ; \
69 else \
70 echo "skipped for non-elf file."; \
71 touch $@; \
72 fi
Steve Fungcb2e67f2015-09-24 01:40:52 -070073$(LOCAL_BUILT_MODULE) : $(breakpad_output)
74endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080075
76###########################################################
The Android Open Source Project88b60792009-03-03 19:28:42 -080077## Strip
78###########################################################
Ying Wang374b3252011-03-14 11:44:57 -070079strip_input := $(symbolic_output)
Dmitriy Ivanov86bd6532015-05-01 18:12:29 -070080strip_output := $(LOCAL_BUILT_MODULE)
The Android Open Source Project88b60792009-03-03 19:28:42 -080081
Ying Wang6efe88b2016-03-01 20:14:52 -080082my_strip_module := $(firstword \
83 $(LOCAL_STRIP_MODULE_$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) \
84 $(LOCAL_STRIP_MODULE))
Ying Wange1889af2014-03-16 12:43:49 -070085ifeq ($(my_strip_module),)
Yabin Cui700883e2016-04-26 16:08:00 -070086 my_strip_module := mini-debug-info
87endif
88
89ifeq ($(my_strip_module),mini-debug-info)
90# Don't use mini-debug-info on mips (both 32-bit and 64-bit). objcopy checks that all
91# SH_MIPS_DWARF sections having name prefix .debug_ or .zdebug_, so there seems no easy
92# way using objcopy to remove all debug sections except .debug_frame on mips.
93ifneq ($(filter mips mips64,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
Yabin Cui3aa7df52016-04-19 03:38:34 +000094 my_strip_module := true
The Android Open Source Project88b60792009-03-03 19:28:42 -080095endif
Yabin Cui700883e2016-04-26 16:08:00 -070096endif
The Android Open Source Project88b60792009-03-03 19:28:42 -080097
Chih-Hung Hsieh9546d672018-06-01 14:07:52 -070098ifeq ($(my_use_clang_lld),true)
99 # b/80093681: GNU strip and objcopy --{add,remove}-section have bug in handling
100 # GNU_RELRO segment of files lnked by clang lld; so they are replaced
101 # by llvm-strip and llvm-objcopy here.
102 $(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $(LLVM_OBJCOPY)
103 $(strip_output): PRIVATE_STRIP := $(LLVM_STRIP)
104 $(strip_output): PRIVATE_STRIP_O_FLAG :=
105 # GNU strip keeps .ARM.attributes section even with -strip-all,
106 # so here pass -keep=.ARM.attributes to llvm-strip.
107 $(strip_output): PRIVATE_STRIP_ALL_FLAGS := -strip-all -keep=.ARM.attributes
108else
109 $(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
110 $(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
111 $(strip_output): PRIVATE_STRIP_O_FLAG := -o
112 $(strip_output): PRIVATE_STRIP_ALL_FLAGS := --strip-all
113endif
114# PRIVATE_OBJCOPY is not changed to llvm-objcopy yet.
115# It is used even when my_use_clang_lld is true,
116# because some objcopy flags are not supported by llvm-objcopy yet.
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700117$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
Yabin Cuifab79952016-03-29 12:22:20 -0700118$(strip_output): PRIVATE_NM := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700119$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
Ying Wangc1729f32014-08-20 17:12:32 -0700120ifeq ($(my_strip_module),no_debuglink)
121$(strip_output): PRIVATE_NO_DEBUGLINK := true
122else
123$(strip_output): PRIVATE_NO_DEBUGLINK :=
124endif
125
Yabin Cuifab79952016-03-29 12:22:20 -0700126ifeq ($(my_strip_module),mini-debug-info)
127# Strip the binary, but keep debug frames and symbol table in a compressed .gnu_debugdata section.
Dan Willemsen89385952018-03-09 10:56:02 -0800128$(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 -0700129 $(transform-to-stripped-keep-mini-debug-info)
130else ifneq ($(filter true no_debuglink,$(my_strip_module)),)
Ying Wangc1729f32014-08-20 17:12:32 -0700131# Strip the binary
Dan Willemsen89385952018-03-09 10:56:02 -0800132$(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
Ying Wangc1729f32014-08-20 17:12:32 -0700133 $(transform-to-stripped)
134else ifeq ($(my_strip_module),keep_symbols)
135# Strip only the debug frames, but leave the symbol table.
Dan Willemsen89385952018-03-09 10:56:02 -0800136$(strip_output): $(strip_input) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700137 $(transform-to-stripped-keep-symbols)
Ying Wangd8c5ca92014-08-10 16:19:04 -0700138
139# A product may be configured to strip everything in some build variants.
140# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
141# is still with the symbols and we don't need to clean it (and relink) when
142# you switch build variant.
143ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
144$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
145 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
146endif
Christopher Ferrisa6e2f932014-03-18 14:50:09 -0700147else
The Android Open Source Project88b60792009-03-03 19:28:42 -0800148# Don't strip the binary, just copy it. We can't skip this step
149# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
Dan Willemsen7f016152016-02-29 17:52:39 -0800150$(strip_output): $(strip_input)
The Android Open Source Project88b60792009-03-03 19:28:42 -0800151 @echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
152 $(copy-file-to-target)
Ying Wange1889af2014-03-16 12:43:49 -0700153endif # my_strip_module
The Android Open Source Project88b60792009-03-03 19:28:42 -0800154
Ying Wangeda6ac22013-01-28 10:58:01 -0800155$(cleantarget): PRIVATE_CLEAN_FILES += \
156 $(linked_module) \
Steve Fungcb2e67f2015-09-24 01:40:52 -0700157 $(breakpad_output) \
Dmitriy Ivanov4c2d1a62015-04-20 16:59:05 -0700158 $(symbolic_output) \
159 $(strip_output)