diff mbox

[libgfortran,build] Use -z ignore instead of --as-needed on Solaris

Message ID yddli7h39uv.fsf@lokon.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth May 14, 2013, 2:38 p.m. UTC
As requested by Tobias, this patch supports -z ignore with Solaris ld
instead of GNU ld's --as-needed.

i386-pc-solaris2.10 and x86_64-unknown-linux-gnu bootstraps are still
running.  In both cases, the correct options were detected and written
into libgfortran.spec.  AFAICS the -static-libgfortran option isn't
exercised anywhere in the testsuite, so I've both relinked one of the
gfortran.dg testcases and a trivial FORTRAN hello world program with
-static-libgfortran.  -z ignore/--as-needed is passed correctly in both
cases, but while libgfortran is now linked statically, libquadmath.so is
still dragged in due to references to at least quadmath_snprintf.  I
thus can't tell if this --as-needed/-z ignore stuff ever does any good.

Ok for mainline if testing passes?

Thanks.
        Rainer


2013-05-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* acinclude.m4 (libgfor_cv_have_as_needed): Check for -z ignore, too.
	* configure: Regenerate.

Comments

Tobias Burnus May 14, 2013, 3:44 p.m. UTC | #1
Rainer Orth wrote:
> As requested by Tobias, this patch supports -z ignore with Solaris ld
> instead of GNU ld's --as-needed.

For reference, my request was motivated by 
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00425.html
(The patch has been approved, but it does not seem to be in, yet.)

> i386-pc-solaris2.10 and x86_64-unknown-linux-gnu bootstraps are still
> running.  In both cases, the correct options were detected and written
> into libgfortran.spec.  AFAICS the -static-libgfortran option isn't
> exercised anywhere in the testsuite, so I've both relinked one of the
> gfortran.dg testcases and a trivial FORTRAN hello world program with
> -static-libgfortran.  -z ignore/--as-needed is passed correctly in both
> cases, but while libgfortran is now linked statically, libquadmath.so is
> still dragged in due to references to at least quadmath_snprintf.  I
> thus can't tell if this --as-needed/-z ignore stuff ever does any good.

Well, it kind of works - but seemingly not fully. If I use:
    print *, "Hello World"; end
with -static-libgfortran, I get ("nm a.out"):
                  w quadmath_snprintf@@QUADMATH_1.0

While using a quad-precision variable, e.g.,
    print *, 123.4_16; end
gives
                  U quadmath_snprintf@@QUADMATH_1.0

I don't know whether one could do better.

  * * *

+      # Test for native Solaris options first.

Is there a reason that you first test the Solaris's options?



+      # No whitespace after -z to pass it through -Wl.

(By the way, you can use "-Wl,-z,ignore" if you want to have the space. 
For the purpose of this patch, the space doesn't matter.)

> Ok for mainline if testing passes?

Looks fine to me - I don't know whether a build maintainer has still a 
comment.

Tobias

> 2013-05-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
> 	* acinclude.m4 (libgfor_cv_have_as_needed): Check for -z ignore, too.
> 	* configure: Regenerate.
Rainer Orth May 15, 2013, 11:06 a.m. UTC | #2
Hi Tobias,

> Rainer Orth wrote:
>> As requested by Tobias, this patch supports -z ignore with Solaris ld
>> instead of GNU ld's --as-needed.
>
> For reference, my request was motivated by
> http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00425.html
> (The patch has been approved, but it does not seem to be in, yet.)

the patch went in shortly after Paolo's approval, followed recently by
another one to fix major fallout.  The latter prompted me to wait until
I tackle this one...

>> i386-pc-solaris2.10 and x86_64-unknown-linux-gnu bootstraps are still
>> running.  In both cases, the correct options were detected and written
>> into libgfortran.spec.  AFAICS the -static-libgfortran option isn't
>> exercised anywhere in the testsuite, so I've both relinked one of the
>> gfortran.dg testcases and a trivial FORTRAN hello world program with
>> -static-libgfortran.  -z ignore/--as-needed is passed correctly in both
>> cases, but while libgfortran is now linked statically, libquadmath.so is
>> still dragged in due to references to at least quadmath_snprintf.  I
>> thus can't tell if this --as-needed/-z ignore stuff ever does any good.
>
> Well, it kind of works - but seemingly not fully. If I use:
>    print *, "Hello World"; end
> with -static-libgfortran, I get ("nm a.out"):
>                  w quadmath_snprintf@@QUADMATH_1.0
>
> While using a quad-precision variable, e.g.,
>    print *, 123.4_16; end
> gives
>                  U quadmath_snprintf@@QUADMATH_1.0

Still the effect is the same: both binaries depend on libquadmath.so.
TBH, I don't know why the use of --as-needed/-z ignore should depend on
-static-libgfortran at all.

> I don't know whether one could do better.

If there are no scenarios where this machinery avoids the libquadmath.so
dependency completely, I don't really see a good use for.

> +      # Test for native Solaris options first.
>
> Is there a reason that you first test the Solaris's options?

Yes: Solaris ld from Solaris 11 onwards (sometimes backported to Solaris
10) has gained support for gld options for compatibility.  --as-needed
isn't among the supported ones yet, but there's an open bug for that.

I think it's better to stay with the native options if possible, so I
prefer the Solaris ones over the GNU compatiblity ones.

> +      # No whitespace after -z to pass it through -Wl.
>
> (By the way, you can use "-Wl,-z,ignore" if you want to have the space. For
> the purpose of this patch, the space doesn't matter.)

I know.

>> Ok for mainline if testing passes?
>
> Looks fine to me - I don't know whether a build maintainer has still a
> comment.

Testing has passed successfully now on both targets.

	Rainer


>> 2013-05-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>>
>> 	* acinclude.m4 (libgfor_cv_have_as_needed): Check for -z ignore, too.
>> 	* configure: Regenerate.
Rainer Orth May 23, 2013, 1:37 p.m. UTC | #3
Hi Tobias,

>> Rainer Orth wrote:
>>> As requested by Tobias, this patch supports -z ignore with Solaris ld
>>> instead of GNU ld's --as-needed.
>>
>> For reference, my request was motivated by
>> http://gcc.gnu.org/ml/gcc-patches/2013-04/msg00425.html
>> (The patch has been approved, but it does not seem to be in, yet.)
>
> the patch went in shortly after Paolo's approval, followed recently by
> another one to fix major fallout.  The latter prompted me to wait until
> I tackle this one...
>
>>> i386-pc-solaris2.10 and x86_64-unknown-linux-gnu bootstraps are still
>>> running.  In both cases, the correct options were detected and written
>>> into libgfortran.spec.  AFAICS the -static-libgfortran option isn't
>>> exercised anywhere in the testsuite, so I've both relinked one of the
>>> gfortran.dg testcases and a trivial FORTRAN hello world program with
>>> -static-libgfortran.  -z ignore/--as-needed is passed correctly in both
>>> cases, but while libgfortran is now linked statically, libquadmath.so is
>>> still dragged in due to references to at least quadmath_snprintf.  I
>>> thus can't tell if this --as-needed/-z ignore stuff ever does any good.
>>
>> Well, it kind of works - but seemingly not fully. If I use:
>>    print *, "Hello World"; end
>> with -static-libgfortran, I get ("nm a.out"):
>>                  w quadmath_snprintf@@QUADMATH_1.0
>>
>> While using a quad-precision variable, e.g.,
>>    print *, 123.4_16; end
>> gives
>>                  U quadmath_snprintf@@QUADMATH_1.0
>
> Still the effect is the same: both binaries depend on libquadmath.so.
> TBH, I don't know why the use of --as-needed/-z ignore should depend on
> -static-libgfortran at all.
>
>> I don't know whether one could do better.
>
> If there are no scenarios where this machinery avoids the libquadmath.so
> dependency completely, I don't really see a good use for.
>
>> +      # Test for native Solaris options first.
>>
>> Is there a reason that you first test the Solaris's options?
>
> Yes: Solaris ld from Solaris 11 onwards (sometimes backported to Solaris
> 10) has gained support for gld options for compatibility.  --as-needed
> isn't among the supported ones yet, but there's an open bug for that.
>
> I think it's better to stay with the native options if possible, so I
> prefer the Solaris ones over the GNU compatiblity ones.
>
>> +      # No whitespace after -z to pass it through -Wl.
>>
>> (By the way, you can use "-Wl,-z,ignore" if you want to have the space. For
>> the purpose of this patch, the space doesn't matter.)
>
> I know.
>
>>> Ok for mainline if testing passes?
>>
>> Looks fine to me - I don't know whether a build maintainer has still a
>> comment.
>
> Testing has passed successfully now on both targets.

how should we proceed with this patch now, given the questions above?
Install as is, although it doesn't seem really beneficial, or drop it?

Thanks.
        Rainer


>>> 2013-05-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>>>
>>> 	* acinclude.m4 (libgfor_cv_have_as_needed): Check for -z ignore, too.
>>> 	* configure: Regenerate.
Tobias Burnus May 23, 2013, 8:11 p.m. UTC | #4
Hi Rainer,

Rainer Orth wrote:
> how should we proceed with this patch now, given the questions above? 
> Install as is, although it doesn't seem really beneficial, or drop it?

I would install it. Actually, did you get a libquadmath dependence on 
Solaris or not?

On Linux - or to be more precise: with binutils newer than 2013-03-18 - 
you also shouldn't get a dependence. See 
http://sourceware.org/bugzilla/show_bug.cgi?id=12549 for details.

Tobias
Rainer Orth May 24, 2013, 9:09 a.m. UTC | #5
Hi Tobias,

> Rainer Orth wrote:
>> how should we proceed with this patch now, given the questions above?
>> Install as is, although it doesn't seem really beneficial, or drop it?
>
> I would install it. Actually, did you get a libquadmath dependence on
> Solaris or not?

I do, both with Solaris ld and gld 2.23.1.

> On Linux - or to be more precise: with binutils newer than 2013-03-18 - 
> you also shouldn't get a dependence. See
> http://sourceware.org/bugzilla/show_bug.cgi?id=12549 for details.

No wonder I do see the dependency even on Linux: I usually only test
with binutils releases, and that patch will only show up in gld 2.24.

Ok, I'll go ahead and install the patch since it certainly does no harm.

	Rainer
diff mbox

Patch

# HG changeset patch
# Parent 552725704163412331462fc576619c0e82697a9a
 Use -z ignore instead of --as-needed on Solaris

diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -296,7 +296,7 @@  AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
   if test "x$libgfor_cv_have_float128" = xyes; then
     AC_DEFINE(HAVE_FLOAT128, 1, [Define if have a usable __float128 type.])
 
-    dnl Check whether -Wl,--as-needed is supported
+    dnl Check whether -Wl,--as-needed resp. -Wl,-zignore is supported
     dnl 
     dnl Turn warnings into error to avoid testsuite breakage.  So enable
     dnl AC_LANG_WERROR, but there's currently (autoconf 2.64) no way to turn
@@ -304,23 +304,39 @@  AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
     dnl AC_PATH_XTRA.
     dnl Cf. http://gcc.gnu.org/ml/gcc-patches/2010-05/msg01889.html
     ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag=$ac_[]_AC_LANG_ABBREV[]_werror_flag
-    AC_CACHE_CHECK([whether --as-needed works],
+    AC_CACHE_CHECK([whether --as-needed/-z ignore works],
       [libgfor_cv_have_as_needed],
       [
+      # Test for native Solaris options first.
+      # No whitespace after -z to pass it through -Wl.
+      libgfor_cv_as_needed_option="-zignore"
+      libgfor_cv_no_as_needed_option="-zrecord"
       save_LDFLAGS="$LDFLAGS"
-      LDFLAGS="$LDFLAGS -Wl,--as-needed -lm -Wl,--no-as-needed"
+      LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
       libgfor_cv_have_as_needed=no
       AC_LANG_WERROR
       AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
 		     [libgfor_cv_have_as_needed=yes],
 		     [libgfor_cv_have_as_needed=no])
       LDFLAGS="$save_LDFLAGS"
+      if test "x$libgfor_cv_have_as_needed" = xno; then
+	libgfor_cv_as_needed_option="--as-needed"
+	libgfor_cv_no_as_needed_option="--no-as-needed"
+	save_LDFLAGS="$LDFLAGS"
+	LDFLAGS="$LDFLAGS -Wl,$libgfor_cv_as_needed_option -lm -Wl,$libgfor_cv_no_as_needed_option"
+	libgfor_cv_have_as_needed=no
+	AC_LANG_WERROR
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
+		       [libgfor_cv_have_as_needed=yes],
+		       [libgfor_cv_have_as_needed=no])
+	LDFLAGS="$save_LDFLAGS"
+      fi
       ac_[]_AC_LANG_ABBREV[]_werror_flag=$ac_xsave_[]_AC_LANG_ABBREV[]_werror_flag
     ])
 
     dnl For static libgfortran linkage, depend on libquadmath only if needed.
     if test "x$libgfor_cv_have_as_needed" = xyes; then
-      LIBQUADSPEC="%{static-libgfortran:--as-needed} -lquadmath %{static-libgfortran:--no-as-needed}"
+      LIBQUADSPEC="%{static-libgfortran:$libgfor_cv_as_needed_option} -lquadmath %{static-libgfortran:$libgfor_cv_no_as_needed_option}"
     else
       LIBQUADSPEC="-lquadmath"
     fi