From: Anthony Martin Date: Thu, 17 Apr 2014 02:42:02 +0000 (-0400) Subject: cmd/ld: restore the call graph dump X-Git-Tag: go1.3beta1~35 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1e2a61aee19e9f327950a19131b1349ebb5240e6;p=gostls13.git cmd/ld: restore the call graph dump 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 --- diff --git a/src/cmd/ld/lib.c b/src/cmd/ld/lib.c index 585a4c66a2..78b8cf2bad 100644 --- a/src/cmd/ld/lib.c +++ b/src/cmd/ld/lib.c @@ -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; inr; 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, ...) { diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h index b4551a0908..7267c63713 100644 --- a/src/cmd/ld/lib.h +++ b/src/cmd/ld/lib.h @@ -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); diff --git a/src/cmd/ld/pobj.c b/src/cmd/ld/pobj.c index 8276fb7066..819c37954a 100644 --- a/src/cmd/ld/pobj.c +++ b/src/cmd/ld/pobj.c @@ -164,6 +164,7 @@ main(int argc, char *argv[]) } deadcode(); + callgraph(); paramspace = "SP"; /* (FP) now (SP) on output */ doelf();