blob: a515bbf5c8d2c1cf3eb44f8f61ff34b679a05e04 [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
Alex Naidis85ce9962017-01-06 15:57:29 +010044# Workaround for bad optimization
45LOCAL_CFLAGS_arm += -Os
46LOCAL_CFLAGS_arm64 += -O2
47
Dmitriy Ivanov280d5462015-09-28 10:14:17 -070048LOCAL_CFLAGS_arm += -D__work_around_b_24465209__
49LOCAL_CFLAGS_x86 += -D__work_around_b_24465209__
Dmitriy Ivanov9185e042015-05-15 17:53:39 -070050
Colin Cross406a75d2014-03-27 10:45:57 -070051LOCAL_CONLYFLAGS += \
52 -std=gnu99 \
53
54LOCAL_CPPFLAGS += \
Dmitriy Ivanov1649e7e2015-01-22 16:04:25 -080055 -Wold-style-cast \
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 DCc7340c42016-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
67endif
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
72# we don't want crtbegin.o (because we have begin.o), so unset it
73# just for this module
74LOCAL_NO_CRT := true
75# TODO: split out the asflags.
76LOCAL_ASFLAGS := $(LOCAL_CFLAGS)
77
Ying Wangf9e147b2014-09-05 15:42:12 -070078LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Colin Cross406a75d2014-03-27 10:45:57 -070079
tony.ys_liub4474402015-07-29 18:00:22 +080080LOCAL_STATIC_LIBRARIES := libc_nomalloc libziparchive libutils libbase libz liblog
Colin Cross406a75d2014-03-27 10:45:57 -070081
Ying Wangf9e147b2014-09-05 15:42:12 -070082LOCAL_FORCE_STATIC_EXECUTABLE := true
Colin Cross406a75d2014-03-27 10:45:57 -070083
84LOCAL_MODULE := linker
85LOCAL_MODULE_STEM_32 := linker
86LOCAL_MODULE_STEM_64 := linker64
87LOCAL_MULTILIB := both
88
Dmitriy Ivanovad5e8b52014-08-14 15:46:36 -070089# Leave the symbols in the shared library so that stack unwinders can produce
90# meaningful name resolution.
91LOCAL_STRIP_MODULE := keep_symbols
92
Dmitriy Ivanov797bffb2015-03-26 16:47:18 -070093# Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
94# looking up symbols in the linker by mistake.
95#
Ying Wangf9e147b2014-09-05 15:42:12 -070096# Note we are using "=" instead of ":=" to defer the evaluation,
97# because LOCAL_2ND_ARCH_VAR_PREFIX or linked_module isn't set properly yet at this point.
98LOCAL_POST_LINK_CMD = $(hide) $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_OBJCOPY) \
99 --prefix-symbols=__dl_ $(linked_module)
100
101include $(BUILD_EXECUTABLE)
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700102
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700103
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700104define add-linker-symlink
105$(eval _from := $(TARGET_OUT)/bin/$(1))
106$(eval _to:=$(2))
107$(_from): $(LOCAL_MODULE_MAKEFILE)
Evgenii Stepanovd11c3e52015-07-15 16:19:59 -0700108 @echo "Symlink: $$@ -> $(_to)"
109 @mkdir -p $$(dir $$@)
110 @rm -rf $$@
111 $(hide) ln -sf $(_to) $$@
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700112endef
113
114$(eval $(call add-linker-symlink,linker_asan,linker))
115ifeq ($(TARGET_IS_64_BIT),true)
116$(eval $(call add-linker-symlink,linker_asan64,linker64))
117endif
Evgenii Stepanovd640b222015-07-10 17:54:01 -0700118
Dmitriy Ivanovd597d262014-05-05 16:49:04 -0700119include $(call first-makefiles-under,$(LOCAL_PATH))