Sat, 24 Oct 2020 16:43:47 +0800
Merge
1 #
2 # Copyright (c) 1999, 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.
8 #
9 # This code is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # version 2 for more details (a copy is included in the LICENSE file that
13 # accompanied this code).
14 #
15 # You should have received a copy of the GNU General Public License version
16 # 2 along with this work; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 # or visit www.oracle.com if you need additional information or have any
21 # questions.
22 #
23 #
25 #
26 # This file has been modified by Loongson Technology in 2018. These
27 # modifications are Copyright (c) 2018 Loongson Technology, and are made
28 # available on the same license terms set forth above.
29 #
31 # Rules to build JVM and related libraries, included from vm.make in the build
32 # directory.
34 # Common build rules.
35 MAKEFILES_DIR=$(GAMMADIR)/make/$(Platform_os_family)/makefiles
36 include $(MAKEFILES_DIR)/rules.make
37 include $(GAMMADIR)/make/altsrc.make
39 default: build
41 #----------------------------------------------------------------------
42 # Defs
44 GENERATED = ../generated
45 DEP_DIR = $(GENERATED)/dependencies
47 # reads the generated files defining the set of .o's and the .o .h dependencies
48 -include $(DEP_DIR)/*.d
50 # read machine-specific adjustments (%%% should do this via buildtree.make?)
51 ifeq ($(findstring true, $(JVM_VARIANT_ZERO) $(JVM_VARIANT_ZEROSHARK)), true)
52 include $(MAKEFILES_DIR)/zeroshark.make
53 else
54 BUILDARCH_MAKE = $(MAKEFILES_DIR)/$(BUILDARCH).make
55 ALT_BUILDARCH_MAKE = $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/$(BUILDARCH).make
56 include $(if $(wildcard $(ALT_BUILDARCH_MAKE)),$(ALT_BUILDARCH_MAKE),$(BUILDARCH_MAKE))
57 endif
59 # set VPATH so make knows where to look for source files
60 # Src_Dirs_V is everything in src/share/vm/*, plus the right os/*/vm and cpu/*/vm
61 # The adfiles directory contains ad_<arch>.[ch]pp.
62 # The jvmtifiles directory contains jvmti*.[ch]pp
63 Src_Dirs_V += $(GENERATED)/adfiles $(GENERATED)/jvmtifiles $(GENERATED)/jfrfiles
64 VPATH += $(Src_Dirs_V:%=%:)
66 # set INCLUDES for C preprocessor.
67 Src_Dirs_I += $(GENERATED)
68 # The order is important for the precompiled headers to work.
69 INCLUDES += $(PRECOMPILED_HEADER_DIR:%=-I%) $(Src_Dirs_I:%=-I%)
71 # SYMFLAG is used by {jsig,saproc}.make
72 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
73 # always build with debug info when we can create .debuginfo files
74 SYMFLAG = -g
75 else
76 ifeq (${VERSION}, debug)
77 SYMFLAG = -g
78 else
79 SYMFLAG =
80 endif
81 endif
83 # HOTSPOT_RELEASE_VERSION and HOTSPOT_BUILD_VERSION are defined
84 # in $(GAMMADIR)/make/defs.make
85 ifeq ($(HOTSPOT_BUILD_VERSION),)
86 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)\""
87 else
88 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HOTSPOT_RELEASE_VERSION)-$(HOTSPOT_BUILD_VERSION)\""
89 endif
91 # The following variables are defined in the generated flags.make file.
92 BUILD_VERSION = -DHOTSPOT_RELEASE_VERSION="\"$(HS_BUILD_VER)\""
93 JRE_VERSION = -DJRE_RELEASE_VERSION="\"$(JRE_RELEASE_VER)\""
94 HS_LIB_ARCH = -DHOTSPOT_LIB_ARCH=\"$(LIBARCH)\"
95 BUILD_TARGET = -DHOTSPOT_BUILD_TARGET="\"$(TARGET)\""
96 BUILD_USER = -DHOTSPOT_BUILD_USER="\"$(HOTSPOT_BUILD_USER)\""
97 VM_DISTRO = -DHOTSPOT_VM_DISTRO="\"$(HOTSPOT_VM_DISTRO)\""
99 CXXFLAGS = \
100 ${SYSDEFS} \
101 ${INCLUDES} \
102 ${BUILD_VERSION} \
103 ${BUILD_TARGET} \
104 ${BUILD_USER} \
105 ${HS_LIB_ARCH} \
106 ${VM_DISTRO}
108 ifeq ($(MIPS_ABI),n32)
109 CXXFLAGS += -DN32
110 else
111 ifeq ($(MIPS_ABI),n64)
112 CXXFLAGS += -DN64
113 endif
114 endif
115 # This is VERY important! The version define must only be supplied to vm_version.o
116 # If not, ccache will not re-use the cache at all, since the version string might contain
117 # a time and date.
118 ifdef LOONGSON_RUNTIME_NAME
119 LOONGSON_VM_INFO = -DLOONGSON_RUNTIME_NAME="\"$(LOONGSON_RUNTIME_NAME)\""
120 else
121 LOONGSON_VM_INFO = -DLOONGSON_RUNTIME_NAME="\"\""
122 endif
123 CXXFLAGS/vmError.o += ${LOONGSON_VM_INFO}
124 CXXFLAGS/vm_version.o += ${JRE_VERSION} ${VERSION_CFLAGS}
125 CXXFLAGS/arguments.o += ${VERSION_CFLAGS}
127 CXXFLAGS/BYFILE = $(CXXFLAGS/$@)
129 # File specific flags
130 CXXFLAGS += $(CXXFLAGS/BYFILE)
132 # Large File Support
133 ifneq ($(LP64), 1)
134 CXXFLAGS/ostream.o += -D_FILE_OFFSET_BITS=64
135 endif # ifneq ($(LP64), 1)
137 # CFLAGS_WARN holds compiler options to suppress/enable warnings.
138 CFLAGS += $(CFLAGS_WARN/BYFILE)
140 # Do not use C++ exception handling
141 CFLAGS += $(CFLAGS/NOEX)
143 # Extra flags from gnumake's invocation or environment
144 CFLAGS += $(EXTRA_CFLAGS)
145 LFLAGS += $(EXTRA_CFLAGS) $(EXTRA_LDFLAGS)
146 ASFLAGS += $(EXTRA_ASFLAGS)
148 # Don't set excutable bit on stack segment
149 # the same could be done by separate execstack command
150 LFLAGS += -Xlinker -z -Xlinker noexecstack
152 LIBS += -lm -ldl -lpthread
154 # By default, link the *.o into the library, not the executable.
155 LINK_INTO$(LINK_INTO) = LIBJVM
157 JDK_LIBDIR = $(JAVA_HOME)/jre/lib/$(LIBARCH)
159 #----------------------------------------------------------------------
160 # jvm_db & dtrace
161 include $(MAKEFILES_DIR)/dtrace.make
163 #----------------------------------------------------------------------
164 # JVM
166 JVM = jvm
167 LIBJVM = lib$(JVM).so
169 LIBJVM_DEBUGINFO = lib$(JVM).debuginfo
170 LIBJVM_DIZ = lib$(JVM).diz
172 ifneq ($(ENABLE_JFR),true)
173 EXCLUDE_JFR_PATHS:= -o -name jfr -prune
174 endif
175 SPECIAL_PATHS:=adlc c1 gc_implementation opto shark libadt
177 SOURCE_PATHS=\
178 $(shell find $(HS_COMMON_SRC)/share/vm/* -type d \! \
179 \( -name DUMMY $(foreach dir,$(SPECIAL_PATHS),-o -name $(dir)) $(EXCLUDE_JFR_PATHS) \))
180 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/$(Platform_os_family)/vm
181 SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm
182 SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm
183 SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm
185 CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path))
186 CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/jfrfiles
188 COMPILER1_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/c1)
189 COMPILER1_PATHS += $(HS_COMMON_SRC)/share/vm/c1
191 COMPILER2_PATHS := $(call altsrc,$(HS_COMMON_SRC)/share/vm/opto)
192 COMPILER2_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/libadt)
193 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/opto
194 COMPILER2_PATHS += $(HS_COMMON_SRC)/share/vm/libadt
195 COMPILER2_PATHS += $(GENERATED)/adfiles
197 SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark
199 # Include dirs per type.
200 Src_Dirs/CORE := $(CORE_PATHS)
201 Src_Dirs/COMPILER1 := $(CORE_PATHS) $(COMPILER1_PATHS)
202 Src_Dirs/COMPILER2 := $(CORE_PATHS) $(COMPILER2_PATHS)
203 Src_Dirs/TIERED := $(CORE_PATHS) $(COMPILER1_PATHS) $(COMPILER2_PATHS)
204 Src_Dirs/ZERO := $(CORE_PATHS)
205 Src_Dirs/SHARK := $(CORE_PATHS) $(SHARK_PATHS)
206 Src_Dirs := $(Src_Dirs/$(TYPE))
208 COMPILER2_SPECIFIC_FILES := opto libadt bcEscapeAnalyzer.cpp c2_\* runtime_\*
209 COMPILER1_SPECIFIC_FILES := c1_\*
210 SHARK_SPECIFIC_FILES := shark
211 ZERO_SPECIFIC_FILES := zero
213 # Always exclude these.
214 Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp
216 # Exclude per type.
217 Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
218 Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
219 Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
220 Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES)
221 Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp
222 Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES)
224 Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE))
226 # Special handling of arch model.
227 ifeq ($(Platform_arch_model), x86_32)
228 Src_Files_EXCLUDE += \*x86_64\*
229 endif
230 ifeq ($(Platform_arch_model), x86_64)
231 Src_Files_EXCLUDE += \*x86_32\*
232 endif
233 ifeq ($(Platform_arch_model), mips_32)
234 Src_Files_EXCLUDE += \*mips_64\*
235 endif
236 ifeq ($(Platform_arch_model), mips_64)
237 Src_Files_EXCLUDE += \*mips_32\*
238 endif
240 # Alternate vm.make
241 # This has to be included here to allow changes to the source
242 # directories and excluded files before they are expanded
243 # by the definition of Src_Files.
244 -include $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/vm.make
246 # Locate all source files in the given directory, excluding files in Src_Files_EXCLUDE.
247 define findsrc
248 $(notdir $(shell find $(1)/. ! -name . -prune \
249 -a \( -name \*.c -o -name \*.cpp -o -name \*.s \) \
250 -a ! \( -name DUMMY $(addprefix -o -name ,$(Src_Files_EXCLUDE)) \)))
251 endef
253 Src_Files := $(foreach e,$(Src_Dirs),$(call findsrc,$(e)))
255 Obj_Files = $(sort $(addsuffix .o,$(basename $(Src_Files))))
257 JVM_OBJ_FILES = $(Obj_Files)
259 vm_version.o: $(filter-out vm_version.o,$(JVM_OBJ_FILES))
261 mapfile : $(MAPFILE) vm.def mapfile_ext
262 rm -f $@
263 awk '{ if ($$0 ~ "INSERT VTABLE SYMBOLS HERE") \
264 { system ("cat mapfile_ext"); system ("cat vm.def"); } \
265 else \
266 { print $$0 } \
267 }' > $@ < $(MAPFILE)
269 mapfile_reorder : mapfile $(REORDERFILE)
270 rm -f $@
271 cat $^ > $@
273 VMDEF_PAT = ^_ZTV
274 VMDEF_PAT := ^gHotSpotVM|$(VMDEF_PAT)
275 VMDEF_PAT := ^UseSharedSpaces$$|$(VMDEF_PAT)
276 VMDEF_PAT := ^_ZN9Arguments17SharedArchivePathE$$|$(VMDEF_PAT)
278 vm.def: $(Res_Files) $(Obj_Files)
279 $(QUIETLY) $(NM) --defined-only $(Obj_Files) | sort -k3 -u | \
280 awk '$$3 ~ /$(VMDEF_PAT)/ { print "\t" $$3 ";" }' > $@
282 mapfile_ext:
283 rm -f $@
284 touch $@
285 if [ -f $(HS_ALT_MAKE)/linux/makefiles/mapfile-ext ]; then \
286 cat $(HS_ALT_MAKE)/linux/makefiles/mapfile-ext > $@; \
287 fi
289 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
290 STATIC_CXX = false
291 else
292 ifeq ($(ZERO_LIBARCH), ppc64)
293 STATIC_CXX = false
294 else
295 STATIC_CXX = true
296 endif
297 endif
299 ifeq ($(LINK_INTO),AOUT)
300 LIBJVM.o =
301 LIBJVM_MAPFILE =
302 LIBS_VM = $(LIBS)
303 else
304 LIBJVM.o = $(JVM_OBJ_FILES)
305 LIBJVM_MAPFILE$(LDNOMAP) = mapfile_reorder
306 LFLAGS_VM$(LDNOMAP) += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
307 LFLAGS_VM += $(SONAMEFLAG:SONAME=$(LIBJVM))
309 # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
310 # get around library dependency and compatibility issues. Must use gcc not
311 # g++ to link.
312 ifeq ($(STATIC_CXX), true)
313 LFLAGS_VM += $(STATIC_LIBGCC)
314 LIBS_VM += $(STATIC_STDCXX)
315 else
316 LIBS_VM += -lstdc++
317 endif
319 LIBS_VM += $(LIBS)
320 endif
321 ifeq ($(JVM_VARIANT_ZERO), true)
322 LIBS_VM += $(LIBFFI_LIBS)
323 endif
324 ifeq ($(JVM_VARIANT_ZEROSHARK), true)
325 LIBS_VM += $(LIBFFI_LIBS) $(LLVM_LIBS)
326 LFLAGS_VM += $(LLVM_LDFLAGS)
327 endif
329 LINK_VM = $(LINK_LIB.CC)
331 # rule for building precompiled header
332 $(PRECOMPILED_HEADER):
333 $(QUIETLY) echo Generating precompiled header $@
334 $(QUIETLY) mkdir -p $(PRECOMPILED_HEADER_DIR)
335 $(QUIETLY) $(COMPILE.CXX) $(DEPFLAGS) -x c++-header $(PRECOMPILED_HEADER_SRC) -o $@ $(COMPILE_DONE)
337 # making the library:
339 ifneq ($(JVM_BASE_ADDR),)
340 # By default shared library is linked at base address == 0. Modify the
341 # linker script if JVM prefers a different base location. It can also be
342 # implemented with 'prelink -r'. But 'prelink' is not (yet) available on
343 # our build platform (AS-2.1).
344 LD_SCRIPT = libjvm.so.lds
345 $(LD_SCRIPT): $(LIBJVM_MAPFILE)
346 $(QUIETLY) { \
347 rm -rf $@; \
348 $(LINK_VM) -Wl,--verbose $(LFLAGS_VM) 2>&1 | \
349 sed -e '/^======/,/^======/!d' \
350 -e '/^======/d' \
351 -e 's/0\( + SIZEOF_HEADERS\)/$(JVM_BASE_ADDR)\1/' \
352 > $@; \
353 }
354 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
355 endif
357 # With more recent Redhat releases (or the cutting edge version Fedora), if
358 # SELinux is configured to be enabled, the runtime linker will fail to apply
359 # the text relocation to libjvm.so considering that it is built as a non-PIC
360 # DSO. To workaround that, we run chcon to libjvm.so after it is built. See
361 # details in bug 6538311.
362 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
363 $(QUIETLY) { \
364 echo Linking vm...; \
365 $(LINK_LIB.CXX/PRE_HOOK) \
366 $(LINK_VM) $(LD_SCRIPT_FLAG) \
367 $(LFLAGS_VM) -o $@ $(sort $(LIBJVM.o)) $(LIBS_VM); \
368 $(LINK_LIB.CXX/POST_HOOK) \
369 rm -f $@.1; ln -s $@ $@.1; \
370 if [ \"$(CROSS_COMPILE_ARCH)\" = \"\" ] ; then \
371 if [ -x /usr/sbin/selinuxenabled ] ; then \
372 /usr/sbin/selinuxenabled; \
373 if [ $$? = 0 ] ; then \
374 /usr/bin/chcon -t textrel_shlib_t $@; \
375 if [ $$? != 0 ]; then \
376 echo "ERROR: Cannot chcon $@"; \
377 fi \
378 fi \
379 fi \
380 fi \
381 }
383 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
384 ifneq ($(STRIP_POLICY),no_strip)
385 $(QUIETLY) $(OBJCOPY) --only-keep-debug $@ $(LIBJVM_DEBUGINFO)
386 $(QUIETLY) $(OBJCOPY) --add-gnu-debuglink=$(LIBJVM_DEBUGINFO) $@
387 endif
388 ifeq ($(STRIP_POLICY),all_strip)
389 $(QUIETLY) $(STRIP) $@
390 else
391 ifeq ($(STRIP_POLICY),min_strip)
392 $(QUIETLY) $(STRIP) -g $@
393 endif
394 # implied else here is no stripping at all
395 endif
396 ifneq ($(STRIP_POLICY),no_strip)
397 ifeq ($(ZIP_DEBUGINFO_FILES),1)
398 $(ZIPEXE) -q -y $(LIBJVM_DIZ) $(LIBJVM_DEBUGINFO)
399 $(RM) $(LIBJVM_DEBUGINFO)
400 endif
401 endif
402 endif
404 DEST_SUBDIR = $(JDK_LIBDIR)/$(VM_SUBDIR)
405 DEST_JVM = $(DEST_SUBDIR)/$(LIBJVM)
406 DEST_JVM_DEBUGINFO = $(DEST_SUBDIR)/$(LIBJVM_DEBUGINFO)
407 DEST_JVM_DIZ = $(DEST_SUBDIR)/$(LIBJVM_DIZ)
409 install_jvm: $(LIBJVM)
410 @echo "Copying $(LIBJVM) to $(DEST_JVM)"
411 $(QUIETLY) test -f $(LIBJVM_DEBUGINFO) && \
412 cp -f $(LIBJVM_DEBUGINFO) $(DEST_JVM_DEBUGINFO)
413 $(QUIETLY) test -f $(LIBJVM_DIZ) && \
414 cp -f $(LIBJVM_DIZ) $(DEST_JVM_DIZ)
415 $(QUIETLY) cp -f $(LIBJVM) $(DEST_JVM) && echo "Done"
417 #----------------------------------------------------------------------
418 # Other files
420 # Signal interposition library
421 include $(MAKEFILES_DIR)/jsig.make
423 # Serviceability agent
424 include $(MAKEFILES_DIR)/saproc.make
426 #----------------------------------------------------------------------
428 build: $(LIBJVM) $(LAUNCHER) $(LIBJSIG) $(LIBJVM_DB) $(BUILDLIBSAPROC) dtraceCheck
430 install: install_jvm install_jsig install_saproc
432 .PHONY: default build install install_jvm $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/$(BUILDARCH).make $(HS_ALT_MAKE)/$(Platform_os_family)/makefiles/vm.make