]> Cypherpunks repositories - gostls13.git/commit
cmd/gc: emit explicit type information for local variables
authorRuss Cox <rsc@golang.org>
Mon, 25 Feb 2013 17:13:47 +0000 (12:13 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 25 Feb 2013 17:13:47 +0000 (12:13 -0500)
commit1d5dc4fd481ae5ccebe1be0091a88b9343fe0904
treec3ba4fa9c79acbd913530f330011524436ec5a98
parenta411b104f0a32f7c859d63c4fbd46919c2036910
cmd/gc: emit explicit type information for local variables

The type information is (and for years has been) included
as an extra field in the address chunk of an instruction.
Unfortunately, suppose there is a string at a+24(FP) and
we have an instruction reading its length. It will say:

        MOVQ x+32(FP), AX

and the type of *that* argument is int (not slice), because
it is the length being read. This confuses the picture seen
by debuggers and now, worse, by the garbage collector.

Instead of attaching the type information to all uses,
emit an explicit list of TYPE instructions with the information.
The TYPE instructions are no-ops whose only role is to
provide an address to attach type information to.

For example, this function:

        func f(x, y, z int) (a, b string) {
                return
        }

now compiles into:

        --- prog list "f" ---
        0000 (/Users/rsc/x.go:3) TEXT    f+0(SB),$0-56
        0001 (/Users/rsc/x.go:3) LOCALS  ,
        0002 (/Users/rsc/x.go:3) TYPE    x+0(FP){int},$8
        0003 (/Users/rsc/x.go:3) TYPE    y+8(FP){int},$8
        0004 (/Users/rsc/x.go:3) TYPE    z+16(FP){int},$8
        0005 (/Users/rsc/x.go:3) TYPE    a+24(FP){string},$16
        0006 (/Users/rsc/x.go:3) TYPE    b+40(FP){string},$16
        0007 (/Users/rsc/x.go:3) MOVQ    $0,b+40(FP)
        0008 (/Users/rsc/x.go:3) MOVQ    $0,b+48(FP)
        0009 (/Users/rsc/x.go:3) MOVQ    $0,a+24(FP)
        0010 (/Users/rsc/x.go:3) MOVQ    $0,a+32(FP)
        0011 (/Users/rsc/x.go:4) RET     ,

The { } show the formerly hidden type information.
The { } syntax is used when printing from within the gc compiler.
It is not accepted by the assemblers.

The same type information is now included on global variables:

0055 (/Users/rsc/x.go:15) GLOBL   slice+0(SB){[]string},$24(AL*0)

This more accurate type information fixes a bug in the
garbage collector's precise heap collection.

The linker only cares about globals right now, but having the
local information should make things a little nicer for Carl
in the future.

Fixes #4907.

R=ken2
CC=golang-dev
https://golang.org/cl/7395056
33 files changed:
src/cmd/5g/ggen.c
src/cmd/5g/gsubr.c
src/cmd/5g/list.c
src/cmd/5g/peep.c
src/cmd/5g/reg.c
src/cmd/5l/5.out.h
src/cmd/5l/obj.c
src/cmd/5l/span.c
src/cmd/6g/ggen.c
src/cmd/6g/gsubr.c
src/cmd/6g/list.c
src/cmd/6g/peep.c
src/cmd/6g/reg.c
src/cmd/6l/6.out.h
src/cmd/6l/obj.c
src/cmd/6l/optab.c
src/cmd/8g/ggen.c
src/cmd/8g/gsubr.c
src/cmd/8g/list.c
src/cmd/8g/peep.c
src/cmd/8g/reg.c
src/cmd/8l/8.out.h
src/cmd/8l/obj.c
src/cmd/8l/optab.c
src/cmd/gc/closure.c
src/cmd/gc/dcl.c
src/cmd/gc/fmt.c
src/cmd/gc/go.h
src/cmd/gc/obj.c
src/cmd/gc/pgen.c
src/cmd/gc/subr.c
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c