public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] fortran: Add -static-libquadmath support [PR46539]
@ 2022-08-16 14:31 Jakub Jelinek
  2022-08-17  7:19 ` Jakub Jelinek
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jakub Jelinek @ 2022-08-16 14:31 UTC (permalink / raw)
  To: gcc-patches, fortran

Hi!

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 wrapper, but
analyzes gfortran -### -static-libgfortran stderr and based on
that figures out what gcc/configure.ac determined.

So far slightly tested on x86_64-linux (and will bootstrap/regtest
it there tonight), but I unfortunately don't have a way to test it
e.g. on Darwin.

Thoughts on this?

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

	PR fortran/46539
gcc/
	* common.opt (static-libquadmath): New option.
	* gcc.c (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.c (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.

--- gcc/common.opt.jj	2022-06-27 11:18:02.050066582 +0200
+++ gcc/common.opt	2022-08-16 14:51:04.611673800 +0200
@@ -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
 
--- gcc/gcc.cc.jj	2022-08-11 09:57:24.765334380 +0200
+++ gcc/gcc.cc	2022-08-16 14:57:54.708327024 +0200
@@ -4585,12 +4585,14 @@ 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_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;
 
--- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
+++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
@@ -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-libgfortran:%: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)}\
--- gcc/fortran/lang.opt.jj	2022-02-04 14:36:55.050604670 +0100
+++ gcc/fortran/lang.opt	2022-08-16 14:52:52.459267705 +0200
@@ -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.
--- gcc/fortran/options.cc.jj	2022-01-18 11:58:59.568982256 +0100
+++ gcc/fortran/options.cc	2022-08-16 14:56:22.807525218 +0200
@@ -692,6 +692,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_fintrinsic_modules_path:
     case OPT_fintrinsic_modules_path_:
 
--- gcc/fortran/invoke.texi.jj	2022-05-09 09:09:20.312473272 +0200
+++ gcc/fortran/invoke.texi	2022-08-16 16:12:47.638203577 +0200
@@ -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 on redistributing the resulting binaries.
+@end table
+
+
 @node Runtime Options
 @section Influencing runtime behavior
 @cindex options, runtime
--- libgfortran/acinclude.m4.jj	2022-06-29 17:05:45.478790781 +0200
+++ libgfortran/acinclude.m4	2022-08-16 16:06:50.047814043 +0200
@@ -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.* ligfortran.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
--- libgfortran/configure.jj	2022-06-29 17:05:45.483790716 +0200
+++ libgfortran/configure	2022-08-16 16:06:54.119761574 +0200
@@ -30323,14 +30323,34 @@ fi
 { $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.* ligfortran.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

	Jakub


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

* Re: [PATCH] fortran: Add -static-libquadmath support [PR46539]
  2022-08-16 14:31 [PATCH] fortran: Add -static-libquadmath support [PR46539] Jakub Jelinek
@ 2022-08-17  7:19 ` Jakub Jelinek
  2022-08-17  7:55 ` Tobias Burnus
  2022-08-17  8:28 ` Mikael Morin
  2 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2022-08-17  7:19 UTC (permalink / raw)
  To: gcc-patches, fortran

On Tue, Aug 16, 2022 at 04:31:03PM +0200, Jakub Jelinek via Gcc-patches wrote:
> So far slightly tested on x86_64-linux (and will bootstrap/regtest
> it there tonight), but I unfortunately don't have a way to test it

FYI, successfully bootstrapped/regtested on x86_64-linux and i686-linux.

> 2022-08-16  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
> 	    Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR fortran/46539
> gcc/
> 	* common.opt (static-libquadmath): New option.
> 	* gcc.c (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.c (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.

	Jakub


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

* Re: [PATCH] fortran: Add -static-libquadmath support [PR46539]
  2022-08-16 14:31 [PATCH] fortran: Add -static-libquadmath support [PR46539] Jakub Jelinek
  2022-08-17  7:19 ` Jakub Jelinek
@ 2022-08-17  7:55 ` Tobias Burnus
  2022-08-17  8:28 ` Mikael Morin
  2 siblings, 0 replies; 7+ messages in thread
From: Tobias Burnus @ 2022-08-17  7:55 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches, fortran

On 16.08.22 16:31, Jakub Jelinek via Gcc-patches wrote:
> 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.
> [...]
> So far slightly tested on x86_64-linux (and will bootstrap/regtest
> it there tonight), but I unfortunately don't have a way to test it
> e.g. on Darwin.
>
> Thoughts on this?

Looks good to me – with the caveat of having only limited knowledge of
.spec and Darwin.

> --- gcc/fortran/invoke.texi.jj        2022-05-09 09:09:20.312473272 +0200
> +++ gcc/fortran/invoke.texi   2022-08-16 16:12:47.638203577 +0200
...
> +Please note that the @file{libquadmath} runtime library is licensed under the
> +GNU Lesser General Public License (LGPL), and linking it statically introduces
> +requirements on redistributing the resulting binaries.

"on redistributing" sounds odd to me – "when redistributing" or "on
(the) redistribution of" sounds better to me.

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

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

* Re: [PATCH] fortran: Add -static-libquadmath support [PR46539]
  2022-08-16 14:31 [PATCH] fortran: Add -static-libquadmath support [PR46539] Jakub Jelinek
  2022-08-17  7:19 ` Jakub Jelinek
  2022-08-17  7:55 ` Tobias Burnus
@ 2022-08-17  8:28 ` Mikael Morin
  2022-08-17 11:05   ` [PATCH] fortran, v2: " Jakub Jelinek
  2 siblings, 1 reply; 7+ messages in thread
From: Mikael Morin @ 2022-08-17  8:28 UTC (permalink / raw)
  To: Jakub Jelinek, gcc-patches, fortran

Hello,

Tobias approved it already, but I spotted what looks like typos.
See below.

Mikael

> gcc/
> 	* common.opt (static-libquadmath): New option.
> 	* gcc.c (driver_handle_option): Always accept -static-libquadmath.
> 	* config/darwin.h (LINK_SPEC): Handle -static-libquadmath.

(...)

> --- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
> +++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
> @@ -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-libgfortran:%:replace-outfile(-lquadmath libquadmath.a%s)}\

s/static-libgfortran/static-libquadmath/ I guess?  Otherwise I don’t 
understand the corresponding ChangeLog description.

>      %{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)}\

(...)

> --- libgfortran/acinclude.m4.jj	2022-06-29 17:05:45.478790781 +0200
> +++ libgfortran/acinclude.m4	2022-08-16 16:06:50.047814043 +0200
> @@ -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.* ligfortran.a .*conftest2.$ac_objext" \

s/ligfortran.a/libgfortran.a/

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


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

* [PATCH] fortran, v2: Add -static-libquadmath support [PR46539]
  2022-08-17  8:28 ` Mikael Morin
@ 2022-08-17 11:05   ` Jakub Jelinek
  2022-08-18 10:35     ` Iain Sandoe
  0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2022-08-17 11:05 UTC (permalink / raw)
  To: Mikael Morin; +Cc: gcc-patches, fortran

On Wed, Aug 17, 2022 at 10:28:29AM +0200, Mikael Morin wrote:
> Tobias approved it already, but I spotted what looks like typos.
> See below.

Thanks for catching that.

> > --- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
> > +++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
> > @@ -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-libgfortran:%:replace-outfile(-lquadmath libquadmath.a%s)}\
> 
> s/static-libgfortran/static-libquadmath/ I guess?  Otherwise I don’t
> understand the corresponding ChangeLog description.

Yeah.  I just copied this part from the 2014 patch and didn't spot that.

> > +    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.* ligfortran.a .*conftest2.$ac_objext" \
> 
> s/ligfortran.a/libgfortran.a/

Indeed.  Also removed the space before libgfortran.a because I'm not sure if
it won't have because of the %s full path in front of that.
This is Darwin only stuff.
I must say I don't know if even this elif ... LQUADMATH part is needed,
maybe replace-outfile will rename even the -lquadmath from the spec file.

Here is an updated version (but nothing relevant to Linux changed, so there
is no point for me to bootstrap/regtest it again):

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.c (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.c (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.

--- gcc/common.opt.jj	2022-06-27 11:18:02.050066582 +0200
+++ gcc/common.opt	2022-08-16 14:51:04.611673800 +0200
@@ -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
 
--- gcc/gcc.cc.jj	2022-08-11 09:57:24.765334380 +0200
+++ gcc/gcc.cc	2022-08-16 14:57:54.708327024 +0200
@@ -4585,12 +4585,14 @@ 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_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;
 
--- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
+++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
@@ -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)}\
--- gcc/fortran/lang.opt.jj	2022-02-04 14:36:55.050604670 +0100
+++ gcc/fortran/lang.opt	2022-08-16 14:52:52.459267705 +0200
@@ -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.
--- gcc/fortran/options.cc.jj	2022-01-18 11:58:59.568982256 +0100
+++ gcc/fortran/options.cc	2022-08-16 14:56:22.807525218 +0200
@@ -692,6 +692,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_fintrinsic_modules_path:
     case OPT_fintrinsic_modules_path_:
 
--- gcc/fortran/invoke.texi.jj	2022-05-09 09:09:20.312473272 +0200
+++ gcc/fortran/invoke.texi	2022-08-16 16:12:47.638203577 +0200
@@ -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
--- libgfortran/acinclude.m4.jj	2022-06-29 17:05:45.478790781 +0200
+++ libgfortran/acinclude.m4	2022-08-16 16:06:50.047814043 +0200
@@ -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
--- libgfortran/configure.jj	2022-06-29 17:05:45.483790716 +0200
+++ libgfortran/configure	2022-08-16 16:06:54.119761574 +0200
@@ -30323,14 +30323,34 @@ fi
 { $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


	Jakub


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

* Re: [PATCH] fortran, v2: Add -static-libquadmath support [PR46539]
  2022-08-17 11:05   ` [PATCH] fortran, v2: " Jakub Jelinek
@ 2022-08-18 10:35     ` Iain Sandoe
  2022-08-18 10:41       ` Jakub Jelinek
  0 siblings, 1 reply; 7+ messages in thread
From: Iain Sandoe @ 2022-08-18 10:35 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Mikael Morin, GCC Patches, GCC Fortran

Hi Folks

> On 17 Aug 2022, at 12:05, Jakub Jelinek via Fortran <fortran@gcc.gnu.org> wrote:
> 
> On Wed, Aug 17, 2022 at 10:28:29AM +0200, Mikael Morin wrote:
>> Tobias approved it already, but I spotted what looks like typos.
>> See below.
> 
> Thanks for catching that.
> 
>>> --- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
>>> +++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
>>> @@ -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-libgfortran:%:replace-outfile(-lquadmath libquadmath.a%s)}\
>> 
>> s/static-libgfortran/static-libquadmath/ I guess?  Otherwise I don’t
>> understand the corresponding ChangeLog description.
> 
> Yeah.  I just copied this part from the 2014 patch and didn't spot that.
> 
>>> +    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.* ligfortran.a .*conftest2.$ac_objext" \
>> 
>> s/ligfortran.a/libgfortran.a/
> 
> Indeed.  Also removed the space before libgfortran.a because I'm not sure if
> it won't have because of the %s full path in front of that.
> This is Darwin only stuff.
> I must say I don't know if even this elif ... LQUADMATH part is needed,
> maybe replace-outfile will rename even the -lquadmath from the spec file.
> 
> Here is an updated version (but nothing relevant to Linux changed, so there
> is no point for me to bootstrap/regtest it again):
> 
> 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.c (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.c (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.
> 
> --- gcc/common.opt.jj	2022-06-27 11:18:02.050066582 +0200
> +++ gcc/common.opt	2022-08-16 14:51:04.611673800 +0200
> @@ -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
> 
> --- gcc/gcc.cc.jj	2022-08-11 09:57:24.765334380 +0200
> +++ gcc/gcc.cc	2022-08-16 14:57:54.708327024 +0200
> @@ -4585,12 +4585,14 @@ 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_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;
> 
> --- gcc/config/darwin.h.jj	2022-08-16 14:51:14.529544492 +0200
> +++ gcc/config/darwin.h	2022-08-16 14:53:54.402460097 +0200
> @@ -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)}\
> --- gcc/fortran/lang.opt.jj	2022-02-04 14:36:55.050604670 +0100
> +++ gcc/fortran/lang.opt	2022-08-16 14:52:52.459267705 +0200
> @@ -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.
> --- gcc/fortran/options.cc.jj	2022-01-18 11:58:59.568982256 +0100
> +++ gcc/fortran/options.cc	2022-08-16 14:56:22.807525218 +0200
> @@ -692,6 +692,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

I think that this will disable the option on Darwin (where the linker does not
support Bstatic/dynamic)  - the point of the specs outfile substitution is to work
for such platforms.  So long as the option is not stripped out by the driver, the
specs substitution should work (there is a bug in the g++ driver where this is
not happening properly for -static-libstdc++ - but the gdc driver has it right).

Iain

> +      break;
> +
>     case OPT_fintrinsic_modules_path:
>     case OPT_fintrinsic_modules_path_:
> 
> --- gcc/fortran/invoke.texi.jj	2022-05-09 09:09:20.312473272 +0200
> +++ gcc/fortran/invoke.texi	2022-08-16 16:12:47.638203577 +0200
> @@ -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
> --- libgfortran/acinclude.m4.jj	2022-06-29 17:05:45.478790781 +0200
> +++ libgfortran/acinclude.m4	2022-08-16 16:06:50.047814043 +0200
> @@ -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
> --- libgfortran/configure.jj	2022-06-29 17:05:45.483790716 +0200
> +++ libgfortran/configure	2022-08-16 16:06:54.119761574 +0200
> @@ -30323,14 +30323,34 @@ fi
> { $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
> 
> 
> 	Jakub
> 


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

* Re: [PATCH] fortran, v2: Add -static-libquadmath support [PR46539]
  2022-08-18 10:35     ` Iain Sandoe
@ 2022-08-18 10:41       ` Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2022-08-18 10:41 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Mikael Morin, GCC Patches, GCC Fortran

On Thu, Aug 18, 2022 at 11:35:06AM +0100, Iain Sandoe wrote:
> > --- gcc/fortran/options.cc.jj	2022-01-18 11:58:59.568982256 +0100
> > +++ gcc/fortran/options.cc	2022-08-16 14:56:22.807525218 +0200
> > @@ -692,6 +692,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
> 
> I think that this will disable the option on Darwin (where the linker does not
> support Bstatic/dynamic)  - the point of the specs outfile substitution is to work
> for such platforms.  So long as the option is not stripped out by the driver, the
> specs substitution should work (there is a bug in the g++ driver where this is
> not happening properly for -static-libstdc++ - but the gdc driver has it right).

It does the same thing as OPT_static_libgfortran and that option
presumably isn't disabled on Darwin.

My guess is that this is just dead code and could be removed for both
options, I think gfc_handle_option is only in f951 program, and the
-static-lib* options are driver only, not passed to the compiler.

Note, for other options like -static-libstdc++, we also don't reject them
if HAVE_LD_STATIC_DYNAMIC isn't defined.

	Jakub


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

end of thread, other threads:[~2022-08-18 10:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 14:31 [PATCH] fortran: Add -static-libquadmath support [PR46539] Jakub Jelinek
2022-08-17  7:19 ` Jakub Jelinek
2022-08-17  7:55 ` Tobias Burnus
2022-08-17  8:28 ` Mikael Morin
2022-08-17 11:05   ` [PATCH] fortran, v2: " Jakub Jelinek
2022-08-18 10:35     ` Iain Sandoe
2022-08-18 10:41       ` Jakub Jelinek

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).