1
0
mirror of https://github.com/golang/go synced 2024-11-14 15:10:54 -07:00
go/src/cmd
Russ Cox 3d40062c68 cmd/gc, cmd/ld: struct field tracking
This is an experiment in static analysis of Go programs
to understand which struct fields a program might use.
It is not part of the Go language specification, it must
be enabled explicitly when building the toolchain,
and it may be removed at any time.

After building the toolchain with GOEXPERIMENT=fieldtrack,
a specific field can be marked for tracking by including
`go:"track"` in the field tag:

        package pkg

        type T struct {
                F int `go:"track"`
                G int // untracked
        }

To simplify usage, only named struct types can have
tracked fields, and only exported fields can be tracked.

The implementation works by making each function begin
with a sequence of no-op USEFIELD instructions declaring
which tracked fields are accessed by a specific function.
After the linker's dead code elimination removes unused
functions, the fields referred to by the remaining
USEFIELD instructions are the ones reported as used by
the binary.

The -k option to the linker specifies the fully qualified
symbol name (such as my/pkg.list) of a string variable that
should be initialized with the field tracking information
for the program. The field tracking string is a sequence
of lines, each terminated by a \n and describing a single
tracked field referred to by the program. Each line is made
up of one or more tab-separated fields. The first field is
the name of the tracked field, fully qualified, as in
"my/pkg.T.F". Subsequent fields give a shortest path of
reverse references from that field to a global variable or
function, corresponding to one way in which the program
might reach that field.

A common source of false positives in field tracking is
types with large method sets, because a reference to the
type descriptor carries with it references to all methods.
To address this problem, the CL also introduces a comment
annotation

        //go:nointerface

that marks an upcoming method declaration as unavailable
for use in satisfying interfaces, both statically and
dynamically. Such a method is also invisible to package
reflect.

Again, all of this is disabled by default. It only turns on
if you have GOEXPERIMENT=fieldtrack set during make.bash.

R=iant, ken
CC=golang-dev
https://golang.org/cl/6749064
2012-11-02 00:17:21 -04:00
..
5a cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
5c cmd/5c: fix dataflag annotation 2012-09-25 14:42:44 +08:00
5g cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
5l cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
6a cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
6c cmd/{5g,6g,8g,6c}: remove unused macro, use %E to print etype. 2012-09-24 23:44:00 +02:00
6g cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
6l cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
8a cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
8c
8g cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
8l cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
addr2line
api cmd/api: handle contexts re-converging 2012-10-30 13:12:59 +01:00
cc cmd/cc: map C int to int32 in Go defs 2012-10-06 13:56:12 +08:00
cgo cmd/cgo: improve gccgo support 2012-11-01 11:21:30 -07:00
cov
dist lib9, cmd/dist, cmd/5l: embed GOARM into cmd/5l and auto detect GOARM 2012-10-22 14:26:36 +08:00
fix gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
gc cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
go cmd/go: fixes to gccgo support 2012-11-01 11:13:50 -07:00
godoc gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
gofmt gofmt: simplify slices of the form s[a : len(s)] to s[a:] 2012-10-31 11:48:55 -07:00
ld cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
nm gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
objdump
pack cmd/pack: rename __.SYMDEF to __.GOSYMDEF 2012-09-13 10:26:21 -04:00
prof
vet gofmt: apply gofmt -w src misc 2012-10-30 13:38:01 -07:00
yacc cmd/yacc: allow utf-8 token values 2012-09-13 13:59:00 -07:00