1## Clang configurations. 2 3# WITHOUT_CLANG covers both HOST and TARGET 4ifeq ($(WITHOUT_CLANG),true) 5WITHOUT_TARGET_CLANG := true 6WITHOUT_HOST_CLANG := true 7endif 8 9LLVM_PREBUILTS_VERSION := 3.6 10LLVM_PREBUILTS_PATH := prebuilts/clang/$(BUILD_OS)-x86/host/$(LLVM_PREBUILTS_VERSION)/bin 11LLVM_RTLIB_PATH := $(LLVM_PREBUILTS_PATH)/../lib/clang/$(LLVM_PREBUILTS_VERSION)/lib/linux/ 12 13CLANG := $(LLVM_PREBUILTS_PATH)/clang$(BUILD_EXECUTABLE_SUFFIX) 14CLANG_CXX := $(LLVM_PREBUILTS_PATH)/clang++$(BUILD_EXECUTABLE_SUFFIX) 15LLVM_AS := $(LLVM_PREBUILTS_PATH)/llvm-as$(BUILD_EXECUTABLE_SUFFIX) 16LLVM_LINK := $(LLVM_PREBUILTS_PATH)/llvm-link$(BUILD_EXECUTABLE_SUFFIX) 17 18CLANG_TBLGEN := $(BUILD_OUT_EXECUTABLES)/clang-tblgen$(BUILD_EXECUTABLE_SUFFIX) 19LLVM_TBLGEN := $(BUILD_OUT_EXECUTABLES)/llvm-tblgen$(BUILD_EXECUTABLE_SUFFIX) 20 21# Clang flags for all host or target rules 22CLANG_CONFIG_EXTRA_ASFLAGS := 23CLANG_CONFIG_EXTRA_CFLAGS := 24CLANG_CONFIG_EXTRA_CONLYFLAGS := -std=gnu99 25CLANG_CONFIG_EXTRA_CPPFLAGS := 26CLANG_CONFIG_EXTRA_LDFLAGS := 27 28CLANG_CONFIG_EXTRA_CFLAGS += \ 29 -D__compiler_offsetof=__builtin_offsetof 30 31# Help catch common 32/64-bit errors. 32CLANG_CONFIG_EXTRA_CFLAGS += \ 33 -Werror=int-conversion 34 35# Disable overly aggressive warning for macros defined with a leading underscore 36# This happens in AndroidConfig.h, which is included nearly everywhere. 37CLANG_CONFIG_EXTRA_CFLAGS += \ 38 -Wno-reserved-id-macro 39 40# Disable overly aggressive warning for format strings. 41# Bug: 20148343 42CLANG_CONFIG_EXTRA_CFLAGS += \ 43 -Wno-format-pedantic 44 45# Workaround for ccache with clang. 46# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html. 47CLANG_CONFIG_EXTRA_CFLAGS += \ 48 -Wno-unused-command-line-argument 49 50# Disable -Winconsistent-missing-override until we can clean up the existing 51# codebase for it. 52CLANG_CONFIG_EXTRA_CPPFLAGS += \ 53 -Wno-inconsistent-missing-override 54 55CLANG_CONFIG_UNKNOWN_CFLAGS := \ 56 -finline-functions \ 57 -finline-limit=64 \ 58 -fno-canonical-system-headers \ 59 -Wno-clobbered \ 60 -fno-devirtualize \ 61 -fno-tree-sra \ 62 -fprefetch-loop-arrays \ 63 -funswitch-loops \ 64 -Werror=unused-but-set-parameter \ 65 -Werror=unused-but-set-variable \ 66 -Wmaybe-uninitialized \ 67 -Wno-error=clobbered \ 68 -Wno-error=maybe-uninitialized \ 69 -Wno-error=unused-but-set-parameter \ 70 -Wno-error=unused-but-set-variable \ 71 -Wno-free-nonheap-object \ 72 -Wno-literal-suffix \ 73 -Wno-maybe-uninitialized \ 74 -Wno-old-style-declaration \ 75 -Wno-psabi \ 76 -Wno-unused-but-set-parameter \ 77 -Wno-unused-but-set-variable \ 78 -Wno-unused-local-typedefs \ 79 -Wunused-but-set-parameter \ 80 -Wunused-but-set-variable 81 82# Clang flags for all host rules 83CLANG_CONFIG_HOST_EXTRA_ASFLAGS := 84CLANG_CONFIG_HOST_EXTRA_CFLAGS := 85CLANG_CONFIG_HOST_EXTRA_CPPFLAGS := 86CLANG_CONFIG_HOST_EXTRA_LDFLAGS := 87 88# Clang flags for all target rules 89CLANG_CONFIG_TARGET_EXTRA_ASFLAGS := 90CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc 91CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc 92CLANG_CONFIG_TARGET_EXTRA_LDFLAGS := 93 94CLANG_DEFAULT_UB_CHECKS := \ 95 bool \ 96 integer-divide-by-zero \ 97 return \ 98 returns-nonnull-attribute \ 99 shift-exponent \ 100 unreachable \ 101 vla-bound \ 102 103# TODO(danalbert): The following checks currently have compiler performance 104# issues. 105# CLANG_DEFAULT_UB_CHECKS += alignment 106# CLANG_DEFAULT_UB_CHECKS += bounds 107# CLANG_DEFAULT_UB_CHECKS += enum 108# CLANG_DEFAULT_UB_CHECKS += float-cast-overflow 109# CLANG_DEFAULT_UB_CHECKS += float-divide-by-zero 110# CLANG_DEFAULT_UB_CHECKS += nonnull-attribute 111# CLANG_DEFAULT_UB_CHECKS += null 112# CLANG_DEFAULT_UB_CHECKS += shift-base 113# CLANG_DEFAULT_UB_CHECKS += signed-integer-overflow 114 115# TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on. 116# https://llvm.org/PR19302 117# http://reviews.llvm.org/D6974 118# CLANG_DEFAULT_UB_CHECKS += object-size 119 120# HOST config 121clang_2nd_arch_prefix := 122include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk 123 124# HOST_2ND_ARCH config 125ifdef HOST_2ND_ARCH 126clang_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX) 127include $(BUILD_SYSTEM)/clang/HOST_$(HOST_2ND_ARCH).mk 128endif 129 130# TARGET config 131clang_2nd_arch_prefix := 132include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk 133 134# TARGET_2ND_ARCH config 135ifdef TARGET_2ND_ARCH 136clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX) 137include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk 138endif 139 140ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fno-omit-frame-pointer 141ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit 142 143ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES := libdl 144ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan 145 146# This allows us to use the superset of functionality that compiler-rt 147# provides to Clang (for supporting features like -ftrapv). 148COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras 149 150ifeq ($(HOST_PREFER_32_BIT),true) 151# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source. 152FORCE_BUILD_LLVM_COMPONENTS := true 153endif 154