Skip to content

Commit 78984d3

Browse files
hirochachachaianlancetaylor
authored andcommitted
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3ce05d2 commit 78984d3

File tree

2 files changed

+101
-99
lines changed

2 files changed

+101
-99
lines changed

src/debug/macho/file.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ type Dysymtab struct {
143143
IndirectSyms []uint32 // indices into Symtab.Syms
144144
}
145145

146+
// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
147+
type Symbol struct {
148+
Name string
149+
Type uint8
150+
Sect uint8
151+
Desc uint16
152+
Value uint64
153+
}
154+
146155
/*
147156
* Mach-O reader
148157
*/

src/debug/macho/macho.go

Lines changed: 92 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ func (i Cpu) GoString() string { return stringName(uint32(i), cpuStrings, true)
7979
type LoadCmd uint32
8080

8181
const (
82-
LoadCmdSegment LoadCmd = 1
83-
LoadCmdSymtab LoadCmd = 2
84-
LoadCmdThread LoadCmd = 4
85-
LoadCmdUnixThread LoadCmd = 5 // thread+stack
86-
LoadCmdDysymtab LoadCmd = 11
87-
LoadCmdDylib LoadCmd = 12
88-
LoadCmdDylinker LoadCmd = 15
89-
LoadCmdSegment64 LoadCmd = 25
82+
LoadCmdSegment LoadCmd = 0x1
83+
LoadCmdSymtab LoadCmd = 0x2
84+
LoadCmdThread LoadCmd = 0x4
85+
LoadCmdUnixThread LoadCmd = 0x5 // thread+stack
86+
LoadCmdDysymtab LoadCmd = 0xb
87+
LoadCmdDylib LoadCmd = 0xc
88+
LoadCmdDylinker LoadCmd = 0xf
89+
LoadCmdSegment64 LoadCmd = 0x19
9090
)
9191

9292
var cmdStrings = []intName{
@@ -100,53 +100,97 @@ var cmdStrings = []intName{
100100
func (i LoadCmd) String() string { return stringName(uint32(i), cmdStrings, false) }
101101
func (i LoadCmd) GoString() string { return stringName(uint32(i), cmdStrings, true) }
102102

103+
type (
104+
// A Segment32 is a 32-bit Mach-O segment load command.
105+
Segment32 struct {
106+
Cmd LoadCmd
107+
Len uint32
108+
Name [16]byte
109+
Addr uint32
110+
Memsz uint32
111+
Offset uint32
112+
Filesz uint32
113+
Maxprot uint32
114+
Prot uint32
115+
Nsect uint32
116+
Flag uint32
117+
}
118+
119+
// A Segment64 is a 64-bit Mach-O segment load command.
120+
Segment64 struct {
121+
Cmd LoadCmd
122+
Len uint32
123+
Name [16]byte
124+
Addr uint64
125+
Memsz uint64
126+
Offset uint64
127+
Filesz uint64
128+
Maxprot uint32
129+
Prot uint32
130+
Nsect uint32
131+
Flag uint32
132+
}
133+
134+
// A SymtabCmd is a Mach-O symbol table command.
135+
SymtabCmd struct {
136+
Cmd LoadCmd
137+
Len uint32
138+
Symoff uint32
139+
Nsyms uint32
140+
Stroff uint32
141+
Strsize uint32
142+
}
143+
144+
// A DysymtabCmd is a Mach-O dynamic symbol table command.
145+
DysymtabCmd struct {
146+
Cmd LoadCmd
147+
Len uint32
148+
Ilocalsym uint32
149+
Nlocalsym uint32
150+
Iextdefsym uint32
151+
Nextdefsym uint32
152+
Iundefsym uint32
153+
Nundefsym uint32
154+
Tocoffset uint32
155+
Ntoc uint32
156+
Modtaboff uint32
157+
Nmodtab uint32
158+
Extrefsymoff uint32
159+
Nextrefsyms uint32
160+
Indirectsymoff uint32
161+
Nindirectsyms uint32
162+
Extreloff uint32
163+
Nextrel uint32
164+
Locreloff uint32
165+
Nlocrel uint32
166+
}
167+
168+
// A DylibCmd is a Mach-O load dynamic library command.
169+
DylibCmd struct {
170+
Cmd LoadCmd
171+
Len uint32
172+
Name uint32
173+
Time uint32
174+
CurrentVersion uint32
175+
CompatVersion uint32
176+
}
177+
178+
// A Thread is a Mach-O thread state command.
179+
Thread struct {
180+
Cmd LoadCmd
181+
Len uint32
182+
Type uint32
183+
Data []uint32
184+
}
185+
)
186+
103187
const (
104188
FlagNoUndefs uint32 = 0x1
105189
FlagDyldLink uint32 = 0x4
106190
FlagTwoLevel uint32 = 0x80
107191
FlagPIE uint32 = 0x200000
108192
)
109193

110-
// A Segment64 is a 64-bit Mach-O segment load command.
111-
type Segment64 struct {
112-
Cmd LoadCmd
113-
Len uint32
114-
Name [16]byte
115-
Addr uint64
116-
Memsz uint64
117-
Offset uint64
118-
Filesz uint64
119-
Maxprot uint32
120-
Prot uint32
121-
Nsect uint32
122-
Flag uint32
123-
}
124-
125-
// A Segment32 is a 32-bit Mach-O segment load command.
126-
type Segment32 struct {
127-
Cmd LoadCmd
128-
Len uint32
129-
Name [16]byte
130-
Addr uint32
131-
Memsz uint32
132-
Offset uint32
133-
Filesz uint32
134-
Maxprot uint32
135-
Prot uint32
136-
Nsect uint32
137-
Flag uint32
138-
}
139-
140-
// A DylibCmd is a Mach-O load dynamic library command.
141-
type DylibCmd struct {
142-
Cmd LoadCmd
143-
Len uint32
144-
Name uint32
145-
Time uint32
146-
CurrentVersion uint32
147-
CompatVersion uint32
148-
}
149-
150194
// A Section32 is a 32-bit Mach-O section header.
151195
type Section32 struct {
152196
Name [16]byte
@@ -178,40 +222,6 @@ type Section64 struct {
178222
Reserve3 uint32
179223
}
180224

181-
// A SymtabCmd is a Mach-O symbol table command.
182-
type SymtabCmd struct {
183-
Cmd LoadCmd
184-
Len uint32
185-
Symoff uint32
186-
Nsyms uint32
187-
Stroff uint32
188-
Strsize uint32
189-
}
190-
191-
// A DysymtabCmd is a Mach-O dynamic symbol table command.
192-
type DysymtabCmd struct {
193-
Cmd LoadCmd
194-
Len uint32
195-
Ilocalsym uint32
196-
Nlocalsym uint32
197-
Iextdefsym uint32
198-
Nextdefsym uint32
199-
Iundefsym uint32
200-
Nundefsym uint32
201-
Tocoffset uint32
202-
Ntoc uint32
203-
Modtaboff uint32
204-
Nmodtab uint32
205-
Extrefsymoff uint32
206-
Nextrefsyms uint32
207-
Indirectsymoff uint32
208-
Nindirectsyms uint32
209-
Extreloff uint32
210-
Nextrel uint32
211-
Locreloff uint32
212-
Nlocrel uint32
213-
}
214-
215225
// An Nlist32 is a Mach-O 32-bit symbol table entry.
216226
type Nlist32 struct {
217227
Name uint32
@@ -230,23 +240,6 @@ type Nlist64 struct {
230240
Value uint64
231241
}
232242

233-
// A Symbol is a Mach-O 32-bit or 64-bit symbol table entry.
234-
type Symbol struct {
235-
Name string
236-
Type uint8
237-
Sect uint8
238-
Desc uint16
239-
Value uint64
240-
}
241-
242-
// A Thread is a Mach-O thread state command.
243-
type Thread struct {
244-
Cmd LoadCmd
245-
Len uint32
246-
Type uint32
247-
Data []uint32
248-
}
249-
250243
// Regs386 is the Mach-O 386 register structure.
251244
type Regs386 struct {
252245
AX uint32

0 commit comments

Comments
 (0)