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