1LOCAL_PATH := $(call my-dir)
2
3include $(CLEAR_VARS)
4
5LOCAL_CLANG := true
6
7LOCAL_SRC_FILES := \
8    debugger.cpp \
9    dlfcn.cpp \
10    linker.cpp \
11    linker_allocator.cpp \
12    linker_block_allocator.cpp \
13    linker_dlwarning.cpp \
14    linker_gdb_support.cpp \
15    linker_libc_support.c \
16    linker_mapped_file_fragment.cpp \
17    linker_memory.cpp \
18    linker_phdr.cpp \
19    linker_sdk_versions.cpp \
20    linker_utils.cpp \
21    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
27LOCAL_SRC_FILES_mips    := arch/mips/begin.S linker_mips.cpp
28LOCAL_SRC_FILES_mips64  := arch/mips64/begin.S linker_mips.cpp
29
30# -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.
33LOCAL_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 \
42    -Wall -Wextra -Wunused -Werror \
43
44LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
45LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
46
47LOCAL_CONLYFLAGS += \
48    -std=gnu99 \
49
50LOCAL_CPPFLAGS += \
51    -Wold-style-cast \
52
53ifeq ($(TARGET_IS_64_BIT),true)
54LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
55endif
56
57# 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
66LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
67
68LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
69
70LOCAL_FORCE_STATIC_EXECUTABLE := true
71
72LOCAL_MODULE := linker
73LOCAL_MODULE_STEM_32 := linker
74LOCAL_MODULE_STEM_64 := linker64
75LOCAL_MULTILIB := both
76
77# Leave the symbols in the shared library so that stack unwinders can produce
78# meaningful name resolution.
79LOCAL_STRIP_MODULE := keep_symbols
80
81# 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#
84# 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)
90
91
92define add-linker-symlink
93$(eval _from := $(TARGET_OUT)/bin/$(1))
94$(eval _to:=$(2))
95$(_from): $(LOCAL_MODULE_MAKEFILE)
96	@echo "Symlink: $$@ -> $(_to)"
97	@mkdir -p $$(dir $$@)
98	@rm -rf $$@
99	$(hide) ln -sf $(_to) $$@
100endef
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
106
107include $(call first-makefiles-under,$(LOCAL_PATH))
108