blob: 78ca17f9b4b3ee5a62f6d0281f1ca6ef4213374a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ObjectFileMachO.cpp -------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Jim Ingham672e6f52011-03-07 23:44:08 +000010#include "llvm/Support/MachO.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "ObjectFileMachO.h"
13
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Core/ArchSpec.h"
15#include "lldb/Core/DataBuffer.h"
Greg Clayton53239f02011-02-08 05:05:52 +000016#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/FileSpecList.h"
18#include "lldb/Core/Module.h"
19#include "lldb/Core/PluginManager.h"
20#include "lldb/Core/Section.h"
21#include "lldb/Core/StreamFile.h"
22#include "lldb/Core/StreamString.h"
23#include "lldb/Core/Timer.h"
24#include "lldb/Core/UUID.h"
25#include "lldb/Symbol/ObjectFile.h"
26
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027
28using namespace lldb;
29using namespace lldb_private;
Greg Claytone1a916a2010-07-21 22:12:05 +000030using namespace llvm::MachO;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031
Greg Claytonded470d2011-03-19 01:12:21 +000032#define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033
34void
35ObjectFileMachO::Initialize()
36{
37 PluginManager::RegisterPlugin (GetPluginNameStatic(),
38 GetPluginDescriptionStatic(),
39 CreateInstance);
40}
41
42void
43ObjectFileMachO::Terminate()
44{
45 PluginManager::UnregisterPlugin (CreateInstance);
46}
47
48
49const char *
50ObjectFileMachO::GetPluginNameStatic()
51{
52 return "object-file.mach-o";
53}
54
55const char *
56ObjectFileMachO::GetPluginDescriptionStatic()
57{
58 return "Mach-o object file reader (32 and 64 bit)";
59}
60
61
62ObjectFile *
63ObjectFileMachO::CreateInstance (Module* module, DataBufferSP& dataSP, const FileSpec* file, addr_t offset, addr_t length)
64{
65 if (ObjectFileMachO::MagicBytesMatch(dataSP))
66 {
67 std::auto_ptr<ObjectFile> objfile_ap(new ObjectFileMachO (module, dataSP, file, offset, length));
68 if (objfile_ap.get() && objfile_ap->ParseHeader())
69 return objfile_ap.release();
70 }
71 return NULL;
72}
73
74
75static uint32_t
76MachHeaderSizeFromMagic(uint32_t magic)
77{
78 switch (magic)
79 {
Greg Claytone1a916a2010-07-21 22:12:05 +000080 case HeaderMagic32:
81 case HeaderMagic32Swapped:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082 return sizeof(struct mach_header);
83
Greg Claytone1a916a2010-07-21 22:12:05 +000084 case HeaderMagic64:
85 case HeaderMagic64Swapped:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086 return sizeof(struct mach_header_64);
87 break;
88
89 default:
90 break;
91 }
92 return 0;
93}
94
95
96bool
97ObjectFileMachO::MagicBytesMatch (DataBufferSP& dataSP)
98{
Greg Clayton7fb56d02011-02-01 01:31:41 +000099 DataExtractor data(dataSP, lldb::endian::InlHostByteOrder(), 4);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000100 uint32_t offset = 0;
101 uint32_t magic = data.GetU32(&offset);
102 return MachHeaderSizeFromMagic(magic) != 0;
103}
104
105
106ObjectFileMachO::ObjectFileMachO(Module* module, DataBufferSP& dataSP, const FileSpec* file, addr_t offset, addr_t length) :
107 ObjectFile(module, file, offset, length, dataSP),
108 m_mutex (Mutex::eMutexTypeRecursive),
109 m_header(),
110 m_sections_ap(),
Jim Ingham672e6f52011-03-07 23:44:08 +0000111 m_symtab_ap(),
112 m_entry_point_address ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113{
Greg Clayton72b77eb2011-02-04 21:13:05 +0000114 ::memset (&m_header, 0, sizeof(m_header));
115 ::memset (&m_dysymtab, 0, sizeof(m_dysymtab));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116}
117
118
119ObjectFileMachO::~ObjectFileMachO()
120{
121}
122
123
124bool
125ObjectFileMachO::ParseHeader ()
126{
127 lldb_private::Mutex::Locker locker(m_mutex);
128 bool can_parse = false;
129 uint32_t offset = 0;
Greg Clayton7fb56d02011-02-01 01:31:41 +0000130 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131 // Leave magic in the original byte order
132 m_header.magic = m_data.GetU32(&offset);
133 switch (m_header.magic)
134 {
Greg Claytone1a916a2010-07-21 22:12:05 +0000135 case HeaderMagic32:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000136 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000137 m_data.SetAddressByteSize(4);
138 can_parse = true;
139 break;
140
Greg Claytone1a916a2010-07-21 22:12:05 +0000141 case HeaderMagic64:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000142 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000143 m_data.SetAddressByteSize(8);
144 can_parse = true;
145 break;
146
Greg Claytone1a916a2010-07-21 22:12:05 +0000147 case HeaderMagic32Swapped:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000148 m_data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149 m_data.SetAddressByteSize(4);
150 can_parse = true;
151 break;
152
Greg Claytone1a916a2010-07-21 22:12:05 +0000153 case HeaderMagic64Swapped:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000154 m_data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155 m_data.SetAddressByteSize(8);
156 can_parse = true;
157 break;
158
159 default:
160 break;
161 }
162
163 if (can_parse)
164 {
165 m_data.GetU32(&offset, &m_header.cputype, 6);
166
Greg Clayton41f92322010-06-11 03:25:34 +0000167 ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Jim Ingham5aee1622010-08-09 23:31:02 +0000168
169 if (SetModulesArchitecture (mach_arch))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170 {
171 // Read in all only the load command data
172 DataBufferSP data_sp(m_file.ReadFileContents(m_offset, m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic)));
173 m_data.SetData (data_sp);
174 return true;
175 }
176 }
177 else
178 {
179 memset(&m_header, 0, sizeof(struct mach_header));
180 }
181 return false;
182}
183
184
185ByteOrder
186ObjectFileMachO::GetByteOrder () const
187{
188 lldb_private::Mutex::Locker locker(m_mutex);
189 return m_data.GetByteOrder ();
190}
191
Jim Ingham5aee1622010-08-09 23:31:02 +0000192bool
193ObjectFileMachO::IsExecutable() const
194{
195 return m_header.filetype == HeaderFileTypeExecutable;
196}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197
198size_t
199ObjectFileMachO::GetAddressByteSize () const
200{
201 lldb_private::Mutex::Locker locker(m_mutex);
202 return m_data.GetAddressByteSize ();
203}
204
Greg Claytone0d378b2011-03-24 21:19:54 +0000205AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +0000206ObjectFileMachO::GetAddressClass (lldb::addr_t file_addr)
207{
208 Symtab *symtab = GetSymtab();
209 if (symtab)
210 {
211 Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
212 if (symbol)
213 {
214 const AddressRange *range_ptr = symbol->GetAddressRangePtr();
215 if (range_ptr)
216 {
217 const Section *section = range_ptr->GetBaseAddress().GetSection();
218 if (section)
219 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000220 const SectionType section_type = section->GetType();
Greg Claytonded470d2011-03-19 01:12:21 +0000221 switch (section_type)
222 {
223 case eSectionTypeInvalid: return eAddressClassUnknown;
224 case eSectionTypeCode:
225 if (m_header.cputype == llvm::MachO::CPUTypeARM)
226 {
227 // For ARM we have a bit in the n_desc field of the symbol
228 // that tells us ARM/Thumb which is bit 0x0008.
229 if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
230 return eAddressClassCodeAlternateISA;
231 }
232 return eAddressClassCode;
233
234 case eSectionTypeContainer: return eAddressClassUnknown;
235 case eSectionTypeData: return eAddressClassData;
Greg Claytone0d378b2011-03-24 21:19:54 +0000236 case eSectionTypeDataCString: return eAddressClassData;
Greg Claytonded470d2011-03-19 01:12:21 +0000237 case eSectionTypeDataCStringPointers: return eAddressClassData;
238 case eSectionTypeDataSymbolAddress: return eAddressClassData;
239 case eSectionTypeData4: return eAddressClassData;
240 case eSectionTypeData8: return eAddressClassData;
241 case eSectionTypeData16: return eAddressClassData;
242 case eSectionTypeDataPointers: return eAddressClassData;
243 case eSectionTypeZeroFill: return eAddressClassData;
Greg Claytone0d378b2011-03-24 21:19:54 +0000244 case eSectionTypeDataObjCMessageRefs: return eAddressClassData;
245 case eSectionTypeDataObjCCFStrings: return eAddressClassData;
Greg Claytonded470d2011-03-19 01:12:21 +0000246 case eSectionTypeDebug: return eAddressClassDebug;
247 case eSectionTypeDWARFDebugAbbrev: return eAddressClassDebug;
248 case eSectionTypeDWARFDebugAranges: return eAddressClassDebug;
249 case eSectionTypeDWARFDebugFrame: return eAddressClassDebug;
250 case eSectionTypeDWARFDebugInfo: return eAddressClassDebug;
251 case eSectionTypeDWARFDebugLine: return eAddressClassDebug;
252 case eSectionTypeDWARFDebugLoc: return eAddressClassDebug;
253 case eSectionTypeDWARFDebugMacInfo: return eAddressClassDebug;
254 case eSectionTypeDWARFDebugPubNames: return eAddressClassDebug;
255 case eSectionTypeDWARFDebugPubTypes: return eAddressClassDebug;
256 case eSectionTypeDWARFDebugRanges: return eAddressClassDebug;
257 case eSectionTypeDWARFDebugStr: return eAddressClassDebug;
Greg Clayton17674402011-09-28 17:06:40 +0000258 case eSectionTypeDWARFAppleNames: return eAddressClassDebug;
259 case eSectionTypeDWARFAppleTypes: return eAddressClassDebug;
Greg Clayton7f995132011-10-04 22:41:51 +0000260 case eSectionTypeDWARFAppleNamespaces: return eAddressClassDebug;
Greg Claytonded470d2011-03-19 01:12:21 +0000261 case eSectionTypeEHFrame: return eAddressClassRuntime;
262 case eSectionTypeOther: return eAddressClassUnknown;
263 }
264 }
265 }
266
Greg Claytone0d378b2011-03-24 21:19:54 +0000267 const SymbolType symbol_type = symbol->GetType();
Greg Claytonded470d2011-03-19 01:12:21 +0000268 switch (symbol_type)
269 {
270 case eSymbolTypeAny: return eAddressClassUnknown;
271 case eSymbolTypeAbsolute: return eAddressClassUnknown;
272 case eSymbolTypeExtern: return eAddressClassUnknown;
273
274 case eSymbolTypeCode:
275 case eSymbolTypeTrampoline:
276 if (m_header.cputype == llvm::MachO::CPUTypeARM)
277 {
278 // For ARM we have a bit in the n_desc field of the symbol
279 // that tells us ARM/Thumb which is bit 0x0008.
280 if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
281 return eAddressClassCodeAlternateISA;
282 }
283 return eAddressClassCode;
284
285 case eSymbolTypeData: return eAddressClassData;
286 case eSymbolTypeRuntime: return eAddressClassRuntime;
287 case eSymbolTypeException: return eAddressClassRuntime;
288 case eSymbolTypeSourceFile: return eAddressClassDebug;
289 case eSymbolTypeHeaderFile: return eAddressClassDebug;
290 case eSymbolTypeObjectFile: return eAddressClassDebug;
291 case eSymbolTypeCommonBlock: return eAddressClassDebug;
292 case eSymbolTypeBlock: return eAddressClassDebug;
293 case eSymbolTypeLocal: return eAddressClassData;
294 case eSymbolTypeParam: return eAddressClassData;
295 case eSymbolTypeVariable: return eAddressClassData;
296 case eSymbolTypeVariableType: return eAddressClassDebug;
297 case eSymbolTypeLineEntry: return eAddressClassDebug;
298 case eSymbolTypeLineHeader: return eAddressClassDebug;
299 case eSymbolTypeScopeBegin: return eAddressClassDebug;
300 case eSymbolTypeScopeEnd: return eAddressClassDebug;
301 case eSymbolTypeAdditional: return eAddressClassUnknown;
302 case eSymbolTypeCompiler: return eAddressClassDebug;
303 case eSymbolTypeInstrumentation:return eAddressClassDebug;
304 case eSymbolTypeUndefined: return eAddressClassUnknown;
305 }
306 }
307 }
308 return eAddressClassUnknown;
309}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000310
311Symtab *
312ObjectFileMachO::GetSymtab()
313{
Greg Clayton1a65ae12011-01-25 23:55:37 +0000314 lldb_private::Mutex::Locker symfile_locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000315 if (m_symtab_ap.get() == NULL)
316 {
317 m_symtab_ap.reset(new Symtab(this));
Greg Clayton1a65ae12011-01-25 23:55:37 +0000318 Mutex::Locker symtab_locker (m_symtab_ap->GetMutex());
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000319 ParseSymtab (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320 }
321 return m_symtab_ap.get();
322}
323
324
325SectionList *
326ObjectFileMachO::GetSectionList()
327{
328 lldb_private::Mutex::Locker locker(m_mutex);
329 if (m_sections_ap.get() == NULL)
330 {
331 m_sections_ap.reset(new SectionList());
332 ParseSections();
333 }
334 return m_sections_ap.get();
335}
336
337
338size_t
339ObjectFileMachO::ParseSections ()
340{
341 lldb::user_id_t segID = 0;
342 lldb::user_id_t sectID = 0;
343 struct segment_command_64 load_cmd;
344 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
345 uint32_t i;
346 //bool dump_sections = false;
347 for (i=0; i<m_header.ncmds; ++i)
348 {
349 const uint32_t load_cmd_offset = offset;
350 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
351 break;
352
Greg Claytone1a916a2010-07-21 22:12:05 +0000353 if (load_cmd.cmd == LoadCommandSegment32 || load_cmd.cmd == LoadCommandSegment64)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 {
355 if (m_data.GetU8(&offset, (uint8_t*)load_cmd.segname, 16))
356 {
357 load_cmd.vmaddr = m_data.GetAddress(&offset);
358 load_cmd.vmsize = m_data.GetAddress(&offset);
359 load_cmd.fileoff = m_data.GetAddress(&offset);
360 load_cmd.filesize = m_data.GetAddress(&offset);
361 if (m_data.GetU32(&offset, &load_cmd.maxprot, 4))
362 {
Greg Clayton414f5d32011-01-25 02:58:48 +0000363
364 const bool segment_is_encrypted = (load_cmd.flags & SegmentCommandFlagBitProtectedVersion1) != 0;
365
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 // Keep a list of mach segments around in case we need to
367 // get at data that isn't stored in the abstracted Sections.
368 m_mach_segments.push_back (load_cmd);
369
370 ConstString segment_name (load_cmd.segname, std::min<int>(strlen(load_cmd.segname), sizeof(load_cmd.segname)));
371 // Use a segment ID of the segment index shifted left by 8 so they
372 // never conflict with any of the sections.
373 SectionSP segment_sp;
374 if (segment_name)
375 {
376 segment_sp.reset(new Section (NULL,
377 GetModule(), // Module to which this section belongs
378 ++segID << 8, // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
379 segment_name, // Name of this section
380 eSectionTypeContainer, // This section is a container of other sections.
381 load_cmd.vmaddr, // File VM address == addresses as they are found in the object file
382 load_cmd.vmsize, // VM size in bytes of this section
383 load_cmd.fileoff, // Offset to the data for this section in the file
384 load_cmd.filesize, // Size in bytes of this section as found in the the file
385 load_cmd.flags)); // Flags for this section
386
Greg Clayton414f5d32011-01-25 02:58:48 +0000387 segment_sp->SetIsEncrypted (segment_is_encrypted);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388 m_sections_ap->AddSection(segment_sp);
389 }
390
391 struct section_64 sect64;
Greg Clayton72b77eb2011-02-04 21:13:05 +0000392 ::memset (&sect64, 0, sizeof(sect64));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393 // Push a section into our mach sections for the section at
Greg Claytonf4abd0d2010-10-06 01:26:32 +0000394 // index zero (NListSectionNoSection) if we don't have any
395 // mach sections yet...
396 if (m_mach_sections.empty())
397 m_mach_sections.push_back(sect64);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398 uint32_t segment_sect_idx;
399 const lldb::user_id_t first_segment_sectID = sectID + 1;
400
401
Greg Claytone1a916a2010-07-21 22:12:05 +0000402 const uint32_t num_u32s = load_cmd.cmd == LoadCommandSegment32 ? 7 : 8;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 for (segment_sect_idx=0; segment_sect_idx<load_cmd.nsects; ++segment_sect_idx)
404 {
405 if (m_data.GetU8(&offset, (uint8_t*)sect64.sectname, sizeof(sect64.sectname)) == NULL)
406 break;
407 if (m_data.GetU8(&offset, (uint8_t*)sect64.segname, sizeof(sect64.segname)) == NULL)
408 break;
409 sect64.addr = m_data.GetAddress(&offset);
410 sect64.size = m_data.GetAddress(&offset);
411
412 if (m_data.GetU32(&offset, &sect64.offset, num_u32s) == NULL)
413 break;
414
415 // Keep a list of mach sections around in case we need to
416 // get at data that isn't stored in the abstracted Sections.
417 m_mach_sections.push_back (sect64);
418
419 ConstString section_name (sect64.sectname, std::min<size_t>(strlen(sect64.sectname), sizeof(sect64.sectname)));
420 if (!segment_name)
421 {
422 // We have a segment with no name so we need to conjure up
423 // segments that correspond to the section's segname if there
424 // isn't already such a section. If there is such a section,
425 // we resize the section so that it spans all sections.
426 // We also mark these sections as fake so address matches don't
427 // hit if they land in the gaps between the child sections.
428 segment_name.SetTrimmedCStringWithLength(sect64.segname, sizeof(sect64.segname));
429 segment_sp = m_sections_ap->FindSectionByName (segment_name);
430 if (segment_sp.get())
431 {
432 Section *segment = segment_sp.get();
433 // Grow the section size as needed.
434 const lldb::addr_t sect64_min_addr = sect64.addr;
435 const lldb::addr_t sect64_max_addr = sect64_min_addr + sect64.size;
436 const lldb::addr_t curr_seg_byte_size = segment->GetByteSize();
437 const lldb::addr_t curr_seg_min_addr = segment->GetFileAddress();
438 const lldb::addr_t curr_seg_max_addr = curr_seg_min_addr + curr_seg_byte_size;
439 if (sect64_min_addr >= curr_seg_min_addr)
440 {
441 const lldb::addr_t new_seg_byte_size = sect64_max_addr - curr_seg_min_addr;
442 // Only grow the section size if needed
443 if (new_seg_byte_size > curr_seg_byte_size)
444 segment->SetByteSize (new_seg_byte_size);
445 }
446 else
447 {
448 // We need to change the base address of the segment and
449 // adjust the child section offsets for all existing children.
450 const lldb::addr_t slide_amount = sect64_min_addr - curr_seg_min_addr;
451 segment->Slide(slide_amount, false);
452 segment->GetChildren().Slide (-slide_amount, false);
453 segment->SetByteSize (curr_seg_max_addr - sect64_min_addr);
454 }
Greg Clayton8d38ac42010-06-28 23:51:11 +0000455
456 // Grow the section size as needed.
457 if (sect64.offset)
458 {
459 const lldb::addr_t segment_min_file_offset = segment->GetFileOffset();
460 const lldb::addr_t segment_max_file_offset = segment_min_file_offset + segment->GetFileSize();
461
462 const lldb::addr_t section_min_file_offset = sect64.offset;
463 const lldb::addr_t section_max_file_offset = section_min_file_offset + sect64.size;
464 const lldb::addr_t new_file_offset = std::min (section_min_file_offset, segment_min_file_offset);
465 const lldb::addr_t new_file_size = std::max (section_max_file_offset, segment_max_file_offset) - new_file_offset;
466 segment->SetFileOffset (new_file_offset);
467 segment->SetFileSize (new_file_size);
468 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000469 }
470 else
471 {
472 // Create a fake section for the section's named segment
473 segment_sp.reset(new Section(segment_sp.get(), // Parent section
474 GetModule(), // Module to which this section belongs
475 ++segID << 8, // Section ID is the 1 based segment index shifted right by 8 bits as not to collide with any of the 256 section IDs that are possible
476 segment_name, // Name of this section
477 eSectionTypeContainer, // This section is a container of other sections.
478 sect64.addr, // File VM address == addresses as they are found in the object file
479 sect64.size, // VM size in bytes of this section
480 sect64.offset, // Offset to the data for this section in the file
481 sect64.offset ? sect64.size : 0, // Size in bytes of this section as found in the the file
482 load_cmd.flags)); // Flags for this section
483 segment_sp->SetIsFake(true);
484 m_sections_ap->AddSection(segment_sp);
Greg Clayton414f5d32011-01-25 02:58:48 +0000485 segment_sp->SetIsEncrypted (segment_is_encrypted);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486 }
487 }
488 assert (segment_sp.get());
489
Greg Claytone1a916a2010-07-21 22:12:05 +0000490 uint32_t mach_sect_type = sect64.flags & SectionFlagMaskSectionType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000491 static ConstString g_sect_name_objc_data ("__objc_data");
492 static ConstString g_sect_name_objc_msgrefs ("__objc_msgrefs");
493 static ConstString g_sect_name_objc_selrefs ("__objc_selrefs");
494 static ConstString g_sect_name_objc_classrefs ("__objc_classrefs");
495 static ConstString g_sect_name_objc_superrefs ("__objc_superrefs");
496 static ConstString g_sect_name_objc_const ("__objc_const");
497 static ConstString g_sect_name_objc_classlist ("__objc_classlist");
498 static ConstString g_sect_name_cfstring ("__cfstring");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000499
500 static ConstString g_sect_name_dwarf_debug_abbrev ("__debug_abbrev");
501 static ConstString g_sect_name_dwarf_debug_aranges ("__debug_aranges");
502 static ConstString g_sect_name_dwarf_debug_frame ("__debug_frame");
503 static ConstString g_sect_name_dwarf_debug_info ("__debug_info");
504 static ConstString g_sect_name_dwarf_debug_line ("__debug_line");
505 static ConstString g_sect_name_dwarf_debug_loc ("__debug_loc");
506 static ConstString g_sect_name_dwarf_debug_macinfo ("__debug_macinfo");
507 static ConstString g_sect_name_dwarf_debug_pubnames ("__debug_pubnames");
508 static ConstString g_sect_name_dwarf_debug_pubtypes ("__debug_pubtypes");
509 static ConstString g_sect_name_dwarf_debug_ranges ("__debug_ranges");
510 static ConstString g_sect_name_dwarf_debug_str ("__debug_str");
Greg Clayton17674402011-09-28 17:06:40 +0000511 static ConstString g_sect_name_dwarf_apple_names ("__apple_names");
512 static ConstString g_sect_name_dwarf_apple_types ("__apple_types");
Greg Clayton7f995132011-10-04 22:41:51 +0000513 static ConstString g_sect_name_dwarf_apple_namespaces ("__apple_namespac");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000514 static ConstString g_sect_name_eh_frame ("__eh_frame");
Greg Clayton89411422010-10-08 00:21:05 +0000515 static ConstString g_sect_name_DATA ("__DATA");
516 static ConstString g_sect_name_TEXT ("__TEXT");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000517
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 SectionType sect_type = eSectionTypeOther;
519
Greg Clayton4ceb9982010-07-21 22:54:26 +0000520 if (section_name == g_sect_name_dwarf_debug_abbrev)
521 sect_type = eSectionTypeDWARFDebugAbbrev;
522 else if (section_name == g_sect_name_dwarf_debug_aranges)
523 sect_type = eSectionTypeDWARFDebugAranges;
524 else if (section_name == g_sect_name_dwarf_debug_frame)
525 sect_type = eSectionTypeDWARFDebugFrame;
526 else if (section_name == g_sect_name_dwarf_debug_info)
527 sect_type = eSectionTypeDWARFDebugInfo;
528 else if (section_name == g_sect_name_dwarf_debug_line)
529 sect_type = eSectionTypeDWARFDebugLine;
530 else if (section_name == g_sect_name_dwarf_debug_loc)
531 sect_type = eSectionTypeDWARFDebugLoc;
532 else if (section_name == g_sect_name_dwarf_debug_macinfo)
533 sect_type = eSectionTypeDWARFDebugMacInfo;
534 else if (section_name == g_sect_name_dwarf_debug_pubnames)
535 sect_type = eSectionTypeDWARFDebugPubNames;
536 else if (section_name == g_sect_name_dwarf_debug_pubtypes)
537 sect_type = eSectionTypeDWARFDebugPubTypes;
538 else if (section_name == g_sect_name_dwarf_debug_ranges)
539 sect_type = eSectionTypeDWARFDebugRanges;
540 else if (section_name == g_sect_name_dwarf_debug_str)
541 sect_type = eSectionTypeDWARFDebugStr;
Greg Clayton17674402011-09-28 17:06:40 +0000542 else if (section_name == g_sect_name_dwarf_apple_names)
543 sect_type = eSectionTypeDWARFAppleNames;
544 else if (section_name == g_sect_name_dwarf_apple_types)
545 sect_type = eSectionTypeDWARFAppleTypes;
Greg Clayton7f995132011-10-04 22:41:51 +0000546 else if (section_name == g_sect_name_dwarf_apple_namespaces)
547 sect_type = eSectionTypeDWARFAppleNamespaces;
Greg Clayton4ceb9982010-07-21 22:54:26 +0000548 else if (section_name == g_sect_name_objc_selrefs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000549 sect_type = eSectionTypeDataCStringPointers;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000550 else if (section_name == g_sect_name_objc_msgrefs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551 sect_type = eSectionTypeDataObjCMessageRefs;
Greg Clayton4ceb9982010-07-21 22:54:26 +0000552 else if (section_name == g_sect_name_eh_frame)
553 sect_type = eSectionTypeEHFrame;
554 else if (section_name == g_sect_name_cfstring)
555 sect_type = eSectionTypeDataObjCCFStrings;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 else if (section_name == g_sect_name_objc_data ||
557 section_name == g_sect_name_objc_classrefs ||
558 section_name == g_sect_name_objc_superrefs ||
559 section_name == g_sect_name_objc_const ||
560 section_name == g_sect_name_objc_classlist)
561 {
562 sect_type = eSectionTypeDataPointers;
563 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000564
565 if (sect_type == eSectionTypeOther)
566 {
567 switch (mach_sect_type)
568 {
569 // TODO: categorize sections by other flags for regular sections
Greg Clayton89411422010-10-08 00:21:05 +0000570 case SectionTypeRegular:
571 if (segment_sp->GetName() == g_sect_name_TEXT)
572 sect_type = eSectionTypeCode;
573 else if (segment_sp->GetName() == g_sect_name_DATA)
574 sect_type = eSectionTypeData;
575 else
576 sect_type = eSectionTypeOther;
577 break;
Greg Claytone1a916a2010-07-21 22:12:05 +0000578 case SectionTypeZeroFill: sect_type = eSectionTypeZeroFill; break;
579 case SectionTypeCStringLiterals: sect_type = eSectionTypeDataCString; break; // section with only literal C strings
580 case SectionType4ByteLiterals: sect_type = eSectionTypeData4; break; // section with only 4 byte literals
581 case SectionType8ByteLiterals: sect_type = eSectionTypeData8; break; // section with only 8 byte literals
582 case SectionTypeLiteralPointers: sect_type = eSectionTypeDataPointers; break; // section with only pointers to literals
583 case SectionTypeNonLazySymbolPointers: sect_type = eSectionTypeDataPointers; break; // section with only non-lazy symbol pointers
584 case SectionTypeLazySymbolPointers: sect_type = eSectionTypeDataPointers; break; // section with only lazy symbol pointers
585 case SectionTypeSymbolStubs: sect_type = eSectionTypeCode; break; // section with only symbol stubs, byte size of stub in the reserved2 field
586 case SectionTypeModuleInitFunctionPointers: sect_type = eSectionTypeDataPointers; break; // section with only function pointers for initialization
587 case SectionTypeModuleTermFunctionPointers: sect_type = eSectionTypeDataPointers; break; // section with only function pointers for termination
588 case SectionTypeCoalesced: sect_type = eSectionTypeOther; break;
589 case SectionTypeZeroFillLarge: sect_type = eSectionTypeZeroFill; break;
590 case SectionTypeInterposing: sect_type = eSectionTypeCode; break; // section with only pairs of function pointers for interposing
591 case SectionType16ByteLiterals: sect_type = eSectionTypeData16; break; // section with only 16 byte literals
592 case SectionTypeDTraceObjectFormat: sect_type = eSectionTypeDebug; break;
593 case SectionTypeLazyDylibSymbolPointers: sect_type = eSectionTypeDataPointers; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594 default: break;
595 }
596 }
597
598 SectionSP section_sp(new Section(segment_sp.get(),
599 GetModule(),
600 ++sectID,
601 section_name,
602 sect_type,
603 sect64.addr - segment_sp->GetFileAddress(),
604 sect64.size,
605 sect64.offset,
606 sect64.offset == 0 ? 0 : sect64.size,
607 sect64.flags));
Greg Clayton414f5d32011-01-25 02:58:48 +0000608 // Set the section to be encrypted to match the segment
609 section_sp->SetIsEncrypted (segment_is_encrypted);
610
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 segment_sp->GetChildren().AddSection(section_sp);
612
613 if (segment_sp->IsFake())
614 {
615 segment_sp.reset();
616 segment_name.Clear();
617 }
618 }
Greg Claytona63d08c2011-07-19 03:57:15 +0000619 if (segment_sp && m_header.filetype == HeaderFileTypeDSYM)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620 {
621 if (first_segment_sectID <= sectID)
622 {
623 lldb::user_id_t sect_uid;
624 for (sect_uid = first_segment_sectID; sect_uid <= sectID; ++sect_uid)
625 {
626 SectionSP curr_section_sp(segment_sp->GetChildren().FindSectionByID (sect_uid));
627 SectionSP next_section_sp;
628 if (sect_uid + 1 <= sectID)
629 next_section_sp = segment_sp->GetChildren().FindSectionByID (sect_uid+1);
630
631 if (curr_section_sp.get())
632 {
633 if (curr_section_sp->GetByteSize() == 0)
634 {
635 if (next_section_sp.get() != NULL)
636 curr_section_sp->SetByteSize ( next_section_sp->GetFileAddress() - curr_section_sp->GetFileAddress() );
637 else
638 curr_section_sp->SetByteSize ( load_cmd.vmsize );
639 }
640 }
641 }
642 }
643 }
644 }
645 }
646 }
Greg Claytone1a916a2010-07-21 22:12:05 +0000647 else if (load_cmd.cmd == LoadCommandDynamicSymtabInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 {
649 m_dysymtab.cmd = load_cmd.cmd;
650 m_dysymtab.cmdsize = load_cmd.cmdsize;
651 m_data.GetU32 (&offset, &m_dysymtab.ilocalsym, (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2);
652 }
653
654 offset = load_cmd_offset + load_cmd.cmdsize;
655 }
656// if (dump_sections)
657// {
658// StreamFile s(stdout);
659// m_sections_ap->Dump(&s, true);
660// }
661 return sectID; // Return the number of sections we registered with the module
662}
663
664class MachSymtabSectionInfo
665{
666public:
667
668 MachSymtabSectionInfo (SectionList *section_list) :
669 m_section_list (section_list),
670 m_section_infos()
671 {
672 // Get the number of sections down to a depth of 1 to include
673 // all segments and their sections, but no other sections that
674 // may be added for debug map or
675 m_section_infos.resize(section_list->GetNumSections(1));
676 }
677
678
679 Section *
680 GetSection (uint8_t n_sect, addr_t file_addr)
681 {
682 if (n_sect == 0)
683 return NULL;
684 if (n_sect < m_section_infos.size())
685 {
686 if (m_section_infos[n_sect].section == NULL)
687 {
688 Section *section = m_section_list->FindSectionByID (n_sect).get();
689 m_section_infos[n_sect].section = section;
Greg Claytondda0d122011-07-10 17:32:33 +0000690 if (section != NULL)
691 {
692 m_section_infos[n_sect].vm_range.SetBaseAddress (section->GetFileAddress());
693 m_section_infos[n_sect].vm_range.SetByteSize (section->GetByteSize());
694 }
695 else
696 {
697 fprintf (stderr, "error: unable to find section for section %u\n", n_sect);
698 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000699 }
700 if (m_section_infos[n_sect].vm_range.Contains(file_addr))
Greg Clayton8f258512011-08-26 20:01:35 +0000701 {
702 // Symbol is in section.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703 return m_section_infos[n_sect].section;
Greg Clayton8f258512011-08-26 20:01:35 +0000704 }
705 else if (m_section_infos[n_sect].vm_range.GetByteSize () == 0 &&
706 m_section_infos[n_sect].vm_range.GetBaseAddress() == file_addr)
707 {
708 // Symbol is in section with zero size, but has the same start
709 // address as the section. This can happen with linker symbols
710 // (symbols that start with the letter 'l' or 'L'.
711 return m_section_infos[n_sect].section;
712 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713 }
714 return m_section_list->FindSectionContainingFileAddress(file_addr).get();
715 }
716
717protected:
718 struct SectionInfo
719 {
720 SectionInfo () :
721 vm_range(),
722 section (NULL)
723 {
724 }
725
726 VMRange vm_range;
727 Section *section;
728 };
729 SectionList *m_section_list;
730 std::vector<SectionInfo> m_section_infos;
731};
732
733
734
735size_t
736ObjectFileMachO::ParseSymtab (bool minimize)
737{
738 Timer scoped_timer(__PRETTY_FUNCTION__,
739 "ObjectFileMachO::ParseSymtab () module = %s",
740 m_file.GetFilename().AsCString(""));
741 struct symtab_command symtab_load_command;
742 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
743 uint32_t i;
744 for (i=0; i<m_header.ncmds; ++i)
745 {
746 const uint32_t cmd_offset = offset;
747 // Read in the load command and load command size
748 if (m_data.GetU32(&offset, &symtab_load_command, 2) == NULL)
749 break;
750 // Watch for the symbol table load command
Greg Claytone1a916a2010-07-21 22:12:05 +0000751 if (symtab_load_command.cmd == LoadCommandSymtab)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752 {
753 // Read in the rest of the symtab load command
Jason Molendaea84e762010-07-06 22:38:03 +0000754 if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4)) // fill in symoff, nsyms, stroff, strsize fields
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 {
756 Symtab *symtab = m_symtab_ap.get();
757 SectionList *section_list = GetSectionList();
758 assert(section_list);
759 const size_t addr_size = m_data.GetAddressByteSize();
760 const ByteOrder endian = m_data.GetByteOrder();
761 bool bit_width_32 = addr_size == 4;
762 const size_t nlist_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64);
763
764 DataBufferSP symtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.symoff, symtab_load_command.nsyms * nlist_size));
765 DataBufferSP strtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.stroff, symtab_load_command.strsize));
766
767 const char *strtab_data = (const char *)strtab_data_sp->GetBytes();
768// DataExtractor symtab_data(symtab_data_sp, endian, addr_size);
769// DataExtractor strtab_data(strtab_data_sp, endian, addr_size);
770
771 static ConstString g_segment_name_TEXT ("__TEXT");
772 static ConstString g_segment_name_DATA ("__DATA");
773 static ConstString g_segment_name_OBJC ("__OBJC");
774 static ConstString g_section_name_eh_frame ("__eh_frame");
775 SectionSP text_section_sp(section_list->FindSectionByName(g_segment_name_TEXT));
776 SectionSP data_section_sp(section_list->FindSectionByName(g_segment_name_DATA));
777 SectionSP objc_section_sp(section_list->FindSectionByName(g_segment_name_OBJC));
778 SectionSP eh_frame_section_sp;
779 if (text_section_sp.get())
780 eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName (g_section_name_eh_frame);
781 else
782 eh_frame_section_sp = section_list->FindSectionByName (g_section_name_eh_frame);
783
Greg Claytone1a916a2010-07-21 22:12:05 +0000784 uint8_t TEXT_eh_frame_sectID = eh_frame_section_sp.get() ? eh_frame_section_sp->GetID() : NListSectionNoSection;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 //uint32_t symtab_offset = 0;
786 const uint8_t* nlist_data = symtab_data_sp->GetBytes();
787 assert (symtab_data_sp->GetByteSize()/nlist_size >= symtab_load_command.nsyms);
788
789
Greg Clayton7fb56d02011-02-01 01:31:41 +0000790 if (endian != lldb::endian::InlHostByteOrder())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000791 {
792 // ...
793 assert (!"UNIMPLEMENTED: Swap all nlist entries");
794 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000795 uint32_t N_SO_index = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796
797 MachSymtabSectionInfo section_info (section_list);
798 std::vector<uint32_t> N_FUN_indexes;
799 std::vector<uint32_t> N_NSYM_indexes;
800 std::vector<uint32_t> N_INCL_indexes;
801 std::vector<uint32_t> N_BRAC_indexes;
802 std::vector<uint32_t> N_COMM_indexes;
Greg Clayton928d8292010-09-08 16:38:06 +0000803 typedef std::map <uint64_t, uint32_t> ValueToSymbolIndexMap;
Greg Clayton0c38b0d2010-09-12 05:25:16 +0000804 typedef std::map <uint32_t, uint32_t> NListIndexToSymbolIndexMap;
Greg Clayton928d8292010-09-08 16:38:06 +0000805 ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
806 ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000807 // Any symbols that get merged into another will get an entry
808 // in this map so we know
Greg Clayton0c38b0d2010-09-12 05:25:16 +0000809 NListIndexToSymbolIndexMap m_nlist_idx_to_sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000810 uint32_t nlist_idx = 0;
811 Symbol *symbol_ptr = NULL;
812
813 uint32_t sym_idx = 0;
814 Symbol *sym = symtab->Resize (symtab_load_command.nsyms + m_dysymtab.nindirectsyms);
815 uint32_t num_syms = symtab->GetNumSymbols();
816
817 //symtab->Reserve (symtab_load_command.nsyms + m_dysymtab.nindirectsyms);
818 for (nlist_idx = 0; nlist_idx < symtab_load_command.nsyms; ++nlist_idx)
819 {
820 struct nlist_64 nlist;
821 if (bit_width_32)
822 {
823 struct nlist* nlist32_ptr = (struct nlist*)(nlist_data + (nlist_idx * nlist_size));
Greg Claytone1a916a2010-07-21 22:12:05 +0000824 nlist.n_strx = nlist32_ptr->n_strx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 nlist.n_type = nlist32_ptr->n_type;
826 nlist.n_sect = nlist32_ptr->n_sect;
827 nlist.n_desc = nlist32_ptr->n_desc;
828 nlist.n_value = nlist32_ptr->n_value;
829 }
830 else
831 {
832 nlist = *((struct nlist_64*)(nlist_data + (nlist_idx * nlist_size)));
833 }
834
835 SymbolType type = eSymbolTypeInvalid;
Greg Claytone1a916a2010-07-21 22:12:05 +0000836 const char* symbol_name = &strtab_data[nlist.n_strx];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000837 if (symbol_name[0] == '\0')
838 symbol_name = NULL;
839 Section* symbol_section = NULL;
840 bool add_nlist = true;
Greg Claytone1a916a2010-07-21 22:12:05 +0000841 bool is_debug = ((nlist.n_type & NlistMaskStab) != 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000842
843 assert (sym_idx < num_syms);
844
845 sym[sym_idx].SetDebug (is_debug);
846
847 if (is_debug)
848 {
849 switch (nlist.n_type)
850 {
Greg Claytone1a916a2010-07-21 22:12:05 +0000851 case StabGlobalSymbol:
852 // N_GSYM -- global symbol: name,,NO_SECT,type,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853 // Sometimes the N_GSYM value contains the address.
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000854 sym[sym_idx].SetExternal(true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000855 if (nlist.n_value != 0)
856 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000857 type = eSymbolTypeData;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000858 break;
859
Greg Claytone1a916a2010-07-21 22:12:05 +0000860 case StabFunctionName:
861 // N_FNAME -- procedure name (f77 kludge): name,,NO_SECT,0,0
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000862 type = eSymbolTypeCompiler;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000863 break;
864
Greg Claytone1a916a2010-07-21 22:12:05 +0000865 case StabFunction:
866 // N_FUN -- procedure: name,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867 if (symbol_name)
868 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000869 type = eSymbolTypeCode;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Clayton928d8292010-09-08 16:38:06 +0000871
872 N_FUN_addr_to_sym_idx[nlist.n_value] = sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000873 // We use the current number of symbols in the symbol table in lieu of
874 // using nlist_idx in case we ever start trimming entries out
875 N_FUN_indexes.push_back(sym_idx);
876 }
877 else
878 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000879 type = eSymbolTypeCompiler;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880
881 if ( !N_FUN_indexes.empty() )
882 {
883 // Copy the size of the function into the original STAB entry so we don't have
884 // to hunt for it later
885 symtab->SymbolAtIndex(N_FUN_indexes.back())->SetByteSize(nlist.n_value);
886 N_FUN_indexes.pop_back();
Jason Molendaea84e762010-07-06 22:38:03 +0000887 // We don't really need the end function STAB as it contains the size which
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000888 // we already placed with the original symbol, so don't add it if we want a
889 // minimal symbol table
890 if (minimize)
891 add_nlist = false;
892 }
893 }
894 break;
895
Greg Claytone1a916a2010-07-21 22:12:05 +0000896 case StabStaticSymbol:
897 // N_STSYM -- static symbol: name,,n_sect,type,address
Greg Clayton928d8292010-09-08 16:38:06 +0000898 N_STSYM_addr_to_sym_idx[nlist.n_value] = sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000899 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000900 type = eSymbolTypeData;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000901 break;
902
Greg Claytone1a916a2010-07-21 22:12:05 +0000903 case StabLocalCommon:
904 // N_LCSYM -- .lcomm symbol: name,,n_sect,type,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000905 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
906 type = eSymbolTypeCommonBlock;
907 break;
908
Greg Claytone1a916a2010-07-21 22:12:05 +0000909 case StabBeginSymbol:
910 // N_BNSYM
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000911 // We use the current number of symbols in the symbol table in lieu of
912 // using nlist_idx in case we ever start trimming entries out
913 if (minimize)
914 {
915 // Skip these if we want minimal symbol tables
916 add_nlist = false;
917 }
918 else
919 {
920 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
921 N_NSYM_indexes.push_back(sym_idx);
922 type = eSymbolTypeScopeBegin;
923 }
924 break;
925
Greg Claytone1a916a2010-07-21 22:12:05 +0000926 case StabEndSymbol:
927 // N_ENSYM
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000928 // Set the size of the N_BNSYM to the terminating index of this N_ENSYM
929 // so that we can always skip the entire symbol if we need to navigate
930 // more quickly at the source level when parsing STABS
931 if (minimize)
932 {
933 // Skip these if we want minimal symbol tables
934 add_nlist = false;
935 }
936 else
937 {
938 if ( !N_NSYM_indexes.empty() )
939 {
940 symbol_ptr = symtab->SymbolAtIndex(N_NSYM_indexes.back());
941 symbol_ptr->SetByteSize(sym_idx + 1);
942 symbol_ptr->SetSizeIsSibling(true);
943 N_NSYM_indexes.pop_back();
944 }
945 type = eSymbolTypeScopeEnd;
946 }
947 break;
948
949
Greg Claytone1a916a2010-07-21 22:12:05 +0000950 case StabSourceFileOptions:
951 // N_OPT - emitted with gcc2_compiled and in gcc source
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000952 type = eSymbolTypeCompiler;
953 break;
954
Greg Claytone1a916a2010-07-21 22:12:05 +0000955 case StabRegisterSymbol:
956 // N_RSYM - register sym: name,,NO_SECT,type,register
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957 type = eSymbolTypeVariable;
958 break;
959
Greg Claytone1a916a2010-07-21 22:12:05 +0000960 case StabSourceLine:
961 // N_SLINE - src line: 0,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000962 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
963 type = eSymbolTypeLineEntry;
964 break;
965
Greg Claytone1a916a2010-07-21 22:12:05 +0000966 case StabStructureType:
967 // N_SSYM - structure elt: name,,NO_SECT,type,struct_offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000968 type = eSymbolTypeVariableType;
969 break;
970
Greg Claytone1a916a2010-07-21 22:12:05 +0000971 case StabSourceFileName:
972 // N_SO - source file name
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000973 type = eSymbolTypeSourceFile;
974 if (symbol_name == NULL)
975 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000976 if (minimize)
977 add_nlist = false;
978 if (N_SO_index != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000979 {
980 // Set the size of the N_SO to the terminating index of this N_SO
981 // so that we can always skip the entire N_SO if we need to navigate
982 // more quickly at the source level when parsing STABS
983 symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000984 symbol_ptr->SetByteSize(sym_idx + (minimize ? 0 : 1));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000985 symbol_ptr->SetSizeIsSibling(true);
986 }
987 N_NSYM_indexes.clear();
988 N_INCL_indexes.clear();
989 N_BRAC_indexes.clear();
990 N_COMM_indexes.clear();
991 N_FUN_indexes.clear();
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000992 N_SO_index = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000994 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995 {
996 // We use the current number of symbols in the symbol table in lieu of
997 // using nlist_idx in case we ever start trimming entries out
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000998 if (symbol_name[0] == '/')
999 N_SO_index = sym_idx;
Greg Clayton5cf21f52011-06-19 04:26:01 +00001000 else if (minimize && (N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001001 {
1002 const char *so_path = sym[sym_idx - 1].GetMangled().GetDemangledName().AsCString();
1003 if (so_path && so_path[0])
1004 {
1005 std::string full_so_path (so_path);
1006 if (*full_so_path.rbegin() != '/')
1007 full_so_path += '/';
1008 full_so_path += symbol_name;
1009 sym[sym_idx - 1].GetMangled().SetValue(full_so_path.c_str(), false);
1010 add_nlist = false;
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001011 m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001012 }
1013 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001015
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001016 break;
1017
Greg Claytone1a916a2010-07-21 22:12:05 +00001018 case StabObjectFileName:
1019 // N_OSO - object file name: name,,0,0,st_mtime
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001020 type = eSymbolTypeObjectFile;
1021 break;
1022
Greg Claytone1a916a2010-07-21 22:12:05 +00001023 case StabLocalSymbol:
1024 // N_LSYM - local sym: name,,NO_SECT,type,offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001025 type = eSymbolTypeLocal;
1026 break;
1027
1028 //----------------------------------------------------------------------
1029 // INCL scopes
1030 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001031 case StabBeginIncludeFileName:
1032 // N_BINCL - include file beginning: name,,NO_SECT,0,sum
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001033 // We use the current number of symbols in the symbol table in lieu of
1034 // using nlist_idx in case we ever start trimming entries out
1035 N_INCL_indexes.push_back(sym_idx);
1036 type = eSymbolTypeScopeBegin;
1037 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038
Greg Claytone1a916a2010-07-21 22:12:05 +00001039 case StabEndIncludeFile:
1040 // N_EINCL - include file end: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001041 // Set the size of the N_BINCL to the terminating index of this N_EINCL
1042 // so that we can always skip the entire symbol if we need to navigate
1043 // more quickly at the source level when parsing STABS
1044 if ( !N_INCL_indexes.empty() )
1045 {
1046 symbol_ptr = symtab->SymbolAtIndex(N_INCL_indexes.back());
1047 symbol_ptr->SetByteSize(sym_idx + 1);
1048 symbol_ptr->SetSizeIsSibling(true);
1049 N_INCL_indexes.pop_back();
1050 }
1051 type = eSymbolTypeScopeEnd;
1052 break;
1053
Greg Claytone1a916a2010-07-21 22:12:05 +00001054 case StabIncludeFileName:
1055 // N_SOL - #included file name: name,,n_sect,0,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001056 type = eSymbolTypeHeaderFile;
Greg Clayton49bd1c82010-09-07 17:36:17 +00001057
1058 // We currently don't use the header files on darwin
1059 if (minimize)
1060 add_nlist = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061 break;
1062
Greg Claytone1a916a2010-07-21 22:12:05 +00001063 case StabCompilerParameters:
1064 // N_PARAMS - compiler parameters: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001065 type = eSymbolTypeCompiler;
1066 break;
1067
Greg Claytone1a916a2010-07-21 22:12:05 +00001068 case StabCompilerVersion:
1069 // N_VERSION - compiler version: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001070 type = eSymbolTypeCompiler;
1071 break;
1072
Greg Claytone1a916a2010-07-21 22:12:05 +00001073 case StabCompilerOptLevel:
1074 // N_OLEVEL - compiler -O level: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001075 type = eSymbolTypeCompiler;
1076 break;
1077
Greg Claytone1a916a2010-07-21 22:12:05 +00001078 case StabParameter:
1079 // N_PSYM - parameter: name,,NO_SECT,type,offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001080 type = eSymbolTypeVariable;
1081 break;
1082
Greg Claytone1a916a2010-07-21 22:12:05 +00001083 case StabAlternateEntry:
1084 // N_ENTRY - alternate entry: name,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001085 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1086 type = eSymbolTypeLineEntry;
1087 break;
1088
1089 //----------------------------------------------------------------------
1090 // Left and Right Braces
1091 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001092 case StabLeftBracket:
1093 // N_LBRAC - left bracket: 0,,NO_SECT,nesting level,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 // We use the current number of symbols in the symbol table in lieu of
1095 // using nlist_idx in case we ever start trimming entries out
1096 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1097 N_BRAC_indexes.push_back(sym_idx);
1098 type = eSymbolTypeScopeBegin;
1099 break;
1100
Greg Claytone1a916a2010-07-21 22:12:05 +00001101 case StabRightBracket:
1102 // N_RBRAC - right bracket: 0,,NO_SECT,nesting level,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001103 // Set the size of the N_LBRAC to the terminating index of this N_RBRAC
1104 // so that we can always skip the entire symbol if we need to navigate
1105 // more quickly at the source level when parsing STABS
1106 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1107 if ( !N_BRAC_indexes.empty() )
1108 {
1109 symbol_ptr = symtab->SymbolAtIndex(N_BRAC_indexes.back());
1110 symbol_ptr->SetByteSize(sym_idx + 1);
1111 symbol_ptr->SetSizeIsSibling(true);
1112 N_BRAC_indexes.pop_back();
1113 }
1114 type = eSymbolTypeScopeEnd;
1115 break;
1116
Greg Claytone1a916a2010-07-21 22:12:05 +00001117 case StabDeletedIncludeFile:
1118 // N_EXCL - deleted include file: name,,NO_SECT,0,sum
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001119 type = eSymbolTypeHeaderFile;
1120 break;
1121
1122 //----------------------------------------------------------------------
1123 // COMM scopes
1124 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001125 case StabBeginCommon:
1126 // N_BCOMM - begin common: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001127 // We use the current number of symbols in the symbol table in lieu of
1128 // using nlist_idx in case we ever start trimming entries out
1129 type = eSymbolTypeScopeBegin;
1130 N_COMM_indexes.push_back(sym_idx);
1131 break;
1132
Greg Claytone1a916a2010-07-21 22:12:05 +00001133 case StabEndCommonLocal:
1134 // N_ECOML - end common (local name): 0,,n_sect,0,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001135 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1136 // Fall through
1137
Greg Claytone1a916a2010-07-21 22:12:05 +00001138 case StabEndCommon:
1139 // N_ECOMM - end common: name,,n_sect,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001140 // Set the size of the N_BCOMM to the terminating index of this N_ECOMM/N_ECOML
1141 // so that we can always skip the entire symbol if we need to navigate
1142 // more quickly at the source level when parsing STABS
1143 if ( !N_COMM_indexes.empty() )
1144 {
1145 symbol_ptr = symtab->SymbolAtIndex(N_COMM_indexes.back());
1146 symbol_ptr->SetByteSize(sym_idx + 1);
1147 symbol_ptr->SetSizeIsSibling(true);
1148 N_COMM_indexes.pop_back();
1149 }
1150 type = eSymbolTypeScopeEnd;
1151 break;
1152
Greg Claytone1a916a2010-07-21 22:12:05 +00001153 case StabLength:
1154 // N_LENG - second stab entry with length information
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 type = eSymbolTypeAdditional;
1156 break;
1157
1158 default: break;
1159 }
1160 }
1161 else
1162 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001163 //uint8_t n_pext = NlistMaskPrivateExternal & nlist.n_type;
1164 uint8_t n_type = NlistMaskType & nlist.n_type;
1165 sym[sym_idx].SetExternal((NlistMaskExternal & nlist.n_type) != 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001166
1167 if (symbol_name && ::strstr (symbol_name, ".objc") == symbol_name)
1168 {
1169 type = eSymbolTypeRuntime;
1170 }
1171 else
1172 {
1173 switch (n_type)
1174 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001175 case NListTypeIndirect: // N_INDR - Fall through
1176 case NListTypePreboundUndefined:// N_PBUD - Fall through
1177 case NListTypeUndefined: // N_UNDF
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001178 type = eSymbolTypeExtern;
1179 break;
1180
Greg Claytone1a916a2010-07-21 22:12:05 +00001181 case NListTypeAbsolute: // N_ABS
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001182 type = eSymbolTypeAbsolute;
1183 break;
1184
Greg Claytone1a916a2010-07-21 22:12:05 +00001185 case NListTypeSection: // N_SECT
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001186 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1187
Greg Clayton8f258512011-08-26 20:01:35 +00001188 if (symbol_section == NULL)
1189 {
1190 // TODO: warn about this?
1191 add_nlist = false;
1192 break;
1193 }
1194
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001195 if (TEXT_eh_frame_sectID == nlist.n_sect)
1196 {
1197 type = eSymbolTypeException;
1198 }
1199 else
1200 {
Greg Clayton73b472d2010-10-27 03:32:59 +00001201 uint32_t section_type = symbol_section->Get() & SectionFlagMaskSectionType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202
1203 switch (section_type)
1204 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001205 case SectionTypeRegular: break; // regular section
1206 //case SectionTypeZeroFill: type = eSymbolTypeData; break; // zero fill on demand section
1207 case SectionTypeCStringLiterals: type = eSymbolTypeData; break; // section with only literal C strings
1208 case SectionType4ByteLiterals: type = eSymbolTypeData; break; // section with only 4 byte literals
1209 case SectionType8ByteLiterals: type = eSymbolTypeData; break; // section with only 8 byte literals
1210 case SectionTypeLiteralPointers: type = eSymbolTypeTrampoline; break; // section with only pointers to literals
1211 case SectionTypeNonLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
1212 case SectionTypeLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
1213 case SectionTypeSymbolStubs: type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
1214 case SectionTypeModuleInitFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for initialization
1215 case SectionTypeModuleTermFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for termination
1216 //case SectionTypeCoalesced: type = eSymbolType; break; // section contains symbols that are to be coalesced
1217 //case SectionTypeZeroFillLarge: type = eSymbolTypeData; break; // zero fill on demand section (that can be larger than 4 gigabytes)
1218 case SectionTypeInterposing: type = eSymbolTypeTrampoline; break; // section with only pairs of function pointers for interposing
1219 case SectionType16ByteLiterals: type = eSymbolTypeData; break; // section with only 16 byte literals
1220 case SectionTypeDTraceObjectFormat: type = eSymbolTypeInstrumentation; break;
1221 case SectionTypeLazyDylibSymbolPointers: type = eSymbolTypeTrampoline; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001222 default: break;
1223 }
1224
1225 if (type == eSymbolTypeInvalid)
1226 {
1227 const char *symbol_sect_name = symbol_section->GetName().AsCString();
1228 if (symbol_section->IsDescendant (text_section_sp.get()))
1229 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001230 if (symbol_section->IsClear(SectionAttrUserPureInstructions |
1231 SectionAttrUserSelfModifyingCode |
1232 SectionAttrSytemSomeInstructions))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001233 type = eSymbolTypeData;
1234 else
1235 type = eSymbolTypeCode;
1236 }
1237 else
1238 if (symbol_section->IsDescendant(data_section_sp.get()))
1239 {
1240 if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
1241 {
1242 type = eSymbolTypeRuntime;
1243 }
1244 else
1245 if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
1246 {
1247 type = eSymbolTypeException;
1248 }
1249 else
1250 {
1251 type = eSymbolTypeData;
1252 }
1253 }
1254 else
1255 if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
1256 {
1257 type = eSymbolTypeTrampoline;
1258 }
1259 else
1260 if (symbol_section->IsDescendant(objc_section_sp.get()))
1261 {
1262 type = eSymbolTypeRuntime;
1263 }
1264 }
1265 }
1266 break;
Greg Clayton928d8292010-09-08 16:38:06 +00001267 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001268 }
1269 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270 if (add_nlist)
1271 {
1272 bool symbol_name_is_mangled = false;
1273 if (symbol_name && symbol_name[0] == '_')
1274 {
1275 symbol_name_is_mangled = symbol_name[1] == '_';
1276 symbol_name++; // Skip the leading underscore
1277 }
1278 uint64_t symbol_value = nlist.n_value;
Greg Clayton928d8292010-09-08 16:38:06 +00001279
1280 if (symbol_name)
1281 sym[sym_idx].GetMangled().SetValue(symbol_name, symbol_name_is_mangled);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001282 if (is_debug == false)
Greg Clayton928d8292010-09-08 16:38:06 +00001283 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001284 if (type == eSymbolTypeCode)
Greg Clayton928d8292010-09-08 16:38:06 +00001285 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001286 // See if we can find a N_FUN entry for any code symbols.
1287 // If we do find a match, and the name matches, then we
1288 // can merge the two into just the function symbol to avoid
1289 // duplicate entries in the symbol table
1290 ValueToSymbolIndexMap::const_iterator pos = N_FUN_addr_to_sym_idx.find (nlist.n_value);
1291 if (pos != N_FUN_addr_to_sym_idx.end())
Greg Clayton928d8292010-09-08 16:38:06 +00001292 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001293 if ((symbol_name_is_mangled == true && sym[sym_idx].GetMangled().GetMangledName() == sym[pos->second].GetMangled().GetMangledName()) ||
1294 (symbol_name_is_mangled == false && sym[sym_idx].GetMangled().GetDemangledName() == sym[pos->second].GetMangled().GetDemangledName()))
1295 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001296 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001297 // We just need the flags from the linker symbol, so put these flags
1298 // into the N_FUN flags to avoid duplicate symbols in the symbol table
1299 sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1300 sym[sym_idx].Clear();
1301 continue;
1302 }
Greg Clayton928d8292010-09-08 16:38:06 +00001303 }
1304 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001305 else if (type == eSymbolTypeData)
Greg Clayton928d8292010-09-08 16:38:06 +00001306 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001307 // See if we can find a N_STSYM entry for any data symbols.
1308 // If we do find a match, and the name matches, then we
1309 // can merge the two into just the Static symbol to avoid
1310 // duplicate entries in the symbol table
1311 ValueToSymbolIndexMap::const_iterator pos = N_STSYM_addr_to_sym_idx.find (nlist.n_value);
1312 if (pos != N_STSYM_addr_to_sym_idx.end())
Greg Clayton928d8292010-09-08 16:38:06 +00001313 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001314 if ((symbol_name_is_mangled == true && sym[sym_idx].GetMangled().GetMangledName() == sym[pos->second].GetMangled().GetMangledName()) ||
1315 (symbol_name_is_mangled == false && sym[sym_idx].GetMangled().GetDemangledName() == sym[pos->second].GetMangled().GetDemangledName()))
1316 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001317 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001318 // We just need the flags from the linker symbol, so put these flags
1319 // into the N_STSYM flags to avoid duplicate symbols in the symbol table
1320 sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1321 sym[sym_idx].Clear();
1322 continue;
1323 }
Greg Clayton928d8292010-09-08 16:38:06 +00001324 }
1325 }
1326 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 if (symbol_section != NULL)
1328 symbol_value -= symbol_section->GetFileAddress();
1329
1330 sym[sym_idx].SetID (nlist_idx);
1331 sym[sym_idx].SetType (type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001332 sym[sym_idx].GetAddressRangeRef().GetBaseAddress().SetSection (symbol_section);
1333 sym[sym_idx].GetAddressRangeRef().GetBaseAddress().SetOffset (symbol_value);
1334 sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1335
1336 ++sym_idx;
1337 }
1338 else
1339 {
1340 sym[sym_idx].Clear();
1341 }
1342
1343 }
1344
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001345 // STAB N_GSYM entries end up having a symbol type eSymbolTypeGlobal and when the symbol value
1346 // is zero, the address of the global ends up being in a non-STAB entry. Try and fix up all
1347 // such entries by figuring out what the address for the global is by looking up this non-STAB
1348 // entry and copying the value into the debug symbol's value to save us the hassle in the
1349 // debug symbol parser.
1350
1351 Symbol *global_symbol = NULL;
1352 for (nlist_idx = 0;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001353 nlist_idx < symtab_load_command.nsyms && (global_symbol = symtab->FindSymbolWithType (eSymbolTypeData, Symtab::eDebugYes, Symtab::eVisibilityAny, nlist_idx)) != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001354 nlist_idx++)
1355 {
1356 if (global_symbol->GetValue().GetFileAddress() == 0)
1357 {
1358 std::vector<uint32_t> indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001359 if (symtab->AppendSymbolIndexesWithName (global_symbol->GetMangled().GetName(), indexes) > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001360 {
1361 std::vector<uint32_t>::const_iterator pos;
1362 std::vector<uint32_t>::const_iterator end = indexes.end();
1363 for (pos = indexes.begin(); pos != end; ++pos)
1364 {
1365 symbol_ptr = symtab->SymbolAtIndex(*pos);
1366 if (symbol_ptr != global_symbol && symbol_ptr->IsDebug() == false)
1367 {
1368 global_symbol->SetValue(symbol_ptr->GetValue());
1369 break;
1370 }
1371 }
1372 }
1373 }
1374 }
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001375
1376 // Trim our symbols down to just what we ended up with after
1377 // removing any symbols.
1378 if (sym_idx < num_syms)
1379 {
1380 num_syms = sym_idx;
1381 sym = symtab->Resize (num_syms);
1382 }
1383
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001384 // Now synthesize indirect symbols
1385 if (m_dysymtab.nindirectsyms != 0)
1386 {
1387 DataBufferSP indirect_symbol_indexes_sp(m_file.ReadFileContents(m_offset + m_dysymtab.indirectsymoff, m_dysymtab.nindirectsyms * 4));
1388
1389 if (indirect_symbol_indexes_sp && indirect_symbol_indexes_sp->GetByteSize())
1390 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001391 NListIndexToSymbolIndexMap::const_iterator end_index_pos = m_nlist_idx_to_sym_idx.end();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001392 DataExtractor indirect_symbol_index_data (indirect_symbol_indexes_sp, m_data.GetByteOrder(), m_data.GetAddressByteSize());
1393
1394 for (uint32_t sect_idx = 1; sect_idx < m_mach_sections.size(); ++sect_idx)
1395 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001396 if ((m_mach_sections[sect_idx].flags & SectionFlagMaskSectionType) == SectionTypeSymbolStubs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001397 {
1398 uint32_t symbol_stub_byte_size = m_mach_sections[sect_idx].reserved2;
1399 if (symbol_stub_byte_size == 0)
1400 continue;
1401
1402 const uint32_t num_symbol_stubs = m_mach_sections[sect_idx].size / symbol_stub_byte_size;
1403
1404 if (num_symbol_stubs == 0)
1405 continue;
1406
1407 const uint32_t symbol_stub_index_offset = m_mach_sections[sect_idx].reserved1;
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001408 uint32_t synthetic_stub_sym_id = symtab_load_command.nsyms;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001409 for (uint32_t stub_idx = 0; stub_idx < num_symbol_stubs; ++stub_idx)
1410 {
1411 const uint32_t symbol_stub_index = symbol_stub_index_offset + stub_idx;
1412 const lldb::addr_t symbol_stub_addr = m_mach_sections[sect_idx].addr + (stub_idx * symbol_stub_byte_size);
1413 uint32_t symbol_stub_offset = symbol_stub_index * 4;
1414 if (indirect_symbol_index_data.ValidOffsetForDataOfSize(symbol_stub_offset, 4))
1415 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001416 const uint32_t stub_sym_id = indirect_symbol_index_data.GetU32 (&symbol_stub_offset);
Greg Claytonf4abd0d2010-10-06 01:26:32 +00001417 if (stub_sym_id & (IndirectSymbolAbsolute | IndirectSymbolLocal))
1418 continue;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001419
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001420 NListIndexToSymbolIndexMap::const_iterator index_pos = m_nlist_idx_to_sym_idx.find (stub_sym_id);
1421 Symbol *stub_symbol = NULL;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001422 if (index_pos != end_index_pos)
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001423 {
1424 // We have a remapping from the original nlist index to
1425 // a current symbol index, so just look this up by index
1426 stub_symbol = symtab->SymbolAtIndex (index_pos->second);
1427 }
1428 else
1429 {
1430 // We need to lookup a symbol using the original nlist
1431 // symbol index since this index is coming from the
1432 // S_SYMBOL_STUBS
1433 stub_symbol = symtab->FindSymbolByID (stub_sym_id);
1434 }
Greg Clayton49bd1c82010-09-07 17:36:17 +00001435
1436 assert (stub_symbol);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437 if (stub_symbol)
1438 {
1439 Address so_addr(symbol_stub_addr, section_list);
1440
1441 if (stub_symbol->GetType() == eSymbolTypeExtern)
1442 {
1443 // Change the external symbol into a trampoline that makes sense
1444 // These symbols were N_UNDF N_EXT, and are useless to us, so we
1445 // can re-use them so we don't have to make up a synthetic symbol
1446 // for no good reason.
1447 stub_symbol->SetType (eSymbolTypeTrampoline);
1448 stub_symbol->SetExternal (false);
1449 stub_symbol->GetAddressRangeRef().GetBaseAddress() = so_addr;
1450 stub_symbol->GetAddressRangeRef().SetByteSize (symbol_stub_byte_size);
1451 }
1452 else
1453 {
1454 // Make a synthetic symbol to describe the trampoline stub
1455 if (sym_idx >= num_syms)
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001456 sym = symtab->Resize (++num_syms);
1457 sym[sym_idx].SetID (synthetic_stub_sym_id++);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001458 sym[sym_idx].GetMangled() = stub_symbol->GetMangled();
1459 sym[sym_idx].SetType (eSymbolTypeTrampoline);
1460 sym[sym_idx].SetIsSynthetic (true);
1461 sym[sym_idx].GetAddressRangeRef().GetBaseAddress() = so_addr;
1462 sym[sym_idx].GetAddressRangeRef().SetByteSize (symbol_stub_byte_size);
1463 ++sym_idx;
1464 }
1465 }
1466 }
1467 }
1468 }
1469 }
1470 }
1471 }
1472
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001473 return symtab->GetNumSymbols();
1474 }
1475 }
1476 offset = cmd_offset + symtab_load_command.cmdsize;
1477 }
1478 return 0;
1479}
1480
1481
1482void
1483ObjectFileMachO::Dump (Stream *s)
1484{
1485 lldb_private::Mutex::Locker locker(m_mutex);
Jason Molendafd54b362011-09-20 21:44:10 +00001486 s->Printf("%p: ", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001487 s->Indent();
Greg Claytone1a916a2010-07-21 22:12:05 +00001488 if (m_header.magic == HeaderMagic64 || m_header.magic == HeaderMagic64Swapped)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001489 s->PutCString("ObjectFileMachO64");
1490 else
1491 s->PutCString("ObjectFileMachO32");
1492
Greg Clayton41f92322010-06-11 03:25:34 +00001493 ArchSpec header_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494
Greg Clayton64195a22011-02-23 00:35:02 +00001495 *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496
1497 if (m_sections_ap.get())
Greg Clayton10177aa2010-12-08 05:08:21 +00001498 m_sections_ap->Dump(s, NULL, true, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001499
1500 if (m_symtab_ap.get())
Greg Clayton8087ca22010-10-08 04:20:14 +00001501 m_symtab_ap->Dump(s, NULL, eSortOrderNone);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001502}
1503
1504
1505bool
Greg Clayton60830262011-02-04 18:53:10 +00001506ObjectFileMachO::GetUUID (lldb_private::UUID* uuid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001507{
1508 lldb_private::Mutex::Locker locker(m_mutex);
1509 struct uuid_command load_cmd;
1510 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1511 uint32_t i;
1512 for (i=0; i<m_header.ncmds; ++i)
1513 {
1514 const uint32_t cmd_offset = offset;
1515 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1516 break;
1517
Greg Claytone1a916a2010-07-21 22:12:05 +00001518 if (load_cmd.cmd == LoadCommandUUID)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001519 {
1520 const uint8_t *uuid_bytes = m_data.PeekData(offset, 16);
1521 if (uuid_bytes)
1522 {
1523 uuid->SetBytes (uuid_bytes);
1524 return true;
1525 }
1526 return false;
1527 }
1528 offset = cmd_offset + load_cmd.cmdsize;
1529 }
1530 return false;
1531}
1532
1533
1534uint32_t
1535ObjectFileMachO::GetDependentModules (FileSpecList& files)
1536{
1537 lldb_private::Mutex::Locker locker(m_mutex);
1538 struct load_command load_cmd;
1539 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1540 uint32_t count = 0;
Greg Clayton9b72eb72011-05-24 23:06:02 +00001541 const bool resolve_path = false; // Don't resolve the dependend file paths since they may not reside on this system
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001542 uint32_t i;
1543 for (i=0; i<m_header.ncmds; ++i)
1544 {
1545 const uint32_t cmd_offset = offset;
1546 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1547 break;
1548
1549 switch (load_cmd.cmd)
1550 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001551 case LoadCommandDylibLoad:
1552 case LoadCommandDylibLoadWeak:
1553 case LoadCommandDylibReexport:
1554 case LoadCommandDynamicLinkerLoad:
1555 case LoadCommandFixedVMShlibLoad:
Greg Clayton74f6e9f2010-10-09 00:48:53 +00001556 case LoadCommandDylibLoadUpward:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001557 {
1558 uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
1559 const char *path = m_data.PeekCStr(name_offset);
1560 // Skip any path that starts with '@' since these are usually:
1561 // @executable_path/.../file
1562 // @rpath/.../file
1563 if (path && path[0] != '@')
1564 {
Greg Clayton9b72eb72011-05-24 23:06:02 +00001565 FileSpec file_spec(path, resolve_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001566 if (files.AppendIfUnique(file_spec))
1567 count++;
1568 }
1569 }
1570 break;
1571
1572 default:
1573 break;
1574 }
1575 offset = cmd_offset + load_cmd.cmdsize;
1576 }
1577 return count;
1578}
1579
Jim Ingham672e6f52011-03-07 23:44:08 +00001580lldb_private::Address
1581ObjectFileMachO::GetEntryPointAddress ()
1582{
1583 // If the object file is not an executable it can't hold the entry point. m_entry_point_address
1584 // is initialized to an invalid address, so we can just return that.
1585 // If m_entry_point_address is valid it means we've found it already, so return the cached value.
1586
1587 if (!IsExecutable() || m_entry_point_address.IsValid())
1588 return m_entry_point_address;
1589
1590 // Otherwise, look for the UnixThread or Thread command. The data for the Thread command is given in
1591 // /usr/include/mach-o.h, but it is basically:
1592 //
1593 // uint32_t flavor - this is the flavor argument you would pass to thread_get_state
1594 // uint32_t count - this is the count of longs in the thread state data
1595 // struct XXX_thread_state state - this is the structure from <machine/thread_status.h> corresponding to the flavor.
1596 // <repeat this trio>
1597 //
1598 // So we just keep reading the various register flavors till we find the GPR one, then read the PC out of there.
1599 // FIXME: We will need to have a "RegisterContext data provider" class at some point that can get all the registers
1600 // out of data in this form & attach them to a given thread. That should underlie the MacOS X User process plugin,
1601 // and we'll also need it for the MacOS X Core File process plugin. When we have that we can also use it here.
1602 //
1603 // For now we hard-code the offsets and flavors we need:
1604 //
1605 //
1606
1607 lldb_private::Mutex::Locker locker(m_mutex);
1608 struct load_command load_cmd;
1609 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1610 uint32_t i;
1611 lldb::addr_t start_address = LLDB_INVALID_ADDRESS;
1612 bool done = false;
1613
1614 for (i=0; i<m_header.ncmds; ++i)
1615 {
1616 const uint32_t cmd_offset = offset;
1617 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1618 break;
1619
1620 switch (load_cmd.cmd)
1621 {
1622 case LoadCommandUnixThread:
1623 case LoadCommandThread:
1624 {
1625 while (offset < cmd_offset + load_cmd.cmdsize)
1626 {
1627 uint32_t flavor = m_data.GetU32(&offset);
1628 uint32_t count = m_data.GetU32(&offset);
1629 if (count == 0)
1630 {
1631 // We've gotten off somehow, log and exit;
1632 return m_entry_point_address;
1633 }
1634
1635 switch (m_header.cputype)
1636 {
1637 case llvm::MachO::CPUTypeARM:
1638 if (flavor == 1) // ARM_THREAD_STATE from mach/arm/thread_status.h
1639 {
1640 offset += 60; // This is the offset of pc in the GPR thread state data structure.
1641 start_address = m_data.GetU32(&offset);
1642 done = true;
1643 }
1644 break;
1645 case llvm::MachO::CPUTypeI386:
1646 if (flavor == 1) // x86_THREAD_STATE32 from mach/i386/thread_status.h
1647 {
1648 offset += 40; // This is the offset of eip in the GPR thread state data structure.
1649 start_address = m_data.GetU32(&offset);
1650 done = true;
1651 }
1652 break;
1653 case llvm::MachO::CPUTypeX86_64:
1654 if (flavor == 4) // x86_THREAD_STATE64 from mach/i386/thread_status.h
1655 {
1656 offset += 16 * 8; // This is the offset of rip in the GPR thread state data structure.
1657 start_address = m_data.GetU64(&offset);
1658 done = true;
1659 }
1660 break;
1661 default:
1662 return m_entry_point_address;
1663 }
1664 // Haven't found the GPR flavor yet, skip over the data for this flavor:
1665 if (done)
1666 break;
1667 offset += count * 4;
1668 }
1669 }
1670 break;
1671
1672 default:
1673 break;
1674 }
1675 if (done)
1676 break;
1677
1678 // Go to the next load command:
1679 offset = cmd_offset + load_cmd.cmdsize;
1680 }
1681
1682 if (start_address != LLDB_INVALID_ADDRESS)
1683 {
1684 // We got the start address from the load commands, so now resolve that address in the sections
1685 // of this ObjectFile:
1686 if (!m_entry_point_address.ResolveAddressUsingFileSections (start_address, GetSectionList()))
1687 {
1688 m_entry_point_address.Clear();
1689 }
1690 }
1691 else
1692 {
1693 // We couldn't read the UnixThread load command - maybe it wasn't there. As a fallback look for the
1694 // "start" symbol in the main executable.
1695
1696 SymbolContextList contexts;
1697 SymbolContext context;
Greg Claytone0d378b2011-03-24 21:19:54 +00001698 if (!m_module->FindSymbolsWithNameAndType(ConstString ("start"), eSymbolTypeCode, contexts))
Jim Ingham672e6f52011-03-07 23:44:08 +00001699 return m_entry_point_address;
1700
1701 contexts.GetContextAtIndex(0, context);
1702
1703 m_entry_point_address = context.symbol->GetValue();
1704 }
1705
1706 return m_entry_point_address;
1707
1708}
1709
Greg Clayton9e00b6a652011-07-09 00:41:34 +00001710ObjectFile::Type
1711ObjectFileMachO::CalculateType()
1712{
1713 switch (m_header.filetype)
1714 {
1715 case HeaderFileTypeObject: // 0x1u MH_OBJECT
1716 if (GetAddressByteSize () == 4)
1717 {
1718 // 32 bit kexts are just object files, but they do have a valid
1719 // UUID load command.
1720 UUID uuid;
1721 if (GetUUID(&uuid))
1722 {
1723 // this checking for the UUID load command is not enough
1724 // we could eventually look for the symbol named
1725 // "OSKextGetCurrentIdentifier" as this is required of kexts
1726 if (m_strata == eStrataInvalid)
1727 m_strata = eStrataKernel;
1728 return eTypeSharedLibrary;
1729 }
1730 }
1731 return eTypeObjectFile;
1732
1733 case HeaderFileTypeExecutable: return eTypeExecutable; // 0x2u MH_EXECUTE
1734 case HeaderFileTypeFixedVMShlib: return eTypeSharedLibrary; // 0x3u MH_FVMLIB
1735 case HeaderFileTypeCore: return eTypeCoreFile; // 0x4u MH_CORE
1736 case HeaderFileTypePreloadedExecutable: return eTypeSharedLibrary; // 0x5u MH_PRELOAD
1737 case HeaderFileTypeDynamicShlib: return eTypeSharedLibrary; // 0x6u MH_DYLIB
1738 case HeaderFileTypeDynamicLinkEditor: return eTypeDynamicLinker; // 0x7u MH_DYLINKER
1739 case HeaderFileTypeBundle: return eTypeSharedLibrary; // 0x8u MH_BUNDLE
1740 case HeaderFileTypeDynamicShlibStub: return eTypeStubLibrary; // 0x9u MH_DYLIB_STUB
1741 case HeaderFileTypeDSYM: return eTypeDebugInfo; // 0xAu MH_DSYM
1742 case HeaderFileTypeKextBundle: return eTypeSharedLibrary; // 0xBu MH_KEXT_BUNDLE
1743 default:
1744 break;
1745 }
1746 return eTypeUnknown;
1747}
1748
1749ObjectFile::Strata
1750ObjectFileMachO::CalculateStrata()
1751{
1752 switch (m_header.filetype)
1753 {
1754 case HeaderFileTypeObject: // 0x1u MH_OBJECT
1755 {
1756 // 32 bit kexts are just object files, but they do have a valid
1757 // UUID load command.
1758 UUID uuid;
1759 if (GetUUID(&uuid))
1760 {
1761 // this checking for the UUID load command is not enough
1762 // we could eventually look for the symbol named
1763 // "OSKextGetCurrentIdentifier" as this is required of kexts
1764 if (m_type == eTypeInvalid)
1765 m_type = eTypeSharedLibrary;
1766
1767 return eStrataKernel;
1768 }
1769 }
1770 return eStrataUnknown;
1771
1772 case HeaderFileTypeExecutable: // 0x2u MH_EXECUTE
1773 // Check for the MH_DYLDLINK bit in the flags
1774 if (m_header.flags & HeaderFlagBitIsDynamicLinkObject)
1775 return eStrataUser;
1776 return eStrataKernel;
1777
1778 case HeaderFileTypeFixedVMShlib: return eStrataUser; // 0x3u MH_FVMLIB
1779 case HeaderFileTypeCore: return eStrataUnknown; // 0x4u MH_CORE
1780 case HeaderFileTypePreloadedExecutable: return eStrataUser; // 0x5u MH_PRELOAD
1781 case HeaderFileTypeDynamicShlib: return eStrataUser; // 0x6u MH_DYLIB
1782 case HeaderFileTypeDynamicLinkEditor: return eStrataUser; // 0x7u MH_DYLINKER
1783 case HeaderFileTypeBundle: return eStrataUser; // 0x8u MH_BUNDLE
1784 case HeaderFileTypeDynamicShlibStub: return eStrataUser; // 0x9u MH_DYLIB_STUB
1785 case HeaderFileTypeDSYM: return eStrataUnknown; // 0xAu MH_DSYM
1786 case HeaderFileTypeKextBundle: return eStrataKernel; // 0xBu MH_KEXT_BUNDLE
1787 default:
1788 break;
1789 }
1790 return eStrataUnknown;
1791}
1792
1793
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794bool
Greg Clayton514487e2011-02-15 21:59:32 +00001795ObjectFileMachO::GetArchitecture (ArchSpec &arch)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796{
1797 lldb_private::Mutex::Locker locker(m_mutex);
Greg Claytone0d378b2011-03-24 21:19:54 +00001798 arch.SetArchitecture (eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Greg Clayton593577a2011-09-21 03:57:31 +00001799
1800 // Files with type MH_PRELOAD are currently used in cases where the image
1801 // debugs at the addresses in the file itself. Below we set the OS to
1802 // unknown to make sure we use the DynamicLoaderStatic()...
1803 if (m_header.filetype == HeaderFileTypePreloadedExecutable)
1804 {
1805 arch.GetTriple().setOS (llvm::Triple::UnknownOS);
1806 }
1807
Greg Clayton514487e2011-02-15 21:59:32 +00001808 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001809}
1810
1811
1812//------------------------------------------------------------------
1813// PluginInterface protocol
1814//------------------------------------------------------------------
1815const char *
1816ObjectFileMachO::GetPluginName()
1817{
1818 return "ObjectFileMachO";
1819}
1820
1821const char *
1822ObjectFileMachO::GetShortPluginName()
1823{
1824 return GetPluginNameStatic();
1825}
1826
1827uint32_t
1828ObjectFileMachO::GetPluginVersion()
1829{
1830 return 1;
1831}
1832