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

NAKAMURA Takumi geek4civic at gmail.com
Thu Feb 3 20:24:54 PST 2011


Eric and Oscar,

I re-tweaked configurations. Here is my "take 2" patchset. (last one
was simply reformatted)
Please look at what you would like to look at. ;)

...Takumi


* Changes in last patchset

  - Macros, _WIN32_WINNT, &c. may affect seeking declarations in configuration.
  - [CMake] let #define HAVE_DECL_ set "1" or "0" (or undefined).
  - Added checking _chsize_s on mingw.


* 0001-Windows-DynamicLibrary.inc-ELM_Callback-fix.patch.txt
* 0002-lib-Target-X86-X86JITInfo.cpp-Add-Win64-stuff.patch.txt

  They are trivial patches.


* 0003-CMake-Add-macro-add_llvm_config_definition-NAME-.patch.txt

  [CMake] I added; add_llvm_config_definition(name value)
  It provides definition(-Dname=value) at checking decls,
  and definition at configure_file().


* 0004-lib-Support-Windows-Windows.h-Autoconf-provides-.patch.txt

  [autoconf][CMake] It provides 3 definitions;
    _WIN32_WINNT = 0x0500
    _WIN32_IE = 0x0500
    WIN32_LEAN_AND_MEAN
  to check decls with these definitions.
  They are set in llvm/Config/config.h.
  lib/Support/Windows/Windows.h uses definitions in config.h.


* 0005-autoconf-Redefine-_WIN32_WINNT-in-config.h.patch.txt

  [autoconf][CMake] With mingw-w64 headers, _WIN32_WINNT would be
defined in system headers.
  It undefines and redefines _WIN32_WINNT.
  It suppresses a warning in a case;
    #include <_mingw.h> /* any system headers */
    #include "llvm/Config/config.h"


* 0006-autoconf-define-HAVE_DECL_SETINFORMATIONJOBOBJEC.patch.txt
* 0008-Windows-Program.inc-Declare-SetInformationJobObj.patch.txt

  Note: The declaration of SetInformationJobObject() requires
_WIN32_WINNT >= 0x0500.


* 0009-Autoconf-may-check-symbols-in-libgcc.a-for-JIT-o.patch.txt
* 0011-Windows-DynamicLibrary.inc-Split-explicit-symbol.patch.txt

  (as same as last patches)

* 0012-include-llvm-Config-config.h.-Provide-MINGW_HAS_.patch.txt

  [autoconf][CMake] On mingw-w64, Secure API (****_s) requires
definition "MINGW_HAS_SECURE_API".


* 0013-autoconf-Seek-strerror_s-with-AC_CHECK_DECLS.patch.txt
* 0015-lib-Support-Errno.cpp-Check-strerror_s-with-HAVE.patch.txt

  [autoconf][CMake]
  On mingw-w64, the symbol "strerror_s" could be found in libs but not
defined in headers.
  On MSVC, "strerror_s" can be found in string.h.


* 0016-autoconf-Check-_chsize_s-s-declaration.patch.txt
* 0018-Use-HAVE_DECL__CHSIZE_S-to-check-_chsize_s-on-Wi.patch.txt

  [autoconf][CMake]
  Mingw-w64 provides _chsize_s() with MINGW_HAS_SECURE_API.
  It could be found to seek symbols in libs.


* 0007-Regenerate-configure.patch.txt.gz
* 0010-Regenerate-configure.patch.txt.gz
* 0014-Regenerate-configure.patch.txt.gz
* 0017-Regenerate-configure.patch.txt.gz

  Included for consistency.
-------------- next part --------------
From 261edc0095b53714f1306c64d2dea2a36f2d490a 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 01/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 1d76503fd68304f769ce6577f21d03d4a65f5e55 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 02/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 e69a9f88f3e0ac4cc9c43b774fe0a9861e00440a Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Thu, 3 Feb 2011 20:49:11 +0900
Subject: [PATCH 03/18] CMake: Add macro: add_llvm_config_definition(NAME value).

Following C/C++ checks can use -Dname=value.
eg. add_llvm_config_definition(_WIN32_WINNT 0x0500)
Some declarations might be unavailable without certain definition.
configure_file() can use its definition(s).
---
 cmake/modules/AddLLVMDefinitions.cmake |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/cmake/modules/AddLLVMDefinitions.cmake b/cmake/modules/AddLLVMDefinitions.cmake
index 33ac973..a44a3d0 100644
--- a/cmake/modules/AddLLVMDefinitions.cmake
+++ b/cmake/modules/AddLLVMDefinitions.cmake
@@ -11,3 +11,12 @@ macro(add_llvm_definitions)
   endforeach(arg)
   add_definitions( ${ARGN} )
 endmacro(add_llvm_definitions)
+
+# Following C/C++ checks can use -Dname=value.
+# eg. add_llvm_config_definition(_WIN32_WINNT 0x0500)
+# Some declarations might be unavailable without certain definition.
+# configure_file() can use its definition(s).
+macro(add_llvm_config_definition name value)
+  set(${name} ${value})
+  list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D${name}=${value}")
+endmacro(add_llvm_config_definition name value)
-- 
1.7.1.GIT

-------------- next part --------------
From 45be38ca409cbbdf2b63be2eaf7bf230aa9d6b38 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Thu, 3 Feb 2011 20:49:11 +0900
Subject: [PATCH 04/18] lib/Support/Windows/Windows.h: Autoconf provides predefined macros (_WIN32_WINNT, etc.).

_WIN32_WINNT, _WIN32_IE, WIN32_LEAN_AND_MEAN
They affect seeking declarations at configure.
---
 autoconf/configure.ac              |    7 +++++++
 cmake/config-ix.cmake              |    6 ++++++
 configure                          |   16 ++++++++++++++++
 include/llvm/Config/config.h.cmake |    9 +++++++++
 include/llvm/Config/config.h.in    |    9 +++++++++
 lib/Support/Windows/Windows.h      |    5 -----
 6 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 260b4b4..b282772 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1218,6 +1218,13 @@ dnl===-----------------------------------------------------------------------===
 
 AC_CHECK_LIB(m,sin)
 if test "$llvm_cv_os_type" = "MingW" ; then
+  AC_DEFINE([_WIN32_WINNT],[0x0500],
+            [We require Windows 2000 API.])
+  AC_DEFINE([_WIN32_IE],[0x0500],
+            [MinGW at it again.])
+  AC_DEFINE([WIN32_LEAN_AND_MEAN],[],
+            [We don't need fullset of Windows headers.])
+
   AC_CHECK_LIB(imagehlp, main)
   AC_CHECK_LIB(psapi, main)
 fi
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 8484bb6..de71fed 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -86,6 +86,12 @@ if( NOT LLVM_ON_WIN32 )
 endif()
 
 # function checks
+if (LLVM_ON_WIN32)
+  add_llvm_config_definition(_WIN32_WINNT 0x0500)
+  add_llvm_config_definition(_WIN32_IE 0x0500)
+  add_llvm_config_definition(WIN32_LEAN_AND_MEAN 1)
+endif ()
+
 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
diff --git a/configure b/configure
index 427a10d..94b121b 100755
--- a/configure
+++ b/configure
@@ -13553,6 +13553,22 @@ fi
 
 if test "$llvm_cv_os_type" = "MingW" ; then
 
+cat >>confdefs.h <<\_ACEOF
+#define _WIN32_WINNT 0x0500
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define _WIN32_IE 0x0500
+_ACEOF
+
+
+cat >>confdefs.h <<\_ACEOF
+#define WIN32_LEAN_AND_MEAN
+_ACEOF
+
+
+
 { echo "$as_me:$LINENO: checking for main in -limagehlp" >&5
 echo $ECHO_N "checking for main in -limagehlp... $ECHO_C" >&6; }
 if test "${ac_cv_lib_imagehlp_main+set}" = set; then
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 12e10ce..5e4b418 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -612,6 +612,15 @@
 /* Define if use udis86 library */
 #undef USE_UDIS86
 
+/* We don't need fullset of Windows headers. */
+#cmakedefine WIN32_LEAN_AND_MEAN
+
+/* MinGW at it again. */
+#cmakedefine _WIN32_IE ${_WIN32_IE}
+
+/* We require Windows 2000 API. */
+#cmakedefine _WIN32_WINNT ${_WIN32_WINNT}
+
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 5e16646..06d8a1b 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -623,6 +623,15 @@
 /* Define if use udis86 library */
 #undef USE_UDIS86
 
+/* We don't need fullset of Windows headers. */
+#undef WIN32_LEAN_AND_MEAN
+
+/* MinGW at it again. */
+#undef _WIN32_IE
+
+/* We require Windows 2000 API. */
+#undef _WIN32_WINNT
+
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const
 
diff --git a/lib/Support/Windows/Windows.h b/lib/Support/Windows/Windows.h
index 6e0b585..926d58a 100644
--- a/lib/Support/Windows/Windows.h
+++ b/lib/Support/Windows/Windows.h
@@ -16,11 +16,6 @@
 //===          is guaranteed to work on *all* Win32 variants.
 //===----------------------------------------------------------------------===//
 
-// Require at least Windows 2000 API.
-#define _WIN32_WINNT 0x0500
-#define _WIN32_IE    0x0500 // MinGW at it again.
-#define WIN32_LEAN_AND_MEAN
-
 #include "llvm/Config/config.h" // Get build system configuration settings
 #include <Windows.h>
 #include <ShlObj.h>
-- 
1.7.1.GIT

-------------- next part --------------
From 6f412b6dc3d796f9070662ad9502987fad719554 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 05/18] autoconf: Redefine _WIN32_WINNT in config.h.

_WIN32_WINNT might be defined in system headers (depend on _mingw.h) on mingw-w64.
---
 autoconf/configure.ac              |    5 ++++-
 include/llvm/Config/config.h.cmake |    3 +++
 include/llvm/Config/config.h.in    |    3 +++
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index b282772..0e38f92 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1665,7 +1665,10 @@ dnl contains the same list of files as AC_CONFIG_HEADERS below. This ensures the
 dnl files can be updated automatically when their *.in sources change.
 AC_CONFIG_HEADERS([include/llvm/Config/config.h include/llvm/Config/llvm-config.h])
 AH_TOP([#ifndef CONFIG_H
-#define CONFIG_H])
+#define CONFIG_H
+#ifdef _WIN32_WINNT
+#undef /*nosubst*/_WIN32_WINNT
+#endif])
 AH_BOTTOM([#endif])
 
 AC_CONFIG_FILES([include/llvm/Config/Targets.def])
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index 5e4b418..7179fd1 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -4,6 +4,9 @@
 
 #ifndef CONFIG_H
 #define CONFIG_H
+#ifdef _WIN32_WINNT
+#undef /*nosubst*/_WIN32_WINNT
+#endif
 
 /* Define if CBE is enabled for printf %a output */
 #cmakedefine ENABLE_CBE_PRINTF_A ${ENABLE_CBE_PRINTF_A}
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 06d8a1b..0fe0941 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -2,6 +2,9 @@
 
 #ifndef CONFIG_H
 #define CONFIG_H
+#ifdef _WIN32_WINNT
+#undef /*nosubst*/_WIN32_WINNT
+#endif
 
 /* Relative directory for resource files */
 #undef CLANG_RESOURCE_DIR
-- 
1.7.1.GIT

-------------- next part --------------
From ddc9a842308a444b4fd45c4325036fcfe2c09681 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 06/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 0e38f92..3954d72 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1227,6 +1227,7 @@ 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 --------------
A non-text attachment was scrubbed...
Name: 0007-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 1079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110204/8385f6e3/attachment.bin>
-------------- next part --------------
From 1870e8dcdb633cae7f80c6274c66db8580c7aa17 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 08/18] Windows/Program.inc: Declare SetInformationJobObject() if decls not found in Windows.h.

config.h.*: define HAVE_DECL_SETINFORMATIONJOBOBJECT for SetInformationJobObject() on Mingw32.
---
 cmake/config-ix.cmake              |    1 +
 include/llvm/Config/config.h.cmake |    4 ++++
 include/llvm/Config/config.h.in    |    4 ++++
 lib/Support/Windows/Program.inc    |    4 +++-
 4 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index de71fed..848ffe7 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -156,6 +156,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 7179fd1..c7e47ad 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -65,6 +65,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. */
+#cmakedefine01 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}
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 0fe0941..226b873 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -81,6 +81,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
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 6d204d59981b21766b1f1adbfe66a372c572b399 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 3954d72..e4850bd 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1405,6 +1405,28 @@ AC_CHECK_FUNCS([setjmp longjmp sigsetjmp siglongjmp writev])
 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 --------------
A non-text attachment was scrubbed...
Name: 0010-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 2174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110204/8385f6e3/attachment-0001.bin>
-------------- next part --------------
From d847f60f91bf3ccc98011b4c6586bef64c0c0478 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 11/18] Windows/DynamicLibrary.inc: Split explicit symbols into explicit_symbols.inc.

config.h.* have conditions whether each symbol is defined or not.
---
 cmake/config-ix.cmake                    |   20 ++++++++
 include/llvm/Config/config.h.cmake       |   48 ++++++++++++++++++
 include/llvm/Config/config.h.in          |   48 ++++++++++++++++++
 lib/Support/Windows/DynamicLibrary.inc   |   77 +++++++-----------------------
 lib/Support/Windows/explicit_symbols.inc |   66 +++++++++++++++++++++++++
 5 files changed, 199 insertions(+), 60 deletions(-)
 create mode 100644 lib/Support/Windows/explicit_symbols.inc

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 848ffe7..85c0c6e 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -157,6 +157,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 c7e47ad..a2345e3f 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -461,9 +461,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
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 226b873..4d59d68 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -483,9 +483,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
 
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 6201ecd0fc4cc51361f2577635dc6b4c2122168e Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Fri, 4 Feb 2011 12:03:33 +0900
Subject: [PATCH 12/18] include/llvm/Config/config.h.*: Provide MINGW_HAS_SECURE_API for mingw-w64.

---
 autoconf/configure.ac              |    2 ++
 cmake/config-ix.cmake              |    5 +++++
 configure                          |    5 +++++
 include/llvm/Config/config.h.cmake |    3 +++
 include/llvm/Config/config.h.in    |    3 +++
 5 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index e4850bd..fdbd7fd 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1224,6 +1224,8 @@ if test "$llvm_cv_os_type" = "MingW" ; then
             [MinGW at it again.])
   AC_DEFINE([WIN32_LEAN_AND_MEAN],[],
             [We don't need fullset of Windows headers.])
+  AC_DEFINE([MINGW_HAS_SECURE_API],[],
+            [It enables Secure API on mingw.])
 
   AC_CHECK_LIB(imagehlp, main)
   AC_CHECK_LIB(psapi, main)
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 85c0c6e..7605356 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -92,6 +92,11 @@ if (LLVM_ON_WIN32)
   add_llvm_config_definition(WIN32_LEAN_AND_MEAN 1)
 endif ()
 
+if (MINGW)
+  # Newer version of mingw header could use Secure APIs
+  add_llvm_config_definition(MINGW_HAS_SECURE_API 1)
+endif ()
+
 check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE)
 check_symbol_exists(getrusage sys/resource.h HAVE_GETRUSAGE)
 check_symbol_exists(setrlimit sys/resource.h HAVE_SETRLIMIT)
diff --git a/configure b/configure
index ab6dd62..5bb5d79 100755
--- a/configure
+++ b/configure
@@ -13568,6 +13568,11 @@ cat >>confdefs.h <<\_ACEOF
 _ACEOF
 
 
+cat >>confdefs.h <<\_ACEOF
+#define MINGW_HAS_SECURE_API
+_ACEOF
+
+
 
 { echo "$as_me:$LINENO: checking for main in -limagehlp" >&5
 echo $ECHO_N "checking for main in -limagehlp... $ECHO_C" >&6; }
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index a2345e3f..315c1d1 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -613,6 +613,9 @@
 /* Define to the system default library search path. */
 #cmakedefine LTDL_SYSSEARCHPATH "${LTDL_SYSSEARCHPATH}"
 
+/* It enables Secure API on mingw. */
+#cmakedefine MINGW_HAS_SECURE_API
+
 /* Define if /dev/zero should be used when mapping RWX memory, or undefine if
    its not necessary */
 #undef NEED_DEV_ZERO_FOR_MMAP
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 4d59d68..4725179 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -635,6 +635,9 @@
 /* Define to the system default library search path. */
 #undef LTDL_SYSSEARCHPATH
 
+/* It enables Secure API on mingw. */
+#undef MINGW_HAS_SECURE_API
+
 /* Define if /dev/zero should be used when mapping RWX memory, or undefine if
    its not necessary */
 #undef NEED_DEV_ZERO_FOR_MMAP
-- 
1.7.1.GIT

-------------- next part --------------
From 6fc49e1eb7b61afd6931ba040fb06d1fd66211d6 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 13/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 fdbd7fd..972c5e5 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1401,12 +1401,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 writev])
 AC_C_PRINTF_A
 AC_FUNC_RAND48
 
+dnl Check the declaration "Secure API" on Windows environments.
+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 --------------
A non-text attachment was scrubbed...
Name: 0014-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110204/8385f6e3/attachment-0002.bin>
-------------- next part --------------
From 6cc977f9a9747c07b247fbbf508d0c91664f9856 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] lib/Support/Errno.cpp: Check strerror_s() with HAVE_DECL_STRERROR_S int config.h.*.

FIXME: I have never seen mingw(s) have strerror_s() (not _strerror_s()).
---
 cmake/config-ix.cmake              |    2 +-
 include/llvm/Config/config.h.cmake |    7 ++++---
 include/llvm/Config/config.h.in    |    7 ++++---
 lib/Support/Errno.cpp              |    2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 7605356..951bed8 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -155,7 +155,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 315c1d1..df8d5e4 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -69,6 +69,10 @@
    to 0 if you don't. */
 #cmakedefine01 HAVE_DECL_SETINFORMATIONJOBOBJECT
 
+/* Define to 1 if you have the declaration of `strerror_s', and to 0 if you
+   don't. */
+#cmakedefine01 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}
@@ -375,9 +379,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}
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 4725179..2038c9f 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -85,6 +85,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
@@ -391,9 +395,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
 
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

-------------- next part --------------
From ee39daa4e561e41415da3a24fc5094e3107f8fbd Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Thu, 3 Feb 2011 12:41:25 +0900
Subject: [PATCH 16/18] autoconf: Check _chsize_s's declaration.

On mingw, _chsize_s requires MINGW_HAS_SECURE_API.
---
 autoconf/configure.ac |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/autoconf/configure.ac b/autoconf/configure.ac
index 972c5e5..20109b4 100644
--- a/autoconf/configure.ac
+++ b/autoconf/configure.ac
@@ -1408,7 +1408,7 @@ AC_C_PRINTF_A
 AC_FUNC_RAND48
 
 dnl Check the declaration "Secure API" on Windows environments.
-AC_CHECK_DECLS([strerror_s])
+AC_CHECK_DECLS([_chsize_s,strerror_s],,,[#include <io.h>])
 
 dnl Check symbols in libgcc.a for JIT on Mingw.
 if test "$llvm_cv_os_type" = "MingW" ; then
-- 
1.7.1.GIT

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0017-Regenerate-configure.patch.txt.gz
Type: application/x-gzip
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110204/8385f6e3/attachment-0003.bin>
-------------- next part --------------
From c64d0a0ad3816f94532523c6d2361ec2929fb224 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Thu, 3 Feb 2011 12:43:38 +0900
Subject: [PATCH 18/18] Use HAVE_DECL__CHSIZE_S to check _chsize_s on Win32(s).

---
 cmake/config-ix.cmake              |    2 +-
 include/llvm/Config/config.h.cmake |    7 ++++---
 include/llvm/Config/config.h.in    |    4 ++++
 lib/Support/Windows/PathV2.inc     |    2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake
index 951bed8..7551e33 100755
--- a/cmake/config-ix.cmake
+++ b/cmake/config-ix.cmake
@@ -160,7 +160,7 @@ check_symbol_exists(memcpy string.h HAVE_MEMCPY)
 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(_chsize_s io.h HAVE_DECL__CHSIZE_S)
   check_symbol_exists(SetInformationJobObject windows.h HAVE_DECL_SETINFORMATIONJOBOBJECT)
 
   check_function_exists(_alloca HAVE__ALLOCA)
diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake
index df8d5e4..092b24b 100644
--- a/include/llvm/Config/config.h.cmake
+++ b/include/llvm/Config/config.h.cmake
@@ -73,6 +73,10 @@
    don't. */
 #cmakedefine01 HAVE_DECL_STRERROR_S
 
+/* Define to 1 if you have the declaration of `_chsize_s', and to 0 if you
+   don't. */
+#cmakedefine01 HAVE_DECL__CHSIZE_S
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #cmakedefine HAVE_DIRENT_H ${HAVE_DIRENT_H}
@@ -717,9 +721,6 @@
 /* Define to a function implementing strdup */
 #cmakedefine strdup ${strdup}
 
-/* Define to 1 if you have the `_chsize_s' function. */
-#cmakedefine HAVE__CHSIZE_S ${HAVE__CHSIZE_S}
-
 /* define if the compiler implements namespaces */
 #undef HAVE_NAMESPACES
 
diff --git a/include/llvm/Config/config.h.in b/include/llvm/Config/config.h.in
index 2038c9f..64b2811 100644
--- a/include/llvm/Config/config.h.in
+++ b/include/llvm/Config/config.h.in
@@ -89,6 +89,10 @@
    don't. */
 #undef HAVE_DECL_STRERROR_S
 
+/* Define to 1 if you have the declaration of `_chsize_s', and to 0 if you
+   don't. */
+#undef HAVE_DECL__CHSIZE_S
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc
index b36b291..e8085c3 100644
--- a/lib/Support/Windows/PathV2.inc
+++ b/lib/Support/Windows/PathV2.inc
@@ -328,7 +328,7 @@ error_code resize_file(const Twine &path, uint64_t size) {
   int fd = ::_wopen(path_utf16.begin(), O_BINARY, S_IREAD | S_IWRITE);
   if (fd == -1)
     return error_code(errno, generic_category());
-#ifdef HAVE__CHSIZE_S
+#if defined(HAVE_DECL__CHSIZE_S) && HAVE_DECL__CHSIZE_S
   errno_t error = ::_chsize_s(fd, size);
 #else
   errno_t error = ::_chsize(fd, size);
-- 
1.7.1.GIT



More information about the llvm-commits mailing list