diff mbox

tcg/i386: Fix build for systems without working cpuid.h (MacOSX, Win32)

Message ID 1392918631-14234-1-git-send-email-peter.maydell@linaro.org
State Superseded
Headers show

Commit Message

Peter Maydell Feb. 20, 2014, 5:50 p.m. UTC
Win32 doesn't have a cpuid.h, and MacOSX may have one but without
the __cpuid() function we use, which means that commit 9d2eec20
broke the build for those platforms. Fix this by tightening up
our configure cpuid.h check to test that the functions we need
are present, and adding some missing #ifdef guerds in
tcg/i386/tcg-target.c.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
Tested with Linux x86/64 gcc build, Linux x86/64 clang build,
W32 cross-build and MacOSX 10.8 build. If somebody would like to
review this I'll apply it directly to unbreak things.
Apologies for not catching it before I pushed the tcg pullreq;
I had forgotten to add the 'build on w32' command to my script.

 configure             | 8 +++++++-
 tcg/i386/tcg-target.c | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)

Comments

Peter Maydell Feb. 20, 2014, 5:53 p.m. UTC | #1
On 20 February 2014 17:50, Peter Maydell <peter.maydell@linaro.org> wrote:
> Win32 doesn't have a cpuid.h, and MacOSX may have one but without
> the __cpuid() function we use, which means that commit 9d2eec20
> broke the build for those platforms. Fix this by tightening up
> our configure cpuid.h check to test that the functions we need
> are present, and adding some missing #ifdef guerds in

"guards"; will fix locally.

> tcg/i386/tcg-target.c.

thanks
-- PMM
Peter Maydell Feb. 20, 2014, 10:18 p.m. UTC | #2
On 20 February 2014 21:18, Stefan Weil <sw@weilnetz.de> wrote:
> MinGW-w64's gcc has cpuid.h, so my 32 and 64 bit cross builds work
> without problems. We can use that code for MinGW, too, but we could also
> stop supporting MinGW (which has several other deficits).

We need the conditionals for MacOSX builds anyway, so we
don't need to drop MinGW for this. (I compile with the 32 bit
version rather than -w64 because I was able to get that to
install on my Ubuntu box, whereas the -w64 seemed to have
dependency issues/conflicts somehow. I figured the 32 bit
version was good enough for detecting the typical "long is
a funny size and we don't build" issues.)

thanks
-- PMM
Peter Maydell Feb. 21, 2014, 12:09 a.m. UTC | #3
On 20 February 2014 23:55, Brad Smith <brad@comstyle.com> wrote:
> On 20/02/14 12:50 PM, Peter Maydell wrote:
>>
>> Win32 doesn't have a cpuid.h, and MacOSX may have one but without
>> the __cpuid() function we use, which means that commit 9d2eec20
>> broke the build for those platforms. Fix this by tightening up
>> our configure cpuid.h check to test that the functions we need
>> are present, and adding some missing #ifdef guerds in
>> tcg/i386/tcg-target.c.
>
>
> The build will also fail if not using fairly new GCC

Do you happen to know how new 'fairly new' is? My stock compile
is with gcc 4.6.something, which isn't a spring chicken any more,
and that worked OK.

(We're going to fix this anyway, so it's just for my curiosity.)

thanks
-- PMM
Peter Maydell Feb. 21, 2014, 4:32 p.m. UTC | #4
On 21 February 2014 05:53, Stefan Weil <sw@weilnetz.de> wrote:
> One of my hosts runs Ubuntu precise. mingw-w64 works fine here and
> includes both 32 bit and 64 compilers and libraries (the -w64 in its
> name might be misleading). Maybe you will also need mingw-w64-tools, and
> you can also add g++-mingw-w64 (which also includes two compilers).

Hmm, it looks like apt-get is just confused and produces
a useless error message if you try to install mingw-w64
at the same time as mingw32...

thanks
-- PMM
diff mbox

Patch

diff --git a/configure b/configure
index 4648117..a2af9db 100755
--- a/configure
+++ b/configure
@@ -3564,7 +3564,13 @@  cpuid_h=no
 cat > $TMPC << EOF
 #include <cpuid.h>
 int main(void) {
-  return 0;
+    unsigned a, b, c, d;
+    int max = __get_cpuid_max(0, 0);
+
+    if (max >= 1) {
+        __cpuid(1, a, b, c, d);
+    }
+    return 0;
 }
 EOF
 if compile_prog "" "" ; then
diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index fef1717..f832282 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -115,7 +115,7 @@  static const int tcg_target_call_oarg_regs[] = {
    is available.  */
 #if TCG_TARGET_REG_BITS == 64
 # define have_cmov 1
-#elif defined(CONFIG_CPUID_H)
+#elif defined(CONFIG_CPUID_H) && defined(bit_CMOV)
 static bool have_cmov;
 #else
 # define have_cmov 0
@@ -2295,6 +2295,7 @@  static void tcg_target_qemu_prologue(TCGContext *s)
 
 static void tcg_target_init(TCGContext *s)
 {
+#ifdef CONFIG_CPUID_H
     unsigned a, b, c, d;
     int max = __get_cpuid_max(0, 0);
 
@@ -2323,6 +2324,7 @@  static void tcg_target_init(TCGContext *s)
         have_bmi2 = (b & bit_BMI2) != 0;
 #endif
     }
+#endif
 
     if (TCG_TARGET_REG_BITS == 64) {
         tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffff);