blob: 65dd7ddea631c03487d8aaaf5a905a9979601c1a [file] [log] [blame]
Elliott Hughes88b44fe2014-04-01 11:41:36 -07001LOCAL_PATH := $(call my-dir)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08002
Colin Cross406a75d2014-03-27 10:45:57 -07003include $(CLEAR_VARS)
Colin Cross36ee4ab2014-02-12 21:58:47 -08004
Dmitriy Ivanovb28ffc72015-10-12 16:27:32 -07005LOCAL_CLANG := true
6
7LOCAL_SRC_FILES := \
Colin Cross406a75d2014-03-27 10:45:57 -07008 debugger.cpp \
9 dlfcn.cpp \
10 linker.cpp \
Dmitriy Ivanov19656ce2015-03-10 17:48:27 -070011 linker_allocator.cpp \
Dmitriy Ivanovc9ce70d2015-03-10 15:30:26 -070012 linker_block_allocator.cpp \
Dimitry Ivanovdf91dc22016-02-25 15:22:04 -080013 linker_dlwarning.cpp \
Dimitry Ivanoved70f6a2016-02-17 16:08:03 -080014 linker_gdb_support.cpp \
Dmitriy Ivanov14241402014-08-26 14:16:52 -070015 linker_libc_support.c \
Dmitriy Ivanovcf1cbbe2015-10-19 16:57:46 -070016 linker_mapped_file_fragment.cpp \
Dmitriy Ivanov19656ce2015-03-10 17:48:27 -070017 linker_memory.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070018 linker_phdr.cpp \
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070019 linker_sdk_versions.cpp \
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070020 linker_utils.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070021 rt.cpp \
22
23LOCAL_SRC_FILES_arm := arch/arm/begin.S
24LOCAL_SRC_FILES_arm64 := arch/arm64/begin.S
25LOCAL_SRC_FILES_x86 := arch/x86/begin.c
26LOCAL_SRC_FILES_x86_64 := arch/x86_64/begin.S
Dmitriy Ivanov114ff692015-01-14 11:36:38 -080027LOCAL_SRC_FILES_mips := arch/mips/begin.S linker_mips.cpp
28LOCAL_SRC_FILES_mips64 := arch/mips64/begin.S linker_mips.cpp
Colin Cross406a75d2014-03-27 10:45:57 -070029
Chih-Hung Hsieh306ea7e2015-01-22 14:05:15 -080030# -shared is used to overwrite the -Bstatic and -static
31# flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
32# This dynamic linker is actually a shared object linked with static libraries.
Colin Cross406a75d2014-03-27 10:45:57 -070033LOCAL_LDFLAGS := \
34 -shared \
35 -Wl,-Bsymbolic \
36 -Wl,--exclude-libs,ALL \
37
38LOCAL_CFLAGS += \
39 -fno-stack-protector \
40 -Wstrict-overflow=5 \
41 -fvisibility=hidden \
Elliott Hughesd2867962014-06-03 15:22:34 -070042 -Wall -Wextra -Wunused -Werror \
Colin Cross406a75d2014-03-27 10:45:57 -070043
Dmitriy Ivanov280d5462015-09-28 10:14:17 -070044LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
45LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
Dmitriy Ivanov9185e042015-05-15 17:53:39 -070046
Colin Cross406a75d2014-03-27 10:45:57 -070047LOCAL_CONLYFLAGS += \
48 -std=gnu99 \
49
Pawit Pornkitprasan79b8d032012-11-23 12:27:25 +070050ifneq ($(TARGET_NEEDS_PRELINK_SUPPORT),true)
Colin Cross406a75d2014-03-27 10:45:57 -070051LOCAL_CPPFLAGS += \
Pawit Pornkitprasan79b8d032012-11-23 12:27:25 +070052 -Wold-style-cast
53else
54 LOCAL_CFLAGS += -DENABLE_PRELINK_SUPPORT
55endif
Colin Cross406a75d2014-03-27 10:45:57 -070056
Christopher Ferris151da682015-01-19 11:16:52 -080057ifeq ($(TARGET_IS_64_BIT),true)
58LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
59endif
60
Adrian DCf1e0b672016-08-27 15:09:36 +020061ifeq ($(TARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS),true)
62ifeq ($(user_variant),user)
63$(error Do not enable text relocations on user builds)
64else
65LOCAL_CPPFLAGS += -DTARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS
66endif
Adrian DCc02be8c2016-08-27 15:09:36 +020067endif
68
Colin Cross406a75d2014-03-27 10:45:57 -070069# We need to access Bionic private headers in the linker.
70LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
71
Michael Bestas2b0e1842014-11-24 22:12:22 +020072ifeq ($(TARGET_NEEDS_NON_PIE_SUPPORT),true)
73 LOCAL_CFLAGS += -DENABLE_NON_PIE_SUPPORT
74endif
75
Colin Cross406a75d2014-03-27 10:45:57 -070076# we don't want crtbegin.o (because we have begin.o), so unset it
77# just for this module
78LOCAL_NO_CRT := true
79# TODO: split out the asflags.
80LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
81
Ying Wangf9e147b2014-09-05 15:42:12 -070082LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Colin Cross406a75d2014-03-27 10:45:57 -070083
tony.ys_liub4474402015-07-29 18:00:22 +080084LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
Colin Cross406a75d2014-03-27 10:45:57 -070085
Ying Wangf9e147b2014-09-05 15:42:12 -070086LOCAL_FORCE_STATIC_EXECUTABLE := true
Colin Cross406a75d2014-03-27 10:45:57 -070087
88LOCAL_MODULE := linker
89LOCAL_MODULE_STEM_32 := linker
90LOCAL_MODULE_STEM_64 := linker64
91LOCAL_MULTILIB := both
92
Dmitriy Ivanovad5e8b52014-08-14 15:46:36 -070093# Leave the symbols in the shared library so that stack unwinders can produce
94# meaningful name resolution.
95LOCAL_STRIP_MODULE := keep_symbols
96
Dmitriy Ivanov797bffb2015-03-26 16:47:18 -070097# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
98# looking up symbols in the linker by mistake.
99#
Ying Wangf9e147b2014-09-05 15:42:12 -0700100# Note we are using "=" instead of ":=" to defer the evaluation,
101# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
102LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
103 --prefix-symbols=__dl_ $(linked_module)
104
105include $(BUILD_EXECUTABLE)
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700106
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700107
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700108define add-linker-symlink
109$(eval _from := $(TARGET_OUT)/bin/$(1))
110$(eval _to:=$(2))
111$(_from): $(LOCAL_MODULE_MAKEFILE)
Evgenii Stepanovd11c3e52015-07-15 16:19:59 -0700112 @echo "Symlink: $$@ -> $(_to)"
113 @mkdir -p $$(dir $$@)
114 @rm -rf $$@
115 $(hide) ln -sf $(_to) $$@
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700116endef
117
118$(eval $(call add-linker-symlink,linker_asan,linker))
119ifeq ($(TARGET_IS_64_BIT),true)
120$(eval $(call add-linker-symlink,linker_asan64,linker64))
121endif
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700122
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700123include $(call first-makefiles-under,$(LOCAL_PATH))