public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Add -static-libquadmath option
@ 2014-10-04 13:51 FX
  2014-10-05 12:41 ` Iain Sandoe
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: FX @ 2014-10-04 13:51 UTC (permalink / raw)
  To: GCC Patches; +Cc: fortran List

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

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?

FX



[-- Attachment #2: static_quadmath.ChangeLog --]
[-- Type: application/octet-stream, Size: 824 bytes --]

2014-10-04  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* lang.opt: Add -static-libquadmath option.
	* invoke.texi: Document -static-libquadmath option.
	* gfortranspec.c (add_arg_libgfortran): Add argument to handle
	static libquadmath.
	(lang_specific_driver): Handle -static-libquadmath.
	* options.c (gfc_handle_option): Error out if -static-libquadmath
	is passed but we do not support it.


2014-10-04  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* common.opt: Add -static-libquadmath option.
	* gcc.c (driver_handle_option): Accept -static-libquadmath always.


2014-10-04  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* acinclude.m4: Adjust LIBQUADSPEC so we don't link libquadmath
	if the driver already did it, due to -static-libquadmath.


[-- Attachment #3: static_quadmath.diff --]
[-- Type: application/octet-stream, Size: 7183 bytes --]

Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 215887)
+++ gcc/gcc.c	(working copy)
@@ -3723,10 +3723,12 @@
     case OPT_static_libgcc:
     case OPT_shared_libgcc:
     case OPT_static_libgfortran:
+    case OPT_static_libquadmath:
     case OPT_static_libstdc__:
       /* These are always valid, since gcc.c itself understands the
-	 first two, gfortranspec.c understands -static-libgfortran and
-	 g++spec.c understands -static-libstdc++ */
+	 first two, gfortranspec.c understands -static-libgfortran 
+	 and -static-libquadmath, and g++spec.c understands
+	 -static-libstdc++ */
       validated = true;
       break;
 
Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 215887)
+++ gcc/common.opt	(working copy)
@@ -2743,6 +2743,10 @@
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libquadmath
+Driver
+; Documented for Fortran, but always accepted by driver.
+
 static-libstdc++
 Driver
 
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 215887)
+++ gcc/fortran/lang.opt	(working copy)
@@ -661,6 +661,10 @@
 Fortran
 Statically link the GNU Fortran helper library (libgfortran)
 
+static-libquadmath
+Fortran
+Statically link the quad-math runtime library
+
 std=f2003
 Fortran
 Conform to the ISO Fortran 2003 standard
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 215887)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -160,7 +160,7 @@
 
 @item Link Options
 @xref{Link Options,,Options for influencing the linking step}.
-@gccoptlist{-static-libgfortran}
+@gccoptlist{-static-libgfortran  -static-libquadmath}
 
 @item Runtime Options
 @xref{Runtime Options,,Options for influencing runtime behavior}.
@@ -1142,6 +1142,16 @@
 @end table
 
 
+@table @gcctabopt
+@item -static-libquadmath
+@opindex @code{static-libquadmath}
+On systems that provide @file{libquadmath} as a shared and a static
+library, this option forces the use of the static version. If no
+shared version of @file{libquadmath} was built when the compiler was
+configured, this option has no effect.
+@end table
+
+
 @node Runtime Options
 @section Influencing runtime behavior
 @cindex options, runtime
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c	(revision 215887)
+++ gcc/fortran/gfortranspec.c	(working copy)
@@ -61,6 +61,10 @@
 #define FORTRAN_LIBRARY "gfortran"
 #endif
 
+#ifndef QUADMATH_LIBRARY
+#define QUADMATH_LIBRARY "quadmath"
+#endif
+
 /* Name of the spec file.  */
 #define SPEC_FILE "libgfortran.spec"
 
@@ -160,17 +164,23 @@
 }
 
 /* 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);
 #endif
@@ -198,8 +208,9 @@
   /* 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 +258,21 @@
 	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:
+#ifdef HAVE_LD_STATIC_DYNAMIC
+	  static_libquadmath = 1;
+#endif
+	  break;
+
 	case OPT_static:
 #ifdef HAVE_LD_STATIC_DYNAMIC
 	  static_linking = 1;
@@ -300,7 +317,7 @@
 
   /* 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 +381,15 @@
 	      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 +412,8 @@
       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:
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 215887)
+++ gcc/fortran/options.c	(working copy)
@@ -861,6 +861,13 @@
 #endif
       break;
 
+    case OPT_static_libquadmath:
+#ifndef HAVE_LD_STATIC_DYNAMIC
+      gfc_fatal_error ("-static-libquadmath is not supported in this "
+		       "configuration");
+#endif
+      break;
+
     case OPT_fimplicit_none:
       gfc_option.flag_implicit_none = value;
       break;
Index: libgfortran/acinclude.m4
===================================================================
--- libgfortran/acinclude.m4	(revision 215887)
+++ libgfortran/acinclude.m4	(working copy)
@@ -335,10 +335,11 @@
     ])
 
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
+    dnl If -static-libquadmath is passed, the driver does it for us.
     if test "x$libgfor_cv_have_as_needed" = xyes; then
-      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} %{!static-libquadmath:-lquadmath} %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
     else
-      LIBQUADSPEC="-lquadmath"
+      LIBQUADSPEC="%{!static-libquadmath:-lquadmath}"
     fi
     if test -f ../libquadmath/libquadmath.la; then
       LIBQUADLIB=../libquadmath/libquadmath.la

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-04 13:51 [patch] Add -static-libquadmath option FX
@ 2014-10-05 12:41 ` Iain Sandoe
  2014-10-06 20:38 ` Joseph S. Myers
  2014-10-09 10:41 ` FX
  2 siblings, 0 replies; 14+ messages in thread
From: Iain Sandoe @ 2014-10-05 12:41 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, fortran List

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:

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-04 13:51 [patch] Add -static-libquadmath option FX
  2014-10-05 12:41 ` Iain Sandoe
@ 2014-10-06 20:38 ` Joseph S. Myers
  2014-10-06 20:52   ` Steve Kargl
  2014-10-09 10:41 ` FX
  2 siblings, 1 reply; 14+ messages in thread
From: Joseph S. Myers @ 2014-10-06 20:38 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, fortran List

Since -static-libquadmath introduces LGPL requirements on redistributing 
the resulting binaries (that you provide source or relinkable object files 
to allow relinking with modified versions of libquadmath) that don't 
otherwise generally apply simply through using GCC to build a program even 
if you link in GCC's other libraries statically, it would seem a good idea 
for the documentation of this option to make that explicit.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-06 20:38 ` Joseph S. Myers
@ 2014-10-06 20:52   ` Steve Kargl
  2014-10-06 21:15     ` Joseph S. Myers
  0 siblings, 1 reply; 14+ messages in thread
From: Steve Kargl @ 2014-10-06 20:52 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: FX, GCC Patches, fortran List

On Mon, Oct 06, 2014 at 08:38:14PM +0000, Joseph S. Myers wrote:
> Since -static-libquadmath introduces LGPL requirements on redistributing 
> the resulting binaries (that you provide source or relinkable object files 
> to allow relinking with modified versions of libquadmath) that don't 
> otherwise generally apply simply through using GCC to build a program even 
> if you link in GCC's other libraries statically, it would seem a good idea 
> for the documentation of this option to make that explicit.

Or, change the license of libquadmath to be compatible with
libgcci and libgfortran.

-- 
Steve

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-06 20:52   ` Steve Kargl
@ 2014-10-06 21:15     ` Joseph S. Myers
  0 siblings, 0 replies; 14+ messages in thread
From: Joseph S. Myers @ 2014-10-06 21:15 UTC (permalink / raw)
  To: Steve Kargl; +Cc: FX, GCC Patches, fortran List

On Mon, 6 Oct 2014, Steve Kargl wrote:

> On Mon, Oct 06, 2014 at 08:38:14PM +0000, Joseph S. Myers wrote:
> > Since -static-libquadmath introduces LGPL requirements on redistributing 
> > the resulting binaries (that you provide source or relinkable object files 
> > to allow relinking with modified versions of libquadmath) that don't 
> > otherwise generally apply simply through using GCC to build a program even 
> > if you link in GCC's other libraries statically, it would seem a good idea 
> > for the documentation of this option to make that explicit.
> 
> Or, change the license of libquadmath to be compatible with
> libgcci and libgfortran.

I believe we established when libquadmath was added that this wasn't an 
option as large parts of the code are not assigned to the FSF.

(Longer-term it might make sense to support TS 18661-3 in GCC and glibc, 
so that libquadmath isn't needed when using new glibc as the functions are 
available in libm under TS 18661-3 names such as sinf128.)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-04 13:51 [patch] Add -static-libquadmath option FX
  2014-10-05 12:41 ` Iain Sandoe
  2014-10-06 20:38 ` Joseph S. Myers
@ 2014-10-09 10:41 ` FX
  2014-10-09 10:52   ` Iain Sandoe
                     ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: FX @ 2014-10-09 10:41 UTC (permalink / raw)
  To: GCC Patches; +Cc: fortran List, Joseph S. Myers, Iain Sandoe

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Version 2 of the patch, now handling the darwin case (thanks Iain) and expressely noting in the documentation the implications on redistribution (thanks Joseph).
Bootstrapped and regtested on x86_64-apple-darwin14.

OK to commit?

I need a C/driver options maintainer, or global reviewer, to OK the C changes (but they really are obvious).
As Iain suggested the darwin.h change, I consider it pre-approved by him :)




> 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?



[-- Attachment #2: static_quad.ChangeLog --]
[-- Type: application/octet-stream, Size: 884 bytes --]

2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* common.opt: Add -static-libquadmath option.
	* gcc.c (driver_handle_option): Always accept -static-libquadmath.
	* config/darwin.h (LINK_SPEC): Handle -static-libquadmath.


2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* lang.opt: Add -static-libquadmath option.
	* invoke.texi: Document -static-libquadmath option.
	* gfortranspec.c (add_arg_libgfortran): Add argument to handle
	static libquadmath.
	(lang_specific_driver): Handle -static-libquadmath.
	* options.c (gfc_handle_option): Error out if -static-libquadmath
	is passed but we do not support it.


2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* acinclude.m4: Adjust LIBQUADSPEC so we don't link libquadmath
	if the driver already did it, due to -static-libquadmath.


[-- Attachment #3: static_quad.diff --]
[-- Type: application/octet-stream, Size: 8676 bytes --]

Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 216036)
+++ gcc/common.opt	(working copy)
@@ -2743,6 +2743,10 @@ static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libquadmath
+Driver
+; Documented for Fortran, but always accepted by driver.
+
 static-libstdc++
 Driver
 
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 216036)
+++ gcc/gcc.c	(working copy)
@@ -3723,10 +3723,12 @@ driver_handle_option (struct gcc_options
     case OPT_static_libgcc:
     case OPT_shared_libgcc:
     case OPT_static_libgfortran:
+    case OPT_static_libquadmath:
     case OPT_static_libstdc__:
       /* These are always valid, since gcc.c itself understands the
-	 first two, gfortranspec.c understands -static-libgfortran and
-	 g++spec.c understands -static-libstdc++ */
+	 first two, gfortranspec.c understands -static-libgfortran 
+	 and -static-libquadmath, and g++spec.c understands
+	 -static-libstdc++ */
       validated = true;
       break;
 
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 216036)
+++ gcc/config/darwin.h	(working copy)
@@ -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: \
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c	(revision 216036)
+++ gcc/fortran/gfortranspec.c	(working copy)
@@ -61,6 +61,10 @@ along with GCC; see the file COPYING3.  
 #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 c
 }
 
 /* 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_
   /* 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,12 +261,18 @@ lang_specific_driver (struct cl_decoded_
 	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:
+#ifdef HAVE_LD_STATIC_DYNAMIC
+	  static_libquadmath = 1;
 #endif
 	  break;
 
@@ -300,7 +320,7 @@ For more information about these matters
 
   /* 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 +384,15 @@ For more information about these matters
 	      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 +415,8 @@ For more information about these matters
       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:
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 216036)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -160,7 +160,7 @@ and warnings}.
 
 @item Link Options
 @xref{Link Options,,Options for influencing the linking step}.
-@gccoptlist{-static-libgfortran}
+@gccoptlist{-static-libgfortran  -static-libquadmath}
 
 @item Runtime Options
 @xref{Runtime Options,,Options for influencing runtime behavior}.
@@ -1142,6 +1142,20 @@ configured, this option has no effect.
 @end table
 
 
+@table @gcctabopt
+@item -static-libquadmath
+@opindex @code{static-libquadmath}
+On systems that provide @file{libquadmath} as a shared and a static
+library, this option forces the use of the static version. If no
+shared version of @file{libquadmath} was built when the compiler was
+configured, this option has no effect.
+
+Please note that the @file{libquadmath} runtime library is under the GNU
+Library General Public License (LGPL), and linking it statically introduces
+requirements on redistributing the resulting binaries.
+@end table
+
+
 @node Runtime Options
 @section Influencing runtime behavior
 @cindex options, runtime
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 216036)
+++ gcc/fortran/lang.opt	(working copy)
@@ -665,6 +665,10 @@ static-libgfortran
 Fortran
 Statically link the GNU Fortran helper library (libgfortran)
 
+static-libquadmath
+Fortran
+Statically link the quad-math runtime library
+
 std=f2003
 Fortran
 Conform to the ISO Fortran 2003 standard
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 216036)
+++ gcc/fortran/options.c	(working copy)
@@ -869,6 +869,13 @@ gfc_handle_option (size_t scode, const c
 #endif
       break;
 
+    case OPT_static_libquadmath:
+#ifndef HAVE_LD_STATIC_DYNAMIC
+      gfc_fatal_error ("-static-libquadmath is not supported in this "
+		       "configuration");
+#endif
+      break;
+
     case OPT_fimplicit_none:
       gfc_option.flag_implicit_none = value;
       break;
Index: libgfortran/acinclude.m4
===================================================================
--- libgfortran/acinclude.m4	(revision 216036)
+++ libgfortran/acinclude.m4	(working copy)
@@ -335,10 +335,11 @@ AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
     ])
 
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
+    dnl If -static-libquadmath is passed, the driver does it for us.
     if test "x$libgfor_cv_have_as_needed" = xyes; then
-      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} %{!static-libquadmath:-lquadmath} %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
     else
-      LIBQUADSPEC="-lquadmath"
+      LIBQUADSPEC="%{!static-libquadmath:-lquadmath}"
     fi
     if test -f ../libquadmath/libquadmath.la; then
       LIBQUADLIB=../libquadmath/libquadmath.la

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-09 10:41 ` FX
@ 2014-10-09 10:52   ` Iain Sandoe
  2014-10-09 12:03     ` FX
  2014-10-09 21:21   ` Mike Stump
  2014-10-15  6:59   ` FX
  2 siblings, 1 reply; 14+ messages in thread
From: Iain Sandoe @ 2014-10-09 10:52 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, fortran List, Joseph Myers, Mike Stump

Hi FX,

On 9 Oct 2014, at 11:39, FX wrote:

> Version 2 of the patch, now handling the darwin case (thanks Iain) and expressely noting in the documentation the implications on redistribution (thanks Joseph).
> Bootstrapped and regtested on x86_64-apple-darwin14.
> 
> OK to commit?
> 
> I need a C/driver options maintainer, or global reviewer, to OK the C changes (but they really are obvious).
> As Iain suggested the darwin.h change, I consider it pre-approved by him :)

But it still needs to be OK'd by either a global reviewer or one of the listed Darwin maintainers ;) ...
... (ccing Mike)

Iain
> 
> 
> 
>> 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?
> 
> 
> <static_quad.ChangeLog><static_quad.diff>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-09 10:52   ` Iain Sandoe
@ 2014-10-09 12:03     ` FX
  0 siblings, 0 replies; 14+ messages in thread
From: FX @ 2014-10-09 12:03 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: GCC Patches, fortran List, Joseph Myers, Mike Stump

> But it still needs to be OK'd by either a global reviewer or one of the listed Darwin maintainers ;) ...
> ... (ccing Mike)

Duh me. I thought you were a darwin maintainer. Sorry.

FX

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-09 10:41 ` FX
  2014-10-09 10:52   ` Iain Sandoe
@ 2014-10-09 21:21   ` Mike Stump
  2014-10-15  6:59   ` FX
  2 siblings, 0 replies; 14+ messages in thread
From: Mike Stump @ 2014-10-09 21:21 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, fortran List, Joseph S. Myers, Iain Sandoe

On Oct 9, 2014, at 3:39 AM, FX <fxcoudert@gmail.com> wrote:
> Version 2 of the patch, now handling the darwin case (thanks Iain)

> OK to commit?

For the bits I can approve, Ok.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-09 10:41 ` FX
  2014-10-09 10:52   ` Iain Sandoe
  2014-10-09 21:21   ` Mike Stump
@ 2014-10-15  6:59   ` FX
  2014-10-15 13:04     ` Tobias Burnus
                       ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: FX @ 2014-10-15  6:59 UTC (permalink / raw)
  To: GCC Patches, fortran List; +Cc: Joseph Myers, neil

[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]

ping

Patch needs:
  - C/driver options maintainer, or global reviewer, to OK the C changes (outside darwin). They are really simple
  - Fortran maintainer to OK the Fortran part


> Version 2 of the patch, now handling the darwin case (thanks Iain) and expressely noting in the documentation the implications on redistribution (thanks Joseph).
> Bootstrapped and regtested on x86_64-apple-darwin14.
> 
> OK to commit?
> 
> I need a C/driver options maintainer, or global reviewer, to OK the C changes (but they really are obvious).
> As Iain suggested the darwin.h change, I consider it pre-approved by him :)
> 
> 
> 
> 
>> 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?
> 
> 

[-- Attachment #2: static_quad.ChangeLog --]
[-- Type: application/octet-stream, Size: 884 bytes --]

2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* common.opt: Add -static-libquadmath option.
	* gcc.c (driver_handle_option): Always accept -static-libquadmath.
	* config/darwin.h (LINK_SPEC): Handle -static-libquadmath.


2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* lang.opt: Add -static-libquadmath option.
	* invoke.texi: Document -static-libquadmath option.
	* gfortranspec.c (add_arg_libgfortran): Add argument to handle
	static libquadmath.
	(lang_specific_driver): Handle -static-libquadmath.
	* options.c (gfc_handle_option): Error out if -static-libquadmath
	is passed but we do not support it.


2014-10-09  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>

	PR fortran/46539
	* acinclude.m4: Adjust LIBQUADSPEC so we don't link libquadmath
	if the driver already did it, due to -static-libquadmath.


[-- Attachment #3: static_quad.diff --]
[-- Type: application/octet-stream, Size: 8676 bytes --]

Index: gcc/common.opt
===================================================================
--- gcc/common.opt	(revision 216036)
+++ gcc/common.opt	(working copy)
@@ -2743,6 +2743,10 @@ static-libgfortran
 Driver
 ; Documented for Fortran, but always accepted by driver.
 
+static-libquadmath
+Driver
+; Documented for Fortran, but always accepted by driver.
+
 static-libstdc++
 Driver
 
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 216036)
+++ gcc/gcc.c	(working copy)
@@ -3723,10 +3723,12 @@ driver_handle_option (struct gcc_options
     case OPT_static_libgcc:
     case OPT_shared_libgcc:
     case OPT_static_libgfortran:
+    case OPT_static_libquadmath:
     case OPT_static_libstdc__:
       /* These are always valid, since gcc.c itself understands the
-	 first two, gfortranspec.c understands -static-libgfortran and
-	 g++spec.c understands -static-libstdc++ */
+	 first two, gfortranspec.c understands -static-libgfortran 
+	 and -static-libquadmath, and g++spec.c understands
+	 -static-libstdc++ */
       validated = true;
       break;
 
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 216036)
+++ gcc/config/darwin.h	(working copy)
@@ -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: \
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c	(revision 216036)
+++ gcc/fortran/gfortranspec.c	(working copy)
@@ -61,6 +61,10 @@ along with GCC; see the file COPYING3.  
 #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 c
 }
 
 /* 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_
   /* 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,12 +261,18 @@ lang_specific_driver (struct cl_decoded_
 	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:
+#ifdef HAVE_LD_STATIC_DYNAMIC
+	  static_libquadmath = 1;
 #endif
 	  break;
 
@@ -300,7 +320,7 @@ For more information about these matters
 
   /* 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 +384,15 @@ For more information about these matters
 	      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 +415,8 @@ For more information about these matters
       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:
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 216036)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -160,7 +160,7 @@ and warnings}.
 
 @item Link Options
 @xref{Link Options,,Options for influencing the linking step}.
-@gccoptlist{-static-libgfortran}
+@gccoptlist{-static-libgfortran  -static-libquadmath}
 
 @item Runtime Options
 @xref{Runtime Options,,Options for influencing runtime behavior}.
@@ -1142,6 +1142,20 @@ configured, this option has no effect.
 @end table
 
 
+@table @gcctabopt
+@item -static-libquadmath
+@opindex @code{static-libquadmath}
+On systems that provide @file{libquadmath} as a shared and a static
+library, this option forces the use of the static version. If no
+shared version of @file{libquadmath} was built when the compiler was
+configured, this option has no effect.
+
+Please note that the @file{libquadmath} runtime library is under the GNU
+Library General Public License (LGPL), and linking it statically introduces
+requirements on redistributing the resulting binaries.
+@end table
+
+
 @node Runtime Options
 @section Influencing runtime behavior
 @cindex options, runtime
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 216036)
+++ gcc/fortran/lang.opt	(working copy)
@@ -665,6 +665,10 @@ static-libgfortran
 Fortran
 Statically link the GNU Fortran helper library (libgfortran)
 
+static-libquadmath
+Fortran
+Statically link the quad-math runtime library
+
 std=f2003
 Fortran
 Conform to the ISO Fortran 2003 standard
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 216036)
+++ gcc/fortran/options.c	(working copy)
@@ -869,6 +869,13 @@ gfc_handle_option (size_t scode, const c
 #endif
       break;
 
+    case OPT_static_libquadmath:
+#ifndef HAVE_LD_STATIC_DYNAMIC
+      gfc_fatal_error ("-static-libquadmath is not supported in this "
+		       "configuration");
+#endif
+      break;
+
     case OPT_fimplicit_none:
       gfc_option.flag_implicit_none = value;
       break;
Index: libgfortran/acinclude.m4
===================================================================
--- libgfortran/acinclude.m4	(revision 216036)
+++ libgfortran/acinclude.m4	(working copy)
@@ -335,10 +335,11 @@ AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
     ])
 
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
+    dnl If -static-libquadmath is passed, the driver does it for us.
     if test "x$libgfor_cv_have_as_needed" = xyes; then
-      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} %{!static-libquadmath:-lquadmath} %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
     else
-      LIBQUADSPEC="-lquadmath"
+      LIBQUADSPEC="%{!static-libquadmath:-lquadmath}"
     fi
     if test -f ../libquadmath/libquadmath.la; then
       LIBQUADLIB=../libquadmath/libquadmath.la

[-- Attachment #4: Type: text/plain, Size: 4 bytes --]

> 


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-15  6:59   ` FX
@ 2014-10-15 13:04     ` Tobias Burnus
       [not found]     ` <B66E9E31-8161-4236-813E-91B2C2AD3575@gmail.com>
  2017-10-19 13:07     ` Janus Weil
  2 siblings, 0 replies; 14+ messages in thread
From: Tobias Burnus @ 2014-10-15 13:04 UTC (permalink / raw)
  To: FX, fortran, gcc-patches; +Cc: Joseph Myers, neil

FX wrote:
> Patch needs:
>   - C/driver options maintainer, or global reviewer, to OK the C changes (outside darwin). They are really simple
>   - Fortran maintainer to OK the Fortran part
[...]
> >> 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.

That unfortunately looses the -as-needed functionality, not that it currently works as hoped for.


> >> Bootstrapped and regtested on x86_64 linux. OK to commit?

--- gcc/fortran/gfortranspec.c	(revision 216036)
+++ gcc/fortran/gfortranspec.c	(working copy)
...
+add_arg_libgfortran (bool force_static ATTRIBUTE_UNUSED,
+		     bool force_static_libquadmath ATTRIBUTE_UNUSED)

First, you don't need ATTRIBUTE_UNUSED for force_static_libquadmath as
it is always used.

But my actual problem is that your patch does't seem to work if -static-gfortran
is not in force. You then get:

   append_option (OPT_l, FORTRAN_LIBRARY, 1);
   append_option (OPT_l, QUADMATH_LIBRARY, 1);

instead of:

  append_option (OPT_l, FORTRAN_LIBRARY, 1);

  append_option (OPT_Wl_, LD_STATIC_OPTION, 1);
  append_option (OPT_l, QUADMATH_LIBRARY, 1);
  append_option (OPT_Wl_, LD_DYNAMIC_OPTION, 1);

Additionally, I wonder whether you need the
 #ifdef HAVE_LD_STATIC_DYNAMIC
...
+#else
+  if (force_static_libquadmath)
+    append_option (OPT_l, QUADMATH_LIBRARY, 1);

at all, given that you have in:

Index: gcc/fortran/options.c
...
+    case OPT_static_libquadmath:
+#ifndef HAVE_LD_STATIC_DYNAMIC
+      gfc_fatal_error ("-static-libquadmath is not supported in this "
+		       "configuration");
+#endif
+      break;

and that without -static-lquadmath, the -lquadmath is added - with as-needed -
in libgfortran's .spec file. (Mentioning this in gfortranspec.c wouldn't harm,
I'd presume.)

(NB: If you remove the #else, you do need the ATTRIBUTE_UNUSED, again.)

Tobias

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
       [not found]     ` <B66E9E31-8161-4236-813E-91B2C2AD3575@gmail.com>
@ 2017-02-26 22:10       ` Gerald Pfeifer
  0 siblings, 0 replies; 14+ messages in thread
From: Gerald Pfeifer @ 2017-02-26 22:10 UTC (permalink / raw)
  To: FX; +Cc: gcc, gcc-patches, Joseph Myers

[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]

On Wed, 15 Oct 2014, FX wrote:
> I sent my last “driver/options” patch to Neil Booth, listed as “option 
> handling” maintainer, but the email bounced back from his 
> daikokuya.co.uk address. Given that he did not commit to the tree since 
> January 2005 (almost 10 years), and that his last commit was to the 
> toplevel ChangeLog:
> 
> 2005-01-19  Neil Booth  <neil@daikokuya.co.uk>
> 
>         * MAINTAINERS: Remove self as cpplib maintainer.
> 
> I suppose it would make sense to remove it “option handling” maintainer.

I guess Neil not removing himself as option handling maintainer
back then was just an oversight, and I have now committed the
change below.

Gerald

2017-02-26  Gerald Pfeifer  <gerald@pfeifer.com>

	* MAINTAINERS: Remove Neil Booth as option handling maintainer.

Index: MAINTAINERS
===================================================================
--- MAINTAINERS	(revision 245741)
+++ MAINTAINERS	(working copy)
@@ -220,7 +220,6 @@
 predict.def		Jan Hubicka		<hubicka@ucw.cz>
 gcov			Jan Hubicka		<hubicka@ucw.cz>
 gcov			Nathan Sidwell		<nathan@acm.org>
-option handling		Neil Booth		<neil@daikokuya.co.uk>
 option handling		Joseph Myers		<joseph@codesourcery.com>
 middle-end		Jeff Law		<law@redhat.com>
 middle-end		Ian Lance Taylor	<ian@airs.com>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2014-10-15  6:59   ` FX
  2014-10-15 13:04     ` Tobias Burnus
       [not found]     ` <B66E9E31-8161-4236-813E-91B2C2AD3575@gmail.com>
@ 2017-10-19 13:07     ` Janus Weil
  2017-10-31  0:18       ` Joseph Myers
  2 siblings, 1 reply; 14+ messages in thread
From: Janus Weil @ 2017-10-19 13:07 UTC (permalink / raw)
  To: FX; +Cc: GCC Patches, fortran List, Joseph Myers, neil

Ping!

Is there any hope to get this 3-year-old patch to trunk after all? (It
seems there was at least a review of the Fortran parts, which has not
seen a reply ...)

Cheers,
Janus



2014-10-15 8:49 GMT+02:00 FX <fxcoudert@gmail.com>:
> ping
>
> Patch needs:
>   - C/driver options maintainer, or global reviewer, to OK the C changes (outside darwin). They are really simple
>   - Fortran maintainer to OK the Fortran part
>
>
>> Version 2 of the patch, now handling the darwin case (thanks Iain) and expressely noting in the documentation the implications on redistribution (thanks Joseph).
>> Bootstrapped and regtested on x86_64-apple-darwin14.
>>
>> OK to commit?
>>
>> I need a C/driver options maintainer, or global reviewer, to OK the C changes (but they really are obvious).
>> As Iain suggested the darwin.h change, I consider it pre-approved by him :)
>>
>>
>>
>>
>>> 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?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [patch] Add -static-libquadmath option
  2017-10-19 13:07     ` Janus Weil
@ 2017-10-31  0:18       ` Joseph Myers
  0 siblings, 0 replies; 14+ messages in thread
From: Joseph Myers @ 2017-10-31  0:18 UTC (permalink / raw)
  To: Janus Weil; +Cc: FX, GCC Patches, fortran List

On Thu, 19 Oct 2017, Janus Weil wrote:

> Ping!
> 
> Is there any hope to get this 3-year-old patch to trunk after all? (It
> seems there was at least a review of the Fortran parts, which has not
> seen a reply ...)

I'm not clear here what the semantics of -static-libquadmath are meant to 
be without -static-libgfortran.

I'm guessing the patch version at 
<https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00771.html> is the one you 
want reviewed.  The documentation appears to indicate that 
-static-libquadmath is perfectly meaningful without -static-libgfortran.  
But in the code, the comment on add_arg_libgfortran seems to imply 
FORCE_STATIC_LIBQUADMATH is only relevant if FORCE_STATIC is true, and the 
implementation seems likewise (only adding -Wl,-Bstatic if FORCE_STATIC).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-10-30 23:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-04 13:51 [patch] Add -static-libquadmath option FX
2014-10-05 12:41 ` Iain Sandoe
2014-10-06 20:38 ` Joseph S. Myers
2014-10-06 20:52   ` Steve Kargl
2014-10-06 21:15     ` Joseph S. Myers
2014-10-09 10:41 ` FX
2014-10-09 10:52   ` Iain Sandoe
2014-10-09 12:03     ` FX
2014-10-09 21:21   ` Mike Stump
2014-10-15  6:59   ` FX
2014-10-15 13:04     ` Tobias Burnus
     [not found]     ` <B66E9E31-8161-4236-813E-91B2C2AD3575@gmail.com>
2017-02-26 22:10       ` Gerald Pfeifer
2017-10-19 13:07     ` Janus Weil
2017-10-31  0:18       ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).