1 From 08ec5766e5cf7b24fdebefb83b6f760bceeddf40 Mon Sep 17 00:00:00 2001
2 From: Andres Freund <andres@anarazel.de>
3 Date: Sun, 31 Jul 2022 18:38:29 -0700
4 Subject: [PATCH 2/5] tools include: add dis-asm-compat.h to handle version
7 binutils changed the signature of init_disassemble_info(), which now causes
8 compilation failures for tools/{perf,bpf}, e.g. on debian unstable.
10 Relevant binutils commit:
12 https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
14 This commit introduces a wrapper for init_disassemble_info(), to avoid
15 spreading #ifdef DISASM_INIT_STYLED to a bunch of places. Subsequent
16 commits will use it to fix the build failures.
18 It likely is worth adding a wrapper for disassember(), to avoid the already
19 existing DISASM_FOUR_ARGS_SIGNATURE ifdefery.
21 Signed-off-by: Andres Freund <andres@anarazel.de>
22 Signed-off-by: Ben Hutchings <benh@debian.org>
23 Acked-by: Quentin Monnet <quentin@isovalent.com>
24 Cc: Alexei Starovoitov <ast@kernel.org>
25 Cc: Ben Hutchings <benh@debian.org>
26 Cc: Jiri Olsa <jolsa@kernel.org>
27 Cc: Quentin Monnet <quentin@isovalent.com>
28 Cc: Sedat Dilek <sedat.dilek@gmail.com>
29 Cc: bpf@vger.kernel.org
30 Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de
31 Link: https://lore.kernel.org/r/20220801013834.156015-4-andres@anarazel.de
32 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
33 (cherry picked from commit a45b3d6926231c3d024ea0de4f7bd967f83709ee)
35 tools/include/tools/dis-asm-compat.h | 55 ++++++++++++++++++++++++++++
36 1 file changed, 55 insertions(+)
37 create mode 100644 tools/include/tools/dis-asm-compat.h
40 +++ b/tools/include/tools/dis-asm-compat.h
42 +/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */
43 +#ifndef _TOOLS_DIS_ASM_COMPAT_H
44 +#define _TOOLS_DIS_ASM_COMPAT_H
49 +/* define types for older binutils version, to centralize ifdef'ery a bit */
50 +#ifndef DISASM_INIT_STYLED
51 +enum disassembler_style {DISASSEMBLER_STYLE_NOT_EMPTY};
52 +typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...);
56 + * Trivial fprintf wrapper to be used as the fprintf_styled_func argument to
57 + * init_disassemble_info_compat() when normal fprintf suffices.
59 +static inline int fprintf_styled(void *out,
60 + enum disassembler_style style,
61 + const char *fmt, ...)
68 + va_start(args, fmt);
69 + r = vfprintf(out, fmt, args);
76 + * Wrapper for init_disassemble_info() that hides version
77 + * differences. Depending on binutils version and architecture either
78 + * fprintf_func or fprintf_styled_func will be called.
80 +static inline void init_disassemble_info_compat(struct disassemble_info *info,
82 + fprintf_ftype unstyled_func,
83 + fprintf_styled_ftype styled_func)
85 +#ifdef DISASM_INIT_STYLED
86 + init_disassemble_info(info, stream,
91 + init_disassemble_info(info, stream,
96 +#endif /* _TOOLS_DIS_ASM_COMPAT_H */