2
# Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
28
# Include support files that will setup compiler flags due to the selected
29
# jvm feature set, specific file overrides, and general flags.
30
include lib/JvmFeatures.gmk
31
include lib/JvmOverrideFiles.gmk
32
include lib/JvmFlags.gmk
34
################################################################################
35
# Setup compilation of the main Hotspot native library (libjvm).
37
JVM_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm
39
################################################################################
40
# Platform independent setup
43
$(SHARED_LIBRARY_FLAGS) \
44
$(JVM_LDFLAGS_FEATURES) \
48
JVM_ASFLAGS += $(EXTRA_ASFLAGS)
51
-I$(TOPDIR)/src/hotspot/os_cpu/$(HOTSPOT_TARGET_OS)_$(HOTSPOT_TARGET_CPU_ARCH) \
52
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS) \
53
-I$(TOPDIR)/src/hotspot/os/$(HOTSPOT_TARGET_OS_TYPE) \
57
$(JVM_LIBS_FEATURES) \
60
# These files and directories are always excluded
61
JVM_EXCLUDE_FILES += args.cc
64
# Needed by abstract_vm_version.cpp
65
ifeq ($(call isTargetCpu, x86_64), true)
66
OPENJDK_TARGET_CPU_VM_VERSION := amd64
68
OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
71
ifeq ($(VERSION_BUILD), )
72
# Hotspot cannot handle an empty build number
76
ifeq ($(HOTSPOT_BUILD_TIME), )
77
HOTSPOT_BUILD_TIME := $(call EpochToISO8601, $(shell $(DATE) +"%s"))
82
-DHOTSPOT_VERSION_STRING='"$(VERSION_STRING)"' \
83
-DDEBUG_LEVEL='"$(DEBUG_LEVEL)"' \
84
-DHOTSPOT_VM_DISTRO='"$(HOTSPOT_VM_DISTRO)"' \
85
-DCPU='"$(OPENJDK_TARGET_CPU_VM_VERSION)"' \
86
-DHOTSPOT_BUILD_TIME='"$(HOTSPOT_BUILD_TIME)"' \
89
################################################################################
92
DISABLED_WARNINGS_gcc := array-bounds comment delete-non-virtual-dtor \
93
empty-body implicit-fallthrough int-in-bool-context \
94
maybe-uninitialized missing-field-initializers \
95
shift-negative-value unknown-pragmas
97
DISABLED_WARNINGS_clang := sometimes-uninitialized \
98
missing-braces delete-non-abstract-non-virtual-dtor unknown-pragmas
100
ifneq ($(DEBUG_LEVEL), release)
101
# Assert macro gives warning
102
DISABLED_WARNINGS_clang += tautological-constant-out-of-range-compare
103
# Some reasonable asserts produce warnings on GCC <= 7
104
DISABLED_WARNINGS_gcc += strict-overflow
107
DISABLED_WARNINGS_microsoft := 4624 4244 4291 4146 4127 4722
109
################################################################################
110
# Platform specific setup
112
# ARM source selection
114
ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, arm)), true)
115
JVM_EXCLUDE_PATTERNS += arm_64
117
else ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, aarch64)), true)
118
# For 64-bit arm builds, we use the 64 bit hotspot/src/cpu/arm
119
# hotspot sources if HOTSPOT_TARGET_CPU_ARCH is set to arm.
120
# Exclude the aarch64 and 32 bit arm files for this build.
121
ifeq ($(HOTSPOT_TARGET_CPU_ARCH), arm)
122
JVM_EXCLUDE_PATTERNS += arm_32 aarch64
126
ifeq ($(call isTargetOs, linux macosx windows), true)
127
JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
130
ifeq ($(call isTargetCpu, x86), true)
131
JVM_EXCLUDE_PATTERNS += x86_64
132
else ifeq ($(call isTargetCpu, x86_64), true)
133
JVM_EXCLUDE_PATTERNS += x86_32
136
JVM_OPTIMIZATION ?= HIGHEST_JVM
138
# Need to set JVM_STRIPFLAGS to the default value from SPEC since the STRIPFLAGS
139
# parameter to SetupJdkLibrary allows an empty value to override the
141
JVM_STRIPFLAGS ?= $(STRIPFLAGS)
143
# This source set is reused so save in cache.
144
$(call FillFindCache, $(JVM_SRC_DIRS))
146
ifeq ($(call isTargetOs, windows), true)
147
ifeq ($(STATIC_LIBS), true)
148
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/static-win-exports.def
150
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/win-exports.def
153
JVM_LDFLAGS += -def:$(WIN_EXPORT_FILE)
156
ifeq ($(call isTargetOs, linux), true)
157
HOTSPOT_VERSION_SCRIPT := $(TOPDIR)/make/data/hotspot-symbols/version-script-$(TOOLCHAIN_TYPE).txt
159
JVM_LDFLAGS += -Wl,-version-script=$(HOTSPOT_VERSION_SCRIPT)
162
################################################################################
164
################################################################################
166
$(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
169
OUTPUT_DIR := $(JVM_LIB_OUTPUTDIR), \
170
SRC := $(JVM_SRC_DIRS), \
171
EXCLUDES := $(JVM_EXCLUDES), \
172
EXCLUDE_FILES := $(JVM_EXCLUDE_FILES), \
173
EXCLUDE_PATTERNS := $(JVM_EXCLUDE_PATTERNS), \
174
DEFAULT_CFLAGS := false, \
175
CFLAGS := $(JVM_CFLAGS), \
176
abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
177
arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
178
DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \
179
DISABLED_WARNINGS_gcc_ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp := nonnull, \
180
DISABLED_WARNINGS_gcc_cgroupV1Subsystem_linux.cpp := address, \
181
DISABLED_WARNINGS_gcc_cgroupV2Subsystem_linux.cpp := address, \
182
DISABLED_WARNINGS_gcc_handshake.cpp := stringop-overflow, \
183
DISABLED_WARNINGS_gcc_interp_masm_x86.cpp := uninitialized, \
184
DISABLED_WARNINGS_gcc_jvmciCodeInstaller.cpp := stringop-overflow, \
185
DISABLED_WARNINGS_gcc_jvmtiTagMap.cpp := stringop-overflow, \
186
DISABLED_WARNINGS_gcc_postaloc.cpp := address, \
187
DISABLED_WARNINGS_gcc_shenandoahLock.cpp := stringop-overflow, \
188
DISABLED_WARNINGS_gcc_synchronizer.cpp := stringop-overflow, \
189
DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \
190
DISABLED_WARNINGS_clang_arguments.cpp := missing-field-initializers, \
191
DISABLED_WARNINGS_clang_codeBuffer.cpp := tautological-undefined-compare, \
192
DISABLED_WARNINGS_clang_directivesParser.cpp := missing-field-initializers, \
193
DISABLED_WARNINGS_clang_g1ParScanThreadState.cpp := delete-abstract-non-virtual-dtor, \
194
DISABLED_WARNINGS_clang_g1YoungGCPostEvacuateTasks.cpp := delete-abstract-non-virtual-dtor, \
195
DISABLED_WARNINGS_clang_management.cpp := missing-field-initializers, \
196
DISABLED_WARNINGS_clang_notificationThread.cpp := bitwise-instead-of-logical, \
197
DISABLED_WARNINGS_clang_os_posix.cpp := mismatched-tags missing-field-initializers, \
198
DISABLED_WARNINGS_clang_aix_os_posix.cpp := format-nonliteral, \
199
DISABLED_WARNINGS_clang_postaloc.cpp := tautological-undefined-compare, \
200
DISABLED_WARNINGS_clang_serviceThread.cpp := bitwise-instead-of-logical, \
201
DISABLED_WARNINGS_clang_vm_version_x86.cpp := missing-field-initializers, \
202
DISABLED_WARNINGS_clang_zTracer.cpp := undefined-var-template, \
203
DISABLED_WARNINGS_clang_aix_debug.cpp := format-nonliteral, \
204
DISABLED_WARNINGS_clang_aix_jvm.cpp := format-nonliteral, \
205
DISABLED_WARNINGS_clang_aix_osThread_aix.cpp := tautological-undefined-compare, \
206
DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \
207
ASFLAGS := $(JVM_ASFLAGS), \
208
LD_SET_ORIGIN := false, \
209
DEFAULT_LDFLAGS := false, \
210
LDFLAGS := $(JVM_LDFLAGS), \
211
LIBS := $(JVM_LIBS), \
212
OPTIMIZATION := $(JVM_OPTIMIZATION), \
213
OBJECT_DIR := $(JVM_OUTPUTDIR)/objs, \
214
STRIPFLAGS := $(JVM_STRIPFLAGS), \
215
EMBED_MANIFEST := true, \
216
RC_FILEDESC := $(HOTSPOT_VM_DISTRO) $(OPENJDK_TARGET_CPU_BITS)-Bit $(JVM_VARIANT) VM, \
217
PRECOMPILED_HEADER := $(JVM_PRECOMPILED_HEADER), \
218
PRECOMPILED_HEADER_EXCLUDE := $(JVM_PRECOMPILED_HEADER_EXCLUDE), \
221
ifeq ($(call isTargetOs, windows), true)
222
# The following lines create a list of vftable symbols to be filtered out of
223
# the symbol file. Removing this line causes the linker to complain about too
224
# many (> 64K) symbols, so the _guess_ is that this line is here to keep down
225
# the number of exported symbols below that limit.
227
# Some usages of C++ lambdas require the vftable symbol of classes that use
228
# the lambda type as a template parameter. The usage of those classes won't
229
# link if their vftable symbols are removed. That's why there's an exception
230
# for vftable symbols containing the string 'lambda'.
232
# A very simple example of a lambda usage that fails if the lambda vftable
233
# symbols are missing in the symbol file:
235
# #include <functional>
236
# std::function<void()> f = [](){}
237
FILTER_SYMBOLS_AWK_SCRIPT := \
239
if ($$7 ~ /\?\?_7.*@@6B@/ && $$7 !~ /type_info/ && $$7 !~ /lambda/) print " " $$7; \
242
# A more correct solution would be to send BUILD_LIBJVM_ALL_OBJS instead of
243
# cd && *.obj, but this will result in very long command lines, which could be
245
$(WIN_EXPORT_FILE): $(BUILD_LIBJVM_ALL_OBJS)
246
$(call LogInfo, Generating list of symbols to export from object files)
247
$(call MakeDir, $(@D))
248
$(ECHO) "EXPORTS" > $@.tmp
249
$(CD) $(BUILD_LIBJVM_OBJECT_DIR) && \
250
$(DUMPBIN) -symbols *$(OBJ_SUFFIX) | $(AWK) $(FILTER_SYMBOLS_AWK_SCRIPT) | $(SORT) -u >> $@.tmp
254
$(BUILD_LIBJVM_TARGET): $(WIN_EXPORT_FILE)
257
# Always recompile abstract_vm_version.cpp if libjvm needs to be relinked. This ensures
258
# that the internal vm version is updated as it relies on __DATE__ and __TIME__
260
ABSTRACT_VM_VERSION_OBJ := $(JVM_OUTPUTDIR)/objs/abstract_vm_version$(OBJ_SUFFIX)
261
$(ABSTRACT_VM_VERSION_OBJ): $(filter-out $(ABSTRACT_VM_VERSION_OBJ), \
262
$(BUILD_LIBJVM_TARGET_DEPS))
264
ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
265
ifeq ($(call isTargetOs, windows), true)
266
# It doesn't matter which jvm.lib file gets exported, but we need
268
ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
269
$(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
270
DEST := $(LIB_OUTPUTDIR), \
271
FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
273
TARGETS += $(COPY_JVM_LIB)
278
# AIX warning explanation:
279
# 1500-010 : (W) WARNING in ...: Infinite loop. Program may not stop.
280
# There are several infinite loops in the vm, so better suppress.
281
# 1540-0198 : (W) The omitted keyword "private" is assumed for base class "...".
282
# 1540-0216 : (W) An expression of type .. cannot be converted to type ..
283
# In hotspot this fires for functionpointer to pointer conversions
284
# 1540-1088 : (W) The exception specification is being ignored.
285
# In hotspot this is caused by throw() in declaration of new() in nmethod.hpp.
286
# 1540-1090 : (I) The destructor of "..." might not be called.
287
# 1540-1639 : (I) The behavior of long type bit fields has changed ...
289
TARGETS += $(BUILD_LIBJVM)
291
################################################################################
292
# Hotspot disallows the use of global operators 'new' and 'delete'. This build
293
# time check helps enforce this requirement. If you trigger this check and the
294
# reference is not obvious from the source, GNU objdump can be used to help find
295
# the reference if compiled with GCC:
297
# objdump -lrdSC <path/to/file.o>
301
# -r print relocation entries, interspersed with the disassembly
302
# -S print source code, intermixed with disassembly
303
# -l include filenames and line numbers
305
# Search the output for the operator(s) of interest, to see where they are
308
# When a reference to the global 'operator delete' is reported, it might be
309
# due to a "deleting destructor". In this case, objdump may show the
310
# reference to be associated with but not actually in a destructor. A
311
# deleting destructor is automatically generated for a class whose destructor
312
# is virtual. A deleting destructor requires an accessible 'operator delete'
313
# for the associated class. If the class doesn't provide a more specific
314
# declaration (either directly or by inheriting from a class that provides
315
# one) then the global definition will be used, triggering this check.
317
ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
318
ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang), )
320
DEMANGLED_REGEXP := [^:]operator (new|delete)
322
# Running c++filt to find offending symbols in all files is too expensive,
323
# so use mangled names when looking for symbols.
324
# Save the demangling for when something is actually found.
331
UNDEF_PATTERN := ' U '
333
define SetupOperatorNewDeleteCheck
335
$$(call ExecuteWithLog, $1.op_check, \
336
$$(NM) $$(NMFLAGS) $$< 2>&1 | $$(GREP) $$(addprefix -e , $$(MANGLED_SYMS)) | $$(GREP) $$(UNDEF_PATTERN) > $1.op_check || true)
337
if [ -s $1.op_check ]; then \
338
$$(ECHO) "$$(notdir $$<): Error: Use of global operators new and delete is not allowed in Hotspot:"; \
339
$$(NM) $$(NMFLAGS) $$< | $$(CXXFILT) | $$(EGREP) '$$(DEMANGLED_REGEXP)' | $$(GREP) $$(UNDEF_PATTERN); \
340
$$(ECHO) "See: $$(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
344
TARGETS += $1.op_check
347
$(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))