honggfuzz/0002-linux-bfd-use-DIAGNOSTIC_ERROR_SWITCH-define-to-figu.patch
Martin Pluskal 20cb796de7 Accepting request 999245 from home:cgiboudeaux:branches:devel:tools
- Update to 2.5
  * fixed build for Android NDK >= 23
  * fixed build for CygWin
  * improved hfuzz-cc, so it supports -x correctly
  * error returned if unknown cmd-line parameters are provided
  * support for thread CPU pinning
  * various fixes for *BSD
  * increased number of dictionary entries (to 8192)
- Add upstream changes to fix build with recent binutils:
  * 0001-Always-pass-4-arguments-to-init_disassemble_info-no-.patch
  * 0002-linux-bfd-use-DIAGNOSTIC_ERROR_SWITCH-define-to-figu.patch
  * 0003-linux-bfd-cover-include-diagnostics.h-with-__has_inc.patch

OBS-URL: https://build.opensuse.org/request/show/999245
OBS-URL: https://build.opensuse.org/package/show/devel:tools/honggfuzz?expand=0&rev=25
2022-08-29 06:57:05 +00:00

84 lines
3.0 KiB
Diff

From e35ef0db3e45516ea34ffc820f13ec462a6cff03 Mon Sep 17 00:00:00 2001
From: Robert Swiecki <robert@swiecki.net>
Date: Mon, 6 Jun 2022 18:01:41 +0200
Subject: [PATCH 2/3] linux/bfd: use DIAGNOSTIC_ERROR_SWITCH define to figure
out if init_disassemble_info takes 3 or 4 arguments
---
linux/bfd.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/linux/bfd.c b/linux/bfd.c
index 986081e..e9d9c2b 100644
--- a/linux/bfd.c
+++ b/linux/bfd.c
@@ -26,6 +26,7 @@
#include "linux/bfd.h"
#include <bfd.h>
+#include <diagnostics.h>
#include <dis-asm.h>
#include <inttypes.h>
#include <pthread.h>
@@ -61,7 +62,15 @@ typedef struct {
*/
#if defined(FOR_EACH_DISASSEMBLER_OPTION)
#define _HF_BFD_GE_2_29
-#endif
+#endif /* defined(FOR_EACH_DISASSEMBLER_OPTION) */
+/*
+ * binutils/libopcode has an unstable public interface. At some point in time the function
+ * init_disassemble_info() started taking 4 arguments instead of 3. Try to differentiate on the
+ * basis of some defines which apeared around the same time.
+ */
+#if defined(DIAGNOSTIC_ERROR_SWITCH)
+#define _HF_DISASM_4_ARGS
+#endif /* defined(DIAGNOSTIC_ERROR_SWITCH) */
static pthread_mutex_t arch_bfd_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -197,7 +206,9 @@ static int arch_bfdFPrintF(void* buf, const char* fmt, ...) {
return ret;
}
-static int arch_bfdFPrintFStyled(void* buf, int style HF_ATTR_UNUSED, const char* fmt, ...) {
+#if defined(_HF_DISASM_4_ARGS)
+static int arch_bfdFPrintFStyled(
+ void* buf, enum disassembler_style style HF_ATTR_UNUSED, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
int ret = util_vssnprintf(buf, _HF_INSTR_SZ, fmt, args);
@@ -205,15 +216,7 @@ static int arch_bfdFPrintFStyled(void* buf, int style HF_ATTR_UNUSED, const char
return ret;
}
-
-/*
- * binutils/libopcode has an unstable public interface. At some point in time the function
- * init_disassemble_info() started taking 4 arguments instead of 3. Always pass 4 arguments to it,
- * no matter what's the declaration.
- */
-static void arch_bfdInitDisassembleInfoStub(
- struct disassemble_info* info, char* instr, void* bfd_printf_func, void* bfd_printf_styled_func)
- __attribute__((weakref, alias("init_disassemble_info")));
+#endif /* defined(_HF_DISASM_4_ARGS) */
void arch_bfdDisasm(pid_t pid, uint8_t* mem, size_t size, char* instr) {
MX_SCOPED_LOCK(&arch_bfd_mutex);
@@ -247,7 +250,11 @@ void arch_bfdDisasm(pid_t pid, uint8_t* mem, size_t size, char* instr) {
struct disassemble_info info = {};
- arch_bfdInitDisassembleInfoStub(&info, instr, arch_bfdFPrintF, arch_bfdFPrintFStyled);
+#if defined(_HF_DISASM_4_ARGS)
+ init_disassemble_info(&info, instr, arch_bfdFPrintF, arch_bfdFPrintFStyled);
+#else /* defined(_HF_DISASM_4_ARGS) */
+ init_disassemble_info(&info, instr, arch_bfdFPrintF);
+#endif /* defined(_HF_DISASM_4_ARGS) */
info.arch = bfd_get_arch(bfdh);
info.mach = bfd_get_mach(bfdh);
info.buffer = mem;
--
2.37.2