Use llvm-{objcopy,strip} when clang lld is used.

* PRIVATE_OBJCOPY is still set to objcopy and used
  when llvm-objcopy cannot replace objcopy.

Bug: 80093681
Test: build/boot with USE_CLANG_LLD=true
Change-Id: I4bd8a53f74864b49e007f0c5f1b0f4b16e121135
This commit is contained in:
Chih-Hung Hsieh 2018-06-01 14:07:52 -07:00
parent bc965aa7a9
commit 9546d67fe9
2 changed files with 28 additions and 7 deletions

View File

@ -1835,14 +1835,15 @@ endef
###########################################################
ifneq ($(TARGET_BUILD_VARIANT),user)
TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
TARGET_STRIP_EXTRA = && $(PRIVATE_OBJCOPY_ADD_SECTION) --add-gnu-debuglink=$< $@
TARGET_STRIP_KEEP_SYMBOLS_EXTRA = --add-gnu-debuglink=$<
endif
define transform-to-stripped
@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip: $(PRIVATE_MODULE) ($@)"
@mkdir -p $(dir $@)
$(hide) $(PRIVATE_STRIP) --strip-all $< -o $@ \
$(hide) $(PRIVATE_STRIP) $(PRIVATE_STRIP_ALL_FLAGS) $< \
$(PRIVATE_STRIP_O_FLAG) $@ \
$(if $(PRIVATE_NO_DEBUGLINK),,$(TARGET_STRIP_EXTRA))
endef
@ -1850,7 +1851,9 @@ define transform-to-stripped-keep-mini-debug-info
@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (mini debug info): $(PRIVATE_MODULE) ($@)"
@mkdir -p $(dir $@)
$(hide) rm -f $@ $@.dynsyms $@.funcsyms $@.keep_symbols $@.debug $@.mini_debuginfo.xz
if $(PRIVATE_STRIP) --strip-all -R .comment $< -o $@; then \
if $(PRIVATE_STRIP) $(PRIVATE_STRIP_ALL_FLAGS) \
--remove-section .comment $< \
$(PRIVATE_STRIP_O_FLAG) $@; then \
$(PRIVATE_OBJCOPY) --only-keep-debug $< $@.debug && \
$(PRIVATE_NM) -D $< --format=posix --defined-only | awk '{ print $$1 }' | sort >$@.dynsyms && \
$(PRIVATE_NM) $< --format=posix --defined-only | awk '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort >$@.funcsyms && \
@ -1861,7 +1864,7 @@ if $(PRIVATE_STRIP) --strip-all -R .comment $< -o $@; then \
$(PRIVATE_OBJCOPY) --rename-section saved_debug_frame=.debug_frame $@.mini_debuginfo && \
rm -f $@.mini_debuginfo.xz && \
$(XZ) $@.mini_debuginfo && \
$(PRIVATE_OBJCOPY) --add-section .gnu_debugdata=$@.mini_debuginfo.xz $@; \
$(PRIVATE_OBJCOPY_ADD_SECTION) --add-section .gnu_debugdata=$@.mini_debuginfo.xz $@; \
else \
cp -f $< $@; \
fi
@ -1870,8 +1873,8 @@ endef
define transform-to-stripped-keep-symbols
@echo "$($(PRIVATE_PREFIX)DISPLAY) Strip (keep symbols): $(PRIVATE_MODULE) ($@)"
@mkdir -p $(dir $@)
$(hide) $(PRIVATE_OBJCOPY) \
`$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "-R " $$2}' | xargs` \
$(hide) $(PRIVATE_OBJCOPY_ADD_SECTION) \
`$(PRIVATE_READELF) -S $< | awk '/.debug_/ {print "--remove-section " $$2}' | xargs` \
$(TARGET_STRIP_KEEP_SYMBOLS_EXTRA) $< $@
endef

View File

@ -117,7 +117,25 @@ ifneq ($(filter mips mips64,$($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
endif
endif
$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
ifeq ($(my_use_clang_lld),true)
# b/80093681: GNU strip and objcopy --{add,remove}-section have bug in handling
# GNU_RELRO segment of files lnked by clang lld; so they are replaced
# by llvm-strip and llvm-objcopy here.
$(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $(LLVM_OBJCOPY)
$(strip_output): PRIVATE_STRIP := $(LLVM_STRIP)
$(strip_output): PRIVATE_STRIP_O_FLAG :=
# GNU strip keeps .ARM.attributes section even with -strip-all,
# so here pass -keep=.ARM.attributes to llvm-strip.
$(strip_output): PRIVATE_STRIP_ALL_FLAGS := -strip-all -keep=.ARM.attributes
else
$(strip_output): PRIVATE_OBJCOPY_ADD_SECTION := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
$(strip_output): PRIVATE_STRIP := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_STRIP)
$(strip_output): PRIVATE_STRIP_O_FLAG := -o
$(strip_output): PRIVATE_STRIP_ALL_FLAGS := --strip-all
endif
# PRIVATE_OBJCOPY is not changed to llvm-objcopy yet.
# It is used even when my_use_clang_lld is true,
# because some objcopy flags are not supported by llvm-objcopy yet.
$(strip_output): PRIVATE_OBJCOPY := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY)
$(strip_output): PRIVATE_NM := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_NM)
$(strip_output): PRIVATE_READELF := $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_READELF)