[ovs-dev] [PATCH] configure: Pass correct -target option to "cgcc" in the common case.

Ben Pfaff blp at nicira.com
Mon Jul 11 20:58:12 UTC 2011


The "cgcc" script included with sparse guesses the target architecture
based on the host architecture instead of based on the GCC architecture.
This means that it often guesses wrong on biarch systems, e.g. my Linux
kernel is x86_64 but userspace is i686 and thus GCC targets i686 by
default.

This fixes the problem by passing an explicit "-target=i86" to cgcc if
GCC targets x86 or "-target=x86_64" if GCC targets x86_64.

Bug #6312.
Reported-by: Ethan Jackson <ethan at nicira.com>
---
 acinclude.m4 |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 1618a43..b379489 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -409,10 +409,30 @@ EOF
       fi])
    AS_IF([test $ovs_cv_gnu_make_if = yes], [$1], [$2])])
 
+dnl OVS_CHECK_SPARSE_TARGET
+dnl
+dnl The "cgcc" script from "sparse" isn't very good at detecting the
+dnl target for which the code is being built.  This helps it out.
+AC_DEFUN([OVS_CHECK_SPARSE_TARGET],
+  [AC_CACHE_CHECK(
+    [target hint for cgcc],
+    [ac_cv_sparse_target],
+    [AS_CASE([`$CC -dumpmachine 2>/dev/null`],
+       [i?86-* | athlon-*], [ac_cv_sparse_target=x86],
+       [x86_64-*], [ac_cv_sparse_target=x86_64],
+       [ac_cv_sparse_target=other])])
+   AS_CASE([$ac_cv_sparse_target],
+     [x86], [SPARSEFLAGS= CGCCFLAGS=-target=i86],
+     [x86_64], [SPARSEFLAGS=-m64 CGCCFLAGS=-target=x86_64],
+     [SPARSEFLAGS= CGCCFLAGS=])
+   AC_SUBST([SPARSEFLAGS])
+   AC_SUBST([CGCCFLAGS])])
+
 dnl OVS_ENABLE_SPARSE
 AC_DEFUN([OVS_ENABLE_SPARSE],
-  [OVS_MAKE_HAS_IF(
+  [AC_REQUIRE([OVS_CHECK_SPARSE_TARGET])
+   OVS_MAKE_HAS_IF(
      [AC_CONFIG_COMMANDS_PRE(
         [: ${SPARSE=sparse}
          AC_SUBST([SPARSE])
-         CC='$(if $(C),REAL_CC="'"$CC"'" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse" cgcc,'"$CC"')'])])])
+         CC='$(if $(C),REAL_CC="'"$CC"'" CHECK="$(SPARSE) -I $(top_srcdir)/include/sparse $(SPARSEFLAGS)" cgcc $(CGCCFLAGS),'"$CC"')'])])])
-- 
1.7.4.4




More information about the dev mailing list