aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi Ioka <hirochachacha@gmail.com>2017-08-16 20:50:26 +0900
committerIan Lance Taylor <iant@golang.org>2017-08-16 22:22:19 +0000
commit78984d3954a60f446d04c796f9c22e073f07cbd3 (patch)
tree12f4f2c662a9f95a6da81c6471bbe0872a36f794
parent3ce05d2d8d6dbdbec527a9aa49085558bbe05ec0 (diff)
downloadgo-78984d3954a60f446d04c796f9c22e073f07cbd3.tar.gz
go-78984d3954a60f446d04c796f9c22e073f07cbd3.zip
debug/macho: rearrange code
* group load command structs. * use hex literal for LoadCommand. Decimal number is not a proper representation for some commands. (e.g. LC_RPATH = 0x8000001c) * move Symbol struct from macho.go to file.go. Symbol is a high level representation, not in Mach-O. Change-Id: I3c69923cb464fb1211f2e766c02e1b537e0b5de2 Reviewed-on: https://go-review.googlesource.com/56130 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/debug/macho/file.go9
-rw-r--r--src/debug/macho/macho.go191
2 files changed, 101 insertions, 99 deletions
diff --git a/src/debug/macho/file.go b/src/debug/macho/file.go
index 223346f10d..306e9ae1da 100644
--- a/src/debug/macho/file.go
+++ b/src/debug/macho/file.go
@@ -143,6 +143,15 @@ type Dysymtab struct {
IndirectSyms []uint32 // indices into Symtab.Syms
}
+// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
+type Symbol struct {
+ Name string
+ Type uint8
+ Sect uint8
+ Desc uint16
+ Value uint64
+}
+
/*
* Mach-O reader
*/
diff --git a/src/debug/macho/macho.go b/src/debug/macho/macho.go
index 6535ba787b..0010775f45 100644
--- a/src/debug/macho/macho.go
+++ b/src/debug/macho/macho.go
@@ -79,14 +79,14 @@ func (i Cpu) GoString() string { return stringName(uint32(i), cpuStrings, true)
type LoadCmd uint32
const (
- LoadCmdSegment LoadCmd = 1
- LoadCmdSymtab LoadCmd = 2
- LoadCmdThread LoadCmd = 4
- LoadCmdUnixThread LoadCmd = 5 // thread+stack
- LoadCmdDysymtab LoadCmd = 11
- LoadCmdDylib LoadCmd = 12
- LoadCmdDylinker LoadCmd = 15
- LoadCmdSegment64 LoadCmd = 25
+ LoadCmdSegment LoadCmd = 0x1
+ LoadCmdSymtab LoadCmd = 0x2
+ LoadCmdThread LoadCmd = 0x4
+ LoadCmdUnixThread LoadCmd = 0x5 // thread+stack
+ LoadCmdDysymtab LoadCmd = 0xb
+ LoadCmdDylib LoadCmd = 0xc
+ LoadCmdDylinker LoadCmd = 0xf
+ LoadCmdSegment64 LoadCmd = 0x19
)
var cmdStrings = []intName{
@@ -100,6 +100,90 @@ var cmdStrings = []intName{
func (i LoadCmd) String() string { return stringName(uint32(i), cmdStrings, false) }
func (i LoadCmd) GoString() string { return stringName(uint32(i), cmdStrings, true) }
+type (
+ // A Segment32 is a 32-bit Mach-O segment load command.
+ Segment32 struct {
+ Cmd LoadCmd
+ Len uint32
+ Name [16]byte
+ Addr uint32
+ Memsz uint32
+ Offset uint32
+ Filesz uint32
+ Maxprot uint32
+ Prot uint32
+ Nsect uint32
+ Flag uint32
+ }
+
+ // A Segment64 is a 64-bit Mach-O segment load command.
+ Segment64 struct {
+ Cmd LoadCmd
+ Len uint32
+ Name [16]byte
+ Addr uint64
+ Memsz uint64
+ Offset uint64
+ Filesz uint64
+ Maxprot uint32
+ Prot uint32
+ Nsect uint32
+ Flag uint32
+ }
+
+ // A SymtabCmd is a Mach-O symbol table command.
+ SymtabCmd struct {
+ Cmd LoadCmd
+ Len uint32
+ Symoff uint32
+ Nsyms uint32
+ Stroff uint32
+ Strsize uint32
+ }
+
+ // A DysymtabCmd is a Mach-O dynamic symbol table command.
+ DysymtabCmd struct {
+ Cmd LoadCmd
+ Len uint32
+ Ilocalsym uint32
+ Nlocalsym uint32
+ Iextdefsym uint32
+ Nextdefsym uint32
+ Iundefsym uint32
+ Nundefsym uint32
+ Tocoffset uint32
+ Ntoc uint32
+ Modtaboff uint32
+ Nmodtab uint32
+ Extrefsymoff uint32
+ Nextrefsyms uint32
+ Indirectsymoff uint32
+ Nindirectsyms uint32
+ Extreloff uint32
+ Nextrel uint32
+ Locreloff uint32
+ Nlocrel uint32
+ }
+
+ // A DylibCmd is a Mach-O load dynamic library command.
+ DylibCmd struct {
+ Cmd LoadCmd
+ Len uint32
+ Name uint32
+ Time uint32
+ CurrentVersion uint32
+ CompatVersion uint32
+ }
+
+ // A Thread is a Mach-O thread state command.
+ Thread struct {
+ Cmd LoadCmd
+ Len uint32
+ Type uint32
+ Data []uint32
+ }
+)
+
const (
FlagNoUndefs uint32 = 0x1
FlagDyldLink uint32 = 0x4
@@ -107,46 +191,6 @@ const (
FlagPIE uint32 = 0x200000
)
-// A Segment64 is a 64-bit Mach-O segment load command.
-type Segment64 struct {
- Cmd LoadCmd
- Len uint32
- Name [16]byte
- Addr uint64
- Memsz uint64
- Offset uint64
- Filesz uint64
- Maxprot uint32
- Prot uint32
- Nsect uint32
- Flag uint32
-}
-
-// A Segment32 is a 32-bit Mach-O segment load command.
-type Segment32 struct {
- Cmd LoadCmd
- Len uint32
- Name [16]byte
- Addr uint32
- Memsz uint32
- Offset uint32
- Filesz uint32
- Maxprot uint32
- Prot uint32
- Nsect uint32
- Flag uint32
-}
-
-// A DylibCmd is a Mach-O load dynamic library command.
-type DylibCmd struct {
- Cmd LoadCmd
- Len uint32
- Name uint32
- Time uint32
- CurrentVersion uint32
- CompatVersion uint32
-}
-
// A Section32 is a 32-bit Mach-O section header.
type Section32 struct {
Name [16]byte
@@ -178,40 +222,6 @@ type Section64 struct {
Reserve3 uint32
}
-// A SymtabCmd is a Mach-O symbol table command.
-type SymtabCmd struct {
- Cmd LoadCmd
- Len uint32
- Symoff uint32
- Nsyms uint32
- Stroff uint32
- Strsize uint32
-}
-
-// A DysymtabCmd is a Mach-O dynamic symbol table command.
-type DysymtabCmd struct {
- Cmd LoadCmd
- Len uint32
- Ilocalsym uint32
- Nlocalsym uint32
- Iextdefsym uint32
- Nextdefsym uint32
- Iundefsym uint32
- Nundefsym uint32
- Tocoffset uint32
- Ntoc uint32
- Modtaboff uint32
- Nmodtab uint32
- Extrefsymoff uint32
- Nextrefsyms uint32
- Indirectsymoff uint32
- Nindirectsyms uint32
- Extreloff uint32
- Nextrel uint32
- Locreloff uint32
- Nlocrel uint32
-}
-
// An Nlist32 is a Mach-O 32-bit symbol table entry.
type Nlist32 struct {
Name uint32
@@ -230,23 +240,6 @@ type Nlist64 struct {
Value uint64
}
-// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
-type Symbol struct {
- Name string
- Type uint8
- Sect uint8
- Desc uint16
- Value uint64
-}
-
-// A Thread is a Mach-O thread state command.
-type Thread struct {
- Cmd LoadCmd
- Len uint32
- Type uint32
- Data []uint32
-}
-
// Regs386 is the Mach-O 386 register structure.
type Regs386 struct {
AX uint32