Discussion:
[patch] Add -static-libquadmath option
FX
2014-10-04 13:51:25 UTC
Permalink
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
Iain Sandoe
2014-10-05 12:41:28 UTC
Permalink
Hi FX,
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:
Joseph S. Myers
2014-10-06 20:38:14 UTC
Permalink
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
***@codesourcery.com
Steve Kargl
2014-10-06 20:52:35 UTC
Permalink
Post by Joseph S. Myers
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
Joseph S. Myers
2014-10-06 21:15:31 UTC
Permalink
Post by Steve Kargl
Post by Joseph S. Myers
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
***@codesourcery.com
FX
2014-10-09 10:39:04 UTC
Permalink
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 :)
Post by FX
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?
Iain Sandoe
2014-10-09 10:44:10 UTC
Permalink
Hi FX,
Post by FX
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
Post by FX
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>
FX
2014-10-09 11:55:37 UTC
Permalink
Post by Iain Sandoe
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

Loading...