Skip to content

Commit c2efd77

Browse files
committedOct 23, 2023
8295795: hsdis does not build with binutils 2.39+
Reviewed-by: ihse, djelinski
1 parent 99de9bb commit c2efd77

File tree

2 files changed

+83
-36
lines changed

2 files changed

+83
-36
lines changed
 

‎make/autoconf/lib-hsdis.m4

+55-32
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
134134
BINUTILS_SRC="$with_binutils_src"
135135
UTIL_FIXUP_PATH(BINUTILS_SRC)
136136
137-
BINUTILS_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
137+
BINUTILS_BUILD_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils"
138+
BINUTILS_INSTALL_DIR="$CONFIGURESUPPORT_OUTPUTDIR/binutils-install"
138139
139140
if ! test -d $BINUTILS_SRC; then
140141
AC_MSG_ERROR([--with-binutils-src is not pointing to a directory])
@@ -143,15 +144,15 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
143144
AC_MSG_ERROR([--with-binutils-src does not look like a binutils source directory])
144145
fi
145146
146-
if ! test -d $BINUTILS_DIR; then
147-
$MKDIR -p $BINUTILS_DIR
147+
if ! test -d $BINUTILS_BUILD_DIR; then
148+
$MKDIR -p $BINUTILS_BUILD_DIR
148149
fi
149150
150-
if test -e $BINUTILS_DIR/bfd/libbfd.a && \
151-
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
152-
test -e $BINUTILS_DIR/libiberty/libiberty.a && \
153-
test -e $BINUTILS_DIR/zlib/libz.a; then
154-
AC_MSG_NOTICE([Found binutils binaries in binutils source directory -- not building])
151+
# We don't know the version, not checking for libsframe.a
152+
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \
153+
test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \
154+
test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
155+
AC_MSG_NOTICE([Found binutils binaries in binutils install directory -- not building])
155156
else
156157
# On Windows, we cannot build with the normal Microsoft CL, but must instead use
157158
# a separate mingw toolchain.
@@ -190,20 +191,26 @@ AC_DEFUN([LIB_BUILD_BINUTILS],
190191
binutils_cflags="$binutils_cflags $MACHINE_FLAG $JVM_PICFLAG $C_O_FLAG_NORM"
191192
192193
AC_MSG_NOTICE([Running binutils configure])
193-
AC_MSG_NOTICE([configure command line: cd $BINUTILS_DIR && $BINUTILS_SRC/configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target])
194+
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])
194195
saved_dir=`pwd`
195-
cd "$BINUTILS_DIR"
196-
$BINUTILS_SRC/configure --disable-nls CFLAGS="$binutils_cflags" CC="$binutils_cc" AR="$AR" $binutils_target
197-
if test $? -ne 0 || ! test -e $BINUTILS_DIR/Makefile; then
196+
cd "$BINUTILS_BUILD_DIR"
197+
$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
198+
if test $? -ne 0 || ! test -e $BINUTILS_BUILD_DIR/Makefile; then
198199
AC_MSG_NOTICE([Automatic building of binutils failed on configure. Try building it manually])
199200
AC_MSG_ERROR([Cannot continue])
200201
fi
201202
AC_MSG_NOTICE([Running binutils make])
202-
$MAKE all-opcodes
203+
$MAKE all-opcodes all-libiberty
203204
if test $? -ne 0; then
204205
AC_MSG_NOTICE([Automatic building of binutils failed on make. Try building it manually])
205206
AC_MSG_ERROR([Cannot continue])
206207
fi
208+
AC_MSG_NOTICE([Running binutils make install])
209+
$MAKE install-opcodes install-libiberty
210+
if test $? -ne 0; then
211+
AC_MSG_NOTICE([Automatic building, install step, of binutils failed on make. Try building it manually])
212+
AC_MSG_ERROR([Cannot continue])
213+
fi
207214
cd $saved_dir
208215
AC_MSG_NOTICE([Building of binutils done])
209216
fi
@@ -223,41 +230,57 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
223230
224231
# We need the binutils static libs and includes.
225232
if test "x$with_binutils_src" != x; then
226-
# Try building the source first. If it succeeds, it sets $BINUTILS_DIR.
233+
# Try building the source first. If it succeeds, it sets $BINUTILS_INSTALL_DIR.
227234
LIB_BUILD_BINUTILS
228235
fi
229236
230237
if test "x$with_binutils" != x; then
231-
BINUTILS_DIR="$with_binutils"
238+
BINUTILS_INSTALL_DIR="$with_binutils"
232239
fi
233240
234241
binutils_system_error=""
242+
HSDIS_LDFLAGS=""
235243
HSDIS_LIBS=""
236-
if test "x$BINUTILS_DIR" = xsystem; then
244+
disasm_header="<dis-asm.h>"
245+
246+
if test "x$BINUTILS_INSTALL_DIR" = xsystem; then
237247
AC_CHECK_LIB(bfd, bfd_openr, [ HSDIS_LIBS="-lbfd" ], [ binutils_system_error="libbfd not found" ])
238248
AC_CHECK_LIB(opcodes, disassembler, [ HSDIS_LIBS="$HSDIS_LIBS -lopcodes" ], [ binutils_system_error="libopcodes not found" ])
249+
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
239250
# libiberty is not required on Ubuntu
240251
AC_CHECK_LIB(iberty, xmalloc, [ HSDIS_LIBS="$HSDIS_LIBS -liberty" ])
241-
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
252+
AC_CHECK_LIB(sframe, frame, [ HSDIS_LIBS="$HSDIS_LIBS -lsframe" ], )
242253
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
243-
elif test "x$BINUTILS_DIR" != x; then
244-
if test -e $BINUTILS_DIR/bfd/libbfd.a && \
245-
test -e $BINUTILS_DIR/opcodes/libopcodes.a && \
246-
test -e $BINUTILS_DIR/libiberty/libiberty.a && \
247-
test -e $BINUTILS_DIR/zlib/libz.a; then
248-
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB"
249-
if test -n "$BINUTILS_SRC"; then
250-
HSDIS_CFLAGS="$HSDIS_CFLAGS -I$BINUTILS_SRC/include -I$BINUTILS_DIR/bfd"
251-
else
252-
HSDIS_CFLAGS="$HSDIS_CFLAGS -I$BINUTILS_DIR/include -I$BINUTILS_DIR/bfd"
254+
elif test "x$BINUTILS_INSTALL_DIR" != x; then
255+
disasm_header="\"$BINUTILS_INSTALL_DIR/include/dis-asm.h\""
256+
if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \
257+
test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \
258+
test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then
259+
HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB -I$BINUTILS_INSTALL_DIR/include"
260+
HSDIS_LIBS="$BINUTILS_INSTALL_DIR/lib/libbfd.a $BINUTILS_INSTALL_DIR/lib/libopcodes.a $BINUTILS_INSTALL_DIR/lib/libiberty.a"
261+
# If we have libsframe add it.
262+
if test -e $BINUTILS_INSTALL_DIR/lib/libsframe.a; then
263+
HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_INSTALL_DIR/lib/libsframe.a"
253264
fi
254-
HSDIS_LDFLAGS=""
255-
HSDIS_LIBS="$BINUTILS_DIR/bfd/libbfd.a $BINUTILS_DIR/opcodes/libopcodes.a $BINUTILS_DIR/libiberty/libiberty.a $BINUTILS_DIR/zlib/libz.a"
265+
AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], AC_MSG_ERROR([libz not found]))
266+
else
267+
AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/libs/ must contain libbfd.a, libopcodes.a, libiberty.a"])
Has conversations. Original line has conversations.
256268
fi
257269
fi
258270
271+
AC_MSG_CHECKING([Checking binutils API])
272+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $disasm_header],[[void foo() {init_disassemble_info(0, 0, 0, 0);}]])],
273+
[
274+
AC_MSG_RESULT([New API])
275+
HSDIS_CFLAGS="$HSDIS_CFLAGS -DBINUTILS_NEW_API"
276+
],
277+
[
278+
AC_MSG_RESULT([Old API])
279+
]
280+
)
281+
259282
AC_MSG_CHECKING([for binutils to use with hsdis])
260-
case "x$BINUTILS_DIR" in
283+
case "x$BINUTILS_INSTALL_DIR" in
261284
xsystem)
262285
if test "x$OPENJDK_TARGET_OS" != xlinux; then
263286
AC_MSG_RESULT([invalid])
@@ -280,10 +303,10 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS],
280303
;;
281304
*)
282305
if test "x$HSDIS_LIBS" != x; then
283-
AC_MSG_RESULT([$BINUTILS_DIR])
306+
AC_MSG_RESULT([$BINUTILS_INSTALL_DIR])
284307
else
285308
AC_MSG_RESULT([invalid])
286-
AC_MSG_ERROR([$BINUTILS_DIR does not contain a proper binutils installation])
309+
AC_MSG_ERROR([$BINUTILS_INSTALL_DIR does not contain a proper binutils installation])
287310
fi
288311
;;
289312
esac

‎src/utils/hsdis/binutils/hsdis-binutils.c

+28-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@
4949
HotSpot PrintAssembly option.
5050
*/
5151

52-
#ifndef SYSTEM_BINUTILS
53-
#include <config.h> /* required by bfd.h */
54-
#endif
55-
5652
#include <errno.h>
5753
#include <inttypes.h>
5854
#include <string.h>
5955

56+
#ifndef SYSTEM_BINUTILS
57+
/* defines for bfd.h */
58+
#define PACKAGE "hsdis"
59+
#define PACKAGE_VERSION 1
60+
#endif
61+
6062
#include <bfd.h>
6163
#include <dis-asm.h>
6264

@@ -555,12 +557,34 @@ static void parse_fake_insn(disassembler_ftype dfn,
555557
dinfo->fprintf_func = fprintf_func;
556558
}
557559

560+
static fprintf_ftype target_fprintf_func = NULL;
561+
562+
#ifdef BINUTILS_NEW_API
563+
static int wrapper_fprintf_styled_ftype(void *v, enum disassembler_style style_unused, const char* fmt, ...) {
564+
char buffer[1024] = {};
565+
va_list args;
566+
int r;
567+
va_start(args, fmt);
568+
r = vsnprintf(buffer, sizeof(buffer), fmt, args);
569+
va_end(args);
570+
if (target_fprintf_func != NULL) {
571+
return target_fprintf_func(v, "%s", buffer);
572+
}
573+
return r;
574+
}
575+
#endif
576+
558577
static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo,
559578
void *stream,
560579
fprintf_ftype fprintf_func,
561580
bfd* abfd,
562581
char* disassembler_options) {
582+
target_fprintf_func = fprintf_func;
583+
#ifdef BINUTILS_NEW_API
584+
init_disassemble_info(dinfo, stream, fprintf_func, wrapper_fprintf_styled_ftype);
585+
#else
563586
init_disassemble_info(dinfo, stream, fprintf_func);
587+
#endif
564588

565589
dinfo->flavour = bfd_get_flavour(abfd);
566590
dinfo->arch = bfd_get_arch(abfd);

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Oct 23, 2023

@openjdk-notifier[bot]
Please sign in to comment.