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