This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

RFC: Setting the "externally_visible" attribute on MAIN__


Background: There are currently two reasons why -fwhole-program
doesn't work for Fortran: first, because it removes MAIN__, the MAIN__
fortran program, because it never called; secondly, because of the
famous more-than-one-decl-per-function problem. While the second one
will have to wait 4.4 to be fixed, we can at least get the first
fixed. My first two attempts failed:

  1. I first wanted to emit main() directly, instead of having MAIN__
called by a main() function in libgfortranbegin.a. Paul Brook objected
to that, partly for keeping compatibility with the current behaviour,
and that reason seemed good enough to me.
(http://gcc.gnu.org/ml/fortran/2007-03/msg00300.html)

  2. My second patch tried to use main_identifier_node() for that job,
which is not appropriate at all, as Andrew pointed
(http://gcc.gnu.org/ml/fortran/2007-09/msg00289.html).

Being such a slow learner, I couldn't do without a third attempt. This
patch sets the "externally_visible" attribute on the decl for MAIN__.
This was tested and appears to work fine, and this time I don't think
there is any undesirable side effect. Andrew, you said you had an idea
how to fix this, was that it? Also, I'd appreciate comments on whether
this is the right way to set attributes on a decl (it seems to work,
but I couldn't find a simple example of that in the C front-end, so
I'm not 100% sure.)

Does that look OK?

Thanks,
FX




Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 128673)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -1321,6 +1321,12 @@ build_function_decl (gfc_symbol * sym)
       TREE_SIDE_EFFECTS (fndecl) = 0;
     }

+  /* For -fwhole-program to work well, MAIN__ needs to have the
+     "externally_visible" attribute.  */
+  if (attr.is_main_program)
+    DECL_ATTRIBUTES (fndecl)
+      = tree_cons (get_identifier("externally_visible"), NULL_TREE, NULL_TREE);
+
   /* Layout the function declaration and put it in the binding level
      of the current function.  */
   pushdecl (fndecl);


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