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