blob: c37d6db6780dc93454543e76cba697e689252df5 [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)
Dimitry Ivanovaa9cb262016-02-16 10:13:42 -08004LOCAL_CLANG := true
5
6LOCAL_MODULE := liblinker_malloc
7
8LOCAL_SRC_FILES := \
9 linker_allocator.cpp \
10 linker_memory.cpp
11
12# We need to access Bionic private headers in the linker.
13LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
14
15include $(BUILD_STATIC_LIBRARY)
16
17include $(CLEAR_VARS)
Colin Cross36ee4ab2014-02-12 21:58:47 -080018
Dmitriy Ivanovb28ffc72015-10-12 16:27:32 -070019LOCAL_CLANG := true
20
21LOCAL_SRC_FILES := \
Colin Cross406a75d2014-03-27 10:45:57 -070022 debugger.cpp \
23 dlfcn.cpp \
24 linker.cpp \
Dmitriy Ivanovc9ce70d2015-03-10 15:30:26 -070025 linker_block_allocator.cpp \
Dimitry Ivanov6b788ee2016-02-17 16:08:03 -080026 linker_gdb_support.cpp \
Dmitriy Ivanov14241402014-08-26 14:16:52 -070027 linker_libc_support.c \
Dmitriy Ivanovcf1cbbe2015-10-19 16:57:46 -070028 linker_mapped_file_fragment.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070029 linker_phdr.cpp \
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070030 linker_sdk_versions.cpp \
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070031 linker_utils.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070032 rt.cpp \
33
34LOCAL_SRC_FILES_arm := arch/arm/begin.S
35LOCAL_SRC_FILES_arm64 := arch/arm64/begin.S
36LOCAL_SRC_FILES_x86 := arch/x86/begin.c
37LOCAL_SRC_FILES_x86_64 := arch/x86_64/begin.S
Dmitriy Ivanov114ff692015-01-14 11:36:38 -080038LOCAL_SRC_FILES_mips := arch/mips/begin.S linker_mips.cpp
39LOCAL_SRC_FILES_mips64 := arch/mips64/begin.S linker_mips.cpp
Colin Cross406a75d2014-03-27 10:45:57 -070040
Chih-Hung Hsieh306ea7e2015-01-22 14:05:15 -080041# -shared is used to overwrite the -Bstatic and -static
42# flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
43# This dynamic linker is actually a shared object linked with static libraries.
Colin Cross406a75d2014-03-27 10:45:57 -070044LOCAL_LDFLAGS := \
45 -shared \
46 -Wl,-Bsymbolic \
47 -Wl,--exclude-libs,ALL \
48
49LOCAL_CFLAGS += \
50 -fno-stack-protector \
51 -Wstrict-overflow=5 \
52 -fvisibility=hidden \
Elliott Hughesd2867962014-06-03 15:22:34 -070053 -Wall -Wextra -Wunused -Werror \
Colin Cross406a75d2014-03-27 10:45:57 -070054
Dmitriy Ivanov280d5462015-09-28 10:14:17 -070055LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
56LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
Dmitriy Ivanov9185e042015-05-15 17:53:39 -070057
Colin Cross406a75d2014-03-27 10:45:57 -070058LOCAL_CONLYFLAGS += \
59 -std=gnu99 \
60
61LOCAL_CPPFLAGS += \
Dmitriy Ivanov1649e7e2015-01-22 16:04:25 -080062 -Wold-style-cast \
Colin Cross406a75d2014-03-27 10:45:57 -070063
Christopher Ferris151da682015-01-19 11:16:52 -080064ifeq ($(TARGET_IS_64_BIT),true)
65LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
66endif
67
Colin Cross406a75d2014-03-27 10:45:57 -070068# We need to access Bionic private headers in the linker.
69LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
70
71# we don't want crtbegin.o (because we have begin.o), so unset it
72# just for this module
73LOCAL_NO_CRT := true
74# TODO: split out the asflags.
75LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
76
Ying Wangf9e147b2014-09-05 15:42:12 -070077LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Colin Cross406a75d2014-03-27 10:45:57 -070078
Dimitry Ivanov3bbeca72016-02-15 19:19:35 +000079LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
Colin Cross406a75d2014-03-27 10:45:57 -070080
Dimitry Ivanovaa9cb262016-02-16 10:13:42 -080081# Important: The liblinker_malloc should be the last library in the list
82# to overwrite any other malloc implementations by other static libraries.
83LOCAL_STATIC_LIBRARIES += liblinker_malloc
84
Ying Wangf9e147b2014-09-05 15:42:12 -070085LOCAL_FORCE_STATIC_EXECUTABLE := true
Colin Cross406a75d2014-03-27 10:45:57 -070086
87LOCAL_MODULE := linker
88LOCAL_MODULE_STEM_32 := linker
89LOCAL_MODULE_STEM_64 := linker64
90LOCAL_MULTILIB := both
91
Dmitriy Ivanovad5e8b52014-08-14 15:46:36 -070092# Leave the symbols in the shared library so that stack unwinders can produce
93# meaningful name resolution.
94LOCAL_STRIP_MODULE := keep_symbols
95
Dmitriy Ivanov797bffb2015-03-26 16:47:18 -070096# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
97# looking up symbols in the linker by mistake.
98#
Ying Wangf9e147b2014-09-05 15:42:12 -070099# Note we are using "=" instead of ":=" to defer the evaluation,
100# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
101LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
102 --prefix-symbols=__dl_ $(linked_module)
103
104include $(BUILD_EXECUTABLE)
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700105
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700106
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700107define add-linker-symlink
108$(eval _from := $(TARGET_OUT)/bin/$(1))
109$(eval _to:=$(2))
110$(_from): $(LOCAL_MODULE_MAKEFILE)
Evgenii Stepanovd11c3e52015-07-15 16:19:59 -0700111 @echo "Symlink: $$@ -> $(_to)"
112 @mkdir -p $$(dir $$@)
113 @rm -rf $$@
114 $(hide) ln -sf $(_to) $$@
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700115endef
116
117$(eval $(call add-linker-symlink,linker_asan,linker))
118ifeq ($(TARGET_IS_64_BIT),true)
119$(eval $(call add-linker-symlink,linker_asan64,linker64))
120endif
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700121
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700122include $(call first-makefiles-under,$(LOCAL_PATH))