kernel: Fix perf build with binutils 2.40
[openwrt/staging/noltari.git] / target / linux / generic / backport-5.15 / 060-v6.0-02-tools-include-add-dis-asm-compat.h-to-handle-version.patch
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
5 differences
6
7 binutils changed the signature of init_disassemble_info(), which now causes
8 compilation failures for tools/{perf,bpf}, e.g. on debian unstable.
9
10 Relevant binutils commit:
11
12 https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
13
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.
17
18 It likely is worth adding a wrapper for disassember(), to avoid the already
19 existing DISASM_FOUR_ARGS_SIGNATURE ifdefery.
20
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)
34 ---
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
38
39 --- /dev/null
40 +++ b/tools/include/tools/dis-asm-compat.h
41 @@ -0,0 +1,55 @@
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
45 +
46 +#include <stdio.h>
47 +#include <dis-asm.h>
48 +
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*, ...);
53 +#endif
54 +
55 +/*
56 + * Trivial fprintf wrapper to be used as the fprintf_styled_func argument to
57 + * init_disassemble_info_compat() when normal fprintf suffices.
58 + */
59 +static inline int fprintf_styled(void *out,
60 + enum disassembler_style style,
61 + const char *fmt, ...)
62 +{
63 + va_list args;
64 + int r;
65 +
66 + (void)style;
67 +
68 + va_start(args, fmt);
69 + r = vfprintf(out, fmt, args);
70 + va_end(args);
71 +
72 + return r;
73 +}
74 +
75 +/*
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.
79 + */
80 +static inline void init_disassemble_info_compat(struct disassemble_info *info,
81 + void *stream,
82 + fprintf_ftype unstyled_func,
83 + fprintf_styled_ftype styled_func)
84 +{
85 +#ifdef DISASM_INIT_STYLED
86 + init_disassemble_info(info, stream,
87 + unstyled_func,
88 + styled_func);
89 +#else
90 + (void)styled_func;
91 + init_disassemble_info(info, stream,
92 + unstyled_func);
93 +#endif
94 +}
95 +
96 +#endif /* _TOOLS_DIS_ASM_COMPAT_H */