Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(422)

Issue 6749064: code review 6749064: cmd/gc, cmd/ld: struct field tracking (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 4 months ago by rsc
Modified:
11 years, 4 months ago
Reviewers:
CC:
iant, ken2, golang-dev
Visibility:
Public.

Description

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.

Patch Set 1 #

Patch Set 2 : diff -r 8d919bfe75d3 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 88c4bdf6cfb8 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 88c4bdf6cfb8 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 88c4bdf6cfb8 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 88c4bdf6cfb8 https://go.googlecode.com/hg/ #

Patch Set 7 : diff -r 88c4bdf6cfb8 https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 024dde07c08d https://go.googlecode.com/hg/ #

Total comments: 10

Patch Set 9 : diff -r a9b2f3280559 https://go.googlecode.com/hg/ #

Patch Set 10 : diff -r a9b2f3280559 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+413 lines, -188 lines) Patch
M src/cmd/5a/lex.c View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5g/gg.h View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/5g/gsubr.c View 1 2 1 chunk +11 lines, -0 lines 0 comments Download
M src/cmd/5l/5.out.h View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5l/l.h View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5l/obj.c View 1 2 3 4 5 6 7 1 chunk +3 lines, -0 lines 0 comments Download
M src/cmd/5l/optab.c View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/5l/span.c View 1 2 3 4 5 6 7 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6a/lex.c View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -1 line 0 comments Download
M src/cmd/6g/gg.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/6g/gsubr.c View 1 2 1 chunk +11 lines, -0 lines 0 comments Download
M src/cmd/6l/6.out.h View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/6l/l.h View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/6l/obj.c View 1 2 3 4 5 6 7 1 chunk +3 lines, -0 lines 0 comments Download
M src/cmd/6l/optab.c View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/8a/lex.c View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8g/gg.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/8g/gsubr.c View 1 2 1 chunk +11 lines, -0 lines 0 comments Download
M src/cmd/8l/8.out.h View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/8l/l.h View 1 2 3 4 5 6 7 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/8l/obj.c View 1 2 3 4 5 6 7 1 chunk +3 lines, -0 lines 0 comments Download
M src/cmd/8l/optab.c View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/gc/dcl.c View 1 2 3 4 5 6 7 8 2 chunks +2 lines, -1 line 0 comments Download
M src/cmd/gc/export.c View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download
M src/cmd/gc/go.h View 1 2 3 4 5 6 7 8 9 chunks +14 lines, -2 lines 0 comments Download
M src/cmd/gc/go.y View 1 2 3 4 5 6 7 8 3 chunks +4 lines, -1 line 0 comments Download
M src/cmd/gc/lex.c View 1 2 3 4 5 6 5 chunks +38 lines, -10 lines 0 comments Download
M src/cmd/gc/pgen.c View 1 2 2 chunks +5 lines, -0 lines 0 comments Download
M src/cmd/gc/reflect.c View 1 2 3 4 5 3 chunks +14 lines, -1 line 0 comments Download
M src/cmd/gc/subr.c View 1 2 3 4 5 1 chunk +1 line, -1 line 0 comments Download
M src/cmd/gc/typecheck.c View 1 2 3 4 5 6 7 8 2 chunks +2 lines, -1 line 0 comments Download
M src/cmd/gc/walk.c View 1 2 3 4 5 6 7 2 chunks +48 lines, -2 lines 0 comments Download
M src/cmd/gc/y.tab.c View 1 2 3 4 5 6 7 8 45 chunks +134 lines, -131 lines 0 comments Download
M src/cmd/ld/data.c View 1 2 1 chunk +4 lines, -0 lines 0 comments Download
M src/cmd/ld/go.c View 1 2 3 4 5 6 7 8 5 chunks +75 lines, -37 lines 0 comments Download
M src/cmd/ld/lib.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 5
rsc
Hello iant, ken2 (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 4 months ago (2012-11-01 02:43:02 UTC) #1
iant
https://codereview.appspot.com/6749064/diff/14001/src/cmd/5a/lex.c File src/cmd/5a/lex.c (right): https://codereview.appspot.com/6749064/diff/14001/src/cmd/5a/lex.c#newcode416 src/cmd/5a/lex.c:416: "USEFIELD", LTYPEN, AUSEFIELD, At least in codereview, the new ...
11 years, 4 months ago (2012-11-01 21:30:14 UTC) #2
rsc
PTAL https://codereview.appspot.com/6749064/diff/14001/src/cmd/5a/lex.c File src/cmd/5a/lex.c (right): https://codereview.appspot.com/6749064/diff/14001/src/cmd/5a/lex.c#newcode416 src/cmd/5a/lex.c:416: "USEFIELD", LTYPEN, AUSEFIELD, On 2012/11/01 21:30:15, iant wrote: ...
11 years, 4 months ago (2012-11-02 03:33:37 UTC) #3
iant
LGTM
11 years, 4 months ago (2012-11-02 03:43:03 UTC) #4
rsc
11 years, 4 months ago (2012-11-02 04:17:27 UTC) #5
*** Submitted as http://code.google.com/p/go/source/detail?r=53c4c08250f0 ***

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
http://codereview.appspot.com/6749064
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b