Use LOCAL_POST_LINK_CMD to insert the objcopy command for linker.

Previously we duplicated code in build/core/executable.mk and it's hard
to maintain. LOCAL_POST_LINK_CMD is a clean solution for this.

Bug: 17403674
Change-Id: I8c054bf782af68cf1f88b8d787a78ca74a7968b5
This commit is contained in:
Ying Wang 2014-09-05 15:42:12 -07:00
parent 8adace5f2c
commit f9e147b0bf
2 changed files with 9 additions and 44 deletions

View File

@ -45,13 +45,11 @@ LOCAL_NO_CRT := true
# TODO: split out the asflags.
LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/linker_executable.mk
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_STATIC_LIBRARIES := libc_nomalloc
LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
LOCAL_2ND_ARCH_VAR_PREFIX := $(linker_2nd_arch_var_prefix)
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE := linker
LOCAL_MODULE_STEM_32 := linker
@ -62,17 +60,12 @@ LOCAL_MULTILIB := both
# meaningful name resolution.
LOCAL_STRIP_MODULE := keep_symbols
include $(LOCAL_PATH)/linker_executable.mk
ifdef TARGET_2ND_ARCH
LOCAL_2ND_ARCH_VAR_PREFIX := $(TARGET_2ND_ARCH_VAR_PREFIX)
OVERRIDE_BUILT_MODULE_PATH :=
LOCAL_BUILT_MODULE :=
LOCAL_INSTALLED_MODULE :=
LOCAL_MODULE_STEM :=
LOCAL_BUILT_MODULE_STEM :=
LOCAL_INSTALLED_MODULE_STEM :=
LOCAL_INTERMEDIATE_TARGETS :=
include $(LOCAL_PATH)/linker_executable.mk
endif
# Insert an extra objcopy step to add prefix to symbols.
# Note we are using "=" instead of ":=" to defer the evaluation,
# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
--prefix-symbols=__dl_ $(linked_module)
include $(BUILD_EXECUTABLE)
include $(call first-makefiles-under,$(LOCAL_PATH))

View File

@ -1,28 +0,0 @@
#
# Instead of including $(BUILD_EXECUTABLE), we execute the steps to create an executable by
# hand, as we want to insert an extra objcopy step that is not supported by the build
# system, and is probably specific the linker only, so there's no need to modify the build
# system for the purpose.
#
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_SUFFIX := $(TARGET_EXECUTABLE_SUFFIX)
# Clang calls /usr/bin/ld: unrecognized option '--icf=safe', http://b/17403674.
LOCAL_CLANG := false
include $(BUILD_SYSTEM)/dynamic_binary.mk
# See build/core/executable_internal.mk
$(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LD_DIRS)
$(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_GLOBAL_LDFLAGS)
$(linked_module): PRIVATE_TARGET_FDO_LIB := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_FDO_LIB)
$(linked_module): PRIVATE_TARGET_LIBGCC := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_LIBGCC)
$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_DYNAMIC_O)
$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTBEGIN_STATIC_O)
$(linked_module): PRIVATE_TARGET_CRTEND_O := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTEND_O)
$(linked_module): PRIVATE_TARGET_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CRTEND_O)
$(transform-o-to-static-executable)
@echo "target PrefixSymbols: $(PRIVATE_MODULE) ($@)"
$(hide) $(PRIVATE_TARGET_OBJCOPY) --prefix-symbols=__dl_ $@