TARGET_linux-x86_64.mk revision a6e2f9322c47ac02546aa436341fa42afd0000c5
1#
2# Copyright (C) 2006 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 x86_64 as a target.
18# Included by combo/select.mk
19
20# Provide a default variant.
21ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
22TARGET_ARCH_VARIANT := x86_64
23endif
24
25ifeq ($(strip $(TARGET_GCC_VERSION_EXP)),)
26TARGET_GCC_VERSION := 4.8
27else
28TARGET_GCC_VERSION := $(TARGET_GCC_VERSION_EXP)
29endif
30
31TARGET_IS_64_BIT := true
32
33# Include the arch-variant-specific configuration file.
34# Its role is to define various ARCH_X86_HAVE_XXX feature macros,
35# plus initial values for TARGET_GLOBAL_CFLAGS
36#
37TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
38ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
39$(error Unknown $(TARGET_ARCH) architecture version: $(TARGET_ARCH_VARIANT))
40endif
41
42include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
43
44
45# You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
46ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
47TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/x86/x86_64-linux-android-$(TARGET_GCC_VERSION)
48TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/x86_64-linux-android-
49endif
50
51TARGET_CC := $(TARGET_TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
52TARGET_CXX := $(TARGET_TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
53TARGET_AR := $(TARGET_TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
54TARGET_OBJCOPY := $(TARGET_TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
55TARGET_LD := $(TARGET_TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
56TARGET_READELF := $(TARGET_TOOLS_PREFIX)readelf$(HOST_EXECUTABLE_SUFFIX)
57TARGET_STRIP := $(TARGET_TOOLS_PREFIX)strip$(HOST_EXECUTABLE_SUFFIX)
58include $(BUILD_SYSTEM)/strip.mk
59
60ifneq ($(wildcard $(TARGET_CC)),)
61TARGET_LIBGCC := \
62	$(shell $(TARGET_CC) -m64 -print-file-name=libgcc.a)
63target_libgcov := $(shell $(TARGET_CC) $(TARGET_GLOBAL_CFLAGS) \
64	-print-file-name=libgcov.a)
65endif
66
67TARGET_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
68
69libc_root := bionic/libc
70libm_root := bionic/libm
71libstdc++_root := bionic/libstdc++
72
73# Define FDO (Feedback Directed Optimization) options.
74
75TARGET_FDO_CFLAGS:=
76TARGET_FDO_LIB:=
77
78ifneq ($(strip $(BUILD_FDO_INSTRUMENT)),)
79  # Set BUILD_FDO_INSTRUMENT=true to turn on FDO instrumentation.
80  # The profile will be generated on /data/local/tmp/profile on the device.
81  TARGET_FDO_CFLAGS := -fprofile-generate=/data/local/tmp/profile -DANDROID_FDO
82  TARGET_FDO_LIB := $(target_libgcov)
83else
84  # If BUILD_FDO_INSTRUMENT is turned off, then consider doing the FDO optimizations.
85  # Set TARGET_FDO_PROFILE_PATH to set a custom profile directory for your build.
86  ifeq ($(strip $(TARGET_FDO_PROFILE_PATH)),)
87    TARGET_FDO_PROFILE_PATH := fdo/profiles/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT)
88  else
89    ifeq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
90      $(warning Custom TARGET_FDO_PROFILE_PATH supplied, but directory does not exist. Turn off FDO.)
91    endif
92  endif
93
94  # If the FDO profile directory can't be found, then FDO is off.
95  ifneq ($(strip $(wildcard $(TARGET_FDO_PROFILE_PATH))),)
96    TARGET_FDO_CFLAGS := -fprofile-use=$(TARGET_FDO_PROFILE_PATH) -DANDROID_FDO
97    TARGET_FDO_LIB := $(target_libgcov)
98  endif
99endif
100
101KERNEL_HEADERS_COMMON := $(libc_root)/kernel/uapi
102KERNEL_HEADERS_ARCH   := $(libc_root)/kernel/uapi/asm-x86 # x86 covers both x86 and x86_64.
103KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
104
105TARGET_GLOBAL_CFLAGS += \
106			-O2 \
107			-Ulinux \
108			-Wa,--noexecstack \
109			-Werror=format-security \
110			-D_FORTIFY_SOURCE=2 \
111			-Wstrict-aliasing=2 \
112			-fPIC -fPIE \
113			-ffunction-sections \
114			-finline-functions \
115			-finline-limit=300 \
116			-fno-inline-functions-called-once \
117			-fno-short-enums \
118			-fstrict-aliasing \
119			-funswitch-loops \
120			-funwind-tables \
121			-fstack-protector \
122			-m64
123
124# Help catch common 32/64-bit errors.
125TARGET_GLOBAL_CFLAGS += \
126    -Werror=pointer-to-int-cast \
127    -Werror=int-to-pointer-cast \
128
129android_config_h := $(call select-android-config-h,target_linux-x86)
130TARGET_ANDROID_CONFIG_CFLAGS := -include $(android_config_h) -I $(dir $(android_config_h))
131TARGET_GLOBAL_CFLAGS += $(TARGET_ANDROID_CONFIG_CFLAGS)
132
133TARGET_GLOBAL_CFLAGS += $(arch_variant_cflags)
134
135ifeq ($(ARCH_X86_HAVE_SSSE3),true)   # yes, really SSSE3, not SSE3!
136    TARGET_GLOBAL_CFLAGS += -DUSE_SSSE3 -mssse3
137endif
138ifeq ($(ARCH_X86_HAVE_SSE4),true)
139    TARGET_GLOBAL_CFLAGS += -msse4
140endif
141ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
142    TARGET_GLOBAL_CFLAGS += -msse4.1
143endif
144ifeq ($(ARCH_X86_HAVE_SSE4_2),true)
145    TARGET_GLOBAL_CFLAGS += -msse4.2
146endif
147ifeq ($(ARCH_X86_HAVE_AVX),true)
148    TARGET_GLOBAL_CFLAGS += -mavx
149endif
150ifeq ($(ARCH_X86_HAVE_AES_NI),true)
151    TARGET_GLOBAL_CFLAGS += -maes
152endif
153
154TARGET_GLOBAL_LDFLAGS += -m64
155
156TARGET_GLOBAL_LDFLAGS += -Wl,-z,noexecstack
157TARGET_GLOBAL_LDFLAGS += -Wl,-z,relro -Wl,-z,now
158TARGET_GLOBAL_LDFLAGS += -Wl,--warn-shared-textrel
159TARGET_GLOBAL_LDFLAGS += -Wl,--gc-sections
160
161TARGET_C_INCLUDES := \
162	$(libc_root)/arch-x86_64/include \
163	$(libc_root)/include \
164	$(libstdc++_root)/include \
165	$(KERNEL_HEADERS) \
166	$(libm_root)/include \
167	$(libm_root)/include/amd64 \
168
169TARGET_CRTBEGIN_STATIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_static.o
170TARGET_CRTBEGIN_DYNAMIC_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_dynamic.o
171TARGET_CRTEND_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_android.o
172
173TARGET_CRTBEGIN_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtbegin_so.o
174TARGET_CRTEND_SO_O := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/crtend_so.o
175
176TARGET_STRIP_MODULE:=true
177
178TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES := libc libstdc++ libm
179
180TARGET_CUSTOM_LD_COMMAND := true
181define transform-o-to-shared-lib-inner
182$(hide) $(PRIVATE_CXX) \
183	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
184	 -nostdlib -Wl,-soname,$(notdir $@) \
185	 -shared -Bsymbolic \
186	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
187	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_SO_O)) \
188	$(PRIVATE_ALL_OBJECTS) \
189	-Wl,--whole-archive \
190	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
191	-Wl,--no-whole-archive \
192	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
193	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
194	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
195	$(PRIVATE_TARGET_LIBGCC) \
196	$(PRIVATE_TARGET_FDO_LIB) \
197	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
198	-o $@ \
199	$(PRIVATE_LDFLAGS) \
200	$(PRIVATE_TARGET_LIBGCC) \
201	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_SO_O))
202endef
203
204define transform-o-to-executable-inner
205$(hide) $(PRIVATE_CXX) \
206	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
207	-nostdlib -Bdynamic \
208	-Wl,-z,nocopyreloc \
209	-fPIE -pie \
210	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
211	-Wl,-rpath-link=$(PRIVATE_TARGET_OUT_INTERMEDIATE_LIBRARIES) \
212	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_DYNAMIC_O)) \
213	$(PRIVATE_ALL_OBJECTS) \
214	-Wl,--whole-archive \
215	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
216	-Wl,--no-whole-archive \
217	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
218	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
219	$(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
220	$(PRIVATE_TARGET_LIBGCC) \
221	$(PRIVATE_TARGET_FDO_LIB) \
222	$(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
223	-o $@ \
224	$(PRIVATE_LDFLAGS) \
225	$(PRIVATE_TARGET_LIBGCC) \
226	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
227endef
228
229define transform-o-to-static-executable-inner
230$(hide) $(PRIVATE_CXX) \
231	$(PRIVATE_TARGET_GLOBAL_LDFLAGS) \
232	-nostdlib -Bstatic \
233	-o $@ \
234	$(PRIVATE_TARGET_GLOBAL_LD_DIRS) \
235	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTBEGIN_STATIC_O)) \
236	$(PRIVATE_LDFLAGS) \
237	$(PRIVATE_ALL_OBJECTS) \
238	-Wl,--whole-archive \
239	$(call normalize-target-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
240	-Wl,--no-whole-archive \
241	-Wl,--start-group \
242	$(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
243	$(PRIVATE_TARGET_FDO_LIB) \
244	$(PRIVATE_TARGET_LIBGCC) \
245	-Wl,--end-group \
246	$(if $(filter true,$(PRIVATE_NO_CRT)),,$(PRIVATE_TARGET_CRTEND_O))
247endef
248