1.1 --- a/make/bsd/makefiles/gcc.make Tue Jun 04 12:06:54 2013 -0700 1.2 +++ b/make/bsd/makefiles/gcc.make Tue Jun 04 22:16:15 2013 -0700 1.3 @@ -71,6 +71,11 @@ 1.4 CC = $(CC32) 1.5 endif 1.6 1.7 + ifeq ($(USE_CLANG), true) 1.8 + CXX = clang++ 1.9 + CC = clang 1.10 + endif 1.11 + 1.12 HOSTCXX = $(CXX) 1.13 HOSTCC = $(CC) 1.14 endif 1.15 @@ -79,21 +84,79 @@ 1.16 endif 1.17 1.18 1.19 -# -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 1.20 -# prints the numbers (e.g. "2.95", "3.2.1") 1.21 -CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 1.22 -CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 1.23 - 1.24 -# check for precompiled headers support 1.25 -ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 1.26 -# Allow the user to turn off precompiled headers from the command line. 1.27 -ifneq ($(USE_PRECOMPILED_HEADER),0) 1.28 -PRECOMPILED_HEADER_DIR=. 1.29 -PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.30 -PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 1.31 -endif 1.32 +ifeq ($(USE_CLANG), true) 1.33 + CC_VER_MAJOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f1) 1.34 + CC_VER_MINOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f2) 1.35 +else 1.36 + # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 1.37 + # prints the numbers (e.g. "2.95", "3.2.1") 1.38 + CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 1.39 + CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 1.40 endif 1.41 1.42 +ifeq ($(USE_CLANG), true) 1.43 + # clang has precompiled headers support by default, but the user can switch 1.44 + # it off by using 'USE_PRECOMPILED_HEADER=0'. 1.45 + ifdef LP64 1.46 + ifeq ($(USE_PRECOMPILED_HEADER),) 1.47 + USE_PRECOMPILED_HEADER=1 1.48 + endif 1.49 + else 1.50 + # We don't support precompiled headers on 32-bit builds because there some files are 1.51 + # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make) 1.52 + # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit. 1.53 + USE_PRECOMPILED_HEADER=0 1.54 + endif 1.55 + 1.56 + ifeq ($(USE_PRECOMPILED_HEADER),1) 1.57 + 1.58 + ifndef LP64 1.59 + $(error " Precompiled Headers only supported on 64-bit platforms!") 1.60 + endif 1.61 + 1.62 + PRECOMPILED_HEADER_DIR=. 1.63 + PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.64 + PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch 1.65 + 1.66 + PCH_FLAG = -include precompiled.hpp 1.67 + PCH_FLAG/DEFAULT = $(PCH_FLAG) 1.68 + PCH_FLAG/NO_PCH = -DNO_PCH 1.69 + PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@)) 1.70 + 1.71 + VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE) 1.72 + VM_PCH_FLAG/AOUT = 1.73 + VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO)) 1.74 + 1.75 + # We only use precompiled headers for the JVM build 1.76 + CFLAGS += $(VM_PCH_FLAG) 1.77 + 1.78 + # There are some files which don't like precompiled headers 1.79 + # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. 1.80 + # But Clang doesn't support a precompiled header which was compiled with -O3 1.81 + # to be used in a compilation unit which uses '-O0'. We could also prepare an 1.82 + # extra '-O0' PCH file for the opt build and use it here, but it's probably 1.83 + # not worth the effort as long as only two files need this special handling. 1.84 + PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) 1.85 + PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) 1.86 + PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) 1.87 + 1.88 + endif 1.89 +else # ($(USE_CLANG), true) 1.90 + # check for precompiled headers support 1.91 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 1.92 + # Allow the user to turn off precompiled headers from the command line. 1.93 + ifneq ($(USE_PRECOMPILED_HEADER),0) 1.94 + PRECOMPILED_HEADER_DIR=. 1.95 + PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 1.96 + PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 1.97 + endif 1.98 + endif 1.99 +endif 1.100 + 1.101 +# -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 1.102 +ifeq ($(USE_PRECOMPILED_HEADER),0) 1.103 + CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 1.104 +endif 1.105 1.106 #------------------------------------------------------------------------ 1.107 # Compiler flags 1.108 @@ -115,17 +178,31 @@ 1.109 CFLAGS += $(VM_PICFLAG) 1.110 CFLAGS += -fno-rtti 1.111 CFLAGS += -fno-exceptions 1.112 -CFLAGS += -pthread 1.113 -CFLAGS += -fcheck-new 1.114 -# version 4 and above support fvisibility=hidden (matches jni_x86.h file) 1.115 -# except 4.1.2 gives pointless warnings that can't be disabled (afaik) 1.116 -ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.117 -CFLAGS += -fvisibility=hidden 1.118 +ifeq ($(USE_CLANG),) 1.119 + CFLAGS += -pthread 1.120 + CFLAGS += -fcheck-new 1.121 + # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 1.122 + # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 1.123 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.124 + CFLAGS += -fvisibility=hidden 1.125 + endif 1.126 +else 1.127 + CFLAGS += -fvisibility=hidden 1.128 +endif 1.129 + 1.130 +ifeq ($(USE_CLANG), true) 1.131 + # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm' 1.132 + # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment') 1.133 + ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0" 1.134 + STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16 1.135 + else 1.136 + STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16 1.137 + endif 1.138 endif 1.139 1.140 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 1.141 ARCHFLAG/i486 = -m32 -march=i586 1.142 -ARCHFLAG/amd64 = -m64 1.143 +ARCHFLAG/amd64 = -m64 $(STACK_ALIGNMENT_OPT) 1.144 ARCHFLAG/ia64 = 1.145 ARCHFLAG/sparc = -m32 -mcpu=v9 1.146 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 1.147 @@ -163,14 +240,25 @@ 1.148 WARNINGS_ARE_ERRORS = -Werror 1.149 endif 1.150 1.151 -# Except for a few acceptable ones 1.152 -# Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 1.153 -# conversions which might affect the values. To avoid that, we need to turn 1.154 -# it off explicitly. 1.155 -ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.156 +ifeq ($(USE_CLANG), true) 1.157 + # However we need to clean the code up before we can unrestrictedly enable this option with Clang 1.158 + WARNINGS_ARE_ERRORS += -Wno-unused-value -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses 1.159 + WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-compare 1.160 +# Not yet supported by clang in Xcode 4.6.2 1.161 +# WARNINGS_ARE_ERRORS += -Wno-tautological-constant-out-of-range-compare 1.162 + WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess 1.163 + WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body 1.164 +endif 1.165 + 1.166 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef 1.167 -else 1.168 -WARNING_FLAGS = -Wpointer-arith -Wconversion -Wsign-compare -Wundef 1.169 + 1.170 +ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 1.171 + # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 1.172 + # conversions which might affect the values. Only enable it in earlier versions. 1.173 + WARNING_FLAGS = -Wunused-function 1.174 + ifeq ($(USE_CLANG),) 1.175 + WARNINGS_FLAGS += -Wconversion 1.176 + endif 1.177 endif 1.178 1.179 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 1.180 @@ -214,14 +302,24 @@ 1.181 1.182 OPT_CFLAGS/NOOPT=-O0 1.183 1.184 -# 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 1.185 -ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0" 1.186 -OPT_CFLAGS/mulnode.o += -O0 1.187 +# Work around some compiler bugs. 1.188 +ifeq ($(USE_CLANG), true) 1.189 + ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) 1.190 + OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) 1.191 + endif 1.192 +else 1.193 + # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 1.194 + ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) 1.195 + OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) 1.196 + endif 1.197 endif 1.198 1.199 # Flags for generating make dependency flags. 1.200 -ifneq ("${CC_VER_MAJOR}", "2") 1.201 -DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 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 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 1.210 @@ -249,13 +347,15 @@ 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 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 1.232 @@ -296,25 +396,31 @@ 1.233 #------------------------------------------------------------------------ 1.234 # Debug flags 1.235 1.236 -# Use the stabs format for debugging information (this is the default 1.237 -# on gcc-2.91). It's good enough, has all the information about line 1.238 -# numbers and local variables, and libjvm.so is only about 16M. 1.239 -# Change this back to "-g" if you want the most expressive format. 1.240 -# (warning: that could easily inflate libjvm.so to 150M!) 1.241 -# Note: The Itanium gcc compiler crashes when using -gstabs. 1.242 -DEBUG_CFLAGS/ia64 = -g 1.243 -DEBUG_CFLAGS/amd64 = -g 1.244 -DEBUG_CFLAGS/arm = -g 1.245 -DEBUG_CFLAGS/ppc = -g 1.246 -DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 1.247 -ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 1.248 -DEBUG_CFLAGS += -gstabs 1.249 +ifeq ($(USE_CLANG), true) 1.250 + # Restrict the debug information created by Clang to avoid 1.251 + # too big object files and speed the build up a little bit 1.252 + # (see http://llvm.org/bugs/show_bug.cgi?id=7554) 1.253 + CFLAGS += -flimit-debug-info 1.254 endif 1.255 1.256 -# DEBUG_BINARIES overrides everything, use full -g debug information 1.257 +# DEBUG_BINARIES uses full -g debug information for all configs 1.258 ifeq ($(DEBUG_BINARIES), true) 1.259 - DEBUG_CFLAGS = -g 1.260 - CFLAGS += $(DEBUG_CFLAGS) 1.261 + CFLAGS += -g 1.262 +else 1.263 + # Use the stabs format for debugging information (this is the default 1.264 + # on gcc-2.91). It's good enough, has all the information about line 1.265 + # numbers and local variables, and libjvm.so is only about 16M. 1.266 + # Change this back to "-g" if you want the most expressive format. 1.267 + # (warning: that could easily inflate libjvm.so to 150M!) 1.268 + # Note: The Itanium gcc compiler crashes when using -gstabs. 1.269 + DEBUG_CFLAGS/ia64 = -g 1.270 + DEBUG_CFLAGS/amd64 = -g 1.271 + DEBUG_CFLAGS/arm = -g 1.272 + DEBUG_CFLAGS/ppc = -g 1.273 + DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 1.274 + ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 1.275 + DEBUG_CFLAGS += -gstabs 1.276 + endif 1.277 endif 1.278 1.279 # If we are building HEADLESS, pass on to VM