TARGET_linux-arm64.mk revision ed56902c29e984b987089e13a27f9f25ac6c6e42
1#
2# Copyright (C) 2013 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17# Configuration for Linux on ARM.
18# Included by combo/select.mk
19
20# You can set TARGET_ARCH_VARIANT to use an arch version other
21# than ARMv5TE. Each value should correspond to a file named
22# $(BUILD_COMBOS)/arch/<name>.mk which must contain
23# makefile variable definitions similar to the preprocessor
24# defines in build/core/combo/include/arch/<combo>/AndroidConfig.h. Their
25# purpose is to allow module Android.mk files to selectively compile
26# different versions of code based upon the funtionality and
27# instructions available in a given architecture version.
28#
29# The blocks also define specific arch_variant_cflags, which
30# include defines, and compiler settings for the given architecture
31# version.
32#
33ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
34TARGET_ARCH_VARIANT := armv8
35endif
36
37ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)
38TARGET_GCC_VERSION := 4.8
39else
40TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)
41endif
42
43TARGET_IS_64_BIT := true
44
45TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
46ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
47$(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
48endif
49
50include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
51
52# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
53ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
54TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/aarch64/aarch64-linux-android-$(TARGET_GCC_VERSION)
55TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/aarch64-linux-android-
56endif
57
58TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
59TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
60TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
61TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
62TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
63TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
64ifeq ($(TARGET_BUILD_VARIANT),user)
65    TARGET_STRIP_COMMAND = $(PRIVATE_STRIP) --strip-all $< -o $@
66else
67    TARGET_STRIP_COMMAND = $(PRIVATE_STRIP) --strip-all $< -o $@ && \
68        $(PRIVATE_OBJCOPY) --add-gnu-debuglink=$< $@
69endif
70
71TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
72
73TARGET_GLOBAL_CFLAGS += \
74    -fno-strict-aliasing \
75
76android_config_h := $(call select-android-config-h,linux-arm64)
77
78# HACK: globally disable -fstack-protector until the toolchain supports it
79TARGET_GLOBAL_UNSUPPORTED_CFLAGS := \
80    -fstack-protector \
81    -fstack-protector-all \
82
83TARGET_GLOBAL_CFLAGS += \
84			-fpic -fPIE \
85			-ffunction-sections \
86			-fdata-sections \
87			-funwind-tables \
88			-Wa,--noexecstack \
89			-Werror=format-security \
90			-D_FORTIFY_SOURCE=2 \
91			-fno-short-enums \
92			$(arch_variant_cflags) \
93			-include $(android_config_h) \
94			-I $(dir $(android_config_h))
95
96# Help catch common 32/64-bit errors.
97TARGET_GLOBAL_CFLAGS += \
98    -Werror=pointer-to-int-cast \
99    -Werror=int-to-pointer-cast \
100
101TARGET_GLOBAL_CFLAGS += -fno-strict-volatile-bitfields
102
103# This is to avoid the dreaded warning compiler message:
104#   note: the mangling of 'va_list' has changed in GCC 4.4
105#
106# The fact that the mangling changed does not affect the NDK ABI
107# very fortunately (since none of the exposed APIs used va_list
108# in their exported C++ functions). Also, GCC 4.5 has already
109# removed the warning from the compiler.
110#
111TARGET_GLOBAL_CFLAGS += -Wno-psabi
112
113# TODO - temporarily remove "-Wl,-z,relro -Wl,-z,now" as they cause segmentation fault on the
114# v8 foundation model.
115TARGET_GLOBAL_LDFLAGS += \
116			-Wl,-z,noexecstack \
117			-Wl,--warn-shared-textrel \
118			-Wl,--fatal-warnings \
119			$(arch_variant_ldflags)
120
121TARGET_GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
122
123# More flags/options can be added here
124TARGET_RELEASE_CFLAGS := \
125			-DNDEBUG \
126			-O2 -g \
127			-Wstrict-aliasing=2 \
128			-fgcse-after-reload \
129			-frerun-cse-after-loop \
130			-frename-registers
131
132libc_root := bionic/libc
133libm_root := bionic/libm
134libstdc++_root := bionic/libstdc++
135
136TARGET_LIBGCC := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
137	-print-libgcc-file-name)
138
139KERNEL_HEADERS_COMMON := $(libc_root)/kernel/uapi
140KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/uapi/asm-$(TARGET_ARCH)
141KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
142
143TARGET_C_INCLUDES := \
144	$(libc_root)/arch-arm64/include \
145	$(libc_root)/include \
146	$(libstdc++_root)/include \
147	$(KERNEL_HEADERS) \
148	$(libm_root)/include \
149	$(libm_root)/include/arm64 \
150
151TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
152TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
153TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
154
155TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
156TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
157
158TARGET_STRIP_MODULE:=true
159
160TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
161
162TARGET_CUSTOM_LD_COMMAND := true
163
164define transform-o-to-shared-lib-inner
165$(hide) $(PRIVATE_CXX) \
166	-nostdlib -Wl,-soname,$(notdir $@) \
167	-Wl,-shared,-Bsymbolic \
168	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
169	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
170	$(PRIVATE_ALL_OBJECTS) \
171	-Wl,--whole-archive \
172	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
173	-Wl,--no-whole-archive \
174	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
175	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
176	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
177	$(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
178	$(PRIVATE_TARGET_FDO_LIB) \
179	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
180	-o $@ \
181	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
182	$(PRIVATE_LDFLAGS) \
183	$(PRIVATE_TARGET_LIBGCC) \
184	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
185endef
186
187define transform-o-to-executable-inner
188$(hide) $(PRIVATE_CXX) -nostdlib -Bdynamic -fPIE -pie \
189	-Wl,-dynamic-linker,/system/bin/linker64 \
190	-Wl,-z,nocopyreloc \
191	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
192	-Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
193	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
194	$(PRIVATE_ALL_OBJECTS) \
195	-Wl,--whole-archive \
196	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
197	-Wl,--no-whole-archive \
198	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
199	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
200	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
201	$(if $(TARGET_BUILD_APPS),$(PRIVATE_TARGET_LIBGCC)) \
202	$(PRIVATE_TARGET_FDO_LIB) \
203	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
204	-o $@ \
205	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
206	$(PRIVATE_LDFLAGS) \
207	$(PRIVATE_TARGET_LIBGCC) \
208	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
209endef
210
211define transform-o-to-static-executable-inner
212$(hide) $(PRIVATE_CXX) -nostdlib -Bstatic \
213	-o $@ \
214	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
215	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
216	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
217	$(PRIVATE_LDFLAGS) \
218	$(PRIVATE_ALL_OBJECTS) \
219	-Wl,--whole-archive \
220	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
221	-Wl,--no-whole-archive \
222	$(call normalize-target-libraries,$(filter-out %libc_nomalloc.a,$(filter-out %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES)))) \
223	-Wl,--start-group \
224	$(call normalize-target-libraries,$(filter %libc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
225	$(call normalize-target-libraries,$(filter %libc_nomalloc.a,$(PRIVATE_ALL_STATIC_LIBRARIES))) \
226	$(PRIVATE_TARGET_FDO_LIB) \
227	$(PRIVATE_TARGET_LIBGCC) \
228	-Wl,--end-group \
229	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
230endef
231