]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/objfile: add ppc64/ppc64le disassembler support
authorShenghou Ma <minux@golang.org>
Mon, 4 May 2015 05:21:27 +0000 (01:21 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 13 Oct 2016 00:11:22 +0000 (00:11 +0000)
Change-Id: I7d213b4f8e4cda73ea7687fb97dbd22e58163948
Reviewed-on: https://go-review.googlesource.com/9682
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/objfile/disasm.go
src/cmd/internal/objfile/elf.go

index 771187bfe4a1c93058b76e51a924a44d0f26e71d..315aaed2ab2e535f12c331b099a21c4eddd237d8 100644 (file)
@@ -16,6 +16,7 @@ import (
        "text/tabwriter"
 
        "golang.org/x/arch/arm/armasm"
+       "golang.org/x/arch/ppc64/ppc64asm"
        "golang.org/x/arch/x86/x86asm"
 )
 
@@ -49,6 +50,7 @@ func (f *File) Disasm() (*Disasm, error) {
        }
 
        goarch := f.GOARCH()
+       println("GOARCH", goarch)
        disasm := disasms[goarch]
        byteOrder := byteOrders[goarch]
        if disasm == nil || byteOrder == nil {
@@ -170,7 +172,7 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
        lookup := d.lookup
        for pc := start; pc < end; {
                i := pc - d.textStart
-               text, size := d.disasm(code[i:], pc, lookup)
+               text, size := d.disasm(code[i:], pc, lookup, d.byteOrder)
                file, line, _ := d.pcln.PCToLine(pc)
                text += "\t"
                first := true
@@ -189,13 +191,13 @@ func (d *Disasm) Decode(start, end uint64, relocs []Reloc, f func(pc, size uint6
 }
 
 type lookupFunc func(addr uint64) (sym string, base uint64)
-type disasmFunc func(code []byte, pc uint64, lookup lookupFunc) (text string, size int)
+type disasmFunc func(code []byte, pc uint64, lookup lookupFunc, ord binary.ByteOrder) (text string, size int)
 
-func disasm_386(code []byte, pc uint64, lookup lookupFunc) (string, int) {
+func disasm_386(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
        return disasm_x86(code, pc, lookup, 32)
 }
 
-func disasm_amd64(code []byte, pc uint64, lookup lookupFunc) (string, int) {
+func disasm_amd64(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
        return disasm_x86(code, pc, lookup, 64)
 }
 
@@ -232,7 +234,7 @@ func (r textReader) ReadAt(data []byte, off int64) (n int, err error) {
        return
 }
 
-func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) {
+func disasm_arm(code []byte, pc uint64, lookup lookupFunc, _ binary.ByteOrder) (string, int) {
        inst, err := armasm.Decode(code, armasm.ModeARM)
        var text string
        size := inst.Len
@@ -245,10 +247,25 @@ func disasm_arm(code []byte, pc uint64, lookup lookupFunc) (string, int) {
        return text, size
 }
 
+func disasm_ppc64(code []byte, pc uint64, lookup lookupFunc, byteOrder binary.ByteOrder) (string, int) {
+       inst, err := ppc64asm.Decode(code, byteOrder)
+       var text string
+       size := inst.Len
+       if err != nil || size == 0 || inst.Op == 0 {
+               size = 4
+               text = "?"
+       } else {
+               text = ppc64asm.GoSyntax(inst, pc, lookup)
+       }
+       return text, size
+}
+
 var disasms = map[string]disasmFunc{
-       "386":   disasm_386,
-       "amd64": disasm_amd64,
-       "arm":   disasm_arm,
+       "386":     disasm_386,
+       "amd64":   disasm_amd64,
+       "arm":     disasm_arm,
+       "ppc64":   disasm_ppc64,
+       "ppc64le": disasm_ppc64,
 }
 
 var byteOrders = map[string]binary.ByteOrder{
index c8114603d790b3e442138fbf34dfdf4e679010ca..4ab7e6deb812e0ce1d0a57efbd6576ef7bed8b9a 100644 (file)
@@ -9,6 +9,7 @@ package objfile
 import (
        "debug/dwarf"
        "debug/elf"
+       "encoding/binary"
        "fmt"
        "os"
 )
@@ -99,6 +100,9 @@ func (f *elfFile) goarch() string {
        case elf.EM_ARM:
                return "arm"
        case elf.EM_PPC64:
+               if f.elf.ByteOrder == binary.LittleEndian {
+                       return "ppc64le"
+               }
                return "ppc64"
        case elf.EM_S390:
                return "s390x"