]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Add -static-libquadmath support [PR46539]
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Aug 2022 15:00:33 +0000 (17:00 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 17 Aug 2022 15:03:30 +0000 (17:03 +0200)
The following patch is a revival of the
https://gcc.gnu.org/legacy-ml/gcc-patches/2014-10/msg00771.html
patch.  While trunk configured against recent glibc and with linker
--as-needed support doesn't really need to link against -lquadmath
anymore, there are still other targets where libquadmath is still in
use.
As has been discussed, making -static-libgfortran imply statically
linking both libgfortran and libquadmath is undesirable because of
the significant licensing differences between the 2 libraries.
Compared to the 2014 patch, this one doesn't handle -lquadmath
addition in the driver, which to me looks incorrect, libgfortran
configure determines where in libgfortran.spec -lquadmath should
be present if at all and with what it should be wrapped, but
analyzes gfortran -### -static-libgfortran stderr and based on
that figures out what gcc/configure.ac determined.

2022-08-17  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
    Jakub Jelinek  <jakub@redhat.com>

PR fortran/46539
gcc/
* common.opt (static-libquadmath): New option.
* gcc.cc (driver_handle_option): Always accept -static-libquadmath.
* config/darwin.h (LINK_SPEC): Handle -static-libquadmath.
gcc/fortran/
* lang.opt (static-libquadmath): New option.
* invoke.texi (-static-libquadmath): Document it.
* options.cc (gfc_handle_option): Error out if -static-libquadmath
is passed but we do not support it.
libgfortran/
* acinclude.m4 (LIBQUADSPEC): From $FC -static-libgfortran -###
output determine -Bstatic/-Bdynamic, -bstatic/-bdynamic,
-aarchive_shared/-adefault linker support or Darwin remapping
of -lgfortran to libgfortran.a%s and use that around or instead
of -lquadmath in LIBQUADSPEC.
* configure: Regenerated.

Co-Authored-By: Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
gcc/common.opt
gcc/config/darwin.h
gcc/fortran/invoke.texi
gcc/fortran/lang.opt
gcc/fortran/options.cc
gcc/gcc.cc
libgfortran/acinclude.m4
libgfortran/configure

index e7a51e882bade3bbf7681d0448c75fb1a3d4ba05..fba90ff6dcbed4b274c99f1affa772469c225990 100644 (file)
@@ -3601,6 +3601,10 @@ static-libphobos
 Driver
 ; Documented for D, but always accepted by driver.
 
+static-libquadmath
+Driver
+; Documented for Fortran, but always accepted by driver.
+
 static-libstdc++
 Driver
 
index f82ec62cf2092ec99a0d8c68ba18374ca5160b86..c5e1ba84e6f885ad2a36c755fc4d3d480e2567d2 100644 (file)
@@ -443,6 +443,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-libphobos:%:replace-outfile(-lgphobos libgphobos.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)}\
index c0932f6cd703e0101fc614510acd855f2e38efef..4d1e0d6b513640f41d72644f55c306dd484901ac 100644 (file)
@@ -170,7 +170,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}.
@@ -1425,6 +1425,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 licensed under the
+GNU Lesser General Public License (LGPL), and linking it statically introduces
+requirements when redistributing the resulting binaries.
+@end table
+
+
 @node Runtime Options
 @section Influencing runtime behavior
 @cindex options, runtime
index cf397129d55b528495c68d23d3b003b5b18167b5..e8cd73505e8f165c590ed5e55184cb81845fe7d9 100644 (file)
@@ -863,6 +863,10 @@ static-libgfortran
 Fortran
 Statically link the GNU Fortran helper library (libgfortran).
 
+static-libquadmath
+Fortran
+Statically link the GCC Quad-Precision Math Library (libquadmath).
+
 std=f2003
 Fortran
 Conform to the ISO Fortran 2003 standard.
index d0fa634f1bafd92f190d8dca7e44e2166b62547e..38249d65cd8e3143760d8500b0da8b962a211e5b 100644 (file)
@@ -692,6 +692,13 @@ gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 #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_fintrinsic_modules_path:
     case OPT_fintrinsic_modules_path_:
 
index 75ca0ece1a46ca2d3898571cf7ea48f47934e014..b6d562a92f0a09d25404fc92a705e177763b3bcf 100644 (file)
@@ -4585,12 +4585,14 @@ driver_handle_option (struct gcc_options *opts,
     case OPT_static_libgcc:
     case OPT_shared_libgcc:
     case OPT_static_libgfortran:
+    case OPT_static_libquadmath:
     case OPT_static_libphobos:
     case OPT_static_libstdc__:
       /* These are always valid, since gcc.cc itself understands the
         first two, gfortranspec.cc understands -static-libgfortran,
-        d-spec.cc understands -static-libphobos, and g++spec.cc
-        understands -static-libstdc++ */
+        d-spec.cc understands -static-libphobos, g++spec.cc
+        understands -static-libstdc++ and libgfortran.spec handles
+        -static-libquadmath.  */
       validated = true;
       break;
 
index b4cc0bdde1251d4d2eea9271468477a72d5d94c2..a73207e54656fdd412eba99551cd77ac37e402de 100644 (file)
@@ -356,18 +356,39 @@ AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
       ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
     ])
 
+    dnl Determine -Bstatic ... -Bdynamic etc. support from gfortran -### stderr.
+    touch conftest1.$ac_objext conftest2.$ac_objext
+    LQUADMATH=-lquadmath
+    $FC -static-libgfortran -### -o conftest \
+       conftest1.$ac_objext -lgfortran conftest2.$ac_objext 2>&1 >/dev/null \
+       | grep "conftest1.$ac_objext.*conftest2.$ac_objext" > conftest.cmd
+    if grep "conftest1.$ac_objext.* -Bstatic -lgfortran -Bdynamic .*conftest2.$ac_objext" \
+       conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-Bstatic} -lquadmath %{static-libquadmath:-Bdynamic}"
+    elif grep "conftest1.$ac_objext.* -bstatic -lgfortran -bdynamic .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-bstatic} -lquadmath %{static-libquadmath:-bdynamic}"
+    elif grep "conftest1.$ac_objext.* -aarchive_shared -lgfortran -adefault .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-aarchive_shared} -lquadmath %{static-libquadmath:-adefault}"
+    elif grep "conftest1.$ac_objext.*libgfortran.a .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:libquadmath.a%s;:-lquadmath}"
+    fi
+    rm -f conftest1.$ac_objext conftest2.$ac_objext conftest conftest.cmd
+
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
     dnl If using *f128 APIs from libc/libm, depend on libquadmath only if needed
     dnl even for dynamic libgfortran linkage, and don't link libgfortran against
     dnl -lquadmath.
     if test "x$libgfor_cv_have_as_needed" = xyes; then
       if test "x$USE_IEC_60559" = xyes; then
-       LIBQUADSPEC="$libgfor_cv_as_needed_option -lquadmath $libgfor_cv_no_as_needed_option"
+       LIBQUADSPEC="$libgfor_cv_as_needed_option $LQUADMATH $libgfor_cv_no_as_needed_option"
       else
-       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} $LQUADMATH %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
       fi
     else
-      LIBQUADSPEC="-lquadmath"
+      LIBQUADSPEC="$LQUADMATH"
     fi
     if test "x$USE_IEC_60559" != xyes; then
       if test -f ../libquadmath/libquadmath.la; then
index 581f1dc52d291bd1d933dd635a2b6439adb882f1..beb0ec49eb15093a2bd0ba32da4720f85bb096e1 100755 (executable)
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgfor_cv_have_as_needed" >&5
 $as_echo "$libgfor_cv_have_as_needed" >&6; }
 
+        touch conftest1.$ac_objext conftest2.$ac_objext
+    LQUADMATH=-lquadmath
+    $FC -static-libgfortran -### -o conftest \
+       conftest1.$ac_objext -lgfortran conftest2.$ac_objext 2>&1 >/dev/null \
+       | grep "conftest1.$ac_objext.*conftest2.$ac_objext" > conftest.cmd
+    if grep "conftest1.$ac_objext.* -Bstatic -lgfortran -Bdynamic .*conftest2.$ac_objext" \
+       conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-Bstatic} -lquadmath %{static-libquadmath:-Bdynamic}"
+    elif grep "conftest1.$ac_objext.* -bstatic -lgfortran -bdynamic .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-bstatic} -lquadmath %{static-libquadmath:-bdynamic}"
+    elif grep "conftest1.$ac_objext.* -aarchive_shared -lgfortran -adefault .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:-aarchive_shared} -lquadmath %{static-libquadmath:-adefault}"
+    elif grep "conftest1.$ac_objext.*libgfortran.a .*conftest2.$ac_objext" \
+         conftest.cmd >/dev/null 2>&1; then
+      LQUADMATH="%{static-libquadmath:libquadmath.a%s;:-lquadmath}"
+    fi
+    rm -f conftest1.$ac_objext conftest2.$ac_objext conftest conftest.cmd
+
                     if test "x$libgfor_cv_have_as_needed" = xyes; then
       if test "x$USE_IEC_60559" = xyes; then
-       LIBQUADSPEC="$libgfor_cv_as_needed_option -lquadmath $libgfor_cv_no_as_needed_option"
+       LIBQUADSPEC="$libgfor_cv_as_needed_option $LQUADMATH $libgfor_cv_no_as_needed_option"
       else
-       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} $LQUADMATH %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
       fi
     else
-      LIBQUADSPEC="-lquadmath"
+      LIBQUADSPEC="$LQUADMATH"
     fi
     if test "x$USE_IEC_60559" != xyes; then
       if test -f ../libquadmath/libquadmath.la; then