1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
#
# Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
################################################################################
#
# Helper function to setup hsdis using Capstone
#
AC_DEFUN([LIB_SETUP_HSDIS_CAPSTONE],
[
AC_ARG_WITH(capstone, [AS_HELP_STRING([--with-capstone],
[where to find the Capstone files needed for hsdis/capstone])])
if test "x$with_capstone" != x; then
AC_MSG_CHECKING([for capstone])
CAPSTONE="$with_capstone"
AC_MSG_RESULT([$CAPSTONE])
HSDIS_CFLAGS="-I${CAPSTONE}/include/capstone"
if test "x$OPENJDK_TARGET_OS" != xwindows; then
HSDIS_LDFLAGS="-L${CAPSTONE}/lib"
HSDIS_LIBS="-lcapstone"
else
HSDIS_LDFLAGS="-nodefaultlib:libcmt.lib"
HSDIS_LIBS="${CAPSTONE}/capstone.lib"
fi
else
if test "x$OPENJDK_TARGET_OS" = xwindows; then
# There is no way to auto-detect capstone on Windows
AC_MSG_NOTICE([You must specify capstone location using --with-capstone=<path>])
AC_MSG_ERROR([Cannot continue])
fi
PKG_CHECK_MODULES(CAPSTONE, capstone, [CAPSTONE_FOUND=yes], [CAPSTONE_FOUND=no])
if test "x$CAPSTONE_FOUND" = xyes; then
HSDIS_CFLAGS="$CAPSTONE_CFLAGS"
HSDIS_LDFLAGS="$CAPSTONE_LDFLAGS"
HSDIS_LIBS="$CAPSTONE_LIBS"
else
HELP_MSG_MISSING_DEPENDENCY([capstone])
AC_MSG_NOTICE([Cannot locate capstone which is needed for hsdis/capstone. Try using --with-capstone=<path>. $HELP_MSG])
AC_MSG_ERROR([Cannot continue])
fi
fi
capstone_header="\"$CAPSTONE/include/capstone/capstone.h\""
AC_MSG_CHECKING([capstone aarch64 arch name])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $capstone_header],[[cs_arch test = CS_ARCH_AARCH64]])],
[
AC_MSG_RESULT([AARCH64])
CAPSTONE_ARCH_AARCH64_NAME="AARCH64"
],
[
AC_MSG_RESULT([ARM64])
CAPSTONE_ARCH_AARCH64_NAME="ARM64"
]
)
])
################################################################################
#
# Helper function to setup hsdis using LLVM
#
AC_DEFUN([LIB_SETUP_HSDIS_LLVM],
[
AC_ARG_WITH([llvm], [AS_HELP_STRING([--with-llvm],
[where to find the LLVM files needed for hsdis/llvm])])
if test "x$with_llvm" != x; then
LLVM_DIR="$with_llvm"
fi
if test "x$OPENJDK_TARGET_OS" != xwindows; then
if test "x$LLVM_DIR" = x; then
# Macs with homebrew can have llvm in different places
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$PATH:/usr/local/opt/llvm/bin:/opt/homebrew/opt/llvm/bin])
if test "x$LLVM_CONFIG" = x; then
AC_MSG_NOTICE([Cannot locate llvm-config which is needed for hsdis/llvm. Try using --with-llvm=<LLVM home>.])
AC_MSG_ERROR([Cannot continue])
fi
else
UTIL_LOOKUP_PROGS(LLVM_CONFIG, llvm-config, [$LLVM_DIR/bin])
if test "x$LLVM_CONFIG" = x; then
AC_MSG_NOTICE([Cannot locate llvm-config in $LLVM_DIR. Check your --with-llvm argument.])
AC_MSG_ERROR([Cannot continue])
fi
fi
# We need the LLVM flags and libs, and llvm-config provides them for us.
HSDIS_CFLAGS=`$LLVM_CONFIG --cflags`
HSDIS_LDFLAGS=`$LLVM_CONFIG --ldflags`
HSDIS_LIBS=`$LLVM_CONFIG --libs $OPENJDK_TARGET_CPU_ARCH ${OPENJDK_TARGET_CPU_ARCH}disassembler`
else
if test "x$LLVM_DIR" = x; then
AC_MSG_NOTICE([--with-llvm is needed on Windows to point out the LLVM home])
AC_MSG_ERROR([Cannot continue])
fi
# Official Windows installation of LLVM do not ship llvm-config, and self-built llvm-config
# produced unusable output, so just ignore it on Windows.
if ! test -e $LLVM_DIR/include/llvm-c/lto.h; then
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; include dir is missing])
AC_MSG_ERROR([Cannot continue])
fi
if ! test -e $LLVM_DIR/include/llvm-c/Disassembler.h; then
AC_MSG_NOTICE([$LLVM_DIR does not point to a complete LLVM installation. ])
AC_MSG_NOTICE([The official LLVM distribution is missing crucical files; you need to build LLVM yourself or get all include files elsewhere])
AC_MSG_ERROR([Cannot continue])
fi
if ! test -e $LLVM_DIR/lib/llvm-c.lib; then
AC_MSG_NOTICE([$LLVM_DIR does not seem like a valid LLVM home; lib dir is missing])
AC_MSG_ERROR([Cannot continue])
fi
HSDIS_CFLAGS="-I$LLVM_DIR/include"
HSDIS_LDFLAGS="-libpath:$LLVM_DIR/lib"
HSDIS_LIBS="llvm-c.lib"
fi
])
################################################################################
#
# Helper function to build binutils from source.
#
AC_DEFUN([LIB_BUILD_BINUTILS],
[
BINUTILS_SRC="$with_binutils_src"
UTIL_FIXUP_PATH(BINUTILS_SRC)
BINUTILS_BUILD_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
BINUTILS_INSTALL_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils-install"
if ! test -d $BINUTILS_SRC; then
AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
fi
if ! test -x $BINUTILS_SRC/configure; then
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
fi
if ! test -d $BINUTILS_BUILD_DIR; then
$MKDIR -p $BINUTILS_BUILD_DIR
fi
# We don't know the version, not checking for libsframe.a
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \
test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \
test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
AC_MSG_NOTICE([Found binutils binaries in binutils install directory -- not building])
else
# On Windows, we cannot build with the normal Microsoft CL, but must instead use
# a separate mingw toolchain.
if test "x$OPENJDK_BUILD_OS" = xwindows; then
if test "x$OPENJDK_TARGET_CPU" = "xx86"; then
target_base="i686-w64-mingw32"
else
target_base="$OPENJDK_TARGET_CPU-w64-mingw32"
fi
binutils_cc="$target_base-gcc"
binutils_target="--host=$target_base --target=$target_base"
# Somehow the uint typedef is not included when building with mingw
binutils_cflags="-Duint=unsigned"
compiler_version=`$binutils_cc --version 2>&1`
if ! [ [[ "$compiler_version" =~ GCC ]] ]; then
AC_MSG_NOTICE([Could not find correct mingw compiler $binutils_cc.])
HELP_MSG_MISSING_DEPENDENCY([$binutils_cc])
AC_MSG_ERROR([Cannot continue. $HELP_MSG])
else
AC_MSG_NOTICE([Using compiler $binutils_cc with version $compiler_version])
fi
elif test "x$OPENJDK_BUILD_OS" = xmacosx; then
if test "x$OPENJDK_TARGET_CPU" = "xaarch64"; then
binutils_target="--enable-targets=aarch64-darwin"
else
binutils_target=""
fi
else
binutils_cc="$CC $SYSROOT_CFLAGS"
if test "x$COMPILE_TYPE" = xcross; then
binutils_target="--host=$OPENJDK_TARGET_AUTOCONF_NAME"
else
binutils_target=""
fi
fi
binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
AC_MSG_NOTICE([Running binutils configure])
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])
saved_dir=`pwd`
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
if test $? -ne 0 || ! test -e $BINUTILS_BUILD_DIR/Makefile; then
AC_MSG_NOTICE([Automatic building of binutils failed on configure. Try building it manually])
AC_MSG_ERROR([Cannot continue])
fi
AC_MSG_NOTICE([Running binutils make])
$MAKE all-opcodes all-libiberty
if test $? -ne 0; then
AC_MSG_NOTICE([Automatic building of binutils failed on make. Try building it manually])
AC_MSG_ERROR([Cannot continue])
fi
AC_MSG_NOTICE([Running binutils make install])
$MAKE install-opcodes install-libiberty
if test $? -ne 0; then
AC_MSG_NOTICE([Automatic building, install step, of binutils failed on make. Try building it manually])
AC_MSG_ERROR([Cannot continue])
fi
cd $saved_dir
AC_MSG_NOTICE([Building of binutils done])
fi
])
################################################################################
#
# Helper function to setup hsdis using binutils
#
AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
[
AC_ARG_WITH([binutils], [AS_HELP_STRING([--with-binutils],
[where to find the binutils files needed for hsdis/binutils])])
AC_ARG_WITH([binutils-src], [AS_HELP_STRING([--with-binutils-src],
[where to find the binutils source for building])])
# We need the binutils static libs and includes.
if test "x$with_binutils_src" != x; then
# Try building the source first. If it succeeds, it sets $BINUTILS_INSTALL_DIR.
LIB_BUILD_BINUTILS
fi
if test "x$with_binutils" != x; then
BINUTILS_INSTALL_DIR="$with_binutils"
fi
binutils_system_error=""
HSDIS_LDFLAGS=""
HSDIS_LIBS=""
disasm_header="<dis-asm.h>"
if test "x$BINUTILS_INSTALL_DIR" = xsystem; then
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd_pic -lsframe -lzstd -liberty" ], [ binutils_system_error="libbfd not found" ])
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes_pic" ], [ binutils_system_error="libopcodes not found" ])
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
# libiberty is not required on Ubuntu
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ])
AC_CHECK_LIB(sframe, frame, [ HSDIS_LIBS="$HSDIS_LIBS -lsframe" ], )
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
elif test "x$BINUTILS_INSTALL_DIR" != x; then
disasm_header="\"$BINUTILS_INSTALL_DIR/include/dis-asm.h\""
if (test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a || \
test -e $BINUTILS_INSTALL_DIR/lib64/libbfd.a) && \
(test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a || \
test -e $BINUTILS_INSTALL_DIR/lib64/libopcodes.a) && \
(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
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB -I$BINUTILS_INSTALL_DIR/include"
# libiberty ignores --libdir and may be installed in $BINUTILS_INSTALL_DIR/lib, $BINUTILS_INSTALL_DIR/lib32
# or $BINUTILS_INSTALL_DIR/lib64, depending on system setup
LIBOPCODES_LIB=""
LIBBFD_LIB=""
LIBIBERTY_LIB=""
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a; then
LIBBFD_LIB="$BINUTILS_INSTALL_DIR/lib/libbfd.a"
else
LIBBFD_LIB="$BINUTILS_INSTALL_DIR/lib64/libbfd.a"
fi
if test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a; then
LIBOPCODES_LIB="$BINUTILS_INSTALL_DIR/lib/libopcodes.a"
else
LIBOPCODES_LIB="$BINUTILS_INSTALL_DIR/lib64/libopcodes.a"
fi
if test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib/libiberty.a"
elif test -e $BINUTILS_INSTALL_DIR/lib32/libiberty.a; then
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib32/libiberty.a"
else
LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib64/libiberty.a"
fi
HSDIS_LIBS="$LIBBFD_LIB $LIBOPCODES_LIB $LIBIBERTY_LIB"
# If we have libsframe add it.
if test -e $BINUTILS_INSTALL_DIR/lib/libsframe.a; then
HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_INSTALL_DIR/lib/libsframe.a"
fi
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], AC_MSG_ERROR([libz not found]))
else
AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/lib[64] must contain libbfd.a, libopcodes.a and libiberty.a"])
fi
fi
AC_MSG_CHECKING([Checking binutils API])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $disasm_header],[[init_disassemble_info(0, 0, 0, 0);]])],
[
AC_MSG_RESULT([New API])
HSDIS_CFLAGS="$HSDIS_CFLAGS -DBINUTILS_NEW_API"
],
[
AC_MSG_RESULT([Old API])
]
)
AC_MSG_CHECKING([for binutils to use with hsdis])
case "x$BINUTILS_INSTALL_DIR" in
xsystem)
if test "x$OPENJDK_TARGET_OS" != xlinux; then
AC_MSG_RESULT([invalid])
AC_MSG_ERROR([binutils on system is supported for Linux only])
elif test "x$binutils_system_error" = x; then
AC_MSG_RESULT([system])
HSDIS_CFLAGS="$HSDIS_CFLAGS -DSYSTEM_BINUTILS"
else
AC_MSG_RESULT([invalid])
AC_MSG_ERROR([$binutils_system_error])
fi
;;
x)
AC_MSG_RESULT([missing])
AC_MSG_NOTICE([--with-hsdis=binutils requires specifying a binutils installation.])
AC_MSG_NOTICE([Download binutils from https://www.gnu.org/software/binutils and unpack it,])
AC_MSG_NOTICE([and point --with-binutils-src to the resulting directory, or use])
AC_MSG_NOTICE([--with-binutils to point to a pre-built binutils installation.])
AC_MSG_ERROR([Cannot continue])
;;
*)
if test "x$HSDIS_LIBS" != x; then
AC_MSG_RESULT([$BINUTILS_INSTALL_DIR])
else
AC_MSG_RESULT([invalid])
AC_MSG_ERROR([$BINUTILS_INSTALL_DIR does not contain a proper binutils installation])
fi
;;
esac
])
################################################################################
#
# Determine if hsdis should be built, and if so, with which backend.
#
AC_DEFUN_ONCE([LIB_SETUP_HSDIS],
[
AC_ARG_WITH([hsdis], [AS_HELP_STRING([--with-hsdis],
[what hsdis backend to use ('none', 'capstone', 'llvm', 'binutils') @<:@none@:>@])])
UTIL_ARG_ENABLE(NAME: hsdis-bundling, DEFAULT: false,
RESULT: ENABLE_HSDIS_BUNDLING,
DESC: [enable bundling of hsdis to allow HotSpot disassembly out-of-the-box])
AC_MSG_CHECKING([what hsdis backend to use])
if test "x$with_hsdis" = xyes; then
AC_MSG_ERROR([--with-hsdis must have a value])
elif test "x$with_hsdis" = xnone || test "x$with_hsdis" = xno || test "x$with_hsdis" = x; then
HSDIS_BACKEND=none
AC_MSG_RESULT(['none', hsdis will not be built])
elif test "x$with_hsdis" = xcapstone; then
HSDIS_BACKEND=capstone
AC_MSG_RESULT(['capstone'])
LIB_SETUP_HSDIS_CAPSTONE
elif test "x$with_hsdis" = xllvm; then
HSDIS_BACKEND=llvm
AC_MSG_RESULT(['llvm'])
LIB_SETUP_HSDIS_LLVM
elif test "x$with_hsdis" = xbinutils; then
HSDIS_BACKEND=binutils
AC_MSG_RESULT(['binutils'])
LIB_SETUP_HSDIS_BINUTILS
else
AC_MSG_RESULT([invalid])
AC_MSG_ERROR([Incorrect hsdis backend "$with_hsdis"])
fi
AC_SUBST(HSDIS_BACKEND)
AC_SUBST(HSDIS_CFLAGS)
AC_SUBST(HSDIS_LDFLAGS)
AC_SUBST(HSDIS_LIBS)
AC_SUBST(CAPSTONE_ARCH_AARCH64_NAME)
AC_MSG_CHECKING([if hsdis should be bundled])
if test "x$ENABLE_HSDIS_BUNDLING" = "xtrue"; then
if test "x$HSDIS_BACKEND" = xnone; then
AC_MSG_RESULT([no, backend missing])
AC_MSG_ERROR([hsdis-bundling requires a hsdis backend. Please set --with-hsdis=<backend>]);
fi
AC_MSG_RESULT([yes])
if test "x$HSDIS_BACKEND" = xbinutils; then
AC_MSG_WARN([The resulting build might not be redistributable. Seek legal advice before distributing.])
fi
else
AC_MSG_RESULT([no])
fi
AC_SUBST(ENABLE_HSDIS_BUNDLING)
])
|