Iain Buclaw avatar Iain Buclaw committed 134e81e

Change use of gdc driver linking in thread library. Remove last of GCC patches.

Comments (0)

Files changed (3)

 
 #endif
 
+/* mingw and cygwin don't have pthread. %% TODO: check darwin.  */
+#if TARGET_WINDOS || TARGET_OSX
+#define USE_PTHREADS    0
+#else
+#define USE_PTHREADS    1
+#endif
+
 /* This macro allows casting away const-ness to pass -Wcast-qual
    warnings.  DO NOT USE THIS UNLESS YOU REALLY HAVE TO!  It should
    only be used in certain specific cases.  One valid case is where
 #define CONST_CAST(TYPE,X) ((__extension__(union {const TYPE _q; TYPE _nq;})(X))._nq)
 #endif
 
-/* Whether we need -pthread flag. */
-extern int need_pthreads;
 
 #if D_GCC_VER >= 46
 
     const struct cl_decoded_option *saw_math = 0;
 
     /* "-lpthread" if it appears on the command line.  */
-    const struct cl_decoded_option *saw_pthread = 0;
+    const struct cl_decoded_option *saw_thread = 0;
 
     /* "-lrt" if it appears on the command line.  */
     const struct cl_decoded_option *saw_librt = 0;
        LANGSPEC, MATHLIB, WITHTHREAD, or WITHLIBC.  */
     int *args;
 
+    /* Whether we need the thread library.  */
+    int need_thread;
+
     /* By default, we throw on the math library if we have one.  */
     int need_math = (MATH_LIBRARY[0] != '\0');
 
     /* Make sure to have room for the trailing NULL argument.  */
     /* There is one extra argument added here for the runtime
        library: -lgphobos.  The -pthread argument is added by
-       setting need_pthreads. */
+       setting need_thread. */
     num_args = argc + added + need_math + shared_libgcc + (library > 0) * 4 + 2;
     new_decoded_options = XNEWVEC (struct cl_decoded_option, num_args);
 
             saw_math = &decoded_options[i];
         }
 
-        if (!saw_pthread && (args[i] & WITHTHREAD) && library > 0)
+        if (!saw_thread && (args[i] & WITHTHREAD) && library > 0)
         {
             --j;
-            saw_pthread = &decoded_options[i];
+            saw_thread = &decoded_options[i];
         }
 
         if (!saw_librt && (args[i] & TIMERLIB) && library > 0)
                          CL_DRIVER, &new_decoded_options[j]);
         added_libraries++;
         j++;
+
+#if USE_PTHREADS
+        /* When linking libphobos we also need to link with the pthread library.  */
+        if (library > 1 && (static_phobos || static_link))
+            need_thread = 1;
+#endif
     }
     else if (saw_debug_flag && debuglib)
     {
         added_libraries++;
         j++;
     }
-
+    
     if (saw_math)
         new_decoded_options[j++] = *saw_math;
     else if (library > 0 && need_math)
         j++;
     }
 
-    if (saw_pthread)
-        new_decoded_options[j++] = *saw_pthread;
-    else if (library > 0)
+    if (saw_thread)
+        new_decoded_options[j++] = *saw_thread;
+    else if (library > 0 && need_thread)
     {
-        /* Handled in gcc.c  */
-        need_pthreads = 1;
+        generate_option (OPT_l, "pthread", 1, CL_DRIVER,
+                         &new_decoded_options[j]);
+        added_libraries++;
+        j++;
     }
 
     if (saw_librt)
     const char *saw_math = 0;
 
     /* "-lpthread" if it appears on the command line.  */
-    const char *saw_pthread = 0;
+    const char *saw_thread = 0;
 
     /* "-lrt" if it appears on the command line.  */
     const char *saw_librt = 0;
     /* Make sure to have room for the trailing NULL argument.  */
     /* There is one extra argument added here for the runtime
        library: -lgphobos.  The -pthread argument is added by
-       setting need_pthreads. */
+       setting need_thread. */
     num_args = argc + added + need_math + shared_libgcc + (library > 0) * 4 + 2;
     arglist = (const char **) xmalloc (num_args * sizeof (char *));
 
             saw_math = argv[i];
         }
 
-        if (!saw_pthread && (args[i] & WITHTHREAD) && library > 0)
+        if (!saw_thread && (args[i] & WITHTHREAD) && library > 0)
         {
             --j;
-            saw_pthread = argv[i];
+            saw_thread = argv[i];
         }
 
         if (!saw_librt && (args[i] & TIMERLIB) && library > 0)
     {
         arglist[j++] = saw_profile_flag ? LIBPHOBOS_PROFILE : LIBPHOBOS;
         added_libraries++;
+
+#if USE_PTHREADS
+        /* When linking libphobos we also need to link with the pthread library.  */
+        if (library > 1 && (static_phobos || static_link))
+            need_thread = 1;
+#endif
     }
     else if (saw_debug_flag && debuglib)
     {
         added_libraries++;
     }
 
-    if (saw_pthread)
-        arglist[j++] = saw_pthread;
-    else if (library > 0)
+    if (saw_thread)
+        arglist[j++] = saw_thread;
+    else if (library > 0 && need_thread)
     {
-        /* Handled in gcc.c  */
-        need_pthreads = 1;
+        arglist[j++] = "-lpthread";
+        added_libraries++;
     }
 
     if (saw_librt)

d/patches/patch-gcc-4.5.x

    else if (strcmp (language_string, "GNU F77") == 0)
      language = DW_LANG_Fortran77;
    else if (strcmp (language_string, "GNU Pascal") == 0)
---- gcc~/gcc.c	2010-04-18 18:46:08.000000000 +0100
-+++ gcc/gcc.c	2012-01-14 19:04:06.515374068 +0000
-@@ -139,6 +139,9 @@ int is_cpp_driver;
- /* Flag set to nonzero if an @file argument has been supplied to gcc.  */
- static bool at_file_supplied;
- 
-+/* Flag set by drivers needing Pthreads. */
-+int need_pthreads;
-+
- /* Flag saying to pass the greatest exit code returned by a sub-process
-    to the calling program.  */
- static int pass_exit_codes;
-@@ -4282,6 +4285,9 @@ process_command (int argc, const char **
-       save_temps_prefix = NULL;
-     }
- 
-+  if (need_pthreads)
-+      n_switches++;
-+
-   if (save_temps_flag && use_pipes)
-     {
-       /* -save-temps overrides -pipe, so that temp files are produced */
-@@ -4646,6 +4652,18 @@ process_command (int argc, const char **
-       infiles[0].name   = "help-dummy";
-     }
- 
-+  if (need_pthreads)
-+    {
-+      switches[n_switches].part1 = "pthread";
-+      switches[n_switches].args = 0;
-+      switches[n_switches].live_cond = 0;
-+      /* Do not print an error if there is not expansion for -pthread. */
-+      switches[n_switches].validated = 1;
-+      switches[n_switches].ordering = 0;
-+
-+      n_switches++;
-+    }
-+
-   switches[n_switches].part1 = 0;
-   infiles[n_infiles].name = 0;
- }

d/patches/patch-gcc-4.6.x

    else if (strcmp (language_string, "GNU F77") == 0)
      language = DW_LANG_Fortran77;
    else if (strcmp (language_string, "GNU Pascal") == 0)
---- gcc~/gcc.c	2011-02-23 02:04:43.000000000 +0000
-+++ gcc/gcc.c	2012-01-10 21:58:14.531416885 +0000
-@@ -83,6 +83,9 @@ int is_cpp_driver;
- /* Flag set to nonzero if an @file argument has been supplied to gcc.  */
- static bool at_file_supplied;
- 
-+/* Flag set by drivers needing Pthreads. */
-+int need_pthreads;
-+
- /* Definition of string containing the arguments given to configure.  */
- #include "configargs.h"
- 
-@@ -3925,6 +3928,18 @@ process_command (unsigned int decoded_op
-       add_infile ("help-dummy", "c");
-     }
- 
-+  if (need_pthreads)
-+    {
-+      alloc_switch ();
-+      switches[n_switches].part1 = "pthread";
-+      switches[n_switches].args = 0;
-+      switches[n_switches].live_cond = 0;
-+      /* Do not print an error if there is not expansion for -pthread. */
-+      switches[n_switches].validated = 1;
-+      switches[n_switches].ordering = 0;
-+      n_switches++;
-+    }
-+
-   alloc_switch ();
-   switches[n_switches].part1 = 0;
-   alloc_infile ();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.