File: jdk-8295795.patch

package info (click to toggle)
openjdk-21 21.0.9%2B10-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 821,840 kB
  • sloc: java: 5,620,360; xml: 1,643,607; cpp: 1,297,809; ansic: 421,231; asm: 404,850; objc: 21,018; sh: 15,299; javascript: 11,217; python: 6,895; makefile: 2,367; perl: 357; awk: 351; sed: 172; jsp: 24; csh: 3
file content (226 lines) | stat: -rw-r--r-- 9,846 bytes parent folder | download | duplicates (3)
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
Description: 8295795: hsdis does not build with binutils 2.39+
  binutils 2.39 changed the signature of init_disassemble_info,
  breaking the build.
  See https://lore.kernel.org/bpf/20220622231624.t63bkmkzphqvh3kx@alap3.anarazel.de/T/
Origin: upstream, https://github.com/openjdk/jdk/commit/c2efd7741202a5e3c209de62b8b5e6bd8ae7611a
Author: Robbin Ehn <rehn@openjdk.org>
Bug: https://bugs.openjdk.org/browse/JDK-8295795
Last-Update: 2024-03-12

diff --git a/make/autoconf/lib-hsdis.m4 b/make/autoconf/lib-hsdis.m4
index 974d0e8b793..987658bc411 100644
--- a/make/autoconf/lib-hsdis.m4
+++ b/make/autoconf/lib-hsdis.m4
@@ -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])
@@ -143,15 +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

-  if test -e $BINUTILS_DIR/bfd/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])
+  # 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.
@@ -190,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
@@ -223,41 +230,57 @@ 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
+  disasm_header="<dis-asm.h>"
+
+  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(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(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], [ binutils_system_error="libz not found" ])
+    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/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"
+  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/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_INSTALL_DIR/lib/libsframe.a; then
+        HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_INSTALL_DIR/lib/libsframe.a"
       fi
-      HSDIS_LDFLAGS=""
-      HSDIS_LIBS="$BINUTILS_DIR/bfd/libbfd.a $BINUTILS_DIR/opcodes/libopcodes.a $BINUTILS_DIR/libiberty/libiberty.a $BINUTILS_DIR/zlib/libz.a"
+      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])
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $disasm_header],[[void foo() {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_DIR" in
+  case "x$BINUTILS_INSTALL_DIR" in
     xsystem)
       if test "x$OPENJDK_TARGET_OS" != xlinux; then
         AC_MSG_RESULT([invalid])
@@ -280,10 +303,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
diff --git a/src/utils/hsdis/binutils/hsdis-binutils.c b/src/utils/hsdis/binutils/hsdis-binutils.c
index 28e374e05fc..86d49964f90 100644
--- a/src/utils/hsdis/binutils/hsdis-binutils.c
+++ b/src/utils/hsdis/binutils/hsdis-binutils.c
@@ -49,14 +49,16 @@
    HotSpot PrintAssembly option.
 */

-#ifndef SYSTEM_BINUTILS
-#include <config.h> /* required by bfd.h */
-#endif
-
 #include <errno.h>
 #include <inttypes.h>
 #include <string.h>

+#ifndef SYSTEM_BINUTILS
+/* defines for bfd.h */
+#define PACKAGE "hsdis"
+#define PACKAGE_VERSION 1
+#endif
+
 #include <bfd.h>
 #include <dis-asm.h>

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

+static fprintf_ftype target_fprintf_func = NULL;
+
+#ifdef BINUTILS_NEW_API
+static int wrapper_fprintf_styled_ftype(void *v, enum disassembler_style style_unused, const char* fmt, ...) {
+  char buffer[1024] = {};
+  va_list args;
+  int r;
+  va_start(args, fmt);
+  r = vsnprintf(buffer, sizeof(buffer), fmt, args);
+  va_end(args);
+  if (target_fprintf_func != NULL) {
+    return target_fprintf_func(v, "%s", buffer);
+  }
+  return r;
+}
+#endif
+
 static void init_disassemble_info_from_bfd(struct disassemble_info* dinfo,
                                            void *stream,
                                            fprintf_ftype fprintf_func,
                                            bfd* abfd,
                                            char* disassembler_options) {
+  target_fprintf_func = fprintf_func;
+#ifdef BINUTILS_NEW_API
+  init_disassemble_info(dinfo, stream, fprintf_func, wrapper_fprintf_styled_ftype);
+#else
   init_disassemble_info(dinfo, stream, fprintf_func);
+#endif

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