jdk

Форк
0
/
lib-hsdis.m4 
399 строк · 15.5 Кб
1
#
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.
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 Windows
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
  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]])],
70
    [
71
      AC_MSG_RESULT([AARCH64])
72
      CAPSTONE_ARCH_AARCH64_NAME="AARCH64"
73
    ],
74
    [
75
      AC_MSG_RESULT([ARM64])
76
      CAPSTONE_ARCH_AARCH64_NAME="ARM64"
77
    ]
78
  )
79
])
80

81
################################################################################
82
#
83
# Helper function to setup hsdis using LLVM
84
#
85
AC_DEFUN([LIB_SETUP_HSDIS_LLVM],
86
[
87
  AC_ARG_WITH([llvm], [AS_HELP_STRING([--with-llvm],
88
      [where to find the LLVM files needed for hsdis/llvm])])
89

90
  if test "x$with_llvm" != x; then
91
    LLVM_DIR="$with_llvm"
92
  fi
93

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])
101
      fi
102
    else
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])
107
      fi
108
    fi
109

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`
114
  else
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])
118
    fi
119

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])
125
    fi
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])
130
    fi
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])
134
    fi
135
    HSDIS_CFLAGS="-I$LLVM_DIR/include"
136
    HSDIS_LDFLAGS="-libpath:$LLVM_DIR/lib"
137
    HSDIS_LIBS="llvm-c.lib"
138
  fi
139
])
140

141
################################################################################
142
#
143
# Helper function to build binutils from source.
144
#
145
AC_DEFUN([LIB_BUILD_BINUTILS],
146
[
147
  BINUTILS_SRC="$with_binutils_src"
148
  UTIL_FIXUP_PATH(BINUTILS_SRC)
149

150
  BINUTILS_BUILD_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
151
  BINUTILS_INSTALL_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils-install"
152

153
  if ! test -d $BINUTILS_SRC; then
154
    AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
155
  fi
156
  if ! test -x $BINUTILS_SRC/configure; then
157
    AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
158
  fi
159

160
  if ! test -d $BINUTILS_BUILD_DIR; then
161
    $MKDIR -p $BINUTILS_BUILD_DIR
162
  fi
163

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])
169
  else
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"
175
      else
176
        target_base="$OPENJDK_TARGET_CPU-w64-mingw32"
177
      fi
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])
187
      else
188
        AC_MSG_NOTICE([Using compiler $binutils_cc with version $compiler_version])
189
      fi
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"
193
      else
194
        binutils_target=""
195
      fi
196
    else
197
      binutils_cc="$CC $SYSROOT_CFLAGS"
198
      if test "x$COMPILE_TYPE" = xcross; then
199
        binutils_target="--host=$OPENJDK_TARGET_AUTOCONF_NAME"
200
      else
201
        binutils_target=""
202
      fi
203
    fi
204
    binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
205

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])
208
    saved_dir=`pwd`
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])
214
    fi
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])
220
    fi
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])
226
    fi
227
    cd $saved_dir
228
    AC_MSG_NOTICE([Building of binutils done])
229
  fi
230
])
231

232
################################################################################
233
#
234
# Helper function to setup hsdis using binutils
235
#
236
AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
237
[
238
  AC_ARG_WITH([binutils], [AS_HELP_STRING([--with-binutils],
239
      [where to find the binutils files needed for hsdis/binutils])])
240

241
  AC_ARG_WITH([binutils-src], [AS_HELP_STRING([--with-binutils-src],
242
      [where to find the binutils source for building])])
243

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.
247
    LIB_BUILD_BINUTILS
248
  fi
249

250
  if test "x$with_binutils" != x; then
251
    BINUTILS_INSTALL_DIR="$with_binutils"
252
  fi
253

254
  binutils_system_error=""
255
  HSDIS_LDFLAGS=""
256
  HSDIS_LIBS=""
257
  disasm_header="<dis-asm.h>"
258

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"
273

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
276
      LIBIBERTY_LIB=""
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"
281
      else
282
        LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib64/libiberty.a"
283
      fi
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"
288
      fi
289
      AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], AC_MSG_ERROR([libz not found]))
290
    else
291
      AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/lib[64] must contain libbfd.a, libopcodes.a and libiberty.a"])
292
    fi
293
  fi
294

295
  AC_MSG_CHECKING([Checking binutils API])
296
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $disasm_header],[[init_disassemble_info(0, 0, 0, 0);]])],
297
    [
298
      AC_MSG_RESULT([New API])
299
      HSDIS_CFLAGS="$HSDIS_CFLAGS -DBINUTILS_NEW_API"
300
    ],
301
    [
302
      AC_MSG_RESULT([Old API])
303
    ]
304
  )
305

306
  AC_MSG_CHECKING([for binutils to use with hsdis])
307
  case "x$BINUTILS_INSTALL_DIR" in
308
    xsystem)
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"
315
      else
316
        AC_MSG_RESULT([invalid])
317
        AC_MSG_ERROR([$binutils_system_error])
318
      fi
319
      ;;
320
    x)
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])
327
      ;;
328
    *)
329
      if test "x$HSDIS_LIBS" != x; then
330
        AC_MSG_RESULT([$BINUTILS_INSTALL_DIR])
331
      else
332
        AC_MSG_RESULT([invalid])
333
        AC_MSG_ERROR([$BINUTILS_INSTALL_DIR does not contain a proper binutils installation])
334
      fi
335
      ;;
336
  esac
337
])
338

339
################################################################################
340
#
341
# Determine if hsdis should be built, and if so, with which backend.
342
#
343
AC_DEFUN_ONCE([LIB_SETUP_HSDIS],
344
[
345
  AC_ARG_WITH([hsdis], [AS_HELP_STRING([--with-hsdis],
346
      [what hsdis backend to use ('none', 'capstone', 'llvm', 'binutils') @<:@none@:>@])])
347

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])
351

352
  AC_MSG_CHECKING([what hsdis backend to use])
353

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
357
    HSDIS_BACKEND=none
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'])
362

363
    LIB_SETUP_HSDIS_CAPSTONE
364
  elif test "x$with_hsdis" = xllvm; then
365
    HSDIS_BACKEND=llvm
366
    AC_MSG_RESULT(['llvm'])
367

368
    LIB_SETUP_HSDIS_LLVM
369
  elif test "x$with_hsdis" = xbinutils; then
370
    HSDIS_BACKEND=binutils
371
    AC_MSG_RESULT(['binutils'])
372

373
    LIB_SETUP_HSDIS_BINUTILS
374
  else
375
    AC_MSG_RESULT([invalid])
376
    AC_MSG_ERROR([Incorrect hsdis backend "$with_hsdis"])
377
  fi
378

379
  AC_SUBST(HSDIS_BACKEND)
380
  AC_SUBST(HSDIS_CFLAGS)
381
  AC_SUBST(HSDIS_LDFLAGS)
382
  AC_SUBST(HSDIS_LIBS)
383
  AC_SUBST(CAPSTONE_ARCH_AARCH64_NAME)
384

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>]);
390
    fi
391
    AC_MSG_RESULT([yes])
392
    if test "x$HSDIS_BACKEND" = xbinutils; then
393
      AC_MSG_WARN([The resulting build might not be redistributable. Seek legal advice before distributing.])
394
    fi
395
  else
396
    AC_MSG_RESULT([no])
397
  fi
398
  AC_SUBST(ENABLE_HSDIS_BUNDLING)
399
])
400

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.