060-v6.0-02-tools-include-add-dis-asm-compat.h-to-handle-version.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 08ec5766e5cf7b24fdebefb83b6f760bceeddf40 Mon Sep 17 00:00:00 2001
  2. From: Andres Freund <[email protected]>
  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. binutils changed the signature of init_disassemble_info(), which now causes
  7. compilation failures for tools/{perf,bpf}, e.g. on debian unstable.
  8. Relevant binutils commit:
  9. https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07
  10. This commit introduces a wrapper for init_disassemble_info(), to avoid
  11. spreading #ifdef DISASM_INIT_STYLED to a bunch of places. Subsequent
  12. commits will use it to fix the build failures.
  13. It likely is worth adding a wrapper for disassember(), to avoid the already
  14. existing DISASM_FOUR_ARGS_SIGNATURE ifdefery.
  15. Signed-off-by: Andres Freund <[email protected]>
  16. Signed-off-by: Ben Hutchings <[email protected]>
  17. Acked-by: Quentin Monnet <[email protected]>
  18. Cc: Alexei Starovoitov <[email protected]>
  19. Cc: Ben Hutchings <[email protected]>
  20. Cc: Jiri Olsa <[email protected]>
  21. Cc: Quentin Monnet <[email protected]>
  22. Cc: Sedat Dilek <[email protected]>
  23. Cc: [email protected]
  24. Link: http://lore.kernel.org/lkml/[email protected]
  25. Link: https://lore.kernel.org/r/[email protected]
  26. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  27. (cherry picked from commit a45b3d6926231c3d024ea0de4f7bd967f83709ee)
  28. ---
  29. tools/include/tools/dis-asm-compat.h | 55 ++++++++++++++++++++++++++++
  30. 1 file changed, 55 insertions(+)
  31. create mode 100644 tools/include/tools/dis-asm-compat.h
  32. --- /dev/null
  33. +++ b/tools/include/tools/dis-asm-compat.h
  34. @@ -0,0 +1,55 @@
  35. +/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */
  36. +#ifndef _TOOLS_DIS_ASM_COMPAT_H
  37. +#define _TOOLS_DIS_ASM_COMPAT_H
  38. +
  39. +#include <stdio.h>
  40. +#include <dis-asm.h>
  41. +
  42. +/* define types for older binutils version, to centralize ifdef'ery a bit */
  43. +#ifndef DISASM_INIT_STYLED
  44. +enum disassembler_style {DISASSEMBLER_STYLE_NOT_EMPTY};
  45. +typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...);
  46. +#endif
  47. +
  48. +/*
  49. + * Trivial fprintf wrapper to be used as the fprintf_styled_func argument to
  50. + * init_disassemble_info_compat() when normal fprintf suffices.
  51. + */
  52. +static inline int fprintf_styled(void *out,
  53. + enum disassembler_style style,
  54. + const char *fmt, ...)
  55. +{
  56. + va_list args;
  57. + int r;
  58. +
  59. + (void)style;
  60. +
  61. + va_start(args, fmt);
  62. + r = vfprintf(out, fmt, args);
  63. + va_end(args);
  64. +
  65. + return r;
  66. +}
  67. +
  68. +/*
  69. + * Wrapper for init_disassemble_info() that hides version
  70. + * differences. Depending on binutils version and architecture either
  71. + * fprintf_func or fprintf_styled_func will be called.
  72. + */
  73. +static inline void init_disassemble_info_compat(struct disassemble_info *info,
  74. + void *stream,
  75. + fprintf_ftype unstyled_func,
  76. + fprintf_styled_ftype styled_func)
  77. +{
  78. +#ifdef DISASM_INIT_STYLED
  79. + init_disassemble_info(info, stream,
  80. + unstyled_func,
  81. + styled_func);
  82. +#else
  83. + (void)styled_func;
  84. + init_disassemble_info(info, stream,
  85. + unstyled_func);
  86. +#endif
  87. +}
  88. +
  89. +#endif /* _TOOLS_DIS_ASM_COMPAT_H */