求分析下面两个golang汇编的区别

mlzhou · · 788 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

``` package main import ( "time" ) func main() { cTime := time.NewTimer(time.Duration(3) * time.Second) cTime.Reset(time.Duration(3) * time.Second) } ``` go tool compile -l -N -S demo.go > demo.s 2>&1 下面是不同golang版本的汇编: 版本1.9.7 ``` "".main STEXT size=89 args=0x0 locals=0x28 0x0000 00000 (demo.go:7) TEXT "".main(SB), $40-0 0x0000 00000 (demo.go:7) MOVQ (TLS), CX 0x0009 00009 (demo.go:7) CMPQ SP, 16(CX) 0x000d 00013 (demo.go:7) JLS 82 0x000f 00015 (demo.go:7) SUBQ $40, SP 0x0013 00019 (demo.go:7) MOVQ BP, 32(SP) 0x0018 00024 (demo.go:7) LEAQ 32(SP), BP 0x001d 00029 (demo.go:7) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001d 00029 (demo.go:7) FUNCDATA $1, gclocals·2a5305abe05176240e61b8620e19a815(SB) 0x001d 00029 (demo.go:7) MOVL $3000000000, AX 0x0022 00034 (demo.go:8) MOVQ AX, (SP) 0x0026 00038 (demo.go:8) PCDATA $0, $0 0x0026 00038 (demo.go:8) CALL time.NewTimer(SB) 0x002b 00043 (demo.go:8) MOVQ 8(SP), AX 0x0030 00048 (demo.go:8) MOVQ AX, "".cTime+24(SP) 0x0035 00053 (demo.go:9) MOVQ AX, (SP) 0x0039 00057 (demo.go:9) MOVL $3000000000, AX 0x003e 00062 (demo.go:9) MOVQ AX, 8(SP) 0x0043 00067 (demo.go:9) PCDATA $0, $0 0x0043 00067 (demo.go:9) CALL time.(*Timer).Reset(SB) 0x0048 00072 (demo.go:10) MOVQ 32(SP), BP 0x004d 00077 (demo.go:10) ADDQ $40, SP 0x0051 00081 (demo.go:10) RET 0x0052 00082 (demo.go:10) NOP 0x0052 00082 (demo.go:7) PCDATA $0, $-1 0x0052 00082 (demo.go:7) CALL runtime.morestack_noctxt(SB) 0x0057 00087 (demo.go:7) JMP 0 0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 43 48 dH..%....H;a.vCH 0x0010 83 ec 28 48 89 6c 24 20 48 8d 6c 24 20 b8 00 5e ..(H.l$ H.l$ ..^ 0x0020 d0 b2 48 89 04 24 e8 00 00 00 00 48 8b 44 24 08 ..H..$.....H.D$. 0x0030 48 89 44 24 18 48 89 04 24 b8 00 5e d0 b2 48 89 H.D$.H..$..^..H. 0x0040 44 24 08 e8 00 00 00 00 48 8b 6c 24 20 48 83 c4 D$......H.l$ H.. 0x0050 28 c3 e8 00 00 00 00 eb a7 (........ rel 5+4 t=16 TLS+0 rel 39+4 t=8 time.NewTimer+0 rel 68+4 t=8 time.(*Timer).Reset+0 rel 83+4 t=8 runtime.morestack_noctxt+0 "".init STEXT size=104 args=0x0 locals=0x8 0x0000 00000 (<autogenerated>:1) TEXT "".init(SB), $8-0 0x0000 00000 (<autogenerated>:1) MOVQ (TLS), CX 0x0009 00009 (<autogenerated>:1) CMPQ SP, 16(CX) 0x000d 00013 (<autogenerated>:1) JLS 97 0x000f 00015 (<autogenerated>:1) SUBQ $8, SP 0x0013 00019 (<autogenerated>:1) MOVQ BP, (SP) 0x0017 00023 (<autogenerated>:1) LEAQ (SP), BP 0x001b 00027 (<autogenerated>:1) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001b 00027 (<autogenerated>:1) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001b 00027 (<autogenerated>:1) MOVBLZX "".initdone·(SB), AX 0x0022 00034 (<autogenerated>:1) CMPB AL, $1 0x0024 00036 (<autogenerated>:1) JHI 40 0x0026 00038 (<autogenerated>:1) JMP 49 0x0028 00040 (<autogenerated>:1) MOVQ (SP), BP 0x002c 00044 (<autogenerated>:1) ADDQ $8, SP 0x0030 00048 (<autogenerated>:1) RET 0x0031 00049 (<autogenerated>:1) MOVBLZX "".initdone·(SB), AX 0x0038 00056 (<autogenerated>:1) CMPB AL, $1 0x003a 00058 (<autogenerated>:1) JEQ 62 0x003c 00060 (<autogenerated>:1) JMP 69 0x003e 00062 (<autogenerated>:1) PCDATA $0, $0 0x003e 00062 (<autogenerated>:1) CALL runtime.throwinit(SB) 0x0043 00067 (<autogenerated>:1) UNDEF 0x0045 00069 (<autogenerated>:1) MOVB $1, "".initdone·(SB) 0x004c 00076 (<autogenerated>:1) PCDATA $0, $0 0x004c 00076 (<autogenerated>:1) CALL time.init(SB) 0x0051 00081 (<autogenerated>:1) MOVB $2, "".initdone·(SB) 0x0058 00088 (<autogenerated>:1) MOVQ (SP), BP 0x005c 00092 (<autogenerated>:1) ADDQ $8, SP 0x0060 00096 (<autogenerated>:1) RET 0x0061 00097 (<autogenerated>:1) NOP 0x0061 00097 (<autogenerated>:1) PCDATA $0, $-1 0x0061 00097 (<autogenerated>:1) CALL runtime.morestack_noctxt(SB) 0x0066 00102 (<autogenerated>:1) JMP 0 0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 52 48 dH..%....H;a.vRH 0x0010 83 ec 08 48 89 2c 24 48 8d 2c 24 0f b6 05 00 00 ...H.,$H.,$..... 0x0020 00 00 3c 01 77 02 eb 09 48 8b 2c 24 48 83 c4 08 ..<.w...H.,$H... 0x0030 c3 0f b6 05 00 00 00 00 3c 01 74 02 eb 07 e8 00 ........<.t..... 0x0040 00 00 00 0f 0b c6 05 00 00 00 00 01 e8 00 00 00 ................ 0x0050 00 c6 05 00 00 00 00 02 48 8b 2c 24 48 83 c4 08 ........H.,$H... 0x0060 c3 e8 00 00 00 00 eb 98 ........ rel 5+4 t=16 TLS+0 rel 30+4 t=15 "".initdone·+0 rel 52+4 t=15 "".initdone·+0 rel 63+4 t=8 runtime.throwinit+0 rel 71+4 t=15 "".initdone·+-1 rel 77+4 t=8 time.init+0 rel 83+4 t=15 "".initdone·+-1 rel 98+4 t=8 runtime.morestack_noctxt+0 go.info."".main SDWARFINFO size=45 0x0000 02 22 22 2e 6d 61 69 6e 00 00 00 00 00 00 00 00 ."".main........ 0x0010 00 00 00 00 00 00 00 00 00 01 9c 01 04 63 54 69 .............cTi 0x0020 6d 65 00 04 9c 11 68 22 00 00 00 00 00 me....h"..... rel 9+8 t=1 "".main+0 rel 17+8 t=1 "".main+89 rel 40+4 t=28 go.info.*time.Timer+0 go.range."".main SDWARFRANGE size=0 go.info."".init SDWARFINFO size=29 0x0000 02 22 22 2e 69 6e 69 74 00 00 00 00 00 00 00 00 ."".init........ 0x0010 00 00 00 00 00 00 00 00 00 01 9c 01 00 ............. rel 9+8 t=1 "".init+0 rel 17+8 t=1 "".init+104 go.range."".init SDWARFRANGE size=0 "".initdone· SNOPTRBSS size=1 type..importpath.time. SRODATA dupok size=7 0x0000 00 00 04 74 69 6d 65 ...time gclocals·33cdeccccebe80329f1fdbee7f5874cb SRODATA dupok size=8 0x0000 01 00 00 00 00 00 00 00 ........ gclocals·2a5305abe05176240e61b8620e19a815 SRODATA dupok size=9 0x0000 01 00 00 00 01 00 00 00 00 ......... ``` //版本1.11 ``` "".main STEXT size=89 args=0x0 locals=0x28 0x0000 00000 (demo.go:7) TEXT "".main(SB), $40-0 0x0000 00000 (demo.go:7) MOVQ (TLS), CX 0x0009 00009 (demo.go:7) CMPQ SP, 16(CX) 0x000d 00013 (demo.go:7) JLS 82 0x000f 00015 (demo.go:7) SUBQ $40, SP 0x0013 00019 (demo.go:7) MOVQ BP, 32(SP) 0x0018 00024 (demo.go:7) LEAQ 32(SP), BP 0x001d 00029 (demo.go:7) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001d 00029 (demo.go:7) FUNCDATA $1, gclocals·2a5305abe05176240e61b8620e19a815(SB) 0x001d 00029 (demo.go:7) FUNCDATA $3, gclocals·9fb7f0986f647f17cb53dda1484e0f7a(SB) 0x001d 00029 (demo.go:8) PCDATA $2, $0 0x001d 00029 (demo.go:8) PCDATA $0, $0 0x001d 00029 (demo.go:8) MOVL $3000000000, AX 0x0022 00034 (demo.go:8) MOVQ AX, (SP) 0x0026 00038 (demo.go:8) CALL time.NewTimer(SB) 0x002b 00043 (demo.go:8) PCDATA $2, $1 0x002b 00043 (demo.go:8) MOVQ 8(SP), AX 0x0030 00048 (demo.go:8) MOVQ AX, "".cTime+24(SP) 0x0035 00053 (demo.go:9) PCDATA $2, $0 0x0035 00053 (demo.go:9) MOVQ AX, (SP) 0x0039 00057 (demo.go:9) MOVL $3000000000, AX 0x003e 00062 (demo.go:9) MOVQ AX, 8(SP) 0x0043 00067 (demo.go:9) CALL time.(*Timer).Reset(SB) 0x0048 00072 (demo.go:10) MOVQ 32(SP), BP 0x004d 00077 (demo.go:10) ADDQ $40, SP 0x0051 00081 (demo.go:10) RET 0x0052 00082 (demo.go:10) NOP 0x0052 00082 (demo.go:7) PCDATA $0, $-1 0x0052 00082 (demo.go:7) PCDATA $2, $-1 0x0052 00082 (demo.go:7) CALL runtime.morestack_noctxt(SB) 0x0057 00087 (demo.go:7) JMP 0 0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 43 48 dH..%....H;a.vCH 0x0010 83 ec 28 48 89 6c 24 20 48 8d 6c 24 20 b8 00 5e ..(H.l$ H.l$ ..^ 0x0020 d0 b2 48 89 04 24 e8 00 00 00 00 48 8b 44 24 08 ..H..$.....H.D$. 0x0030 48 89 44 24 18 48 89 04 24 b8 00 5e d0 b2 48 89 H.D$.H..$..^..H. 0x0040 44 24 08 e8 00 00 00 00 48 8b 6c 24 20 48 83 c4 D$......H.l$ H.. 0x0050 28 c3 e8 00 00 00 00 eb a7 (........ rel 5+4 t=16 TLS+0 rel 39+4 t=8 time.NewTimer+0 rel 68+4 t=8 time.(*Timer).Reset+0 rel 83+4 t=8 runtime.morestack_noctxt+0 "".init STEXT size=100 args=0x0 locals=0x8 0x0000 00000 (<autogenerated>:1) TEXT "".init(SB), $8-0 0x0000 00000 (<autogenerated>:1) MOVQ (TLS), CX 0x0009 00009 (<autogenerated>:1) CMPQ SP, 16(CX) 0x000d 00013 (<autogenerated>:1) JLS 93 0x000f 00015 (<autogenerated>:1) SUBQ $8, SP 0x0013 00019 (<autogenerated>:1) MOVQ BP, (SP) 0x0017 00023 (<autogenerated>:1) LEAQ (SP), BP 0x001b 00027 (<autogenerated>:1) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001b 00027 (<autogenerated>:1) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001b 00027 (<autogenerated>:1) FUNCDATA $3, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) 0x001b 00027 (<autogenerated>:1) PCDATA $2, $0 0x001b 00027 (<autogenerated>:1) PCDATA $0, $0 0x001b 00027 (<autogenerated>:1) CMPB "".initdone·(SB), $1 0x0022 00034 (<autogenerated>:1) JHI 38 0x0024 00036 (<autogenerated>:1) JMP 47 0x0026 00038 (<autogenerated>:1) PCDATA $2, $-2 0x0026 00038 (<autogenerated>:1) PCDATA $0, $-2 0x0026 00038 (<autogenerated>:1) MOVQ (SP), BP 0x002a 00042 (<autogenerated>:1) ADDQ $8, SP 0x002e 00046 (<autogenerated>:1) RET 0x002f 00047 (<autogenerated>:1) PCDATA $2, $0 0x002f 00047 (<autogenerated>:1) PCDATA $0, $0 0x002f 00047 (<autogenerated>:1) CMPB "".initdone·(SB), $1 0x0036 00054 (<autogenerated>:1) JEQ 58 0x0038 00056 (<autogenerated>:1) JMP 65 0x003a 00058 (<autogenerated>:1) CALL runtime.throwinit(SB) 0x003f 00063 (<autogenerated>:1) UNDEF 0x0041 00065 (<autogenerated>:1) MOVB $1, "".initdone·(SB) 0x0048 00072 (<autogenerated>:1) CALL time.init(SB) 0x004d 00077 (<autogenerated>:1) MOVB $2, "".initdone·(SB) 0x0054 00084 (<autogenerated>:1) MOVQ (SP), BP 0x0058 00088 (<autogenerated>:1) ADDQ $8, SP 0x005c 00092 (<autogenerated>:1) RET 0x005d 00093 (<autogenerated>:1) NOP 0x005d 00093 (<autogenerated>:1) PCDATA $0, $-1 0x005d 00093 (<autogenerated>:1) PCDATA $2, $-1 0x005d 00093 (<autogenerated>:1) CALL runtime.morestack_noctxt(SB) 0x0062 00098 (<autogenerated>:1) JMP 0 0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 4e 48 dH..%....H;a.vNH 0x0010 83 ec 08 48 89 2c 24 48 8d 2c 24 80 3d 00 00 00 ...H.,$H.,$.=... 0x0020 00 01 77 02 eb 09 48 8b 2c 24 48 83 c4 08 c3 80 ..w...H.,$H..... 0x0030 3d 00 00 00 00 01 74 02 eb 07 e8 00 00 00 00 0f =.....t......... 0x0040 0b c6 05 00 00 00 00 01 e8 00 00 00 00 c6 05 00 ................ 0x0050 00 00 00 02 48 8b 2c 24 48 83 c4 08 c3 e8 00 00 ....H.,$H....... 0x0060 00 00 eb 9c .... rel 5+4 t=16 TLS+0 rel 29+4 t=15 "".initdone·+-1 rel 49+4 t=15 "".initdone·+-1 rel 59+4 t=8 runtime.throwinit+0 rel 67+4 t=15 "".initdone·+-1 rel 73+4 t=8 time.init+0 rel 79+4 t=15 "".initdone·+-1 rel 94+4 t=8 runtime.morestack_noctxt+0 go.loc."".main SDWARFLOC size=0 go.info."".main SDWARFINFO size=48 0x0000 02 22 22 2e 6d 61 69 6e 00 00 00 00 00 00 00 00 ."".main........ 0x0010 00 00 00 00 00 00 00 00 00 01 9c 00 00 00 00 01 ................ 0x0020 09 63 54 69 6d 65 00 08 00 00 00 00 02 91 68 00 .cTime........h. rel 9+8 t=1 "".main+0 rel 17+8 t=1 "".main+89 rel 27+4 t=29 gofile../media/sf_work/joserver/jojoserver/src/demo/demo.go+0 rel 40+4 t=28 go.info.*time.Timer+0 go.range."".main SDWARFRANGE size=0 go.isstmt."".main SDWARFMISC size=0 0x0000 04 0f 04 0e 03 05 01 13 02 04 01 0f 02 11 00 ............... go.loc."".init SDWARFLOC size=0 go.info."".init SDWARFINFO size=33 0x0000 02 22 22 2e 69 6e 69 74 00 00 00 00 00 00 00 00 ."".init........ 0x0010 00 00 00 00 00 00 00 00 00 01 9c 00 00 00 00 01 ................ 0x0020 00 . rel 9+8 t=1 "".init+0 rel 17+8 t=1 "".init+100 rel 27+4 t=29 gofile..<autogenerated>+0 go.range."".init SDWARFRANGE size=0 go.isstmt."".init SDWARFMISC size=0 0x0000 04 0f 04 0c 03 07 01 04 02 09 01 10 02 09 01 15 ................ 0x0010 02 07 00 ... "".initdone· SNOPTRBSS size=1 type..importpath.time. SRODATA dupok size=7 0x0000 00 00 04 74 69 6d 65 ...time gclocals·33cdeccccebe80329f1fdbee7f5874cb SRODATA dupok size=8 0x0000 01 00 00 00 00 00 00 00 ........ gclocals·2a5305abe05176240e61b8620e19a815 SRODATA dupok size=9 0x0000 01 00 00 00 01 00 00 00 00 ......... gclocals·9fb7f0986f647f17cb53dda1484e0f7a SRODATA dupok size=10 0x0000 02 00 00 00 01 00 00 00 00 01 .......... ```

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

788 次点击  
加入收藏 微博
1 回复  |  直到 2018-11-21 16:53:36
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传