1
0
mirror of https://github.com/golang/go synced 2024-10-03 09:21:21 -06:00
go/src/cmd/8l
Russ Cox 1d5dc4fd48 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
2013-02-25 12:13:47 -05:00
..
8.out.h cmd/gc: emit explicit type information for local variables 2013-02-25 12:13:47 -05:00
asm.c cmd/8l/asm.c: Unused function arguments, suppress warnings. 2013-02-11 10:15:56 +11:00
doc.go cmd/godoc: use go/build to determine package and example files 2013-02-19 11:19:58 -08:00
l.h cmd/5g, cmd/5l, cmd/6l, cmd/8l, cmd/gc, cmd/ld, runtime: accurate args and locals information 2013-02-21 12:52:26 -08:00
list.c cmd/8l: add SSE2 instructions 2012-10-07 16:36:14 -04:00
Makefile build: delete make paraphernalia 2012-02-06 13:34:25 -05:00
mkenam 5l, 6l, 8l: drop use of ed during build 2011-06-27 12:03:19 -04:00
obj.c cmd/gc: emit explicit type information for local variables 2013-02-25 12:13:47 -05:00
optab.c cmd/gc: emit explicit type information for local variables 2013-02-25 12:13:47 -05:00
pass.c cmd/6g, cmd/8g: switch to DX for indirect call block 2013-02-22 10:47:54 -05:00
prof.c 8l/prof.c: #if 0 is not accepted by the Plan 9 native toolchain. 2011-04-21 17:03:58 -04:00
span.c cmd/8l: fix misassembling of MOVB involving (AX)(BX*1) 2013-01-31 08:52:46 +01:00