200-tools_portability.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From a7ae4ed0a3951c45d4a59ee575951b64ae4a23fb Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Tue, 7 May 2024 12:22:15 +0200
  4. Subject: [PATCH] kernel: fix tools build breakage on macos with x86
  5. Signed-off-by: Felix Fietkau <[email protected]>
  6. ---
  7. --- a/tools/scripts/Makefile.include
  8. +++ b/tools/scripts/Makefile.include
  9. @@ -72,8 +72,6 @@ $(call allow-override,CXX,$(CROSS_COMPIL
  10. $(call allow-override,STRIP,$(CROSS_COMPILE)strip)
  11. endif
  12. -CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
  13. -
  14. ifneq ($(LLVM),)
  15. HOSTAR ?= $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
  16. HOSTCC ?= $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
  17. @@ -84,6 +82,9 @@ HOSTCC ?= gcc
  18. HOSTLD ?= ld
  19. endif
  20. +CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
  21. +HOSTCC_NO_CLANG := $(shell $(HOSTCC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?)
  22. +
  23. # Some tools require Clang, LLC and/or LLVM utils
  24. CLANG ?= clang
  25. LLC ?= llc
  26. @@ -92,8 +93,9 @@ LLVM_OBJCOPY ?= llvm-objcopy
  27. LLVM_STRIP ?= llvm-strip
  28. ifeq ($(CC_NO_CLANG), 1)
  29. -EXTRA_WARNINGS += -Wstrict-aliasing=3
  30. -
  31. + ifeq ($(HOSTCC_NO_CLANG), 1)
  32. + EXTRA_WARNINGS += -Wstrict-aliasing=3
  33. + endif
  34. else ifneq ($(CROSS_COMPILE),)
  35. # Allow userspace to override CLANG_CROSS_FLAGS to specify their own
  36. # sysroots and flags or to avoid the GCC call in pure Clang builds.
  37. --- a/tools/include/linux/types.h
  38. +++ b/tools/include/linux/types.h
  39. @@ -56,6 +56,7 @@ typedef __s8 s8;
  40. #define __user
  41. #endif
  42. #define __must_check
  43. +#undef __cold
  44. #define __cold
  45. typedef __u16 __bitwise __le16;
  46. --- a/tools/objtool/include/objtool/objtool.h
  47. +++ b/tools/objtool/include/objtool/objtool.h
  48. @@ -12,6 +12,7 @@
  49. #include <objtool/elf.h>
  50. +#undef __weak
  51. #define __weak __attribute__((weak))
  52. struct pv_state {
  53. --- a/tools/include/asm-generic/bitops/fls.h
  54. +++ b/tools/include/asm-generic/bitops/fls.h
  55. @@ -2,6 +2,8 @@
  56. #ifndef _ASM_GENERIC_BITOPS_FLS_H_
  57. #define _ASM_GENERIC_BITOPS_FLS_H_
  58. +#include <string.h>
  59. +
  60. /**
  61. * fls - find last (most-significant) bit set
  62. * @x: the word to search
  63. @@ -10,6 +12,7 @@
  64. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  65. */
  66. +#define fls __linux_fls
  67. static __always_inline int fls(unsigned int x)
  68. {
  69. int r = 32;
  70. --- a/tools/lib/string.c
  71. +++ b/tools/lib/string.c
  72. @@ -96,6 +96,7 @@ int strtobool(const char *s, bool *res)
  73. * If libc has strlcpy() then that version will override this
  74. * implementation:
  75. */
  76. +#ifndef __APPLE__
  77. #ifdef __clang__
  78. #pragma clang diagnostic push
  79. #pragma clang diagnostic ignored "-Wignored-attributes"
  80. @@ -114,6 +115,7 @@ size_t __weak strlcpy(char *dest, const
  81. #ifdef __clang__
  82. #pragma clang diagnostic pop
  83. #endif
  84. +#endif
  85. /**
  86. * skip_spaces - Removes leading whitespace from @str.