[PATCH] winebuild: Use Clang to assemble if its integrated assembler is being used. (try 2)

Charles Davis cdavis5x at gmail.com
Wed Jan 2 17:04:07 CST 2013


Try 2: Clarify that this is a Mac OS-only change. Don't use $CC as the assembler. Use the right flags to select 32/64-bit assembly.

The configure script invokes the system compiler to figure out if .cfi
pseudo-ops are supported, on the assumption that it will invoke the
system assembler. Winebuild, on the other hand, invokes the system
assembler directly. This caused a problem on Mac OS hosts when compiling
with Clang: configure would detect that .cfi ops were supported, because
Clang's integrated assembler supports them; however, when winebuild then
emitted assembly with .cfi ops in them, the system assembler would then
choke. This patch makes winebuild invoke Clang's assembler if a) we are
on Mac OS, b) $CC is detected to be Clang, and c) it is using (whether
by request or by default) its built-in assembler.

GNU as on other platforms supports .cfi directives, so there is no need
to do this anywhere but Mac OS.
---
 aclocal.m4              | 18 ++++++++++++++++++
 configure.ac            |  3 +++
 tools/winebuild/utils.c | 16 ++++++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/aclocal.m4 b/aclocal.m4
index 14cf916..0340f32 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -137,6 +137,24 @@ esac
 AC_CHECK_PROGS([$1],[$ac_prefix_list],[$3],[$4])])
 
 
+dnl **** Check if $CC is Clang and (if so) if integrated-as is being used ****
+dnl
+dnl Usage: WINE_CHECK_CLANG_AS
+dnl
+AC_DEFUN([WINE_CHECK_CLANG_AS],
+[AC_MSG_CHECKING([if the C compiler $CC is Clang])
+AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#ifndef __clang__
+                                    #error not clang
+                                    #endif]])],
+                  [AC_MSG_RESULT(yes)
+                   AC_MSG_CHECKING([if the Clang compiler $CC is using its built-in assembler])
+                   AS_IF([$CC -### -c -x c - </dev/null 2>&1 | grep "-emit-obj" >/dev/null],
+                         [AC_MSG_RESULT(yes)
+                          AC_DEFINE(USE_CLANG_AS,1,[Define to 1 if using Clang to assemble.])],
+                         AC_MSG_RESULT(no))],
+                  AC_MSG_RESULT(no))])
+
+
 dnl **** Define helper functions for creating config.status files ****
 dnl
 dnl Usage: AC_REQUIRE([WINE_CONFIG_HELPERS])
diff --git a/configure.ac b/configure.ac
index cb2e99a..e3c34ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -827,6 +827,9 @@ case $host_os in
                                        AC_MSG_ERROR([Xcode 3.x cannot build 16-bit code correctly. Use --disable-win16 if you don't need 16-bit support.])],
                                        AC_MSG_RESULT([[cross-compiling, assuming yes]]))
     fi
+
+    dnl Check for Clang's integrated-as
+    WINE_CHECK_CLANG_AS
     ;;
   *)
     DLLFLAGS="$DLLFLAGS -fPIC"
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index 09f9b73..c7da0d4 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -345,13 +345,28 @@ struct strarray *get_as_command(void)
 
     if (!as_command)
     {
+#ifdef USE_CLANG_AS
+        /* The native assembler might not support CFI pseudo-ops,
+         * but clang does. So on Mac OS, if we were compiled with
+         * clang, we should assemble with clang, too.
+         */
+        static const char * const commands[] = { "clang", NULL };
+        as_command = find_tool( "clang", commands );
+#else
         static const char * const commands[] = { "gas", "as", NULL };
         as_command = find_tool( "as", commands );
+#endif
     }
     strarray_add_one( args, as_command );
+#ifdef USE_CLANG_AS
+    strarray_add( args, "-xassembler", "-c", NULL );
+#endif
 
     if (force_pointer_size)
     {
+#ifdef USE_CLANG_AS
+        strarray_add_one( args, (force_pointer_size == 8) ? "-m64" : "-m32" );
+#else
         switch (target_platform)
         {
         case PLATFORM_APPLE:
@@ -369,6 +384,7 @@ struct strarray *get_as_command(void)
             }
             break;
         }
+#endif
     }
 
     if (cpu_option) strarray_add_one( args, strmake("-mcpu=%s", cpu_option) );
-- 
1.7.12.4




More information about the wine-patches mailing list