duanche9384 2017-08-29 10:45
浏览 145

使用golang汇编语言对golang方法进行下划线实现

I wrote a simple go package as follows:

package mytest

type T int32

func (a T) MyTest(b T) (T, T)
func (p *T) MyTestp(b T) (T, T)
func MyTest(a, b T) (T, T)
func MyTestp(p *T, b T) (T, T)

The corresponding assembly code(generated by go tool objdump), as follows:

TEXT ·MyTest(SB), $0-16
MOVL a + 0x0(FP), AX
MOVL b + 0x4(FP), BX
MOVL BX, CX
ADDL AX, CX
MOVL CX, r1 + 0x8(FP)
SUBL BX, AX
MOVL AX, r2 + 0xc(FP)
RET

TEXT ·MyTestp(SB), $0-24
MOVQ p + 0x0(FP), CX
MOVL b + 0x8(FP), BX
MOVL (CX), AX
MOVL BX, CX
ADDL AX, CX
MOVL CX, r1 + 0x10(FP)
SUBL BX, AX
MOVL AX, r2 + 0x14(FP)
RET

TEXT ·T·MyTest(SB), $0-16
MOVL a + 0x0(FP), AX
MOVL b + 0x4(FP), BX
MOVL BX, CX
ADDL AX, CX
MOVL CX, r1 + 0x8(FP)
SUBL BX, AX
MOVL AX, r2 + 0xc(FP)
RET

TEXT ·(*T)·MyTestp(SB), $0-24
MOVQ p + 0x0(FP), CX
MOVL b + 0x8(FP), BX
MOVL (CX), AX
MOVL BX, CX
ADDL AX, CX
MOVL CX, r1 + 0xC(FP)
SUBL BX, AX
MOVL AX, r2 + 0x10(FP)
RET

when I compile these assembly code, all is ok except "TEXT ·(*T)·MyTestp(SB), $0-24", error message as follows:

expected identifier, found *

I think objdump using a readable denotion (*T) for output, but for complier, it is wrong. so any one know the correct denotion? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • doutuo1939 2017-09-17 06:43
    关注

    ok well you have 3 different tools you're talking about, as for go object dump it does dump the correct symbols. The go compiler compiles go source code and generates symbols such as the above. The go assembler can't use without modification symbols with '(', "*", ")" and many others. When it see's the parentheses it expects what's inside to be a register. So you got a few options, like use a different assembler that supports symbols like that, you could modify the assembler to allow symbols like that or you could rename your symbols to something that the go assembler allows.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条