1.1 --- a/make/linux/makefiles/gcc.make Tue Jun 04 12:06:54 2013 -0700 1.2 +++ b/make/linux/makefiles/gcc.make Tue Jun 04 22:16:15 2013 -0700 1.3 @@ -36,8 +36,14 @@ 1.4 HOSTCC = gcc 1.5 STRIP = $(ALT_COMPILER_PATH)/strip 1.6 else 1.7 - CXX = g++ 1.8 - CC = gcc 1.9 + ifeq ($(USE_CLANG), true) 1.10 + CXX = clang++ 1.11 + CC = clang 1.12 + else 1.13 + CXX = g++ 1.14 + CC = gcc 1.15 + endif 1.16 + 1.17 HOSTCXX = $(CXX) 1.18 HOSTCC = $(CC) 1.19 STRIP = strip 1.20 @@ -46,19 +52,79 @@ 1.21 endif 1.22 1.23 1.24 -# -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 1.25 -# prints the numbers (e.g. "2.95", "3.2.1") 1.26 -CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 1.27 -CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 1.28 +ifeq ($(USE_CLANG), true) 1.29 + CC_VER_MAJOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f1) 1.30 + CC_VER_MINOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f2) 1.31 +else 1.32 + # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 1.33 + # prints the numbers (e.g. "2.95", "3.2.1") 1.34 + CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 1.35 + CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 1.36 +endif 1.37 1.38 -# check for precompiled headers support 1.39 -ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 1.40 -# Allow the user to turn off precompiled headers from the command line. 1.41 -ifneq ($(USE_PRECOMPILED_HEADER),0) 1.42 -PRECOMPILED_HEADER_DIR=. 1.43 -PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.44 -PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 1.45 + 1.46 +ifeq ($(USE_CLANG), true) 1.47 + # Clang has precompiled headers support by default, but the user can switch 1.48 + # it off by using 'USE_PRECOMPILED_HEADER=0'. 1.49 + ifdef LP64 1.50 + ifeq ($(USE_PRECOMPILED_HEADER),) 1.51 + USE_PRECOMPILED_HEADER=1 1.52 + endif 1.53 + else 1.54 + # We don't support precompiled headers on 32-bit builds because there some files are 1.55 + # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make) 1.56 + # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit. 1.57 + USE_PRECOMPILED_HEADER=0 1.58 + endif 1.59 + 1.60 + ifeq ($(USE_PRECOMPILED_HEADER),1) 1.61 + 1.62 + ifndef LP64 1.63 + $(error " Precompiled Headers only supported on 64-bit platforms!") 1.64 + endif 1.65 + 1.66 + PRECOMPILED_HEADER_DIR=. 1.67 + PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.68 + PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch 1.69 + 1.70 + PCH_FLAG = -include precompiled.hpp 1.71 + PCH_FLAG/DEFAULT = $(PCH_FLAG) 1.72 + PCH_FLAG/NO_PCH = -DNO_PCH 1.73 + PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@)) 1.74 + 1.75 + VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE) 1.76 + VM_PCH_FLAG/AOUT = 1.77 + VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO)) 1.78 + 1.79 + # We only use precompiled headers for the JVM build 1.80 + CFLAGS += $(VM_PCH_FLAG) 1.81 + 1.82 + # There are some files which don't like precompiled headers 1.83 + # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. 1.84 + # But Clang doesn't support a precompiled header which was compiled with -O3 1.85 + # to be used in a compilation unit which uses '-O0'. We could also prepare an 1.86 + # extra '-O0' PCH file for the opt build and use it here, but it's probably 1.87 + # not worth the effoert as long as only two files need this special handling. 1.88 + PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) 1.89 + PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) 1.90 + PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) 1.91 + 1.92 + endif 1.93 +else # ($(USE_CLANG), true) 1.94 + # check for precompiled headers support 1.95 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 1.96 + # Allow the user to turn off precompiled headers from the command line. 1.97 + ifneq ($(USE_PRECOMPILED_HEADER),0) 1.98 + PRECOMPILED_HEADER_DIR=. 1.99 + PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.100 + PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 1.101 + endif 1.102 + endif 1.103 endif 1.104 + 1.105 +# -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 1.106 +ifeq ($(USE_PRECOMPILED_HEADER),0) 1.107 + CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 1.108 endif 1.109 1.110 1.111 @@ -83,16 +149,30 @@ 1.112 CFLAGS += -fno-rtti 1.113 CFLAGS += -fno-exceptions 1.114 CFLAGS += -D_REENTRANT 1.115 -CFLAGS += -fcheck-new 1.116 -# version 4 and above support fvisibility=hidden (matches jni_x86.h file) 1.117 -# except 4.1.2 gives pointless warnings that can't be disabled (afaik) 1.118 -ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.119 -CFLAGS += -fvisibility=hidden 1.120 +ifeq ($(USE_CLANG),) 1.121 + CFLAGS += -fcheck-new 1.122 + # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 1.123 + # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 1.124 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.125 + CFLAGS += -fvisibility=hidden 1.126 + endif 1.127 +else 1.128 + CFLAGS += -fvisibility=hidden 1.129 +endif 1.130 + 1.131 +ifeq ($(USE_CLANG), true) 1.132 + # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm' 1.133 + # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment') 1.134 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0" 1.135 + STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16 1.136 + else 1.137 + STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16 1.138 + endif 1.139 endif 1.140 1.141 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 1.142 ARCHFLAG/i486 = -m32 -march=i586 1.143 -ARCHFLAG/amd64 = -m64 1.144 +ARCHFLAG/amd64 = -m64 $(STACK_ALIGNMENT_OPT) 1.145 ARCHFLAG/ia64 = 1.146 ARCHFLAG/sparc = -m32 -mcpu=v9 1.147 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 1.148 @@ -126,12 +206,22 @@ 1.149 # Compiler warnings are treated as errors 1.150 WARNINGS_ARE_ERRORS = -Werror 1.151 1.152 +ifeq ($(USE_CLANG), true) 1.153 + # However we need to clean the code up before we can unrestrictedly enable this option with Clang 1.154 + WARNINGS_ARE_ERRORS += -Wno-unused-value -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses 1.155 + WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare 1.156 + WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess 1.157 + WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body 1.158 +endif 1.159 + 1.160 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function 1.161 1.162 -# Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 1.163 -# conversions which might affect the values. Only enable it in earlier versions. 1.164 -ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.165 -WARNING_FLAGS += -Wconversion 1.166 +ifeq ($(USE_CLANG),) 1.167 + # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 1.168 + # conversions which might affect the values. Only enable it in earlier versions. 1.169 + ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.170 + WARNING_FLAGS += -Wconversion 1.171 + endif 1.172 endif 1.173 1.174 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 1.175 @@ -165,19 +255,24 @@ 1.176 1.177 OPT_CFLAGS/NOOPT=-O0 1.178 1.179 -# 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 1.180 -ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0" 1.181 -OPT_CFLAGS/mulnode.o += -O0 1.182 +# Work around some compiler bugs. 1.183 +ifeq ($(USE_CLANG), true) 1.184 + ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) 1.185 + OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) 1.186 + endif 1.187 +else 1.188 + # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 1.189 + ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) 1.190 + OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) 1.191 + endif 1.192 endif 1.193 1.194 # Flags for generating make dependency flags. 1.195 -ifneq ("${CC_VER_MAJOR}", "2") 1.196 -DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 1.197 -endif 1.198 - 1.199 -# -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 1.200 -ifeq ($(USE_PRECOMPILED_HEADER),0) 1.201 -CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 1.202 +DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 1.203 +ifeq ($(USE_CLANG),) 1.204 + ifneq ("${CC_VER_MAJOR}", "2") 1.205 + DEPFLAGS += -fpch-deps 1.206 + endif 1.207 endif 1.208 1.209 #------------------------------------------------------------------------ 1.210 @@ -186,24 +281,33 @@ 1.211 # statically link libstdc++.so, work with gcc but ignored by g++ 1.212 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 1.213 1.214 -# statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 1.215 -ifneq ("${CC_VER_MAJOR}", "2") 1.216 -STATIC_LIBGCC += -static-libgcc 1.217 -endif 1.218 +ifeq ($(USE_CLANG),) 1.219 + # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 1.220 + ifneq ("${CC_VER_MAJOR}", "2") 1.221 + STATIC_LIBGCC += -static-libgcc 1.222 + endif 1.223 1.224 -ifeq ($(BUILDARCH), ia64) 1.225 -LFLAGS += -Wl,-relax 1.226 + ifeq ($(BUILDARCH), ia64) 1.227 + LFLAGS += -Wl,-relax 1.228 + endif 1.229 endif 1.230 1.231 # Enable linker optimization 1.232 LFLAGS += -Xlinker -O1 1.233 1.234 -# If this is a --hash-style=gnu system, use --hash-style=both 1.235 -# The gnu .hash section won't work on some Linux systems like SuSE 10. 1.236 -_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') 1.237 -ifneq ($(_HAS_HASH_STYLE_GNU),) 1.238 +ifeq ($(USE_CLANG),) 1.239 + # If this is a --hash-style=gnu system, use --hash-style=both 1.240 + # The gnu .hash section won't work on some Linux systems like SuSE 10. 1.241 + _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') 1.242 + ifneq ($(_HAS_HASH_STYLE_GNU),) 1.243 + LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 1.244 + endif 1.245 +else 1.246 + # Don't know how to find out the 'hash style' of a system as '-dumpspecs' 1.247 + # doesn't work for Clang. So for now we'll alwys use --hash-style=both 1.248 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 1.249 endif 1.250 + 1.251 LFLAGS += $(LDFLAGS_HASH_STYLE) 1.252 1.253 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 1.254 @@ -221,6 +325,13 @@ 1.255 #------------------------------------------------------------------------ 1.256 # Debug flags 1.257 1.258 +ifeq ($(USE_CLANG), true) 1.259 + # Restrict the debug information created by Clang to avoid 1.260 + # too big object files and speed the build up a little bit 1.261 + # (see http://llvm.org/bugs/show_bug.cgi?id=7554) 1.262 + CFLAGS += -flimit-debug-info 1.263 +endif 1.264 + 1.265 # DEBUG_BINARIES uses full -g debug information for all configs 1.266 ifeq ($(DEBUG_BINARIES), true) 1.267 CFLAGS += -g 1.268 @@ -237,7 +348,12 @@ 1.269 DEBUG_CFLAGS/ppc = -g 1.270 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 1.271 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 1.272 - DEBUG_CFLAGS += -gstabs 1.273 + ifeq ($(USE_CLANG), true) 1.274 + # Clang doesn't understand -gstabs 1.275 + OPT_CFLAGS += -g 1.276 + else 1.277 + OPT_CFLAGS += -gstabs 1.278 + endif 1.279 endif 1.280 1.281 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 1.282 @@ -247,7 +363,12 @@ 1.283 FASTDEBUG_CFLAGS/ppc = -g 1.284 FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 1.285 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) 1.286 - FASTDEBUG_CFLAGS += -gstabs 1.287 + ifeq ($(USE_CLANG), true) 1.288 + # Clang doesn't understand -gstabs 1.289 + OPT_CFLAGS += -g 1.290 + else 1.291 + OPT_CFLAGS += -gstabs 1.292 + endif 1.293 endif 1.294 1.295 OPT_CFLAGS/ia64 = -g 1.296 @@ -256,7 +377,12 @@ 1.297 OPT_CFLAGS/ppc = -g 1.298 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) 1.299 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) 1.300 - OPT_CFLAGS += -gstabs 1.301 + ifeq ($(USE_CLANG), true) 1.302 + # Clang doesn't understand -gstabs 1.303 + OPT_CFLAGS += -g 1.304 + else 1.305 + OPT_CFLAGS += -gstabs 1.306 + endif 1.307 endif 1.308 endif 1.309 endif