dynamic_binary.mk revision e24b6f77ffba8f7d9c2a7acbb7a0b748197d48c4
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 := $(LOCAL_PACK_MODULE_RELOCATIONS)
48
49ifeq ($(my_pack_module_relocations),)
50  my_pack_module_relocations := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_PACK_MODULE_RELOCATIONS)
51endif
52
53# Do not pack relocations for executables. Because packing results in
54# non-zero p_vaddr which causes kernel to load executables to lower
55# address (starting at 0x8000) http://b/20665974
56ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES)
57  my_pack_module_relocations := false
58endif
59
60# TODO (dimitry): Relocation packer is not yet available for darwin
61ifneq ($(HOST_OS),linux)
62  my_pack_module_relocations := false
63endif
64
65ifeq (true,$(my_pack_module_relocations))
66# Pack relocations
67$(relocation_packer_output): $(relocation_packer_input) | $(ACP)
68	$(pack-elf-relocations)
69else
70$(relocation_packer_output): $(relocation_packer_input) | $(ACP)
71	@echo "target Unpacked: $(PRIVATE_MODULE) ($@)"
72	$(copy-file-to-target)
73endif
74
75###########################################################
76## Store a copy with symbols for symbolic debugging
77###########################################################
78ifeq ($(LOCAL_UNSTRIPPED_PATH),)
79my_unstripped_path := $(TARGET_OUT_UNSTRIPPED)/$(patsubst $(PRODUCT_OUT)/%,%,$(my_module_path))
80else
81my_unstripped_path := $(LOCAL_UNSTRIPPED_PATH)
82endif
83symbolic_input := $(relocation_packer_output)
84symbolic_output := $(my_unstripped_path)/$(my_installed_module_stem)
85$(symbolic_output) : $(symbolic_input) | $(ACP)
86	@echo "target Symbolic: $(PRIVATE_MODULE) ($@)"
87	$(copy-file-to-target)
88
89
90###########################################################
91## Strip
92###########################################################
93strip_input := $(symbolic_output)
94strip_output := $(LOCAL_BUILT_MODULE)
95
96my_strip_module := $(LOCAL_STRIP_MODULE)
97ifeq ($(my_strip_module),)
98  my_strip_module := true
99endif
100
101$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
102$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
103$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)
104ifeq ($(my_strip_module),no_debuglink)
105$(strip_output): PRIVATE_NO_DEBUGLINK := true
106else
107$(strip_output): PRIVATE_NO_DEBUGLINK :=
108endif
109
110ifneq ($(filter true no_debuglink,$(my_strip_module)),)
111# Strip the binary
112$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
113	$(transform-to-stripped)
114else ifeq ($(my_strip_module),keep_symbols)
115# Strip only the debug frames, but leave the symbol table.
116$(strip_output): $(strip_input) | $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
117	$(transform-to-stripped-keep-symbols)
118
119# A product may be configured to strip everything in some build variants.
120# We do the stripping as a post-install command so that LOCAL_BUILT_MODULE
121# is still with the symbols and we don't need to clean it (and relink) when
122# you switch build variant.
123ifneq ($(filter $(STRIP_EVERYTHING_BUILD_VARIANTS),$(TARGET_BUILD_VARIANT)),)
124$(LOCAL_INSTALLED_MODULE): PRIVATE_POST_INSTALL_CMD := \
125  $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP) --strip-all $(LOCAL_INSTALLED_MODULE)
126endif
127else
128# Don't strip the binary, just copy it.  We can't skip this step
129# because a copy of the binary must appear at LOCAL_BUILT_MODULE.
130#
131# If the binary we're copying is acp or a prerequisite,
132# use cp(1) instead.
133ifneq ($(LOCAL_ACP_UNAVAILABLE),true)
134$(strip_output): $(strip_input) | $(ACP)
135	@echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
136	$(copy-file-to-target)
137else
138$(strip_output): $(strip_input)
139	@echo "target Unstripped: $(PRIVATE_MODULE) ($@)"
140	$(copy-file-to-target-with-cp)
141endif
142endif # my_strip_module
143
144$(cleantarget): PRIVATE_CLEAN_FILES += \
145    $(linked_module) \
146    $(symbolic_output) \
147    $(strip_output)
148