aboutsummaryrefslogtreecommitdiff
path: root/target/linux/generic/hack-6.1/212-tools_portability.patch
blob: 3ee4393006f9774febd7d74bf3a8f92fdd7763d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
From 48232d3d931c95953ce2ddfe7da7bb164aef6a73 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name>
Date: Fri, 7 Jul 2017 17:03:16 +0200
Subject: fix portability of some includes files in tools/ used on the host

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 tools/include/tools/be_byteshift.h |  4 ++++
 tools/include/tools/le_byteshift.h |  4 ++++
 tools/include/tools/linux_types.h  | 22 ++++++++++++++++++++++
 3 files changed, 30 insertions(+)
 create mode 100644 tools/include/tools/linux_types.h

--- a/tools/include/tools/be_byteshift.h
+++ b/tools/include/tools/be_byteshift.h
@@ -2,6 +2,10 @@
 #ifndef _TOOLS_BE_BYTESHIFT_H
 #define _TOOLS_BE_BYTESHIFT_H
 
+#ifndef __linux__
+#include "linux_types.h"
+#endif
+
 #include <stdint.h>
 
 static inline uint16_t __get_unaligned_be16(const uint8_t *p)
--- a/tools/include/tools/le_byteshift.h
+++ b/tools/include/tools/le_byteshift.h
@@ -2,6 +2,10 @@
 #ifndef _TOOLS_LE_BYTESHIFT_H
 #define _TOOLS_LE_BYTESHIFT_H
 
+#ifndef __linux__
+#include "linux_types.h"
+#endif
+
 #include <stdint.h>
 
 static inline uint16_t __get_unaligned_le16(const uint8_t *p)
--- /dev/null
+++ b/tools/include/tools/linux_types.h
@@ -0,0 +1,18 @@
+#ifndef __LINUX_TYPES_H
+#define __LINUX_TYPES_H
+
+#include <stdint.h>
+
+typedef int8_t __s8;
+typedef uint8_t __u8;
+
+typedef int16_t __s16;
+typedef uint16_t __u16;
+
+typedef int32_t __s32;
+typedef uint32_t __u32;
+
+typedef int64_t __s64;
+typedef uint64_t __u64;
+
+#endif
--- a/tools/include/linux/types.h
+++ b/tools/include/linux/types.h
@@ -10,8 +10,12 @@
 #define __SANE_USERSPACE_TYPES__	/* For PPC64, to get LL64 types */
 #endif
 
+#ifndef __linux__
+#include <tools/linux_types.h>
+#else
 #include <asm/types.h>
 #include <asm/posix_types.h>
+#endif
 
 struct page;
 struct kmem_cache;
@@ -51,7 +55,9 @@ typedef __s8  s8;
 #define __force
 #define __user
 #define __must_check
+#ifndef __cold
 #define __cold
+#endif
 
 typedef __u16 __bitwise __le16;
 typedef __u16 __bitwise __be16;
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -684,6 +684,7 @@ def main() -> None:
 #include "util/header.h"
 #include "util/pmu.h"
 #include <string.h>
+#include <strings.h>
 #include <stddef.h>
 
 struct compact_pmu_event {
--- a/tools/arch/x86/include/asm/insn.h
+++ b/tools/arch/x86/include/asm/insn.h
@@ -7,8 +7,8 @@
  * Copyright (C) IBM Corporation, 2009
  */
 
-#include <asm/byteorder.h>
 /* insn_attr_t is defined in inat.h */
+#include <linux/kernel.h>
 #include "inat.h" /* __ignore_sync_check__ */
 
 #if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN)
--- a/tools/arch/x86/include/asm/orc_types.h
+++ b/tools/arch/x86/include/asm/orc_types.h
@@ -40,7 +40,6 @@
 #define ORC_REG_MAX			15
 
 #ifndef __ASSEMBLY__
-#include <asm/byteorder.h>
 
 /*
  * This struct is more or less a vastly simplified version of the DWARF Call
@@ -53,12 +52,12 @@
 struct orc_entry {
 	s16		sp_offset;
 	s16		bp_offset;
-#if defined(__LITTLE_ENDIAN_BITFIELD)
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 	unsigned	sp_reg:4;
 	unsigned	bp_reg:4;
 	unsigned	type:2;
 	unsigned	end:1;
-#elif defined(__BIG_ENDIAN_BITFIELD)
+#elif __BYTE_ORDER == __BIG_ENDIAN
 	unsigned	bp_reg:4;
 	unsigned	sp_reg:4;
 	unsigned	unused:5;
--- a/tools/arch/x86/lib/insn.c
+++ b/tools/arch/x86/lib/insn.c
@@ -15,7 +15,11 @@
 #include "../include/asm/insn.h" /* __ignore_sync_check__ */
 #include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */
 
+#ifdef __KERNEL__
 #include <linux/errno.h>
+#else
+#include <errno.h>
+#endif
 #include <linux/kconfig.h>
 
 #include "../include/asm/emulate_prefix.h" /* __ignore_sync_check__ */
--- a/tools/include/asm-generic/bitops/fls.h
+++ b/tools/include/asm-generic/bitops/fls.h
@@ -2,6 +2,8 @@
 #ifndef _ASM_GENERIC_BITOPS_FLS_H_
 #define _ASM_GENERIC_BITOPS_FLS_H_
 
+#include <string.h>
+
 /**
  * fls - find last (most-significant) bit set
  * @x: the word to search
@@ -10,7 +12,7 @@
  * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  */
 
-static __always_inline int fls(unsigned int x)
+static __always_inline int __generic_fls(unsigned int x)
 {
 	int r = 32;
 
@@ -38,5 +40,6 @@ static __always_inline int fls(unsigned
 	}
 	return r;
 }
+#define fls __generic_fls
 
 #endif /* _ASM_GENERIC_BITOPS_FLS_H_ */
--- a/tools/include/asm-generic/bitsperlong.h
+++ b/tools/include/asm-generic/bitsperlong.h
@@ -4,11 +4,13 @@
 
 #include <uapi/asm-generic/bitsperlong.h>
 
+#ifndef BITS_PER_LONG
 #ifdef __SIZEOF_LONG__
 #define BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
 #else
 #define BITS_PER_LONG __WORDSIZE
 #endif
+#endif
 
 #if BITS_PER_LONG != __BITS_PER_LONG
 #error Inconsistent word size. Check asm/bitsperlong.h
--- a/tools/include/linux/rbtree.h
+++ b/tools/include/linux/rbtree.h
@@ -18,7 +18,6 @@
 #define __TOOLS_LINUX_PERF_RBTREE_H
 
 #include <linux/kernel.h>
-#include <linux/stddef.h>
 
 struct rb_node {
 	unsigned long  __rb_parent_color;
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -4,7 +4,7 @@ include ../scripts/Makefile.arch
 
 # always use the host compiler
 AR	 = $(HOSTAR)
-CC	 = $(HOSTCC)
+CC	 = $(HOSTCC) $(HOST_EXTRACFLAGS)
 LD	 = $(HOSTLD)
 
 ifeq ($(srctree),)
@@ -43,6 +43,7 @@ BUILD_ORC := n
 
 ifeq ($(SRCARCH),x86)
 	BUILD_ORC := y
+	CFLAGS += -DBUILD_ORC
 endif
 
 export BUILD_ORC
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1164,11 +1164,12 @@ static int add_ignore_alternatives(struc
 	return 0;
 }
 
+#ifndef BUILD_ORC
 /*
  * Symbols that replace INSN_CALL_DYNAMIC, every (tail) call to such a symbol
  * will be added to the .retpoline_sites section.
  */
-__weak bool arch_is_retpoline(struct symbol *sym)
+bool arch_is_retpoline(struct symbol *sym)
 {
 	return false;
 }
@@ -1177,7 +1178,7 @@ __weak bool arch_is_retpoline(struct sym
  * Symbols that replace INSN_RETURN, every (tail) call to such a symbol
  * will be added to the .return_sites section.
  */
-__weak bool arch_is_rethunk(struct symbol *sym)
+bool arch_is_rethunk(struct symbol *sym)
 {
 	return false;
 }
@@ -1186,10 +1187,11 @@ __weak bool arch_is_rethunk(struct symbo
  * Symbols that are embedded inside other instructions, because sometimes crazy
  * code exists. These are mostly ignored for validation purposes.
  */
-__weak bool arch_is_embedded_insn(struct symbol *sym)
+bool arch_is_embedded_insn(struct symbol *sym)
 {
 	return false;
 }
+#endif
 
 #define NEGATIVE_RELOC	((void *)-1L)
 
--- a/tools/objtool/include/objtool/objtool.h
+++ b/tools/objtool/include/objtool/objtool.h
@@ -12,7 +12,9 @@
 
 #include <objtool/elf.h>
 
+#ifndef __weak
 #define __weak __attribute__((weak))
+#endif
 
 struct pv_state {
 	bool clean;
--- a/tools/objtool/orc_dump.c
+++ b/tools/objtool/orc_dump.c
@@ -5,10 +5,10 @@
 
 #include <unistd.h>
 #include <linux/objtool.h>
-#include <asm/orc_types.h>
 #include <objtool/objtool.h>
 #include <objtool/warn.h>
 #include <objtool/endianness.h>
+#include <asm/orc_types.h>
 
 static const char *reg_name(unsigned int reg)
 {
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -7,11 +7,11 @@
 #include <string.h>
 
 #include <linux/objtool.h>
-#include <asm/orc_types.h>
 
 #include <objtool/check.h>
 #include <objtool/warn.h>
 #include <objtool/endianness.h>
+#include <asm/orc_types.h>
 
 static int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi,
 			  struct instruction *insn)
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -54,9 +54,11 @@ struct special_entry entries[] = {
 	{},
 };
 
-void __weak arch_handle_alternative(unsigned short feature, struct special_alt *alt)
+#ifndef BUILD_ORC
+void arch_handle_alternative(unsigned short feature, struct special_alt *alt)
 {
 }
+#endif
 
 static void reloc_to_sec_off(struct reloc *reloc, struct section **sec,
 			     unsigned long *off)
--- a/tools/objtool/weak.c
+++ b/tools/objtool/weak.c
@@ -15,12 +15,14 @@
 	return ENOSYS;							\
 })
 
-int __weak orc_dump(const char *_objname)
+#ifndef BUILD_ORC
+int orc_dump(const char *_objname)
 {
 	UNSUPPORTED("ORC");
 }
 
-int __weak orc_create(struct objtool_file *file)
+int orc_create(struct objtool_file *file)
 {
 	UNSUPPORTED("ORC");
 }
+#endif
--- a/tools/scripts/Makefile.include
+++ b/tools/scripts/Makefile.include
@@ -92,7 +92,7 @@ LLVM_OBJCOPY	?= llvm-objcopy
 LLVM_STRIP	?= llvm-strip
 
 ifeq ($(CC_NO_CLANG), 1)
-EXTRA_WARNINGS += -Wstrict-aliasing=3
+# EXTRA_WARNINGS += -Wstrict-aliasing=3
 
 else ifneq ($(CROSS_COMPILE),)
 # Allow userspace to override CLANG_CROSS_FLAGS to specify their own
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -100,6 +100,7 @@ int strtobool(const char *s, bool *res)
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wignored-attributes"
 #endif
+#ifndef __APPLE__
 size_t __weak strlcpy(char *dest, const char *src, size_t size)
 {
 	size_t ret = strlen(src);
@@ -111,6 +112,7 @@ size_t __weak strlcpy(char *dest, const
 	}
 	return ret;
 }
+#endif
 #ifdef __clang__
 #pragma clang diagnostic pop
 #endif