Skip to contentSkip to conversation

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

PATCH Superseded Peter Maydell 4 participants 10 messages Feb 20, 2014 – Feb 21, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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.

---
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(-)
configure +7 -1
index 4648117..a2af9db 100755
@@ -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
tcg/i386/tcg-target.c +3 -1
index fef1717..f832282 100644
@@ -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);
Signature · 1 line
1.8.5
#1 lore raw
Quoted 5 lines · Peter Maydell

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.

Quoted 1 line

tcg/i386/tcg-target.c.

thanks
-- PMM

#2 lore raw
In reply to Peter Maydell

configure cpuid_h=no · line 3574

Quoted 8 lines · Peter Maydell
configure +7 -0
+    unsigned a, b, c, d;
+    int max = __get_cpuid_max(0, 0);
+
+    if (max >= 1) {
+        __cpuid(1, a, b, c, d);
+    }
+    return 0;
 }

You might as well check for __cpuid_count too while you're at it:

  if (max >= 7)
    __cpuid_count(7, 0, a, b, c, d);

Otherwise it looks good to me.

r~

#3 lore raw
In reply to Peter Maydell

Am 20.02.2014 18:50, schrieb Peter Maydell:

Quoted 7 lines

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.

Quoted 8 lines

---
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.

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).

Regards
Stefan

#4 lore raw
Quoted 3 lines · Stefan Weil

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

#5 lore raw

Am 20.02.2014 23:18, schrieb Peter Maydell:

Quoted 5 lines · Stefan Weil
Quoted 3 lines

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).

Quoted 7 lines

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.)

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).

Run configure with --cross-prefix=i686-w64-mingw32- or --cross-prefix=x86_64-w64-mingw32- to build 32 or 64 bit executables.

Stefan

#6 lore raw
Quoted 4 lines · Stefan Weil

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

#7 lore raw
In reply to Peter Maydell
Quoted 6 lines · Peter Maydell

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 or LLVM/Clang 3.4 or newer.

Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
#8 lore raw
Quoted 11 lines · Brad Smith
Quoted 7 lines · Peter Maydell

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

#9 lore raw
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Brad Smith
Quoted 7 lines · Peter Maydell

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.

Quoted 7 lines
Quoted 1 line

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.)

Ok, it wasn't as new as I had thought. Actually taking a look at the various releases __cpuid was added with GCC 4.3. __cpuid_count was added with GCC 4.4.

Signature · 3 lines
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.