Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools include: add dis-asm-compat.h to handle version differences

binutils changed the signature of init_disassemble_info(), which now causes
compilation failures for tools/{perf,bpf}, e.g. on debian unstable.

Relevant binutils commit:

https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07

This commit introduces a wrapper for init_disassemble_info(), to avoid
spreading #ifdef DISASM_INIT_STYLED to a bunch of places. Subsequent
commits will use it to fix the build failures.

It likely is worth adding a wrapper for disassember(), to avoid the already
existing DISASM_FOUR_ARGS_SIGNATURE ifdefery.

Signed-off-by: Andres Freund <andres@anarazel.de>
Signed-off-by: Ben Hutchings <benh@debian.org>
Acked-by: Quentin Monnet <quentin@isovalent.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Ben Hutchings <benh@debian.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Sedat Dilek <sedat.dilek@gmail.com>
Cc: bpf@vger.kernel.org
Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de
Link: https://lore.kernel.org/r/20220801013834.156015-4-andres@anarazel.de
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andres Freund and committed by
Arnaldo Carvalho de Melo
a45b3d69 516ddaad

+55
+55
tools/include/tools/dis-asm-compat.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */ 2 + #ifndef _TOOLS_DIS_ASM_COMPAT_H 3 + #define _TOOLS_DIS_ASM_COMPAT_H 4 + 5 + #include <stdio.h> 6 + #include <dis-asm.h> 7 + 8 + /* define types for older binutils version, to centralize ifdef'ery a bit */ 9 + #ifndef DISASM_INIT_STYLED 10 + enum disassembler_style {DISASSEMBLER_STYLE_NOT_EMPTY}; 11 + typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...); 12 + #endif 13 + 14 + /* 15 + * Trivial fprintf wrapper to be used as the fprintf_styled_func argument to 16 + * init_disassemble_info_compat() when normal fprintf suffices. 17 + */ 18 + static inline int fprintf_styled(void *out, 19 + enum disassembler_style style, 20 + const char *fmt, ...) 21 + { 22 + va_list args; 23 + int r; 24 + 25 + (void)style; 26 + 27 + va_start(args, fmt); 28 + r = vfprintf(out, fmt, args); 29 + va_end(args); 30 + 31 + return r; 32 + } 33 + 34 + /* 35 + * Wrapper for init_disassemble_info() that hides version 36 + * differences. Depending on binutils version and architecture either 37 + * fprintf_func or fprintf_styled_func will be called. 38 + */ 39 + static inline void init_disassemble_info_compat(struct disassemble_info *info, 40 + void *stream, 41 + fprintf_ftype unstyled_func, 42 + fprintf_styled_ftype styled_func) 43 + { 44 + #ifdef DISASM_INIT_STYLED 45 + init_disassemble_info(info, stream, 46 + unstyled_func, 47 + styled_func); 48 + #else 49 + (void)styled_func; 50 + init_disassemble_info(info, stream, 51 + unstyled_func); 52 + #endif 53 + } 54 + 55 + #endif /* _TOOLS_DIS_ASM_COMPAT_H */