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