Skip to content

Commit

Permalink
Fix installed binutils
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Oct 19, 2023
1 parent 57d5a24 commit 36226f8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
82 changes: 40 additions & 42 deletions make/autoconf/lib-hsdis.m4
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
BINUTILS_SRC="$with_binutils_src"
UTIL_FIXUP_PATH(BINUTILS_SRC)
BINUTILS_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
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])
Expand All @@ -143,16 +144,15 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
fi
if ! test -d $BINUTILS_DIR; then
$MKDIR -p $BINUTILS_DIR
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_DIR/bfd/.libs/libbfd.a && \
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
test -e $BINUTILS_DIR/libiberty/libiberty.a && \
test -e $BINUTILS_DIR/zlib/libz.a ; then
AC_MSG_NOTICE([Found binutils binaries in binutils source directory -- not building])
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.
Expand Down Expand Up @@ -191,20 +191,26 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
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_DIR && $BINUTILS_SRC/configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target])
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_DIR"
$BINUTILS_SRC/configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target
if test $? -ne 0 || ! test -e $BINUTILS_DIR/Makefile; then
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
$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
Expand All @@ -224,51 +230,43 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
# 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_DIR.
# 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_DIR="$with_binutils"
BINUTILS_INSTALL_DIR="$with_binutils"
fi
binutils_system_error=""
HSDIS_LDFLAGS=""
HSDIS_LIBS=""
if test "x$BINUTILS_DIR" = xsystem; then
if test "x$BINUTILS_INSTALL_DIR" = xsystem; then
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd" ], [ binutils_system_error="libbfd not found" ])
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes" ], [ binutils_system_error="libopcodes not found" ])
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ], [ binutils_system_error="libiberty not found" ])
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
// If we find them
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_DIR" != x; then
if test -e $BINUTILS_DIR/bfd/.libs/libbfd.a && \
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
test -e $BINUTILS_DIR/libiberty/libiberty.a && \
test -e $BINUTILS_DIR/zlib/libz.a; then
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
if test -n "$BINUTILS_SRC"; then
HSDIS_CFLAGS="$HSDIS_CFLAGS -I$BINUTILS_SRC/include -I$BINUTILS_DIR/bfd"
else
HSDIS_CFLAGS="$HSDIS_CFLAGS -I$BINUTILS_DIR/include -I$BINUTILS_DIR/bfd"
fi
HSDIS_LDFLAGS=""
HSDIS_LIBS="$BINUTILS_DIR/bfd/.libs/libbfd.a $BINUTILS_DIR/opcodes/libopcodes.a $BINUTILS_DIR/libiberty/libiberty.a $BINUTILS_DIR/zlib/libz.a"
elif test "x$BINUTILS_INSTALL_DIR" != x; then
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
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB -I$BINUTILS_INSTALL_DIR/include"
HSDIS_LIBS="$BINUTILS_INSTALL_DIR/lib/libbfd.a $BINUTILS_INSTALL_DIR/lib/libopcodes.a $BINUTILS_INSTALL_DIR/lib/libiberty.a"
# If we have libsframe add it.
if test -e $BINUTILS_DIR/libsframe/.libs/libsframe.a; then
HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_DIR/libsframe/.libs/libsframe.a"
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/libs/ must contain libbfd.a, libopcodes.a, libiberty.a"])
fi
fi
AC_MSG_CHECKING([Checking binutils API])
if test -n "$BINUTILS_SRC"; then
binutils_include_dir=$BINUTILS_SRC/include
else
binutils_include_dir=$BINUTILS_DIR/include
fi
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "$binutils_include_dir/dis-asm.h"],[[void foo() {init_disassemble_info(0, 0, 0, 0);}]])],
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "$BINUTILS_INSTALL_DIR/include/dis-asm.h"],[[void foo() {init_disassemble_info(0, 0, 0, 0);}]])],
[
AC_MSG_RESULT([New API])
HSDIS_CFLAGS="$HSDIS_CFLAGS -DBINUTILS_NEW_API"
Expand All @@ -279,7 +277,7 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
)
AC_MSG_CHECKING([for binutils to use with hsdis])
case "x$BINUTILS_DIR" in
case "x$BINUTILS_INSTALL_DIR" in
xsystem)
if test "x$OPENJDK_TARGET_OS" != xlinux; then
AC_MSG_RESULT([invalid])
Expand All @@ -302,10 +300,10 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
;;
*)
if test "x$HSDIS_LIBS" != x; then
AC_MSG_RESULT([$BINUTILS_DIR])
AC_MSG_RESULT([$BINUTILS_INSTALL_DIR])
else
AC_MSG_RESULT([invalid])
AC_MSG_ERROR([$BINUTILS_DIR does not contain a proper binutils installation])
AC_MSG_ERROR([$BINUTILS_INSTALL_DIR does not contain a proper binutils installation])
fi
;;
esac
Expand Down
9 changes: 4 additions & 5 deletions src/utils/hsdis/binutils/hsdis-binutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@
HotSpot PrintAssembly option.
*/

#ifndef SYSTEM_BINUTILS
#include <config.h> /* required by bfd.h */
#endif

#include <errno.h>
#include <inttypes.h>
#include <string.h>

#include <libiberty.h>
/* defines for bfd.h */
#define PACKAGE "hsdis"
#define PACKAGE_VERSION 1

#include <bfd.h>
#include <dis-asm.h>

Expand Down

0 comments on commit 36226f8

Please sign in to comment.