[llvmlinux] [PATCH] x86/hweight: LLVMLinux: Fix __arch_hweight{32, 64}() for compilation with clang

Sedat Dilek sedat.dilek at gmail.com
Sun Sep 13 15:20:24 UTC 2015


Adapted partly from the original patch (see [1]).
This patch was formerly together with [2] and provided as a single patch.

To quote [3]:
"interesting, Jan-Simon said that patch was still part of the llvmlinux
tree (it is really mandatory for clang) so i'm not sure what's going on."

See also [3] for an explanation of PaX Team on how to do a proper fix.

Tested against Linux v4.2 with a self-built llvm-toolchain v3.7.0.
The generated Linux-kernel boots fine on a Ubuntu/precise AMD64 system.

A big thank you goes to Sanjoy and others for the vital help on #llvm.

NOTE: Please, follow the discussion in [4] to see the impact of this issue.

[1] http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob_plain;f=arch/x86_64/patches/ARCHIVE/0029-Fix-ARCH_HWEIGHT-for-compilation-with-clang.patch
[2] http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=arch/x86_64/patches/hweight-x86.patch
[3] http://lists.linuxfoundation.org/pipermail/llvmlinux/2015-September/001356.html
[4] http://marc.info/?t=144156156700001&r=1&w=2

CC: PaX Team <pageexec at gmail.com>
CC: Jan-Simon Moeller <jsmoeller at linuxfoundation.org>
CC: David Woodhouse <dwmw2 at infradead.org>
CC: llvmlinux at lists.linuxfoundation.org
CC: Sanjoy Das <sanjoy at playingwithpointers.com>
Signed-off-by: Sedat Dilek <sedat.dilek at gmail.com>
---
[ dileks: v2: Add a more meaningful subject-line ]

 arch/x86/include/asm/arch_hweight.h | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h
index 9686c3d9ff73..a187db48e77d 100644
--- a/arch/x86/include/asm/arch_hweight.h
+++ b/arch/x86/include/asm/arch_hweight.h
@@ -23,13 +23,7 @@
  */
 static inline unsigned int __arch_hweight32(unsigned int w)
 {
-	unsigned int res = 0;
-
-	asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT)
-		     : "="REG_OUT (res)
-		     : REG_IN (w));
-
-	return res;
+	return __sw_hweight32(w);
 }
 
 static inline unsigned int __arch_hweight16(unsigned int w)
@@ -44,18 +38,13 @@ static inline unsigned int __arch_hweight8(unsigned int w)
 
 static inline unsigned long __arch_hweight64(__u64 w)
 {
-	unsigned long res = 0;
 
 #ifdef CONFIG_X86_32
 	return  __arch_hweight32((u32)w) +
 		__arch_hweight32((u32)(w >> 32));
-#else
-	asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
-		     : "="REG_OUT (res)
-		     : REG_IN (w));
 #endif /* CONFIG_X86_32 */
 
-	return res;
+	return __sw_hweight64(w);
 }
 
 #endif
-- 
2.5.2



More information about the LLVMLinux mailing list