|
| 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 | +]) |
0 commit comments