0001-btrfs-progs-kerncompat-fix-fallthrough-definition-fo.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From 0d2bf742df7f6b6d91fff8abe3c2f8b6ef0e0c01 Mon Sep 17 00:00:00 2001
  2. From: Julien Olivain <ju.o@free.fr>
  3. Date: Sun, 14 Jul 2024 12:52:33 +0200
  4. Subject: [PATCH] btrfs-progs: kerncompat: fix fallthrough definition for gcc
  5. 5.x and 6.x.
  6. Commit [1] 3a1d4aa089 "btrfs-progs: fix fallthrough cases with proper
  7. attributes" introduced a macro "fallthrough" to better handle compiler
  8. warnings of fallthrough situations.
  9. This macro is defined using the "__has_attribute" built-in
  10. function-like macro, which was introduced in GCC 5. See [2]. It then
  11. test for the "__fallthrough__" attribute, which was introduced in
  12. GCC 7. See [3].
  13. When compiling with a gcc version which supports "__has_attribute" and
  14. not the "__fallthrough__" attribute, compilation fails with error
  15. message:
  16. common/format-output.c: In function 'print_escaped':
  17. common/format-output.c:78:4: error: 'fallthrough' undeclared (first use in this function)
  18. fallthrough;
  19. ^
  20. btrfs-progs claim to support gcc at minimal version 4.8 in [4].
  21. This commit fixes this issue by adding the missing definition.
  22. The definition of the unsupported case is duplicated, because testing
  23. for "__has_attribute" and an attribute at the same time is not
  24. portable. See the cpp "__has_attribute" documentation [5].
  25. Note: the issue was found with Buildroot Linux [6], while testing with
  26. the command "utils/test-pkg -a -p btrfs-progs".
  27. [1] https://github.com/kdave/btrfs-progs/commit/3a1d4aa089419b7c94b31ff87122fa74907e1aa6
  28. [2] https://gcc.gnu.org/gcc-5/changes.html
  29. [3] https://gcc.gnu.org/gcc-7/changes.html
  30. [4] https://github.com/kdave/btrfs-progs/tree/v6.9.2#build-compatibility
  31. [5] https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
  32. [6] https://buildroot.org/
  33. Upstream: Proposed: https://github.com/kdave/btrfs-progs/pull/842
  34. Signed-off-by: Julien Olivain <ju.o@free.fr>
  35. ---
  36. include/kerncompat.h | 2 ++
  37. 1 file changed, 2 insertions(+)
  38. diff --git a/include/kerncompat.h b/include/kerncompat.h
  39. index 31cd9d8d..bcd46bde 100644
  40. --- a/include/kerncompat.h
  41. +++ b/include/kerncompat.h
  42. @@ -305,6 +305,8 @@ static inline void up_read(struct rw_semaphore *sem)
  43. #if defined __has_attribute
  44. # if __has_attribute(__fallthrough__)
  45. # define fallthrough __attribute__((__fallthrough__))
  46. +# else
  47. +# define fallthrough do {} while (0) /* fallthrough */
  48. # endif
  49. #else
  50. # define fallthrough do {} while (0) /* fallthrough */
  51. --
  52. 2.45.2