Skip to content

Commit b6c35ae

Browse files
committedMar 2, 2022
8209784: Include hsdis in the JDK
Reviewed-by: erikj
1 parent ce18ff8 commit b6c35ae

File tree

8 files changed

+400
-290
lines changed

8 files changed

+400
-290
lines changed
 

‎make/Hsdis.gmk

+31-18
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,13 @@ include JdkNativeCompilation.gmk
3535
################################################################################
3636

3737
HSDIS_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/hsdis
38+
REAL_HSDIS_NAME := hsdis-$(OPENJDK_TARGET_CPU_LEGACY_LIB)$(SHARED_LIBRARY_SUFFIX)
39+
BUILT_HSDIS_LIB := $(HSDIS_OUTPUT_DIR)/$(REAL_HSDIS_NAME)
3840

3941
HSDIS_TOOLCHAIN := TOOLCHAIN_DEFAULT
4042
HSDIS_TOOLCHAIN_CFLAGS := $(CFLAGS_JDKLIB)
4143
HSDIS_TOOLCHAIN_LDFLAGS := $(LDFLAGS_JDKLIB)
4244

43-
ifeq ($(call isTargetOs, windows), true)
44-
INSTALLED_HSDIS_DIR := $(JDK_OUTPUTDIR)/bin
45-
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/bin
46-
else
47-
INSTALLED_HSDIS_DIR := $(JDK_OUTPUTDIR)/lib
48-
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/lib
49-
endif
50-
5145
ifeq ($(HSDIS_BACKEND), capstone)
5246
ifeq ($(call isTargetCpuArch, x86), true)
5347
CAPSTONE_ARCH := CS_ARCH_X86
@@ -162,25 +156,44 @@ $(eval $(call SetupJdkLibrary, BUILD_HSDIS, \
162156
LIBS := $(HSDIS_LIBS) $(HSDIS_TOOLCHAIN_LIBS), \
163157
))
164158

165-
build: $(BUILD_HSDIS)
159+
$(BUILT_HSDIS_LIB): $(BUILD_HSDIS_TARGET)
160+
$(install-file)
161+
162+
build: $(BUILD_HSDIS) $(BUILT_HSDIS_LIB)
166163

167164
TARGETS += build
168165

169-
INSTALLED_HSDIS_NAME := hsdis-$(OPENJDK_TARGET_CPU_LEGACY_LIB)$(SHARED_LIBRARY_SUFFIX)
166+
ifeq ($(ENABLE_HSDIS_BUNDLING), false)
170167

171-
INSTALLED_HSDIS := $(INSTALLED_HSDIS_DIR)/$(INSTALLED_HSDIS_NAME)
172-
INSTALLED_HSDIS_IMAGE := $(IMAGE_HSDIS_DIR)/$(INSTALLED_HSDIS_NAME)
168+
ifeq ($(call isTargetOs, windows), true)
169+
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/bin
170+
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/bin
171+
else
172+
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/lib
173+
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/lib
174+
endif
173175

174-
$(INSTALLED_HSDIS): $(BUILD_HSDIS_TARGET)
175-
ifeq ($(HSDIS_BACKEND), binutils)
176-
$(call LogWarn, NOTE: The resulting build might not be redistributable. Seek legal advice before distributing.)
177-
endif
176+
177+
INSTALLED_HSDIS_JDK := $(JDK_HSDIS_DIR)/$(REAL_HSDIS_NAME)
178+
INSTALLED_HSDIS_IMAGE := $(IMAGE_HSDIS_DIR)/$(REAL_HSDIS_NAME)
179+
180+
$(INSTALLED_HSDIS_JDK): $(BUILT_HSDIS_LIB)
181+
ifeq ($(HSDIS_BACKEND), binutils)
182+
$(call LogWarn, NOTE: The resulting build might not be redistributable. Seek legal advice before distributing.)
183+
endif
178184
$(install-file)
179185

180-
$(INSTALLED_HSDIS_IMAGE): $(INSTALLED_HSDIS)
186+
$(INSTALLED_HSDIS_IMAGE): $(BUILT_HSDIS_LIB)
181187
$(install-file)
182188

183-
install: $(INSTALLED_HSDIS_IMAGE)
189+
install: $(INSTALLED_HSDIS_JDK) $(INSTALLED_HSDIS_IMAGE)
190+
191+
else
192+
193+
install:
194+
$(ECHO) NOTE: make install-hsdis is a no-op with --enable-hsdis-bundling
195+
196+
endif
184197

185198
TARGETS += install
186199

‎make/Main.gmk

+5
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ ifneq ($(HSDIS_BACKEND), none)
535535
$(eval $(call SetupTarget, install-hsdis, \
536536
MAKEFILE := Hsdis, \
537537
TARGET := install, \
538+
DEPS := jdk-image, \
538539
))
539540
endif
540541

@@ -861,6 +862,10 @@ else
861862
$(foreach t, $(filter-out java.base-libs, $(LIBS_TARGETS)), \
862863
$(eval $t: java.base-libs))
863864

865+
ifeq ($(ENABLE_HSDIS_BUNDLING), true)
866+
java.base-copy: build-hsdis
867+
endif
868+
864869
# jdk.accessibility depends on java.desktop
865870
jdk.accessibility-libs: java.desktop-libs
866871

‎make/autoconf/configure.ac

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -249,7 +249,6 @@ JDKOPT_EXCLUDE_TRANSLATIONS
249249
JDKOPT_ENABLE_DISABLE_MANPAGES
250250
JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE
251251
JDKOPT_ENABLE_DISABLE_COMPATIBLE_CDS_ALIGNMENT
252-
JDKOPT_SETUP_HSDIS
253252

254253
###############################################################################
255254
#

‎make/autoconf/jdk-options.m4

-266
Original file line numberDiff line numberDiff line change
@@ -727,269 +727,3 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_REPRODUCIBLE_BUILD],
727727
AC_SUBST(SOURCE_DATE)
728728
AC_SUBST(ENABLE_REPRODUCIBLE_BUILD)
729729
])
730-
731-
################################################################################
732-
#
733-
# Helper function to build binutils from source.
734-
#
735-
AC_DEFUN([JDKOPT_BUILD_BINUTILS],
736-
[
737-
BINUTILS_SRC="$with_binutils_src"
738-
UTIL_FIXUP_PATH(BINUTILS_SRC)
739-
740-
if ! test -d $BINUTILS_SRC; then
741-
AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
742-
fi
743-
if ! test -x $BINUTILS_SRC/configure; then
744-
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
745-
fi
746-
747-
if test -e $BINUTILS_SRC/bfd/libbfd.a && \
748-
test -e $BINUTILS_SRC/opcodes/libopcodes.a && \
749-
test -e $BINUTILS_SRC/libiberty/libiberty.a && \
750-
test -e $BINUTILS_SRC/zlib/libz.a; then
751-
AC_MSG_NOTICE([Found binutils binaries in binutils source directory -- not building])
752-
else
753-
# On Windows, we cannot build with the normal Microsoft CL, but must instead use
754-
# a separate mingw toolchain.
755-
if test "x$OPENJDK_BUILD_OS" = xwindows; then
756-
if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
757-
target_base="i686-w64-mingw32"
758-
else
759-
target_base="$OPENJDK_TARGET_CPU-w64-mingw32"
760-
fi
761-
binutils_cc="$target_base-gcc"
762-
binutils_target="--host=$target_base --target=$target_base"
763-
# Somehow the uint typedef is not included when building with mingw
764-
binutils_cflags="-Duint=unsigned"
765-
compiler_version=`$binutils_cc --version 2>&1`
766-
if ! [ [[ "$compiler_version" =~ GCC ]] ]; then
767-
AC_MSG_NOTICE([Could not find correct mingw compiler $binutils_cc.])
768-
HELP_MSG_MISSING_DEPENDENCY([$binutils_cc])
769-
AC_MSG_ERROR([Cannot continue. $HELP_MSG])
770-
else
771-
AC_MSG_NOTICE([Using compiler $binutils_cc with version $compiler_version])
772-
fi
773-
elif test "x$OPENJDK_BUILD_OS" = xmacosx; then
774-
if test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
775-
binutils_target="--enable-targets=aarch64-darwin"
776-
else
777-
binutils_target=""
778-
fi
779-
else
780-
binutils_cc="$CC $SYSROOT_CFLAGS"
781-
binutils_target=""
782-
fi
783-
binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
784-
785-
AC_MSG_NOTICE([Running binutils configure])
786-
AC_MSG_NOTICE([configure command line: ./configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" $binutils_target])
787-
saved_dir=`pwd`
788-
cd "$BINUTILS_SRC"
789-
./configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" $binutils_target
790-
if test $? -ne 0 || ! test -e $BINUTILS_SRC/Makefile; then
791-
AC_MSG_NOTICE([Automatic building of binutils failed on configure. Try building it manually])
792-
AC_MSG_ERROR([Cannot continue])
793-
fi
794-
AC_MSG_NOTICE([Running binutils make])
795-
$MAKE all-opcodes
796-
if test $? -ne 0; then
797-
AC_MSG_NOTICE([Automatic building of binutils failed on make. Try building it manually])
798-
AC_MSG_ERROR([Cannot continue])
799-
fi
800-
cd $saved_dir
801-
AC_MSG_NOTICE([Building of binutils done])
802-
fi
803-
804-
BINUTILS_DIR="$BINUTILS_SRC"
805-
])
806-
807-
################################################################################
808-
#
809-
# Determine if hsdis should be built, and if so, with which backend.
810-
#
811-
AC_DEFUN_ONCE([JDKOPT_SETUP_HSDIS],
812-
[
813-
AC_ARG_WITH([hsdis], [AS_HELP_STRING([--with-hsdis],
814-
[what hsdis backend to use ('none', 'capstone', 'llvm', 'binutils') @<:@none@:>@])])
815-
816-
AC_ARG_WITH(capstone, [AS_HELP_STRING([--with-capstone],
817-
[where to find the Capstone files needed for hsdis/capstone])])
818-
819-
AC_ARG_WITH([llvm], [AS_HELP_STRING([--with-llvm],
820-
[where to find the LLVM files needed for hsdis/llvm])])
821-
822-
AC_ARG_WITH([binutils], [AS_HELP_STRING([--with-binutils],
823-
[where to find the binutils files needed for hsdis/binutils])])
824-
825-
AC_ARG_WITH([binutils-src], [AS_HELP_STRING([--with-binutils-src],
826-
[where to find the binutils source for building])])
827-
828-
AC_MSG_CHECKING([what hsdis backend to use])
829-
830-
if test "x$with_hsdis" = xyes; then
831-
AC_MSG_ERROR([--with-hsdis must have a value])
832-
elif test "x$with_hsdis" = xnone || test "x$with_hsdis" = xno || test "x$with_hsdis" = x; then
833-
HSDIS_BACKEND=none
834-
AC_MSG_RESULT(['none', hsdis will not be built])
835-
elif test "x$with_hsdis" = xcapstone; then
836-
HSDIS_BACKEND=capstone
837-
AC_MSG_RESULT(['capstone'])
838-
839-
if test "x$with_capstone" != x; then
840-
AC_MSG_CHECKING([for capstone])
841-
CAPSTONE="$with_capstone"
842-
AC_MSG_RESULT([$CAPSTONE])
843-
844-
HSDIS_CFLAGS="-I${CAPSTONE}/include/capstone"
845-
if test "x$OPENJDK_TARGET_OS" != xwindows; then
846-
HSDIS_LDFLAGS="-L${CAPSTONE}/lib"
847-
HSDIS_LIBS="-lcapstone"
848-
else
849-
HSDIS_LDFLAGS="-nodefaultlib:libcmt.lib"
850-
HSDIS_LIBS="${CAPSTONE}/capstone.lib"
851-
fi
852-
else
853-
if test "x$OPENJDK_TARGET_OS" = xwindows; then
854-
# There is no way to auto-detect capstone on Windowos
855-
AC_MSG_NOTICE([You must specify capstone location using --with-capstone=<path>])
856-
AC_MSG_ERROR([Cannot continue])
857-
fi
858-
859-
PKG_CHECK_MODULES(CAPSTONE, capstone, [CAPSTONE_FOUND=yes], [CAPSTONE_FOUND=no])
860-
if test "x$CAPSTONE_FOUND" = xyes; then
861-
HSDIS_CFLAGS="$CAPSTONE_CFLAGS"
862-
HSDIS_LDFLAGS="$CAPSTONE_LDFLAGS"
863-
HSDIS_LIBS="$CAPSTONE_LIBS"
864-
else
865-
HELP_MSG_MISSING_DEPENDENCY([capstone])
866-
AC_MSG_NOTICE([Cannot locate capstone which is needed for hsdis/capstone. Try using --with-capstone=<path>. $HELP_MSG])
867-
AC_MSG_ERROR([Cannot continue])
868-
fi
869-
fi
870-
elif test "x$with_hsdis" = xllvm; then
871-
HSDIS_BACKEND=llvm
872-
AC_MSG_RESULT(['llvm'])
873-
874-
if test "x$with_llvm" != x; then
875-
LLVM_DIR="$with_llvm"
876-
fi
877-
878-
if test "x$OPENJDK_TARGET_OS" != xwindows; then
879-
if test "x$LLVM_DIR" = x; then
880-
# Macs with homebrew can have llvm in different places
881-
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$PATH:/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin])
882-
if test "x$LLVM_CONFIG" = x; then
883-
AC_MSG_NOTICE([Cannot locate llvm-config which is needed for hsdis/llvm. Try using --with-llvm=<LLVM home>.])
884-
AC_MSG_ERROR([Cannot continue])
885-
fi
886-
else
887-
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$LLVM_DIR/bin])
888-
if test "x$LLVM_CONFIG" = x; then
889-
AC_MSG_NOTICE([Cannot locate llvm-config in $LLVM_DIR. Check your --with-llvm argument.])
890-
AC_MSG_ERROR([Cannot continue])
891-
fi
892-
fi
893-
894-
# We need the LLVM flags and libs, and llvm-config provides them for us.
895-
HSDIS_CFLAGS=`$LLVM_CONFIG --cflags`
896-
HSDIS_LDFLAGS=`$LLVM_CONFIG --ldflags`
897-
HSDIS_LIBS=`$LLVM_CONFIG --libs $OPENJDK_TARGET_CPU_ARCH ${OPENJDK_TARGET_CPU_ARCH}disassembler`
898-
else
899-
if test "x$LLVM_DIR" = x; then
900-
AC_MSG_NOTICE([--with-llvm is needed on Windows to point out the LLVM home])
901-
AC_MSG_ERROR([Cannot continue])
902-
fi
903-
904-
# Official Windows installation of LLVM do not ship llvm-config, and self-built llvm-config
905-
# produced unusable output, so just ignore it on Windows.
906-
if ! test -e $LLVM_DIR/include/llvm-c/lto.h; then
907-
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; include dir is missing])
908-
AC_MSG_ERROR([Cannot continue])
909-
fi
910-
if ! test -e $LLVM_DIR/include/llvm-c/Disassembler.h; then
911-
AC_MSG_NOTICE([$LLVM_DIR does not point to a complete LLVM installation. ])
912-
AC_MSG_NOTICE([The official LLVM distribution is missing crucical files; you need to build LLVM yourself or get all include files elsewhere])
913-
AC_MSG_ERROR([Cannot continue])
914-
fi
915-
if ! test -e $LLVM_DIR/lib/llvm-c.lib; then
916-
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; lib dir is missing])
917-
AC_MSG_ERROR([Cannot continue])
918-
fi
919-
HSDIS_CFLAGS="-I$LLVM_DIR/include"
920-
HSDIS_LDFLAGS="-libpath:$LLVM_DIR/lib"
921-
HSDIS_LIBS="llvm-c.lib"
922-
fi
923-
elif test "x$with_hsdis" = xbinutils; then
924-
HSDIS_BACKEND=binutils
925-
AC_MSG_RESULT(['binutils'])
926-
927-
# We need the binutils static libs and includes.
928-
if test "x$with_binutils_src" != x; then
929-
# Try building the source first. If it succeeds, it sets $BINUTILS_DIR.
930-
JDKOPT_BUILD_BINUTILS
931-
fi
932-
933-
if test "x$with_binutils" != x; then
934-
BINUTILS_DIR="$with_binutils"
935-
fi
936-
937-
binutils_system_error=""
938-
HSDIS_LIBS=""
939-
if test "x$BINUTILS_DIR" = xsystem; then
940-
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd" ], [ binutils_system_error="libbfd not found" ])
941-
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes" ], [ binutils_system_error="libopcodes not found" ])
942-
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ], [ binutils_system_error="libiberty not found" ])
943-
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
944-
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
945-
elif test "x$BINUTILS_DIR" != x; then
946-
if test -e $BINUTILS_DIR/bfd/libbfd.a && \
947-
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
948-
test -e $BINUTILS_DIR/libiberty/libiberty.a; then
949-
HSDIS_CFLAGS="-I$BINUTILS_DIR/include -I$BINUTILS_DIR/bfd -DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
950-
HSDIS_LDFLAGS=""
951-
HSDIS_LIBS="$BINUTILS_DIR/bfd/libbfd.a $BINUTILS_DIR/opcodes/libopcodes.a $BINUTILS_DIR/libiberty/libiberty.a $BINUTILS_DIR/zlib/libz.a"
952-
fi
953-
fi
954-
955-
AC_MSG_CHECKING([for binutils to use with hsdis])
956-
case "x$BINUTILS_DIR" in
957-
xsystem)
958-
if test "x$OPENJDK_TARGET_OS" != xlinux; then
959-
AC_MSG_RESULT([invalid])
960-
AC_MSG_ERROR([binutils on system is supported for Linux only])
961-
elif test "x$binutils_system_error" = x; then
962-
AC_MSG_RESULT([system])
963-
HSDIS_CFLAGS="$HSDIS_CFLAGS -DSYSTEM_BINUTILS"
964-
else
965-
AC_MSG_RESULT([invalid])
966-
AC_MSG_ERROR([$binutils_system_error])
967-
fi
968-
;;
969-
x)
970-
AC_MSG_RESULT([missing])
971-
AC_MSG_NOTICE([--with-hsdis=binutils requires specifying a binutils installation.])
972-
AC_MSG_NOTICE([Download binutils from https://www.gnu.org/software/binutils and unpack it,])
973-
AC_MSG_NOTICE([and point --with-binutils-src to the resulting directory, or use])
974-
AC_MSG_NOTICE([--with-binutils to point to a pre-built binutils installation.])
975-
AC_MSG_ERROR([Cannot continue])
976-
;;
977-
*)
978-
if test "x$HSDIS_LIBS" != x; then
979-
AC_MSG_RESULT([$BINUTILS_DIR])
980-
else
981-
AC_MSG_RESULT([invalid])
982-
AC_MSG_ERROR([$BINUTILS_DIR does not contain a proper binutils installation])
983-
fi
984-
;;
985-
esac
986-
else
987-
AC_MSG_RESULT([invalid])
988-
AC_MSG_ERROR([Incorrect hsdis backend "$with_hsdis"])
989-
fi
990-
991-
AC_SUBST(HSDIS_BACKEND)
992-
AC_SUBST(HSDIS_CFLAGS)
993-
AC_SUBST(HSDIS_LDFLAGS)
994-
AC_SUBST(HSDIS_LIBS)
995-
])

‎make/autoconf/lib-hsdis.m4

+336
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,336 @@
1+
#
2+
# Copyright (c) 2021, 2022, 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+
################################################################################
27+
#
28+
# Helper function to setup hsdis using Capstone
29+
#
30+
AC_DEFUN([LIB_SETUP_HSDIS_CAPSTONE],
31+
[
32+
AC_ARG_WITH(capstone, [AS_HELP_STRING([--with-capstone],
33+
[where to find the Capstone files needed for hsdis/capstone])])
34+
35+
if test "x$with_capstone" != x; then
36+
AC_MSG_CHECKING([for capstone])
37+
CAPSTONE="$with_capstone"
38+
AC_MSG_RESULT([$CAPSTONE])
39+
40+
HSDIS_CFLAGS="-I${CAPSTONE}/include/capstone"
41+
if test "x$OPENJDK_TARGET_OS" != xwindows; then
42+
HSDIS_LDFLAGS="-L${CAPSTONE}/lib"
43+
HSDIS_LIBS="-lcapstone"
44+
else
45+
HSDIS_LDFLAGS="-nodefaultlib:libcmt.lib"
46+
HSDIS_LIBS="${CAPSTONE}/capstone.lib"
47+
fi
48+
else
49+
if test "x$OPENJDK_TARGET_OS" = xwindows; then
50+
# There is no way to auto-detect capstone on Windowos
51+
AC_MSG_NOTICE([You must specify capstone location using --with-capstone=<path>])
52+
AC_MSG_ERROR([Cannot continue])
53+
fi
54+
55+
PKG_CHECK_MODULES(CAPSTONE, capstone, [CAPSTONE_FOUND=yes], [CAPSTONE_FOUND=no])
56+
if test "x$CAPSTONE_FOUND" = xyes; then
57+
HSDIS_CFLAGS="$CAPSTONE_CFLAGS"
58+
HSDIS_LDFLAGS="$CAPSTONE_LDFLAGS"
59+
HSDIS_LIBS="$CAPSTONE_LIBS"
60+
else
61+
HELP_MSG_MISSING_DEPENDENCY([capstone])
62+
AC_MSG_NOTICE([Cannot locate capstone which is needed for hsdis/capstone. Try using --with-capstone=<path>. $HELP_MSG])
63+
AC_MSG_ERROR([Cannot continue])
64+
fi
65+
fi
66+
])
67+
68+
################################################################################
69+
#
70+
# Helper function to setup hsdis using LLVM
71+
#
72+
AC_DEFUN([LIB_SETUP_HSDIS_LLVM],
73+
[
74+
AC_ARG_WITH([llvm], [AS_HELP_STRING([--with-llvm],
75+
[where to find the LLVM files needed for hsdis/llvm])])
76+
77+
if test "x$with_llvm" != x; then
78+
LLVM_DIR="$with_llvm"
79+
fi
80+
81+
if test "x$OPENJDK_TARGET_OS" != xwindows; then
82+
if test "x$LLVM_DIR" = x; then
83+
# Macs with homebrew can have llvm in different places
84+
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$PATH:/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin])
85+
if test "x$LLVM_CONFIG" = x; then
86+
AC_MSG_NOTICE([Cannot locate llvm-config which is needed for hsdis/llvm. Try using --with-llvm=<LLVM home>.])
87+
AC_MSG_ERROR([Cannot continue])
88+
fi
89+
else
90+
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$LLVM_DIR/bin])
91+
if test "x$LLVM_CONFIG" = x; then
92+
AC_MSG_NOTICE([Cannot locate llvm-config in $LLVM_DIR. Check your --with-llvm argument.])
93+
AC_MSG_ERROR([Cannot continue])
94+
fi
95+
fi
96+
97+
# We need the LLVM flags and libs, and llvm-config provides them for us.
98+
HSDIS_CFLAGS=`$LLVM_CONFIG --cflags`
99+
HSDIS_LDFLAGS=`$LLVM_CONFIG --ldflags`
100+
HSDIS_LIBS=`$LLVM_CONFIG --libs $OPENJDK_TARGET_CPU_ARCH ${OPENJDK_TARGET_CPU_ARCH}disassembler`
101+
else
102+
if test "x$LLVM_DIR" = x; then
103+
AC_MSG_NOTICE([--with-llvm is needed on Windows to point out the LLVM home])
104+
AC_MSG_ERROR([Cannot continue])
105+
fi
106+
107+
# Official Windows installation of LLVM do not ship llvm-config, and self-built llvm-config
108+
# produced unusable output, so just ignore it on Windows.
109+
if ! test -e $LLVM_DIR/include/llvm-c/lto.h; then
110+
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; include dir is missing])
111+
AC_MSG_ERROR([Cannot continue])
112+
fi
113+
if ! test -e $LLVM_DIR/include/llvm-c/Disassembler.h; then
114+
AC_MSG_NOTICE([$LLVM_DIR does not point to a complete LLVM installation. ])
115+
AC_MSG_NOTICE([The official LLVM distribution is missing crucical files; you need to build LLVM yourself or get all include files elsewhere])
116+
AC_MSG_ERROR([Cannot continue])
117+
fi
118+
if ! test -e $LLVM_DIR/lib/llvm-c.lib; then
119+
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; lib dir is missing])
120+
AC_MSG_ERROR([Cannot continue])
121+
fi
122+
HSDIS_CFLAGS="-I$LLVM_DIR/include"
123+
HSDIS_LDFLAGS="-libpath:$LLVM_DIR/lib"
124+
HSDIS_LIBS="llvm-c.lib"
125+
fi
126+
])
127+
128+
################################################################################
129+
#
130+
# Helper function to build binutils from source.
131+
#
132+
AC_DEFUN([LIB_BUILD_BINUTILS],
133+
[
134+
BINUTILS_SRC="$with_binutils_src"
135+
UTIL_FIXUP_PATH(BINUTILS_SRC)
136+
137+
if ! test -d $BINUTILS_SRC; then
138+
AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
139+
fi
140+
if ! test -x $BINUTILS_SRC/configure; then
141+
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
142+
fi
143+
144+
if test -e $BINUTILS_SRC/bfd/libbfd.a && \
145+
test -e $BINUTILS_SRC/opcodes/libopcodes.a && \
146+
test -e $BINUTILS_SRC/libiberty/libiberty.a && \
147+
test -e $BINUTILS_SRC/zlib/libz.a; then
148+
AC_MSG_NOTICE([Found binutils binaries in binutils source directory -- not building])
149+
else
150+
# On Windows, we cannot build with the normal Microsoft CL, but must instead use
151+
# a separate mingw toolchain.
152+
if test "x$OPENJDK_BUILD_OS" = xwindows; then
153+
if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
154+
target_base="i686-w64-mingw32"
155+
else
156+
target_base="$OPENJDK_TARGET_CPU-w64-mingw32"
157+
fi
158+
binutils_cc="$target_base-gcc"
159+
binutils_target="--host=$target_base --target=$target_base"
160+
# Somehow the uint typedef is not included when building with mingw
161+
binutils_cflags="-Duint=unsigned"
162+
compiler_version=`$binutils_cc --version 2>&1`
163+
if ! [ [[ "$compiler_version" =~ GCC ]] ]; then
164+
AC_MSG_NOTICE([Could not find correct mingw compiler $binutils_cc.])
165+
HELP_MSG_MISSING_DEPENDENCY([$binutils_cc])
166+
AC_MSG_ERROR([Cannot continue. $HELP_MSG])
167+
else
168+
AC_MSG_NOTICE([Using compiler $binutils_cc with version $compiler_version])
169+
fi
170+
elif test "x$OPENJDK_BUILD_OS" = xmacosx; then
171+
if test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
172+
binutils_target="--enable-targets=aarch64-darwin"
173+
else
174+
binutils_target=""
175+
fi
176+
else
177+
binutils_cc="$CC $SYSROOT_CFLAGS"
178+
binutils_target=""
179+
fi
180+
binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
181+
182+
AC_MSG_NOTICE([Running binutils configure])
183+
AC_MSG_NOTICE([configure command line: ./configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" $binutils_target])
184+
saved_dir=`pwd`
185+
cd "$BINUTILS_SRC"
186+
./configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" $binutils_target
187+
if test $? -ne 0 || ! test -e $BINUTILS_SRC/Makefile; then
188+
AC_MSG_NOTICE([Automatic building of binutils failed on configure. Try building it manually])
189+
AC_MSG_ERROR([Cannot continue])
190+
fi
191+
AC_MSG_NOTICE([Running binutils make])
192+
$MAKE all-opcodes
193+
if test $? -ne 0; then
194+
AC_MSG_NOTICE([Automatic building of binutils failed on make. Try building it manually])
195+
AC_MSG_ERROR([Cannot continue])
196+
fi
197+
cd $saved_dir
198+
AC_MSG_NOTICE([Building of binutils done])
199+
fi
200+
201+
BINUTILS_DIR="$BINUTILS_SRC"
202+
])
203+
204+
################################################################################
205+
#
206+
# Helper function to setup hsdis using binutils
207+
#
208+
AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
209+
[
210+
AC_ARG_WITH([binutils], [AS_HELP_STRING([--with-binutils],
211+
[where to find the binutils files needed for hsdis/binutils])])
212+
213+
AC_ARG_WITH([binutils-src], [AS_HELP_STRING([--with-binutils-src],
214+
[where to find the binutils source for building])])
215+
216+
# We need the binutils static libs and includes.
217+
if test "x$with_binutils_src" != x; then
218+
# Try building the source first. If it succeeds, it sets $BINUTILS_DIR.
219+
LIB_BUILD_BINUTILS
220+
fi
221+
222+
if test "x$with_binutils" != x; then
223+
BINUTILS_DIR="$with_binutils"
224+
fi
225+
226+
binutils_system_error=""
227+
HSDIS_LIBS=""
228+
if test "x$BINUTILS_DIR" = xsystem; then
229+
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd" ], [ binutils_system_error="libbfd not found" ])
230+
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes" ], [ binutils_system_error="libopcodes not found" ])
231+
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ], [ binutils_system_error="libiberty not found" ])
232+
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
233+
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
234+
elif test "x$BINUTILS_DIR" != x; then
235+
if test -e $BINUTILS_DIR/bfd/libbfd.a && \
236+
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
237+
test -e $BINUTILS_DIR/libiberty/libiberty.a; then
238+
HSDIS_CFLAGS="-I$BINUTILS_DIR/include -I$BINUTILS_DIR/bfd -DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
239+
HSDIS_LDFLAGS=""
240+
HSDIS_LIBS="$BINUTILS_DIR/bfd/libbfd.a $BINUTILS_DIR/opcodes/libopcodes.a $BINUTILS_DIR/libiberty/libiberty.a $BINUTILS_DIR/zlib/libz.a"
241+
fi
242+
fi
243+
244+
AC_MSG_CHECKING([for binutils to use with hsdis])
245+
case "x$BINUTILS_DIR" in
246+
xsystem)
247+
if test "x$OPENJDK_TARGET_OS" != xlinux; then
248+
AC_MSG_RESULT([invalid])
249+
AC_MSG_ERROR([binutils on system is supported for Linux only])
250+
elif test "x$binutils_system_error" = x; then
251+
AC_MSG_RESULT([system])
252+
HSDIS_CFLAGS="$HSDIS_CFLAGS -DSYSTEM_BINUTILS"
253+
else
254+
AC_MSG_RESULT([invalid])
255+
AC_MSG_ERROR([$binutils_system_error])
256+
fi
257+
;;
258+
x)
259+
AC_MSG_RESULT([missing])
260+
AC_MSG_NOTICE([--with-hsdis=binutils requires specifying a binutils installation.])
261+
AC_MSG_NOTICE([Download binutils from https://www.gnu.org/software/binutils and unpack it,])
262+
AC_MSG_NOTICE([and point --with-binutils-src to the resulting directory, or use])
263+
AC_MSG_NOTICE([--with-binutils to point to a pre-built binutils installation.])
264+
AC_MSG_ERROR([Cannot continue])
265+
;;
266+
*)
267+
if test "x$HSDIS_LIBS" != x; then
268+
AC_MSG_RESULT([$BINUTILS_DIR])
269+
else
270+
AC_MSG_RESULT([invalid])
271+
AC_MSG_ERROR([$BINUTILS_DIR does not contain a proper binutils installation])
272+
fi
273+
;;
274+
esac
275+
])
276+
277+
################################################################################
278+
#
279+
# Determine if hsdis should be built, and if so, with which backend.
280+
#
281+
AC_DEFUN_ONCE([LIB_SETUP_HSDIS],
282+
[
283+
AC_ARG_WITH([hsdis], [AS_HELP_STRING([--with-hsdis],
284+
[what hsdis backend to use ('none', 'capstone', 'llvm', 'binutils') @<:@none@:>@])])
285+
286+
UTIL_ARG_ENABLE(NAME: hsdis-bundling, DEFAULT: false,
287+
RESULT: ENABLE_HSDIS_BUNDLING,
288+
DESC: [enable bundling of hsdis to allow HotSpot disassembly out-of-the-box])
289+
290+
AC_MSG_CHECKING([what hsdis backend to use])
291+
292+
if test "x$with_hsdis" = xyes; then
293+
AC_MSG_ERROR([--with-hsdis must have a value])
294+
elif test "x$with_hsdis" = xnone || test "x$with_hsdis" = xno || test "x$with_hsdis" = x; then
295+
HSDIS_BACKEND=none
296+
AC_MSG_RESULT(['none', hsdis will not be built])
297+
elif test "x$with_hsdis" = xcapstone; then
298+
HSDIS_BACKEND=capstone
299+
AC_MSG_RESULT(['capstone'])
300+
301+
LIB_SETUP_HSDIS_CAPSTONE
302+
elif test "x$with_hsdis" = xllvm; then
303+
HSDIS_BACKEND=llvm
304+
AC_MSG_RESULT(['llvm'])
305+
306+
LIB_SETUP_HSDIS_LLVM
307+
elif test "x$with_hsdis" = xbinutils; then
308+
HSDIS_BACKEND=binutils
309+
AC_MSG_RESULT(['binutils'])
310+
311+
LIB_SETUP_HSDIS_BINUTILS
312+
else
313+
AC_MSG_RESULT([invalid])
314+
AC_MSG_ERROR([Incorrect hsdis backend "$with_hsdis"])
315+
fi
316+
317+
AC_SUBST(HSDIS_BACKEND)
318+
AC_SUBST(HSDIS_CFLAGS)
319+
AC_SUBST(HSDIS_LDFLAGS)
320+
AC_SUBST(HSDIS_LIBS)
321+
322+
AC_MSG_CHECKING([if hsdis should be bundled])
323+
if test "x$ENABLE_HSDIS_BUNDLING" = "xtrue"; then
324+
if test "x$HSDIS_BACKEND" = xnone; then
325+
AC_MSG_RESULT([no, backend missing])
326+
AC_MSG_ERROR([hsdis-bundling requires a hsdis backend. Please set --with-hsdis=<backend>]);
327+
fi
328+
AC_MSG_RESULT([yes])
329+
if test "x$HSDIS_BACKEND" = xbinutils; then
330+
AC_MSG_WARN([The resulting build might not be redistributable. Seek legal advice before distributing.])
331+
fi
332+
else
333+
AC_MSG_RESULT([no])
334+
fi
335+
AC_SUBST(ENABLE_HSDIS_BUNDLING)
336+
])

‎make/autoconf/libraries.m4

+9-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ m4_include([lib-alsa.m4])
2828
m4_include([lib-bundled.m4])
2929
m4_include([lib-cups.m4])
3030
m4_include([lib-ffi.m4])
31+
m4_include([lib-fontconfig.m4])
3132
m4_include([lib-freetype.m4])
33+
m4_include([lib-hsdis.m4])
3234
m4_include([lib-std.m4])
3335
m4_include([lib-x11.m4])
34-
m4_include([lib-fontconfig.m4])
36+
3537
m4_include([lib-tests.m4])
3638

3739
################################################################################
@@ -93,14 +95,17 @@ AC_DEFUN_ONCE([LIB_DETERMINE_DEPENDENCIES],
9395
AC_DEFUN_ONCE([LIB_SETUP_LIBRARIES],
9496
[
9597
LIB_SETUP_STD_LIBS
96-
LIB_SETUP_X11
98+
99+
LIB_SETUP_ALSA
100+
LIB_SETUP_BUNDLED_LIBS
97101
LIB_SETUP_CUPS
98102
LIB_SETUP_FONTCONFIG
99103
LIB_SETUP_FREETYPE
100-
LIB_SETUP_ALSA
104+
LIB_SETUP_HSDIS
101105
LIB_SETUP_LIBFFI
102-
LIB_SETUP_BUNDLED_LIBS
103106
LIB_SETUP_MISC_LIBS
107+
LIB_SETUP_X11
108+
104109
LIB_TESTS_SETUP_GTEST
105110
106111
BASIC_JDKLIB_LIBS=""

‎make/autoconf/spec.gmk.in

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ ENABLE_COMPATIBLE_CDS_ALIGNMENT := @ENABLE_COMPATIBLE_CDS_ALIGNMENT@
360360
ALLOW_ABSOLUTE_PATHS_IN_OUTPUT := @ALLOW_ABSOLUTE_PATHS_IN_OUTPUT@
361361

362362
HSDIS_BACKEND := @HSDIS_BACKEND@
363+
ENABLE_HSDIS_BUNDLING := @ENABLE_HSDIS_BUNDLING@
363364
HSDIS_CFLAGS := @HSDIS_CFLAGS@
364365
HSDIS_LDFLAGS := @HSDIS_LDFLAGS@
365366
HSDIS_LIBS := @HSDIS_LIBS@

‎make/modules/java.base/Copy.gmk

+17
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ ifeq ($(ENABLE_LIBFFI_BUNDLING), true)
246246
TARGETS += $(COPY_LIBFFI)
247247
endif
248248

249+
################################################################################
250+
# Optionally copy hsdis into the the image
251+
252+
ifeq ($(ENABLE_HSDIS_BUNDLING), true)
253+
HSDIS_NAME := hsdis-$(OPENJDK_TARGET_CPU_LEGACY_LIB)$(SHARED_LIBRARY_SUFFIX)
254+
HSDIS_PATH := $(SUPPORT_OUTPUTDIR)/hsdis/$(HSDIS_NAME)
255+
256+
$(eval $(call SetupCopyFiles, COPY_HSDIS, \
257+
FILES := $(HSDIS_PATH), \
258+
DEST := $(call FindLibDirForModule, $(MODULE)), \
259+
FLATTEN := true, \
260+
MACRO := install-file-nolink, \
261+
))
262+
263+
TARGETS += $(COPY_HSDIS)
264+
endif
265+
249266
################################################################################
250267
# Generate classfile_constants.h
251268

0 commit comments

Comments
 (0)
Please sign in to comment.