200-tools_portability.patch 6.8 KB

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