Bug 31400 - enable static linking of support libraries through -static-libXY
Summary: enable static linking of support libraries through -static-libXY
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2007-03-30 13:14 UTC by Daniel Franke
Modified: 2017-11-14 13:00 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-05-07 12:18:33


Attachments
check for -static in lookup_option. (442 bytes, patch)
2010-04-09 19:04 UTC, Iain Sandoe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2007-03-30 13:14:23 UTC
To deploy testing versions of applications built with (yet unreleased) versions of gcc may be difficult due to linked in libraries as libgfortran and libgomp.

Similar to -static-libgcc, options like -static-libgfortran or -static-libgomp would help to avoid problems. Especially for libgomp, one can not simply use LDFLAGS=-static as libgomp pulls in libpthread and static linking is not supported with libpthread (see PR30471, PR30613).
Comment 1 H.J. Lu 2007-03-30 15:47:52 UTC
You may want to look at

http://gcc.gnu.org/ml/gcc/2005-12/msg00783.html
Comment 2 Andrew Pinski 2007-03-30 16:22:53 UTC
In general this is wrong.  There are reasons why you don't want static linking.  code size/memory usage is one of them.
Comment 3 Daniel Franke 2007-03-30 16:30:07 UTC
Andrew, I agree that static linking should not be overused. But there are valid cases where one may want to do it anyway. Deploying a testing application may be one of them. Asking the user to compile gcc from scratch just to get the latest libraries is usually not an option. Delivering a bunch of libraries together with the binary may mess up the customers system, especially if it is a test-and-discard like approach.

Given the two PRs I cited plus the thread H. J. pointed out, there are people looking for options like the ones requested here.
Comment 4 Francois-Xavier Coudert 2007-04-18 18:48:47 UTC
I certainly agree that we should have an option to ask the driver to link libgfortran statically.
Comment 5 Francois-Xavier Coudert 2007-06-14 12:13:28 UTC
Still pinging for someone to review my one-line patch to gcc.c... maybe we can get this feature into trunk before GCC 12.0 ;-)
Comment 6 Francois-Xavier Coudert 2007-06-27 22:58:49 UTC
Subject: Bug 31400

Author: fxcoudert
Date: Wed Jun 27 22:58:37 2007
New Revision: 126068

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126068
Log:
	PR other/31400

	* gcc.c (process_command): Recognize the new -static-libgfortran
	option.

	* lang.opt (static-libgfortran): New option.
	* gfortranspec.c (ADD_ARG_LIBGFORTRAN): New macro.
	(Option): Add OPTION_static and OPTION_static_libgfortran.
	(lookup_option): Handle the new -static-libgfortran option.
	(lang_specific_driver): Check whether -static is passed.
	Handle the new -static-libgfortran option.
	* options.c (gfc_handle_option): If -static-libgfortran is
	passed and isn't supported on this configuration, error out.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortranspec.c
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/options.c
    trunk/gcc/gcc.c

Comment 7 Francois-Xavier Coudert 2007-06-27 23:00:22 UTC
Fixed on mainline.
Comment 8 Daniel Franke 2007-06-28 07:00:30 UTC
FX, thanks for your patch :)

As libgfortran is one of many, at least -static-libgomp would be nice to have as well (others?). Reopening, so the request is not lost.
Comment 9 H.J. Lu 2008-06-17 18:16:17 UTC
I can contribute a patch for -static-libc++/-static-libstdc++.
Comment 10 Daniel Franke 2009-08-06 19:54:49 UTC
-static-libstdc++ was added for 4.5.0 (thanks!):
2009-06-25  Ian Lance Taylor  <iant@google.com>

        * g++spec.c (SKIPOPT): define.
        (lang_specific_driver): Handle -static-libstdc++.  Only add
        LIBSTDCXX_STATIC if we add LIBSTDCXX.

Any chance to ever get -static-libgomp? Otherwise this PR can probably be closed?!
Comment 11 Jakub Jelinek 2010-04-09 17:05:16 UTC
The http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126068
patch adds OPTION_static, but nothing ever returns that value, so the code setting static_linking is clearly dead code.  That couldn't be the intent.
Comment 12 Iain Sandoe 2010-04-09 17:42:16 UTC
(In reply to comment #11)
> The http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126068
> patch adds OPTION_static, but nothing ever returns that value, so the code
> setting static_linking is clearly dead code.  That couldn't be the intent.

indeed:
how about this? (tested on ia32-pc-linux)

Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c	(revision 158167)
+++ gcc/fortran/gfortranspec.c	(working copy)
@@ -186,6 +186,8 @@ lookup_option (Option *xopt, int *xskip, const cha
 	opt = OPTION_syntax_only;
       else if (!strcmp (text, "-static-libgfortran"))
 	opt = OPTION_static_libgfortran;
+      else if (!strcmp (text, "-static"))
+	opt = OPTION_static;
       else if (!strcmp (text, "-fversion"))	/* Really --version!! */
 	opt = OPTION_version;
       else if (!strcmp (text, "-Xlinker") || !strcmp (text, "-specs"))
@@ -351,8 +353,7 @@ lang_specific_driver (int *in_argc, const char *co
 #ifdef HAVE_LD_STATIC_DYNAMIC
 	  static_linking = 1;
 #endif
-	  /* Fall through, count OPTION_static as an item included in
-	     the rewritten command line. */
+	  break;
 
 	case OPTION_l:
 	  ++n_infiles;


Comment 13 Iain Sandoe 2010-04-09 19:04:54 UTC
Created attachment 20349 [details]
check for -static in lookup_option.


	PR bootstrap/31400
	* gfortranspec.c (lookup_option): Check for -static and return
	OPTION_static.
	(lang_specific_driver): Break when OPTION_static is discovered.
Comment 14 Iain Sandoe 2010-04-09 19:06:50 UTC
(In reply to comment #10)

> Any chance to ever get -static-libgomp? Otherwise this PR can probably be
> closed?!

On Darwin - I made it so that if -static-* is given for {stdc++,cc, fortran} the specs cause a substitution for static libgomp.  Would that work for you?

Comment 15 Daniel Franke 2010-04-09 21:04:24 UTC
(In reply to comment #14)
> On Darwin - I made it so that if -static-* is given for {stdc++,cc, fortran}
> the specs cause a substitution for static libgomp.  Would that work for you?

Iain, I can't say as I can't parse your statement?! Could you elaborate a bit?
Thanks.
Comment 16 Iain Sandoe 2010-04-09 21:19:35 UTC
(In reply to comment #15)
> (In reply to comment #14)
> > On Darwin - I made it so that if -static-* is given for {stdc++,cc, fortran}
> > the specs cause a substitution for static libgomp.  Would that work for you?
> 
> Iain, I can't say as I can't parse your statement?! Could you elaborate a bit?
> Thanks.

Sorry ;) - specs processing.

It's possible to detect that "-static-libgfortran" has been given on the command line and cause that to substitute libgomp.a instead of libgomp.so.

I arranged that this would happen on darwin if any of libgcc, libstdc++ or libgfortran were made static  (for reasons of unwind symbol consistency, rather than to satisfy a requirement for static-libgomp).

I think it's more difficult to approach libgomp directly - since it doesn't "belong" to any specific language - therefore whatever changes you effect to it need to be coordinated between all FEs.

Having said that, there was a comment made that libgomp.spec might be "going away".

Does that help?
Comment 17 Daniel Franke 2010-04-09 21:28:09 UTC
(In reply to comment #16)
> Does that help?

Much. Thanks. :)

Don't know if this is still a problem, but #0 has:
> for libgomp, one can not simply use LDFLAGS=-static as libgomp pulls in
> libpthread and static linking is not supported with libpthread

Question being, is there a difference between darwin and, say, our average linux box, that allows static linking with the one, but not with the other? In PR30471, comment #7, Jakub once posted a semi work around to this question.
Comment 18 Iain Sandoe 2010-04-09 21:51:24 UTC
(In reply to comment #17)
 
> Question being, is there a difference between darwin and, say, our average
> linux box, that allows static linking with the one, but not with the other?

yes, there is a significant difference - threads are part of libSystem on darwin (which is always linked dynamically).  So I guess that this is not a solution.
Comment 19 Iain Sandoe 2010-04-13 11:37:48 UTC
Subject: Bug 31400

Author: iains
Date: Tue Apr 13 11:37:34 2010
New Revision: 158262

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158262
Log:
gcc/fortran:
2010-04-13  Iain Sandoe  <iains@gcc.gnu.org>

	PR bootstrap/31400
	* gfortranspec.c (lookup_option): Check for -static and return
	OPTION_static.
	(lang_specific_driver): Break when OPTION_static is discovered.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortranspec.c

Comment 20 Matt Arsenault 2011-06-19 18:25:27 UTC
I would find the -static-libgomp option useful
Comment 21 janus 2017-11-14 13:00:46 UTC
(In reply to Matt Arsenault from comment #20)
> I would find the -static-libgomp option useful

+1