diff --git a/gcc/d/d-ctype.cc b/gcc/d/d-ctype.cc
index 7661dec..c1c10a0 100644
--- a/gcc/d/d-ctype.cc
+++ b/gcc/d/d-ctype.cc
@@ -393,6 +393,11 @@ TypeFunction::toCtype (void)
 	    case LINKc:
 	    case LINKcpp:
 	    case LINKd:
+	    #if TARGET_WINDOS
+            /* GCC switched MinGW's Default ABI to THISCALL/CDECL.  GDC 
+               currently has issues with this so force CDECL fow now. */
+            ctype = insert_type_attribute (ctype, "cdecl");
+	    #endif
 	      break;
 
 	    default:
diff --git a/gcc/d/d-decls.cc b/gcc/d/d-decls.cc
index 4f178cb..62208b0 100644
--- a/gcc/d/d-decls.cc
+++ b/gcc/d/d-decls.cc
@@ -227,11 +227,11 @@ VarDeclaration::toSymbol (void)
       // Have to test for import first
       if (isImportedSymbol())
 	{
-	  gen.addDeclAttribute (var_decl, "dllimport");
+	  insert_decl_attribute (var_decl, "dllimport");
 	  DECL_DLLIMPORT_P (var_decl) = 1;
 	}
       else if (isExport())
-	gen.addDeclAttribute (var_decl, "dllexport");
+	insert_decl_attribute (var_decl, "dllexport");
 #endif
 
       if (isDataseg() && isThreadlocal())
@@ -478,12 +478,12 @@ FuncDeclaration::toSymbol (void)
 	  // Have to test for import first
 	  if (isImportedSymbol())
 	    {
-	      gen.addDeclAttribute (fndecl, "dllimport");
+	      insert_decl_attribute (fndecl, "dllimport");
 	      DECL_DLLIMPORT_P (fndecl) = 1;
 	    }
 	  else if (isExport())
 	    {
-	      gen.addDeclAttribute (fndecl, "dllexport");
+	      insert_decl_attribute (fndecl, "dllexport");
 	    }
 #endif
 	  object_file->setDeclLoc (fndecl, this);
diff --git a/gcc/d/dfrontend/mtype.c b/gcc/d/dfrontend/mtype.c
index 749a801..7e4f4b1 100644
--- a/gcc/d/dfrontend/mtype.c
+++ b/gcc/d/dfrontend/mtype.c
@@ -2214,8 +2214,11 @@ Identifier *Type::getTypeInfoIdent(int internal)
     assert(strlen(name) < namelen);     // don't overflow the buffer
 
     size_t off = 0;
+// MinGW needs the '_'
+#if !defined(__MINGW32__)
     if (global.params.isOSX || global.params.isWindows && !global.params.is64bit)
         ++off;                 // C mangling will add '_' back in
+#endif
     Identifier *id = Lexer::idPool(name + off);
 
     if (name != namebuf)
diff --git a/libphobos/Makefile.am b/libphobos/Makefile.am
index dd25d22..a07529a 100644
--- a/libphobos/Makefile.am
+++ b/libphobos/Makefile.am
@@ -114,7 +114,7 @@ FREEBSD_OBJS=std/c/freebsd/socket.o
 WINDOWS_OBJS=std/c/windows/com.o std/c/windows/stat.o std/c/wcharh.o \
 	     std/c/windows/windows.o std/c/windows/winsock.o \
 	     std/windows/charset.o std/windows/iunknown.o std/windows/registry.o \
-	     std/windows/syserror.o std/__fileinit.o std/internal/windows/advapi32.o
+	     std/windows/syserror.o std/internal/windows/advapi32.o
 
 D_EXTRA_OBJS=@D_EXTRA_OBJS@
 
diff --git a/libphobos/Makefile.in b/libphobos/Makefile.in
index 8d0cf1d..94fa4ca 100644
--- a/libphobos/Makefile.in
+++ b/libphobos/Makefile.in
@@ -333,7 +333,7 @@ FREEBSD_OBJS = std/c/freebsd/socket.o
 WINDOWS_OBJS = std/c/windows/com.o std/c/windows/stat.o std/c/wcharh.o \
 	     std/c/windows/windows.o std/c/windows/winsock.o \
 	     std/windows/charset.o std/windows/iunknown.o std/windows/registry.o \
-	     std/windows/syserror.o std/__fileinit.o std/internal/windows/advapi32.o
+	     std/windows/syserror.o std/internal/windows/advapi32.o
 
 ALL_PHOBOS_OBJS = $(D_EXTRA_OBJS) $(MAIN_OBJS) $(ZLIB_OBJS)
 
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
index c9b1207..97e1686 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -110,7 +110,7 @@ RT_POSIX_OBJS=core/sys/posix/dirent.o core/sys/posix/netdb.o \
 
 RT_WINDOWS_OBJS=core/sys/windows/dbghelp.o core/sys/windows/dll.o \
 		core/sys/windows/stacktrace.o core/sys/windows/threadaux.o \
-		core/sys/windows/windows.o
+		core/sys/windows/windows.o core/sys/windows/mingwex.o
 
 # This should not be linked into a shared library.
 CMAIN_OBJS= #rt/cmain.o
diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in
index 3745a7d..fd73001 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -270,7 +270,7 @@ RT_POSIX_OBJS = core/sys/posix/dirent.o core/sys/posix/netdb.o \
 
 RT_WINDOWS_OBJS = core/sys/windows/dbghelp.o core/sys/windows/dll.o \
 		core/sys/windows/stacktrace.o core/sys/windows/threadaux.o \
-		core/sys/windows/windows.o
+		core/sys/windows/windows.o core/sys/windows/mingwex.o
 
 
 # This should not be linked into a shared library.
diff --git a/libphobos/libdruntime/core/runtime.d b/libphobos/libdruntime/core/runtime.d
index 3c9330b..3f23777 100644
--- a/libphobos/libdruntime/core/runtime.d
+++ b/libphobos/libdruntime/core/runtime.d
@@ -28,6 +28,10 @@ version(Android)
     version = HaveDLADDR;
     version = GenericBacktrace;
 }
+else version(GNU)
+{
+    version = GenericBacktrace;
+}
 else version(Windows)
 {
     version = WindowsBacktrace;
@@ -41,10 +45,7 @@ else version(OSX)
 {
     version = OSXBacktrace;
 }
-else version(GNU)
-{
-    version = GenericBacktrace;
-}
+
 
 private
 {
@@ -677,8 +678,16 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
             return s;
         }
     }
+    else version(MinGW)
+    {
+        /* This can probably yuse GenericBacktrace once the const issues 
+         * are dealt with.
+         */
+        return null;
+    }
     else version(GenericBacktrace)
     {
+
         class DefaultTraceInfo : Throwable.TraceInfo
         {
             this()
@@ -687,15 +696,15 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
                 framelist = gdcBacktraceSymbols(callstack);
             }
 
-            override int opApply( scope int delegate(ref char[]) dg )
+            override int opApply( scope int delegate(ref const(char[])) dg ) const
             {
-                return opApply( (ref size_t, ref char[] buf)
+                return opApply( (ref size_t, ref const(char[]) buf)
                                 {
                                     return dg( buf );
                                 } );
             }
 
-            override int opApply( scope int delegate(ref size_t, ref char[]) dg )
+            override int opApply( scope int delegate(ref size_t, ref const(char[])) dg ) const
             {
                 version( Posix )
                 {
@@ -743,7 +752,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
             char[4096] fixbuf;
 
             /*Do not put \n at end of line!*/
-            char[] formatLine(backtraceSymbol sym)
+            char[] formatLine( const(backtraceSymbol) sym) const
             {
                 int ret;
                 
diff --git a/libphobos/libdruntime/core/sys/posix/sys/wait.d b/libphobos/libdruntime/core/sys/posix/sys/wait.d
index b21eef4..63322ef 100644
--- a/libphobos/libdruntime/core/sys/posix/sys/wait.d
+++ b/libphobos/libdruntime/core/sys/posix/sys/wait.d
@@ -14,12 +14,12 @@
  */
 module core.sys.posix.sys.wait;
 
+version (Posix):
 private import core.sys.posix.config;
 public import core.sys.posix.sys.types; // for id_t, pid_t
 public import core.sys.posix.signal;    // for siginfo_t (XSI)
 //public import core.sys.posix.resource; // for rusage (XSI)
 
-version (Posix):
 extern (C):
 
 //
diff --git a/libphobos/libdruntime/core/sys/windows/dll.d b/libphobos/libdruntime/core/sys/windows/dll.d
index 271091b..1a6e2bf 100644
--- a/libphobos/libdruntime/core/sys/windows/dll.d
+++ b/libphobos/libdruntime/core/sys/windows/dll.d
@@ -297,7 +297,7 @@ public:
      *
      * _tls_index is initialized by the compiler to 0, so we can use this as a test.
      */
-    bool dll_fixTLS( HINSTANCE hInstance, void* tlsstart, void* tlsend, void* tls_callbacks_a, int* tlsindex ) nothrow
+    bool dll_fixTLS( HINSTANCE hInstance, void* tlsstart, void* tlsend, void* tls_callbacks_a, int* tlsindex )
     {
         version (Win64)
             return true;                // fixed
@@ -312,11 +312,15 @@ public:
             return true;
 
         void** peb;
-        asm
-        {
-            mov EAX,FS:[0x30];
-            mov peb, EAX;
-        }
+        version( GNU_InlineAsm ) 
+            asm { "movl %%fs:0x30, %0;" : "=r" peb; }
+        else        
+            asm
+            {
+                mov EAX,FS:[0x30];
+                mov peb, EAX;
+            }
+        
         dll_aux.LDR_MODULE *ldrMod = dll_aux.findLdrModule( hInstance, peb );
         if( !ldrMod )
             return false; // not in module list, bail out
diff --git a/libphobos/libdruntime/core/sys/windows/mingwex.d b/libphobos/libdruntime/core/sys/windows/mingwex.d
new file mode 100644
index 0000000..33bb441
--- /dev/null
+++ b/libphobos/libdruntime/core/sys/windows/mingwex.d
@@ -0,0 +1,272 @@
+/*
+ * MinGW uses MSVCRT stdio functions by default.  Support for C99 is done with 
+ * macros and inline functions.  This module generates replacement functions
+ * suitable for extern(C) usage.
+ *
+ * From mingw-w64 stdio.h
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the w64 mingw-runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+module core.sys.windows.mingwex;
+  
+//version (MinGW):
+version (none):
+extern (C):
+
+private import gcc.builtins;
+private import core.vararg;
+private import core.stdc.stdio;
+private import core.stdc.stddef;
+
+
+extern {
+    int __mingw_sscanf(in char *  _Src,in char *  _Format,...);
+    int __mingw_vsscanf (in char *  _Str,in char *  Format,va_list argp);
+    int __mingw_scanf(in char *  _Format,...);
+    int __mingw_vscanf(in char *  Format, va_list argp);
+    int __mingw_fscanf(FILE *  _File,in char *  _Format,...);
+    int __mingw_vfscanf (FILE *  fp, in char *  Format,va_list argp);
+    int __mingw_vsnprintf(char *  _DstBuf,size_t _MaxCount,in char *  _Format, va_list _ArgList);
+    int __mingw_snprintf(char *  s, size_t n, in char *   format, ...);
+    
+    int __mingw_swscanf(in wchar_t *  _Src,in wchar_t *  _Format,...);
+    int __mingw_vswscanf (in wchar_t *  _Str,in wchar_t *  Format,va_list argp);
+    int __mingw_wscanf(in wchar_t *  _Format,...);
+    int __mingw_vwscanf(in wchar_t *  Format, va_list argp);
+    int __mingw_fwscanf(FILE *  _File,in wchar_t *  _Format,...);
+    int __mingw_vfwscanf (FILE *  fp, in wchar_t *  Format,va_list argp);
+    
+    int __mingw_fwprintf(FILE *  _File,in wchar_t *  _Format,...);
+    int __mingw_wprintf(in wchar_t *  _Format,...);
+    int __mingw_vfwprintf(FILE *  _File,in wchar_t *  _Format,va_list    _ArgList);
+    int __mingw_vwprintf(in wchar_t *  _Format,va_list _ArgList);
+    deprecated int __mingw_swprintf(wchar_t *  , in wchar_t *  , ...);
+    deprecated int __mingw_vswprintf(wchar_t *  , in wchar_t *  ,va_list);
+    int __mingw_snwprintf (wchar_t *  s, size_t n, in wchar_t *  format, ...);
+    int __mingw_vsnwprintf (wchar_t *  , size_t, in wchar_t *  , va_list);
+
+
+    nothrow 
+    {
+        int __mingw_printf(in char *  , ... );
+        int __mingw_vprintf (in char *  , va_list);
+        int __mingw_fprintf (FILE *  , in char *  , ...);
+        int __mingw_vfprintf (FILE *  , in char *  , va_list);
+        int __mingw_sprintf (char *  , in char *  , ...);
+        int __mingw_vsprintf (char *  , in char *  , va_list);
+        int __mingw_asprintf(char **  , in char *  , ...);
+        int __mingw_vasprintf(char **  , in char *  , va_list);
+    }
+}
+
+int sscanf(in char *__source, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vsscanf( __source, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int scanf(in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vscanf( __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int fscanf(FILE *__stream, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vfscanf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vsscanf (in char *__source, in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vsscanf( __source, __format, __local_argv );
+}
+
+int vscanf(in char *__format,  __builtin_va_list __local_argv)
+{
+  return __mingw_vscanf( __format, __local_argv );
+}
+
+int vfscanf (FILE *__stream,  in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vfscanf( __stream, __format, __local_argv );
+}
+
+int fprintf (FILE *__stream, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vfprintf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int printf (in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vprintf( __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int sprintf (char *__stream, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vsprintf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vfprintf (FILE *__stream, in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vfprintf( __stream, __format, __local_argv );
+}
+
+int vprintf (in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vprintf( __format, __local_argv );
+}
+
+int vsprintf (char *__stream, in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vsprintf( __stream, __format, __local_argv );
+}
+
+int asprintf(char **__ret, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vasprintf( __ret, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+
+int vasprintf(char **__ret, in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vasprintf( __ret, __format, __local_argv );
+}
+
+int snprintf (char *__stream, size_t __n, in char *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vsnprintf( __stream, __n, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vsnprintf (char *__stream, size_t __n, in char *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vsnprintf( __stream, __n, __format, __local_argv );
+}
+ 
+int swscanf(in wchar_t *__source, in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vswscanf( __source, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int wscanf(in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vwscanf( __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int fwscanf(FILE *__stream, in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vfwscanf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vswscanf (in wchar_t * __source, in wchar_t * __format, __builtin_va_list __local_argv)
+{
+  return __mingw_vswscanf( __source, __format, __local_argv );
+}
+
+int vwscanf(in wchar_t *__format,  __builtin_va_list __local_argv)
+{
+  return __mingw_vwscanf( __format, __local_argv );
+}
+
+int vfwscanf (FILE *__stream,  in wchar_t *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vfwscanf( __stream, __format, __local_argv );
+}
+
+int fwprintf (FILE *__stream, in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vfwprintf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int wprintf (in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vwprintf( __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int swprintf (wchar_t *__stream, in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vswprintf( __stream, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vfwprintf (FILE *__stream, in wchar_t *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vfwprintf( __stream, __format, __local_argv );
+}
+
+int vwprintf (in wchar_t *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vwprintf( __format, __local_argv );
+}
+
+int vswprintf (wchar_t *__stream, in wchar_t *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vswprintf( __stream, __format, __local_argv );
+}
+
+int snwprintf (wchar_t *__stream, size_t __n, in wchar_t *__format, ...)
+{
+  int __retval;
+  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
+  __retval = __mingw_vsnwprintf( __stream, __n, __format, __local_argv );
+  __builtin_va_end( __local_argv );
+  return __retval;
+}
+
+int vsnwprintf (wchar_t *__stream, size_t __n, in wchar_t *__format, __builtin_va_list __local_argv)
+{
+  return __mingw_vsnwprintf( __stream, __n, __format, __local_argv );
+}
diff --git a/libphobos/libdruntime/core/sys/windows/threadaux.d b/libphobos/libdruntime/core/sys/windows/threadaux.d
index 15599c1..3695e69 100644
--- a/libphobos/libdruntime/core/sys/windows/threadaux.d
+++ b/libphobos/libdruntime/core/sys/windows/threadaux.d
@@ -162,26 +162,39 @@ private:
         }
 
         // get linear address of TEB of current thread
-        static void** getTEB() nothrow
+        static void** getTEB() 
         {
             version(Win32)
             {
-                asm
+                version( GNU_InlineAsm ) 
                 {
-                    naked;
-                    mov EAX,FS:[0x18];
-                    ret;
+                    void** teb;
+                    asm 
+                    { 
+                        "movl %%fs:0x18, %0;" : "=r" teb;
+                    }
+                    return teb;
                 }
+                else
+                    asm
+                    {
+                        naked;
+                        mov EAX,FS:[0x18];
+                        ret;
+                    }
             }
             else version(Win64)
             {
-                asm
-                {
-                    naked;
-                    mov RAX,0x30;
-                    mov RAX,GS:[RAX]; // immediate value causes fixup
-                    ret;
-                }
+                version(GNU_InlineAsm)
+                    static assert(false, "unsupported");
+                else
+                    asm
+                    {
+                        naked;
+                        mov RAX,0x30;
+                        mov RAX,GS:[RAX]; // immediate value causes fixup
+                        ret;
+                    }
             }
             else
             {
diff --git a/libphobos/libdruntime/core/thread.d b/libphobos/libdruntime/core/thread.d
index f99ee9b..ba88300 100644
--- a/libphobos/libdruntime/core/thread.d
+++ b/libphobos/libdruntime/core/thread.d
@@ -152,6 +152,22 @@ version( Windows )
                 alias _tls_end   _tlsend;
             }
         }
+        else version( MinGW )
+        {
+            import gcc.builtins;
+        
+            // NOTE: The memory between the addresses of _tls_start and _tls_end
+            //       is the storage for thread-local data in MinGW.  Both of
+            //       these are defined in tlssup.c.
+            extern (C)
+            {
+                extern int _tls_start;
+                extern int _tls_end;
+            }
+            
+            alias _tls_start _tlsstart;
+            alias _tls_end _tlsend;
+        }        
         else
         {
             __gshared int   _tlsstart;
@@ -2883,6 +2899,19 @@ private void* getStackBottom()
                  mov RAX, GS:[RAX];
                  ret;
             }
+        else version( GNU_InlineAsm )
+        {
+            void *bottom;
+
+            version( X86 )
+                asm{ "movl %%fs:4, %0;" : "=r" bottom; }                
+            else version( X86_64 )
+                asm{ "movq %%gs:8, %0;" : "=r" bottom; }            
+            else
+                static assert( false, "Platform not supported.");
+
+            return bottom;
+        }                    
         else
             static assert(false, "Architecture not supported.");
     }
@@ -3396,6 +3425,10 @@ private
                 jmp RCX;
             }
         }
+        else version(MinGW)
+        {
+            assert(0, "unimplemented");
+        }
         else static if( __traits( compiles, ucontext_t ) )
         {
             Fiber   cfib = Fiber.getThis();
@@ -4223,6 +4256,10 @@ private:
             pstack -= ABOVE;
             *cast(size_t*)(pstack - SZ_RA) = cast(size_t)&fiber_entryPoint;
         }
+        else version(MinGW)
+        {
+            assert(0, "unimplemented");
+        }
         else static if( __traits( compiles, ucontext_t ) )
         {
             getcontext( &m_utxt );
diff --git a/libphobos/libdruntime/rt/dmain2.d b/libphobos/libdruntime/rt/dmain2.d
index 7c68b45..689e4bc 100644
--- a/libphobos/libdruntime/rt/dmain2.d
+++ b/libphobos/libdruntime/rt/dmain2.d
@@ -515,6 +515,12 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
     {
         if (IsDebuggerPresent())
             trapExceptions = false;
+        version (MinGW)
+        {
+            /* IsDebuggerPresent doesn't detect GDC.  Would be nice to have
+               some way of detecting valid console output */
+            trapExceptions = true;
+        }
     }
 
     void tryExec(scope void delegate() dg)
diff --git a/libphobos/std/outbuffer.d b/libphobos/std/outbuffer.d
index ffe1c16..3b8f4a9 100644
--- a/libphobos/std/outbuffer.d
+++ b/libphobos/std/outbuffer.d
@@ -267,7 +267,19 @@ class OutBuffer
         auto psize = buffer.length;
         for (;;)
         {
-            version(Windows)
+            version(MinGW)
+            {
+                /* _vsnprintf defaults to msvcrt which is not comptable. */
+                count = vsnprintf(p,psize,f,args);
+                if (count == -1)
+                    psize *= 2;
+                else if (count >= psize)
+                    psize = count + 1;
+                else
+                    break;                    
+                p = cast(char *) alloca(psize); // buffer too small, try again with larger size            
+            } 
+            else version(Windows)
             {
                 count = _vsnprintf(p,psize,f,args);
                 if (count != -1)
diff --git a/libphobos/std/stream.d b/libphobos/std/stream.d
index 9e65602..91d5937 100644
--- a/libphobos/std/stream.d
+++ b/libphobos/std/stream.d
@@ -1145,7 +1145,16 @@ class Stream : InputStream, OutputStream {
     size_t psize = buffer.length;
     size_t count;
     while (true) {
-      version (Windows) {
+      version (MinGW) {
+        count = vsnprintf(p, psize, f, args);
+        if (count == -1)
+          psize *= 2;
+        else if (count >= psize)
+          psize = count + 1;
+        else
+          break;
+        p = cast(char*) alloca(psize);
+      } else version (Windows) {
         count = _vsnprintf(p, psize, f, args);
         if (count != -1)
           break;
diff --git a/setup-gcc.sh b/setup-gcc.sh
index 214992f..84d4ac1 100755
--- a/setup-gcc.sh
+++ b/setup-gcc.sh
@@ -13,6 +13,7 @@ fi
 d_gccsrc=
 d_update_gcc=0
 top=`pwd`
+is_mingw=`[ "$(uname -s)" == "MINGW32_NT-6.1" ] && echo 1`
 
 # Read command line arguments
 for arg in "$@"; do
@@ -63,33 +64,40 @@ if test ! -f gcc/"$gcc_patch_fn"; then
     exit 1
 fi
 
-# 1. Remove d sources from d_gccsrc if already exist
-test -h "$d_gccsrc/gcc/d" && rm "$d_gccsrc/gcc/d"
-test -d "$d_gccsrc/libphobos" && rm -r "$d_gccsrc/libphobos"
-if test -e "$d_gccsrc/gcc/d" -o -e "$d_gccsrc/libphobos"; then
-    echo "error: cannot update gcc source, please remove D sources by hand."
-    exit 1
-fi
-
-d_test=$d_gccsrc/gcc/testsuite
-# remove testsuite sources
-test -d "$d_test/gdc.test" && rm -r "$d_test/gdc.test"
-test -e "$d_test/lib/gdc.exp" && rm "$d_test/lib/gdc.exp"
-test -e "$d_test/lib/gdc-dg.exp" && rm "$d_test/lib/gdc-dg.exp"
-if test -e "$d_test/gdc.test" -o -e "$d_test/lib/gdc.exp" -o -e "$d_test/lib/gdc-dg.exp"; then
-    echo "error: cannot update gcc source, please remove D testsuite sources by hand."
-    exit 1
-fi
-
+# MinGW lacks symbolic links, so we use rsync. This ensures only modified files get rebuilt.
+if [ $is_mingw ]; then
+  rsync -rav "$top/gcc/d" "$d_gccsrc/gcc/"
+  rsync -rav "$top/libphobos" "$d_gccsrc/"
+  rsync -rav "$top/gcc/testsuite" "$d_gccsrc/gcc/"
+  cd $top
+else
+  # 1. Remove d sources from d_gccsrc if already exist
+  test -h "$d_gccsrc/gcc/d" && rm -r "$d_gccsrc/gcc/d"
+  test -d "$d_gccsrc/libphobos" && rm -r "$d_gccsrc/libphobos"
+  if test -e "$d_gccsrc/gcc/d" -o -e "$d_gccsrc/libphobos"; then
+      echo "error: cannot update gcc source, please remove D sources by hand."
+      exit 1
+  fi
+
+  d_test=$d_gccsrc/gcc/testsuite
+  # remove testsuite sources
+  test -d "$d_test/gdc.test" && rm -r "$d_test/gdc.test"
+  test -e "$d_test/lib/gdc.exp" && rm "$d_test/lib/gdc.exp"
+  test -e "$d_test/lib/gdc-dg.exp" && rm "$d_test/lib/gdc-dg.exp"
+  if test -e "$d_test/gdc.test" -o -e "$d_test/lib/gdc.exp" -o -e "$d_test/lib/gdc-dg.exp"; then
+      echo "error: cannot update gcc source, please remove D testsuite sources by hand."
+      exit 1
+  fi
 
 # 2. Copy sources
-ln -s "$top/gcc/d" "$d_gccsrc/gcc/d"   && \
-  mkdir "$d_gccsrc/libphobos"          && \
-  cd "$d_gccsrc/libphobos"             && \
-  ../symlink-tree "$top/libphobos"     && \
-  cd "../gcc/testsuite"                && \
-  ../../symlink-tree "$top/gcc/testsuite" && \
-  cd $top
+  ln -s "$top/gcc/d" "$d_gccsrc/gcc/d"   && \
+    mkdir "$d_gccsrc/libphobos"          && \
+    cd "$d_gccsrc/libphobos"             && \
+    ../symlink-tree "$top/libphobos"     && \
+    cd "../gcc/testsuite"                && \
+    ../../symlink-tree "$top/gcc/testsuite" && \
+    cd $top
+fi
 
 
 if test $d_update_gcc -eq 1; then
