blob: 162088804dded9827474bee403425f416ddad595 [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 \
Dmitriy Ivanov14241402014-08-26 14:16:52 -070014 linker_libc_support.c \
Dmitriy Ivanovcf1cbbe2015-10-19 16:57:46 -070015 linker_mapped_file_fragment.cpp \
Dmitriy Ivanov19656ce2015-03-10 17:48:27 -070016 linker_memory.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070017 linker_phdr.cpp \
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070018 linker_sdk_versions.cpp \
Dmitriy Ivanova1feb112015-10-01 18:41:57 -070019 linker_utils.cpp \
Colin Cross406a75d2014-03-27 10:45:57 -070020 rt.cpp \
21
22LOCAL_SRC_FILES_arm := arch/arm/begin.S
23LOCAL_SRC_FILES_arm64 := arch/arm64/begin.S
24LOCAL_SRC_FILES_x86 := arch/x86/begin.c
25LOCAL_SRC_FILES_x86_64 := arch/x86_64/begin.S
Dmitriy Ivanov114ff692015-01-14 11:36:38 -080026LOCAL_SRC_FILES_mips := arch/mips/begin.S linker_mips.cpp
27LOCAL_SRC_FILES_mips64 := arch/mips64/begin.S linker_mips.cpp
Colin Cross406a75d2014-03-27 10:45:57 -070028
Chih-Hung Hsieh306ea7e2015-01-22 14:05:15 -080029# -shared is used to overwrite the -Bstatic and -static
30# flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
31# This dynamic linker is actually a shared object linked with static libraries.
Colin Cross406a75d2014-03-27 10:45:57 -070032LOCAL_LDFLAGS := \
33 -shared \
34 -Wl,-Bsymbolic \
35 -Wl,--exclude-libs,ALL \
36
37LOCAL_CFLAGS += \
38 -fno-stack-protector \
39 -Wstrict-overflow=5 \
40 -fvisibility=hidden \
Elliott Hughesd2867962014-06-03 15:22:34 -070041 -Wall -Wextra -Wunused -Werror \
Colin Cross406a75d2014-03-27 10:45:57 -070042
Dmitriy Ivanov280d5462015-09-28 10:14:17 -070043LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
44LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
Dmitriy Ivanov9185e042015-05-15 17:53:39 -070045
Colin Cross406a75d2014-03-27 10:45:57 -070046LOCAL_CONLYFLAGS += \
47 -std=gnu99 \
48
49LOCAL_CPPFLAGS += \
Dmitriy Ivanov1649e7e2015-01-22 16:04:25 -080050 -Wold-style-cast \
Colin Cross406a75d2014-03-27 10:45:57 -070051
Christopher Ferris151da682015-01-19 11:16:52 -080052ifeq ($(TARGET_IS_64_BIT),true)
53LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
54endif
55
Colin Cross406a75d2014-03-27 10:45:57 -070056# We need to access Bionic private headers in the linker.
57LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
58
59# we don't want crtbegin.o (because we have begin.o), so unset it
60# just for this module
61LOCAL_NO_CRT := true
62# TODO: split out the asflags.
63LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
64
Ying Wangf9e147b2014-09-05 15:42:12 -070065LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Colin Cross406a75d2014-03-27 10:45:57 -070066
tony.ys_liub4474402015-07-29 18:00:22 +080067LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
Colin Cross406a75d2014-03-27 10:45:57 -070068
Ying Wangf9e147b2014-09-05 15:42:12 -070069LOCAL_FORCE_STATIC_EXECUTABLE := true
Colin Cross406a75d2014-03-27 10:45:57 -070070
71LOCAL_MODULE := linker
72LOCAL_MODULE_STEM_32 := linker
73LOCAL_MODULE_STEM_64 := linker64
74LOCAL_MULTILIB := both
75
Dmitriy Ivanovad5e8b52014-08-14 15:46:36 -070076# Leave the symbols in the shared library so that stack unwinders can produce
77# meaningful name resolution.
78LOCAL_STRIP_MODULE := keep_symbols
79
Dmitriy Ivanov797bffb2015-03-26 16:47:18 -070080# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
81# looking up symbols in the linker by mistake.
82#
Ying Wangf9e147b2014-09-05 15:42:12 -070083# Note we are using "=" instead of ":=" to defer the evaluation,
84# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
85LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
86 --prefix-symbols=__dl_ $(linked_module)
87
88include $(BUILD_EXECUTABLE)
Dmitriy Ivanovd597d262014-05-05 16:49:04 -070089
Evgenii Stepanovd640b222015-07-10 17:54:01 -070090
Evgenii Stepanovd640b222015-07-10 17:54:01 -070091define add-linker-symlink
92$(eval _from := $(TARGET_OUT)/bin/$(1))
93$(eval _to:=$(2))
94$(_from): $(LOCAL_MODULE_MAKEFILE)
Evgenii Stepanovd11c3e52015-07-15 16:19:59 -070095 @echo "Symlink: $$@ -> $(_to)"
96 @mkdir -p $$(dir $$@)
97 @rm -rf $$@
98 $(hide) ln -sf $(_to) $$@
Evgenii Stepanovd640b222015-07-10 17:54:01 -070099endef
100
101$(eval $(call add-linker-symlink,linker_asan,linker))
102ifeq ($(TARGET_IS_64_BIT),true)
103$(eval $(call add-linker-symlink,linker_asan64,linker64))
104endif
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700105
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700106include $(call first-makefiles-under,$(LOCAL_PATH))