1 #
   2 # Copyright (c) 2013, 2020, 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 ################################################################################
  33 # Setup compilation of the main Hotspot native library (libjvm).
  34 
  35 JVM_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm
  36 JVM_MAPFILE := $(JVM_OUTPUTDIR)/mapfile
  37 
  38 ################################################################################
  39 # Platform independent setup
  40 
  41 JVM_LDFLAGS += \
  42     $(SHARED_LIBRARY_FLAGS) \
  43     $(JVM_LDFLAGS_FEATURES) \
  44     $(EXTRA_LDFLAGS) \
  45     #
  46 
  47 JVM_ASFLAGS += $(EXTRA_ASFLAGS)
  48 
  49 JVM_LIBS += \
  50     $(JVM_LIBS_FEATURES) \
  51     #
  52 
  53 # These files and directories are always excluded
  54 JVM_EXCLUDE_FILES += args.cc
  55 JVM_EXCLUDES += adlc
  56 
  57 # Needed by abstract_vm_version.cpp
  58 ifeq ($(call isTargetCpu, x86_64), true)
  59   OPENJDK_TARGET_CPU_VM_VERSION := amd64
  60 else
  61   OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
  62 endif
  63 
  64 CFLAGS_VM_VERSION := \
  65     $(VERSION_CFLAGS) \
  66     -DHOTSPOT_VERSION_STRING='"$(VERSION_STRING)"' \
  67     -DDEBUG_LEVEL='"$(DEBUG_LEVEL)"' \
  68     -DHOTSPOT_BUILD_USER='"$(USERNAME)"' \
  69     -DHOTSPOT_VM_DISTRO='"$(HOTSPOT_VM_DISTRO)"' \
  70     -DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \
  71     #
  72 
  73 ifneq ($(HOTSPOT_BUILD_TIME), )
  74   CFLAGS_VM_VERSION += -DHOTSPOT_BUILD_TIME='"$(HOTSPOT_BUILD_TIME)"'
  75 endif
  76 
  77 ################################################################################
  78 # Disabled warnings
  79 
  80 DISABLED_WARNINGS_gcc := parentheses comment unknown-pragmas address \
  81     delete-non-virtual-dtor char-subscripts array-bounds int-in-bool-context \
  82     ignored-qualifiers  missing-field-initializers implicit-fallthrough \
  83     empty-body strict-overflow sequence-point maybe-uninitialized \
  84     misleading-indentation cast-function-type
  85 
  86 ifeq ($(call check-jvm-feature, zero), true)
  87   DISABLED_WARNINGS_gcc += return-type switch clobbered
  88 endif
  89 
  90 DISABLED_WARNINGS_clang := tautological-compare \
  91     undefined-var-template sometimes-uninitialized unknown-pragmas \
  92     delete-non-virtual-dtor missing-braces char-subscripts \
  93     ignored-qualifiers missing-field-initializers mismatched-tags
  94 
  95 DISABLED_WARNINGS_xlc := tautological-compare shift-negative-value
  96 
  97 DISABLED_WARNINGS_microsoft :=
  98 
  99 
 100 
 101 ################################################################################
 102 # Platform specific setup
 103 
 104 # ARM source selection
 105 
 106 ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, arm)), true)
 107   JVM_EXCLUDE_PATTERNS += arm_64
 108 
 109 else ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, aarch64)), true)
 110   # For 64-bit arm builds, we use the 64 bit hotspot/src/cpu/arm
 111   # hotspot sources if HOTSPOT_TARGET_CPU_ARCH is set to arm.
 112   # Exclude the aarch64 and 32 bit arm files for this build.
 113   ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
 114     JVM_EXCLUDE_PATTERNS += arm_32 aarch64
 115   endif
 116 endif
 117 
 118 ifeq ($(call isTargetOs, linux macosx windows), true)
 119   JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
 120 endif
 121 
 122 ifeq ($(call isTargetCpu, x86), true)
 123   JVM_EXCLUDE_PATTERNS += x86_64
 124 else ifeq ($(call isTargetCpu, x86_64), true)
 125   JVM_EXCLUDE_PATTERNS += x86_32
 126 endif
 127 
 128 ifeq ($(call isTargetOs, windows), true)
 129   ifeq ($(call isTargetCpuBits, 64), true)
 130     RC_DESC := 64-Bit$(SPACE)
 131   endif
 132   JVM_RCFLAGS += -D"HS_FILEDESC=$(HOTSPOT_VM_DISTRO) $(RC_DESC)$(JVM_VARIANT) VM"
 133 endif
 134 
 135 JVM_OPTIMIZATION ?= HIGHEST_JVM
 136 
 137 # Need to set JVM_STRIPFLAGS to the default value from SPEC since the STRIPFLAGS
 138 # parameter to SetupNativeCompilation allows an empty value to override the
 139 # default.
 140 JVM_STRIPFLAGS ?= $(STRIPFLAGS)
 141 
 142 # This source set is reused so save in cache.
 143 $(call FillFindCache, $(JVM_SRC_DIRS))
 144 
 145 ################################################################################
 146 # Now set up the actual compilation of the main hotspot native library
 147 
 148 $(eval $(call SetupNativeCompilation, BUILD_LIBJVM, \
 149     NAME := jvm, \
 150     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
 151     OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \
 152     SRC := $(JVM_SRC_DIRS), \
 153     EXCLUDES := $(JVM_EXCLUDES), \
 154     EXCLUDE_FILES := $(JVM_EXCLUDE_FILES), \
 155     EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
 156     CFLAGS := $(JVM_CFLAGS), \
 157     abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 158     arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 159     DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \
 160     DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \
 161     DISABLED_WARNINGS_xlc := $(DISABLED_WARNINGS_xlc), \
 162     DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \
 163     ASFLAGS := $(JVM_ASFLAGS), \
 164     LDFLAGS := $(JVM_LDFLAGS), \
 165     LIBS := $(JVM_LIBS), \
 166     OPTIMIZATION := $(JVM_OPTIMIZATION), \
 167     OBJECT_DIR := $(JVM_OUTPUTDIR)/objs, \
 168     MAPFILE := $(JVM_MAPFILE), \
 169     USE_MAPFILE_FOR_SYMBOLS := true, \
 170     STRIPFLAGS := $(JVM_STRIPFLAGS), \
 171     EMBED_MANIFEST := true, \
 172     RC_FLAGS := $(JVM_RCFLAGS), \
 173     VERSIONINFO_RESOURCE := $(TOPDIR)/src/hotspot/os/windows/version.rc, \
 174     PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
 175     PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
 176 ))
 177 
 178 # Always recompile abstract_vm_version.cpp if libjvm needs to be relinked. This ensures
 179 # that the internal vm version is updated as it relies on __DATE__ and __TIME__
 180 # macros.
 181 ABSTRACT_VM_VERSION_OBJ := $(JVM_OUTPUTDIR)/objs/abstract_vm_version$(OBJ_SUFFIX)
 182 $(ABSTRACT_VM_VERSION_OBJ): $(filter-out $(ABSTRACT_VM_VERSION_OBJ) $(JVM_MAPFILE), \
 183     $(BUILD_LIBJVM_TARGET_DEPS))
 184 
 185 ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
 186   ifeq ($(call isTargetOs, windows), true)
 187     # It doesn't matter which jvm.lib file gets exported, but we need
 188     # to pick just one.
 189     ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
 190       $(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
 191           DEST := $(LIB_OUTPUTDIR), \
 192           FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
 193       ))
 194       TARGETS += $(COPY_JVM_LIB)
 195     endif
 196   endif
 197 endif
 198 
 199 # AIX warning explanation:
 200 # 1500-010  : (W) WARNING in ...: Infinite loop.  Program may not stop.
 201 #             There are several infinite loops in the vm, so better suppress.
 202 # 1540-0198 : (W) The omitted keyword "private" is assumed for base class "...".
 203 # 1540-0216 : (W) An expression of type .. cannot be converted to type ..
 204 #             In hotspot this fires for functionpointer to pointer conversions
 205 # 1540-1088 : (W) The exception specification is being ignored.
 206 #             In hotspot this is caused by throw() in declaration of new() in nmethod.hpp.
 207 # 1540-1090 : (I) The destructor of "..." might not be called.
 208 # 1540-1639 : (I) The behavior of long type bit fields has changed ...
 209 
 210 # Include mapfile generation. It relies on BUILD_LIBJVM_ALL_OBJS which is only
 211 # defined after the above call to BUILD_LIBJVM. Mapfile will be generated
 212 # after all object files are built, but before the jvm library is linked.
 213 include lib/JvmMapfile.gmk
 214 
 215 TARGETS += $(BUILD_LIBJVM)
 216 
 217 ################################################################################
 218 # Hotspot disallows the use of global operators 'new' and 'delete'. This build
 219 # time check helps enforce this requirement. If you trigger this check and the
 220 # reference is not obvious from the source, GNU objdump can be used to help find
 221 # the reference if compiled with GCC:
 222 #
 223 # objdump -lrdSC <path/to/file.o>
 224 #
 225 # -C demangle
 226 # -d disassemble
 227 # -r print relocation entries, interspersed with the disassembly
 228 # -S print source code, intermixed with disassembly
 229 # -l include filenames and line numbers
 230 #
 231 # Search the output for the operator(s) of interest, to see where they are
 232 # referenced.
 233 #
 234 # When a reference to the global 'operator delete' is reported, it might be
 235 # due to a "deleting destructor".  In this case, objdump may show the
 236 # reference to be associated with but not actually in a destructor.  A
 237 # deleting destructor is automatically generated for a class whose destructor
 238 # is virtual.  A deleting destructor requires an accessible 'operator delete'
 239 # for the associated class.  If the class doesn't provide a more specific
 240 # declaration (either directly or by inheriting from a class that provides
 241 # one) then the global definition will be used, triggering this check.
 242 
 243 ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
 244   ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang), )
 245 
 246     DEMANGLED_REGEXP := [^:]operator (new|delete)
 247 
 248     # Running c++filt to find offending symbols in all files is too expensive,
 249     # so use mangled names when looking for symbols.
 250     # Save the demangling for when something is actually found.
 251     MANGLED_SYMS := \
 252         _ZdaPv \
 253         _ZdlPv \
 254         _Znam \
 255         _Znwm \
 256         #
 257     UNDEF_PATTERN := ' U '
 258 
 259     define SetupOperatorNewDeleteCheck
 260         $1.op_check: $1
 261           if [ -n "`$(NM) $$< | $(GREP) $(addprefix -e , $(MANGLED_SYMS)) \
 262               | $(GREP) $(UNDEF_PATTERN)`" ]; then \
 263             $(ECHO) "$$<: Error: Use of global operators new and delete is not allowed in Hotspot:"; \
 264             $(NM) $$< | $(CXXFILT) | $(EGREP) '$(DEMANGLED_REGEXP)' | $(GREP) $(UNDEF_PATTERN); \
 265             $(ECHO) "See: $(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
 266             exit 1; \
 267           fi
 268           $(TOUCH) $$@
 269 
 270       TARGETS += $1.op_check
 271     endef
 272 
 273     $(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
 274   endif
 275 endif