Skip to contentSkip to conversation

x86: uapi: Fix __BITS_PER_LONG for x32

PATCH In review Ben Hutchings 4 participants 6 messages Oct 1, 2015 – Oct 2, 2015 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: uapi: Fix __BITS_PER_LONG for x32

On x32, gcc predefines __x86_64__ but long is only 32-bit. Use __ILP32__ to distinguish x32.

Fixes this compiler error in perf:

/«PKGBUILDDIR»/tools/include/asm-generic/bitops/__ffs.h: In function '__ffs':
/«PKGBUILDDIR»/tools/include/asm-generic/bitops/__ffs.h:19:8: error: right shift count >= width of type [-Werror=shift-count-overflow]

   word >>= 32;
        ^

This isn't sufficient to build perf for x32, though.

---
 arch/x86/include/uapi/asm/bitsperlong.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64
 #else
 # define __BITS_PER_LONG 32
Signature · 2 lines
Ben Hutchings
Knowledge is power.  France is bacon.
#1 lore raw

arch/x86/include/uapi/asm/bitsperlong.h line 5

Quoted 11 lines · Ben Hutchings
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64

Can we write this as:

   #ifdef __ILP64__

?

Thanks,

Ingo

#2 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 8 lines · Ben Hutchings
arch/x86/include/uapi/asm/bitsperlong.h +0 -0
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
Quoted 7 lines

arch/x86/include/uapi/asm/bitsperlong.h line 5

Quoted 3 lines
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64

Can we write this as:

   #ifdef __ILP64__

Do all versions of gcc/clang define that, even if x32 isn't supported?

--
Brian Gerst

#3 lore raw
Quoted 13 lines · Brian Gerst
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Ben Hutchings
arch/x86/include/uapi/asm/bitsperlong.h +0 -0
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
Quoted 7 lines
Quoted 7 lines

arch/x86/include/uapi/asm/bitsperlong.h line 5

Quoted 3 lines
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64

Can we write this as:

   #ifdef __ILP64__

Assuming you meant __LP64__...

Quoted 2 lines

Do all versions of gcc/clang define that, even if x32 isn't supported?

For gcc, it's been defined since 2003 (gcc 3.3):
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=0bdab2d89e28ca4dc84f8f0fafed85a4822bca49

For clang, it's been defined since before its first public release:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?r1=38978&r2=38987&pathrev=161685

So gcc 3.1 and 3.2 didn't define it, but everything newer does.

Ben.

Signature · 2 lines
Ben Hutchings
Knowledge is power.  France is bacon.
#4 lore raw
Quoted 27 lines · Ben Hutchings
Quoted 13 lines · Brian Gerst
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Ben Hutchings
arch/x86/include/uapi/asm/bitsperlong.h +0 -0
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
Quoted 7 lines
Quoted 7 lines

arch/x86/include/uapi/asm/bitsperlong.h line 5

Quoted 3 lines
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64

Can we write this as:

   #ifdef __ILP64__

Assuming you meant __LP64__...

Quoted 2 lines

Do all versions of gcc/clang define that, even if x32 isn't supported?

Quoted 7 lines

For gcc, it's been defined since 2003 (gcc 3.3):
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=0bdab2d89e28ca4dc84f8f0fafed85a4822bca49

For clang, it's been defined since before its first public release:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?r1=38978&r2=38987&pathrev=161685

So gcc 3.1 and 3.2 didn't define it, but everything newer does.

As the kernel itself is supposed to still be compilable with gcc 3.2, I think this means that my patch has the right condition.

Ben.

Signature · 2 lines
Ben Hutchings
When in doubt, use brute force. - Ken Thompson
#5 lore raw

[tip:x86/urgent] x86/headers/uapi: Fix __BITS_PER_LONG value for x32 builds

In reply to Ben Hutchings
x86/headers/uapi: Fix __BITS_PER_LONG value for x32 builds
Commit-ID:  f4b4aae1828855db761bf998ce37d3062b1d6446
Gitweb:     http://git.kernel.org/tip/f4b4aae1828855db761bf998ce37d3062b1d6446
Author:     Ben Hutchings <[email protected]>
AuthorDate: Thu, 1 Oct 2015 01:40:43 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 2 Oct 2015 09:43:21 +0200

x86/headers/uapi: Fix __BITS_PER_LONG value for x32 builds

On x32, gcc predefines __x86_64__ but long is only 32-bit. Use __ILP32__ to distinguish x32.

Fixes this compiler error in perf:

	tools/include/asm-generic/bitops/__ffs.h: In function '__ffs':
	tools/include/asm-generic/bitops/__ffs.h:19:8: error: right shift count >= width of type [-Werror=shift-count-overflow]
	  word >>= 32;
	       ^

This isn't sufficient to build perf for x32, though.

---
 arch/x86/include/uapi/asm/bitsperlong.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/uapi/asm/bitsperlong.h +1 -1
index b0ae1c4..217909b 100644
@@ -1,7 +1,7 @@
 #ifndef __ASM_X86_BITSPERLONG_H
 #define __ASM_X86_BITSPERLONG_H
 
-#ifdef __x86_64__
+#if defined(__x86_64__) && !defined(__ILP32__)
 # define __BITS_PER_LONG 64
 #else
 # define __BITS_PER_LONG 32