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