1 #
   2 # Copyright (c) 2013, 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.  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 ($(OPENJDK_TARGET_CPU), x86_64)
  60   OPENJDK_TARGET_CPU_VM_VERSION := amd64
  61 else ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
  62   OPENJDK_TARGET_CPU_VM_VERSION := sparc
  63 else ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
  64   ifeq ($(OPENJDK_TARGET_CPU), aarch64)
  65     # This sets the Oracle Aarch64 port to use arm64
  66     # while the original Aarch64 port uses aarch64
  67     OPENJDK_TARGET_CPU_VM_VERSION := arm64
  68   endif
  69 else
  70   OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
  71 endif
  72 
  73 CFLAGS_VM_VERSION := \
  74     $(VERSION_CFLAGS) \
  75     -DHOTSPOT_VERSION_STRING='"$(VERSION_STRING)"' \
  76     -DDEBUG_LEVEL='"$(DEBUG_LEVEL)"' \
  77     -DHOTSPOT_BUILD_USER='"$(USERNAME)"' \
  78     -DHOTSPOT_VM_DISTRO='"$(HOTSPOT_VM_DISTRO)"' \
  79     -DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \
  80     #
  81 
  82 ################################################################################
  83 # Platform specific setup
  84 
  85 # ARM source selection
  86 
  87 ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), linux-arm)
  88   JVM_EXCLUDE_PATTERNS += arm_64
  89 
  90 else ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), linux-aarch64)
  91   # For 64-bit arm builds, we use the 64 bit hotspot/src/cpu/arm
  92   # hotspot sources if HOTSPOT_TARGET_CPU_ARCH is set to arm.
  93   # Exclude the aarch64 and 32 bit arm files for this build.
  94   ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
  95     JVM_EXCLUDE_PATTERNS += arm_32 aarch64
  96   endif
  97 endif
  98 
  99 ifneq ($(filter $(OPENJDK_TARGET_OS), linux macosx windows), )
 100   JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
 101 endif
 102 
 103 ifeq ($(OPENJDK_TARGET_CPU), x86)
 104   JVM_EXCLUDE_PATTERNS += x86_64
 105 else ifeq ($(OPENJDK_TARGET_CPU), x86_64)
 106   JVM_EXCLUDE_PATTERNS += x86_32
 107 endif
 108 
 109 # Inline assembly for solaris
 110 ifeq ($(OPENJDK_TARGET_OS), solaris)
 111   ifeq ($(OPENJDK_TARGET_CPU), x86_64)
 112     JVM_CFLAGS += $(TOPDIR)/src/hotspot/os_cpu/solaris_x86/solaris_x86_64.il
 113   else ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
 114     JVM_CFLAGS += $(TOPDIR)/src/hotspot/os_cpu/solaris_sparc/solaris_sparc.il
 115   endif
 116 endif
 117 
 118 ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), solaris-sparcv9)
 119   ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), false)
 120     # NOTE: In the old build, we weirdly enough set -g/-g0 always, regardless
 121     # of if debug symbols were needed. Without it, compilation fails on
 122     # sparc! :-(
 123     JVM_CFLAGS += -g0
 124   endif
 125 endif
 126 
 127 ifeq ($(OPENJDK_TARGET_OS), windows)
 128   ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
 129     RC_DESC := 64-Bit$(SPACE)
 130   endif
 131   JVM_RCFLAGS += -D"HS_FILEDESC=$(HOTSPOT_VM_DISTRO) $(RC_DESC)$(JVM_VARIANT) VM"
 132 endif
 133 
 134 JVM_OPTIMIZATION ?= HIGHEST_JVM
 135 
 136 # Need to set JVM_STRIPFLAGS to the default value from SPEC since the STRIPFLAGS
 137 # parameter to SetupNativeCompilation allows an empty value to override the
 138 # default.
 139 JVM_STRIPFLAGS ?= $(STRIPFLAGS)
 140 
 141 ################################################################################
 142 # Now set up the actual compilation of the main hotspot native library
 143 
 144 $(eval $(call SetupNativeCompilation, BUILD_LIBJVM, \
 145     NAME := jvm, \
 146     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
 147     OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \
 148     SRC := $(JVM_SRC_DIRS), \
 149     EXCLUDES := $(JVM_EXCLUDES), \
 150     EXCLUDE_FILES := $(JVM_EXCLUDE_FILES), \
 151     EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
 152     EXTRA_OBJECT_FILES := $(DTRACE_EXTRA_OBJECT_FILES), \
 153     CFLAGS := $(JVM_CFLAGS), \
 154     vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 155     arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
 156     DISABLED_WARNINGS_clang := tautological-compare, \
 157     DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 \
 158         1540-1088 1500-010, \
 159     ASFLAGS := $(JVM_ASFLAGS), \
 160     LDFLAGS := $(JVM_LDFLAGS), \
 161     LIBS := $(JVM_LIBS), \
 162     OPTIMIZATION := $(JVM_OPTIMIZATION), \
 163     OBJECT_DIR := $(JVM_OUTPUTDIR)/objs, \
 164     MAPFILE := $(JVM_MAPFILE), \
 165     USE_MAPFILE_FOR_SYMBOLS := true, \
 166     STRIPFLAGS := $(JVM_STRIPFLAGS), \
 167     EMBED_MANIFEST := true, \
 168     RC_FLAGS := $(JVM_RCFLAGS), \
 169     VERSIONINFO_RESOURCE := $(TOPDIR)/src/hotspot/os/windows/version.rc, \
 170     PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
 171     PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
 172 ))
 173 
 174 ifeq ($(OPENJDK_TARGET_OS), windows)
 175   # It doesn't matter which jvm.lib file gets exported, but we need
 176   # to pick just one.
 177   ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
 178     $(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
 179         DEST := $(LIB_OUTPUTDIR), \
 180         FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
 181     ))
 182     TARGETS += $(COPY_JVM_LIB)
 183   endif
 184 endif
 185 
 186 # AIX warning explanation:
 187 # 1500-010  : (W) WARNING in ...: Infinite loop.  Program may not stop.
 188 #             There are several infinite loops in the vm, so better suppress.
 189 # 1540-0198 : (W) The omitted keyword "private" is assumed for base class "...".
 190 # 1540-0216 : (W) An expression of type .. cannot be converted to type ..
 191 #             In hotspot this fires for functionpointer to pointer conversions
 192 # 1540-1088 : (W) The exception specification is being ignored.
 193 #             In hotspot this is caused by throw() in declaration of new() in nmethod.hpp.
 194 # 1540-1090 : (I) The destructor of "..." might not be called.
 195 # 1540-1639 : (I) The behavior of long type bit fields has changed ...
 196 
 197 # Include mapfile generation. It relies on BUILD_LIBJVM_ALL_OBJS which is only
 198 # defined after the above call to BUILD_LIBJVM. Mapfile will be generated
 199 # after all object files are built, but before the jvm library is linked.
 200 include lib/JvmMapfile.gmk
 201 
 202 TARGETS += $(BUILD_LIBJVM)
 203 
 204 ################################################################################
 205 # Hotspot disallows the use of global operators 'new' and 'delete'. This build
 206 # time check helps enforce this requirement. If you trigger this check and the
 207 # reference is not obvious from the source, GNU objdump can be used to help find
 208 # the reference if compiled with GCC:
 209 #
 210 # objdump -lrdSC <path/to/file.o>
 211 #
 212 # -C demangle
 213 # -d disassemble
 214 # -r print relocation entries, interspersed with the disassembly
 215 # -S print source code, intermixed with disassembly
 216 # -l include filenames and line numbers
 217 #
 218 # Search the output for the operator(s) of interest, to see where they are
 219 # referenced.
 220 
 221 ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang solstudio), )
 222 
 223   DEMANGLED_REGEXP := [^:]operator (new|delete)
 224 
 225   # Running c++filt to find offending symbols in all files is too expensive,
 226   # especially on Solaris, so use mangled names when looking for symbols.
 227   # Save the demangling for when something is actually found.
 228   ifeq ($(TOOLCHAIN_TYPE), solstudio)
 229     MANGLED_SYMS := \
 230         __1c2n6FL_pv_ \
 231         __1c2N6FL_pv_ \
 232         __1c2k6Fpv_v_ \
 233         __1c2K6Fpv_v_ \
 234         #
 235     UNDEF_PATTERN := UNDEF
 236   else
 237     MANGLED_SYMS := \
 238         _ZdaPv \
 239         _ZdlPv \
 240         _Znam \
 241         _Znwm \
 242         #
 243     UNDEF_PATTERN := ' U '
 244   endif
 245 
 246   define SetupOperatorNewDeleteCheck
 247     $1.op_check: $1
 248         if [ -n "`$(NM) $$< | $(GREP) $(addprefix -e , $(MANGLED_SYMS)) \
 249             | $(GREP) $(UNDEF_PATTERN)`" ]; then \
 250           $(ECHO) "$$<: Error: Use of global operators new and delete is not allowed in Hotspot:"; \
 251           $(NM) $$< | $(CXXFILT) | $(EGREP) '$(DEMANGLED_REGEXP)' | $(GREP) $(UNDEF_PATTERN); \
 252           $(ECHO) "See: $(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
 253           exit 1; \
 254         fi
 255         $(TOUCH) $$@
 256 
 257     TARGETS += $1.op_check
 258   endef
 259 
 260   $(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
 261 endif