am 95b808c4: Merge "build linker and linker64 on 64-bit architectures"

* commit '95b808c4ae11ea5737fee63f7b61673483ea5e2d':
  build linker and linker64 on 64-bit architectures
This commit is contained in:
Colin Cross 2014-02-14 01:02:47 +00:00 committed by Android Git Automerger
commit 9e8ee4dd6a
3 changed files with 90 additions and 83 deletions

View File

@ -1,86 +1,9 @@
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
ifeq ($(TARGET_ARCH),x86) linker_2nd_arch_var_prefix :=
linker_begin_extension := c include $(LOCAL_PATH)/linker.mk
else
linker_begin_extension := S ifdef TARGET_2ND_ARCH
linker_2nd_arch_var_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
include $(LOCAL_PATH)/linker.mk
endif endif
LOCAL_SRC_FILES:= \
arch/$(TARGET_ARCH)/begin.$(linker_begin_extension) \
debugger.cpp \
dlfcn.cpp \
linker.cpp \
linker_environ.cpp \
linker_phdr.cpp \
rt.cpp \
LOCAL_LDFLAGS := \
-shared \
-Wl,-Bsymbolic \
-Wl,--exclude-libs,ALL \
LOCAL_CFLAGS += \
-fno-stack-protector \
-Wstrict-overflow=5 \
-fvisibility=hidden \
-Wall -Wextra -Werror \
LOCAL_CONLYFLAGS += \
-std=gnu99 \
LOCAL_CPPFLAGS += \
-std=gnu++11 \
# We need to access Bionic private headers in the linker.
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
ifeq ($(TARGET_IS_64_BIT),true)
LOCAL_MODULE := linker64
else
LOCAL_MODULE := linker
endif
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_STATIC_LIBRARIES := libc_nomalloc
#LOCAL_FORCE_STATIC_EXECUTABLE := true # not necessary when not including BUILD_EXECUTABLE
#
# include $(BUILD_EXECUTABLE)
#
# Instead of including $(BUILD_EXECUTABLE), we execute the steps to create an executable by
# hand, as we want to insert an extra 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)
# we don't want crtbegin.o (because we have begin.o), so unset it
# just for this module
LOCAL_NO_CRT := true
# TODO: split out the asflags.
LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
include $(BUILD_SYSTEM)/dynamic_binary.mk
# See build/core/executable.mk
$(linked_module): PRIVATE_TARGET_GLOBAL_LD_DIRS := $(TARGET_GLOBAL_LD_DIRS)
$(linked_module): PRIVATE_TARGET_GLOBAL_LDFLAGS := $(TARGET_GLOBAL_LDFLAGS)
$(linked_module): PRIVATE_TARGET_FDO_LIB := $(TARGET_FDO_LIB)
$(linked_module): PRIVATE_TARGET_LIBGCC := $(TARGET_LIBGCC)
$(linked_module): PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_CRTBEGIN_DYNAMIC_O)
$(linked_module): PRIVATE_TARGET_CRTBEGIN_STATIC_O := $(TARGET_CRTBEGIN_STATIC_O)
$(linked_module): PRIVATE_TARGET_CRTEND_O := $(TARGET_CRTEND_O)
$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
$(transform-o-to-static-executable)
@echo "target PrefixSymbols: $(PRIVATE_MODULE) ($@)"
$(hide) $(TARGET_OBJCOPY) --prefix-symbols=__dl_ $@
#
# end of BUILD_EXECUTABLE hack
#

58
linker/linker.mk Normal file
View File

@ -0,0 +1,58 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
debugger.cpp \
dlfcn.cpp \
linker.cpp \
linker_environ.cpp \
linker_phdr.cpp \
rt.cpp \
LOCAL_SRC_FILES_arm := arch/arm/begin.S
LOCAL_SRC_FILES_arm64 := arch/arm64/begin.S
LOCAL_SRC_FILES_x86 := arch/x86/begin.c
LOCAL_SRC_FILES_x86_64 := arch/x86_64/begin.S
LOCAL_SRC_FILES_mips := arch/mips/begin.S
LOCAL_LDFLAGS := \
-shared \
-Wl,-Bsymbolic \
-Wl,--exclude-libs,ALL \
LOCAL_CFLAGS += \
-fno-stack-protector \
-Wstrict-overflow=5 \
-fvisibility=hidden \
-Wall -Wextra -Werror \
LOCAL_CONLYFLAGS += \
-std=gnu99 \
LOCAL_CPPFLAGS += \
-std=gnu++11 \
# We need to access Bionic private headers in the linker.
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
# we don't want crtbegin.o (because we have begin.o), so unset it
# just for this module
LOCAL_NO_CRT := true
# TODO: split out the asflags.
LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/linker.mk $(LOCAL_PATH)/linker_executable.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)
ifeq ($(TARGET_IS_64_BIT)|$(linker_2nd_arch_var_prefix),true|)
LOCAL_MODULE := linker64
else
LOCAL_MODULE := linker
endif
include $(LOCAL_PATH)/linker_executable.mk

View File

@ -0,0 +1,26 @@
#
# 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)
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_ $@