diff mbox

Additional RFC, Re: RFC automatic linkage of libquadmath with gfortran: PR driver/46516; libgfortran.spec, multilib search path

Message ID 8F247BFC-9228-4058-A27A-6EA907FA9BBA@sandoe-acoustics.co.uk
State New
Headers show

Commit Message

Iain Sandoe Nov. 25, 2010, 11:11 a.m. UTC
Hello all...

On 22 Nov 2010, at 07:28, Tobias Burnus wrote:

> On 11/22/2010 12:07 AM, Michael Matz wrote:
>> I have another improvement here.  I'm regularly testing uninstalled
>> compilers (or compilers installed in temp paths).  This exposed a  
>> problem
>> in that the .spec file is only found when the proper -L option is  
>> given
>> (that's okay), which it usually isn't for non-linking commands.  In  
>> that
>> case lang_specific_pre_link is nevertheless called, tries to include
>> libgfortran.spec and fails.  Hence, let's remember if we're in a  
>> non-link
>> run, and not do anything with that .spec file.
>>
>> Regstrapping on x86_64-linux in progress.  Okay if that passes?
>
> OK. Thanks for the patch!

I have some requested additions (for Darwin), but also some  
observations/suggestions...

Firstly, when one hijacks *lib, it means that the target has no chance  
to do spec substitutions/outfile removal
-- this is because the new libs are added after "output files" have  
been evaluated in the LINK_COMMAND.
-- because libs are not treated as switches, one cannot switch on them  
either 

So that means that we must ensure:
(a) that we don't add any libs that the target doesn't want
(b) if there are any substitutions, unfortunately they need to appear  
in the libgfortran spec - since we can't hide them away in the target  
LINK_COMMAND

      if test -f ../libquadmath/libquadmath.la; then
        LIBQUADLIB=../libquadmath/libquadmath.la


====

Thoughts? OK for trunk?
(tested on *-darwin9, and x86_64-unk-linux)
cheers,
Iain
diff mbox

Patch

====

Firstly, I wonder if it would be better to hijack the   
"*link_gcc_c_sequence" rather than "*lib"
(this means that the correct link sequence for libgcc/lc will follow  
directly after the libgfortran/libquadmath sequence .
... which also means one doesn't have to embed any differences in the  
way targets make that sequence)

like this:

===================================================================
--- libgfortran/libgfortran.spec.in	(revision 167142)
+++ libgfortran/libgfortran.spec.in	(working copy)
@@ -2,7 +2,10 @@ 
  # This spec file is read by gfortran when linking.
  # It is used to specify the libraries we need to link in, in the right
  # order.
-#

-%rename lib liborig
-*lib: @LIBQUADSPEC@ -lm %(libgcc) %(liborig)
+# Hijack the link sequence for libgcc and lc so that we can interpose
+# the quad math and system math libs just before it. This also works  
for
+# targets that only link lgcc once.
+
+%rename link_gcc_c_sequence link_gcc_c_sequence_orig
+*link_gcc_c_sequence: @LIBQUADSPEC@ @LIBMSPEC@ % 
(link_gcc_c_sequence_orig)


If that's not OK - then we need to suppress the additional %(libgcc)  
for darwin too.

NOTE;  I think that if we do this we can lose all the libm agonizing  
from gfortranspec.c - because the libgfortan.spec will automatically  
place "-lm" just before the libgcc/lc sequence for targets that  
require it.
(If the user inserts a '-lm' by hand we should just pass that through  
-  on the assumption that the user knows what (s)he is doing).

-----

Secondly to cater for  Darwin (and any other target that doesn't want - 
lm unconditionally);
(plus our spec substitution for the static case)

Index: libgfortran/configure.ac
===================================================================
--- libgfortran/configure.ac	(revision 167142)
+++ libgfortran/configure.ac	(working copy)
@@ -515,6 +515,17 @@  else
    multilib_arg=
  fi

+# Allow for targets which don't need/want -lm.
+case "${host}" in
+  *-darwin*)
+    LIBMSPEC=
+    ;;
+  *)
+    LIBMSPEC="-lm"
+    ;;
+esac
+AC_SUBST(LIBMSPEC)
+
  # Write our Makefile and spec file.
  AC_CONFIG_FILES([
  Makefile

Index: libgfortran/acinclude.m4
===================================================================
--- libgfortran/acinclude.m4	(revision 167142)
+++ libgfortran/acinclude.m4	(working copy)
@@ -329,7 +329,10 @@  AC_DEFUN([LIBGFOR_CHECK_FLOAT128], [
      if test "x$libgfor_cv_have_as_needed" = xyes; then
        LIBQUADSPEC="%{static-libgfortran:--as-needed} -lquadmath % 
{static-libgfortran:--no-as-needed}"
      else
-      LIBQUADSPEC="-lquadmath"
+      case "${target}" in
+        *86*-*-darwin*) LIBQUADSPEC="%{static|static-libgcc|static- 
libgfortran: libquadmath.a%s; : -lquadmath}" ;;
+        *) LIBQUADSPEC="-lquadmath" ;;
+      esac
      fi