config.mk revision 43146118aab8e15e8ed4f859106d8ddccc06d21b
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 used to happen in AndroidConfig.h, which was included everywhere.
37# TODO: can we remove this now?
38CLANG_CONFIG_EXTRA_CFLAGS += \
39  -Wno-reserved-id-macro
40
41# Disable overly aggressive warning for format strings.
42# Bug: 20148343
43CLANG_CONFIG_EXTRA_CFLAGS += \
44  -Wno-format-pedantic
45
46# Workaround for ccache with clang.
47# See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
48CLANG_CONFIG_EXTRA_CFLAGS += \
49  -Wno-unused-command-line-argument
50
51# Disable -Winconsistent-missing-override until we can clean up the existing
52# codebase for it.
53CLANG_CONFIG_EXTRA_CPPFLAGS += \
54  -Wno-inconsistent-missing-override
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  -Wmaybe-uninitialized \
66  -Wno-error=clobbered \
67  -Wno-error=maybe-uninitialized \
68  -Wno-error=unused-but-set-parameter \
69  -Wno-error=unused-but-set-variable \
70  -Wno-free-nonheap-object \
71  -Wno-literal-suffix \
72  -Wno-maybe-uninitialized \
73  -Wno-old-style-declaration \
74  -Wno-psabi \
75  -Wno-unused-but-set-parameter \
76  -Wno-unused-but-set-variable \
77  -Wno-unused-local-typedefs \
78  -Wunused-but-set-parameter \
79  -Wunused-but-set-variable
80
81# Clang flags for all host rules
82CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
83CLANG_CONFIG_HOST_EXTRA_CFLAGS :=
84CLANG_CONFIG_HOST_EXTRA_CPPFLAGS :=
85CLANG_CONFIG_HOST_EXTRA_LDFLAGS :=
86
87# Clang flags for all target rules
88CLANG_CONFIG_TARGET_EXTRA_ASFLAGS :=
89CLANG_CONFIG_TARGET_EXTRA_CFLAGS := -nostdlibinc
90CLANG_CONFIG_TARGET_EXTRA_CPPFLAGS := -nostdlibinc
91CLANG_CONFIG_TARGET_EXTRA_LDFLAGS :=
92
93CLANG_DEFAULT_UB_CHECKS := \
94  bool \
95  integer-divide-by-zero \
96  return \
97  returns-nonnull-attribute \
98  shift-exponent \
99  unreachable \
100  vla-bound \
101
102# TODO(danalbert): The following checks currently have compiler performance
103# issues.
104# CLANG_DEFAULT_UB_CHECKS += alignment
105# CLANG_DEFAULT_UB_CHECKS += bounds
106# CLANG_DEFAULT_UB_CHECKS += enum
107# CLANG_DEFAULT_UB_CHECKS += float-cast-overflow
108# CLANG_DEFAULT_UB_CHECKS += float-divide-by-zero
109# CLANG_DEFAULT_UB_CHECKS += nonnull-attribute
110# CLANG_DEFAULT_UB_CHECKS += null
111# CLANG_DEFAULT_UB_CHECKS += shift-base
112# CLANG_DEFAULT_UB_CHECKS += signed-integer-overflow
113
114# TODO(danalbert): Fix UB in libc++'s __tree so we can turn this on.
115# https://llvm.org/PR19302
116# http://reviews.llvm.org/D6974
117# CLANG_DEFAULT_UB_CHECKS += object-size
118
119# HOST config
120clang_2nd_arch_prefix :=
121include $(BUILD_SYSTEM)/clang/HOST_$(HOST_ARCH).mk
122
123# HOST_2ND_ARCH config
124ifdef HOST_2ND_ARCH
125clang_2nd_arch_prefix := $(HOST_2ND_ARCH_VAR_PREFIX)
126include $(BUILD_SYSTEM)/clang/HOST_$(HOST_2ND_ARCH).mk
127endif
128
129# TARGET config
130clang_2nd_arch_prefix :=
131include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_ARCH).mk
132
133# TARGET_2ND_ARCH config
134ifdef TARGET_2ND_ARCH
135clang_2nd_arch_prefix := $(TARGET_2ND_ARCH_VAR_PREFIX)
136include $(BUILD_SYSTEM)/clang/TARGET_$(TARGET_2ND_ARCH).mk
137endif
138
139ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS := -fno-omit-frame-pointer
140ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS := -Wl,-u,__asan_preinit
141
142ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES :=
143ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES := libasan
144
145# This allows us to use the superset of functionality that compiler-rt
146# provides to Clang (for supporting features like -ftrapv).
147COMPILER_RT_CONFIG_EXTRA_STATIC_LIBRARIES := libcompiler_rt-extras
148
149ifeq ($(HOST_PREFER_32_BIT),true)
150# We don't have 32-bit prebuilt libLLVM/libclang, so force to build them from source.
151FORCE_BUILD_LLVM_COMPONENTS := true
152endif
153