go语言编译
main.go文件
package main
import "fmt"
func main() {
x,y:=1,2
x,y=y+1,x+2
fmt.Println(x,y)
}
编译:
方法一: go tool compile
使用go tool compile -N -l -S main.go生成汇编代码: 会生成main.o
方法二: go build -gcflags -S
使用go build -gcflags -S main.go也可以得到汇编代码:生成main 二进制文件
方法三: go tool objdump
首先先编译程序: go tool compile -N -l main.go,
使用go tool objdump main.o反汇编出代码
或 go tool objdump -s main main.o反汇编特定的函数
TEXT %22%22.main(SB) gofile..D:/10GoWorkSpace/src/github.com/siduoge2/learngo/main.go
main.go:5 0x6e8 65488b0c2528000000 MOVQ GS:0x28, CX
main.go:5 0x6f1 488b8900000000 MOVQ 0(CX), CX [3:7]R_TLS_LE
main.go:5 0x6f8 488d4424d8 LEAQ -0x28(SP), AX
main.go:5 0x6fd 483b4110 CMPQ 0x10(CX), AX
main.go:5 0x701 0f862e010000 JBE 0x835
main.go:5 0x707 4881eca8000000 SUBQ $0xa8, SP
main.go:5 0x70e 4889ac24a0000000 MOVQ BP, 0xa0(SP)
main.go:5 0x716 488dac24a0000000 LEAQ 0xa0(SP), BP
main.go:6 0x71e 48c744243801000000 MOVQ $0x1, 0x38(SP)
main.go:6 0x727 48c744243002000000 MOVQ $0x2, 0x30(SP)
main.go:7 0x730 48c744244803000000 MOVQ $0x3, 0x48(SP)
main.go:7 0x739 488b442438 MOVQ 0x38(SP), AX
main.go:7 0x73e 4883c002 ADDQ $0x2, AX
main.go:7 0x742 4889442440 MOVQ AX, 0x40(SP)
main.go:7 0x747 488b442448 MOVQ 0x48(SP), AX
main.go:7 0x74c 4889442438 MOVQ AX, 0x38(SP)
main.go:7 0x751 488b442440 MOVQ 0x40(SP), AX
main.go:7 0x756 4889442430 MOVQ AX, 0x30(SP)
main.go:9 0x75b 488b442438 MOVQ 0x38(SP), AX
main.go:9 0x760 48890424 MOVQ AX, 0(SP)
main.go:9 0x764 e800000000 CALL 0x769 [1:5]R_CALL:runtime.convT64
main.go:9 0x769 488b442408 MOVQ 0x8(SP), AX
main.go:9 0x76e 4889442460 MOVQ AX, 0x60(SP)
main.go:9 0x773 488b442430 MOVQ 0x30(SP), AX
main.go:9 0x778 48890424 MOVQ AX, 0(SP)
main.go:9 0x77c e800000000 CALL 0x781 [1:5]R_CALL:runtime.convT64
main.go:9 0x781 488b442408 MOVQ 0x8(SP), AX
main.go:9 0x786 4889442458 MOVQ AX, 0x58(SP)
main.go:9 0x78b 0f57c0 XORPS X0, X0
main.go:9 0x78e 0f11842480000000 MOVUPS X0, 0x80(SP)
main.go:9 0x796 0f57c0 XORPS X0, X0
main.go:9 0x799 0f11842490000000 MOVUPS X0, 0x90(SP)
main.go:9 0x7a1 488d842480000000 LEAQ 0x80(SP), AX
main.go:9 0x7a9 4889442450 MOVQ AX, 0x50(SP)
main.go:9 0x7ae 8400 TESTB AL, 0(AX)
main.go:9 0x7b0 488b4c2460 MOVQ 0x60(SP), CX
main.go:9 0x7b5 488d1500000000 LEAQ 0(IP), DX [3:7]R_PCREL:type.int
main.go:9 0x7bc 4889942480000000 MOVQ DX, 0x80(SP)
main.go:9 0x7c4 48898c2488000000 MOVQ CX, 0x88(SP)
main.go:9 0x7cc 8400 TESTB AL, 0(AX)
main.go:9 0x7ce 488b442458 MOVQ 0x58(SP), AX
main.go:9 0x7d3 488d0d00000000 LEAQ 0(IP), CX [3:7]R_PCREL:type.int
main.go:9 0x7da 48898c2490000000 MOVQ CX, 0x90(SP)
main.go:9 0x7e2 4889842498000000 MOVQ AX, 0x98(SP)
main.go:9 0x7ea 488b442450 MOVQ 0x50(SP), AX
main.go:9 0x7ef 8400 TESTB AL, 0(AX)
main.go:9 0x7f1 eb00 JMP 0x7f3
main.go:9 0x7f3 4889442468 MOVQ AX, 0x68(SP)
main.go:9 0x7f8 48c744247002000000 MOVQ $0x2, 0x70(SP)
main.go:9 0x801 48c744247802000000 MOVQ $0x2, 0x78(SP)
main.go:9 0x80a 48890424 MOVQ AX, 0(SP)
main.go:9 0x80e 48c744240802000000 MOVQ $0x2, 0x8(SP)
main.go:9 0x817 48c744241002000000 MOVQ $0x2, 0x10(SP)
main.go:9 0x820 e800000000 CALL 0x825 [1:5]R_CALL:fmt.Println
main.go:10 0x825 488bac24a0000000 MOVQ 0xa0(SP), BP
main.go:10 0x82d 4881c4a8000000 ADDQ $0xa8, SP
main.go:10 0x834 c3 RET
main.go:5 0x835 e800000000 CALL 0x83a [1:5]R_CALL:runtime.morestack_noctxt
main.go:5 0x83a e9a9feffff JMP %22%22.main(SB)
TEXT type..eq.[2]interface {}(SB) gofile..<autogenerated>
gofile..<autogenerated>:1 0x8a7 65488b0c2528000000 MOVQ GS:0x28, CX
gofile..<autogenerated>:1 0x8b0 488b8900000000 MOVQ 0(CX), CX [3:7]R_TLS_LE
gofile..<autogenerated>:1 0x8b7 483b6110 CMPQ 0x10(CX), SP
gofile..<autogenerated>:1 0x8bb 0f86db000000 JBE 0x99c
gofile..<autogenerated>:1 0x8c1 4883ec60 SUBQ $0x60, SP
gofile..<autogenerated>:1 0x8c5 48896c2458 MOVQ BP, 0x58(SP)
gofile..<autogenerated>:1 0x8ca 488d6c2458 LEAQ 0x58(SP), BP
gofile..<autogenerated>:1 0x8cf c644247800 MOVB $0x0, 0x78(SP)
gofile..<autogenerated>:1 0x8d4 48c744243000000000 MOVQ $0x0, 0x30(SP)
gofile..<autogenerated>:1 0x8dd 48c744242802000000 MOVQ $0x2, 0x28(SP)
gofile..<autogenerated>:1 0x8e6 eb00 JMP 0x8e8
gofile..<autogenerated>:1 0x8e8 488b442428 MOVQ 0x28(SP), AX
gofile..<autogenerated>:1 0x8ed 4839442430 CMPQ AX, 0x30(SP)
gofile..<autogenerated>:1 0x8f2 7c05 JL 0x8f9
gofile..<autogenerated>:1 0x8f4 e994000000 JMP 0x98d
gofile..<autogenerated>:1 0x8f9 488b442430 MOVQ 0x30(SP), AX
gofile..<autogenerated>:1 0x8fe 4889442420 MOVQ AX, 0x20(SP)
gofile..<autogenerated>:1 0x903 48c1e004 SHLQ $0x4, AX
gofile..<autogenerated>:1 0x907 4803442470 ADDQ 0x70(SP), AX
gofile..<autogenerated>:1 0x90c 488b4808 MOVQ 0x8(AX), CX
gofile..<autogenerated>:1 0x910 488b00 MOVQ 0(AX), AX
gofile..<autogenerated>:1 0x913 4889442448 MOVQ AX, 0x48(SP)
gofile..<autogenerated>:1 0x918 48894c2450 MOVQ CX, 0x50(SP)
gofile..<autogenerated>:1 0x91d 488b442420 MOVQ 0x20(SP), AX
gofile..<autogenerated>:1 0x922 48c1e004 SHLQ $0x4, AX
gofile..<autogenerated>:1 0x926 4803442468 ADDQ 0x68(SP), AX
gofile..<autogenerated>:1 0x92b 488b4808 MOVQ 0x8(AX), CX
gofile..<autogenerated>:1 0x92f 488b00 MOVQ 0(AX), AX
gofile..<autogenerated>:1 0x932 4889442438 MOVQ AX, 0x38(SP)
gofile..<autogenerated>:1 0x937 48894c2440 MOVQ CX, 0x40(SP)
gofile..<autogenerated>:1 0x93c 4839442448 CMPQ AX, 0x48(SP)
gofile..<autogenerated>:1 0x941 7502 JNE 0x945
gofile..<autogenerated>:1 0x943 eb11 JMP 0x956
gofile..<autogenerated>:1 0x945 eb00 JMP 0x947
gofile..<autogenerated>:1 0x947 c644247800 MOVB $0x0, 0x78(SP)
gofile..<autogenerated>:1 0x94c 488b6c2458 MOVQ 0x58(SP), BP
gofile..<autogenerated>:1 0x951 4883c460 ADDQ $0x60, SP
gofile..<autogenerated>:1 0x955 c3 RET
gofile..<autogenerated>:1 0x956 48890424 MOVQ AX, 0(SP)
gofile..<autogenerated>:1 0x95a 48894c2408 MOVQ CX, 0x8(SP)
gofile..<autogenerated>:1 0x95f 488b442450 MOVQ 0x50(SP), AX
gofile..<autogenerated>:1 0x964 4889442410 MOVQ AX, 0x10(SP)
gofile..<autogenerated>:1 0x969 e800000000 CALL 0x96e [1:5]R_CALL:runtime.efaceeq
gofile..<autogenerated>:1 0x96e 807c241800 CMPB $0x0, 0x18(SP)
gofile..<autogenerated>:1 0x973 7502 JNE 0x977
gofile..<autogenerated>:1 0x975 eb14 JMP 0x98b
gofile..<autogenerated>:1 0x977 eb00 JMP 0x979
gofile..<autogenerated>:1 0x979 488b442430 MOVQ 0x30(SP), AX
gofile..<autogenerated>:1 0x97e 48ffc0 INCQ AX
gofile..<autogenerated>:1 0x981 4889442430 MOVQ AX, 0x30(SP)
gofile..<autogenerated>:1 0x986 e95dffffff JMP 0x8e8
gofile..<autogenerated>:1 0x98b ebba JMP 0x947
gofile..<autogenerated>:1 0x98d c644247801 MOVB $0x1, 0x78(SP)
gofile..<autogenerated>:1 0x992 488b6c2458 MOVQ 0x58(SP), BP
gofile..<autogenerated>:1 0x997 4883c460 ADDQ $0x60, SP
gofile..<autogenerated>:1 0x99b c3 RET
gofile..<autogenerated>:1 0x99c e800000000 CALL 0x9a1 [1:5]R_CALL:runtime.morestack_no
ctxt
gofile..<autogenerated>:1 0x9a1 e901ffffff JMP type..eq.[2]interface {}(SB)