Hello,

This patch enables for native windows targets the posix
threading-model by using pthread-library.   To build toolchain
defaulting to posx-threading model it is necessary to use winpthread
library for a complete bootstrap.  The pthread-win32 library isn't
suitable as it uses for the pthread_t type a structure, which isn't
handled by gthr-posix.

2011-03-31  Kai Tietz

        * config.gcc (*-*-mingw*): Allow as option the
        posix threading model.
        * config/i386/mingw32.h ( SPEC_PTHREAD1,  SPEC_PTHREAD2):
        New macros defined dependent to TARGET_USE_PTHREAD_BY_DEFAULT
        definition.
        (CPP_SPEC): Add pthread/no-pthread handling.
        (LIB_SPEC): Likewise.
        * config/i386/mingw-w64.h (CPP_SPEC):Likewise.
        (LIB_SPEC): Likewise.
        * config/i386/t-cygming (SHLIB_PTHREAD_CFLAG): New
        flag to pass -pthread option for shared libgcc build.
        (SHLIB_PTHREAD_LDFLAG): New option to pass -lpthread
        for shared libgcc build.
        * config/i386/t-mingw-pthread: New file.
        * config/i386/mingw-pthread.h (TARGET_USE_PTHREAD_BY_DEFAULT):
        New define to enable use of library pthread by default.
        * config/i386/mingw.opt (pthread): New driver option.
        (no-pthread): New driver option.
        * config/i386/cygming.opt: Make sure trailing empty line
        is retained.
        * config/i386/mingw-w64.opt: Likewise.

Tested for x86_64-w64-ming32, i686-pc-mingw32, and regression-tested
for i686-pc-cygwin. I will apply this tomorrow, if there aren't any
objections.

Regards,
Kai
Index: gcc/gcc/config.gcc
===================================================================
--- gcc.orig/gcc/config.gcc     2011-03-23 21:15:32.000000000 +0100
+++ gcc/gcc/config.gcc  2011-03-31 10:50:05.559129000 +0200
@@ -1410,7 +1410,7 @@ i[34567]86-*-cygwin*)
        use_gcc_stdint=wrap
        ;;
 i[34567]86-*-mingw* | x86_64-*-mingw*)
-       tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h 
i386/cygming.h i386/mingw32.h"
+       tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h dbxcoff.h 
i386/cygming.h"
        xm_file=i386/xm-mingw32.h
        case ${target} in
                x86_64-*-* | *-w64-*)
@@ -1420,6 +1420,10 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
                *)
                        ;;
        esac
+       if test x$enable_threads = xposix ; then
+               tm_file="${tm_file} i386/mingw-pthread.h"
+       fi
+       tm_file="${tm_file} i386/mingw32.h"
        # This makes the logic if mingw's or the w64 feature set has to be used
        case ${target} in
                *-w64-*)
@@ -1486,10 +1490,14 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
        cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
        default_use_cxa_atexit=yes
        use_gcc_stdint=wrap
-       case ${enable_threads} in
-         "" | yes | win32)       thread_file='win32'
-         tmake_file="${tmake_file} i386/t-gthr-win32"
-         ;;
+       case x${enable_threads} in
+         x | xyes | xwin32)      thread_file='win32'
+           tmake_file="${tmake_file} i386/t-gthr-win32"
+           ;;
+         xposix)
+           thread_file='posix'
+           tmake_file="i386/t-mingw-pthread ${tmake_file}"
+           ;;
        esac
        case ${target} in
                x86_64-*-mingw*)
Index: gcc/gcc/config/i386/mingw-w64.h
===================================================================
--- gcc.orig/gcc/config/i386/mingw-w64.h        2011-03-24 10:59:32.000000000 
+0100
+++ gcc/gcc/config/i386/mingw-w64.h     2011-03-31 10:54:20.066447300 +0200
@@ -1,8 +1,8 @@
 /* Operating system specific defines to be used when targeting GCC for
    hosting on Windows 32/64 via mingw-w64 runtime, using GNU tools and
    the Windows API Library.
-   Copyright (C) 2009,
-   2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010,
+   2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -20,11 +20,13 @@ You should have received a copy of the G
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-/* Enable -municode feature.  */
+/* Enable -municode feature and support optional pthread support.  */
 
 #undef CPP_SPEC
-#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} \
-  %{municode:-DUNICODE}"
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
+                "%{municode:-DUNICODE} " \
+                "%{" SPEC_PTHREAD1 ":-D_REENTRANCE} " \
+                "%{" SPEC_PTHREAD2 ":-U_REENTRANCE} "
 
 #undef STARTFILE_SPEC
 #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
@@ -38,6 +40,12 @@ along with GCC; see the file COPYING3.
 #undef ASM_SPEC
 #define ASM_SPEC "%{m32:--32} %{m64:--64}"
 
+#undef LIB_SPEC
+#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
+                "%{" SPEC_PTHREAD2 ": } " \
+                "%{mwindows:-lgdi32 -lcomdlg32} " \
+                "-ladvapi32 -lshell32 -luser32 -lkernel32"
+
 #undef SPEC_32
 #undef SPEC_64
 #if TARGET_64BIT_DEFAULT
Index: gcc/gcc/config/i386/t-cygming
===================================================================
--- gcc.orig/gcc/config/i386/t-cygming  2011-03-21 09:03:49.000000000 +0100
+++ gcc/gcc/config/i386/t-cygming       2011-03-30 13:55:34.134484700 +0200
@@ -77,16 +77,23 @@ SHLIB_SLIBDIR_QUAL = @shlib_slibdir_qual
 ifndef SHLIB_DLLDIR
 $(error SHLIB_DLLDIR must be defined)
 endif
+ifndef SHLIB_PTHREAD_CFLAG
+SHLIB_PTHREAD_CFLAG =
+endif
+ifndef SHLIB_PTHREAD_LDFLAG
+SHLIB_PTHREAD_LDFLAG =
+endif
 
 SHLIB_LINK = $(LN_S) -f $(SHLIB_MAP) $(SHLIB_MAP).def && \
        if [ ! -d $(SHLIB_DIR) ]; then \
                mkdir $(SHLIB_DIR); \
        else true; fi && \
-       $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -shared -nodefaultlibs \
+       $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) $(SHLIB_PTHREAD_CFLAG) \
+       -shared -nodefaultlibs \
        $(SHLIB_MAP).def \
        -Wl,--out-implib,$(SHLIB_DIR)/$(SHLIB_IMPLIB).tmp \
        -o $(SHLIB_DIR)/$(SHLIB_SONAME).tmp @multilib_flags@ \
-       $(SHLIB_OBJS) $(SHLIB_LC) && \
+       $(SHLIB_OBJS) ${SHLIB_PTHREAD_LDFLAG} $(SHLIB_LC) && \
        if [ -f $(SHLIB_DIR)/$(SHLIB_SONAME) ]; then \
          mv -f $(SHLIB_DIR)/$(SHLIB_SONAME) \
                $(SHLIB_DIR)/$(SHLIB_SONAME).backup; \
Index: gcc/gcc/config/i386/t-mingw-pthread
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ gcc/gcc/config/i386/t-mingw-pthread 2011-03-30 13:54:00.228060100 +0200
@@ -0,0 +1,2 @@
+SHLIB_PTHREAD_CFLAG = -pthread
+SHLIB_PTHREAD_LDFLAG = -Wl,-lpthread
Index: gcc/gcc/config/i386/mingw-pthread.h
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ gcc/gcc/config/i386/mingw-pthread.h 2011-03-31 09:41:47.308217200 +0200
@@ -0,0 +1,21 @@
+/* Defines that pthread library shall be enabled by default
+   for target.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#define TARGET_USE_PTHREAD_BY_DEFAULT 1
Index: gcc/gcc/config/i386/mingw.opt
===================================================================
--- gcc.orig/gcc/config/i386/mingw.opt  2010-09-09 16:08:48.000000000 +0200
+++ gcc/gcc/config/i386/mingw.opt       2011-03-31 08:55:00.502298100 +0200
@@ -18,6 +18,12 @@
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
 
+pthread
+Driver
+
+no-pthread
+Driver
+
 Wpedantic-ms-format
 C ObjC C++ ObjC++ Var(warn_pedantic_ms_format) Init(1) Warning
 Warn about none ISO msvcrt scanf/printf width extensions
@@ -25,3 +31,5 @@ Warn about none ISO msvcrt scanf/printf
 fset-stack-executable
 Common Report Var(flag_setstackexecutable) Init(1) Optimization
 For nested functions on stack executable permission is set.
+
+; Need to retain blank line above.
Index: gcc/gcc/config/i386/mingw32.h
===================================================================
--- gcc.orig/gcc/config/i386/mingw32.h  2011-03-25 17:09:42.000000000 +0100
+++ gcc/gcc/config/i386/mingw32.h       2011-03-31 10:54:08.299953100 +0200
@@ -1,7 +1,7 @@
 /* Operating system specific defines to be used when targeting GCC for
    hosting on Windows32, using GNU tools and the Windows32 API Library.
    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008,
-   2009, 2010 Free Software Foundation, Inc.
+   2009, 2010, 2011 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -50,6 +50,14 @@ along with GCC; see the file COPYING3.
     }                                                          \
   while (0)
 
+#ifndef TARGET_USE_PTHREAD_BY_DEFAULT
+#define SPEC_PTHREAD1 "pthread"
+#define SPEC_PTHREAD2 "!no-pthread"
+#else
+#define SPEC_PTHREAD1 "!no-pthread"
+#define SPEC_PTHREAD2 "pthread"
+#endif
+
 #undef SUB_LINK_ENTRY32
 #undef SUB_LINK_ENTRY64
 #define SUB_LINK_ENTRY32 "-e _DllMainCRTStartup@12"
@@ -74,13 +82,17 @@ along with GCC; see the file COPYING3.
 #define STANDARD_INCLUDE_COMPONENT "MINGW"
 
 #undef CPP_SPEC
-#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}"
+#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT} " \
+                "%{" SPEC_PTHREAD1 ":-D_REENTRANCE} " \
+                "%{" SPEC_PTHREAD2 ": } "
 
 /* For Windows applications, include more libraries, but always include
    kernel32.  */
 #undef LIB_SPEC
-#define LIB_SPEC "%{pg:-lgmon} %{mwindows:-lgdi32 -lcomdlg32} \
-                  -ladvapi32 -lshell32 -luser32 -lkernel32"
+#define LIB_SPEC "%{pg:-lgmon} %{" SPEC_PTHREAD1 ":-lpthread} " \
+                "%{" SPEC_PTHREAD2 ": } " \
+                "%{mwindows:-lgdi32 -lcomdlg32} " \
+                 "-ladvapi32 -lshell32 -luser32 -lkernel32"
 
 /* Weak symbols do not get resolved if using a Windows dll import lib.
    Make the unwind registration references strong undefs.  */
Index: gcc/gcc/config/i386/cygming.opt
===================================================================
--- gcc.orig/gcc/config/i386/cygming.opt        2011-02-02 08:18:27.000000000 
+0100
+++ gcc/gcc/config/i386/cygming.opt     2011-03-30 19:50:20.225975100 +0200
@@ -52,3 +52,5 @@ Compile code that relies on Cygwin DLL w
 
 posix
 Driver
+
+; Retain blank line above
Index: gcc/gcc/config/i386/mingw-w64.opt
===================================================================
--- gcc.orig/gcc/config/i386/mingw-w64.opt      2010-09-09 16:08:47.000000000 
+0200
+++ gcc/gcc/config/i386/mingw-w64.opt   2011-03-30 19:49:52.472950900 +0200
@@ -21,3 +21,5 @@
 municode
 Target
 Use unicode startup and define UNICODE macro
+
+; Retain blank line above.

Reply via email to