[PATCH] lscpu: fix cpuid code on x86/PIC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we build lscpu as PIE, we currently get a build failure:
lscpu.c: In function 'main':
lscpu.c:333: error: can't find a register in class 'BREG' while reloading 'asm'
lscpu.c:333: error: 'asm' operand has impossible constraints
make[2]: *** [lscpu.o] Error 1

So we need a little bit of register shuffling to keep gcc happy.

Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
---
 sys-utils/lscpu.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 3e3fbbe..6b6082f 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -330,9 +330,19 @@ static inline void
 cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx,
 			 unsigned int *ecx, unsigned int *edx)
 {
-	__asm__("cpuid"
-		: "=a" (*eax),
-		  "=b" (*ebx),
+	__asm__(
+#if defined(__PIC__) && defined(__i386__)
+		/* x86 PIC cannot clobber ebx -- gcc bitches */
+		"pushl %%ebx;"
+		"cpuid;"
+		"movl %%ebx, %%esi;"
+		"popl %%ebx;"
+		: "=S" (*ebx),
+#else
+		"cpuid;"
+		: "=b" (*ebx),
+#endif
+		  "=a" (*eax),
 		  "=c" (*ecx),
 		  "=d" (*edx)
 		: "0" (op), "c"(0));
-- 
1.6.2.3

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux