2023-08-01 13:50:18

by Naresh Kamboju

[permalink] [raw]
Subject: next: arm64: gcc-8-defconfig: ufshcd.c:10629:2: /builds/linux/include/linux/compiler_types.h:397:38: error: call to '__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON failed:

Following build error noticed while building Linux next-20230801 tag
arm64 defconfig with gcc-8 toolchain.

Regressions found on arm64:

- build/gcc-8-defconfig
- build/gcc-8-defconfig-40bc7ee5


Reported-by: Linux Kernel Functional Testing <[email protected]>

log:
-----
In function 'ufshcd_check_header_layout',
inlined from 'ufshcd_core_init' at
/builds/linux/drivers/ufs/core/ufshcd.c:10629:2:
/builds/linux/include/linux/compiler_types.h:397:38: error: call to
'__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON
failed: ((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2]
!= 0x80
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^


Links:
- https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/log
- https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/details/
- https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/history/


--
Linaro LKFT
https://lkft.linaro.org


2023-08-01 15:39:40

by Arnd Bergmann

[permalink] [raw]
Subject: Re: next: arm64: gcc-8-defconfig: ufshcd.c:10629:2: /builds/linux/include/linux/compiler_types.h:397:38: error: call to '__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON failed:

On Tue, Aug 1, 2023, at 16:23, Naresh Kamboju wrote:
> On Tue, 1 Aug 2023 at 18:53, Bart Van Assche <[email protected]> wrote:

>> > - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/log
>> > - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/details/
>> > - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/history/
>>
>> I can't reproduce this build error with a gcc-12 arm64 cross-compiler. How
>> important is gcc-8 for the ARM community?
>
> You are right,
> gcc-12 build pass.
> gcc-8 build failed.

I can also reproduce this with gcc-9.5.0 from
https://mirrors.edge.kernel.org/pub/tools/crosstool/ but
not with 10.5.0 or clang.

I get the same results for x86 with gcc-9.5.0.

See https://godbolt.org/z/GjGrW9znc for a partially reduced testcase.

Arnd

2023-08-01 18:23:47

by Bart Van Assche

[permalink] [raw]
Subject: Re: next: arm64: gcc-8-defconfig: ufshcd.c:10629:2: /builds/linux/include/linux/compiler_types.h:397:38: error: call to '__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON failed:

On 8/1/23 07:56, Arnd Bergmann wrote:
> On Tue, Aug 1, 2023, at 16:23, Naresh Kamboju wrote:
>> On Tue, 1 Aug 2023 at 18:53, Bart Van Assche <[email protected]> wrote:
>
>>>> - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/log
>>>> - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/details/
>>>> - https://qa-reports.linaro.org/lkft/linux-next-master/build/next-20230801/testrun/18754886/suite/build/test/gcc-8-defconfig/history/
>>>
>>> I can't reproduce this build error with a gcc-12 arm64 cross-compiler. How
>>> important is gcc-8 for the ARM community?
>>
>> You are right,
>> gcc-12 build pass.
>> gcc-8 build failed.
>
> I can also reproduce this with gcc-9.5.0 from
> https://mirrors.edge.kernel.org/pub/tools/crosstool/ but
> not with 10.5.0 or clang.
>
> I get the same results for x86 with gcc-9.5.0.
>
> See https://godbolt.org/z/GjGrW9znc for a partially reduced testcase.
Thanks Arnd, this is very helpful. The first error message reported for that
test case is as follows:

<source>:34:286: error: call to '__compiletime_assert_655' declared with attribute error: BUILD_BUG_ON failed: ((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80
34 | do { __attribute__((__noreturn__)) extern void __compiletime_assert_655(void) __attribute__((__error__("BUILD_BUG_ON failed: " "((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80")));
if (!(!(((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80))) __compiletime_assert_655(); } while (0);
|

If I change the return type of ufshcd_check_header_layout() from void
into unsigned int and insert the following at the start of that function:

return ((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80;

then the compiler shows the following in the output window:

xorl %eax, %eax

In other words, the expression next to the return statement evaluates to zero
but the same expression does not evaluate to zero in the BUILD_BUG_ON()
statement. Does this perhaps indicate a compiler bug? And if so, what is the
appropriate way to fix the build error? Insert an #ifdef/#endif pair inside
ufshcd_check_header_layout() such that the compile-time checks do not happen
for gcc version 9 or older?

Thanks,

Bart.

2023-08-01 20:31:00

by Arnd Bergmann

[permalink] [raw]
Subject: Re: next: arm64: gcc-8-defconfig: ufshcd.c:10629:2: /builds/linux/include/linux/compiler_types.h:397:38: error: call to '__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON failed:

On Tue, Aug 1, 2023, at 19:51, Bart Van Assche wrote:
> On 8/1/23 07:56, Arnd Bergmann wrote:
>> On Tue, Aug 1, 2023, at 16:23, Naresh Kamboju wrote:
>
> If I change the return type of ufshcd_check_header_layout() from void
> into unsigned int and insert the following at the start of that function:
>
> return ((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80;
>
> then the compiler shows the following in the output window:
>
> xorl %eax, %eax
>
> In other words, the expression next to the return statement evaluates to zero
> but the same expression does not evaluate to zero in the BUILD_BUG_ON()
> statement. Does this perhaps indicate a compiler bug? And if so, what is the
> appropriate way to fix the build error? Insert an #ifdef/#endif pair inside
> ufshcd_check_header_layout() such that the compile-time checks do not happen
> for gcc version 9 or older?

I played around it some more, and this apparently comes
down to constant-folding in sub-byte bitfields, so in the
older compilers neither the ==0x80 nor the !=0x80 case
can be ruled out because of a missing optimization.
Instead the generated code would try to initialize the
variable at runtime and then do a conditional branch to
the assert, but that of course fails the build.

I'd suggest something like

if (defined(GCC_VERSION) && GCC_VERSION < 100000)
return;

before the assertion, in that case it doesn't evaluate it.

Arnd

2023-08-01 20:39:53

by Bart Van Assche

[permalink] [raw]
Subject: Re: next: arm64: gcc-8-defconfig: ufshcd.c:10629:2: /builds/linux/include/linux/compiler_types.h:397:38: error: call to '__compiletime_assert_553' declared with attribute error: BUILD_BUG_ON failed:

On 8/1/23 12:54, Arnd Bergmann wrote:
> On Tue, Aug 1, 2023, at 19:51, Bart Van Assche wrote:
>> On 8/1/23 07:56, Arnd Bergmann wrote:
>>> On Tue, Aug 1, 2023, at 16:23, Naresh Kamboju wrote:
>>
>> If I change the return type of ufshcd_check_header_layout() from void
>> into unsigned int and insert the following at the start of that function:
>>
>> return ((u8 *)&(struct request_desc_header){ .enable_crypto = 1})[2] != 0x80;
>>
>> then the compiler shows the following in the output window:
>>
>> xorl %eax, %eax
>>
>> In other words, the expression next to the return statement evaluates to zero
>> but the same expression does not evaluate to zero in the BUILD_BUG_ON()
>> statement. Does this perhaps indicate a compiler bug? And if so, what is the
>> appropriate way to fix the build error? Insert an #ifdef/#endif pair inside
>> ufshcd_check_header_layout() such that the compile-time checks do not happen
>> for gcc version 9 or older?
>
> I played around it some more, and this apparently comes
> down to constant-folding in sub-byte bitfields, so in the
> older compilers neither the ==0x80 nor the !=0x80 case
> can be ruled out because of a missing optimization.
> Instead the generated code would try to initialize the
> variable at runtime and then do a conditional branch to
> the assert, but that of course fails the build.
>
> I'd suggest something like
>
> if (defined(GCC_VERSION) && GCC_VERSION < 100000)
> return;
>
> before the assertion, in that case it doesn't evaluate it.

An untested patch has been posted on the linux-scsi mailing list. It would
be really appreciated if someone could help with testing that patch since
none of the Linux distro's that I use regularly provides binaries for gcc-9
nor for gcc-8.

Thanks,

Bart.