From: Mike Frysinger Date: Sun, 10 May 2009 20:37:18 +0000 (-0400) Subject: lscpu: fix cpuid code on x86/PIC X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9239f23acdc8b50f8bcbfadf967c6a490fd4693;p=util-linux 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 --- 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));