This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Add -static-libgfortran to gcc.c and Fortran driver


Attached patch adds a -static-libgfortran option that links the static
libgfortran library on systems where the linker supports
-Bdynamic/-Bstatic. This is an update of my previous patch
(http://gcc.gnu.org/ml/gcc/2007-04/msg00680.html). The name of the
option was changed from -fstatic-libgfortran to -static-libgfortran
for consistency with -static-libgcc.

This change in the option name requires a one-line addition to gcc.c,
in order to validate this option that has a name that doesn't start
with -f. I don't know who exactly can approve this change, I think it
qualifies as "driver".

Bootstrapped, regtested and manually tested on i686-linux. OK for
mainline? (for both the Fortran and gcc.c parts)




:ADDPATCH driver:


2007-05-07 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>

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


2007-05-07 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>


       * 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.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c	(revision 124496)
+++ gcc/gcc.c	(working copy)
@@ -4211,11 +4211,13 @@ warranty; not even for MERCHANTABILITY o
 	  switches[n_switches].live_cond = SWITCH_OK;
 	  switches[n_switches].validated = 0;
 	  switches[n_switches].ordering = 0;
-	  /* These are always valid, since gcc.c itself understands them.  */
+	  /* These are always valid, since gcc.c itself understands the
+	     first four and gfortranspec.c understands -static-libgfortran.  */
 	  if (!strcmp (p, "save-temps")
 	      || !strcmp (p, "static-libgcc")
 	      || !strcmp (p, "shared-libgcc")
-	      || !strcmp (p, "pipe"))
+	      || !strcmp (p, "pipe")
+	      || !strcmp (p, "static-libgfortran"))
 	    switches[n_switches].validated = 1;
 	  else
 	    {
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 124496)
+++ gcc/fortran/lang.opt	(working copy)
@@ -253,6 +253,10 @@ funderscoring
 Fortran
 Append underscores to externally visible names
 
+static-libgfortran
+Fortran
+Statically link the GNU Fortran helper library (libgfortran)
+
 std=f2003
 Fortran
 Conform to the ISO Fortran 2003 standard
Index: gcc/fortran/gfortranspec.c
===================================================================
--- gcc/fortran/gfortranspec.c	(revision 124496)
+++ gcc/fortran/gfortranspec.c	(working copy)
@@ -66,6 +66,20 @@ Boston, MA 02110-1301, USA.  */
 #define FORTRAN_LIBRARY "-lgfortran"
 #endif
 
+#ifdef HAVE_LD_STATIC_DYNAMIC
+#define ADD_ARG_LIBGFORTRAN(arg) \
+  { \
+    if (static_lib && !static_linking) \
+      append_arg ("-Wl,-Bstatic"); \
+    append_arg (arg); \
+    if (static_lib && !static_linking) \
+      append_arg ("-Wl,-Bdynamic"); \
+  }
+#else
+#define ADD_ARG_LIBGFORTRAN(arg) append_arg (arg);
+#endif
+
+
 /* Options this driver needs to recognize, not just know how to
    skip over.  */
 typedef enum
@@ -82,6 +96,8 @@ typedef enum
 				   -nodefaultlibs.  */
   OPTION_o,			/* Aka --output.  */
   OPTION_S,			/* Aka --assemble.  */
+  OPTION_static,		/* -static.  */
+  OPTION_static_libgfortran,	/* -static-libgfortran.  */
   OPTION_syntax_only,		/* -fsyntax-only.  */
   OPTION_v,			/* Aka --verbose.  */
   OPTION_version,		/* --version.  */
@@ -170,6 +186,8 @@ lookup_option (Option *xopt, int *xskip,
 	opt = OPTION_nostdlib;
       else if (!strcmp (text, "-fsyntax-only"))
 	opt = OPTION_syntax_only;
+      else if (!strcmp (text, "-static-libgfortran"))
+	opt = OPTION_static_libgfortran;
       else if (!strcmp (text, "-dumpversion"))
 	opt = OPTION_version;
       else if (!strcmp (text, "-fversion"))	/* Really --version!! */
@@ -265,6 +283,12 @@ lang_specific_driver (int *in_argc, cons
   /* By default, we throw on the math library if we have one.  */
   int need_math = (MATH_LIBRARY[0] != '\0');
 
+  /* Whether we should link a static libgfortran.  */
+  int static_lib = 0;
+
+  /* Whether we need to link staticaly.  */
+  int static_linking = 0;
+
   /* The number of input and output files in the incoming arg list.  */
   int n_infiles = 0;
   int n_outfiles = 0;
@@ -323,6 +347,13 @@ lang_specific_driver (int *in_argc, cons
 	  library = 0;
 	  break;
 
+	case OPTION_static_libgfortran:
+	  static_lib = 1;
+	  break;
+
+	case OPTION_static:
+	  static_linking = 1;
+
 	case OPTION_l:
 	  ++n_infiles;
 	  break;
@@ -468,11 +499,16 @@ For more information about these matters
 		      append_arg (FORTRAN_INIT);
 		      use_init = 1;
 		    }
-		  append_arg (FORTRAN_LIBRARY);
+
+		  ADD_ARG_LIBGFORTRAN (FORTRAN_LIBRARY);
 		}
 	    }
 	  else if (strcmp (argv[i], FORTRAN_LIBRARY) == 0)
-	    saw_library = 1;	/* -l<library>.  */
+	    {
+	      saw_library = 1;	/* -l<library>.  */
+	      ADD_ARG_LIBGFORTRAN (argv[i]);
+	      continue;
+	    }
 	  else
 	    {			/* Other library, or filename.  */
 	      if (saw_library == 1 && need_math)
@@ -498,7 +534,9 @@ For more information about these matters
 	      append_arg (FORTRAN_INIT);
 	      use_init = 1;
 	    }
-	  append_arg (library);
+	  ADD_ARG_LIBGFORTRAN (library);
+	  /* Fall through.  */
+
 	case 1:
 	  if (need_math)
 	    append_arg (MATH_LIBRARY);
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 124496)
+++ gcc/fortran/options.c	(working copy)
@@ -551,6 +551,13 @@ gfc_handle_option (size_t scode, const c
       gfc_option.flag_second_underscore = value;
       break;
 
+    case OPT_static_libgfortran:
+#ifndef HAVE_LD_STATIC_DYNAMIC
+      gfc_fatal_error ("-static-libgfortran is not supported in this "
+		       "configuration");
+#endif
+      break;
+
     case OPT_fimplicit_none:
       gfc_option.flag_implicit_none = value;
       break;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]