@@ -57,7 +57,8 @@ ObjectContainer *ObjectContainerUniversalMachO::CreateInstance(
57
57
bool ObjectContainerUniversalMachO::MagicBytesMatch (const DataExtractor &data) {
58
58
lldb::offset_t offset = 0 ;
59
59
uint32_t magic = data.GetU32 (&offset);
60
- return magic == FAT_MAGIC || magic == FAT_CIGAM;
60
+ return magic == FAT_MAGIC || magic == FAT_CIGAM || magic == FAT_MAGIC_64 ||
61
+ magic == FAT_CIGAM_64;
61
62
}
62
63
63
64
ObjectContainerUniversalMachO::ObjectContainerUniversalMachO (
@@ -82,38 +83,51 @@ bool ObjectContainerUniversalMachO::ParseHeader() {
82
83
83
84
bool ObjectContainerUniversalMachO::ParseHeader (
84
85
lldb_private::DataExtractor &data, llvm::MachO::fat_header &header,
85
- std::vector<llvm::MachO::fat_arch> &fat_archs) {
86
- bool success = false ;
86
+ std::vector<FatArch> &fat_archs) {
87
87
// Store the file offset for this universal file as we could have a universal
88
88
// .o file in a BSD archive, or be contained in another kind of object.
89
- // Universal mach-o files always have their headers in big endian.
90
89
lldb::offset_t offset = 0 ;
91
90
data.SetByteOrder (eByteOrderBig);
92
91
header.magic = data.GetU32 (&offset);
93
92
fat_archs.clear ();
94
93
95
- if (header.magic == FAT_MAGIC) {
96
-
97
- data.SetAddressByteSize (4 );
94
+ // Universal mach-o files always have their headers in big endian.
95
+ if (header.magic == FAT_MAGIC || header.magic == FAT_MAGIC_64) {
96
+ const bool is_fat64 = header.magic == FAT_MAGIC_64;
97
+ data.SetAddressByteSize (is_fat64 ? 8 : 4 );
98
98
99
99
header.nfat_arch = data.GetU32 (&offset);
100
100
101
101
// Now we should have enough data for all of the fat headers, so lets index
102
102
// them so we know how many architectures that this universal binary
103
103
// contains.
104
- uint32_t arch_idx = 0 ;
105
- for (arch_idx = 0 ; arch_idx < header.nfat_arch ; ++arch_idx) {
104
+ for (uint32_t arch_idx = 0 ; arch_idx < header.nfat_arch ; ++arch_idx) {
106
105
if (data.ValidOffsetForDataOfSize (offset, sizeof (fat_arch))) {
107
- fat_arch arch;
108
- if (data.GetU32 (&offset, &arch, sizeof (fat_arch) / sizeof (uint32_t )))
109
- fat_archs.push_back (arch);
106
+ if (is_fat64) {
107
+ fat_arch_64 arch;
108
+ arch.cputype = data.GetU32 (&offset);
109
+ arch.cpusubtype = data.GetU32 (&offset);
110
+ arch.offset = data.GetU64 (&offset);
111
+ arch.size = data.GetU64 (&offset);
112
+ arch.align = data.GetU32 (&offset);
113
+ arch.reserved = data.GetU32 (&offset);
114
+ fat_archs.emplace_back (arch);
115
+ } else {
116
+ fat_arch arch;
117
+ arch.cputype = data.GetU32 (&offset);
118
+ arch.cpusubtype = data.GetU32 (&offset);
119
+ arch.offset = data.GetU32 (&offset);
120
+ arch.size = data.GetU32 (&offset);
121
+ arch.align = data.GetU32 (&offset);
122
+ fat_archs.emplace_back (arch);
123
+ }
110
124
}
111
125
}
112
- success = true ;
113
- } else {
114
- memset (&header, 0 , sizeof (header));
126
+ return true ;
115
127
}
116
- return success;
128
+
129
+ memset (&header, 0 , sizeof (header));
130
+ return true ;
117
131
}
118
132
119
133
size_t ObjectContainerUniversalMachO::GetNumArchitectures () const {
@@ -123,8 +137,8 @@ size_t ObjectContainerUniversalMachO::GetNumArchitectures() const {
123
137
bool ObjectContainerUniversalMachO::GetArchitectureAtIndex (
124
138
uint32_t idx, ArchSpec &arch) const {
125
139
if (idx < m_header.nfat_arch ) {
126
- arch.SetArchitecture (eArchTypeMachO, m_fat_archs[idx].cputype ,
127
- m_fat_archs[idx].cpusubtype );
140
+ arch.SetArchitecture (eArchTypeMachO, m_fat_archs[idx].GetCPUType () ,
141
+ m_fat_archs[idx].GetCPUSubType () );
128
142
return true ;
129
143
}
130
144
return false ;
@@ -166,8 +180,8 @@ ObjectContainerUniversalMachO::GetObjectFile(const FileSpec *file) {
166
180
DataBufferSP data_sp;
167
181
lldb::offset_t data_offset = 0 ;
168
182
return ObjectFile::FindPlugin (
169
- module_sp, file, m_offset + m_fat_archs[arch_idx].offset ,
170
- m_fat_archs[arch_idx].size , data_sp, data_offset);
183
+ module_sp, file, m_offset + m_fat_archs[arch_idx].GetOffset () ,
184
+ m_fat_archs[arch_idx].GetSize () , data_sp, data_offset);
171
185
}
172
186
}
173
187
return ObjectFileSP ();
@@ -184,11 +198,12 @@ size_t ObjectContainerUniversalMachO::GetModuleSpecifications(
184
198
185
199
if (ObjectContainerUniversalMachO::MagicBytesMatch (data)) {
186
200
llvm::MachO::fat_header header;
187
- std::vector<llvm::MachO::fat_arch > fat_archs;
201
+ std::vector<FatArch > fat_archs;
188
202
if (ParseHeader (data, header, fat_archs)) {
189
- for (const llvm::MachO::fat_arch &fat_arch : fat_archs) {
190
- const lldb::offset_t slice_file_offset = fat_arch.offset + file_offset;
191
- if (fat_arch.offset < file_size && file_size > slice_file_offset) {
203
+ for (const FatArch &fat_arch : fat_archs) {
204
+ const lldb::offset_t slice_file_offset =
205
+ fat_arch.GetOffset () + file_offset;
206
+ if (fat_arch.GetOffset () < file_size && file_size > slice_file_offset) {
192
207
ObjectFile::GetModuleSpecifications (
193
208
file, slice_file_offset, file_size - slice_file_offset, specs);
194
209
}
0 commit comments