blob: 4a4ca5c5a9ca5b46550428f70197b08de6373152 [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
50LOCAL_CPPFLAGS += \
Dmitriy Ivanov1649e7e2015-01-22 16:04:25 -080051 -Wold-style-cast \
Colin Cross406a75d2014-03-27 10:45:57 -070052
Christopher Ferris151da682015-01-19 11:16:52 -080053ifeq ($(TARGET_IS_64_BIT),true)
54LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
55endif
56
Colin Cross406a75d2014-03-27 10:45:57 -070057# We need to access Bionic private headers in the linker.
58LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
59
60# we don't want crtbegin.o (because we have begin.o), so unset it
61# just for this module
62LOCAL_NO_CRT := true
63# TODO: split out the asflags.
64LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
65
Ying Wangf9e147b2014-09-05 15:42:12 -070066LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Colin Cross406a75d2014-03-27 10:45:57 -070067
tony.ys_liub4474402015-07-29 18:00:22 +080068LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
Colin Cross406a75d2014-03-27 10:45:57 -070069
Ying Wangf9e147b2014-09-05 15:42:12 -070070LOCAL_FORCE_STATIC_EXECUTABLE := true
Colin Cross406a75d2014-03-27 10:45:57 -070071
72LOCAL_MODULE := linker
73LOCAL_MODULE_STEM_32 := linker
74LOCAL_MODULE_STEM_64 := linker64
75LOCAL_MULTILIB := both
76
Dmitriy Ivanovad5e8b52014-08-14 15:46:36 -070077# Leave the symbols in the shared library so that stack unwinders can produce
78# meaningful name resolution.
79LOCAL_STRIP_MODULE := keep_symbols
80
Dmitriy Ivanov797bffb2015-03-26 16:47:18 -070081# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
82# looking up symbols in the linker by mistake.
83#
Ying Wangf9e147b2014-09-05 15:42:12 -070084# Note we are using "=" instead of ":=" to defer the evaluation,
85# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
86LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
87 --prefix-symbols=__dl_ $(linked_module)
88
89include $(BUILD_EXECUTABLE)
Dmitriy Ivanovd597d262014-05-05 16:49:04 -070090
Evgenii Stepanovd640b222015-07-10 17:54:01 -070091
Evgenii Stepanovd640b222015-07-10 17:54:01 -070092define add-linker-symlink
93$(eval _from := $(TARGET_OUT)/bin/$(1))
94$(eval _to:=$(2))
95$(_from): $(LOCAL_MODULE_MAKEFILE)
Evgenii Stepanovd11c3e52015-07-15 16:19:59 -070096 @echo "Symlink: $$@ -> $(_to)"
97 @mkdir -p $$(dir $$@)
98 @rm -rf $$@
99 $(hide) ln -sf $(_to) $$@
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700100endef
101
102$(eval $(call add-linker-symlink,linker_asan,linker))
103ifeq ($(TARGET_IS_64_BIT),true)
104$(eval $(call add-linker-symlink,linker_asan64,linker64))
105endif
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700106
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700107include $(call first-makefiles-under,$(LOCAL_PATH))