[llvm-commits] [Review request][Win64] Patches for Mingw-w64(and mingw64-clang)

NAKAMURA Takumi geek4civic at gmail.com
Mon Jan 31 19:05:18 PST 2011


Eric and Oscar,

I reformatted my patchset and attached, thank you.

...Takumi


-- original message(updated) --

Now I can build clang and llvm on Windows x64 with both mingw-w64-g++
and w64-clang.

Here, some patches are, to build.
Please take a look into them.
I have checked on x86_64-centos5, mingw32(and msys), msvs10,
mingw-w64-g++ and stage3-mingw64-clang(with my patches).

ps. please see also; http://llvm.org/bugs/show_bug.cgi?id=9100

...Takumi


* 0001-Windows-Windows.h-mingw64-might-have-_WIN32_WINN.patch.txt

[PR8848] I will honor predefined _WN32_WINNT on x64 compilers.


* 0002-Windows-DynamicLibrary.inc-ELM_Callback-fix.patch.txt

[PR8848] I split conditions. It would be easier to read, I suppose.


* 0003-lib-Target-X86-X86JITInfo.cpp-Add-Win64-stuff.patch.txt

It would be essential to run JIT on x64 with mingw64.


* 0004-autoconf-define-HAVE_DECL_SETINFORMATIONJOBOBJEC.patch.txt
* 0005-include-llvm-Config-config.h.in-Regenerate.patch.txt
* 0006-Regenerate-configure.patch.txt.gz
* 0007-CMake-define-HAVE_DECL_SETINFORMATIONJOBOBJECT-f.patch.txt
* 0008-Windows-Program.inc-Declare-SetInformationJobObj.patch.txt

Ancient mingw32 might not have the declaration of SetInformationJobObject().
Autoconf and CMake can find the decl in windows.h(winbase.h).

FIXME: w/o _WIN32_WINNT := 0x0500, SetInformationJobObject() could not
be found on my w32api/mingw.
I will improve it later.
(I need to inspect the decl with -D_WIN32_WINNT=0x0500)


* 0009-Autoconf-may-check-symbols-in-libgcc.a-for-JIT-o.patch.txt
* 0010-include-llvm-Config-config.h.in-Regenerate.patch.txt
* 0011-Regenerate-configure.patch.txt.gz
* 0012-CMake-may-check-symbols-in-libgcc.a-for-JIT-on-M.patch.txt
* 0013-Windows-DynamicLibrary.inc-Split-explicit-symbol.patch.txt

I know it would be gross, but I think it practical.
Autoconf and CMake seeks symbols for JIT.

FIXME: __cmpdi2 and __main would never be referred to by anyone, I guess.
FIXME: Is there good way to extract symbols for JIT from
lib/CodeGen/SelectionDAG/TargetLowering.cpp?


* 0014-autoconf-Seek-strerror_s-with-AC_CHECK_DECLS.patch.txt
* 0015-include-llvm-Config-config.h.in-Regenerate.patch.txt
* 0016-Regenerate-configure.patch.txt.gz
* 0017-CMake-Use-HAVE_DECL_STRERROR_S.patch.txt
* 0018-lib-Support-Errno.cpp-Use-HAVE_DECL_STRERROR_S.patch.txt

On mingw64, strerror_s() is defined in libs but not defined int
string.h by default.
AC_CHECK_DECL can inspect the declaration.
I wish it would work even if strerror_s() were defined by default!

FIXME: Shall we inspect and define MINGW_HAS_SECURE_API?
-------------- next part --------------
From 1c30d43a3d574b431b2fa3a46eb2c64f862516a4 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 7 Dec 2010 10:33:35 +0900
Subject: [PATCH 01/18] Windows/Windows.h: mingw64 might have _WIN32_WINNT.

---
 lib/Support/Windows/Windows.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/lib/Support/Windows/Windows.h b/lib/Support/Windows/Windows.h
index 6e0b585..8eaaf31 100644
--- a/lib/Support/Windows/Windows.h
+++ b/lib/Support/Windows/Windows.h
@@ -17,9 +17,15 @@
 //===----------------------------------------------------------------------===//
 
 // Require at least Windows 2000 API.
+#ifdef _WIN32_WINNT
+#if _WIN32_WINNT < 0x0500
+#error "We assume at least Windows 2000 API."
+#endif
+#else
 #define _WIN32_WINNT 0x0500
 #define _WIN32_IE    0x0500 // MinGW at it again.
 #define WIN32_LEAN_AND_MEAN
+#endif
 
 #include "llvm/Config/config.h" // Get build system configuration settings
 #include <Windows.h>
-- 
1.7.1.GIT

-------------- next part --------------
From 07adf470b0061c6005d54c5bbab38b247350934b Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 7 Dec 2010 10:32:50 +0900
Subject: [PATCH 02/18] Windows/DynamicLibrary.inc: ELM_Callback fix

---
 lib/Support/Windows/DynamicLibrary.inc |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/lib/Support/Windows/DynamicLibrary.inc b/lib/Support/Windows/DynamicLibrary.inc
index 5fad37a..5e10f77 100644
--- a/lib/Support/Windows/DynamicLibrary.inc
+++ b/lib/Support/Windows/DynamicLibrary.inc
@@ -55,7 +55,17 @@ extern "C" {
 // Use new callback if:
 //  - Newer Visual Studio (comes with newer SDK).
 //  - Visual Studio 2005 with Windows SDK 6.0+
-#if !defined(_MSC_VER) || _MSC_VER < 1500 && (!defined(VER_PRODUCTBUILD) || VER_PRODUCTBUILD < 6000)
+#if defined(_MSC_VER)
+  #if _MSC_VER < 1500 && (!defined(VER_PRODUCTBUILD) || VER_PRODUCTBUILD < 6000)
+    #define OLD_ELM_CALLBACK_DECL 1
+  #endif
+#elif defined(__MINGW64__)
+  // Use new callback.
+#elif defined(__MINGW32__)
+  #define OLD_ELM_CALLBACK_DECL 1
+#endif
+
+#ifdef OLD_ELM_CALLBACK_DECL
   static BOOL CALLBACK ELM_Callback(PSTR  ModuleName,
                                     ModuleBaseType ModuleBase,
                                     ULONG ModuleSize,
-- 
1.7.1.GIT

-------------- next part --------------
From bc9672a27d5b6561afda8f38faa1f5a9b3141448 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Sun, 19 Dec 2010 15:20:08 +0900
Subject: [PATCH 03/18] lib/Target/X86/X86JITInfo.cpp: Add Win64 stuff.

---
 lib/Target/X86/X86JITInfo.cpp |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/Target/X86/X86JITInfo.cpp b/lib/Target/X86/X86JITInfo.cpp
index 759de77..127738d 100644
--- a/lib/Target/X86/X86JITInfo.cpp
+++ b/lib/Target/X86/X86JITInfo.cpp
@@ -127,9 +127,17 @@ extern "C" {
     "movaps  %xmm6, 96(%rsp)\n"
     "movaps  %xmm7, 112(%rsp)\n"
     // JIT callee
+#ifdef _WIN64
+    "subq    $32, %rsp\n"
+    "movq    %rbp, %rcx\n"    // Pass prev frame and return address
+    "movq    8(%rbp), %rdx\n"
+    "call    " ASMPREFIX "X86CompilationCallback2\n"
+    "addq    $32, %rsp\n"
+#else
     "movq    %rbp, %rdi\n"    // Pass prev frame and return address
     "movq    8(%rbp), %rsi\n"
     "call    " ASMPREFIX "X86CompilationCallback2\n"
+#endif
     // Restore all XMM arg registers
     "movaps  112(%rsp), %xmm7\n"
     "movaps  96(%rsp), %xmm6\n"
-- 
1.7.1.GIT

-------------- next part --------------
From 9c376f6d99042d17ef3ba3eff0e3942cef83e1ce Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 12:57:55 +0900
Subject: [PATCH 04/18] autoconf: define HAVE_DECL_SETINFORMATIONJOBOBJECT for SetInformationJobObject() on Mingw32.

---
 autoconf/configure.ac |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 0cc3d3e..cc39ee4 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1220,6 +1220,7 @@ AC_CHECK_LIB(m,sin)
 if test "$llvm_cv_os_type" = "MingW" ; then
   AC_CHECK_LIB(imagehlp, main)
   AC_CHECK_LIB(psapi, main)
+  AC_CHECK_DECLS([SetInformationJobObject],,,[#include <windows.h>])
 fi
 
 dnl dlopen() is required for plugin support.
-- 
1.7.1.GIT

-------------- next part --------------
From 331e0d61610f0c2abe198641c1c106122a6d4914 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 1 Feb 2011 09:09:41 +0900
Subject: [PATCH 05/18] include/llvm/Config/config.h.in: Regenerate.

---
 include/llvm/Config/config.h.in |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index b38ee62..66fd5d2 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -78,6 +78,10 @@
 /* Define to 1 if you have the <ctype.h> header file. */
 #undef HAVE_CTYPE_H
 
+/* Define to 1 if you have the declaration of `SetInformationJobObject', and
+   to 0 if you don't. */
+#undef HAVE_DECL_SETINFORMATIONJOBOBJECT
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H
-- 
1.7.1.GIT

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 1078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110201/e3989f36/attachment.bin>
-------------- next part --------------
From c06ded882884995371f83f6b7348cc905cadc30d Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 19:07:38 +0900
Subject: [PATCH 07/18] CMake: define HAVE_DECL_SETINFORMATIONJOBOBJECT for SetInformationJobObject() on Mingw32.

---
 cmake/config-ix.cmake              |    1 +
 include/llvm/Config/config.h.cmake |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 4cb68df..7ee5c94 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -146,6 +146,7 @@ check_symbol_exists(memmove string.h HAVE_MEMMOVE)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
 if ( LLVM_ON_WIN32 )
   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
+  check_symbol_exists(SetInformationJobObject windows.h HAVE_DECL_SETINFORMATIONJOBOBJECT)
 endif()
 if( HAVE_ARGZ_H )
   check_symbol_exists(argz_append argz.h HAVE_ARGZ_APPEND)
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index c94abb6..95d9efa 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -80,6 +80,10 @@
 /* Define to 1 if you have the <ctype.h> header file. */
 #cmakedefine HAVE_CTYPE_H ${HAVE_CTYPE_H}
 
+/* Define to 1 if you have the declaration of `SetInformationJobObject', and
+   to 0 if you don't. */
+#cmakedefine HAVE_DECL_SETINFORMATIONJOBOBJECT ${HAVE_DECL_SETINFORMATIONJOBOBJECT}
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #cmakedefine HAVE_DIRENT_H ${HAVE_DIRENT_H}
-- 
1.7.1.GIT

-------------- next part --------------
From ed6057397d374fe70526514695857f3bee2a9085 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 12:59:30 +0900
Subject: [PATCH 08/18] Windows/Program.inc: Declare SetInformationJobObject() if decls not found in Windows.h.

---
 lib/Support/Windows/Program.inc |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc
index 0b92c78..9fcbc8d 100644
--- a/lib/Support/Windows/Program.inc
+++ b/lib/Support/Windows/Program.inc
@@ -22,7 +22,8 @@
 //===          and must not be UNIX code
 //===----------------------------------------------------------------------===//
 
-#ifdef __MINGW32__
+#if defined(HAVE_DECL_SETINFORMATIONJOBOBJECT)
+#if !HAVE_DECL_SETINFORMATIONJOBOBJECT
 // Ancient mingw32's w32api might not have this declaration.
 extern "C"
 BOOL WINAPI SetInformationJobObject(HANDLE hJob,
@@ -30,6 +31,7 @@ BOOL WINAPI SetInformationJobObject(HANDLE hJob,
                                     LPVOID lpJobObjectInfo,
                                     DWORD cbJobObjectInfoLength);
 #endif
+#endif
 
 namespace {
   struct Win32ProcessInfo {
-- 
1.7.1.GIT

-------------- next part --------------
From ef868e190baa5494f342edb045c50c72bea5bc52 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 19:12:15 +0900
Subject: [PATCH 09/18] Autoconf may check symbols in libgcc.a for JIT on Mingw.

---
 autoconf/configure.ac |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index cc39ee4..225d0f6 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1398,6 +1398,28 @@ AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp])
 AC_C_PRINTF_A
 AC_FUNC_RAND48
 
+dnl Check symbols in libgcc.a for JIT on Mingw.
+if test "$llvm_cv_os_type" = "MingW" ; then
+  AC_CHECK_LIB(gcc,_alloca,AC_DEFINE([HAVE__ALLOCA],[1],[Have host's _alloca]))
+  AC_CHECK_LIB(gcc,__alloca,AC_DEFINE([HAVE___ALLOCA],[1],[Have host's __alloca]))
+  AC_CHECK_LIB(gcc,__chkstk,AC_DEFINE([HAVE___CHKSTK],[1],[Have host's __chkstk]))
+  AC_CHECK_LIB(gcc,___chkstk,AC_DEFINE([HAVE____CHKSTK],[1],[Have host's ___chkstk]))
+
+  AC_CHECK_LIB(gcc,__ashldi3,AC_DEFINE([HAVE___ASHLDI3],[1],[Have host's __ashldi3]))
+  AC_CHECK_LIB(gcc,__ashrdi3,AC_DEFINE([HAVE___ASHRDI3],[1],[Have host's __ashrdi3]))
+  AC_CHECK_LIB(gcc,__divdi3,AC_DEFINE([HAVE___DIVDI3],[1],[Have host's __divdi3]))
+  AC_CHECK_LIB(gcc,__fixdfdi,AC_DEFINE([HAVE___FIXDFDI],[1],[Have host's __fixdfdi]))
+  AC_CHECK_LIB(gcc,__fixsfdi,AC_DEFINE([HAVE___FIXSFDI],[1],[Have host's __fixsfdi]))
+  AC_CHECK_LIB(gcc,__floatdidf,AC_DEFINE([HAVE___FLOATDIDF],[1],[Have host's __floatdidf]))
+  AC_CHECK_LIB(gcc,__lshrdi3,AC_DEFINE([HAVE___LSHRDI3],[1],[Have host's __lshrdi3]))
+  AC_CHECK_LIB(gcc,__moddi3,AC_DEFINE([HAVE___MODDI3],[1],[Have host's __moddi3]))
+  AC_CHECK_LIB(gcc,__udivdi3,AC_DEFINE([HAVE___UDIVDI3],[1],[Have host's __udivdi3]))
+  AC_CHECK_LIB(gcc,__umoddi3,AC_DEFINE([HAVE___UMODDI3],[1],[Have host's __umoddi3]))
+
+  AC_CHECK_LIB(gcc,__main,AC_DEFINE([HAVE___MAIN],[1],[Have host's __main]))
+  AC_CHECK_LIB(gcc,__cmpdi2,AC_DEFINE([HAVE___CMPDI2],[1],[Have host's __cmpdi2]))
+fi
+
 dnl Check for variations in the Standard C++ library and STL. These macros are
 dnl provided by LLVM in the autoconf/m4 directory.
 AC_FUNC_ISNAN
-- 
1.7.1.GIT

-------------- next part --------------
From ad1b51932da3bee63fe27bf03511fb1a1cce602a Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 1 Feb 2011 09:10:50 +0900
Subject: [PATCH 10/18] include/llvm/Config/config.h.in: Regenerate.

---
 include/llvm/Config/config.h.in |   48 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 66fd5d2..2688795 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -474,9 +474,57 @@
 /* Define if the xdot.py program is available */
 #undef HAVE_XDOT_PY
 
+/* Have host's _alloca */
+#undef HAVE__ALLOCA
+
+/* Have host's __alloca */
+#undef HAVE___ALLOCA
+
+/* Have host's __ashldi3 */
+#undef HAVE___ASHLDI3
+
+/* Have host's __ashrdi3 */
+#undef HAVE___ASHRDI3
+
+/* Have host's __chkstk */
+#undef HAVE___CHKSTK
+
+/* Have host's __cmpdi2 */
+#undef HAVE___CMPDI2
+
+/* Have host's __divdi3 */
+#undef HAVE___DIVDI3
+
 /* Define to 1 if you have the `__dso_handle' function. */
 #undef HAVE___DSO_HANDLE
 
+/* Have host's __fixdfdi */
+#undef HAVE___FIXDFDI
+
+/* Have host's __fixsfdi */
+#undef HAVE___FIXSFDI
+
+/* Have host's __floatdidf */
+#undef HAVE___FLOATDIDF
+
+/* Have host's __lshrdi3 */
+#undef HAVE___LSHRDI3
+
+/* Have host's __main */
+#undef HAVE___MAIN
+
+/* Have host's __moddi3 */
+#undef HAVE___MODDI3
+
+/* Have host's __udivdi3 */
+#undef HAVE___UDIVDI3
+
+/* Have host's __umoddi3 */
+#undef HAVE___UMODDI3
+
+/* Have host's ___chkstk */
+#undef HAVE____CHKSTK
+
 /* Linker version detected at compile time. */
 #undef HOST_LINK_VERSION
 
-- 
1.7.1.GIT

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0011-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 2172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110201/e3989f36/attachment-0001.bin>
-------------- next part --------------
From e2ec7b6b4ca393adee063ce7990e8271c1fac0c2 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 17:56:13 +0900
Subject: [PATCH 12/18] CMake may check symbols in libgcc.a for JIT on Mingw.

---
 cmake/config-ix.cmake              |   20 +++++++++++++++
 include/llvm/Config/config.h.cmake |   48 ++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 7ee5c94..b0d236c 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -147,6 +147,26 @@ check_symbol_exists(setenv stdlib.h HAVE_SETENV)
 if ( LLVM_ON_WIN32 )
   check_symbol_exists(_chsize_s io.h HAVE__CHSIZE_S)
   check_symbol_exists(SetInformationJobObject windows.h HAVE_DECL_SETINFORMATIONJOBOBJECT)
+
+  check_function_exists(_alloca HAVE__ALLOCA)
+  check_function_exists(__alloca HAVE___ALLOCA)
+  check_function_exists(__chkstk HAVE___CHKSTK)
+  check_function_exists(___chkstk HAVE____CHKSTK)
+
+  check_function_exists(__ashldi3 HAVE___ASHLDI3)
+  check_function_exists(__ashrdi3 HAVE___ASHRDI3)
+  check_function_exists(__divdi3 HAVE___DIVDI3)
+  check_function_exists(__fixdfdi HAVE___FIXDFDI)
+  check_function_exists(__fixsfdi HAVE___FIXSFDI)
+  check_function_exists(__floatdidf HAVE___FLOATDIDF)
+  check_function_exists(__lshrdi3 HAVE___LSHRDI3)
+  check_function_exists(__moddi3 HAVE___MODDI3)
+  check_function_exists(__udivdi3 HAVE___UDIVDI3)
+  check_function_exists(__umoddi3 HAVE___UMODDI3)
+
+  check_function_exists(__main HAVE___MAIN)
+  check_function_exists(__cmpdi2 HAVE___CMPDI2)
+
 endif()
 if( HAVE_ARGZ_H )
   check_symbol_exists(argz_append argz.h HAVE_ARGZ_APPEND)
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 95d9efa..375c97f 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -470,9 +470,57 @@
 /* Define if the xdot.py program is available */
 #undef HAVE_XDOT_PY
 
+/* Have host's _alloca */
+#cmakedefine HAVE__ALLOCA ${HAVE__ALLOCA}
+
+/* Have host's __alloca */
+#cmakedefine HAVE___ALLOCA ${HAVE___ALLOCA}
+
+/* Have host's __ashldi3 */
+#cmakedefine HAVE___ASHLDI3 ${HAVE___ASHLDI3}
+
+/* Have host's __ashrdi3 */
+#cmakedefine HAVE___ASHRDI3 ${HAVE___ASHRDI3}
+
+/* Have host's __chkstk */
+#cmakedefine HAVE___CHKSTK ${HAVE___CHKSTK}
+
+/* Have host's __cmpdi2 */
+#cmakedefine HAVE___CMPDI2 ${HAVE___CMPDI2}
+
+/* Have host's __divdi3 */
+#cmakedefine HAVE___DIVDI3 ${HAVE___DIVDI3}
+
 /* Define to 1 if you have the `__dso_handle' function. */
 #undef HAVE___DSO_HANDLE
 
+/* Have host's __fixdfdi */
+#cmakedefine HAVE___FIXDFDI ${HAVE___FIXDFDI}
+
+/* Have host's __fixsfdi */
+#cmakedefine HAVE___FIXSFDI ${HAVE___FIXSFDI}
+
+/* Have host's __floatdidf */
+#cmakedefine HAVE___FLOATDIDF ${HAVE___FLOATDIDF}
+
+/* Have host's __lshrdi3 */
+#cmakedefine HAVE___LSHRDI3 ${HAVE___LSHRDI3}
+
+/* Have host's __main */
+#cmakedefine HAVE___MAIN ${HAVE___MAIN}
+
+/* Have host's __moddi3 */
+#cmakedefine HAVE___MODDI3 ${HAVE___MODDI3}
+
+/* Have host's __udivdi3 */
+#cmakedefine HAVE___UDIVDI3 ${HAVE___UDIVDI3}
+
+/* Have host's __umoddi3 */
+#cmakedefine HAVE___UMODDI3 ${HAVE___UMODDI3}
+
+/* Have host's ___chkstk */
+#cmakedefine HAVE____CHKSTK ${HAVE____CHKSTK}
+
 /* Linker version detected at compile time. */
 #undef HOST_LINK_VERSION
 
-- 
1.7.1.GIT

-------------- next part --------------
From 0ae2080d8027c9a9c37d36f2dbe2534168aebfb3 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 11:27:12 +0900
Subject: [PATCH 13/18] Windows/DynamicLibrary.inc: Split explicit symbols into explicit_symbols.inc.

---
 lib/Support/Windows/DynamicLibrary.inc   |   77 +++++++-----------------------
 lib/Support/Windows/explicit_symbols.inc |   66 +++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 60 deletions(-)
 create mode 100644 lib/Support/Windows/explicit_symbols.inc

diff --git a/lib/Support/Windows/DynamicLibrary.inc b/lib/Support/Windows/DynamicLibrary.inc
index 5e10f77..2c14366 100644
--- a/lib/Support/Windows/DynamicLibrary.inc
+++ b/lib/Support/Windows/DynamicLibrary.inc
@@ -120,35 +120,14 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *filename,
 
 // Stack probing routines are in the support library (e.g. libgcc), but we don't
 // have dynamic linking on windows. Provide a hook.
-#if defined(__MINGW32__) || defined (_MSC_VER)
-  #define EXPLICIT_SYMBOL(SYM)                    \
-    if (!strcmp(symbolName, #SYM)) return (void*)&SYM
-  #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO)        \
-    if (!strcmp(symbolName, #SYMFROM)) return (void*)&SYMTO
-  #define EXPLICIT_SYMBOL_DEF(SYM)                \
-    extern "C" { extern void *SYM; }
-
-  #if defined(__MINGW32__)
-    EXPLICIT_SYMBOL_DEF(_alloca)
-    EXPLICIT_SYMBOL_DEF(__main)
-    EXPLICIT_SYMBOL_DEF(__ashldi3)
-    EXPLICIT_SYMBOL_DEF(__ashrdi3)
-    EXPLICIT_SYMBOL_DEF(__cmpdi2)
-    EXPLICIT_SYMBOL_DEF(__divdi3)
-    EXPLICIT_SYMBOL_DEF(__fixdfdi)
-    EXPLICIT_SYMBOL_DEF(__fixsfdi)
-    EXPLICIT_SYMBOL_DEF(__fixunsdfdi)
-    EXPLICIT_SYMBOL_DEF(__fixunssfdi)
-    EXPLICIT_SYMBOL_DEF(__floatdidf)
-    EXPLICIT_SYMBOL_DEF(__floatdisf)
-    EXPLICIT_SYMBOL_DEF(__lshrdi3)
-    EXPLICIT_SYMBOL_DEF(__moddi3)
-    EXPLICIT_SYMBOL_DEF(__udivdi3)
-    EXPLICIT_SYMBOL_DEF(__umoddi3)
-  #elif defined(_MSC_VER)
-    EXPLICIT_SYMBOL_DEF(_alloca_probe)
-  #endif
-#endif
+#define EXPLICIT_SYMBOL(SYM)                    \
+  extern "C" { extern void *SYM; }
+#define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO)
+
+#include "explicit_symbols.inc"
+
+#undef EXPLICIT_SYMBOL
+#undef EXPLICIT_SYMBOL2
 
 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
   // First check symbols added via AddSymbol().
@@ -169,39 +148,17 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
     }
   }
 
-#if defined(__MINGW32__)
-  {
-    EXPLICIT_SYMBOL(_alloca);
-    EXPLICIT_SYMBOL(__main);
-    EXPLICIT_SYMBOL(__ashldi3);
-    EXPLICIT_SYMBOL(__ashrdi3);
-    EXPLICIT_SYMBOL(__cmpdi2);
-    EXPLICIT_SYMBOL(__divdi3);
-    EXPLICIT_SYMBOL(__fixdfdi);
-    EXPLICIT_SYMBOL(__fixsfdi);
-    EXPLICIT_SYMBOL(__fixunsdfdi);
-    EXPLICIT_SYMBOL(__fixunssfdi);
-    EXPLICIT_SYMBOL(__floatdidf);
-    EXPLICIT_SYMBOL(__floatdisf);
-    EXPLICIT_SYMBOL(__lshrdi3);
-    EXPLICIT_SYMBOL(__moddi3);
-    EXPLICIT_SYMBOL(__udivdi3);
-    EXPLICIT_SYMBOL(__umoddi3);
-
-    EXPLICIT_SYMBOL2(alloca, _alloca);
-#undef EXPLICIT_SYMBOL
-#undef EXPLICIT_SYMBOL2
-#undef EXPLICIT_SYMBOL_DEF
-  }
-#elif defined(_MSC_VER)
+  #define EXPLICIT_SYMBOL(SYM)                    \
+    if (!strcmp(symbolName, #SYM)) return (void*)&SYM;
+  #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO)        \
+    if (!strcmp(symbolName, #SYMFROM)) return (void*)&SYMTO;
+
   {
-    EXPLICIT_SYMBOL2(alloca, _alloca_probe);
-    EXPLICIT_SYMBOL2(_alloca, _alloca_probe);
-#undef EXPLICIT_SYMBOL
-#undef EXPLICIT_SYMBOL2
-#undef EXPLICIT_SYMBOL_DEF
+    #include "explicit_symbols.inc"
   }
-#endif
+
+  #undef EXPLICIT_SYMBOL
+  #undef EXPLICIT_SYMBOL2
 
   return 0;
 }
diff --git a/lib/Support/Windows/explicit_symbols.inc b/lib/Support/Windows/explicit_symbols.inc
new file mode 100644
index 0000000..84862d6
--- /dev/null
+++ b/lib/Support/Windows/explicit_symbols.inc
@@ -0,0 +1,66 @@
+/* in libgcc.a */
+
+#ifdef HAVE__ALLOCA
+  EXPLICIT_SYMBOL(_alloca)
+  EXPLICIT_SYMBOL2(alloca, _alloca);
+#endif
+#ifdef HAVE___ALLOCA
+  EXPLICIT_SYMBOL(__alloca)
+#endif
+#ifdef HAVE___CHKSTK
+  EXPLICIT_SYMBOL(__chkstk)
+#endif
+#ifdef HAVE____CHKSTK
+  EXPLICIT_SYMBOL(___chkstk)
+#endif
+#ifdef HAVE___MAIN
+  EXPLICIT_SYMBOL(__main) // FIXME: Don't call it.
+#endif
+
+#ifdef HAVE___ASHLDI3
+  EXPLICIT_SYMBOL(__ashldi3)
+#endif
+#ifdef HAVE___ASHRDI3
+  EXPLICIT_SYMBOL(__ashrdi3)
+#endif
+#ifdef HAVE___CMPDI2 // FIXME: unused
+  EXPLICIT_SYMBOL(__cmpdi2)
+#endif
+#ifdef HAVE___DIVDI3
+  EXPLICIT_SYMBOL(__divdi3)
+#endif
+#ifdef HAVE___FIXDFDI
+  EXPLICIT_SYMBOL(__fixdfdi)
+#endif
+#ifdef HAVE___FIXSFDI
+  EXPLICIT_SYMBOL(__fixsfdi)
+#endif
+#ifdef HAVE___FIXUNSDFDI
+  EXPLICIT_SYMBOL(__fixunsdfdi)
+#endif
+#ifdef HAVE___FIXUNSSFDI
+  EXPLICIT_SYMBOL(__fixunssfdi)
+#endif
+#ifdef HAVE___FLOATDIDF
+  EXPLICIT_SYMBOL(__floatdidf)
+#endif
+#ifdef HAVE___FLOATDISF
+  EXPLICIT_SYMBOL(__floatdisf)
+#endif
+#ifdef HAVE___LSHRDI3
+  EXPLICIT_SYMBOL(__lshrdi3)
+#endif
+#ifdef HAVE___MODDI3
+  EXPLICIT_SYMBOL(__moddi3)
+#endif
+#ifdef HAVE___UDIVDI3
+  EXPLICIT_SYMBOL(__udivdi3)
+#endif
+#ifdef HAVE___UMODDI3
+  EXPLICIT_SYMBOL(__umoddi3)
+#endif
+
+/* msvcrt */
+#if defined(_MSC_VER)
+  EXPLICIT_SYMBOL2(alloca, _alloca_probe);
+#endif
-- 
1.7.1.GIT

-------------- next part --------------
From 74928d67ec4254ff6fba641b10fb670bae90e9e8 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 18 Jan 2011 15:30:58 +0900
Subject: [PATCH 14/18] autoconf: Seek strerror_s() with AC_CHECK_DECLS.

AC_CHECK_FUNCS seeks a symbol only in libs. We should check decl in string.h.
With recent Mingw, *_s() stuff would be enabled by MINGW_HAS_SECURE_API.
---
 autoconf/configure.ac |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 225d0f6..72eae40 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1392,12 +1392,15 @@ AC_CHECK_FUNCS([powf fmodf strtof round ])
 AC_CHECK_FUNCS([getpagesize getrusage getrlimit setrlimit gettimeofday ])
 AC_CHECK_FUNCS([isatty mkdtemp mkstemp ])
 AC_CHECK_FUNCS([mktemp posix_spawn realpath sbrk setrlimit strdup ])
-AC_CHECK_FUNCS([strerror strerror_r strerror_s setenv ])
+AC_CHECK_FUNCS([strerror strerror_r setenv ])
 AC_CHECK_FUNCS([strtoll strtoq sysconf malloc_zone_statistics ])
 AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp])
 AC_C_PRINTF_A
 AC_FUNC_RAND48
 
+dnl Check the declaration of strerror_s(). It is not provided by default on Mingw.
+AC_CHECK_DECLS([strerror_s])
+
 dnl Check symbols in libgcc.a for JIT on Mingw.
 if test "$llvm_cv_os_type" = "MingW" ; then
   AC_CHECK_LIB(gcc,_alloca,AC_DEFINE([HAVE__ALLOCA],[1],[Have host's _alloca]))
-- 
1.7.1.GIT

-------------- next part --------------
From bdc98817fe819c3de86254ab325b14b2b221e5d6 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 1 Feb 2011 09:12:36 +0900
Subject: [PATCH 15/18] include/llvm/Config/config.h.in: Regenerate.

---
 include/llvm/Config/config.h.in |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 2688795..1f83d99 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -82,6 +82,10 @@
    to 0 if you don't. */
 #undef HAVE_DECL_SETINFORMATIONJOBOBJECT
 
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+   don't. */
+#undef HAVE_DECL_STRERROR_S
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H
@@ -388,9 +392,6 @@
 /* Define to 1 if you have the `strerror_r' function. */
 #undef HAVE_STRERROR_R
 
-/* Define to 1 if you have the `strerror_s' function. */
-#undef HAVE_STRERROR_S
-
 /* Define to 1 if you have the <strings.h> header file. */
 #undef HAVE_STRINGS_H
 
-- 
1.7.1.GIT

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0016-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110201/e3989f36/attachment-0002.bin>
-------------- next part --------------
From 226570dae3459e3c2e0d1cab20f103db9965974e Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Tue, 18 Jan 2011 15:30:58 +0900
Subject: [PATCH 17/18] CMake: Use HAVE_DECL_STRERROR_S.

---
 cmake/config-ix.cmake              |    2 +-
 include/llvm/Config/config.h.cmake |    7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index b0d236c..2ce0b04 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -140,7 +140,7 @@ check_symbol_exists(strtoll stdlib.h HAVE_STRTOLL)
 check_symbol_exists(strtoq stdlib.h HAVE_STRTOQ)
 check_symbol_exists(strerror string.h HAVE_STRERROR)
 check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
-check_symbol_exists(strerror_s string.h HAVE_STRERROR_S)
+check_symbol_exists(strerror_s string.h HAVE_DECL_STRERROR_S)
 check_symbol_exists(memcpy string.h HAVE_MEMCPY)
 check_symbol_exists(memmove string.h HAVE_MEMMOVE)
 check_symbol_exists(setenv stdlib.h HAVE_SETENV)
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 375c97f..0157ec4 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -84,6 +84,10 @@
    to 0 if you don't. */
 #cmakedefine HAVE_DECL_SETINFORMATIONJOBOBJECT ${HAVE_DECL_SETINFORMATIONJOBOBJECT}
 
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+   don't. */
+#cmakedefine HAVE_DECL_STRERROR_S ${HAVE_DECL_STRERROR_S}
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #cmakedefine HAVE_DIRENT_H ${HAVE_DIRENT_H}
@@ -390,9 +394,6 @@
 /* Define to 1 if you have the `strerror_r' function. */
 #cmakedefine HAVE_STRERROR_R ${HAVE_STRERROR_R}
 
-/* Define to 1 if you have the `strerror_s' function. */
-#cmakedefine HAVE_STRERROR_S ${HAVE_STRERROR_S}
-
 /* Define to 1 if you have the <strings.h> header file. */
 #cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H}
 
-- 
1.7.1.GIT

-------------- next part --------------
From 915d1e6394701f88a40dc87afcbba92a843086b5 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Mon, 31 Jan 2011 19:32:27 +0900
Subject: [PATCH 18/18] lib/Support/Errno.cpp: Use HAVE_DECL_STRERROR_S.

---
 lib/Support/Errno.cpp |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/Support/Errno.cpp b/lib/Support/Errno.cpp
index 312d91e..c2a0f71 100644
--- a/lib/Support/Errno.cpp
+++ b/lib/Support/Errno.cpp
@@ -50,7 +50,7 @@ std::string StrError(int errnum) {
 # else
     strerror_r(errnum,buffer,MaxErrStrLen-1);
 # endif
-#elif defined(HAVE_STRERROR_S)  // Windows.
+#elif HAVE_DECL_STRERROR_S // MSVCRT.DLL does not provide one.
     if (errnum)
       strerror_s(buffer, errnum);
 #elif defined(HAVE_STRERROR)
-- 
1.7.1.GIT



More information about the llvm-commits mailing list