Commit bc0c0770 authored by Russ Cox's avatar Russ Cox

doc: update /doc/asm compiler output example

The compiler output shown in the doc is now quite old
(most of the changes happened in Go 1.5).
Update it to be more like what users will actually see.

Also explain how to get literal machine code again.

Prompted by #30968.

Change-Id: I0ce139c3fe299ccc43e85b6aca81c6e0aac1a2df
Reviewed-on: https://go-review.googlesource.com/c/go/+/175757
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarRob Pike <r@golang.org>
parent bc588d4d
...@@ -57,19 +57,32 @@ func main() { ...@@ -57,19 +57,32 @@ func main() {
println(3) println(3)
} }
$ GOOS=linux GOARCH=amd64 go tool compile -S x.go # or: go build -gcflags -S x.go $ GOOS=linux GOARCH=amd64 go tool compile -S x.go # or: go build -gcflags -S x.go
"".main STEXT size=74 args=0x0 locals=0x10
--- prog list "main" --- 0x0000 00000 (x.go:3) TEXT "".main(SB), $16-0
0000 (x.go:3) TEXT main+0(SB),$8-0 0x0000 00000 (x.go:3) MOVQ (TLS), CX
0001 (x.go:3) FUNCDATA $0,gcargs·0+0(SB) 0x0009 00009 (x.go:3) CMPQ SP, 16(CX)
0002 (x.go:3) FUNCDATA $1,gclocals·0+0(SB) 0x000d 00013 (x.go:3) JLS 67
0003 (x.go:4) MOVQ $3,(SP) 0x000f 00015 (x.go:3) SUBQ $16, SP
0004 (x.go:4) PCDATA $0,$8 0x0013 00019 (x.go:3) MOVQ BP, 8(SP)
0005 (x.go:4) CALL ,runtime.printint+0(SB) 0x0018 00024 (x.go:3) LEAQ 8(SP), BP
0006 (x.go:4) PCDATA $0,$-1 0x001d 00029 (x.go:3) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0007 (x.go:4) PCDATA $0,$0 0x001d 00029 (x.go:3) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0008 (x.go:4) CALL ,runtime.printnl+0(SB) 0x001d 00029 (x.go:3) FUNCDATA $2, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0009 (x.go:4) PCDATA $0,$-1 0x001d 00029 (x.go:4) PCDATA $0, $0
0010 (x.go:5) RET , 0x001d 00029 (x.go:4) PCDATA $1, $0
0x001d 00029 (x.go:4) CALL runtime.printlock(SB)
0x0022 00034 (x.go:4) MOVQ $3, (SP)
0x002a 00042 (x.go:4) CALL runtime.printint(SB)
0x002f 00047 (x.go:4) CALL runtime.printnl(SB)
0x0034 00052 (x.go:4) CALL runtime.printunlock(SB)
0x0039 00057 (x.go:5) MOVQ 8(SP), BP
0x003e 00062 (x.go:5) ADDQ $16, SP
0x0042 00066 (x.go:5) RET
0x0043 00067 (x.go:5) NOP
0x0043 00067 (x.go:3) PCDATA $1, $-1
0x0043 00067 (x.go:3) PCDATA $0, $-1
0x0043 00067 (x.go:3) CALL runtime.morestack_noctxt(SB)
0x0048 00072 (x.go:3) JMP 0
... ...
</pre> </pre>
...@@ -78,38 +91,32 @@ The <code>FUNCDATA</code> and <code>PCDATA</code> directives contain information ...@@ -78,38 +91,32 @@ The <code>FUNCDATA</code> and <code>PCDATA</code> directives contain information
for use by the garbage collector; they are introduced by the compiler. for use by the garbage collector; they are introduced by the compiler.
</p> </p>
<!-- Commenting out because the feature is gone but it's popular and may come back.
<p> <p>
To see what gets put in the binary after linking, add the <code>-a</code> flag to the linker: To see what gets put in the binary after linking, use <code>go tool objdump</code>:
</p> </p>
<pre> <pre>
$ go tool 6l -a x.6 # or: go build -ldflags -a x.go $ go build -o x.exe x.go
codeblk [0x2000,0x1d059) at offset 0x1000 $ go tool objdump -s main.main x.exe
002000 main.main | (3) TEXT main.main+0(SB),$8 TEXT main.main(SB) /tmp/x.go
002000 65488b0c25a0080000 | (3) MOVQ 2208(GS),CX x.go:3 0x10501c0 65488b0c2530000000 MOVQ GS:0x30, CX
002009 483b21 | (3) CMPQ SP,(CX) x.go:3 0x10501c9 483b6110 CMPQ 0x10(CX), SP
00200c 7707 | (3) JHI ,2015 x.go:3 0x10501cd 7634 JBE 0x1050203
00200e e83da20100 | (3) CALL ,1c250+runtime.morestack00 x.go:3 0x10501cf 4883ec10 SUBQ $0x10, SP
002013 ebeb | (3) JMP ,2000 x.go:3 0x10501d3 48896c2408 MOVQ BP, 0x8(SP)
002015 4883ec08 | (3) SUBQ $8,SP x.go:3 0x10501d8 488d6c2408 LEAQ 0x8(SP), BP
002019 | (3) FUNCDATA $0,main.gcargs·0+0(SB) x.go:4 0x10501dd e86e45fdff CALL runtime.printlock(SB)
002019 | (3) FUNCDATA $1,main.gclocals·0+0(SB) x.go:4 0x10501e2 48c7042403000000 MOVQ $0x3, 0(SP)
002019 48c7042403000000 | (4) MOVQ $3,(SP) x.go:4 0x10501ea e8e14cfdff CALL runtime.printint(SB)
002021 | (4) PCDATA $0,$8 x.go:4 0x10501ef e8ec47fdff CALL runtime.printnl(SB)
002021 e8aad20000 | (4) CALL ,f2d0+runtime.printint x.go:4 0x10501f4 e8d745fdff CALL runtime.printunlock(SB)
002026 | (4) PCDATA $0,$-1 x.go:5 0x10501f9 488b6c2408 MOVQ 0x8(SP), BP
002026 | (4) PCDATA $0,$0 x.go:5 0x10501fe 4883c410 ADDQ $0x10, SP
002026 e865d40000 | (4) CALL ,f490+runtime.printnl x.go:5 0x1050202 c3 RET
00202b | (4) PCDATA $0,$-1 x.go:3 0x1050203 e83882ffff CALL runtime.morestack_noctxt(SB)
00202b 4883c408 | (5) ADDQ $8,SP x.go:3 0x1050208 ebb6 JMP main.main(SB)
00202f c3 | (5) RET ,
...
</pre> </pre>
-->
<h3 id="constants">Constants</h3> <h3 id="constants">Constants</h3>
<p> <p>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment