Fix kernel gcc7 issue
[AGL/meta-agl.git] / meta-agl-bsp / meta-rcar-gen3 / recipes-kernel / linux / files / 0001-give-up-on-gcc-ilog2-constant-optimizations.patch
1 From 474c90156c8dcc2fa815e6716cc9394d7930cb9c Mon Sep 17 00:00:00 2001
2 From: Linus Torvalds <torvalds@linux-foundation.org>
3 Date: Thu, 2 Mar 2017 12:17:22 -0800
4 Subject: [PATCH] give up on gcc ilog2() constant optimizations
5
6 gcc-7 has an "optimization" pass that completely screws up, and
7 generates the code expansion for the (impossible) case of calling
8 ilog2() with a zero constant, even when the code gcc compiles does not
9 actually have a zero constant.
10
11 And we try to generate a compile-time error for anybody doing ilog2() on
12 a constant where that doesn't make sense (be it zero or negative).  So
13 now gcc7 will fail the build due to our sanity checking, because it
14 created that constant-zero case that didn't actually exist in the source
15 code.
16
17 There's a whole long discussion on the kernel mailing about how to work
18 around this gcc bug.  The gcc people themselevs have discussed their
19 "feature" in
20
21    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785
22
23 but it's all water under the bridge, because while it looked at one
24 point like it would be solved by the time gcc7 was released, that was
25 not to be.
26
27 So now we have to deal with this compiler braindamage.
28
29 And the only simple approach seems to be to just delete the code that
30 tries to warn about bad uses of ilog2().
31
32 So now "ilog2()" will just return 0 not just for the value 1, but for
33 any non-positive value too.
34
35 It's not like I can recall anybody having ever actually tried to use
36 this function on any invalid value, but maybe the sanity check just
37 meant that such code never made it out in public.
38
39 Reported-by: Laura Abbott <labbott@redhat.com>
40 Cc: John Stultz <john.stultz@linaro.org>,
41 Cc: Thomas Gleixner <tglx@linutronix.de>
42 Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
43 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
44 ---
45  include/linux/log2.h       | 13 ++-----------
46  tools/include/linux/log2.h | 13 ++-----------
47  2 files changed, 4 insertions(+), 22 deletions(-)
48
49 diff --git a/include/linux/log2.h b/include/linux/log2.h
50 index ef3d4f67118c..c373295f359f 100644
51 --- a/include/linux/log2.h
52 +++ b/include/linux/log2.h
53 @@ -16,12 +16,6 @@
54  #include <linux/bitops.h>
55  
56  /*
57 - * deal with unrepresentable constant logarithms
58 - */
59 -extern __attribute__((const, noreturn))
60 -int ____ilog2_NaN(void);
61 -
62 -/*
63   * non-constant log of base 2 calculators
64   * - the arch may override these in asm/bitops.h if they can be implemented
65   *   more efficiently than using fls() and fls64()
66 @@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
67  #define ilog2(n)                               \
68  (                                              \
69         __builtin_constant_p(n) ? (             \
70 -               (n) < 1 ? ____ilog2_NaN() :     \
71 +               (n) < 2 ? 0 :                   \
72                 (n) & (1ULL << 63) ? 63 :       \
73                 (n) & (1ULL << 62) ? 62 :       \
74                 (n) & (1ULL << 61) ? 61 :       \
75 @@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
76                 (n) & (1ULL <<  4) ?  4 :       \
77                 (n) & (1ULL <<  3) ?  3 :       \
78                 (n) & (1ULL <<  2) ?  2 :       \
79 -               (n) & (1ULL <<  1) ?  1 :       \
80 -               (n) & (1ULL <<  0) ?  0 :       \
81 -               ____ilog2_NaN()                 \
82 -                                  ) :          \
83 +               1 ) :                           \
84         (sizeof(n) <= 4) ?                      \
85         __ilog2_u32(n) :                        \
86         __ilog2_u64(n)                          \
87 diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h
88 index 41446668ccce..d5677d39c1e4 100644
89 --- a/tools/include/linux/log2.h
90 +++ b/tools/include/linux/log2.h
91 @@ -13,12 +13,6 @@
92  #define _TOOLS_LINUX_LOG2_H
93  
94  /*
95 - * deal with unrepresentable constant logarithms
96 - */
97 -extern __attribute__((const, noreturn))
98 -int ____ilog2_NaN(void);
99 -
100 -/*
101   * non-constant log of base 2 calculators
102   * - the arch may override these in asm/bitops.h if they can be implemented
103   *   more efficiently than using fls() and fls64()
104 @@ -78,7 +72,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
105  #define ilog2(n)                               \
106  (                                              \
107         __builtin_constant_p(n) ? (             \
108 -               (n) < 1 ? ____ilog2_NaN() :     \
109 +               (n) < 2 ? 0 :                   \
110                 (n) & (1ULL << 63) ? 63 :       \
111                 (n) & (1ULL << 62) ? 62 :       \
112                 (n) & (1ULL << 61) ? 61 :       \
113 @@ -141,10 +135,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
114                 (n) & (1ULL <<  4) ?  4 :       \
115                 (n) & (1ULL <<  3) ?  3 :       \
116                 (n) & (1ULL <<  2) ?  2 :       \
117 -               (n) & (1ULL <<  1) ?  1 :       \
118 -               (n) & (1ULL <<  0) ?  0 :       \
119 -               ____ilog2_NaN()                 \
120 -                                  ) :          \
121 +               1 ) :                           \
122         (sizeof(n) <= 4) ?                      \
123         __ilog2_u32(n) :                        \
124         __ilog2_u64(n)                          \
125 -- 
126 2.13.6
127