jdk

Форк
0
/
CompileJvm.gmk 
349 строк · 13.9 Кб
1
#
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.
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 CopyFiles.gmk
27

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
33

34
################################################################################
35
# Setup compilation of the main Hotspot native library (libjvm).
36

37
JVM_OUTPUTDIR := $(JVM_VARIANT_OUTPUTDIR)/libjvm
38

39
################################################################################
40
# Platform independent setup
41

42
JVM_LDFLAGS += \
43
    $(SHARED_LIBRARY_FLAGS) \
44
    $(JVM_LDFLAGS_FEATURES) \
45
    $(EXTRA_LDFLAGS) \
46
    #
47

48
JVM_ASFLAGS += $(EXTRA_ASFLAGS)
49

50
JVM_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) \
54
        #
55

56
JVM_LIBS += \
57
    $(JVM_LIBS_FEATURES) \
58
    #
59

60
# These files and directories are always excluded
61
JVM_EXCLUDE_FILES += args.cc
62
JVM_EXCLUDES += adlc
63

64
# Needed by abstract_vm_version.cpp
65
ifeq ($(call isTargetCpu, x86_64), true)
66
  OPENJDK_TARGET_CPU_VM_VERSION := amd64
67
else
68
  OPENJDK_TARGET_CPU_VM_VERSION := $(OPENJDK_TARGET_CPU)
69
endif
70

71
ifeq ($(VERSION_BUILD), )
72
  # Hotspot cannot handle an empty build number
73
  VERSION_BUILD := 0
74
endif
75

76
ifeq ($(HOTSPOT_BUILD_TIME), )
77
  HOTSPOT_BUILD_TIME := $(call EpochToISO8601, $(shell $(DATE) +"%s"))
78
endif
79

80
CFLAGS_VM_VERSION := \
81
    $(VERSION_CFLAGS) \
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)"' \
87
    #
88

89
################################################################################
90
# Disabled warnings
91

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
96

97
DISABLED_WARNINGS_clang := sometimes-uninitialized \
98
    missing-braces delete-non-abstract-non-virtual-dtor unknown-pragmas
99

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
105
endif
106

107
DISABLED_WARNINGS_microsoft := 4624 4244 4291 4146 4127 4722
108

109
################################################################################
110
# Platform specific setup
111

112
# ARM source selection
113

114
ifeq ($(call And, $(call isTargetOs, linux) $(call isTargetCpu, arm)), true)
115
  JVM_EXCLUDE_PATTERNS += arm_64
116

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
123
  endif
124
endif
125

126
ifeq ($(call isTargetOs, linux macosx windows), true)
127
  JVM_PRECOMPILED_HEADER := $(TOPDIR)/src/hotspot/share/precompiled/precompiled.hpp
128
endif
129

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
134
endif
135

136
JVM_OPTIMIZATION ?= HIGHEST_JVM
137

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
140
# default.
141
JVM_STRIPFLAGS ?= $(STRIPFLAGS)
142

143
# This source set is reused so save in cache.
144
$(call FillFindCache, $(JVM_SRC_DIRS))
145

146
ifeq ($(call isTargetOs, windows), true)
147
  ifeq ($(STATIC_LIBS), true)
148
    WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/static-win-exports.def
149
  else
150
    WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/win-exports.def
151
  endif
152

153
  JVM_LDFLAGS += -def:$(WIN_EXPORT_FILE)
154
endif
155

156
ifeq ($(call isTargetOs, linux), true)
157
  HOTSPOT_VERSION_SCRIPT := $(TOPDIR)/make/data/hotspot-symbols/version-script-$(TOOLCHAIN_TYPE).txt
158

159
  JVM_LDFLAGS += -Wl,-version-script=$(HOTSPOT_VERSION_SCRIPT)
160
endif
161

162
################################################################################
163
## Build libjvm
164
################################################################################
165

166
$(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
167
    NAME := jvm, \
168
    LINK_TYPE := C++, \
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), \
219
))
220

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.
226
  #
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'.
231
  #
232
  # A very simple example of a lambda usage that fails if the lambda vftable
233
  # symbols are missing in the symbol file:
234
  #
235
  # #include <functional>
236
  # std::function<void()> f = [](){}
237
  FILTER_SYMBOLS_AWK_SCRIPT := \
238
      '{ \
239
        if ($$7 ~ /\?\?_7.*@@6B@/ && $$7 !~ /type_info/ && $$7 !~ /lambda/) print "  " $$7; \
240
      }'
241

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
244
  # problematic.
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
251
	$(RM) $@
252
	$(MV) $@.tmp $@
253

254
  $(BUILD_LIBJVM_TARGET): $(WIN_EXPORT_FILE)
255
endif
256

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__
259
# macros.
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))
263

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
267
    # to pick just one.
268
    ifeq ($(JVM_VARIANT), $(JVM_VARIANT_MAIN))
269
      $(eval $(call SetupCopyFiles, COPY_JVM_LIB, \
270
          DEST := $(LIB_OUTPUTDIR), \
271
          FILES :=$(BUILD_LIBJVM_IMPORT_LIBRARY), \
272
      ))
273
      TARGETS += $(COPY_JVM_LIB)
274
    endif
275
  endif
276
endif
277

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 ...
288

289
TARGETS += $(BUILD_LIBJVM)
290

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:
296
#
297
# objdump -lrdSC <path/to/file.o>
298
#
299
# -C demangle
300
# -d disassemble
301
# -r print relocation entries, interspersed with the disassembly
302
# -S print source code, intermixed with disassembly
303
# -l include filenames and line numbers
304
#
305
# Search the output for the operator(s) of interest, to see where they are
306
# referenced.
307
#
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.
316

317
ifneq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
318
  ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang), )
319

320
    DEMANGLED_REGEXP := [^:]operator (new|delete)
321

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.
325
    MANGLED_SYMS := \
326
        _ZdaPv \
327
        _ZdlPv \
328
        _Znam \
329
        _Znwm \
330
        #
331
    UNDEF_PATTERN := ' U '
332

333
    define SetupOperatorNewDeleteCheck
334
        $1.op_check: $1
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"; \
341
	    exit 1; \
342
	  fi
343

344
      TARGETS += $1.op_check
345
    endef
346

347
    $(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
348
  endif
349
endif
350

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.