Linux SPARSE checker discussions
 help / color / mirror / Atom feed
* [PATCH] sparse: predefine __ILP32__ and _ILP32 in 32-bit mode
@ 2026-06-12 10:27 Oleg Nesterov
  0 siblings, 0 replies; only message in thread
From: Oleg Nesterov @ 2026-06-12 10:27 UTC (permalink / raw)
  To: Chris Li, Luc Van Oostenryck; +Cc: Alexey Gladkov, linux-sparse

Unlike gcc, sparse doesn't define __ILP32__ in 32-bit mode:

	$ gcc -dM -E -m32 - </dev/null | grep LP32
	#define __ILP32__ 1
	#define _ILP32 1
	$ ./sparse -dM -E -m32 - </dev/null | grep LP32
	$

Because of this, arch/x86/include/uapi/asm/bitsperlong.h

	#if defined(__x86_64__) && !defined(__ILP32__)
	# define __BITS_PER_LONG 64
	#else
	# define __BITS_PER_LONG 32
	#endif

wrongly defines __BITS_PER_LONG == 64 when sparse inspects the files
in arch/x86/boot/. sparse treats -m16 like -m32 and this is fine for
sparse/semind purposes, but without __ILP32__ the bitsperlong checks
fail. For example, the following command

	$ make C=2 CHECK="semind add --"

complains:

	./include/asm-generic/bitsperlong.h:23:2: error: Inconsistent word size. Check asm/bitsperlong.h
	./include/asm-generic/bitsperlong.h:27:33: error: static assertion failed: "Inconsistent word size. Check asm/bitsperlong.h"

Change predefined_macros() to define __ILP32__ and _ILP32 for both
ARCH_X32 and ARCH_LP32.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 predefine.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/predefine.c b/predefine.c
index 5b0f0caf..28601aba 100644
--- a/predefine.c
+++ b/predefine.c
@@ -209,9 +209,8 @@ void predefined_macros(void)
 	predefine("__pragma__", 0, NULL);
 
 	switch (arch_m64) {
-	case ARCH_LP32:
-		break;
 	case ARCH_X32:
+	case ARCH_LP32:
 		predefine("__ILP32__", 1, "1");
 		predefine("_ILP32", 1, "1");
 		break;
-- 
2.52.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-12 10:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-12 10:27 [PATCH] sparse: predefine __ILP32__ and _ILP32 in 32-bit mode Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox