200-tools_portability.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. * generic_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 generic_fls __linux_fls
  67. static __always_inline int generic_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.
  87. --- a/tools/arch/x86/include/asm/insn.h
  88. +++ b/tools/arch/x86/include/asm/insn.h
  89. @@ -7,7 +7,7 @@
  90. * Copyright (C) IBM Corporation, 2009
  91. */
  92. -#include <asm/byteorder.h>
  93. +#include <linux/kernel.h>
  94. /* insn_attr_t is defined in inat.h */
  95. #include "inat.h" /* __ignore_sync_check__ */
  96. --- a/tools/arch/x86/include/asm/orc_types.h
  97. +++ b/tools/arch/x86/include/asm/orc_types.h
  98. @@ -46,7 +46,17 @@
  99. #define ORC_TYPE_REGS_PARTIAL 4
  100. #ifndef __ASSEMBLY__
  101. +#ifdef __APPLE__
  102. +#include <endian.h>
  103. +
  104. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  105. +#define __LITTLE_ENDIAN_BITFIELD
  106. +#elif __BYTE_ORDER == __BIG_ENDIAN
  107. +#define __BIG_ENDIAN_BITFIELD
  108. +#endif
  109. +#else
  110. #include <asm/byteorder.h>
  111. +#endif
  112. /*
  113. * This struct is more or less a vastly simplified version of the DWARF Call
  114. --- a/tools/include/linux/rbtree.h
  115. +++ b/tools/include/linux/rbtree.h
  116. @@ -18,7 +18,6 @@
  117. #define __TOOLS_LINUX_PERF_RBTREE_H
  118. #include <linux/kernel.h>
  119. -#include <linux/stddef.h>
  120. struct rb_node {
  121. unsigned long __rb_parent_color;
  122. --- a/tools/lib/subcmd/exec-cmd.c
  123. +++ b/tools/lib/subcmd/exec-cmd.c
  124. @@ -12,7 +12,10 @@
  125. #include "subcmd-config.h"
  126. #define MAX_ARGS 32
  127. +
  128. +#ifndef PATH_MAX
  129. #define PATH_MAX 4096
  130. +#endif
  131. static const char *argv_exec_path;
  132. static const char *argv0_path;
  133. --- a/tools/objtool/Makefile
  134. +++ b/tools/objtool/Makefile
  135. @@ -39,6 +39,8 @@ OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBS
  136. elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
  137. OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
  138. +OBJTOOL_CFLAGS += $(HOST_EXTRACFLAGS)
  139. +
  140. # Always want host compilation.
  141. HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
  142. --- a/tools/arch/x86/lib/insn.c
  143. +++ b/tools/arch/x86/lib/insn.c
  144. @@ -15,7 +15,11 @@
  145. #include "../include/asm/insn.h" /* __ignore_sync_check__ */
  146. #include <linux/unaligned.h> /* __ignore_sync_check__ */
  147. +#ifdef __KERNEL__
  148. #include <linux/errno.h>
  149. +#else
  150. +#include <errno.h>
  151. +#endif
  152. #include <linux/kconfig.h>
  153. #include "../include/asm/emulate_prefix.h" /* __ignore_sync_check__ */