golang/go

cmd/asm: doesn't handle register offset correctly when GOARCH=arm

Open

#36,253 创建于 2019年12月23日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Go (19,008 fork)batch import
NeedsInvestigationcompiler/runtimehelp wanted

仓库指标

Star
 (133,883 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

What did you do?

main.go:

package main

import (
	"fmt"
)

func b()

func print32(i uint32) {
	fmt.Printf("0x%x\n", i)
}

func main() {
	b()
}

asm_arm.s:

#include "textflag.h"

TEXT ·b(SB), NOSPLIT, $4
    MOVW    $1, R0
    MOVW    $4, R1
    MOVW    R0, (R13)(R1)
    CALL    ·print32(SB)
    RET

then run,

objdump -d -df 'main.b' ./demo

and

go tool objdump -S -s 'main\.b' ./demo

./demo is the target executable file.

What did you expect to see?

main.b:
   b8e18:       08 e0 2d e5     str     lr, [sp, #-8]!
   b8e1c:       01 00 a0 e3     mov     r0, #1
   b8e20:       04 10 a0 e3     mov     r1, #4
   b8e24:       01 00 8d e7     str     r0, [sp, r1]
   b8e28:       c5 ff ff eb     bl      #-236 <main.print32>
   b8e2c:       08 f0 9d e4     ldr     pc, [sp], #8687 

and

TEXT main.b(SB) 
  0xb8e18               e52de008                MOVW.W R14, -0x8(R13)   
  0xb8e1c               e3a00001                MOVW $1, R0             
  0xb8e20               e3a01004                MOVW $4, R1             
  0xb8e24               e78d0001                MOVW R0, (R13)(R1)      
  0xb8e28               ebffffc5                BL main.print32(SB)     
  0xb8e2c               e49df008                RET #8 

What did you see instead?

main.b:
   b8e18:       08 e0 2d e5     str     lr, [sp, #-8]!
   b8e1c:       01 00 a0 e3     mov     r0, #1
   b8e20:       04 10 a0 e3     mov     r1, #4
   b8e24:       00 00 8d e5     str     r0, [sp]
   b8e28:       c5 ff ff eb     bl      #-236 <main.print32>
   b8e2c:       08 f0 9d e4     ldr     pc, [sp], #8

and

TEXT main.b(SB) 
  0xb8e18               e52de008                MOVW.W R14, -0x8(R13)   
  0xb8e1c               e3a00001                MOVW $1, R0             
  0xb8e20               e3a01004                MOVW $4, R1             
  0xb8e24               e58d0000                MOVW R0, (R13)          
  0xb8e28               ebffffc5                BL main.print32(SB)     
  0xb8e2c               e49df008                RET #8 

don't know why the code of register offset was lost?

MOVW    R0, (R13)(R1)

change into

MOVW    R0, (R13)

贡献者指南