Mercurial > hg > graal-jvmci-8
comparison make/linux/makefiles/gcc.make @ 10398:2cb5d5f6d5e5
8015252: Enable HotSpot build with Clang
Reviewed-by: twisti, dholmes, kvn
author | simonis |
---|---|
date | Tue, 04 Jun 2013 22:16:15 -0700 |
parents | cc32ccaaf47f |
children | ef57c43512d6 |
comparison
equal
deleted
inserted
replaced
10397:075ea888b039 | 10398:2cb5d5f6d5e5 |
---|---|
34 CC = $(ALT_COMPILER_PATH)/gcc | 34 CC = $(ALT_COMPILER_PATH)/gcc |
35 HOSTCXX = g++ | 35 HOSTCXX = g++ |
36 HOSTCC = gcc | 36 HOSTCC = gcc |
37 STRIP = $(ALT_COMPILER_PATH)/strip | 37 STRIP = $(ALT_COMPILER_PATH)/strip |
38 else | 38 else |
39 CXX = g++ | 39 ifeq ($(USE_CLANG), true) |
40 CC = gcc | 40 CXX = clang++ |
41 CC = clang | |
42 else | |
43 CXX = g++ | |
44 CC = gcc | |
45 endif | |
46 | |
41 HOSTCXX = $(CXX) | 47 HOSTCXX = $(CXX) |
42 HOSTCC = $(CC) | 48 HOSTCC = $(CC) |
43 STRIP = strip | 49 STRIP = strip |
44 endif | 50 endif |
45 AS = $(CC) -c | 51 AS = $(CC) -c |
46 endif | 52 endif |
47 | 53 |
48 | 54 |
49 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only | 55 ifeq ($(USE_CLANG), true) |
50 # prints the numbers (e.g. "2.95", "3.2.1") | 56 CC_VER_MAJOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f1) |
51 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) | 57 CC_VER_MINOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | cut -d'.' -f2) |
52 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) | 58 else |
53 | 59 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only |
54 # check for precompiled headers support | 60 # prints the numbers (e.g. "2.95", "3.2.1") |
55 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" | 61 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) |
56 # Allow the user to turn off precompiled headers from the command line. | 62 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) |
57 ifneq ($(USE_PRECOMPILED_HEADER),0) | 63 endif |
58 PRECOMPILED_HEADER_DIR=. | 64 |
59 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp | 65 |
60 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch | 66 ifeq ($(USE_CLANG), true) |
61 endif | 67 # Clang has precompiled headers support by default, but the user can switch |
68 # it off by using 'USE_PRECOMPILED_HEADER=0'. | |
69 ifdef LP64 | |
70 ifeq ($(USE_PRECOMPILED_HEADER),) | |
71 USE_PRECOMPILED_HEADER=1 | |
72 endif | |
73 else | |
74 # We don't support precompiled headers on 32-bit builds because there some files are | |
75 # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make) | |
76 # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit. | |
77 USE_PRECOMPILED_HEADER=0 | |
78 endif | |
79 | |
80 ifeq ($(USE_PRECOMPILED_HEADER),1) | |
81 | |
82 ifndef LP64 | |
83 $(error " Precompiled Headers only supported on 64-bit platforms!") | |
84 endif | |
85 | |
86 PRECOMPILED_HEADER_DIR=. | |
87 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp | |
88 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch | |
89 | |
90 PCH_FLAG = -include precompiled.hpp | |
91 PCH_FLAG/DEFAULT = $(PCH_FLAG) | |
92 PCH_FLAG/NO_PCH = -DNO_PCH | |
93 PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@)) | |
94 | |
95 VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE) | |
96 VM_PCH_FLAG/AOUT = | |
97 VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO)) | |
98 | |
99 # We only use precompiled headers for the JVM build | |
100 CFLAGS += $(VM_PCH_FLAG) | |
101 | |
102 # There are some files which don't like precompiled headers | |
103 # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. | |
104 # But Clang doesn't support a precompiled header which was compiled with -O3 | |
105 # to be used in a compilation unit which uses '-O0'. We could also prepare an | |
106 # extra '-O0' PCH file for the opt build and use it here, but it's probably | |
107 # not worth the effoert as long as only two files need this special handling. | |
108 PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) | |
109 PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) | |
110 PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) | |
111 | |
112 endif | |
113 else # ($(USE_CLANG), true) | |
114 # check for precompiled headers support | |
115 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" | |
116 # Allow the user to turn off precompiled headers from the command line. | |
117 ifneq ($(USE_PRECOMPILED_HEADER),0) | |
118 PRECOMPILED_HEADER_DIR=. | |
119 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp | |
120 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch | |
121 endif | |
122 endif | |
123 endif | |
124 | |
125 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. | |
126 ifeq ($(USE_PRECOMPILED_HEADER),0) | |
127 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER | |
62 endif | 128 endif |
63 | 129 |
64 | 130 |
65 #------------------------------------------------------------------------ | 131 #------------------------------------------------------------------------ |
66 # Compiler flags | 132 # Compiler flags |
81 endif | 147 endif |
82 CFLAGS += $(VM_PICFLAG) | 148 CFLAGS += $(VM_PICFLAG) |
83 CFLAGS += -fno-rtti | 149 CFLAGS += -fno-rtti |
84 CFLAGS += -fno-exceptions | 150 CFLAGS += -fno-exceptions |
85 CFLAGS += -D_REENTRANT | 151 CFLAGS += -D_REENTRANT |
86 CFLAGS += -fcheck-new | 152 ifeq ($(USE_CLANG),) |
87 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) | 153 CFLAGS += -fcheck-new |
88 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) | 154 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) |
89 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" | 155 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) |
90 CFLAGS += -fvisibility=hidden | 156 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" |
157 CFLAGS += -fvisibility=hidden | |
158 endif | |
159 else | |
160 CFLAGS += -fvisibility=hidden | |
161 endif | |
162 | |
163 ifeq ($(USE_CLANG), true) | |
164 # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm' | |
165 # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment') | |
166 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0" | |
167 STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16 | |
168 else | |
169 STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16 | |
170 endif | |
91 endif | 171 endif |
92 | 172 |
93 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) | 173 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) |
94 ARCHFLAG/i486 = -m32 -march=i586 | 174 ARCHFLAG/i486 = -m32 -march=i586 |
95 ARCHFLAG/amd64 = -m64 | 175 ARCHFLAG/amd64 = -m64 $(STACK_ALIGNMENT_OPT) |
96 ARCHFLAG/ia64 = | 176 ARCHFLAG/ia64 = |
97 ARCHFLAG/sparc = -m32 -mcpu=v9 | 177 ARCHFLAG/sparc = -m32 -mcpu=v9 |
98 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 | 178 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 |
99 ARCHFLAG/arm = -fsigned-char | 179 ARCHFLAG/arm = -fsigned-char |
100 ARCHFLAG/zero = $(ZERO_ARCHFLAG) | 180 ARCHFLAG/zero = $(ZERO_ARCHFLAG) |
124 endif | 204 endif |
125 | 205 |
126 # Compiler warnings are treated as errors | 206 # Compiler warnings are treated as errors |
127 WARNINGS_ARE_ERRORS = -Werror | 207 WARNINGS_ARE_ERRORS = -Werror |
128 | 208 |
209 ifeq ($(USE_CLANG), true) | |
210 # However we need to clean the code up before we can unrestrictedly enable this option with Clang | |
211 WARNINGS_ARE_ERRORS += -Wno-unused-value -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses | |
212 WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare | |
213 WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess | |
214 WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body | |
215 endif | |
216 | |
129 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function | 217 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function |
130 | 218 |
131 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit | 219 ifeq ($(USE_CLANG),) |
132 # conversions which might affect the values. Only enable it in earlier versions. | 220 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit |
133 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" | 221 # conversions which might affect the values. Only enable it in earlier versions. |
134 WARNING_FLAGS += -Wconversion | 222 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" |
223 WARNING_FLAGS += -Wconversion | |
224 endif | |
135 endif | 225 endif |
136 | 226 |
137 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) | 227 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) |
138 # Special cases | 228 # Special cases |
139 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) | 229 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) |
163 OPT_CFLAGS += -fno-expensive-optimizations | 253 OPT_CFLAGS += -fno-expensive-optimizations |
164 endif | 254 endif |
165 | 255 |
166 OPT_CFLAGS/NOOPT=-O0 | 256 OPT_CFLAGS/NOOPT=-O0 |
167 | 257 |
168 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. | 258 # Work around some compiler bugs. |
169 ifneq "$(shell expr \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) = 3 \) \))" "0" | 259 ifeq ($(USE_CLANG), true) |
170 OPT_CFLAGS/mulnode.o += -O0 | 260 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) |
261 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) | |
262 endif | |
263 else | |
264 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. | |
265 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) | |
266 OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) | |
267 endif | |
171 endif | 268 endif |
172 | 269 |
173 # Flags for generating make dependency flags. | 270 # Flags for generating make dependency flags. |
174 ifneq ("${CC_VER_MAJOR}", "2") | 271 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) |
175 DEPFLAGS = -fpch-deps -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) | 272 ifeq ($(USE_CLANG),) |
176 endif | 273 ifneq ("${CC_VER_MAJOR}", "2") |
177 | 274 DEPFLAGS += -fpch-deps |
178 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. | 275 endif |
179 ifeq ($(USE_PRECOMPILED_HEADER),0) | |
180 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER | |
181 endif | 276 endif |
182 | 277 |
183 #------------------------------------------------------------------------ | 278 #------------------------------------------------------------------------ |
184 # Linker flags | 279 # Linker flags |
185 | 280 |
186 # statically link libstdc++.so, work with gcc but ignored by g++ | 281 # statically link libstdc++.so, work with gcc but ignored by g++ |
187 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic | 282 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic |
188 | 283 |
189 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. | 284 ifeq ($(USE_CLANG),) |
190 ifneq ("${CC_VER_MAJOR}", "2") | 285 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. |
191 STATIC_LIBGCC += -static-libgcc | 286 ifneq ("${CC_VER_MAJOR}", "2") |
192 endif | 287 STATIC_LIBGCC += -static-libgcc |
193 | 288 endif |
194 ifeq ($(BUILDARCH), ia64) | 289 |
195 LFLAGS += -Wl,-relax | 290 ifeq ($(BUILDARCH), ia64) |
291 LFLAGS += -Wl,-relax | |
292 endif | |
196 endif | 293 endif |
197 | 294 |
198 # Enable linker optimization | 295 # Enable linker optimization |
199 LFLAGS += -Xlinker -O1 | 296 LFLAGS += -Xlinker -O1 |
200 | 297 |
201 # If this is a --hash-style=gnu system, use --hash-style=both | 298 ifeq ($(USE_CLANG),) |
202 # The gnu .hash section won't work on some Linux systems like SuSE 10. | 299 # If this is a --hash-style=gnu system, use --hash-style=both |
203 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') | 300 # The gnu .hash section won't work on some Linux systems like SuSE 10. |
204 ifneq ($(_HAS_HASH_STYLE_GNU),) | 301 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') |
302 ifneq ($(_HAS_HASH_STYLE_GNU),) | |
303 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both | |
304 endif | |
305 else | |
306 # Don't know how to find out the 'hash style' of a system as '-dumpspecs' | |
307 # doesn't work for Clang. So for now we'll alwys use --hash-style=both | |
205 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both | 308 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both |
206 endif | 309 endif |
310 | |
207 LFLAGS += $(LDFLAGS_HASH_STYLE) | 311 LFLAGS += $(LDFLAGS_HASH_STYLE) |
208 | 312 |
209 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. | 313 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. |
210 MAPFLAG = -Xlinker --version-script=FILENAME | 314 MAPFLAG = -Xlinker --version-script=FILENAME |
211 | 315 |
218 # Keep symbols even they are not used | 322 # Keep symbols even they are not used |
219 AOUT_FLAGS += -Xlinker -export-dynamic | 323 AOUT_FLAGS += -Xlinker -export-dynamic |
220 | 324 |
221 #------------------------------------------------------------------------ | 325 #------------------------------------------------------------------------ |
222 # Debug flags | 326 # Debug flags |
327 | |
328 ifeq ($(USE_CLANG), true) | |
329 # Restrict the debug information created by Clang to avoid | |
330 # too big object files and speed the build up a little bit | |
331 # (see http://llvm.org/bugs/show_bug.cgi?id=7554) | |
332 CFLAGS += -flimit-debug-info | |
333 endif | |
223 | 334 |
224 # DEBUG_BINARIES uses full -g debug information for all configs | 335 # DEBUG_BINARIES uses full -g debug information for all configs |
225 ifeq ($(DEBUG_BINARIES), true) | 336 ifeq ($(DEBUG_BINARIES), true) |
226 CFLAGS += -g | 337 CFLAGS += -g |
227 else | 338 else |
235 DEBUG_CFLAGS/amd64 = -g | 346 DEBUG_CFLAGS/amd64 = -g |
236 DEBUG_CFLAGS/arm = -g | 347 DEBUG_CFLAGS/arm = -g |
237 DEBUG_CFLAGS/ppc = -g | 348 DEBUG_CFLAGS/ppc = -g |
238 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) | 349 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) |
239 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) | 350 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) |
240 DEBUG_CFLAGS += -gstabs | 351 ifeq ($(USE_CLANG), true) |
352 # Clang doesn't understand -gstabs | |
353 OPT_CFLAGS += -g | |
354 else | |
355 OPT_CFLAGS += -gstabs | |
356 endif | |
241 endif | 357 endif |
242 | 358 |
243 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) | 359 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) |
244 FASTDEBUG_CFLAGS/ia64 = -g | 360 FASTDEBUG_CFLAGS/ia64 = -g |
245 FASTDEBUG_CFLAGS/amd64 = -g | 361 FASTDEBUG_CFLAGS/amd64 = -g |
246 FASTDEBUG_CFLAGS/arm = -g | 362 FASTDEBUG_CFLAGS/arm = -g |
247 FASTDEBUG_CFLAGS/ppc = -g | 363 FASTDEBUG_CFLAGS/ppc = -g |
248 FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) | 364 FASTDEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) |
249 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) | 365 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) |
250 FASTDEBUG_CFLAGS += -gstabs | 366 ifeq ($(USE_CLANG), true) |
367 # Clang doesn't understand -gstabs | |
368 OPT_CFLAGS += -g | |
369 else | |
370 OPT_CFLAGS += -gstabs | |
371 endif | |
251 endif | 372 endif |
252 | 373 |
253 OPT_CFLAGS/ia64 = -g | 374 OPT_CFLAGS/ia64 = -g |
254 OPT_CFLAGS/amd64 = -g | 375 OPT_CFLAGS/amd64 = -g |
255 OPT_CFLAGS/arm = -g | 376 OPT_CFLAGS/arm = -g |
256 OPT_CFLAGS/ppc = -g | 377 OPT_CFLAGS/ppc = -g |
257 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) | 378 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) |
258 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) | 379 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) |
259 OPT_CFLAGS += -gstabs | 380 ifeq ($(USE_CLANG), true) |
381 # Clang doesn't understand -gstabs | |
382 OPT_CFLAGS += -g | |
383 else | |
384 OPT_CFLAGS += -gstabs | |
385 endif | |
260 endif | 386 endif |
261 endif | 387 endif |
262 endif | 388 endif |
263 | 389 |
264 # If we are building HEADLESS, pass on to VM | 390 # If we are building HEADLESS, pass on to VM |