diff mbox

[debug-early] fix -fdump-go-spec

Message ID 55417DCC.2090708@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez April 30, 2015, 12:56 a.m. UTC
Hi guys!

Despite what Go thinks:

   /* The debug hooks are used to implement -fdump-go-spec because it
      gives a simple and stable API for all the information we need to
      dump.  */

...the debug hooks are not stable... :).

The godump-1.c test is failing in the debug-early branch.  It seems that 
Go is hijacking the debug_hook machinery to access globals generated by 
the front-ends.  In debug-early, things have moved around.

With this patch I have done my best to give Go what it wants without 
recreating what the front-ends were doing.  I've made the go_decl() call 
work from within the early_global_decl() hook which gets called as we 
parse (rest_of_decl_compilation).  I far as I understand, this hack is a 
one-time thing for use internally in the build process, so we don't care 
whether go_decl() will receive location information??

I have also relaxed the condition in rest_of_decl_compilation to allow 
function prototypes.  Go was expecting to be fed function prototypes as 
part of the global_decl machinery.  However, it won't ever see these, as 
the early_global_decl code iterating through functions uses the symbol 
table, which does not have prototypes:

   /* Emit early debug for reachable functions, and by consequence,
      locally scoped symbols.  */
   struct cgraph_node *cnode;
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
     if (!decl_function_context (cnode->decl))
       (*debug_hooks->early_global_decl) (cnode->decl);

(By the way, even iterating through symbols, without regards to gimple 
body, we end up with nothing...and even before we analyze_functions() 
and prune unreachable nodes.).

Relaxing the condition does the trick, and the dwarf early_global_decl 
debug hook just works because it avoids functions with no body anyhow.

In a world with Go and non dwarf (stabs, etc) debug hooks, I may have to 
adjust the calls to debug_hooks->{early,late}_global_decl a bit more to 
get all debugging backends to get what they want.  This may involve 
feeding more to the debug hooks while making the individual hooks 
disregard DECLs they don't want/need.

Is there not a more modern way of Go getting the DECLs it needs without 
abusing the debug_hook machinery?

Anyways... this is what I have so far.  It may change, as I have at 
least one stabs problem that may regarding tweaking things again.

Committed to branch.

Aldy
commit 040d95e2436d7fa1ef75761dfe50b7481726373d
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Apr 29 17:37:21 2015 -0700

    Fix -fdump-go-spec.

Comments

Ian Lance Taylor May 8, 2015, 6:06 p.m. UTC | #1
On Wed, Apr 29, 2015 at 5:56 PM, Aldy Hernandez <aldyh@redhat.com> wrote:
>
> Despite what Go thinks:
>
>   /* The debug hooks are used to implement -fdump-go-spec because it
>      gives a simple and stable API for all the information we need to
>      dump.  */
>
> ...the debug hooks are not stable... :).

Alas.


> With this patch I have done my best to give Go what it wants without
> recreating what the front-ends were doing.  I've made the go_decl() call
> work from within the early_global_decl() hook which gets called as we parse
> (rest_of_decl_compilation).  I far as I understand, this hack is a one-time
> thing for use internally in the build process, so we don't care whether
> go_decl() will receive location information??

That is true: the goal is to output the declarations in Go syntax;
location information is irrelevant.


> Is there not a more modern way of Go getting the DECLs it needs without
> abusing the debug_hook machinery?

I don't know.

Thanks for working on this.  Have you tried building with
--enable-languages=go?  On a GNU/Linux system it should build and pass
all tests with no extra effort.

Ian
Aldy Hernandez May 8, 2015, 6:54 p.m. UTC | #2
> Thanks for working on this.  Have you tried building with
> --enable-languages=go?  On a GNU/Linux system it should build and pass
> all tests with no extra effort.

Yes.  No regressions.

Thanks.
Aldy
diff mbox

Patch

diff --git a/gcc/godump.c b/gcc/godump.c
index 94d0c8b..5de34db 100644
--- a/gcc/godump.c
+++ b/gcc/godump.c
@@ -517,6 +517,7 @@  go_function_decl (tree decl)
 static void
 go_early_global_decl (tree decl)
 {
+  go_decl (decl);
   real_debug_hooks->early_global_decl (decl);
 }
 
@@ -526,7 +527,6 @@  static void
 go_late_global_decl (tree decl)
 {
   real_debug_hooks->late_global_decl (decl);
-  go_decl (decl);
 }
 
 /* A type declaration.  */
diff --git a/gcc/passes.c b/gcc/passes.c
index 3bb0e5d..4dee8ad 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -297,10 +297,20 @@  rest_of_decl_compilation (tree decl,
   /* Generate early debug for global variables.  Any local variables will
      be handled by either handling reachable functions from
      finalize_compilation_unit (and by consequence, locally scoped
-     symbols), or by rest_of_type_compilation below.  */
+     symbols), or by rest_of_type_compilation below.
+
+     Also, pick up function prototypes, which will be mostly ignored
+     by the different early_global_decl() hooks, but will at least be
+     used by Go's hijack of the debug_hooks to implement
+     -fdump-go-spec.  */
   if (!flag_wpa
       && !in_lto_p
-      && TREE_CODE (decl) != FUNCTION_DECL
+      && (TREE_CODE (decl) != FUNCTION_DECL
+	  /* This will pick up function prototypes with no bodies,
+	     which are not visible in finalize_compilation_unit()
+	     while iterating with FOR_EACH_*_FUNCTION through the
+	     symbol table.  */
+	  || !DECL_SAVED_TREE (decl))
       && !decl_function_context (decl)
       && !current_function_decl
       && !decl_type_context (decl))