]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/ld: restore the call graph dump
authorAnthony Martin <ality@pbrane.org>
Thu, 17 Apr 2014 02:42:02 +0000 (22:42 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 17 Apr 2014 02:42:02 +0000 (22:42 -0400)
Before the switch to liblink, the linkers accepted the -c flag
to print the call graph. This change restores the functionality.

This came in handy when I was trying to audit the use of SSE
instructions inside the Plan 9 note handler.

LGTM=rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews
https://golang.org/cl/73990043

src/cmd/ld/lib.c
src/cmd/ld/lib.h
src/cmd/ld/pobj.c

index 585a4c66a2842ef97a256fad06b6ddd67e9957e9..78b8cf2badd3949f1181e007f2f90c9325088e9f 100644 (file)
@@ -1483,6 +1483,27 @@ undef(void)
                errorexit();
 }
 
+void
+callgraph(void)
+{
+       LSym *s;
+       Reloc *r;
+       int i;
+
+       if(!debug['c'])
+               return;
+
+       for(s = ctxt->textp; s != nil; s = s->next) {
+               for(i=0; i<s->nr; i++) {
+                       r = &s->r[i];
+                       if(r->sym == nil)
+                               continue;
+                       if((r->type == R_CALL || r->type == R_CALLARM) && r->sym->type == STEXT)
+                               Bprint(&bso, "%s calls %s\n", s->name, r->sym->name);
+               }
+       }
+}
+
 void
 diag(char *fmt, ...)
 {
index b4551a0908e46f024d210508d2d8a714eb644616..7267c63713b58b36119c2aeb86a5afeea92448e9 100644 (file)
@@ -178,6 +178,7 @@ void        asmplan9sym(void);
 uint16 be16(uchar *b);
 uint32 be32(uchar *b);
 uint64 be64(uchar *b);
+void   callgraph(void);
 void   cflush(void);
 void   codeblk(int32 addr, int32 size);
 vlong  cpos(void);
index 8276fb7066c6aaff57e5a7036d55b49b5b7eefc7..819c37954a6b6a77ec91c00898dee3365004568b 100644 (file)
@@ -164,6 +164,7 @@ main(int argc, char *argv[])
        }
 
        deadcode();
+       callgraph();
        paramspace = "SP";      /* (FP) now (SP) on output */
 
        doelf();