1 # 2 # Copyright (c) 1999, 2018, 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 endif 64 65 66 ifeq ($(USE_CLANG), true) 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 128 endif 129 130 131 #------------------------------------------------------------------------ 132 # Compiler flags 133 134 # position-independent code 135 PICFLAG = -fPIC 136 137 VM_PICFLAG/LIBJVM = $(PICFLAG) 138 VM_PICFLAG/AOUT = 139 VM_PICFLAG = $(VM_PICFLAG/$(LINK_INTO)) 140 141 ifeq ($(JVM_VARIANT_ZERO), true) 142 CFLAGS += $(LIBFFI_CFLAGS) 143 endif 144 ifeq ($(JVM_VARIANT_ZEROSHARK), true) 145 CFLAGS += $(LIBFFI_CFLAGS) 146 CFLAGS += $(LLVM_CFLAGS) 147 endif 148 CFLAGS += $(VM_PICFLAG) 149 CFLAGS += -fno-rtti 150 CFLAGS += -fno-exceptions 151 CFLAGS += -D_REENTRANT 152 ifeq ($(USE_CLANG),) 153 CFLAGS += -fcheck-new 154 # version 4 and above support fvisibility=hidden (matches jni_x86.h file) 155 # except 4.1.2 gives pointless warnings that can't be disabled (afaik) 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 171 endif 172 173 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH)) 174 ARCHFLAG/i486 = -m32 -march=i586 175 ARCHFLAG/amd64 = -m64 $(STACK_ALIGNMENT_OPT) 176 ARCHFLAG/aarch64 = 177 ARCHFLAG/ia64 = 178 ARCHFLAG/sparc = -m32 -mcpu=v9 179 ARCHFLAG/sparcv9 = -m64 -mcpu=v9 180 ARCHFLAG/zero = $(ZERO_ARCHFLAG) 181 ARCHFLAG/ppc64 = -m64 182 183 CFLAGS += $(ARCHFLAG) 184 AOUT_FLAGS += $(ARCHFLAG) 185 LFLAGS += $(ARCHFLAG) 186 ASFLAGS += $(ARCHFLAG) 187 188 ifeq ($(DEBUG_BINARIES), true) 189 ASFLAGS += $(ASFLAGS_DEBUG_SYMBOLS) 190 endif 191 192 # Use C++ Interpreter 193 ifdef CC_INTERP 194 CFLAGS += -DCC_INTERP 195 endif 196 197 # Keep temporary files (.ii, .s) 198 ifdef NEED_ASM 199 CFLAGS += -save-temps 200 else 201 CFLAGS += -pipe 202 endif 203 204 # Compiler warnings are treated as errors 205 WARNINGS_ARE_ERRORS = -Werror 206 207 ifeq ($(USE_CLANG), true) 208 # However we need to clean the code up before we can unrestrictedly enable this option with Clang 209 WARNINGS_ARE_ERRORS += -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses 210 WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare 211 WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess 212 WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body 213 endif 214 215 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wreturn-type 216 217 ifeq ($(USE_CLANG),) 218 # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit 219 # conversions which might affect the values. Only enable it in earlier versions. 220 ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0" 221 WARNING_FLAGS += -Wconversion 222 endif 223 endif 224 225 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS) 226 # Special cases 227 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 228 229 # On newer GCCs, the compiler complains about null being passed 230 # to the %s format specifier. The warning appears only on 8u, 231 # but the code is largely the same up to trunk. We disable 232 # the warning until the code is fixed, to allow builds with 233 # -Werror (the default). 234 # See JDK-8269388 and PR3798 in IcedTea: 235 # https://icedtea.wildebeest.org/hg/icedtea8-forest/hotspot/rev/9f2ceb42dc64 236 # Option only exists on GCC 7 and later, checked by configure 237 ifeq ($(USE_FORMAT_OVERFLOW), 1) 238 CFLAGS_WARN/os_linux.o = $(CFLAGS_WARN/DEFAULT) -Wno-error=format-overflow 239 endif 240 241 # The flags to use for an Optimized g++ build 242 OPT_CFLAGS/SIZE=-Os 243 OPT_CFLAGS/SPEED=-O3 244 245 # Hotspot uses very unstrict aliasing turn this optimization off 246 # This option is added to CFLAGS rather than OPT_CFLAGS 247 # so that OPT_CFLAGS overrides get this option too. 248 CFLAGS += -fno-strict-aliasing 249 250 OPT_CFLAGS_DEFAULT ?= SPEED 251 252 ifdef OPT_CFLAGS 253 ifneq ("$(origin OPT_CFLAGS)", "command line") 254 $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.") 255 endif 256 endif 257 258 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS) 259 260 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp 261 # if we use expensive-optimizations 262 ifeq ($(BUILDARCH), ia64) 263 OPT_CFLAGS += -fno-expensive-optimizations 264 endif 265 266 OPT_CFLAGS/NOOPT=-O0 267 268 # Work around some compiler bugs. 269 ifeq ($(USE_CLANG), true) 270 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1) 271 OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT) 272 endif 273 else 274 # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation. 275 ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1) 276 OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT) 277 endif 278 endif 279 280 # Flags for generating make dependency flags. 281 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d) 282 ifeq ($(USE_CLANG),) 283 ifneq ("${CC_VER_MAJOR}", "2") 284 DEPFLAGS += -fpch-deps 285 endif 286 endif 287 288 #------------------------------------------------------------------------ 289 # Linker flags 290 291 # statically link libstdc++.so, work with gcc but ignored by g++ 292 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic 293 # While the VM needs the above line, adlc needs a separate setting: 294 ADLC_STATIC_STDCXX = -static-libstdc++ 295 296 ifeq ($(USE_CLANG),) 297 # statically link libgcc and/or libgcc_s, libgcc does not exist before gcc-3.x. 298 ifneq ("${CC_VER_MAJOR}", "2") 299 STATIC_LIBGCC += -static-libgcc 300 endif 301 302 ifeq ($(BUILDARCH), ia64) 303 LFLAGS += -Wl,-relax 304 endif 305 endif 306 307 # Enable linker optimization 308 LFLAGS += -Xlinker -O1 309 310 ifeq ($(USE_CLANG),) 311 # If this is a --hash-style=gnu system, use --hash-style=both 312 # The gnu .hash section won't work on some Linux systems like SuSE 10. 313 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu') 314 ifneq ($(_HAS_HASH_STYLE_GNU),) 315 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 316 endif 317 else 318 # Don't know how to find out the 'hash style' of a system as '-dumpspecs' 319 # doesn't work for Clang. So for now we'll alwys use --hash-style=both 320 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 321 endif 322 323 LFLAGS += $(LDFLAGS_HASH_STYLE) 324 325 LDFLAGS_NO_EXEC_STACK="-Wl,-z,noexecstack" 326 327 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file. 328 MAPFLAG = -Xlinker --version-script=FILENAME 329 330 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj 331 SONAMEFLAG = -Xlinker -soname=SONAME 332 333 # Build shared library 334 SHARED_FLAG = -shared 335 336 # Keep symbols even they are not used 337 AOUT_FLAGS += -Xlinker -export-dynamic 338 339 #------------------------------------------------------------------------ 340 # Debug flags 341 342 ifeq ($(USE_CLANG), true) 343 # Restrict the debug information created by Clang to avoid 344 # too big object files and speed the build up a little bit 345 # (see http://llvm.org/bugs/show_bug.cgi?id=7554) 346 CFLAGS += -flimit-debug-info 347 endif 348 349 # DEBUG_BINARIES uses full -g debug information for all configs 350 ifeq ($(DEBUG_BINARIES), true) 351 CFLAGS += -g 352 else 353 DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH)) 354 ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),) 355 DEBUG_CFLAGS += -g 356 endif 357 358 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 359 FASTDEBUG_CFLAGS += $(FASTDEBUG_CFLAGS/$(BUILDARCH)) 360 ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),) 361 FASTDEBUG_CFLAGS/$(BUILDARCH) = -g 362 endif 363 364 OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH)) 365 ifeq ($(OPT_CFLAGS/$(BUILDARCH)),) 366 OPT_CFLAGS/$(BUILDARCH) = -g 367 endif 368 endif 369 endif 370 371 # If we are building HEADLESS, pass on to VM 372 # so it can set the java.awt.headless property 373 ifdef HEADLESS 374 CFLAGS += -DHEADLESS 375 endif 376 377 # We are building Embedded for a small device 378 # favor code space over speed 379 ifdef MINIMIZE_RAM_USAGE 380 CFLAGS += -DMINIMIZE_RAM_USAGE 381 endif 382 383 # Stack walking in the JVM relies on frame pointer (%rbp) to walk thread stack. 384 # Explicitly specify -fno-omit-frame-pointer because it is off by default 385 # starting with gcc 4.6. 386 ifndef USE_SUNCC 387 CFLAGS += -fno-omit-frame-pointer 388 endif 389 390 -include $(HS_ALT_MAKE)/linux/makefiles/gcc.make