sandyou / stressapptest

Automatically exported from code.google.com/p/stressapptest
Apache License 2.0
0 stars 0 forks source link

fix handling of cpuid and PIC on i386 systems #26

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

simple fix:
  int ax, bx, cx, dx;
  __asm__ __volatile__ (
      "mov %%ebx, %%edi;"
      "cpuid;"
      "mov %%ebx, %%esi;"
      "mov %%edi, %%ebx;"
      :"=a" (ax), "=S" (bx), "=c" (cx), "=d" (dx) : "a"(1) :"edi");

it's a few more insns on x86_64 or i386/non-pic, so if you want, you could do 
something like:
#if defined(STRESSAPPTEST_CPU_I686) && defined(__PIC__)
 ... do pic version here ...
#else
 ... do non-pic version here ...
#endif

Original issue reported on code.google.com by vapier@gmail.com on 27 Nov 2012 at 7:19

GoogleCodeExporter commented 9 years ago
simpler patch:
http://sources.gentoo.org/dev-util/stressapptest/files/stressapptest-1.0.4-cpuid
-pic.patch

Original comment by vap...@google.com on 5 Jan 2013 at 7:32

GoogleCodeExporter commented 9 years ago
The similar problem appears in worker.cc line 88.

Original comment by bruce3...@gmail.com on 6 Jan 2013 at 6:32

GoogleCodeExporter commented 9 years ago
i've updated the patch in Gentoo to handle that file too

Original comment by vapier@chromium.org on 6 Jan 2013 at 7:21

GoogleCodeExporter commented 9 years ago
Thanks a lot!

Original comment by bruce3...@gmail.com on 6 Jan 2013 at 7:25

GoogleCodeExporter commented 9 years ago
I've imported vapier's patch. Should be fixed now.

Original comment by nsanders@google.com on 7 Jan 2013 at 10:14