1
0
mirror of https://github.com/golang/go synced 2024-10-04 12:21:26 -06:00
go/src/cmd/8g
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
..
cgen64.c cmd/gc: contiguous loop layout 2012-05-30 18:07:39 -04:00
cgen.c cmd/5g, cmd/6g, cmd/8g: remove width check for componentgen. 2012-11-01 14:36:08 +01:00
doc.go 5g, 8g: remove documentation dregs 2012-02-29 22:56:50 -08:00
galign.c cmd/gc: prepare for 64-bit ints 2012-09-24 14:59:44 -04:00
gg.h cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
ggen.c cmd/5g, cmd/6g, cmd/8g: remove width check for componentgen. 2012-11-01 14:36:08 +01:00
gobj.c cmd/gc: limit data disassembly to -SS 2012-06-07 12:05:34 -04:00
gsubr.c cmd/gc, cmd/ld: struct field tracking 2012-11-02 00:17:21 -04:00
list.c 8g: fix build on Plan 9 2011-08-26 17:42:59 -04:00
Makefile build: delete make paraphernalia 2012-02-06 13:34:25 -05:00
opt.h cmd/[568]g: explain the purpose of various Reg fields. 2012-09-24 20:55:11 +02:00
peep.c cmd/6g, cmd/8g: eliminate short integer arithmetic when possible. 2012-09-01 16:40:54 +02:00
reg.c cmd/{5g,6g,8g,6c}: remove unused macro, use %E to print etype. 2012-09-24 23:44:00 +02:00