[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <DCF1A7F6-727F-4094-8DB9-0B566D0970BA@zytor.com>
Date: Tue, 20 Jan 2026 04:01:04 -0800
From: "H. Peter Anvin" <hpa@...or.com>
To: David Laight <david.laight.linux@...il.com>, Arnd Bergmann <arnd@...db.de>
CC: Thomas Weißschuh <thomas.weissschuh@...utronix.de>,
"David S . Miller" <davem@...emloft.net>,
Andreas Larsson <andreas@...sler.com>,
Andy Lutomirski <luto@...nel.org>, Thomas Gleixner <tglx@...nel.org>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
Heiko Carstens <hca@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, sparclinux@...r.kernel.org,
linux-kernel@...r.kernel.org, Linux-Arch <linux-arch@...r.kernel.org>,
linux-s390@...r.kernel.org
Subject: Re: [PATCH 4/4] asm-generic/bitsperlong.h: Add sanity checks for __BITS_PER_LONG
On January 20, 2026 2:03:31 AM PST, David Laight <david.laight.linux@...il.com> wrote:
>On Mon, 19 Jan 2026 22:39:53 +0100
>"Arnd Bergmann" <arnd@...db.de> wrote:
>
>> On Mon, Jan 19, 2026, at 22:12, H. Peter Anvin wrote:
>> > On 2026-01-19 07:39, Thomas Weißschuh wrote:
>> >>>
>> >>> Do we actually support any compilers which *don't* define __SIZEOF_LONG__?
>> >>
>> >> When building the kernel not. I used this pattern because it is used
>> >> further up in the file. There it makes sense as it is actually a userspace
>> >> header which needs to support all kinds of compilers.
>> >> But this new check is gated behind __KERNEL__ anyways...
>> >> For the next revision I will move it into the regular kernel-internal
>> >> bitsperlong.h. That will be less confusing and still handle the vDSO build,
>> >> due to the way our header hierarchy works.
>> >>
>> >
>> > The point is that we can simply do:
>> >
>> > #define __BITS_PER_LONG (__SIZEOF_LONG__ << 3)
>> >
>> > ... and it will always be consistent.
>>
>> We have discussed this before, but decided it was too early to
>> assume that userspace compilers are recent enough for that.
>> According to godbolt.org, gcc-4.1 lacks __SIZEOF_LONG__ while
>> gcc-4.4 has it, as do all versions of clang. Not sure what other
>> compilers one may encounter using Linux kernel headers.
>
>For instance MSVC doesn't define __SIZEOF_LONG__ or __x86_64__.
>Unlikely to be used, but...
>
>So you can use __SIZEOF_LONG__ if it is defined, if not hunt for
>something else (possible just fixed in the installed headers).
>But in the latter case (at least) a compile-time check that the
>value is correct makes sense.
>And that can be done portably - probable with a negative array size.
>
> David
>
>>
>> Arnd
>>
>
>
If it doesn't define __x86_64__ it isn't API compliant at all, so it doesn't make any sense to talk about it.
The most portable way to do it in standard C is to use <limits.h>, but that of course has the header pollution problem.
Powered by blists - more mailing lists