200-tools_portability.patch 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. @@ -10,8 +10,12 @@
  40. #define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
  41. #endif
  42. +#ifndef __linux__
  43. +#include <tools/linux_types.h>
  44. +#else
  45. #include <asm/types.h>
  46. #include <asm/posix_types.h>
  47. +#endif
  48. struct page;
  49. struct kmem_cache;
  50. @@ -56,6 +60,7 @@ typedef __s8 s8;
  51. #define __user
  52. #endif
  53. #define __must_check
  54. +#undef __cold
  55. #define __cold
  56. typedef __u16 __bitwise __le16;
  57. --- a/tools/objtool/include/objtool/objtool.h
  58. +++ b/tools/objtool/include/objtool/objtool.h
  59. @@ -12,6 +12,7 @@
  60. #include <objtool/elf.h>
  61. +#undef __weak
  62. #define __weak __attribute__((weak))
  63. struct pv_state {
  64. --- a/tools/include/asm-generic/bitops/fls.h
  65. +++ b/tools/include/asm-generic/bitops/fls.h
  66. @@ -2,6 +2,8 @@
  67. #ifndef _ASM_GENERIC_BITOPS_FLS_H_
  68. #define _ASM_GENERIC_BITOPS_FLS_H_
  69. +#include <string.h>
  70. +
  71. /**
  72. * fls - find last (most-significant) bit set
  73. * @x: the word to search
  74. @@ -10,6 +12,7 @@
  75. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  76. */
  77. +#define fls __linux_fls
  78. static __always_inline int fls(unsigned int x)
  79. {
  80. int r = 32;
  81. --- a/tools/lib/string.c
  82. +++ b/tools/lib/string.c
  83. @@ -96,6 +96,7 @@ int strtobool(const char *s, bool *res)
  84. * If libc has strlcpy() then that version will override this
  85. * implementation:
  86. */
  87. +#ifndef __APPLE__
  88. #ifdef __clang__
  89. #pragma clang diagnostic push
  90. #pragma clang diagnostic ignored "-Wignored-attributes"
  91. @@ -114,6 +115,7 @@ size_t __weak strlcpy(char *dest, const
  92. #ifdef __clang__
  93. #pragma clang diagnostic pop
  94. #endif
  95. +#endif
  96. /**
  97. * skip_spaces - Removes leading whitespace from @str.
  98. --- a/tools/arch/x86/include/asm/insn.h
  99. +++ b/tools/arch/x86/include/asm/insn.h
  100. @@ -7,7 +7,7 @@
  101. * Copyright (C) IBM Corporation, 2009
  102. */
  103. -#include <asm/byteorder.h>
  104. +#include <linux/kernel.h>
  105. /* insn_attr_t is defined in inat.h */
  106. #include "inat.h" /* __ignore_sync_check__ */
  107. --- a/tools/arch/x86/include/asm/orc_types.h
  108. +++ b/tools/arch/x86/include/asm/orc_types.h
  109. @@ -46,7 +46,6 @@
  110. #define ORC_TYPE_REGS_PARTIAL 4
  111. #ifndef __ASSEMBLY__
  112. -#include <asm/byteorder.h>
  113. /*
  114. * This struct is more or less a vastly simplified version of the DWARF Call
  115. @@ -59,12 +58,12 @@
  116. struct orc_entry {
  117. s16 sp_offset;
  118. s16 bp_offset;
  119. -#if defined(__LITTLE_ENDIAN_BITFIELD)
  120. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  121. unsigned sp_reg:4;
  122. unsigned bp_reg:4;
  123. unsigned type:3;
  124. unsigned signal:1;
  125. -#elif defined(__BIG_ENDIAN_BITFIELD)
  126. +#elif __BYTE_ORDER == __BIG_ENDIAN
  127. unsigned bp_reg:4;
  128. unsigned sp_reg:4;
  129. unsigned unused:4;
  130. --- a/tools/include/linux/rbtree.h
  131. +++ b/tools/include/linux/rbtree.h
  132. @@ -18,7 +18,6 @@
  133. #define __TOOLS_LINUX_PERF_RBTREE_H
  134. #include <linux/kernel.h>
  135. -#include <linux/stddef.h>
  136. struct rb_node {
  137. unsigned long __rb_parent_color;
  138. --- a/tools/include/tools/be_byteshift.h
  139. +++ b/tools/include/tools/be_byteshift.h
  140. @@ -2,6 +2,10 @@
  141. #ifndef _TOOLS_BE_BYTESHIFT_H
  142. #define _TOOLS_BE_BYTESHIFT_H
  143. +#ifndef __linux__
  144. +#include "linux_types.h"
  145. +#endif
  146. +
  147. #include <stdint.h>
  148. static inline uint16_t __get_unaligned_be16(const uint8_t *p)
  149. --- a/tools/include/tools/le_byteshift.h
  150. +++ b/tools/include/tools/le_byteshift.h
  151. @@ -2,6 +2,10 @@
  152. #ifndef _TOOLS_LE_BYTESHIFT_H
  153. #define _TOOLS_LE_BYTESHIFT_H
  154. +#ifndef __linux__
  155. +#include "linux_types.h"
  156. +#endif
  157. +
  158. #include <stdint.h>
  159. static inline uint16_t __get_unaligned_le16(const uint8_t *p)
  160. --- /dev/null
  161. +++ b/tools/include/tools/linux_types.h
  162. @@ -0,0 +1,18 @@
  163. +#ifndef __LINUX_TYPES_H
  164. +#define __LINUX_TYPES_H
  165. +
  166. +#include <stdint.h>
  167. +
  168. +typedef int8_t __s8;
  169. +typedef uint8_t __u8;
  170. +
  171. +typedef int16_t __s16;
  172. +typedef uint16_t __u16;
  173. +
  174. +typedef int32_t __s32;
  175. +typedef uint32_t __u32;
  176. +
  177. +typedef int64_t __s64;
  178. +typedef uint64_t __u64;
  179. +
  180. +#endif
  181. --- a/tools/objtool/Makefile
  182. +++ b/tools/objtool/Makefile
  183. @@ -39,6 +39,8 @@ OBJTOOL_LDFLAGS := $(LIBELF_LIBS) $(LIBS
  184. elfshdr := $(shell echo '$(pound)include <libelf.h>' | $(HOSTCC) $(OBJTOOL_CFLAGS) -x c -E - | grep elf_getshdr)
  185. OBJTOOL_CFLAGS += $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED)
  186. +OBJTOOL_CFLAGS += $(HOST_EXTRACFLAGS)
  187. +
  188. # Always want host compilation.
  189. HOST_OVERRIDES := CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)"
  190. --- a/tools/objtool/orc_dump.c
  191. +++ b/tools/objtool/orc_dump.c
  192. @@ -4,10 +4,10 @@
  193. */
  194. #include <unistd.h>
  195. -#include <asm/orc_types.h>
  196. #include <objtool/objtool.h>
  197. #include <objtool/warn.h>
  198. #include <objtool/endianness.h>
  199. +#include <asm/orc_types.h>
  200. static const char *reg_name(unsigned int reg)
  201. {
  202. --- a/tools/objtool/orc_gen.c
  203. +++ b/tools/objtool/orc_gen.c
  204. @@ -7,11 +7,11 @@
  205. #include <string.h>
  206. #include <linux/objtool_types.h>
  207. -#include <asm/orc_types.h>
  208. #include <objtool/check.h>
  209. #include <objtool/warn.h>
  210. #include <objtool/endianness.h>
  211. +#include <asm/orc_types.h>
  212. static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi,
  213. struct instruction *insn)
  214. --- a/tools/arch/x86/lib/insn.c
  215. +++ b/tools/arch/x86/lib/insn.c
  216. @@ -15,7 +15,11 @@
  217. #include "../include/asm/insn.h" /* __ignore_sync_check__ */
  218. #include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */
  219. +#ifdef __KERNEL__
  220. #include <linux/errno.h>
  221. +#else
  222. +#include <errno.h>
  223. +#endif
  224. #include <linux/kconfig.h>
  225. #include "../include/asm/emulate_prefix.h" /* __ignore_sync_check__ */