From 28f0c63388ab7eeeb0953355dc4ff2edc5afe9e8 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 10 May 2009 16:37:18 -0400 Subject: [PATCH] lscpu: fix cpuid code on x86/PIC 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 --- sys-utils/lscpu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 3e3fbbeb..6b6082fb 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)); -- 2.39.5