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