URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [debug/] [macho/] [macho.go] - Rev 747
Compare with Previous | Blame | View Log
// Copyright 2009 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Mach-O header data structures// http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.htmlpackage machoimport "strconv"// A FileHeader represents a Mach-O file header.type FileHeader struct {Magic uint32Cpu CpuSubCpu uint32Type TypeNcmd uint32Cmdsz uint32Flags uint32}const (fileHeaderSize32 = 7 * 4fileHeaderSize64 = 8 * 4)const (Magic32 uint32 = 0xfeedfaceMagic64 uint32 = 0xfeedfacf)// A Type is a Mach-O file type, either an object or an executable.type Type uint32const (TypeObj Type = 1TypeExec Type = 2)// A Cpu is a Mach-O cpu type.type Cpu uint32const (Cpu386 Cpu = 7CpuAmd64 Cpu = Cpu386 + 1<<24)var cpuStrings = []intName{{uint32(Cpu386), "Cpu386"},{uint32(CpuAmd64), "CpuAmd64"},}func (i Cpu) String() string { return stringName(uint32(i), cpuStrings, false) }func (i Cpu) GoString() string { return stringName(uint32(i), cpuStrings, true) }// A LoadCmd is a Mach-O load command.type LoadCmd uint32const (LoadCmdSegment LoadCmd = 1LoadCmdSymtab LoadCmd = 2LoadCmdThread LoadCmd = 4LoadCmdUnixThread LoadCmd = 5 // thread+stackLoadCmdDysymtab LoadCmd = 11LoadCmdDylib LoadCmd = 12LoadCmdDylinker LoadCmd = 15LoadCmdSegment64 LoadCmd = 25)var cmdStrings = []intName{{uint32(LoadCmdSegment), "LoadCmdSegment"},{uint32(LoadCmdThread), "LoadCmdThread"},{uint32(LoadCmdUnixThread), "LoadCmdUnixThread"},{uint32(LoadCmdDylib), "LoadCmdDylib"},{uint32(LoadCmdSegment64), "LoadCmdSegment64"},}func (i LoadCmd) String() string { return stringName(uint32(i), cmdStrings, false) }func (i LoadCmd) GoString() string { return stringName(uint32(i), cmdStrings, true) }// A Segment64 is a 64-bit Mach-O segment load command.type Segment64 struct {Cmd LoadCmdLen uint32Name [16]byteAddr uint64Memsz uint64Offset uint64Filesz uint64Maxprot uint32Prot uint32Nsect uint32Flag uint32}// A Segment32 is a 32-bit Mach-O segment load command.type Segment32 struct {Cmd LoadCmdLen uint32Name [16]byteAddr uint32Memsz uint32Offset uint32Filesz uint32Maxprot uint32Prot uint32Nsect uint32Flag uint32}// A DylibCmd is a Mach-O load dynamic library command.type DylibCmd struct {Cmd LoadCmdLen uint32Name uint32Time uint32CurrentVersion uint32CompatVersion uint32}// A Section32 is a 32-bit Mach-O section header.type Section32 struct {Name [16]byteSeg [16]byteAddr uint32Size uint32Offset uint32Align uint32Reloff uint32Nreloc uint32Flags uint32Reserve1 uint32Reserve2 uint32}// A Section32 is a 64-bit Mach-O section header.type Section64 struct {Name [16]byteSeg [16]byteAddr uint64Size uint64Offset uint32Align uint32Reloff uint32Nreloc uint32Flags uint32Reserve1 uint32Reserve2 uint32Reserve3 uint32}// A SymtabCmd is a Mach-O symbol table command.type SymtabCmd struct {Cmd LoadCmdLen uint32Symoff uint32Nsyms uint32Stroff uint32Strsize uint32}// A DysymtabCmd is a Mach-O dynamic symbol table command.type DysymtabCmd struct {Cmd LoadCmdLen uint32Ilocalsym uint32Nlocalsym uint32Iextdefsym uint32Nextdefsym uint32Iundefsym uint32Nundefsym uint32Tocoffset uint32Ntoc uint32Modtaboff uint32Nmodtab uint32Extrefsymoff uint32Nextrefsyms uint32Indirectsymoff uint32Nindirectsyms uint32Extreloff uint32Nextrel uint32Locreloff uint32Nlocrel uint32}// An Nlist32 is a Mach-O 32-bit symbol table entry.type Nlist32 struct {Name uint32Type uint8Sect uint8Desc uint16Value uint32}// An Nlist64 is a Mach-O 64-bit symbol table entry.type Nlist64 struct {Name uint32Type uint8Sect uint8Desc uint16Value uint64}// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.type Symbol struct {Name stringType uint8Sect uint8Desc uint16Value uint64}// A Thread is a Mach-O thread state command.type Thread struct {Cmd LoadCmdLen uint32Type uint32Data []uint32}// Regs386 is the Mach-O 386 register structure.type Regs386 struct {AX uint32BX uint32CX uint32DX uint32DI uint32SI uint32BP uint32SP uint32SS uint32FLAGS uint32IP uint32CS uint32DS uint32ES uint32FS uint32GS uint32}// RegsAMD64 is the Mach-O AMD64 register structure.type RegsAMD64 struct {AX uint64BX uint64CX uint64DX uint64DI uint64SI uint64BP uint64SP uint64R8 uint64R9 uint64R10 uint64R11 uint64R12 uint64R13 uint64R14 uint64R15 uint64IP uint64FLAGS uint64CS uint64FS uint64GS uint64}type intName struct {i uint32s string}func stringName(i uint32, names []intName, goSyntax bool) string {for _, n := range names {if n.i == i {if goSyntax {return "macho." + n.s}return n.s}}return strconv.FormatUint(uint64(i), 10)}func flagName(i uint32, names []intName, goSyntax bool) string {s := ""for _, n := range names {if n.i&i == n.i {if len(s) > 0 {s += "+"}if goSyntax {s += "macho."}s += n.si -= n.i}}if len(s) == 0 {return "0x" + strconv.FormatUint(uint64(i), 16)}if i != 0 {s += "+0x" + strconv.FormatUint(uint64(i), 16)}return s}
