[patch] Add -static-libquadmath option

Iain Sandoe iain@codesourcery.com
Sun Oct 5 12:41:00 GMT 2014


Hi FX,

On 4 Oct 2014, at 14:51, FX wrote:

> We have a -static-libgfortran option, but on targets where we support quad-prec math through libquadmath, we didn’t have an equivalent -static-libquadmath so far. This patch adds it, in what I think is a rather straightforward manner.
> 
> The only minor complication comes from the fact that previously, linking libquadmath was conditionally through libgfortran.spec. So the spec was modified: when we use -static-libquadmath, the driver itself includes the -lquadmath (surrounded by the necessary static linking directives), so that libgfortran.spec shouldn’t do it again.
> 
> Bootstrapped and regtested on x86_64 linux. OK to commit?

If one gives -static-libquadmath on darwin (or presumably any other platform that doesn't support Bstatic/dynamic) then this now breaks linking because the libgfortran.spec then suppresses the addition of "-lquadmath".

Two possible solutions:
 1. don't use -static-libquadmath on darwin ;) ..

 2. make it work for darwin and other platforms without  Bstatic/dynamic by using spec substitution (as we do with other -static-xxxx cases).  

 To do this the library to be substituted needs to appear in "outfiles" (I wonder if one day someone will find time to write a driver substitution method for libraries, the need for them to appear in "outfiles" is odd and inconvenient).

* Patch modifications to achieve this below
* You might also want to double-check for trailing spaces on a couple of lines.
* If you want the (relevant parts of the) test-suite to work with "-static-libquadmath" and spec substitution, then the driver .exp files need to append a -B path/to/libquadmath - if they don't do this already.

---

I tested that the patch mods below DTRT on x86-64-apple-darwin12 (10.8.5) with otool -Lv showing that the referenced lib is no longer present with -static-libquadmath.

NOTE: on darwin I think it is wise to force static runtimes *any* time that -static-libgcc is given.  Otherwise, you can have a situation where part of the executable is refering to state in libgcc (static) but the runtimes are refering to state in libgcc_s.  This can really mess up TLS emulation and/or unwinding (on earlier darwin versions).

cheers
Iain

Part 1 - does the spec substitution.

Part 2 - We note the -static-libquadmath for all platforms.
 - for Bstatic/dysnamic, we use this
 - for others we push "-lquadmath" so that it will be found by the %replace-outfile() spec substitution.

the rest as per your patch.

----


diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 059da35..205afad 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -229,6 +229,7 @@ extern GTY(()) int darwin_ms_struct;
                      %:replace-outfile(-lobjc libobjc-gnu.a%s); \
                     :%:replace-outfile(-lobjc -lobjc-gnu ) } }\
    %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
+   %{static|static-libgcc|static-libquadmath:%:replace-outfile(-lquadmath libquadmath.a%s)}\
    %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
    %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
    %{!Zdynamiclib: \

===
diff --git a/gcc/fortran/gfortranspec.c b/gcc/fortran/gfortranspec.c
index 9d27698..8b9db22 100644
--- a/gcc/fortran/gfortranspec.c
+++ b/gcc/fortran/gfortranspec.c
@@ -61,6 +61,10 @@ along with GCC; see the file COPYING3.  If not see
 #define FORTRAN_LIBRARY "gfortran"
 #endif
 
+#ifndef QUADMATH_LIBRARY
+#define QUADMATH_LIBRARY "quadmath"
+#endif
+
 /* Name of the spec file.  */
 #define SPEC_FILE "libgfortran.spec"
 
@@ -160,19 +164,28 @@ append_option (size_t opt_index, const char *arg, int value)
 }
 
 /* Append a libgfortran argument to the list being built.  If
-   FORCE_STATIC, ensure the library is linked statically.  */
+   FORCE_STATIC, ensure the library is linked statically.  If
+   FORCE_STATIC_LIBQUADMATH, also link the quadmath library statically. */
 
 static void
-add_arg_libgfortran (bool force_static ATTRIBUTE_UNUSED)
+add_arg_libgfortran (bool force_static ATTRIBUTE_UNUSED,
+		     bool force_static_libquadmath ATTRIBUTE_UNUSED)
 {
 #ifdef HAVE_LD_STATIC_DYNAMIC
   if (force_static)
     append_option (OPT_Wl_, LD_STATIC_OPTION, 1);
 #endif
+
   append_option (OPT_l, FORTRAN_LIBRARY, 1);
+
 #ifdef HAVE_LD_STATIC_DYNAMIC
+  if (force_static_libquadmath)
+    append_option (OPT_l, QUADMATH_LIBRARY, 1);
   if (force_static)
     append_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1);
+#else
+  if (force_static_libquadmath)
+    append_option (OPT_l, QUADMATH_LIBRARY, 1);
 #endif
 }
 
@@ -198,8 +211,9 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
   /* By default, we throw on the math library if we have one.  */
   int need_math = (MATH_LIBRARY[0] != '\0');
 
-  /* Whether we should link a static libgfortran.  */
-  int static_lib = 0; 
+  /* Whether we should link a static libgfortran / libquadmath.  */
+  int static_libgfortran = 0;
+  int static_libquadmath = 0;
 
   /* Whether we need to link statically.  */
   int static_linking = 0;
@@ -247,15 +261,19 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
 	case OPT_E:
 	  /* These options disable linking entirely or linking of the
 	     standard libraries.  */
-	  library = 0;
+	  library = NULL;
 	  break;
 
 	case OPT_static_libgfortran:
 #ifdef HAVE_LD_STATIC_DYNAMIC
-	  static_lib = 1;
+	  static_libgfortran = 1;
 #endif
 	  break;
 
+	case OPT_static_libquadmath:
+	  static_libquadmath = 1;
+	  break;
+
 	case OPT_static:
 #ifdef HAVE_LD_STATIC_DYNAMIC
 	  static_linking = 1;
@@ -300,7 +318,7 @@ For more information about these matters, see the file named COPYING\n\n"));
 
   /* If there are no input files, no need for the library.  */
   if (n_infiles == 0)
-    library = 0;
+    library = NULL;
 
   /* Second pass through arglist, transforming arguments as appropriate.  */
 
@@ -364,13 +382,15 @@ For more information about these matters, see the file named COPYING\n\n"));
 	      if (saw_library == 1)
 		saw_library = 2;	/* -l<library> -lm.  */
 	      else
-		add_arg_libgfortran (static_lib && !static_linking);
+		add_arg_libgfortran (static_libgfortran && !static_linking,
+				     static_libquadmath && !static_linking);
 	    }
 	  else if (decoded_options[i].opt_index == OPT_l
 	      && strcmp (decoded_options[i].arg, FORTRAN_LIBRARY) == 0)
 	    {
 	      saw_library = 1;	/* -l<library>.  */
-	      add_arg_libgfortran (static_lib && !static_linking);
+	      add_arg_libgfortran (static_libgfortran && !static_linking,
+				   static_libquadmath && !static_linking);
 	      continue;
 	    }
 	  else
@@ -393,7 +413,8 @@ For more information about these matters, see the file named COPYING\n\n"));
       switch (saw_library)
 	{
 	case 0:
-	  add_arg_libgfortran (static_lib && !static_linking);
+	  add_arg_libgfortran (static_libgfortran && !static_linking,
+			       static_libquadmath && !static_linking);
 	  /* Fall through.  */
 
 	case 1:



More information about the Gcc-patches mailing list