1 # 2 # Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. 8 # 9 # This code is distributed in the hope that it will be useful, but WITHOUT 10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 # version 2 for more details (a copy is included in the LICENSE file that 13 # accompanied this code). 14 # 15 # You should have received a copy of the GNU General Public License version 16 # 2 along with this work; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 # 19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 # or visit www.oracle.com if you need additional information or have any 21 # questions. 22 # 23 # 24 25 #------------------------------------------------------------------------ 26 # CC, CXX & AS 27 28 # If a SPEC is not set already, then use these defaults. 29 ifeq ($(SPEC),) 30 # When cross-compiling the ALT_COMPILER_PATH points 31 # to the cross-compilation toolset 32 ifdef CROSS_COMPILE_ARCH 33 CXX = $(ALT_COMPILER_PATH)/g++ 34 CC = $(ALT_COMPILER_PATH)/gcc 35 HOSTCXX = g++ 36 HOSTCC = gcc 37 STRIP = $(ALT_COMPILER_PATH)/strip 38 else 39 ifeq ($(USE_CLANG), true) 40 CXX = clang++ 41 CC = clang 42 else 43 CXX = g++ 44 CC = gcc 45 endif 46 47 HOSTCXX = $(CXX) 48 HOSTCC = $(CC) 49 STRIP = strip 50 endif 51 AS = $(CC) -c 52 endif 53 54 55 ifeq ($(USE_CLANG), true) 56 CC_VER_MAJOR := $(shell $(CC) -v 2>&1 | grep version | sed "s/.*version \([0-9]*\.[0-9]*\).*/\1/" | 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) 58 else 59 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only 60 # prints the numbers (e.g. "2.95", "3.2.1") 61 CC_VER_MAJOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f1) 62 CC_VER_MINOR := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f2) 63 CC_VER_MICRO := $(shell $(CC) -dumpversion | sed 's/egcs-//' | cut -d'.' -f3) 64 # Workaround Ubuntu bug where -dumpversion doesn't print a micro version 65 # https://bugs.launchpad.net/ubuntu/+source/gcc-4.8/+bug/1360404 66 ifeq ($(CC_VER_MICRO),) 67 CC_VER_MICRO := "0" 68 endif 69 endif 70 71 ifeq ($(USE_CLANG), true) 72 # Clang has precompiled headers support by default, but the user can switch 73 # it off by using 'USE_PRECOMPILED_HEADER=0'. 74 ifdef LP64 75 ifeq ($(USE_PRECOMPILED_HEADER),) 76 USE_PRECOMPILED_HEADER=1 77 endif 78 else 79 # We don't support precompiled headers on 32-bit builds because there some files are 80 # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make) 81 # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit. 82 USE_PRECOMPILED_HEADER=0 83 endif 84 85 ifeq ($(USE_PRECOMPILED_HEADER),1) 86 87 ifndef LP64 88 $(error " Precompiled Headers only supported on 64-bit platforms!") 89 endif 90 91 PRECOMPILED_HEADER_DIR=. 92 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 93 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch 94 95 PCH_FLAG = -include precompiled.hpp 96 PCH_FLAG/DEFAULT = $(PCH_FLAG) 97 PCH_FLAG/NO_PCH = -DNO_PCH 98 PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@)) 99 100 VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE) 101 VM_PCH_FLAG/AOUT = 102 VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO)) 103 104 # We only use precompiled headers for the JVM build 105 CFLAGS += $(VM_PCH_FLAG) 106 107 # There are some files which don't like precompiled headers 108 # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build. 109 # But Clang doesn't support a precompiled header which was compiled with -O3 110 # to be used in a compilation unit which uses '-O0'. We could also prepare an 111 # extra '-O0' PCH file for the opt build and use it here, but it's probably 112 # not worth the effort as long as only two files need this special handling. 113 PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH) 114 PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH) 115 PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH) 116 117 endif 118 else # ($(USE_CLANG), true) 119 # check for precompiled headers support 120 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0" 121 # Allow the user to turn off precompiled headers from the command line. 122 ifneq ($(USE_PRECOMPILED_HEADER),0) 123 PRECOMPILED_HEADER_DIR=. 124 PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp 125 PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch 126 endif 127 endif 128 endif 129 130 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp. 131 ifeq ($(USE_PRECOMPILED_HEADER),0) 132 CFLAGS += -DDONT_USE_PRECOMPILED_HEADER 133 endif 134 135 136 #------------------------------------------------------------------------ 137 # Compiler flags 138 139 # position-independent code 140 PICFLAG = -fPIC 141 142 VM_PICFLAG/LIBJVM = $(PICFLAG) 143 VM_PICFLAG/AOUT = 144 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO)) 145 146 ifeq ($(JVM_VARIANT_ZERO), true) 147 CFLAGS += $(LIBFFI_CFLAGS) 148 endif 149 ifeq ($(JVM_VARIANT_ZEROSHARK), true) 150 CFLAGS += $(LIBFFI_CFLAGS) 151 CFLAGS += $(LLVM_CFLAGS) 152 endif 153 CFLAGS += $(VM_PICFLAG) 154 CFLAGS += -fno-rtti 155 CFLAGS += -fno-exceptions 156 CFLAGS += -D_REENTRANT 157 ifeq ($(USE_CLANG),) 158 CFLAGS += -fcheck-new 159 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 160 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 161 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 162 CFLAGS += -fvisibility=hidden 163 endif 164 else 165 CFLAGS += -fvisibility=hidden 166 endif 167 168 ifeq ($(USE_CLANG), true) 169 # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm' 170 # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment') 171 ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0" 172 STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16 173 else 174 STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16 175 endif 176 endif 177 178 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 179 ARCHFLAG/i486 = -m32 -march=i586 180 ARCHFLAG/amd64 = -m64 $(STACK_ALIGNMENT_OPT) 181 ARCHFLAG/aarch64 = 182 ARCHFLAG/ia64 = 183 ARCHFLAG/sparc = -m32 -mcpu=v9 184 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 185 ARCHFLAG/zero = $(ZERO_ARCHFLAG) 186 ARCHFLAG/ppc64 = -m64 187 188 CFLAGS += $(ARCHFLAG) 189 AOUT_FLAGS += $(ARCHFLAG) 190 LFLAGS += $(ARCHFLAG) 191 ASFLAGS += $(ARCHFLAG) 192 193 # Use C++ Interpreter 194 ifdef CC_INTERP 195 CFLAGS += -DCC_INTERP 196 endif 197 198 # Keep temporary files (.ii, .s) 199 ifdef NEED_ASM 200 CFLAGS += -save-temps 201 else 202 CFLAGS += -pipe 203 endif 204 205 # Compiler warnings are treated as errors 206 WARNINGS_ARE_ERRORS ?= -Werror 207 208 ifeq ($(USE_CLANG), true) 209 # However we need to clean the code up before we can unrestrictedly enable this option with Clang 210 WARNINGS_ARE_ERRORS += -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses 211 WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare 212 WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess 213 WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body 214 endif 215 216 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wreturn-type -Woverloaded-virtual 217 218 ifeq ($(USE_CLANG),) 219 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 220 # conversions which might affect the values. Only enable it in earlier versions. 221 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 222 # GCC < 4.3 223 WARNING_FLAGS += -Wconversion 224 endif 225 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1" 226 # GCC >= 4.8 227 # This flag is only known since GCC 4.3. Gcc 4.8 contains a fix so that with templates no 228 # warnings are issued: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856 229 WARNING_FLAGS += -Wtype-limits 230 # GCC < 4.8 don't accept this flag for C++. 231 WARNING_FLAGS += -Wno-format-zero-length 232 # GCC 4.8 reports less false positives than the older compilers. 233 WARNING_FLAGS += -Wuninitialized 234 endif 235 endif 236 237 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 238 239 # Special cases 240 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 241 242 # optimization control flags (Used by fastdebug and release variants) 243 OPT_CFLAGS/NOOPT=-O0 244 OPT_CFLAGS/DEBUG=-O0 245 OPT_CFLAGS/SIZE=-Os 246 OPT_CFLAGS/SPEED=-O3 247 248 OPT_CFLAGS_DEFAULT ?= SPEED 249 250 # Hotspot uses very unstrict aliasing turn this optimization off 251 # This option is added to CFLAGS rather than OPT_CFLAGS 252 # so that OPT_CFLAGS overrides get this option too. 253 CFLAGS += -fno-strict-aliasing 254 255 ifdef OPT_CFLAGS 256 ifneq ("$(origin OPT_CFLAGS)", "command line") 257 $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.") 258 endif 259 endif 260 261 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS) 262 263 # Variable tracking size limit exceeded for VMStructs::init() 264 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "1" 265 # GCC >= 4.3 266 # Gcc 4.1.2 does not support this flag, nor does it have problems compiling the file. 267 OPT_CFLAGS/vmStructs.o += -fno-var-tracking-assignments 268 endif 269 270 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 271 # if we use expensive-optimizations 272 ifeq ($(BUILDARCH), ia64) 273 OPT_CFLAGS += -fno-expensive-optimizations 274 endif 275 276 # Work around some compiler bugs. 277 ifeq ($(USE_CLANG), true) 278 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) 279 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) 280 endif 281 else 282 # Do not allow GCC 4.1.1 283 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 1 \& $(CC_VER_MICRO) = 1), 1) 284 $(error "GCC $(CC_VER_MAJOR).$(CC_VER_MINOR).$(CC_VER_MICRO) not supported because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=27724") 285 endif 286 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 287 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) 288 OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) 289 endif 290 endif 291 292 # Flags for generating make dependency flags. 293 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 294 ifeq ($(USE_CLANG),) 295 ifneq ($(CC_VER_MAJOR), 2) 296 DEPFLAGS += -fpch-deps 297 endif 298 endif 299 300 #------------------------------------------------------------------------ 301 # Linker flags 302 303 # statically link libstdc++.so, work with gcc but ignored by g++ 304 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 305 306 # Enable linker optimization 307 LFLAGS += -Xlinker -O1 308 309 ifeq ($(USE_CLANG),) 310 STATIC_LIBGCC += -static-libgcc 311 312 ifneq (, findstring(debug,$(BUILD_FLAVOR))) 313 # for relocations read-only 314 LFLAGS += -Xlinker -z -Xlinker relro 315 316 ifeq ($(BUILD_FLAVOR), debug) 317 # disable incremental relocations linking 318 LFLAGS += -Xlinker -z -Xlinker now 319 endif 320 endif 321 322 ifeq ($(BUILDARCH), ia64) 323 LFLAGS += -Wl,-relax 324 endif 325 326 # If this is a --hash-style=gnu system, use --hash-style=both 327 # The gnu .hash section won't work on some Linux systems like SuSE 10. 328 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') 329 ifneq ($(_HAS_HASH_STYLE_GNU),) 330 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 331 endif 332 else 333 # Don't know how to find out the 'hash style' of a system as '-dumpspecs' 334 # doesn't work for Clang. So for now we'll alwys use --hash-style=both 335 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 336 endif 337 338 LFLAGS += $(LDFLAGS_HASH_STYLE) 339 340 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 341 MAPFLAG = -Xlinker --version-script=FILENAME 342 343 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 344 SONAMEFLAG = -Xlinker -soname=SONAME 345 346 # Build shared library 347 SHARED_FLAG = -shared 348 349 # Keep symbols even they are not used 350 AOUT_FLAGS += -Xlinker -export-dynamic 351 352 #------------------------------------------------------------------------ 353 # Debug flags 354 355 ifeq ($(USE_CLANG), true) 356 # Restrict the debug information created by Clang to avoid 357 # too big object files and speed the build up a little bit 358 # (see http://llvm.org/bugs/show_bug.cgi?id=7554) 359 CFLAGS += -flimit-debug-info 360 endif 361 362 # Allow no optimizations. 363 DEBUG_CFLAGS=-O0 364 365 # DEBUG_BINARIES uses full -g debug information for all configs 366 ifeq ($(DEBUG_BINARIES), true) 367 CFLAGS += -g 368 else 369 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 370 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 371 DEBUG_CFLAGS += -g 372 endif 373 374 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 375 FASTDEBUG_CFLAGS += $(FASTDEBUG_CFLAGS/$(BUILDARCH)) 376 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) 377 FASTDEBUG_CFLAGS += -g 378 endif 379 380 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) 381 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) 382 OPT_CFLAGS += -g 383 endif 384 endif 385 endif 386 387 ifeq ($(USE_CLANG),) 388 # Enable bounds checking. 389 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) )" "1" 390 # stack smashing checks. 391 DEBUG_CFLAGS += -fstack-protector-all --param ssp-buffer-size=1 392 endif 393 endif 394 395 396 # If we are building HEADLESS, pass on to VM 397 # so it can set the java.awt.headless property 398 ifdef HEADLESS 399 CFLAGS += -DHEADLESS 400 endif 401 402 # We are building Embedded for a small device 403 # favor code space over speed 404 ifdef MINIMIZE_RAM_USAGE 405 CFLAGS += -DMINIMIZE_RAM_USAGE 406 endif 407 408 # Stack walking in the JVM relies on frame pointer (%rbp) to walk thread stack. 409 # Explicitly specify -fno-omit-frame-pointer because it is off by default 410 # starting with gcc 4.6. 411 ifndef USE_SUNCC 412 CFLAGS += -fno-omit-frame-pointer 413 endif 414 415 -include $(HS_ALT_MAKE)/linux/makefiles/gcc.make