Subject: _LT_SYS_HIDDEN_LIBDEPS oddities with Fortran

From: Christian Feld <[email-masked]>
Date: Mon, 10 Feb 2025 10:53:07 +0000

Dear libtoolers,

my project uses C, C++, Fortran 77. One library consists of mixed CC and 
F77 sources. I intend to switch to more modern Fortran (FC) for this 
library.

Linking this library with F77LINK worked well. Switching to FCLINK 
causes errors for some compilers due to broken postedeps_FC.

  - For HPE Cray PrgEnv-cray's ftn, postedeps_FC contains '... -L -L 
...'.
  - For HPE Cray PrgEnv-gnu's ftn, OpenMPI's and MPICH's mpifort 
(delegating to gfortran), postedeps_FC contains '... -l -l ...'.

During investigating the cause of the broken postdeps_FC, several 
questions arose.

1. Why do we have postdeps for CXX and FC, but not for CC and F77?  
_LT_SYS_HIDDEN_LIBDEPS is expanded in _LT_LANG_CXX_CONFIG and 
_LT_LANG_FC_CONFIG only.

2. Why do we need postdeps at all? Isn't the compiler supposed to do 
just the right thing?

3. Without a C++ compiler (AC_PROG_CXX), postedeps_FC is always empty, 
as output_verbose_link_cmd, the command producing the input to determine 
the postdeps, is set in _LT_LANG_CXX_CONFIG only. If this is coupling 
intended, can you please explain why?

Now, where do the bogus `... -L -L ...` and `... -l -l ...` come from? 
The output_verbose_link_cmd used for CXX and FC postdeps is
     '$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v 
"^Configured with:" | $GREP " [[-]]L"'
For the compilers mentioned above, the output of this command contains a 
line starting with 'Driving:', e.g.,

Driving: 
/p/software/jedi/stages/2025/software/GCCcore/13.3.0/bin/gfortran 
-shared -g -O2 -v conftest.o 
-I/p/software/default/stages/2025/software/OpenMPI/5.0.5-GCC-13.3.0/include 
-I/p/software/default/stages/2025/software/OpenMPI/5.0.5-GCC-13.3.0/lib 
-L/p/software/default/stages/2025/software/OpenMPI/5.0.5-GCC-13.3.0/lib 
-Wl,-rpath 
-Wl,/p/software/default/stages/2025/software/OpenMPI/5.0.5-GCC-13.3.0/lib 
-Wl,--enable-new-dtags -lmpi_usempif08 -lmpi_usempi_ignore_tkr 
-lmpi_mpifh -lmpi -l gfortran -l m -shared-libgcc

The part '-l gfortran -l m' results in '... -l -l ...'

Lines starting with 'Configured with:' are already omitted in 
output_verbose_link_cmd. Omitting lines starting with 'Driving:'  as 
well would fix the invalid postdeps_FC. Note that autoconf's 
_AC_PROG_FC_V_OUTPUT also omits both, '^Driving:' and '^Configured 
with:', see [1].

A patch omitting lines '^Driving:'  is attached. But do we need to 
expand _LT_SYS_HIDDEN_LIBDEPS for FC at all?

Thanks,
Christian

[1] 
https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob;f=lib/autoconf/fortran.m4;h=cdc197bd67f4abab036cfe6a3a59d16aa712a386;hb=6199cff2909e0ac84c9391aa49ed097d6a33268d#l514

diff --git a/m4/libtool.m4 b/m4/libtool.m4
index c0d19e45..30e89563 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -6588,7 +6588,7 @@ if test yes != "$_lt_caught_CXX_error"; then
       # Commands to make compiler produce verbose output that lists
       # what "hidden" libraries, object files and flags are used when
       # linking a shared library.
-      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"'
+      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP -v "^Driving:" | $GREP " [[-]]L"'
 
     else
       GXX=no
@@ -7373,7 +7373,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	      # Commands to make compiler produce verbose output that lists
 	      # what "hidden" libraries, object files and flags are used when
 	      # linking a shared library.
-	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"'
+	      output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP -v "^Driving:" | $GREP " [[-]]L"'
 
 	    else
 	      # FIXME: insert proper C++ library support
@@ -7460,7 +7460,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"'
+	        output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP -v "^Driving:" | $GREP " [[-]]L"'
 	      else
 	        # g++ 2.7 appears to require '-G' NOT '-shared' on this
 	        # platform.
@@ -7471,7 +7471,7 @@ if test yes != "$_lt_caught_CXX_error"; then
 	        # Commands to make compiler produce verbose output that lists
 	        # what "hidden" libraries, object files and flags are used when
 	        # linking a shared library.
-	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP " [[-]]L"'
+	        output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP -v "^Driving:" | $GREP " [[-]]L"'
 	      fi
 
 	      _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir'