github.com/rsc/tmp@v0.0.0-20240517235954-6deaab19748b/go2asm/README (about) 1 Go2asm converts the Go compiler's -S output to equivalent assembler source 2 files. 3 4 Usage: 5 6 go2asm [-s symregexp] [file] 7 8 Go2asm reads the compiler's -S output from file (default standard input), 9 converting it to equivalent assembler input. If the -s option is present, 10 go2asm only converts symbols with names matching the regular expression. 11 12 13 Example 14 15 To extract the assembly for the function math.IsNaN: 16 17 $ go build -a -v -gcflags -S math 2>&1 | go2asm -s math.IsNaN 18 #include "funcdata.h" 19 20 TEXT math·IsNaN(SB), $0-16 // /Users/rsc/go/src/math/bits.go:31 21 NO_LOCAL_POINTERS 22 // FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB) (args) 23 // FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) (no locals) 24 MOVSD f+0(FP), X0 // bits.go:36 25 UCOMISD X0, X0 26 SETNE CL 27 SETPS AL 28 ORL AX, CX 29 MOVB CL, is+8(FP) 30 RET 31 $ 32 33 Or to extract the assembly for a test program: 34 35 $ cat /tmp/x.go 36 package p 37 38 func f(x int) (y int) { 39 return x 40 } 41 $ go tool compile -S /tmp/x.go | go2asm 42 #include "funcdata.h" 43 44 TEXT ·f(SB), $0-16 // /tmp/x.go:3 45 NO_LOCAL_POINTERS 46 // FUNCDATA $0, gclocals·f207267fbf96a0178e8758c6e3e0ce28(SB) (args) 47 // FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB) (no locals) 48 MOVQ $-3689348814741910323, AX // x.go:4 49 MOVQ x+0(FP), CX 50 IMULQ CX 51 ADDQ CX, DX 52 SARQ $3, DX 53 SARQ $63, CX 54 SUBQ CX, DX 55 MOVQ DX, y+8(FP) 56 RET 57 $ 58 59 60 Bugs 61 62 Go2asm only handles amd64 assembler. 63 64 Data symbols are not implemented.