From: nick.j.sanders Date: Mon, 7 Jan 2013 22:13:27 +0000 (+0000) Subject: Fix handling of cpuid and PIC on i386 systems X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=75884d4d5d55df09c56232f460011d5a5d42d547;p=stressapptest Fix handling of cpuid and PIC on i386 systems The current cpuid logic clobbers %ebx. this is OK if the code is not PIC, but if you're building PIEs, it'll fail because %ebx is the PIC register and gcc doesn't let you clobber it. Thanks to vapier@chromium.org --- diff --git a/src/os.cc b/src/os.cc index 944ff88..225e86c 100644 --- a/src/os.cc +++ b/src/os.cc @@ -169,7 +169,16 @@ void OsLayer::GetFeatures() { // http://www.sandpile.org/ia32/cpuid.htm int ax, bx, cx, dx; __asm__ __volatile__ ( - "cpuid": "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (1)); +# if defined(STRESSAPPTEST_CPU_I686) && defined(__PIC__) + "xchg %%ebx, %%esi;" + "cpuid;" + "xchg %%esi, %%ebx;" + : "=S" (bx), +# else + "cpuid;" + : "=b" (bx), +# endif + "=a" (ax), "=c" (cx), "=d" (dx) : "a" (1)); has_clflush_ = (dx >> 19) & 1; has_sse2_ = (dx >> 26) & 1; diff --git a/src/worker.cc b/src/worker.cc index dcf4dcb..eddea6c 100644 --- a/src/worker.cc +++ b/src/worker.cc @@ -82,7 +82,17 @@ namespace { inline int apicid(void) { int cpu; #if defined(STRESSAPPTEST_CPU_X86_64) || defined(STRESSAPPTEST_CPU_I686) - __asm __volatile("cpuid" : "=b" (cpu) : "a" (1) : "cx", "dx"); + __asm__ __volatile__ ( +# if defined(STRESSAPPTEST_CPU_I686) && defined(__PIC__) + "xchg %%ebx, %%esi;" + "cpuid;" + "xchg %%esi, %%ebx;" + : "=S" (cpu) +# else + "cpuid;" + : "=b" (cpu) +# endif + : "a" (1) : "cx", "dx"); #elif defined(STRESSAPPTEST_CPU_ARMV7A) #warning "Unsupported CPU type ARMV7A: unable to determine core ID." cpu = 0;