x86: use symname also for IP-relative arguments

Change-Id: Ic291e8b284290f29dd586415a873fbf90bafcac9
Reviewed-on: https://go-review.googlesource.com/45099
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
aarzilli 2017-06-08 22:18:31 +02:00 коммит произвёл Cherry Zhang
Родитель ec321f9a9f
Коммит 7bacdd692e
4 изменённых файлов: 43 добавлений и 10 удалений

Просмотреть файл

@ -13,6 +13,8 @@ func testFormattingSymname(addr uint64) (string, uint64) {
switch addr {
case 0x424080:
return "runtime.printint", 0x424080
case 0x4c8068:
return "main.A", 0x4c8068
}
return "", 0
}
@ -33,9 +35,9 @@ func TestFormatting(t *testing.T) {
"mov rax, qword ptr [rsp+0x8]",
"mov 0x8(%rsp),%rax"},
{0x450678, "488b05e9790700",
"MOVQ 0x779e9(IP), AX",
"mov rax, qword ptr [rip+0x779e9]",
"mov 0x779e9(%rip),%rax"},
"MOVQ main.A(SB), AX",
"mov rax, qword ptr [main.A]",
"mov main.A,%rax"},
{0x450664, "e8173afdff",
"CALL runtime.printint(SB)",
"call runtime.printint",

Просмотреть файл

@ -539,6 +539,13 @@ func gnuArg(inst *Inst, pc uint64, symname SymLookup, x Arg, usedPrefixes *bool)
}
return gccRegName[x]
case Mem:
if s, disp := memArgToSymbol(x, pc, inst.Len, symname); s != "" {
suffix := ""
if disp != 0 {
suffix = fmt.Sprintf("%+d", disp)
}
return fmt.Sprintf("%s%s", s, suffix)
}
seg := ""
var haveCS, haveDS, haveES, haveFS, haveGS, haveSS bool
switch x.Segment {

Просмотреть файл

@ -428,6 +428,13 @@ func intelArg(inst *Inst, pc uint64, symname SymLookup, arg Arg) string {
}
prefix += "ptr "
if s, disp := memArgToSymbol(a, pc, inst.Len, symname); s != "" {
suffix := ""
if disp != 0 {
suffix = fmt.Sprintf("%+d", disp)
}
return prefix + fmt.Sprintf("[%s%s]", s, suffix)
}
if a.Segment != 0 {
prefix += strings.ToLower(a.Segment.String()) + ":"
}

Просмотреть файл

@ -121,14 +121,12 @@ func plan9Arg(inst *Inst, pc uint64, symname func(uint64) (string, uint64), arg
}
return fmt.Sprintf("$%#x", uint64(a))
case Mem:
if a.Segment == 0 && a.Disp != 0 && a.Base == 0 && (a.Index == 0 || a.Scale == 0) {
if s, base := symname(uint64(a.Disp)); s != "" {
suffix := ""
if uint64(a.Disp) != base {
suffix = fmt.Sprintf("%+d", uint64(a.Disp)-base)
}
return fmt.Sprintf("%s%s(SB)", s, suffix)
if s, disp := memArgToSymbol(a, pc, inst.Len, symname); s != "" {
suffix := ""
if disp != 0 {
suffix = fmt.Sprintf("%+d", disp)
}
return fmt.Sprintf("%s%s(SB)", s, suffix)
}
s := ""
if a.Segment != 0 {
@ -150,6 +148,25 @@ func plan9Arg(inst *Inst, pc uint64, symname func(uint64) (string, uint64), arg
return arg.String()
}
func memArgToSymbol(a Mem, pc uint64, instrLen int, symname SymLookup) (string, int64) {
if a.Segment != 0 || a.Disp == 0 || a.Index != 0 || a.Scale != 0 {
return "", 0
}
var disp uint64
switch a.Base {
case IP, EIP, RIP:
disp = uint64(a.Disp + int64(pc) + int64(instrLen))
case 0:
disp = uint64(a.Disp)
default:
return "", 0
}
s, base := symname(disp)
return s, int64(disp) - int64(base)
}
var plan9Suffix = [maxOp + 1]bool{
ADC: true,
ADD: true,