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 endif
  64 
  65 ifeq ($(USE_CLANG), true)
  66   # Clang has precompiled headers support by default, but the user can switch
  67   # it off by using 'USE_PRECOMPILED_HEADER=0'.
  68   ifdef LP64
  69     ifeq ($(USE_PRECOMPILED_HEADER),)
  70       USE_PRECOMPILED_HEADER=1
  71     endif
  72   else
  73     # We don't support precompiled headers on 32-bit builds because there some files are
  74     # compiled with -fPIC while others are compiled without (see 'NONPIC_OBJ_FILES' rules.make)
  75     # Clang produces an error if the PCH file was compiled with other options than the actual compilation unit.
  76     USE_PRECOMPILED_HEADER=0
  77   endif
  78 
  79   ifeq ($(USE_PRECOMPILED_HEADER),1)
  80 
  81     ifndef LP64
  82       $(error " Precompiled Headers only supported on 64-bit platforms!")
  83     endif
  84 
  85     PRECOMPILED_HEADER_DIR=.
  86     PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
  87     PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.pch
  88 
  89     PCH_FLAG = -include precompiled.hpp
  90     PCH_FLAG/DEFAULT = $(PCH_FLAG)
  91     PCH_FLAG/NO_PCH = -DNO_PCH
  92     PCH_FLAG/BY_FILE = $(PCH_FLAG/$@)$(PCH_FLAG/DEFAULT$(PCH_FLAG/$@))
  93 
  94     VM_PCH_FLAG/LIBJVM = $(PCH_FLAG/BY_FILE)
  95     VM_PCH_FLAG/AOUT =
  96     VM_PCH_FLAG = $(VM_PCH_FLAG/$(LINK_INTO))
  97 
  98     # We only use precompiled headers for the JVM build
  99     CFLAGS += $(VM_PCH_FLAG)
 100 
 101     # There are some files which don't like precompiled headers
 102     # The following files are build with 'OPT_CFLAGS/NOOPT' (-O0) in the opt build.
 103     # But Clang doesn't support a precompiled header which was compiled with -O3
 104     # to be used in a compilation unit which uses '-O0'. We could also prepare an
 105     # extra '-O0' PCH file for the opt build and use it here, but it's probably
 106     # not worth the effort as long as only two files need this special handling.
 107     PCH_FLAG/loopTransform.o = $(PCH_FLAG/NO_PCH)
 108     PCH_FLAG/sharedRuntimeTrig.o = $(PCH_FLAG/NO_PCH)
 109     PCH_FLAG/sharedRuntimeTrans.o = $(PCH_FLAG/NO_PCH)
 110 
 111   endif
 112 else # ($(USE_CLANG), true)
 113   # check for precompiled headers support
 114   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 4 \) \))" "0"
 115     # Allow the user to turn off precompiled headers from the command line.
 116     ifneq ($(USE_PRECOMPILED_HEADER),0)
 117       PRECOMPILED_HEADER_DIR=.
 118       PRECOMPILED_HEADER_SRC=$(GAMMADIR)/src/share/vm/precompiled/precompiled.hpp
 119       PRECOMPILED_HEADER=$(PRECOMPILED_HEADER_DIR)/precompiled.hpp.gch
 120     endif
 121   endif
 122 endif
 123 
 124 # -DDONT_USE_PRECOMPILED_HEADER will exclude all includes in precompiled.hpp.
 125 ifeq ($(USE_PRECOMPILED_HEADER),0)
 126   CFLAGS += -DDONT_USE_PRECOMPILED_HEADER
 127 endif
 128 
 129 
 130 #------------------------------------------------------------------------
 131 # Compiler flags
 132 
 133 # position-independent code
 134 PICFLAG = -fPIC
 135 
 136 VM_PICFLAG/LIBJVM = $(PICFLAG)
 137 VM_PICFLAG/AOUT   =
 138 VM_PICFLAG        = $(VM_PICFLAG/$(LINK_INTO))
 139 
 140 ifeq ($(JVM_VARIANT_ZERO), true)
 141 CFLAGS += $(LIBFFI_CFLAGS)
 142 endif
 143 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
 144 CFLAGS += $(LIBFFI_CFLAGS)
 145 CFLAGS += $(LLVM_CFLAGS)
 146 endif
 147 CFLAGS += $(VM_PICFLAG)
 148 CFLAGS += -fno-rtti
 149 CFLAGS += -fno-exceptions
 150 CFLAGS += -D_REENTRANT
 151 ifeq ($(USE_CLANG),)
 152   CFLAGS += -fcheck-new
 153   # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
 154   # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
 155   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
 156     CFLAGS += -fvisibility=hidden
 157   endif
 158 else
 159   CFLAGS += -fvisibility=hidden
 160 endif
 161 
 162 ifeq ($(USE_CLANG), true)
 163   # Before Clang 3.1, we had to pass the stack alignment specification directly to llvm with the help of '-mllvm'
 164   # Starting with version 3.1, Clang understands the '-mstack-alignment' (and rejects '-mllvm -stack-alignment')
 165   ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) \| \( \( $(CC_VER_MAJOR) = 3 \) \& \( $(CC_VER_MINOR) \>= 1 \) \))" "0"
 166     STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mstack-alignment=16
 167   else
 168     STACK_ALIGNMENT_OPT = -mno-omit-leaf-frame-pointer -mllvm -stack-alignment=16
 169   endif
 170 endif
 171 
 172 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
 173 ARCHFLAG/i486    = -m32 -march=i586
 174 ARCHFLAG/amd64   = -m64 $(STACK_ALIGNMENT_OPT)
 175 ARCHFLAG/aarch64 =
 176 ARCHFLAG/ia64    =
 177 ARCHFLAG/sparc   = -m32 -mcpu=v9
 178 ARCHFLAG/sparcv9 = -m64 -mcpu=v9
 179 ARCHFLAG/zero    = $(ZERO_ARCHFLAG)
 180 ARCHFLAG/ppc64   =  -m64
 181 
 182 CFLAGS     += $(ARCHFLAG)
 183 AOUT_FLAGS += $(ARCHFLAG)
 184 LFLAGS     += $(ARCHFLAG)
 185 ASFLAGS    += $(ARCHFLAG)
 186 
 187 # Use C++ Interpreter
 188 ifdef CC_INTERP
 189   CFLAGS += -DCC_INTERP
 190 endif
 191 
 192 # Keep temporary files (.ii, .s)
 193 ifdef NEED_ASM
 194   CFLAGS += -save-temps
 195 else
 196   CFLAGS += -pipe
 197 endif
 198 
 199 # Compiler warnings are treated as errors
 200 WARNINGS_ARE_ERRORS = -Werror
 201 
 202 ifeq ($(USE_CLANG), true)
 203   # However we need to clean the code up before we can unrestrictedly enable this option with Clang
 204   WARNINGS_ARE_ERRORS += -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses
 205   WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare
 206   WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess
 207   WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body
 208 endif
 209 
 210 WARNING_FLAGS = -Wpointer-arith -Wsign-compare -Wundef -Wunused-function -Wunused-value -Wformat=2 -Wreturn-type -Woverloaded-virtual
 211 
 212 ifeq ($(USE_CLANG),)
 213   # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
 214   # conversions which might affect the values. Only enable it in earlier versions.
 215   ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
 216     # GCC < 4.3
 217     WARNING_FLAGS += -Wconversion
 218   endif  
 219   ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 8 \) \))" "1"
 220     # GCC >= 4.8
 221     # This flag is only known since GCC 4.3. Gcc 4.8 contains a fix so that with templates no
 222     # warnings are issued: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11856
 223     WARNING_FLAGS += -Wtype-limits
 224     # GCC < 4.8 don't accept this flag for C++.
 225     WARNING_FLAGS += -Wno-format-zero-length
 226     # GCC 4.8 reports less false positives than the older compilers.
 227     WARNING_FLAGS += -Wuninitialized
 228   endif
 229 endif
 230 
 231 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(WARNING_FLAGS)
 232 
 233 # Special cases
 234 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@))
 235 
 236 # optimization control flags (Used by fastdebug and release variants)
 237 OPT_CFLAGS/NOOPT=-O0
 238 OPT_CFLAGS/DEBUG=-O0
 239 OPT_CFLAGS/SIZE=-Os
 240 OPT_CFLAGS/SPEED=-O3
 241 
 242 OPT_CFLAGS_DEFAULT ?= SPEED
 243 
 244 # Hotspot uses very unstrict aliasing turn this optimization off
 245 # This option is added to CFLAGS rather than OPT_CFLAGS
 246 # so that OPT_CFLAGS overrides get this option too.
 247 CFLAGS += -fno-strict-aliasing
 248 
 249 ifdef OPT_CFLAGS
 250   ifneq ("$(origin OPT_CFLAGS)", "command line")
 251     $(error " Use OPT_EXTRAS instead of OPT_CFLAGS to add extra flags to OPT_CFLAGS.")
 252   endif
 253 endif
 254 
 255 OPT_CFLAGS = $(OPT_CFLAGS/$(OPT_CFLAGS_DEFAULT)) $(OPT_EXTRAS)
 256 
 257 # The gcc compiler segv's on ia64 when compiling bytecodeInterpreter.cpp
 258 # if we use expensive-optimizations
 259 ifeq ($(BUILDARCH), ia64)
 260 OPT_CFLAGS += -fno-expensive-optimizations
 261 endif
 262 
 263 # Work around some compiler bugs.
 264 ifeq ($(USE_CLANG), true)
 265   ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 2), 1)
 266     OPT_CFLAGS/loopTransform.o += $(OPT_CFLAGS/NOOPT)
 267   endif
 268 else
 269   # 6835796. Problem in GCC 4.3.0 with mulnode.o optimized compilation.
 270   ifeq ($(shell expr $(CC_VER_MAJOR) = 4 \& $(CC_VER_MINOR) = 3), 1)
 271     OPT_CFLAGS/mulnode.o += $(OPT_CFLAGS/NOOPT)
 272   endif
 273 endif
 274 
 275 # Flags for generating make dependency flags.
 276 DEPFLAGS = -MMD -MP -MF $(DEP_DIR)/$(@:%=%.d)
 277 ifeq ($(USE_CLANG),)
 278   ifneq ($(CC_VER_MAJOR), 2)
 279     DEPFLAGS += -fpch-deps
 280   endif
 281 endif
 282 
 283 #------------------------------------------------------------------------
 284 # Linker flags
 285 
 286 # statically link libstdc++.so, work with gcc but ignored by g++
 287 STATIC_STDCXX = -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic
 288 
 289 # Enable linker optimization
 290 LFLAGS += -Xlinker -O1
 291 
 292 ifeq ($(USE_CLANG),)
 293   STATIC_LIBGCC += -static-libgcc
 294 
 295   ifneq (, findstring(debug,$(BUILD_FLAVOR)))
 296     # for relocations read-only
 297     LFLAGS += -Xlinker -z -Xlinker relro
 298 
 299     ifeq ($(BUILD_FLAVOR), debug)
 300       # disable incremental relocations linking
 301       LFLAGS += -Xlinker -z -Xlinker now
 302     endif
 303   endif
 304 
 305   ifeq ($(BUILDARCH), ia64)
 306     LFLAGS += -Wl,-relax
 307   endif
 308 
 309   # If this is a --hash-style=gnu system, use --hash-style=both
 310   #   The gnu .hash section won't work on some Linux systems like SuSE 10.
 311   _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
 312   ifneq ($(_HAS_HASH_STYLE_GNU),)
 313     LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
 314   endif
 315 else
 316   # Don't know how to find out the 'hash style' of a system as '-dumpspecs'
 317   # doesn't work for Clang. So for now we'll alwys use --hash-style=both
 318   LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
 319 endif
 320 
 321 LFLAGS += $(LDFLAGS_HASH_STYLE)
 322 
 323 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
 324 MAPFLAG = -Xlinker --version-script=FILENAME
 325 
 326 # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
 327 SONAMEFLAG = -Xlinker -soname=SONAME
 328 
 329 # Build shared library
 330 SHARED_FLAG = -shared
 331 
 332 # Keep symbols even they are not used
 333 AOUT_FLAGS += -Xlinker -export-dynamic
 334 
 335 #------------------------------------------------------------------------
 336 # Debug flags
 337 
 338 ifeq ($(USE_CLANG), true)
 339   # Restrict the debug information created by Clang to avoid
 340   # too big object files and speed the build up a little bit
 341   # (see http://llvm.org/bugs/show_bug.cgi?id=7554)
 342   CFLAGS += -flimit-debug-info
 343 endif
 344 
 345 # Allow no optimizations.
 346 DEBUG_CFLAGS=-O0
 347 
 348 # DEBUG_BINARIES uses full -g debug information for all configs
 349 ifeq ($(DEBUG_BINARIES), true)
 350   CFLAGS += -g
 351 else
 352   DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
 353   ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),)
 354     DEBUG_CFLAGS += -g
 355   endif
 356 
 357   ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 358     FASTDEBUG_CFLAGS += $(FASTDEBUG_CFLAGS/$(BUILDARCH))
 359     ifeq ($(FASTDEBUG_CFLAGS/$(BUILDARCH)),)
 360       FASTDEBUG_CFLAGS += -g
 361     endif
 362 
 363     OPT_CFLAGS += $(OPT_CFLAGS/$(BUILDARCH))
 364     ifeq ($(OPT_CFLAGS/$(BUILDARCH)),)
 365       OPT_CFLAGS += -g
 366     endif
 367   endif
 368 endif
 369 
 370 ifeq ($(USE_CLANG),)
 371   # Enable bounds checking.
 372   ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 3 \) )" "1"
 373     # stack smashing checks.
 374     DEBUG_CFLAGS += -fstack-protector-all --param ssp-buffer-size=1
 375   endif
 376 endif
 377 
 378 
 379 # If we are building HEADLESS, pass on to VM
 380 # so it can set the java.awt.headless property
 381 ifdef HEADLESS
 382 CFLAGS += -DHEADLESS
 383 endif
 384 
 385 # We are building Embedded for a small device
 386 # favor code space over speed
 387 ifdef MINIMIZE_RAM_USAGE
 388 CFLAGS += -DMINIMIZE_RAM_USAGE
 389 endif
 390 
 391 # Stack walking in the JVM relies on frame pointer (%rbp) to walk thread stack.
 392 # Explicitly specify -fno-omit-frame-pointer because it is off by default
 393 # starting with gcc 4.6.
 394 ifndef USE_SUNCC
 395   CFLAGS += -fno-omit-frame-pointer
 396 endif
 397 
 398 -include $(HS_ALT_MAKE)/linux/makefiles/gcc.make