wok-current diff linux/stuff/linux-fix-noreturn-attributes-gcc8.patch @ rev 25698
Fix ntfs-3g receipt
author | Stanislas Leduc <shann@slitaz.org> |
---|---|
date | Tue Apr 16 19:01:01 2024 +0000 (2 months ago) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux/stuff/linux-fix-noreturn-attributes-gcc8.patch Tue Apr 16 19:01:01 2024 +0000 1.3 @@ -0,0 +1,77 @@ 1.4 +gcc-7 has an "optimization" pass that completely screws up, and 1.5 +generates the code expansion for the (impossible) case of calling 1.6 +ilog2() with a zero constant, even when the code gcc compiles does not 1.7 +actually have a zero constant. 1.8 + 1.9 +And we try to generate a compile-time error for anybody doing ilog2() on 1.10 +a constant where that doesn't make sense (be it zero or negative). So 1.11 +now gcc7 will fail the build due to our sanity checking, because it 1.12 +created that constant-zero case that didn't actually exist in the source 1.13 +code. 1.14 + 1.15 +There's a whole long discussion on the kernel mailing about how to work 1.16 +around this gcc bug. The gcc people themselevs have discussed their 1.17 +"feature" in 1.18 + 1.19 + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785 1.20 + 1.21 +but it's all water under the bridge, because while it looked at one 1.22 +point like it would be solved by the time gcc7 was released, that was 1.23 +not to be. 1.24 + 1.25 +So now we have to deal with this compiler braindamage. 1.26 + 1.27 +And the only simple approach seems to be to just delete the code that 1.28 +tries to warn about bad uses of ilog2(). 1.29 + 1.30 +So now "ilog2()" will just return 0 not just for the value 1, but for 1.31 +any non-positive value too. 1.32 + 1.33 +It's not like I can recall anybody having ever actually tried to use 1.34 +this function on any invalid value, but maybe the sanity check just 1.35 +meant that such code never made it out in public. 1.36 + 1.37 +Reported-by: Laura Abbott <labbott@redhat.com> 1.38 +Cc: John Stultz <john.stultz@linaro.org>, 1.39 +Cc: Thomas Gleixner <tglx@linutronix.de> 1.40 +Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> 1.41 +Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> 1.42 + 1.43 +diff --git a/include/linux/log2.h b/include/linux/log2.h 1.44 +index ef3d4f67118ce..c373295f359fa 100644 1.45 +--- a/include/linux/log2.h 1.46 ++++ b/include/linux/log2.h 1.47 +@@ -16,12 +16,6 @@ 1.48 + #include <linux/bitops.h> 1.49 + 1.50 + /* 1.51 +- * deal with unrepresentable constant logarithms 1.52 +- */ 1.53 +-extern __attribute__((const, noreturn)) 1.54 +-int ____ilog2_NaN(void); 1.55 +- 1.56 +-/* 1.57 + * non-constant log of base 2 calculators 1.58 + * - the arch may override these in asm/bitops.h if they can be implemented 1.59 + * more efficiently than using fls() and fls64() 1.60 +@@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) 1.61 + #define ilog2(n) \ 1.62 + ( \ 1.63 + __builtin_constant_p(n) ? ( \ 1.64 +- (n) < 1 ? ____ilog2_NaN() : \ 1.65 ++ (n) < 2 ? 0 : \ 1.66 + (n) & (1ULL << 63) ? 63 : \ 1.67 + (n) & (1ULL << 62) ? 62 : \ 1.68 + (n) & (1ULL << 61) ? 61 : \ 1.69 +@@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n) 1.70 + (n) & (1ULL << 4) ? 4 : \ 1.71 + (n) & (1ULL << 3) ? 3 : \ 1.72 + (n) & (1ULL << 2) ? 2 : \ 1.73 +- (n) & (1ULL << 1) ? 1 : \ 1.74 +- (n) & (1ULL << 0) ? 0 : \ 1.75 +- ____ilog2_NaN() \ 1.76 +- ) : \ 1.77 ++ 1 ) : \ 1.78 + (sizeof(n) <= 4) ? \ 1.79 + __ilog2_u32(n) : \ 1.80 + __ilog2_u64(n) \