212-tools_portability.patch 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. From 48232d3d931c95953ce2ddfe7da7bb164aef6a73 Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Fri, 7 Jul 2017 17:03:16 +0200
  4. Subject: fix portability of some includes files in tools/ used on the host
  5. Signed-off-by: Felix Fietkau <[email protected]>
  6. ---
  7. tools/include/tools/be_byteshift.h | 4 ++++
  8. tools/include/tools/le_byteshift.h | 4 ++++
  9. tools/include/tools/linux_types.h | 22 ++++++++++++++++++++++
  10. 3 files changed, 30 insertions(+)
  11. create mode 100644 tools/include/tools/linux_types.h
  12. --- a/tools/include/tools/be_byteshift.h
  13. +++ b/tools/include/tools/be_byteshift.h
  14. @@ -2,6 +2,10 @@
  15. #ifndef _TOOLS_BE_BYTESHIFT_H
  16. #define _TOOLS_BE_BYTESHIFT_H
  17. +#ifndef __linux__
  18. +#include "linux_types.h"
  19. +#endif
  20. +
  21. #include <stdint.h>
  22. static inline uint16_t __get_unaligned_be16(const uint8_t *p)
  23. --- a/tools/include/tools/le_byteshift.h
  24. +++ b/tools/include/tools/le_byteshift.h
  25. @@ -2,6 +2,10 @@
  26. #ifndef _TOOLS_LE_BYTESHIFT_H
  27. #define _TOOLS_LE_BYTESHIFT_H
  28. +#ifndef __linux__
  29. +#include "linux_types.h"
  30. +#endif
  31. +
  32. #include <stdint.h>
  33. static inline uint16_t __get_unaligned_le16(const uint8_t *p)
  34. --- /dev/null
  35. +++ b/tools/include/tools/linux_types.h
  36. @@ -0,0 +1,18 @@
  37. +#ifndef __LINUX_TYPES_H
  38. +#define __LINUX_TYPES_H
  39. +
  40. +#include <stdint.h>
  41. +
  42. +typedef int8_t __s8;
  43. +typedef uint8_t __u8;
  44. +
  45. +typedef int16_t __s16;
  46. +typedef uint16_t __u16;
  47. +
  48. +typedef int32_t __s32;
  49. +typedef uint32_t __u32;
  50. +
  51. +typedef int64_t __s64;
  52. +typedef uint64_t __u64;
  53. +
  54. +#endif
  55. --- a/tools/include/linux/types.h
  56. +++ b/tools/include/linux/types.h
  57. @@ -10,8 +10,12 @@
  58. #define __SANE_USERSPACE_TYPES__ /* For PPC64, to get LL64 types */
  59. #endif
  60. +#ifndef __linux__
  61. +#include <tools/linux_types.h>
  62. +#else
  63. #include <asm/types.h>
  64. #include <asm/posix_types.h>
  65. +#endif
  66. struct page;
  67. struct kmem_cache;
  68. @@ -51,7 +55,9 @@ typedef __s8 s8;
  69. #define __force
  70. #define __user
  71. #define __must_check
  72. +#ifndef __cold
  73. #define __cold
  74. +#endif
  75. typedef __u16 __bitwise __le16;
  76. typedef __u16 __bitwise __be16;
  77. --- a/tools/perf/pmu-events/jevents.py
  78. +++ b/tools/perf/pmu-events/jevents.py
  79. @@ -684,6 +684,7 @@ def main() -> None:
  80. #include "util/header.h"
  81. #include "util/pmu.h"
  82. #include <string.h>
  83. +#include <strings.h>
  84. #include <stddef.h>
  85. struct compact_pmu_event {
  86. --- a/tools/arch/x86/include/asm/insn.h
  87. +++ b/tools/arch/x86/include/asm/insn.h
  88. @@ -7,8 +7,8 @@
  89. * Copyright (C) IBM Corporation, 2009
  90. */
  91. -#include <asm/byteorder.h>
  92. /* insn_attr_t is defined in inat.h */
  93. +#include <linux/kernel.h>
  94. #include "inat.h" /* __ignore_sync_check__ */
  95. #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
  96. --- a/tools/arch/x86/include/asm/orc_types.h
  97. +++ b/tools/arch/x86/include/asm/orc_types.h
  98. @@ -40,7 +40,6 @@
  99. #define ORC_REG_MAX 15
  100. #ifndef __ASSEMBLY__
  101. -#include <asm/byteorder.h>
  102. /*
  103. * This struct is more or less a vastly simplified version of the DWARF Call
  104. @@ -53,12 +52,12 @@
  105. struct orc_entry {
  106. s16 sp_offset;
  107. s16 bp_offset;
  108. -#if defined(__LITTLE_ENDIAN_BITFIELD)
  109. +#if __BYTE_ORDER == __LITTLE_ENDIAN
  110. unsigned sp_reg:4;
  111. unsigned bp_reg:4;
  112. unsigned type:2;
  113. unsigned end:1;
  114. -#elif defined(__BIG_ENDIAN_BITFIELD)
  115. +#elif __BYTE_ORDER == __BIG_ENDIAN
  116. unsigned bp_reg:4;
  117. unsigned sp_reg:4;
  118. unsigned unused:5;
  119. --- a/tools/arch/x86/lib/insn.c
  120. +++ b/tools/arch/x86/lib/insn.c
  121. @@ -15,7 +15,11 @@
  122. #include "../include/asm/insn.h" /* __ignore_sync_check__ */
  123. #include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */
  124. +#ifdef __KERNEL__
  125. #include <linux/errno.h>
  126. +#else
  127. +#include <errno.h>
  128. +#endif
  129. #include <linux/kconfig.h>
  130. #include "../include/asm/emulate_prefix.h" /* __ignore_sync_check__ */
  131. --- a/tools/include/asm-generic/bitops/fls.h
  132. +++ b/tools/include/asm-generic/bitops/fls.h
  133. @@ -2,6 +2,8 @@
  134. #ifndef _ASM_GENERIC_BITOPS_FLS_H_
  135. #define _ASM_GENERIC_BITOPS_FLS_H_
  136. +#include <string.h>
  137. +
  138. /**
  139. * fls - find last (most-significant) bit set
  140. * @x: the word to search
  141. @@ -10,7 +12,7 @@
  142. * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  143. */
  144. -static __always_inline int fls(unsigned int x)
  145. +static __always_inline int __generic_fls(unsigned int x)
  146. {
  147. int r = 32;
  148. @@ -38,5 +40,6 @@ static __always_inline int fls(unsigned
  149. }
  150. return r;
  151. }
  152. +#define fls __generic_fls
  153. #endif /* _ASM_GENERIC_BITOPS_FLS_H_ */
  154. --- a/tools/include/asm-generic/bitsperlong.h
  155. +++ b/tools/include/asm-generic/bitsperlong.h
  156. @@ -4,11 +4,13 @@
  157. #include <uapi/asm-generic/bitsperlong.h>
  158. +#ifndef BITS_PER_LONG
  159. #ifdef __SIZEOF_LONG__
  160. #define BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
  161. #else
  162. #define BITS_PER_LONG __WORDSIZE
  163. #endif
  164. +#endif
  165. #if BITS_PER_LONG != __BITS_PER_LONG
  166. #error Inconsistent word size. Check asm/bitsperlong.h
  167. --- a/tools/include/linux/rbtree.h
  168. +++ b/tools/include/linux/rbtree.h
  169. @@ -18,7 +18,6 @@
  170. #define __TOOLS_LINUX_PERF_RBTREE_H
  171. #include <linux/kernel.h>
  172. -#include <linux/stddef.h>
  173. struct rb_node {
  174. unsigned long __rb_parent_color;
  175. --- a/tools/objtool/Makefile
  176. +++ b/tools/objtool/Makefile
  177. @@ -4,7 +4,7 @@ include ../scripts/Makefile.arch
  178. # always use the host compiler
  179. AR = $(HOSTAR)
  180. -CC = $(HOSTCC)
  181. +CC = $(HOSTCC) $(HOST_EXTRACFLAGS)
  182. LD = $(HOSTLD)
  183. ifeq ($(srctree),)
  184. @@ -43,6 +43,7 @@ BUILD_ORC := n
  185. ifeq ($(SRCARCH),x86)
  186. BUILD_ORC := y
  187. + CFLAGS += -DBUILD_ORC
  188. endif
  189. export BUILD_ORC
  190. --- a/tools/objtool/check.c
  191. +++ b/tools/objtool/check.c
  192. @@ -1164,11 +1164,12 @@ static int add_ignore_alternatives(struc
  193. return 0;
  194. }
  195. +#ifndef BUILD_ORC
  196. /*
  197. * Symbols that replace INSN_CALL_DYNAMIC, every (tail) call to such a symbol
  198. * will be added to the .retpoline_sites section.
  199. */
  200. -__weak bool arch_is_retpoline(struct symbol *sym)
  201. +bool arch_is_retpoline(struct symbol *sym)
  202. {
  203. return false;
  204. }
  205. @@ -1177,7 +1178,7 @@ __weak bool arch_is_retpoline(struct sym
  206. * Symbols that replace INSN_RETURN, every (tail) call to such a symbol
  207. * will be added to the .return_sites section.
  208. */
  209. -__weak bool arch_is_rethunk(struct symbol *sym)
  210. +bool arch_is_rethunk(struct symbol *sym)
  211. {
  212. return false;
  213. }
  214. @@ -1186,10 +1187,11 @@ __weak bool arch_is_rethunk(struct symbo
  215. * Symbols that are embedded inside other instructions, because sometimes crazy
  216. * code exists. These are mostly ignored for validation purposes.
  217. */
  218. -__weak bool arch_is_embedded_insn(struct symbol *sym)
  219. +bool arch_is_embedded_insn(struct symbol *sym)
  220. {
  221. return false;
  222. }
  223. +#endif
  224. #define NEGATIVE_RELOC ((void *)-1L)
  225. --- a/tools/objtool/include/objtool/objtool.h
  226. +++ b/tools/objtool/include/objtool/objtool.h
  227. @@ -12,7 +12,9 @@
  228. #include <objtool/elf.h>
  229. +#ifndef __weak
  230. #define __weak __attribute__((weak))
  231. +#endif
  232. struct pv_state {
  233. bool clean;
  234. --- a/tools/objtool/orc_dump.c
  235. +++ b/tools/objtool/orc_dump.c
  236. @@ -5,10 +5,10 @@
  237. #include <unistd.h>
  238. #include <linux/objtool.h>
  239. -#include <asm/orc_types.h>
  240. #include <objtool/objtool.h>
  241. #include <objtool/warn.h>
  242. #include <objtool/endianness.h>
  243. +#include <asm/orc_types.h>
  244. static const char *reg_name(unsigned int reg)
  245. {
  246. --- a/tools/objtool/orc_gen.c
  247. +++ b/tools/objtool/orc_gen.c
  248. @@ -7,11 +7,11 @@
  249. #include <string.h>
  250. #include <linux/objtool.h>
  251. -#include <asm/orc_types.h>
  252. #include <objtool/check.h>
  253. #include <objtool/warn.h>
  254. #include <objtool/endianness.h>
  255. +#include <asm/orc_types.h>
  256. static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi,
  257. struct instruction *insn)
  258. --- a/tools/objtool/special.c
  259. +++ b/tools/objtool/special.c
  260. @@ -54,9 +54,11 @@ struct special_entry entries[] = {
  261. {},
  262. };
  263. -void __weak arch_handle_alternative(unsigned short feature, struct special_alt *alt)
  264. +#ifndef BUILD_ORC
  265. +void arch_handle_alternative(unsigned short feature, struct special_alt *alt)
  266. {
  267. }
  268. +#endif
  269. static void reloc_to_sec_off(struct reloc *reloc, struct section **sec,
  270. unsigned long *off)
  271. --- a/tools/objtool/weak.c
  272. +++ b/tools/objtool/weak.c
  273. @@ -15,12 +15,14 @@
  274. return ENOSYS; \
  275. })
  276. -int __weak orc_dump(const char *_objname)
  277. +#ifndef BUILD_ORC
  278. +int orc_dump(const char *_objname)
  279. {
  280. UNSUPPORTED("ORC");
  281. }
  282. -int __weak orc_create(struct objtool_file *file)
  283. +int orc_create(struct objtool_file *file)
  284. {
  285. UNSUPPORTED("ORC");
  286. }
  287. +#endif
  288. --- a/tools/scripts/Makefile.include
  289. +++ b/tools/scripts/Makefile.include
  290. @@ -92,7 +92,7 @@ LLVM_OBJCOPY ?= llvm-objcopy
  291. LLVM_STRIP ?= llvm-strip
  292. ifeq ($(CC_NO_CLANG), 1)
  293. -EXTRA_WARNINGS += -Wstrict-aliasing=3
  294. +# EXTRA_WARNINGS += -Wstrict-aliasing=3
  295. else ifneq ($(CROSS_COMPILE),)
  296. # Allow userspace to override CLANG_CROSS_FLAGS to specify their own
  297. --- a/tools/lib/string.c
  298. +++ b/tools/lib/string.c
  299. @@ -100,6 +100,7 @@ int strtobool(const char *s, bool *res)
  300. #pragma clang diagnostic push
  301. #pragma clang diagnostic ignored "-Wignored-attributes"
  302. #endif
  303. +#ifndef __APPLE__
  304. size_t __weak strlcpy(char *dest, const char *src, size_t size)
  305. {
  306. size_t ret = strlen(src);
  307. @@ -111,6 +112,7 @@ size_t __weak strlcpy(char *dest, const
  308. }
  309. return ret;
  310. }
  311. +#endif
  312. #ifdef __clang__
  313. #pragma clang diagnostic pop
  314. #endif