1 #
   2 # Copyright (c) 2013, 2019, 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.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 # Include support files that will setup compiler flags due to the selected
  27 # jvm feature set, specific file overrides, and general flags.
  28 include lib/JvmFeatures.gmk
  29 include lib/JvmOverrideFiles.gmk
  30 include lib/JvmFlags.gmk
  31 
  32 # Include support files that will setup DTRACE_EXTRA_OBJECT_FILES.
  33 include lib/JvmDtraceObjects.gmk
  34 
  35 ################################################################################
  36 # Setup compilation of the main Hotspot native library (libjvm).
  37 
  38 JVM_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm
  39 JVM_MAPFILE := $(JVM_OUTPUTDIR)/mapfile
  40 
  41 ################################################################################
  42 # Platform independent setup
  43 
  44 JVM_LDFLAGS += \
  45     $(SHARED_LIBRARY_FLAGS) \
  46     $(JVM_LDFLAGS_FEATURES) \
  47     $(EXTRA_LDFLAGS) \
  48     #
  49 
  50 JVM_LIBS += \
  51     $(JVM_LIBS_FEATURES) \
  52     #
  53 
  54 # These files and directories are always excluded
  55 JVM_EXCLUDE_FILES += args.cc
  56 JVM_EXCLUDES += adlc
  57 
  58 # Needed by vm_version.cpp
  59 ifeq ($(call isTargetCpu, x86_64), true)
  60   OPENJDK_TARGET_CPU_VM_VERSION := amd64
  61 else ifeq ($(call isTargetCpu, sparcv9), true)
  62   OPENJDK_TARGET_CPU_VM_VERSION := sparc
  63 else
  64   OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
  65 endif
  66 
  67 ifneq ($(HOTSPOT_TARGET_LIBC),)
  68   LIBC_DEFINE := -DHOTSPOT_LIBC='"$(HOTSPOT_TARGET_LIBC)"'
  69 endif
  70 
  71 CFLAGS_VM_VERSION := \
  72     $(VERSION_CFLAGS) \
  73     -DHOTSPOT_VERSION_STRING='"$(VERSION_STRING)"' \
  74     -DDEBUG_LEVEL='"$(DEBUG_LEVEL)"' \
  75     -DHOTSPOT_BUILD_USER='"$(USERNAME)"' \
  76     -DHOTSPOT_VM_DISTRO='"$(HOTSPOT_VM_DISTRO)"' \
  77     -DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \
  78     $(LIBC_DEFINE) \
  79     #
  80 
  81 ################################################################################
  82 # Disabled warnings
  83 
  84 DISABLED_WARNINGS_gcc := extra parentheses comment unknown-pragmas address \
  85     delete-non-virtual-dtor char-subscripts array-bounds int-in-bool-context \
  86     ignored-qualifiers  missing-field-initializers implicit-fallthrough \
  87     empty-body strict-overflow sequence-point maybe-uninitialized \
  88     misleading-indentation
  89 
  90 ifeq ($(call check-jvm-feature, zero), true)
  91   DISABLED_WARNINGS_gcc += return-type switch
  92 endif
  93 
  94 DISABLED_WARNINGS_clang := tautological-compare \
  95     undefined-var-template sometimes-uninitialized unknown-pragmas \
  96     delete-non-virtual-dtor missing-braces char-subscripts \
  97     ignored-qualifiers missing-field-initializers mismatched-tags
  98 
  99 DISABLED_WARNINGS_solstudio := labelnotused hidef w_novirtualdescr inlafteruse \
 100     unknownpragma doubunder w_enumnotused w_toomanyenumnotused \
 101     wvarhidenmem wunreachable wnoretvalue notemsource
 102 
 103 DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 1540-1088 \
 104     1500-010
 105 
 106 DISABLED_WARNINGS_microsoft :=
 107 
 108 
 109 
 110 ################################################################################
 111 # Platform specific setup
 112 
 113 # ARM source selection
 114 
 115 ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, arm)), true)
 116   JVM_EXCLUDE_PATTERNS += arm_64
 117 
 118 else ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, aarch64)), true)
 119   # For 64-bit arm builds, we use the 64 bit hotspot/src/cpu/arm
 120   # hotspot sources if HOTSPOT_TARGET_CPU_ARCH is set to arm.
 121   # Exclude the aarch64 and 32 bit arm files for this build.
 122   ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
 123     JVM_EXCLUDE_PATTERNS += arm_32 aarch64
 124   endif
 125 endif
 126 
 127 ifeq ($(call isTargetOs, linux macosx windows), true)
 128   JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
 129 endif
 130 
 131 ifeq ($(call isTargetCpu, x86), true)
 132   JVM_EXCLUDE_PATTERNS += x86_64
 133 else ifeq ($(call isTargetCpu, x86_64), true)
 134   JVM_EXCLUDE_PATTERNS += x86_32
 135 endif
 136 
 137 # Inline assembly for solaris
 138 ifeq ($(call isTargetOs, solaris), true)
 139   ifeq ($(call isTargetCpu, x86_64), true)
 140     JVM_CFLAGS += $(TOPDIR)/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.il
 141   else ifeq ($(call isTargetCpu, sparcv9), true)
 142     JVM_CFLAGS += $(TOPDIR)/src/hotspot/os_cpu/solaris_sparc/solaris_sparc.il
 143   endif
 144   # Exclude warnings in devstudio 12.6
 145   ifeq ($(CC_VERSION_NUMBER), 5.15)
 146     DISABLED_WARNINGS_solstudio += SEC_ARR_OUTSIDE_BOUND_READ \
 147       SEC_ARR_OUTSIDE_BOUND_WRITE
 148   endif
 149 endif
 150 
 151 ifeq ($(call And, $(call isTargetOs, solaris) $(call isTargetCpu, sparcv9)), true)
 152   ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), false)
 153     # NOTE: In the old build, we weirdly enough set -g/-g0 always, regardless
 154     # of if debug symbols were needed. Without it, compilation fails on
 155     # sparc! :-(
 156     JVM_CFLAGS += -g0
 157   endif
 158 endif
 159 
 160 ifeq ($(call isTargetOs, windows), true)
 161   ifeq ($(call isTargetCpuBits, 64), true)
 162     RC_DESC := 64-Bit$(SPACE)
 163   endif
 164   JVM_RCFLAGS += -D"HS_FILEDESC=$(HOTSPOT_VM_DISTRO) $(RC_DESC)$(JVM_VARIANT) VM"
 165 endif
 166 
 167 JVM_OPTIMIZATION ?= HIGHEST_JVM
 168 
 169 # Need to set JVM_STRIPFLAGS to the default value from SPEC since the STRIPFLAGS
 170 # parameter to SetupNativeCompilation allows an empty value to override the
 171 # default.
 172 JVM_STRIPFLAGS ?= $(STRIPFLAGS)
 173 
 174 # This source set is reused so save in cache.
 175 $(call FillFindCache, $(JVM_SRC_DIRS))
 176 
 177 ################################################################################
 178 # Now set up the actual compilation of the main hotspot native library
 179 
 180 $(eval $(call SetupNativeCompilation, BUILD_LIBJVM, \
 181     NAME := jvm, \
 182     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
 183     OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \
 184     SRC := $(JVM_SRC_DIRS), \
 185     EXCLUDES := $(JVM_EXCLUDES), \
 186     EXCLUDE_FILES := $(JVM_EXCLUDE_FILES), \
 187     EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
 188     EXTRA_OBJECT_FILES := $(DTRACE_EXTRA_OBJECT_FILES), \
 189     CFLAGS := $(JVM_CFLAGS), \
 190     vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 191     arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 192     DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \
 193     DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \
 194     DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio), \
 195     DISABLED_WARNINGS_xlc := $(DISABLED_WARNINGS_xlc), \
 196     DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \
 197     ASFLAGS := $(JVM_ASFLAGS), \
 198     LDFLAGS := $(JVM_LDFLAGS), \
 199     LIBS := $(JVM_LIBS), \
 200     OPTIMIZATION := $(JVM_OPTIMIZATION), \
 201     OBJECT_DIR := $(JVM_OUTPUTDIR)/objs, \
 202     MAPFILE := $(JVM_MAPFILE), \
 203     USE_MAPFILE_FOR_SYMBOLS := true, \
 204     STRIPFLAGS := $(JVM_STRIPFLAGS), \
 205     EMBED_MANIFEST := true, \
 206     RC_FLAGS := $(JVM_RCFLAGS), \
 207     VERSIONINFO_RESOURCE := $(TOPDIR)/src/hotspot/os/windows/version.rc, \
 208     PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
 209     PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
 210     DEFINE_THIS_FILE := false, \
 211 ))
 212 
 213 # Always recompile vm_version.cpp if libjvm needs to be relinked. This ensures
 214 # that the internal vm version is updated as it relies on __DATE__ and __TIME__
 215 # macros.
 216 VM_VERSION_OBJ := $(JVM_OUTPUTDIR)/objs/vm_version$(OBJ_SUFFIX)
 217 $(VM_VERSION_OBJ): $(filter-out $(VM_VERSION_OBJ) $(JVM_MAPFILE), \
 218     $(BUILD_LIBJVM_TARGET_DEPS))
 219 
 220 ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
 221   ifeq ($(call isTargetOs, windows), true)
 222     # It doesn't matter which jvm.lib file gets exported, but we need
 223     # to pick just one.
 224     ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
 225       $(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
 226           DEST := $(LIB_OUTPUTDIR), \
 227           FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
 228       ))
 229       TARGETS += $(COPY_JVM_LIB)
 230     endif
 231   endif
 232 endif
 233 
 234 # AIX warning explanation:
 235 # 1500-010  : (W) WARNING in ...: Infinite loop.  Program may not stop.
 236 #             There are several infinite loops in the vm, so better suppress.
 237 # 1540-0198 : (W) The omitted keyword "private" is assumed for base class "...".
 238 # 1540-0216 : (W) An expression of type .. cannot be converted to type ..
 239 #             In hotspot this fires for functionpointer to pointer conversions
 240 # 1540-1088 : (W) The exception specification is being ignored.
 241 #             In hotspot this is caused by throw() in declaration of new() in nmethod.hpp.
 242 # 1540-1090 : (I) The destructor of "..." might not be called.
 243 # 1540-1639 : (I) The behavior of long type bit fields has changed ...
 244 
 245 # Include mapfile generation. It relies on BUILD_LIBJVM_ALL_OBJS which is only
 246 # defined after the above call to BUILD_LIBJVM. Mapfile will be generated
 247 # after all object files are built, but before the jvm library is linked.
 248 include lib/JvmMapfile.gmk
 249 
 250 TARGETS += $(BUILD_LIBJVM)
 251 
 252 ################################################################################
 253 # Hotspot disallows the use of global operators 'new' and 'delete'. This build
 254 # time check helps enforce this requirement. If you trigger this check and the
 255 # reference is not obvious from the source, GNU objdump can be used to help find
 256 # the reference if compiled with GCC:
 257 #
 258 # objdump -lrdSC <path/to/file.o>
 259 #
 260 # -C demangle
 261 # -d disassemble
 262 # -r print relocation entries, interspersed with the disassembly
 263 # -S print source code, intermixed with disassembly
 264 # -l include filenames and line numbers
 265 #
 266 # Search the output for the operator(s) of interest, to see where they are
 267 # referenced.
 268 
 269 ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
 270   ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang solstudio), )
 271 
 272     DEMANGLED_REGEXP := [^:]operator (new|delete)
 273 
 274     # Running c++filt to find offending symbols in all files is too expensive,
 275     # especially on Solaris, so use mangled names when looking for symbols.
 276     # Save the demangling for when something is actually found.
 277     ifeq ($(TOOLCHAIN_TYPE), solstudio)
 278       MANGLED_SYMS := \
 279           __1c2n6FL_pv_ \
 280           __1c2N6FL_pv_ \
 281           __1c2k6Fpv_v_ \
 282           __1c2K6Fpv_v_ \
 283           #
 284       UNDEF_PATTERN := UNDEF
 285     else
 286       MANGLED_SYMS := \
 287           _ZdaPv \
 288           _ZdlPv \
 289           _Znam \
 290           _Znwm \
 291           #
 292       UNDEF_PATTERN := ' U '
 293     endif
 294 
 295     define SetupOperatorNewDeleteCheck
 296         $1.op_check: $1
 297           if [ -n "`$(NM) $$< | $(GREP) $(addprefix -e , $(MANGLED_SYMS)) \
 298               | $(GREP) $(UNDEF_PATTERN)`" ]; then \
 299             $(ECHO) "$$<: Error: Use of global operators new and delete is not allowed in Hotspot:"; \
 300             $(NM) $$< | $(CXXFILT) | $(EGREP) '$(DEMANGLED_REGEXP)' | $(GREP) $(UNDEF_PATTERN); \
 301             $(ECHO) "See: $(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
 302             exit 1; \
 303           fi
 304           $(TOUCH) $$@
 305 
 306       TARGETS += $1.op_check
 307     endef
 308 
 309     $(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
 310   endif
 311 endif