2
# Copyright (c) 2021, 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
26
################################################################################
28
# Helper function to setup hsdis using Capstone
30
AC_DEFUN([LIB_SETUP_HSDIS_CAPSTONE],
32
AC_ARG_WITH(capstone, [AS_HELP_STRING([--with-capstone],
33
[where to find the Capstone files needed for hsdis/capstone])])
35
if test "x$with_capstone" != x; then
36
AC_MSG_CHECKING([for capstone])
37
CAPSTONE="$with_capstone"
38
AC_MSG_RESULT([$CAPSTONE])
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"
45
HSDIS_LDFLAGS="-nodefaultlib:libcmt.lib"
46
HSDIS_LIBS="${CAPSTONE}/capstone.lib"
49
if test "x$OPENJDK_TARGET_OS" = xwindows; then
50
# There is no way to auto-detect capstone on Windows
51
AC_MSG_NOTICE([You must specify capstone location using --with-capstone=<path>])
52
AC_MSG_ERROR([Cannot continue])
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"
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])
67
capstone_header="\"$CAPSTONE/include/capstone/capstone.h\""
68
AC_MSG_CHECKING([capstone aarch64 arch name])
69
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $capstone_header],[[cs_arch test = CS_ARCH_AARCH64]])],
71
AC_MSG_RESULT([AARCH64])
72
CAPSTONE_ARCH_AARCH64_NAME="AARCH64"
75
AC_MSG_RESULT([ARM64])
76
CAPSTONE_ARCH_AARCH64_NAME="ARM64"
81
################################################################################
83
# Helper function to setup hsdis using LLVM
85
AC_DEFUN([LIB_SETUP_HSDIS_LLVM],
87
AC_ARG_WITH([llvm], [AS_HELP_STRING([--with-llvm],
88
[where to find the LLVM files needed for hsdis/llvm])])
90
if test "x$with_llvm" != x; then
94
if test "x$OPENJDK_TARGET_OS" != xwindows; then
95
if test "x$LLVM_DIR" = x; then
96
# Macs with homebrew can have llvm in different places
97
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$PATH:/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin])
98
if test "x$LLVM_CONFIG" = x; then
99
AC_MSG_NOTICE([Cannot locate llvm-config which is needed for hsdis/llvm. Try using --with-llvm=<LLVM home>.])
100
AC_MSG_ERROR([Cannot continue])
103
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$LLVM_DIR/bin])
104
if test "x$LLVM_CONFIG" = x; then
105
AC_MSG_NOTICE([Cannot locate llvm-config in $LLVM_DIR. Check your --with-llvm argument.])
106
AC_MSG_ERROR([Cannot continue])
110
# We need the LLVM flags and libs, and llvm-config provides them for us.
111
HSDIS_CFLAGS=`$LLVM_CONFIG --cflags`
112
HSDIS_LDFLAGS=`$LLVM_CONFIG --ldflags`
113
HSDIS_LIBS=`$LLVM_CONFIG --libs $OPENJDK_TARGET_CPU_ARCH ${OPENJDK_TARGET_CPU_ARCH}disassembler`
115
if test "x$LLVM_DIR" = x; then
116
AC_MSG_NOTICE([--with-llvm is needed on Windows to point out the LLVM home])
117
AC_MSG_ERROR([Cannot continue])
120
# Official Windows installation of LLVM do not ship llvm-config, and self-built llvm-config
121
# produced unusable output, so just ignore it on Windows.
122
if ! test -e $LLVM_DIR/include/llvm-c/lto.h; then
123
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; include dir is missing])
124
AC_MSG_ERROR([Cannot continue])
126
if ! test -e $LLVM_DIR/include/llvm-c/Disassembler.h; then
127
AC_MSG_NOTICE([$LLVM_DIR does not point to a complete LLVM installation. ])
128
AC_MSG_NOTICE([The official LLVM distribution is missing crucical files; you need to build LLVM yourself or get all include files elsewhere])
129
AC_MSG_ERROR([Cannot continue])
131
if ! test -e $LLVM_DIR/lib/llvm-c.lib; then
132
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; lib dir is missing])
133
AC_MSG_ERROR([Cannot continue])
135
HSDIS_CFLAGS="-I$LLVM_DIR/include"
136
HSDIS_LDFLAGS="-libpath:$LLVM_DIR/lib"
137
HSDIS_LIBS="llvm-c.lib"
141
################################################################################
143
# Helper function to build binutils from source.
145
AC_DEFUN([LIB_BUILD_BINUTILS],
147
BINUTILS_SRC="$with_binutils_src"
148
UTIL_FIXUP_PATH(BINUTILS_SRC)
150
BINUTILS_BUILD_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
151
BINUTILS_INSTALL_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils-install"
153
if ! test -d $BINUTILS_SRC; then
154
AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
156
if ! test -x $BINUTILS_SRC/configure; then
157
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
160
if ! test -d $BINUTILS_BUILD_DIR; then
161
$MKDIR -p $BINUTILS_BUILD_DIR
164
# We don't know the version, not checking for libsframe.a
165
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \
166
test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \
167
test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
168
AC_MSG_NOTICE([Found binutils binaries in binutils install directory -- not building])
170
# On Windows, we cannot build with the normal Microsoft CL, but must instead use
171
# a separate mingw toolchain.
172
if test "x$OPENJDK_BUILD_OS" = xwindows; then
173
if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
174
target_base="i686-w64-mingw32"
176
target_base="$OPENJDK_TARGET_CPU-w64-mingw32"
178
binutils_cc="$target_base-gcc"
179
binutils_target="--host=$target_base --target=$target_base"
180
# Somehow the uint typedef is not included when building with mingw
181
binutils_cflags="-Duint=unsigned"
182
compiler_version=`$binutils_cc --version 2>&1`
183
if ! [ [[ "$compiler_version" =~ GCC ]] ]; then
184
AC_MSG_NOTICE([Could not find correct mingw compiler $binutils_cc.])
185
HELP_MSG_MISSING_DEPENDENCY([$binutils_cc])
186
AC_MSG_ERROR([Cannot continue. $HELP_MSG])
188
AC_MSG_NOTICE([Using compiler $binutils_cc with version $compiler_version])
190
elif test "x$OPENJDK_BUILD_OS" = xmacosx; then
191
if test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
192
binutils_target="--enable-targets=aarch64-darwin"
197
binutils_cc="$CC $SYSROOT_CFLAGS"
198
if test "x$COMPILE_TYPE" = xcross; then
199
binutils_target="--host=$OPENJDK_TARGET_AUTOCONF_NAME"
204
binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
206
AC_MSG_NOTICE([Running binutils configure])
207
AC_MSG_NOTICE([configure command line: cd $BINUTILS_BUILD_DIR && $BINUTILS_SRC/configure --disable-werror --prefix=$BINUTILS_INSTALL_DIR --enable-install-libiberty --with-system-zlib --without-zstd --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target])
209
cd "$BINUTILS_BUILD_DIR"
210
$BINUTILS_SRC/configure --disable-werror --prefix=$BINUTILS_INSTALL_DIR --enable-install-libiberty --with-system-zlib --without-zstd --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target
211
if test $? -ne 0 || ! test -e $BINUTILS_BUILD_DIR/Makefile; then
212
AC_MSG_NOTICE([Automatic building of binutils failed on configure. Try building it manually])
213
AC_MSG_ERROR([Cannot continue])
215
AC_MSG_NOTICE([Running binutils make])
216
$MAKE all-opcodes all-libiberty
217
if test $? -ne 0; then
218
AC_MSG_NOTICE([Automatic building of binutils failed on make. Try building it manually])
219
AC_MSG_ERROR([Cannot continue])
221
AC_MSG_NOTICE([Running binutils make install])
222
$MAKE install-opcodes install-libiberty
223
if test $? -ne 0; then
224
AC_MSG_NOTICE([Automatic building, install step, of binutils failed on make. Try building it manually])
225
AC_MSG_ERROR([Cannot continue])
228
AC_MSG_NOTICE([Building of binutils done])
232
################################################################################
234
# Helper function to setup hsdis using binutils
236
AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
238
AC_ARG_WITH([binutils], [AS_HELP_STRING([--with-binutils],
239
[where to find the binutils files needed for hsdis/binutils])])
241
AC_ARG_WITH([binutils-src], [AS_HELP_STRING([--with-binutils-src],
242
[where to find the binutils source for building])])
244
# We need the binutils static libs and includes.
245
if test "x$with_binutils_src" != x; then
246
# Try building the source first. If it succeeds, it sets $BINUTILS_INSTALL_DIR.
250
if test "x$with_binutils" != x; then
251
BINUTILS_INSTALL_DIR="$with_binutils"
254
binutils_system_error=""
257
disasm_header="<dis-asm.h>"
259
if test "x$BINUTILS_INSTALL_DIR" = xsystem; then
260
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd" ], [ binutils_system_error="libbfd not found" ])
261
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes" ], [ binutils_system_error="libopcodes not found" ])
262
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
263
# libiberty is not required on Ubuntu
264
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ])
265
AC_CHECK_LIB(sframe, frame, [ HSDIS_LIBS="$HSDIS_LIBS -lsframe" ], )
266
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
267
elif test "x$BINUTILS_INSTALL_DIR" != x; then
268
disasm_header="\"$BINUTILS_INSTALL_DIR/include/dis-asm.h\""
269
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \
270
test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \
271
(test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a || test -e $BINUTILS_INSTALL_DIR/lib64/libiberty.a || test -e $BINUTILS_INSTALL_DIR/lib32/libiberty.a); then
272
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB -I$BINUTILS_INSTALL_DIR/include"
274
# libiberty ignores --libdir and may be installed in $BINUTILS_INSTALL_DIR/lib, $BINUTILS_INSTALL_DIR/lib32
275
# or $BINUTILS_INSTALL_DIR/lib64, depending on system setup
277
if test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
278
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib/libiberty.a"
279
elif test -e $BINUTILS_INSTALL_DIR/lib32/libiberty.a; then
280
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib32/libiberty.a"
282
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib64/libiberty.a"
284
HSDIS_LIBS="$BINUTILS_INSTALL_DIR/lib/libbfd.a $BINUTILS_INSTALL_DIR/lib/libopcodes.a $LIBIBERTY_LIB"
285
# If we have libsframe add it.
286
if test -e $BINUTILS_INSTALL_DIR/lib/libsframe.a; then
287
HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_INSTALL_DIR/lib/libsframe.a"
289
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], AC_MSG_ERROR([libz not found]))
291
AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/lib[64] must contain libbfd.a, libopcodes.a and libiberty.a"])
295
AC_MSG_CHECKING([Checking binutils API])
296
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $disasm_header],[[init_disassemble_info(0, 0, 0, 0);]])],
298
AC_MSG_RESULT([New API])
299
HSDIS_CFLAGS="$HSDIS_CFLAGS -DBINUTILS_NEW_API"
302
AC_MSG_RESULT([Old API])
306
AC_MSG_CHECKING([for binutils to use with hsdis])
307
case "x$BINUTILS_INSTALL_DIR" in
309
if test "x$OPENJDK_TARGET_OS" != xlinux; then
310
AC_MSG_RESULT([invalid])
311
AC_MSG_ERROR([binutils on system is supported for Linux only])
312
elif test "x$binutils_system_error" = x; then
313
AC_MSG_RESULT([system])
314
HSDIS_CFLAGS="$HSDIS_CFLAGS -DSYSTEM_BINUTILS"
316
AC_MSG_RESULT([invalid])
317
AC_MSG_ERROR([$binutils_system_error])
321
AC_MSG_RESULT([missing])
322
AC_MSG_NOTICE([--with-hsdis=binutils requires specifying a binutils installation.])
323
AC_MSG_NOTICE([Download binutils from https://www.gnu.org/software/binutils and unpack it,])
324
AC_MSG_NOTICE([and point --with-binutils-src to the resulting directory, or use])
325
AC_MSG_NOTICE([--with-binutils to point to a pre-built binutils installation.])
326
AC_MSG_ERROR([Cannot continue])
329
if test "x$HSDIS_LIBS" != x; then
330
AC_MSG_RESULT([$BINUTILS_INSTALL_DIR])
332
AC_MSG_RESULT([invalid])
333
AC_MSG_ERROR([$BINUTILS_INSTALL_DIR does not contain a proper binutils installation])
339
################################################################################
341
# Determine if hsdis should be built, and if so, with which backend.
343
AC_DEFUN_ONCE([LIB_SETUP_HSDIS],
345
AC_ARG_WITH([hsdis], [AS_HELP_STRING([--with-hsdis],
346
[what hsdis backend to use ('none', 'capstone', 'llvm', 'binutils') @<:@none@:>@])])
348
UTIL_ARG_ENABLE(NAME: hsdis-bundling, DEFAULT: false,
349
RESULT: ENABLE_HSDIS_BUNDLING,
350
DESC: [enable bundling of hsdis to allow HotSpot disassembly out-of-the-box])
352
AC_MSG_CHECKING([what hsdis backend to use])
354
if test "x$with_hsdis" = xyes; then
355
AC_MSG_ERROR([--with-hsdis must have a value])
356
elif test "x$with_hsdis" = xnone || test "x$with_hsdis" = xno || test "x$with_hsdis" = x; then
358
AC_MSG_RESULT(['none', hsdis will not be built])
359
elif test "x$with_hsdis" = xcapstone; then
360
HSDIS_BACKEND=capstone
361
AC_MSG_RESULT(['capstone'])
363
LIB_SETUP_HSDIS_CAPSTONE
364
elif test "x$with_hsdis" = xllvm; then
366
AC_MSG_RESULT(['llvm'])
369
elif test "x$with_hsdis" = xbinutils; then
370
HSDIS_BACKEND=binutils
371
AC_MSG_RESULT(['binutils'])
373
LIB_SETUP_HSDIS_BINUTILS
375
AC_MSG_RESULT([invalid])
376
AC_MSG_ERROR([Incorrect hsdis backend "$with_hsdis"])
379
AC_SUBST(HSDIS_BACKEND)
380
AC_SUBST(HSDIS_CFLAGS)
381
AC_SUBST(HSDIS_LDFLAGS)
383
AC_SUBST(CAPSTONE_ARCH_AARCH64_NAME)
385
AC_MSG_CHECKING([if hsdis should be bundled])
386
if test "x$ENABLE_HSDIS_BUNDLING" = "xtrue"; then
387
if test "x$HSDIS_BACKEND" = xnone; then
388
AC_MSG_RESULT([no, backend missing])
389
AC_MSG_ERROR([hsdis-bundling requires a hsdis backend. Please set --with-hsdis=<backend>]);
392
if test "x$HSDIS_BACKEND" = xbinutils; then
393
AC_MSG_WARN([The resulting build might not be redistributable. Seek legal advice before distributing.])
398
AC_SUBST(ENABLE_HSDIS_BUNDLING)