mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: David Laight <david.laight.linux@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>
Cc: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"David S . Miller" <davem@davemloft.net>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org,
	Linux-Arch <linux-arch@vger.kernel.org>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH 4/4] asm-generic/bitsperlong.h: Add sanity checks for __BITS_PER_LONG
Date: Tue, 20 Jan 2026 04:01:04 -0800	[thread overview]
Message-ID: <DCF1A7F6-727F-4094-8DB9-0B566D0970BA@zytor.com> (raw)
In-Reply-To: <20260120100331.1f57aa99@pumpkin>

On January 20, 2026 2:03:31 AM PST, David Laight <david.laight.linux@gmail.com> wrote:
>On Mon, 19 Jan 2026 22:39:53 +0100
>"Arnd Bergmann" <arnd@arndb.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.

      reply	other threads:[~2026-01-20 12:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16  7:40 [PATCH 0/4] vDSO: Use 32-bit CHECKFLAGS for compat vDSO Thomas Weißschuh
2026-01-16  7:40 ` [PATCH 1/4] sparc64: vdso: " Thomas Weißschuh
2026-01-16  7:50   ` Arnd Bergmann
2026-01-16  7:40 ` [PATCH 2/4] x86/vdso: " Thomas Weißschuh
2026-01-16  7:49   ` Arnd Bergmann
2026-01-16  8:09     ` Thomas Weißschuh
2026-01-17 22:02       ` H. Peter Anvin
2026-01-17 22:05   ` Thomas Gleixner
2026-01-19  7:20     ` Thomas Weißschuh
2026-01-19 15:33       ` H. Peter Anvin
2026-01-16  7:40 ` [PATCH 3/4] s390/vdso: Trim includes in linker script Thomas Weißschuh
2026-01-16  7:45   ` Arnd Bergmann
2026-01-16  8:15     ` Thomas Weißschuh
2026-01-17 15:22   ` Heiko Carstens
2026-01-16  7:40 ` [PATCH 4/4] asm-generic/bitsperlong.h: Add sanity checks for __BITS_PER_LONG Thomas Weißschuh
2026-01-16  7:46   ` Arnd Bergmann
2026-01-19 10:06   ` David Laight
2026-01-19 10:13     ` Thomas Weißschuh
2026-01-19 10:37       ` David Laight
2026-01-19 10:56         ` Thomas Weißschuh
2026-01-19 12:45           ` Arnd Bergmann
2026-01-19 13:41             ` Thomas Weißschuh
2026-01-19 14:57               ` Arnd Bergmann
2026-01-19 17:47                 ` David Laight
2026-01-20  7:23                   ` Thomas Weißschuh
2026-01-19 15:33   ` H. Peter Anvin
2026-01-19 15:39     ` Thomas Weißschuh
2026-01-19 21:12       ` H. Peter Anvin
2026-01-19 21:39         ` Arnd Bergmann
2026-01-20 10:03           ` David Laight
2026-01-20 12:01             ` H. Peter Anvin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DCF1A7F6-727F-4094-8DB9-0B566D0970BA@zytor.com \
    --to=hpa@zytor.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andreas@gaisler.com \
    --cc=arnd@arndb.de \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=david.laight.linux@gmail.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=tglx@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®