Skip to content

Commit

Permalink
cmd/compile: fix disassembly of invalid instructions
Browse files Browse the repository at this point in the history
Make sure that if we encode an explicit base register, we print it.
That will ensure that if we make an Addr with an auto variable but
a base that isn't SP, then it will be obvious from the disassembly.

Update #19184

Change-Id: If5556a5183f344d719ec7197aa935a0166061e6f
Reviewed-on: https://go-review.googlesource.com/37255
Reviewed-by: Cherry Zhang <cherryyz@google.com>
  • Loading branch information
randall77 committed Mar 1, 2017
1 parent ffe923f commit 1eed80f
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/cmd/internal/obj/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,39 +312,60 @@ func Mconv(a *Addr) string {
str = fmt.Sprintf("%d(%v)", a.Offset, Rconv(int(a.Reg)))
}

// Note: a.Reg == REG_NONE encodes the default base register for the NAME_ type.
case NAME_EXTERN:
reg := "SB"
if a.Reg != REG_NONE {
reg = Rconv(int(a.Reg))
}
if a.Sym != nil {
str = fmt.Sprintf("%s%s(SB)", a.Sym.Name, offConv(a.Offset))
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
} else {
str = fmt.Sprintf("%s(SB)", offConv(a.Offset))
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
}

case NAME_GOTREF:
reg := "SB"
if a.Reg != REG_NONE {
reg = Rconv(int(a.Reg))
}
if a.Sym != nil {
str = fmt.Sprintf("%s%s@GOT(SB)", a.Sym.Name, offConv(a.Offset))
str = fmt.Sprintf("%s%s@GOT(%s)", a.Sym.Name, offConv(a.Offset), reg)
} else {
str = fmt.Sprintf("%s@GOT(SB)", offConv(a.Offset))
str = fmt.Sprintf("%s@GOT(%s)", offConv(a.Offset), reg)
}

case NAME_STATIC:
reg := "SB"
if a.Reg != REG_NONE {
reg = Rconv(int(a.Reg))
}
if a.Sym != nil {
str = fmt.Sprintf("%s<>%s(SB)", a.Sym.Name, offConv(a.Offset))
str = fmt.Sprintf("%s<>%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
} else {
str = fmt.Sprintf("<>%s(SB)", offConv(a.Offset))
str = fmt.Sprintf("<>%s(%s)", offConv(a.Offset), reg)
}

case NAME_AUTO:
reg := "SP"
if a.Reg != REG_NONE {
reg = Rconv(int(a.Reg))
}
if a.Sym != nil {
str = fmt.Sprintf("%s%s(SP)", a.Sym.Name, offConv(a.Offset))
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
} else {
str = fmt.Sprintf("%s(SP)", offConv(a.Offset))
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
}

case NAME_PARAM:
reg := "FP"
if a.Reg != REG_NONE {
reg = Rconv(int(a.Reg))
}
if a.Sym != nil {
str = fmt.Sprintf("%s%s(FP)", a.Sym.Name, offConv(a.Offset))
str = fmt.Sprintf("%s%s(%s)", a.Sym.Name, offConv(a.Offset), reg)
} else {
str = fmt.Sprintf("%s(FP)", offConv(a.Offset))
str = fmt.Sprintf("%s(%s)", offConv(a.Offset), reg)
}
}
return str
Expand Down

0 comments on commit 1eed80f

Please sign in to comment.