asm: FUNCDATA PCDATA

85 views
Skip to first unread message

Gert

unread,
Aug 20, 2019, 9:42:37 PM8/20/19
to golang-nuts
https://golang.org/doc/asm

$ cat x.go
package main

func main() {
	println(3)
}
$ GOOS=linux GOARCH=amd64 go tool compile -S x.go        # or: go build -gcflags -S x.go

--- prog list "main" ---
0000 (x.go:3) TEXT    main+0(SB),$8-0
0001 (x.go:3) FUNCDATA $0,gcargs·0+0(SB)
0002 (x.go:3) FUNCDATA $1,gclocals·0+0(SB)
0003 (x.go:4) MOVQ    $3,(SP)
0004 (x.go:4) PCDATA  $0,$8
0005 (x.go:4) CALL    ,runtime.printint+0(SB)
0006 (x.go:4) PCDATA  $0,$-1
0007 (x.go:4) PCDATA  $0,$0
0008 (x.go:4) CALL    ,runtime.printnl+0(SB)
0009 (x.go:4) PCDATA  $0,$-1
0010 (x.go:5) RET     ,
...


The FUNCDATA and PCDATA directives contain information for use by the garbage collector; they are introduced by the compiler.


1) funcdata What is this .0 which is not a dot :)

2) pcdata what does $-1 mean here

3) Is there some more information on funcdata and pcdata? Doesn't have to be in detail, because i know its a can of worms, but just enough so I can tell what the garbage collector will be doing :)


--


When defining a TEXT, specifying frame size $-4 tells the linker that this is a leaf function that does not need to save LR on entry.


4) What is LR?

5) Leaf as in closure function?


Ian Lance Taylor

unread,
Aug 21, 2019, 1:45:22 PM8/21/19
to Gert, golang-nuts
On Tue, Aug 20, 2019 at 6:42 PM Gert <gert.c...@gmail.com> wrote:
>
> https://golang.org/doc/asm
>
> $ cat x.go
> package main
>
> func main() {
> println(3)
> }
> $ GOOS=linux GOARCH=amd64 go tool compile -S x.go # or: go build -gcflags -S x.go
>
> --- prog list "main" ---
> 0000 (x.go:3) TEXT main+0(SB),$8-0
> 0001 (x.go:3) FUNCDATA $0,gcargs·0+0(SB)
> 0002 (x.go:3) FUNCDATA $1,gclocals·0+0(SB)
> 0003 (x.go:4) MOVQ $3,(SP)
> 0004 (x.go:4) PCDATA $0,$8
> 0005 (x.go:4) CALL ,runtime.printint+0(SB)
> 0006 (x.go:4) PCDATA $0,$-1
> 0007 (x.go:4) PCDATA $0,$0
> 0008 (x.go:4) CALL ,runtime.printnl+0(SB)
> 0009 (x.go:4) PCDATA $0,$-1
> 0010 (x.go:5) RET ,
> ...
>
>
> The FUNCDATA and PCDATA directives contain information for use by the garbage collector; they are introduced by the compiler.
>
>
> 1) funcdata What is this .0 which is not a dot :)

Note that the current compiler emits different data.

I think the ·0 was just used to distinguish the GC information for
different functions. The second function would use ·1, and so forth.

> 2) pcdata what does $-1 mean here

I'm not sure.

> 3) Is there some more information on funcdata and pcdata? Doesn't have to be in detail, because i know its a can of worms, but just enough so I can tell what the garbage collector will be doing :)

I don't know of any real documentation. You can see some basic stuff
in cmd/internal/objabi and runtime/symtab.go. You can see the garbage
collector using the information in the runtime function getStackMap
and its callers.


> When defining a TEXT, specifying frame size $-4 tells the linker that this is a leaf function that does not need to save LR on entry.
>
>
> 4) What is LR?

The Link Register used on architectures like ARM.

> 5) Leaf as in closure function?

No, leaf as in a function that does not call any other functions.

Ian
Reply all
Reply to author
Forward
0 new messages