[meta-intel] [PATCH] linux-intel: Backport patch to fix build with gcc7

Khem Raj raj.khem at gmail.com
Tue Apr 18 11:08:44 PDT 2017


On Tue, Apr 18, 2017 at 7:46 AM, Saul Wold <sgw at linux.intel.com> wrote:
> On Mon, 2017-04-17 at 23:40 +0000, Khem Raj wrote:
>> Signed-off-by: Khem Raj <raj.khem at gmail.com>
>> ---
>>  ...ve-up-on-gcc-ilog2-constant-optimizations.patch | 127
>> +++++++++++++++++++++
>>  common/recipes-kernel/linux/linux-intel_4.9.bb     |   5 +-
>>  2 files changed, 130 insertions(+), 2 deletions(-)
>>  create mode 100644 common/recipes-kernel/linux/files/0001-give-up-
>> on-gcc-ilog2-constant-optimizations.patch
>>
>> diff --git a/common/recipes-kernel/linux/files/0001-give-up-on-gcc-
>> ilog2-constant-optimizations.patch b/common/recipes-
>> kernel/linux/files/0001-give-up-on-gcc-ilog2-constant-
>> optimizations.patch
>> new file mode 100644
>> index 0000000..481e1b6
>> --- /dev/null
>> +++ b/common/recipes-kernel/linux/files/0001-give-up-on-gcc-ilog2-
>> constant-optimizations.patch
>> @@ -0,0 +1,127 @@
>> +From c2812ad30bf55b62a5aefd3b1602a9c5d7f2dccc Mon Sep 17 00:00:00
>> 2001
>> +From: Linus Torvalds <torvalds at linux-foundation.org>
>> +Date: Thu, 2 Mar 2017 12:17:22 -0800
>> +Subject: [PATCH] give up on gcc ilog2() constant optimizations
>> +
>> +gcc-7 has an "optimization" pass that completely screws up, and
>> +generates the code expansion for the (impossible) case of calling
>> +ilog2() with a zero constant, even when the code gcc compiles does
>> not
>> +actually have a zero constant.
>> +
>> +And we try to generate a compile-time error for anybody doing
>> ilog2() on
>> +a constant where that doesn't make sense (be it zero or
>> negative).  So
>> +now gcc7 will fail the build due to our sanity checking, because it
>> +created that constant-zero case that didn't actually exist in the
>> source
>> +code.
>> +
>> +There's a whole long discussion on the kernel mailing about how to
>> work
>> +around this gcc bug.  The gcc people themselevs have discussed their
>> +"feature" in
>> +
>> +   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72785
>> +
>> +but it's all water under the bridge, because while it looked at one
>> +point like it would be solved by the time gcc7 was released, that
>> was
>> +not to be.
>> +
>> +So now we have to deal with this compiler braindamage.
>> +
>> +And the only simple approach seems to be to just delete the code
>> that
>> +tries to warn about bad uses of ilog2().
>> +
>> +So now "ilog2()" will just return 0 not just for the value 1, but
>> for
>> +any non-positive value too.
>> +
>> +It's not like I can recall anybody having ever actually tried to use
>> +this function on any invalid value, but maybe the sanity check just
>> +meant that such code never made it out in public.
>> +
>> +Reported-by: Laura Abbott <labbott at redhat.com>
>> +Cc: John Stultz <john.stultz at linaro.org>,
>> +Cc: Thomas Gleixner <tglx at linutronix.de>
>> +Cc: Ard Biesheuvel <ard.biesheuvel at linaro.org>
>> +Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
>> +---
>> + include/linux/log2.h       | 13 ++-----------
>> + tools/include/linux/log2.h | 13 ++-----------
>> + 2 files changed, 4 insertions(+), 22 deletions(-)
>> +
>> +diff --git a/include/linux/log2.h b/include/linux/log2.h
>> +index fd7ff3d..f38fae2 100644
>> +--- a/include/linux/log2.h
>> ++++ b/include/linux/log2.h
>> +@@ -16,12 +16,6 @@
>> + #include <linux/bitops.h>
>> +
>> + /*
>> +- * deal with unrepresentable constant logarithms
>> +- */
>> +-extern __attribute__((const, noreturn))
>> +-int ____ilog2_NaN(void);
>> +-
>> +-/*
>> +  * non-constant log of base 2 calculators
>> +  * - the arch may override these in asm/bitops.h if they can be
>> implemented
>> +  *   more efficiently than using fls() and fls64()
>> +@@ -85,7 +79,7 @@ unsigned long __rounddown_pow_of_two(unsigned long
>> n)
>> + #define ilog2(n)                            \
>> + (                                           \
>> +     __builtin_constant_p(n) ? (             \
>> +-            (n) < 1 ? ____ilog2_NaN() :     \
>> ++            (n) < 2 ? 0 :                   \
>> +             (n) & (1ULL << 63) ? 63 :       \
>> +             (n) & (1ULL << 62) ? 62 :       \
>> +             (n) & (1ULL << 61) ? 61 :       \
>> +@@ -148,10 +142,7 @@ unsigned long __rounddown_pow_of_two(unsigned
>> long n)
>> +             (n) & (1ULL <<  4) ?  4 :       \
>> +             (n) & (1ULL <<  3) ?  3 :       \
>> +             (n) & (1ULL <<  2) ?  2 :       \
>> +-            (n) & (1ULL <<  1) ?  1 :       \
>> +-            (n) & (1ULL <<  0) ?  0 :       \
>> +-            ____ilog2_NaN()                 \
>> +-                               ) :          \
>> ++            1 ) :                           \
>> +     (sizeof(n) <= 4) ?                      \
>> +     __ilog2_u32(n) :                        \
>> +     __ilog2_u64(n)                          \
>> +diff --git a/tools/include/linux/log2.h b/tools/include/linux/log2.h
>> +index 4144666..d5677d3 100644
>> +--- a/tools/include/linux/log2.h
>> ++++ b/tools/include/linux/log2.h
>> +@@ -13,12 +13,6 @@
>> + #define _TOOLS_LINUX_LOG2_H
>> +
>> + /*
>> +- * deal with unrepresentable constant logarithms
>> +- */
>> +-extern __attribute__((const, noreturn))
>> +-int ____ilog2_NaN(void);
>> +-
>> +-/*
>> +  * non-constant log of base 2 calculators
>> +  * - the arch may override these in asm/bitops.h if they can be
>> implemented
>> +  *   more efficiently than using fls() and fls64()
>> +@@ -78,7 +72,7 @@ unsigned long __rounddown_pow_of_two(unsigned long
>> n)
>> + #define ilog2(n)                            \
>> + (                                           \
>> +     __builtin_constant_p(n) ? (             \
>> +-            (n) < 1 ? ____ilog2_NaN() :     \
>> ++            (n) < 2 ? 0 :                   \
>> +             (n) & (1ULL << 63) ? 63 :       \
>> +             (n) & (1ULL << 62) ? 62 :       \
>> +             (n) & (1ULL << 61) ? 61 :       \
>> +@@ -141,10 +135,7 @@ unsigned long __rounddown_pow_of_two(unsigned
>> long n)
>> +             (n) & (1ULL <<  4) ?  4 :       \
>> +             (n) & (1ULL <<  3) ?  3 :       \
>> +             (n) & (1ULL <<  2) ?  2 :       \
>> +-            (n) & (1ULL <<  1) ?  1 :       \
>> +-            (n) & (1ULL <<  0) ?  0 :       \
>> +-            ____ilog2_NaN()                 \
>> +-                               ) :          \
>> ++            1 ) :                           \
>> +     (sizeof(n) <= 4) ?                      \
>> +     __ilog2_u32(n) :                        \
>> +     __ilog2_u64(n)                          \
>> +--
>> +1.9.1
>> +
>> diff --git a/common/recipes-kernel/linux/linux-intel_4.9.bb
>> b/common/recipes-kernel/linux/linux-intel_4.9.bb
>> index 46821a9..d26a6ad 100644
>> --- a/common/recipes-kernel/linux/linux-intel_4.9.bb
>> +++ b/common/recipes-kernel/linux/linux-intel_4.9.bb
>> @@ -6,8 +6,9 @@ SRCREV_machine ?=
>> "6f425e57c6afaed5d61cd9b8abe898bae97f9374"
>>  SRCREV_meta ?= "b65e9b6153237e3ee898a01bc418c12f7404a681"
>>
>>  SRC_URI = "git://github.com/01org/linux-intel-
>> 4.9.git;protocol=https;name=machine;branch=${KBRANCH}; \
>> -           git://git.yoctoproject.org/yocto-kernel-
>> cache;type=kmeta;name=meta;branch=yocto-4.9;destsuffix=${KMETA}"
>> -
>> +           git://git.yoctoproject.org/yocto-kernel-
>> cache;type=kmeta;name=meta;branch=yocto-4.9;destsuffix=${KMETA} \
>> +           file://0001-give-up-on-gcc-ilog2-constant-
>> optimizations.patch \
>> +"
>>  LINUX_VERSION ?= "4.9.15"
>>
> Timing is, this patch failed due to a kernel SRCREV Update that pushed
> this to 4.9.20, I am also concerned about adding this patch just before
> the release, can this wait until after M4 BSP releases?
>
> I have also submitted this to the linux-intel kernel, so it might
> appear there directly.

if you are upgrading to 4.9.20+ then this patch is already there
this patch then can be ignored.

>
> Thanks
> Sau!
>
>>  PV = "${LINUX_VERSION}+git${SRCPV}"


More information about the meta-intel mailing list