Blame SOURCES/gcc12-static-libquadmath.patch

db712d
2022-08-17  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
db712d
	    Jakub Jelinek  <jakub@redhat.com>
db712d
db712d
	PR fortran/46539
db712d
gcc/
db712d
	* common.opt (static-libquadmath): New option.
db712d
	* gcc.cc (driver_handle_option): Always accept -static-libquadmath.
db712d
	* config/darwin.h (LINK_SPEC): Handle -static-libquadmath.
db712d
gcc/fortran/
db712d
	* lang.opt (static-libquadmath): New option.
db712d
	* invoke.texi (-static-libquadmath): Document it.
db712d
libgfortran/
db712d
	* acinclude.m4 (LIBQUADSPEC): From $FC -static-libgfortran -###
db712d
	output determine -Bstatic/-Bdynamic, -bstatic/-bdynamic,
db712d
	-aarchive_shared/-adefault linker support or Darwin remapping
db712d
	of -lgfortran to libgfortran.a%s and use that around or instead
db712d
	of -lquadmath in LIBQUADSPEC.
db712d
	* configure: Regenerated.
db712d
db712d
--- gcc/common.opt.jj	2022-04-28 15:56:02.822846833 +0200
db712d
+++ gcc/common.opt	2022-09-29 19:41:37.250880668 +0200
db712d
@@ -3563,6 +3563,10 @@ static-libphobos
db712d
 Driver
db712d
 ; Documented for D, but always accepted by driver.
db712d
 
db712d
+static-libquadmath
db712d
+Driver
db712d
+; Documented for Fortran, but always accepted by driver.
db712d
+
db712d
 static-libstdc++
db712d
 Driver
db712d
 
db712d
--- gcc/gcc.cc.jj	2022-04-28 15:56:04.771819920 +0200
db712d
+++ gcc/gcc.cc	2022-09-29 19:41:37.296880041 +0200
db712d
@@ -4583,12 +4583,14 @@ driver_handle_option (struct gcc_options
db712d
     case OPT_static_libgcc:
db712d
     case OPT_shared_libgcc:
db712d
     case OPT_static_libgfortran:
db712d
+    case OPT_static_libquadmath:
db712d
     case OPT_static_libphobos:
db712d
     case OPT_static_libstdc__:
db712d
       /* These are always valid, since gcc.cc itself understands the
db712d
 	 first two, gfortranspec.cc understands -static-libgfortran,
db712d
-	 d-spec.cc understands -static-libphobos, and g++spec.cc
db712d
-	 understands -static-libstdc++ */
db712d
+	 d-spec.cc understands -static-libphobos, g++spec.cc
db712d
+	 understands -static-libstdc++ and libgfortran.spec handles
db712d
+	 -static-libquadmath.  */
db712d
       validated = true;
db712d
       break;
db712d
 
db712d
--- gcc/config/darwin.h.jj	2022-06-18 21:56:40.666675606 +0200
db712d
+++ gcc/config/darwin.h	2022-09-29 19:41:37.261880518 +0200
db712d
@@ -443,6 +443,7 @@ extern GTY(()) int darwin_ms_struct;
db712d
                      %:replace-outfile(-lobjc libobjc-gnu.a%s); \
db712d
                     :%:replace-outfile(-lobjc -lobjc-gnu )}}\
db712d
    %{static|static-libgcc|static-libgfortran:%:replace-outfile(-lgfortran libgfortran.a%s)}\
db712d
+   %{static|static-libgcc|static-libquadmath:%:replace-outfile(-lquadmath libquadmath.a%s)}\
db712d
    %{static|static-libgcc|static-libphobos:%:replace-outfile(-lgphobos libgphobos.a%s)}\
db712d
    %{static|static-libgcc|static-libstdc++|static-libgfortran:%:replace-outfile(-lgomp libgomp.a%s)}\
db712d
    %{static|static-libgcc|static-libstdc++:%:replace-outfile(-lstdc++ libstdc++.a%s)}\
db712d
--- gcc/fortran/lang.opt.jj	2022-04-28 15:56:04.579822571 +0200
db712d
+++ gcc/fortran/lang.opt	2022-09-29 19:41:37.279880273 +0200
db712d
@@ -863,6 +863,10 @@ static-libgfortran
db712d
 Fortran
db712d
 Statically link the GNU Fortran helper library (libgfortran).
db712d
 
db712d
+static-libquadmath
db712d
+Driver
db712d
+Statically link the GCC Quad-Precision Math Library (libquadmath).
db712d
+
db712d
 std=f2003
db712d
 Fortran
db712d
 Conform to the ISO Fortran 2003 standard.
db712d
--- gcc/fortran/invoke.texi.jj	2022-04-29 15:51:59.080720092 +0200
db712d
+++ gcc/fortran/invoke.texi	2022-09-29 19:41:37.273880354 +0200
db712d
@@ -170,7 +170,7 @@ and warnings}.
db712d
 
db712d
 @item Link Options
db712d
 @xref{Link Options,,Options for influencing the linking step}.
db712d
-@gccoptlist{-static-libgfortran}
db712d
+@gccoptlist{-static-libgfortran  -static-libquadmath}
db712d
 
db712d
 @item Runtime Options
db712d
 @xref{Runtime Options,,Options for influencing runtime behavior}.
db712d
@@ -1425,6 +1425,20 @@ configured, this option has no effect.
db712d
 @end table
db712d
 
db712d
 
db712d
+@table @gcctabopt
db712d
+@item -static-libquadmath
db712d
+@opindex @code{static-libquadmath}
db712d
+On systems that provide @file{libquadmath} as a shared and a static
db712d
+library, this option forces the use of the static version. If no
db712d
+shared version of @file{libquadmath} was built when the compiler was
db712d
+configured, this option has no effect.
db712d
+
db712d
+Please note that the @file{libquadmath} runtime library is licensed under the
db712d
+GNU Lesser General Public License (LGPL), and linking it statically introduces
db712d
+requirements when redistributing the resulting binaries.
db712d
+@end table
db712d
+
db712d
+
db712d
 @node Runtime Options
db712d
 @section Influencing runtime behavior
db712d
 @cindex options, runtime
db712d
--- libgfortran/acinclude.m4.jj	2022-09-29 19:41:37.306879904 +0200
db712d
+++ libgfortran/acinclude.m4	2022-09-29 19:42:42.641988408 +0200
db712d
@@ -338,11 +338,32 @@ AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
db712d
       ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
db712d
     ])
db712d
 
db712d
+    dnl Determine -Bstatic ... -Bdynamic etc. support from gfortran -### stderr.
db712d
+    touch conftest1.$ac_objext conftest2.$ac_objext
db712d
+    LQUADMATH=-lquadmath
db712d
+    $FC -static-libgfortran -### -o conftest \
db712d
+	conftest1.$ac_objext -lgfortran conftest2.$ac_objext 2>&1 >/dev/null \
db712d
+	| grep "conftest1.$ac_objext.*conftest2.$ac_objext" > conftest.cmd
db712d
+    if grep "conftest1.$ac_objext.* -Bstatic -lgfortran -Bdynamic .*conftest2.$ac_objext" \
db712d
+       conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-Bstatic} -lquadmath %{static-libquadmath:-Bdynamic}"
db712d
+    elif grep "conftest1.$ac_objext.* -bstatic -lgfortran -bdynamic .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-bstatic} -lquadmath %{static-libquadmath:-bdynamic}"
db712d
+    elif grep "conftest1.$ac_objext.* -aarchive_shared -lgfortran -adefault .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-aarchive_shared} -lquadmath %{static-libquadmath:-adefault}"
db712d
+    elif grep "conftest1.$ac_objext.*libgfortran.a .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:libquadmath.a%s;:-lquadmath}"
db712d
+    fi
db712d
+    rm -f conftest1.$ac_objext conftest2.$ac_objext conftest conftest.cmd
db712d
+
db712d
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
db712d
     if test "x$libgfor_cv_have_as_needed" = xyes; then
db712d
-      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
db712d
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} $LQUADMATH %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
db712d
     else
db712d
-      LIBQUADSPEC="-lquadmath"
db712d
+      LIBQUADSPEC="$LQUADMATH"
db712d
     fi
db712d
     if test -f ../libquadmath/libquadmath.la; then
db712d
       LIBQUADLIB=../libquadmath/libquadmath.la
db712d
--- libgfortran/configure.jj	2022-09-29 19:41:37.345879372 +0200
db712d
+++ libgfortran/configure	2022-09-29 19:42:59.878753212 +0200
db712d
@@ -27301,10 +27301,30 @@ fi
db712d
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgfor_cv_have_as_needed" >&5
db712d
 $as_echo "$libgfor_cv_have_as_needed" >&6; }
db712d
 
db712d
+        touch conftest1.$ac_objext conftest2.$ac_objext
db712d
+    LQUADMATH=-lquadmath
db712d
+    $FC -static-libgfortran -### -o conftest \
db712d
+	conftest1.$ac_objext -lgfortran conftest2.$ac_objext 2>&1 >/dev/null \
db712d
+	| grep "conftest1.$ac_objext.*conftest2.$ac_objext" > conftest.cmd
db712d
+    if grep "conftest1.$ac_objext.* -Bstatic -lgfortran -Bdynamic .*conftest2.$ac_objext" \
db712d
+       conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-Bstatic} -lquadmath %{static-libquadmath:-Bdynamic}"
db712d
+    elif grep "conftest1.$ac_objext.* -bstatic -lgfortran -bdynamic .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-bstatic} -lquadmath %{static-libquadmath:-bdynamic}"
db712d
+    elif grep "conftest1.$ac_objext.* -aarchive_shared -lgfortran -adefault .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:-aarchive_shared} -lquadmath %{static-libquadmath:-adefault}"
db712d
+    elif grep "conftest1.$ac_objext.*libgfortran.a .*conftest2.$ac_objext" \
db712d
+         conftest.cmd >/dev/null 2>&1; then
db712d
+      LQUADMATH="%{static-libquadmath:libquadmath.a%s;:-lquadmath}"
db712d
+    fi
db712d
+    rm -f conftest1.$ac_objext conftest2.$ac_objext conftest conftest.cmd
db712d
+
db712d
         if test "x$libgfor_cv_have_as_needed" = xyes; then
db712d
-      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
db712d
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} $LQUADMATH %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
db712d
     else
db712d
-      LIBQUADSPEC="-lquadmath"
db712d
+      LIBQUADSPEC="$LQUADMATH"
db712d
     fi
db712d
     if test -f ../libquadmath/libquadmath.la; then
db712d
       LIBQUADLIB=../libquadmath/libquadmath.la