Bug 46539 - libquadmath: Add -static-libquadmath
Summary: libquadmath: Add -static-libquadmath
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Francois-Xavier Coudert
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-18 12:58 UTC by Tobias Burnus
Modified: 2022-08-20 19:20 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-10-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2010-11-18 12:58:38 UTC
One should add such a flag. For some systems such as Darwin, it needs more changes than to the general argument handling (gcc/gcc.c?)

Cf. http://gcc.gnu.org/ml/fortran/2010-11/msg00273.html
Comment 1 Tobias Burnus 2010-11-25 11:22:08 UTC
cf. http://gcc.gnu.org/ml/fortran/2010-11/msg00348.html
Comment 2 Arnaud Desitter 2012-03-22 16:40:41 UTC
I hit this problem. For the application I am dealing with, I need to link statically the compiler provided libraries while linking dynamically the system ones (pthread, mpi, etc.).

Linking with "gfortran -static-libgfortran -static-libgcc -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic" solves the problem except for "libquadmath.so.0".

Linking with "-Wl,-Bstatic -lquadmath -Wl,-Bdynamic" does not help.

The only workaround I found is to configure gcc with "configure --disable-libquadmath-support".

Could you please implement "-static-libquadmath" or make "-Wl,-Bstatic -lquadmath -Wl,-Bdynamic" work?
Comment 3 Tobias Burnus 2012-03-22 17:31:41 UTC
(In reply to comment #2)
> I hit this problem. For the application I am dealing with, I need to link
> statically the compiler provided libraries while linking dynamically the system
> ones (pthread, mpi, etc.).
> 
> Linking with "gfortran -static-libgfortran -static-libgcc -Wl,-Bstatic -lstdc++
> -Wl,-Bdynamic" solves the problem except for "libquadmath.so.0".

Work arounds:

You could try to link with "gcc" rather than with gfortran, but you then need to explicitly include the gfortran, quadmath and m(ath) library:

  gcc -static-libgcc -Wl,-Bstatic -lstdc++ -lgfortran -lquadmath -Wl,-Bdynamic -lm

as that avoids "gfortran"'s special treatment of libquadmath. [You might consider to add -Wl,--as-needed ... -Wl,--no-as-needed. That avoids linking files when they are not needed.]


An alternative is to modify libgfortran.spec - and add there the "-Bstatic" ... "-Bdynamic" unconditionally. Or you create your own .spec file and load it via -specs=<filename>   (The "libgfortran.spec" file is a text file in the installed GCC tree; e.g. it could be <prefix>/lib*/libgfortran.spec. If you use GCC/gfortran with "-v" the output should inform you about which file has been read - and how the linker is called.)
Comment 4 Arnaud Desitter 2012-03-28 10:05:29 UTC
Thanks for the workarounds. 

For information, the Intel Fortran compiler has "-static-intel" which links statically Intel provided libraries. Such option may be un-practical for gcc.
Comment 5 Francois-Xavier Coudert 2014-10-04 13:52:14 UTC
Patch proposed here: https://gcc.gnu.org/ml/gcc-patches/2014-10/msg00375.html
Comment 6 Andrew B 2020-02-02 07:55:57 UTC
It would be great to be able to share a binary with just operating system supplied dynamic libraries. After reading posts about it and looking at otool -L, it seems like this is what is needed.
Comment 7 GCC Commits 2022-08-17 15:03:47 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:745be54bd6634fe63d6be83615e264c83d2ae9f9

commit r13-2094-g745be54bd6634fe63d6be83615e264c83d2ae9f9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Aug 17 17:00:33 2022 +0200

    fortran: Add -static-libquadmath support [PR46539]
    
    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 wrapped, but
    analyzes gfortran -### -static-libgfortran stderr and based on
    that figures out what gcc/configure.ac determined.
    
    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.cc (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.cc (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.
    
    Co-Authored-By: Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Comment 8 Jakub Jelinek 2022-08-17 15:08:56 UTC
Implemented now on the trunk.
Comment 9 GCC Commits 2022-08-20 19:20:47 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:dd899c7de36d19ddf18e3bfab4a0c150096e2368

commit r13-2129-gdd899c7de36d19ddf18e3bfab4a0c150096e2368
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Aug 20 21:20:04 2022 +0200

    fortran: Drop -static-lib{gfortran,quadmath} from f951 [PR46539]
    
    As discussed earlier, all other -static-lib* options are Driver only,
    these 2 are Driver in common.opt and Fortran in lang.opt.
    
    The spec files never pass the -static-lib* options down to any compiler
    (f951 etc.), so the 2 errors below are reported only when one
    runs ./f951 -static-libgfortran by hand.
    
    The following patch just removes f951 support of these options, the
    gfortran driver behavior remains as before.  For other -static-lib*
    option (and even these because it is never passed to f951) we never
    error if we can't support those options, and e.g. Darwin is actually
    able to handle those options through other means.
    
    2022-08-20  Jakub Jelinek  <jakub@redhat.com>
    
            PR fortran/46539
            * lang.opt (static-libgfortran, static-libquadmath): Change Fortran
            to Driver.
            * options.cc (gfc_handle_option): Don't handle OPT_static_libgfortran
            nor OPT_static_libquadmath here.