jdk-24/make/hotspot/lib/CompileJvm.gmk
2024-09-03 15:31:09 +00:00

364 lines
15 KiB
Plaintext

#
# Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
include CopyFiles.gmk
# Include support files that will setup compiler flags due to the selected
# jvm feature set, specific file overrides, and general flags.
include lib/JvmFeatures.gmk
include lib/JvmOverrideFiles.gmk
include lib/JvmFlags.gmk
################################################################################
# Setup compilation of the main Hotspot native library (libjvm).
JVM_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm
################################################################################
# Platform independent setup
JVM_LDFLAGS += \
$(SHARED_LIBRARY_FLAGS) \
$(JVM_LDFLAGS_FEATURES) \
$(EXTRA_LDFLAGS) \
#
JVM_ASFLAGS += $(EXTRA_ASFLAGS)
JVM_ASFLAGS += \
-I$(TOPDIR)/src/hotspot/os_cpu/$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU_ARCH) \
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS) \
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE) \
#
JVM_LIBS += \
$(JVM_LIBS_FEATURES) \
#
# These files and directories are always excluded
JVM_EXCLUDE_FILES += args.cc
JVM_EXCLUDES += adlc
# Needed by abstract_vm_version.cpp
ifeq ($(call isTargetCpu, x86_64), true)
OPENJDK_TARGET_CPU_VM_VERSION := amd64
else
OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
endif
ifeq ($(VERSION_BUILD), )
# Hotspot cannot handle an empty build number
VERSION_BUILD := 0
endif
ifeq ($(HOTSPOT_BUILD_TIME), )
HOTSPOT_BUILD_TIME := $(call EpochToISO8601, $(shell $(DATE) +"%s"))
endif
CFLAGS_VM_VERSION := \
$(VERSION_CFLAGS) \
-DHOTSPOT_VERSION_STRING='"$(VERSION_STRING)"' \
-DDEBUG_LEVEL='"$(DEBUG_LEVEL)"' \
-DHOTSPOT_VM_DISTRO='"$(HOTSPOT_VM_DISTRO)"' \
-DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \
-DHOTSPOT_BUILD_TIME='"$(HOTSPOT_BUILD_TIME)"' \
#
################################################################################
# Disabled warnings
DISABLED_WARNINGS_gcc := array-bounds comment delete-non-virtual-dtor \
empty-body implicit-fallthrough int-in-bool-context \
maybe-uninitialized missing-field-initializers \
shift-negative-value unknown-pragmas unused-but-set-variable \
unused-local-typedefs unused-variable
DISABLED_WARNINGS_clang := delete-non-abstract-non-virtual-dtor missing-braces \
sometimes-uninitialized unknown-pragmas unused-but-set-variable \
unused-function unused-local-typedef unused-private-field unused-variable
ifneq ($(DEBUG_LEVEL), release)
# Assert macro gives warning
DISABLED_WARNINGS_clang += tautological-constant-out-of-range-compare
# Some reasonable asserts produce warnings on GCC <= 7
DISABLED_WARNINGS_gcc += strict-overflow
endif
DISABLED_WARNINGS_microsoft := 4624 4244 4291 4146 4127 4722
################################################################################
# Platform specific setup
# ARM source selection
ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, arm)), true)
JVM_EXCLUDE_PATTERNS += arm_64
else ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, aarch64)), true)
# For 64-bit arm builds, we use the 64 bit hotspot/src/cpu/arm
# hotspot sources if HOTSPOT_TARGET_CPU_ARCH is set to arm.
# Exclude the aarch64 and 32 bit arm files for this build.
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
JVM_EXCLUDE_PATTERNS += arm_32 aarch64
endif
endif
ifeq ($(call isTargetOs, linux macosx windows), true)
JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
endif
ifeq ($(call isTargetCpu, x86), true)
JVM_EXCLUDE_PATTERNS += x86_64
else ifeq ($(call isTargetCpu, x86_64), true)
JVM_EXCLUDE_PATTERNS += x86_32
endif
JVM_OPTIMIZATION ?= HIGHEST_JVM
# Need to set JVM_STRIPFLAGS to the default value from SPEC since the STRIPFLAGS
# parameter to SetupJdkLibrary allows an empty value to override the
# default.
JVM_STRIPFLAGS ?= $(STRIPFLAGS)
# This source set is reused so save in cache.
$(call FillFindCache, $(JVM_SRC_DIRS))
ifeq ($(call isTargetOs, windows), true)
ifeq ($(STATIC_LIBS), true)
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/static-win-exports.def
else
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/win-exports.def
endif
JVM_LDFLAGS += -def:$(WIN_EXPORT_FILE)
endif
ifeq ($(call isTargetOs, linux), true)
HOTSPOT_VERSION_SCRIPT := $(TOPDIR)/make/data/hotspot-symbols/version-script-$(TOOLCHAIN_TYPE).txt
JVM_LDFLAGS += -Wl,-version-script=$(HOTSPOT_VERSION_SCRIPT)
endif
################################################################################
## Build libjvm
################################################################################
$(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
NAME := jvm, \
LINK_TYPE := C++, \
OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \
SRC := $(JVM_SRC_DIRS), \
EXCLUDES := $(JVM_EXCLUDES), \
EXCLUDE_FILES := $(JVM_EXCLUDE_FILES), \
EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
DEFAULT_CFLAGS := false, \
CFLAGS := $(JVM_CFLAGS), \
abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \
DISABLED_WARNINGS_gcc_ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp := nonnull, \
DISABLED_WARNINGS_gcc_bytecodeInterpreter.cpp := unused-label, \
DISABLED_WARNINGS_gcc_c1_Runtime1_aarch64.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_cgroupV1Subsystem_linux.cpp := address, \
DISABLED_WARNINGS_gcc_cgroupV2Subsystem_linux.cpp := address, \
DISABLED_WARNINGS_gcc_g1FreeIdSet.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_handshake.cpp := stringop-overflow, \
DISABLED_WARNINGS_gcc_interp_masm_x86.cpp := uninitialized, \
DISABLED_WARNINGS_gcc_javaClasses.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_jfrChunkWriter.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_jfrMemorySizer.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_jfrTraceIdKlassQueue.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_jvmciCodeInstaller.cpp := stringop-overflow, \
DISABLED_WARNINGS_gcc_jvmFlag.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_jvmtiTagMap.cpp := stringop-overflow, \
DISABLED_WARNINGS_gcc_macroAssembler_ppc_sha.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_postaloc.cpp := address, \
DISABLED_WARNINGS_gcc_shenandoahLock.cpp := stringop-overflow, \
DISABLED_WARNINGS_gcc_stubGenerator_s390.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_synchronizer.cpp := stringop-overflow, \
DISABLED_WARNINGS_gcc_templateInterpreterGenerator_x86.cpp := unused-const-variable, \
DISABLED_WARNINGS_gcc_xGlobals_ppc.cpp := unused-const-variable, \
DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \
DISABLED_WARNINGS_clang_arguments.cpp := missing-field-initializers, \
DISABLED_WARNINGS_clang_codeBuffer.cpp := tautological-undefined-compare, \
DISABLED_WARNINGS_clang_directivesParser.cpp := missing-field-initializers, \
DISABLED_WARNINGS_clang_g1ParScanThreadState.cpp := delete-abstract-non-virtual-dtor, \
DISABLED_WARNINGS_clang_g1YoungGCPostEvacuateTasks.cpp := delete-abstract-non-virtual-dtor, \
DISABLED_WARNINGS_clang_management.cpp := missing-field-initializers, \
DISABLED_WARNINGS_clang_notificationThread.cpp := bitwise-instead-of-logical, \
DISABLED_WARNINGS_clang_os_posix.cpp := mismatched-tags missing-field-initializers, \
DISABLED_WARNINGS_clang_aix_os_posix.cpp := format-nonliteral, \
DISABLED_WARNINGS_clang_postaloc.cpp := tautological-undefined-compare, \
DISABLED_WARNINGS_clang_serviceThread.cpp := bitwise-instead-of-logical, \
DISABLED_WARNINGS_clang_vm_version_x86.cpp := missing-field-initializers, \
DISABLED_WARNINGS_clang_zTracer.cpp := undefined-var-template, \
DISABLED_WARNINGS_clang_aix_debug.cpp := format-nonliteral, \
DISABLED_WARNINGS_clang_aix_jvm.cpp := format-nonliteral, \
DISABLED_WARNINGS_clang_aix_osThread_aix.cpp := tautological-undefined-compare, \
DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \
ASFLAGS := $(JVM_ASFLAGS), \
LD_SET_ORIGIN := false, \
DEFAULT_LDFLAGS := false, \
LDFLAGS := $(JVM_LDFLAGS), \
LIBS := $(JVM_LIBS), \
OPTIMIZATION := $(JVM_OPTIMIZATION), \
OBJECT_DIR := $(JVM_OUTPUTDIR)/objs, \
STRIPFLAGS := $(JVM_STRIPFLAGS), \
EMBED_MANIFEST := true, \
RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
))
ifeq ($(call isTargetOs, windows), true)
# The following lines create a list of vftable symbols to be filtered out of
# the symbol file. Removing this line causes the linker to complain about too
# many (> 64K) symbols, so the _guess_ is that this line is here to keep down
# the number of exported symbols below that limit.
#
# Some usages of C++ lambdas require the vftable symbol of classes that use
# the lambda type as a template parameter. The usage of those classes won't
# link if their vftable symbols are removed. That's why there's an exception
# for vftable symbols containing the string 'lambda'.
#
# A very simple example of a lambda usage that fails if the lambda vftable
# symbols are missing in the symbol file:
#
# #include <functional>
# std::function<void()> f = [](){}
FILTER_SYMBOLS_AWK_SCRIPT := \
'{ \
if ($$7 ~ /\?\?_7.*@@6B@/ && $$7 !~ /type_info/ && $$7 !~ /lambda/) print " " $$7; \
}'
# A more correct solution would be to send BUILD_LIBJVM_ALL_OBJS instead of
# cd && *.obj, but this will result in very long command lines, which could be
# problematic.
$(WIN_EXPORT_FILE): $(BUILD_LIBJVM_ALL_OBJS)
$(call LogInfo, Generating list of symbols to export from object files)
$(call MakeDir, $(@D))
$(ECHO) "EXPORTS" > $@.tmp
$(CD) $(BUILD_LIBJVM_OBJECT_DIR) && \
$(DUMPBIN) -symbols *$(OBJ_SUFFIX) | $(AWK) $(FILTER_SYMBOLS_AWK_SCRIPT) | $(SORT) -u >> $@.tmp
$(RM) $@
$(MV) $@.tmp $@
$(BUILD_LIBJVM_TARGET): $(WIN_EXPORT_FILE)
endif
# Always recompile abstract_vm_version.cpp if libjvm needs to be relinked. This ensures
# that the internal vm version is updated as it relies on __DATE__ and __TIME__
# macros.
ABSTRACT_VM_VERSION_OBJ := $(JVM_OUTPUTDIR)/objs/abstract_vm_version$(OBJ_SUFFIX)
$(ABSTRACT_VM_VERSION_OBJ): $(filter-out $(ABSTRACT_VM_VERSION_OBJ), \
$(BUILD_LIBJVM_TARGET_DEPS))
ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
ifeq ($(call isTargetOs, windows), true)
# It doesn't matter which jvm.lib file gets exported, but we need
# to pick just one.
ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
$(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
DEST := $(LIB_OUTPUTDIR), \
FILES := $(BUILD_LIBJVM_IMPORT_LIBRARY), \
))
TARGETS += $(COPY_JVM_LIB)
endif
endif
endif
# AIX warning explanation:
# 1500-010 : (W) WARNING in ...: Infinite loop. Program may not stop.
# There are several infinite loops in the vm, so better suppress.
# 1540-0198 : (W) The omitted keyword "private" is assumed for base class "...".
# 1540-0216 : (W) An expression of type .. cannot be converted to type ..
# In hotspot this fires for functionpointer to pointer conversions
# 1540-1088 : (W) The exception specification is being ignored.
# In hotspot this is caused by throw() in declaration of new() in nmethod.hpp.
# 1540-1090 : (I) The destructor of "..." might not be called.
# 1540-1639 : (I) The behavior of long type bit fields has changed ...
TARGETS += $(BUILD_LIBJVM)
################################################################################
# Hotspot disallows the use of global operators 'new' and 'delete'. This build
# time check helps enforce this requirement. If you trigger this check and the
# reference is not obvious from the source, GNU objdump can be used to help find
# the reference if compiled with GCC:
#
# objdump -lrdSC <path/to/file.o>
#
# -C demangle
# -d disassemble
# -r print relocation entries, interspersed with the disassembly
# -S print source code, intermixed with disassembly
# -l include filenames and line numbers
#
# Search the output for the operator(s) of interest, to see where they are
# referenced.
#
# When a reference to the global 'operator delete' is reported, it might be
# due to a "deleting destructor". In this case, objdump may show the
# reference to be associated with but not actually in a destructor. A
# deleting destructor is automatically generated for a class whose destructor
# is virtual. A deleting destructor requires an accessible 'operator delete'
# for the associated class. If the class doesn't provide a more specific
# declaration (either directly or by inheriting from a class that provides
# one) then the global definition will be used, triggering this check.
ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang), )
DEMANGLED_REGEXP := [^:]operator (new|delete)
# Running c++filt to find offending symbols in all files is too expensive,
# so use mangled names when looking for symbols.
# Save the demangling for when something is actually found.
MANGLED_SYMS := \
_ZdaPv \
_ZdlPv \
_Znam \
_Znwm \
#
UNDEF_PATTERN := ' U '
define SetupOperatorNewDeleteCheck
$1.op_check: $1
$$(call ExecuteWithLog, $1.op_check, \
$$(NM) $$(NMFLAGS) $$< 2>&1 | $$(GREP) $$(addprefix -e , $$(MANGLED_SYMS)) | $$(GREP) $$(UNDEF_PATTERN) > $1.op_check || true)
if [ -s $1.op_check ]; then \
$$(ECHO) "$$(notdir $$<): Error: Use of global operators new and delete is not allowed in Hotspot:"; \
$$(NM) $$(NMFLAGS) $$< | $$(CXXFILT) | $$(EGREP) '$$(DEMANGLED_REGEXP)' | $$(GREP) $$(UNDEF_PATTERN); \
$$(ECHO) "See: $$(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
exit 1; \
fi
TARGETS += $1.op_check
endef
$(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
endif
endif