From: Eric Biggers Date: Sat, 22 Aug 2015 16:27:12 +0000 (-0500) Subject: x86_cpu_features.c: cpuid fix for x86_32 PIC with old GCC versions X-Git-Tag: v1.8.2~3 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=719a063c87e3abab99b0fb53ebc80223fbf33123;hp=6bf4bba9f875d1815989a94c39a27f01961d82bb x86_cpu_features.c: cpuid fix for x86_32 PIC with old GCC versions --- diff --git a/src/x86_cpu_features.c b/src/x86_cpu_features.c index f8347575..aab200ff 100644 --- a/src/x86_cpu_features.c +++ b/src/x86_cpu_features.c @@ -22,13 +22,23 @@ u32 _x86_cpu_features = 0; +/* With old GCC versions we have to manually save and restore the x86_32 PIC + * register (ebx). See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47602 */ +#if defined(__i386__) && defined(__PIC__) +# define EBX_CONSTRAINT "=r" +#else +# define EBX_CONSTRAINT "=b" +#endif + /* Execute the CPUID instruction. */ static inline void -cpuid(u32 leaf, u32 subleaf, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) +cpuid(u32 leaf, u32 subleaf, u32 *a, u32 *b, u32 *c, u32 *d) { - __asm__ ("cpuid" - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "a" (leaf), "c" (subleaf)); + __asm__(".ifnc %%ebx, %1; mov %%ebx, %1; .endif\n" + "cpuid \n" + ".ifnc %%ebx, %1; xchg %%ebx, %1; .endif\n" + : "=a" (*a), EBX_CONSTRAINT (*b), "=c" (*c), "=d" (*d) + : "a" (leaf), "c" (subleaf)); } /* Read an extended control register. */