wok-current view linux/stuff/linux-fix-noreturn-attributes-gcc8.patch @ rev 25586

Fix linux build with gcc > 6 again
author Stanislas Leduc <shann@slitaz.org>
date Mon May 29 12:23:26 2023 +0000 (13 months ago)
parents
children
line source
1 gcc-7 has an "optimization" pass that completely screws up, and
2 generates the code expansion for the (impossible) case of calling
3 ilog2() with a zero constant, even when the code gcc compiles does not
4 actually have a zero constant.
6 And we try to generate a compile-time error for anybody doing ilog2() on
7 a constant where that doesn't make sense (be it zero or negative). So
8 now gcc7 will fail the build due to our sanity checking, because it
9 created that constant-zero case that didn't actually exist in the source
10 code.
12 There's a whole long discussion on the kernel mailing about how to work
13 around this gcc bug. The gcc people themselevs have discussed their
14 "feature" in
16 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785
18 but it's all water under the bridge, because while it looked at one
19 point like it would be solved by the time gcc7 was released, that was
20 not to be.
22 So now we have to deal with this compiler braindamage.
24 And the only simple approach seems to be to just delete the code that
25 tries to warn about bad uses of ilog2().
27 So now "ilog2()" will just return 0 not just for the value 1, but for
28 any non-positive value too.
30 It's not like I can recall anybody having ever actually tried to use
31 this function on any invalid value, but maybe the sanity check just
32 meant that such code never made it out in public.
34 Reported-by: Laura Abbott <labbott@redhat.com>
35 Cc: John Stultz <john.stultz@linaro.org>,
36 Cc: Thomas Gleixner <tglx@linutronix.de>
37 Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
38 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
40 diff --git a/include/linux/log2.h b/include/linux/log2.h
41 index ef3d4f67118ce..c373295f359fa 100644
42 --- a/include/linux/log2.h
43 +++ b/include/linux/log2.h
44 @@ -16,12 +16,6 @@
45 #include <linux/bitops.h>
47 /*
48 - * deal with unrepresentable constant logarithms
49 - */
50 -extern __attribute__((const, noreturn))
51 -int ____ilog2_NaN(void);
52 -
53 -/*
54 * non-constant log of base 2 calculators
55 * - the arch may override these in asm/bitops.h if they can be implemented
56 * more efficiently than using fls() and fls64()
57 @@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
58 #define ilog2(n) \
59 ( \
60 __builtin_constant_p(n) ? ( \
61 - (n) < 1 ? ____ilog2_NaN() : \
62 + (n) < 2 ? 0 : \
63 (n) & (1ULL << 63) ? 63 : \
64 (n) & (1ULL << 62) ? 62 : \
65 (n) & (1ULL << 61) ? 61 : \
66 @@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
67 (n) & (1ULL << 4) ? 4 : \
68 (n) & (1ULL << 3) ? 3 : \
69 (n) & (1ULL << 2) ? 2 : \
70 - (n) & (1ULL << 1) ? 1 : \
71 - (n) & (1ULL << 0) ? 0 : \
72 - ____ilog2_NaN() \
73 - ) : \
74 + 1 ) : \
75 (sizeof(n) <= 4) ? \
76 __ilog2_u32(n) : \
77 __ilog2_u64(n) \