0002-btrfs-progs-add-uClibc-ng-compatibility-for-printf-f.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From 0f34a362c8644f212138fb8de8e0fba54941e757 Mon Sep 17 00:00:00 2001
  2. From: Julien Olivain <ju.o@free.fr>
  3. Date: Sun, 14 Jul 2024 16:28:08 +0200
  4. Subject: [PATCH] btrfs-progs: add uClibc-ng compatibility for printf format
  5. %pV
  6. Commit [1] 164bc10d "btrfs-progs: add musl compatibility for printf
  7. format %pV" added a logic to detect the presence of the glibc
  8. <printf.h> header, and if present, to use the
  9. register_printf_specifier() and register_printf_modifier() functions.
  10. The original intent (as the commit log suggests), was to support the
  11. musl libc, which does not provides this <printf.h> header.
  12. When compiling with another libc, such as uClibc-ng, btrfs-progs fail
  13. to build with error:
  14. common/messages.c: In function 'print_va_format':
  15. common/messages.c:51:19: error: 'const struct printf_info' has no member named 'user'
  16. 51 | if (!(info->user & va_modifier))
  17. | ^~
  18. common/messages.c: In function 'btrfs_no_printk':
  19. common/messages.c:76:17: warning: implicit declaration of function 'register_printf_specifier'; did you mean 'register_printf_function'? [-Wimplicit-function-declaration]
  20. 76 | register_printf_specifier('V', print_va_format,
  21. | ^~~~~~~~~~~~~~~~~~~~~~~~~
  22. | register_printf_function
  23. common/messages.c:78:31: warning: implicit declaration of function 'register_printf_modifier'; did you mean 'register_printf_function'? [-Wimplicit-function-declaration]
  24. 78 | va_modifier = register_printf_modifier(L"p");
  25. | ^~~~~~~~~~~~~~~~~~~~~~~~
  26. | register_printf_function
  27. This is because uClibc-ng provides a <printf.h> header, but not the
  28. register_printf_specifier() and register_printf_modifier() functions.
  29. See [2]. It mainly includes register_printf_function(). uClibc-ng
  30. emulates an older glibc behavior. Glibc added support for printf user
  31. elements in commit [3] (first included in glibc-2.10, in 2009). Checking
  32. only the <printf.h> is not sufficient.
  33. This commit fixes this build issue by refining the detection logic of
  34. the <printf.h> functions required by btrfs-progs.
  35. [1] https://github.com/kdave/btrfs-progs/commit/164bc10dfc08d8754d23ef0d6d7281e139d6cd53
  36. [2] https://gogs.waldemar-brodkorb.de/oss/uclibc-ng/src/v1.0.49/include/printf.h
  37. [3] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=9d26efa90c6dcbcd6b3e586c9927b6058ef4d529
  38. Upstream: Proposed: https://github.com/kdave/btrfs-progs/pull/843
  39. Signed-off-by: Julien Olivain <ju.o@free.fr>
  40. ---
  41. common/messages.h | 4 +++-
  42. configure.ac | 4 ++++
  43. 2 files changed, 7 insertions(+), 1 deletion(-)
  44. diff --git a/common/messages.h b/common/messages.h
  45. index d6d4044d..aced7c9b 100644
  46. --- a/common/messages.h
  47. +++ b/common/messages.h
  48. @@ -25,7 +25,9 @@
  49. /*
  50. * Workaround for custom format %pV that may not be supported on all libcs.
  51. */
  52. -#ifdef HAVE_PRINTF_H
  53. +#if defined(HAVE_PRINTF_H) \
  54. + && defined(HAVE_REGISTER_PRINTF_SPECIFIER) \
  55. + && defined(HAVE_REGISTER_PRINTF_MODIFIER)
  56. #define DECLARE_PV(name) struct va_format name
  57. #define PV_FMT "%pV"
  58. #define PV_VAL(va) &va
  59. diff --git a/configure.ac b/configure.ac
  60. index b69973b3..62b88973 100644
  61. --- a/configure.ac
  62. +++ b/configure.ac
  63. @@ -95,6 +95,10 @@ AC_CHECK_HEADERS([linux/hw_breakpoint.h])
  64. AC_CHECK_HEADERS([linux/fsverity.h])
  65. AC_CHECK_HEADERS([printf.h])
  66. +dnl Check for printf.h functions.
  67. +AC_CHECK_FUNCS([register_printf_specifier])
  68. +AC_CHECK_FUNCS([register_printf_modifier])
  69. +
  70. if grep -q 'HAVE_LINUX_FSVERITY_H.*1' confdefs.h; then
  71. have_fsverity='yes'
  72. else
  73. --
  74. 2.45.2