blob: 9a5ce34137aca7b1b5422c4469cc50a5b2ddd235 [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"
Sean Callananb6d70eb2011-10-12 02:08:07 +000025#include "lldb/Symbol/ClangNamespaceDecl.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Symbol/ObjectFile.h"
27
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29using namespace lldb;
30using namespace lldb_private;
Greg Claytone1a916a2010-07-21 22:12:05 +000031using namespace llvm::MachO;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032
Greg Claytonded470d2011-03-19 01:12:21 +000033#define MACHO_NLIST_ARM_SYMBOL_IS_THUMB 0x0008
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034
35void
36ObjectFileMachO::Initialize()
37{
38 PluginManager::RegisterPlugin (GetPluginNameStatic(),
39 GetPluginDescriptionStatic(),
40 CreateInstance);
41}
42
43void
44ObjectFileMachO::Terminate()
45{
46 PluginManager::UnregisterPlugin (CreateInstance);
47}
48
49
50const char *
51ObjectFileMachO::GetPluginNameStatic()
52{
53 return "object-file.mach-o";
54}
55
56const char *
57ObjectFileMachO::GetPluginDescriptionStatic()
58{
59 return "Mach-o object file reader (32 and 64 bit)";
60}
61
62
63ObjectFile *
64ObjectFileMachO::CreateInstance (Module* module, DataBufferSP& dataSP, const FileSpec* file, addr_t offset, addr_t length)
65{
66 if (ObjectFileMachO::MagicBytesMatch(dataSP))
67 {
68 std::auto_ptr<ObjectFile> objfile_ap(new ObjectFileMachO (module, dataSP, file, offset, length));
69 if (objfile_ap.get() && objfile_ap->ParseHeader())
70 return objfile_ap.release();
71 }
72 return NULL;
73}
74
75
76static uint32_t
77MachHeaderSizeFromMagic(uint32_t magic)
78{
79 switch (magic)
80 {
Greg Claytone1a916a2010-07-21 22:12:05 +000081 case HeaderMagic32:
82 case HeaderMagic32Swapped:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083 return sizeof(struct mach_header);
84
Greg Claytone1a916a2010-07-21 22:12:05 +000085 case HeaderMagic64:
86 case HeaderMagic64Swapped:
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087 return sizeof(struct mach_header_64);
88 break;
89
90 default:
91 break;
92 }
93 return 0;
94}
95
96
97bool
98ObjectFileMachO::MagicBytesMatch (DataBufferSP& dataSP)
99{
Greg Clayton7fb56d02011-02-01 01:31:41 +0000100 DataExtractor data(dataSP, lldb::endian::InlHostByteOrder(), 4);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000101 uint32_t offset = 0;
102 uint32_t magic = data.GetU32(&offset);
103 return MachHeaderSizeFromMagic(magic) != 0;
104}
105
106
107ObjectFileMachO::ObjectFileMachO(Module* module, DataBufferSP& dataSP, const FileSpec* file, addr_t offset, addr_t length) :
108 ObjectFile(module, file, offset, length, dataSP),
109 m_mutex (Mutex::eMutexTypeRecursive),
110 m_header(),
111 m_sections_ap(),
Jim Ingham672e6f52011-03-07 23:44:08 +0000112 m_symtab_ap(),
113 m_entry_point_address ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000114{
Greg Clayton72b77eb2011-02-04 21:13:05 +0000115 ::memset (&m_header, 0, sizeof(m_header));
116 ::memset (&m_dysymtab, 0, sizeof(m_dysymtab));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117}
118
119
120ObjectFileMachO::~ObjectFileMachO()
121{
122}
123
124
125bool
126ObjectFileMachO::ParseHeader ()
127{
128 lldb_private::Mutex::Locker locker(m_mutex);
129 bool can_parse = false;
130 uint32_t offset = 0;
Greg Clayton7fb56d02011-02-01 01:31:41 +0000131 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132 // Leave magic in the original byte order
133 m_header.magic = m_data.GetU32(&offset);
134 switch (m_header.magic)
135 {
Greg Claytone1a916a2010-07-21 22:12:05 +0000136 case HeaderMagic32:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000137 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 m_data.SetAddressByteSize(4);
139 can_parse = true;
140 break;
141
Greg Claytone1a916a2010-07-21 22:12:05 +0000142 case HeaderMagic64:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000143 m_data.SetByteOrder (lldb::endian::InlHostByteOrder());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144 m_data.SetAddressByteSize(8);
145 can_parse = true;
146 break;
147
Greg Claytone1a916a2010-07-21 22:12:05 +0000148 case HeaderMagic32Swapped:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000149 m_data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000150 m_data.SetAddressByteSize(4);
151 can_parse = true;
152 break;
153
Greg Claytone1a916a2010-07-21 22:12:05 +0000154 case HeaderMagic64Swapped:
Greg Clayton7fb56d02011-02-01 01:31:41 +0000155 m_data.SetByteOrder(lldb::endian::InlHostByteOrder() == eByteOrderBig ? eByteOrderLittle : eByteOrderBig);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000156 m_data.SetAddressByteSize(8);
157 can_parse = true;
158 break;
159
160 default:
161 break;
162 }
163
164 if (can_parse)
165 {
166 m_data.GetU32(&offset, &m_header.cputype, 6);
167
Greg Clayton41f92322010-06-11 03:25:34 +0000168 ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Jim Ingham5aee1622010-08-09 23:31:02 +0000169
170 if (SetModulesArchitecture (mach_arch))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000171 {
172 // Read in all only the load command data
173 DataBufferSP data_sp(m_file.ReadFileContents(m_offset, m_header.sizeofcmds + MachHeaderSizeFromMagic(m_header.magic)));
174 m_data.SetData (data_sp);
175 return true;
176 }
177 }
178 else
179 {
180 memset(&m_header, 0, sizeof(struct mach_header));
181 }
182 return false;
183}
184
185
186ByteOrder
187ObjectFileMachO::GetByteOrder () const
188{
189 lldb_private::Mutex::Locker locker(m_mutex);
190 return m_data.GetByteOrder ();
191}
192
Jim Ingham5aee1622010-08-09 23:31:02 +0000193bool
194ObjectFileMachO::IsExecutable() const
195{
196 return m_header.filetype == HeaderFileTypeExecutable;
197}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198
199size_t
200ObjectFileMachO::GetAddressByteSize () const
201{
202 lldb_private::Mutex::Locker locker(m_mutex);
203 return m_data.GetAddressByteSize ();
204}
205
Greg Claytone0d378b2011-03-24 21:19:54 +0000206AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +0000207ObjectFileMachO::GetAddressClass (lldb::addr_t file_addr)
208{
209 Symtab *symtab = GetSymtab();
210 if (symtab)
211 {
212 Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
213 if (symbol)
214 {
215 const AddressRange *range_ptr = symbol->GetAddressRangePtr();
216 if (range_ptr)
217 {
218 const Section *section = range_ptr->GetBaseAddress().GetSection();
219 if (section)
220 {
Greg Claytone0d378b2011-03-24 21:19:54 +0000221 const SectionType section_type = section->GetType();
Greg Claytonded470d2011-03-19 01:12:21 +0000222 switch (section_type)
223 {
224 case eSectionTypeInvalid: return eAddressClassUnknown;
225 case eSectionTypeCode:
226 if (m_header.cputype == llvm::MachO::CPUTypeARM)
227 {
228 // For ARM we have a bit in the n_desc field of the symbol
229 // that tells us ARM/Thumb which is bit 0x0008.
230 if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
231 return eAddressClassCodeAlternateISA;
232 }
233 return eAddressClassCode;
234
235 case eSectionTypeContainer: return eAddressClassUnknown;
Greg Clayton5009f9d2011-10-27 17:55:14 +0000236 case eSectionTypeData:
237 case eSectionTypeDataCString:
238 case eSectionTypeDataCStringPointers:
239 case eSectionTypeDataSymbolAddress:
240 case eSectionTypeData4:
241 case eSectionTypeData8:
242 case eSectionTypeData16:
243 case eSectionTypeDataPointers:
244 case eSectionTypeZeroFill:
245 case eSectionTypeDataObjCMessageRefs:
246 case eSectionTypeDataObjCCFStrings:
247 return eAddressClassData;
248 case eSectionTypeDebug:
249 case eSectionTypeDWARFDebugAbbrev:
250 case eSectionTypeDWARFDebugAranges:
251 case eSectionTypeDWARFDebugFrame:
252 case eSectionTypeDWARFDebugInfo:
253 case eSectionTypeDWARFDebugLine:
254 case eSectionTypeDWARFDebugLoc:
255 case eSectionTypeDWARFDebugMacInfo:
256 case eSectionTypeDWARFDebugPubNames:
257 case eSectionTypeDWARFDebugPubTypes:
258 case eSectionTypeDWARFDebugRanges:
259 case eSectionTypeDWARFDebugStr:
260 case eSectionTypeDWARFAppleNames:
261 case eSectionTypeDWARFAppleTypes:
262 case eSectionTypeDWARFAppleNamespaces:
263 case eSectionTypeDWARFAppleObjC:
264 return eAddressClassDebug;
Greg Claytonded470d2011-03-19 01:12:21 +0000265 case eSectionTypeEHFrame: return eAddressClassRuntime;
266 case eSectionTypeOther: return eAddressClassUnknown;
267 }
268 }
269 }
270
Greg Claytone0d378b2011-03-24 21:19:54 +0000271 const SymbolType symbol_type = symbol->GetType();
Greg Claytonded470d2011-03-19 01:12:21 +0000272 switch (symbol_type)
273 {
274 case eSymbolTypeAny: return eAddressClassUnknown;
275 case eSymbolTypeAbsolute: return eAddressClassUnknown;
276 case eSymbolTypeExtern: return eAddressClassUnknown;
277
278 case eSymbolTypeCode:
279 case eSymbolTypeTrampoline:
280 if (m_header.cputype == llvm::MachO::CPUTypeARM)
281 {
282 // For ARM we have a bit in the n_desc field of the symbol
283 // that tells us ARM/Thumb which is bit 0x0008.
284 if (symbol->GetFlags() & MACHO_NLIST_ARM_SYMBOL_IS_THUMB)
285 return eAddressClassCodeAlternateISA;
286 }
287 return eAddressClassCode;
288
289 case eSymbolTypeData: return eAddressClassData;
290 case eSymbolTypeRuntime: return eAddressClassRuntime;
291 case eSymbolTypeException: return eAddressClassRuntime;
292 case eSymbolTypeSourceFile: return eAddressClassDebug;
293 case eSymbolTypeHeaderFile: return eAddressClassDebug;
294 case eSymbolTypeObjectFile: return eAddressClassDebug;
295 case eSymbolTypeCommonBlock: return eAddressClassDebug;
296 case eSymbolTypeBlock: return eAddressClassDebug;
297 case eSymbolTypeLocal: return eAddressClassData;
298 case eSymbolTypeParam: return eAddressClassData;
299 case eSymbolTypeVariable: return eAddressClassData;
300 case eSymbolTypeVariableType: return eAddressClassDebug;
301 case eSymbolTypeLineEntry: return eAddressClassDebug;
302 case eSymbolTypeLineHeader: return eAddressClassDebug;
303 case eSymbolTypeScopeBegin: return eAddressClassDebug;
304 case eSymbolTypeScopeEnd: return eAddressClassDebug;
305 case eSymbolTypeAdditional: return eAddressClassUnknown;
306 case eSymbolTypeCompiler: return eAddressClassDebug;
307 case eSymbolTypeInstrumentation:return eAddressClassDebug;
308 case eSymbolTypeUndefined: return eAddressClassUnknown;
309 }
310 }
311 }
312 return eAddressClassUnknown;
313}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314
315Symtab *
316ObjectFileMachO::GetSymtab()
317{
Greg Clayton1a65ae12011-01-25 23:55:37 +0000318 lldb_private::Mutex::Locker symfile_locker(m_mutex);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000319 if (m_symtab_ap.get() == NULL)
320 {
321 m_symtab_ap.reset(new Symtab(this));
Greg Clayton1a65ae12011-01-25 23:55:37 +0000322 Mutex::Locker symtab_locker (m_symtab_ap->GetMutex());
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000323 ParseSymtab (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324 }
325 return m_symtab_ap.get();
326}
327
328
329SectionList *
330ObjectFileMachO::GetSectionList()
331{
332 lldb_private::Mutex::Locker locker(m_mutex);
333 if (m_sections_ap.get() == NULL)
334 {
335 m_sections_ap.reset(new SectionList());
336 ParseSections();
337 }
338 return m_sections_ap.get();
339}
340
341
342size_t
343ObjectFileMachO::ParseSections ()
344{
345 lldb::user_id_t segID = 0;
346 lldb::user_id_t sectID = 0;
347 struct segment_command_64 load_cmd;
348 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
349 uint32_t i;
350 //bool dump_sections = false;
351 for (i=0; i<m_header.ncmds; ++i)
352 {
353 const uint32_t load_cmd_offset = offset;
354 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
355 break;
356
Greg Claytone1a916a2010-07-21 22:12:05 +0000357 if (load_cmd.cmd == LoadCommandSegment32 || load_cmd.cmd == LoadCommandSegment64)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000358 {
359 if (m_data.GetU8(&offset, (uint8_t*)load_cmd.segname, 16))
360 {
361 load_cmd.vmaddr = m_data.GetAddress(&offset);
362 load_cmd.vmsize = m_data.GetAddress(&offset);
363 load_cmd.fileoff = m_data.GetAddress(&offset);
364 load_cmd.filesize = m_data.GetAddress(&offset);
365 if (m_data.GetU32(&offset, &load_cmd.maxprot, 4))
366 {
Greg Clayton414f5d32011-01-25 02:58:48 +0000367
368 const bool segment_is_encrypted = (load_cmd.flags & SegmentCommandFlagBitProtectedVersion1) != 0;
369
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 // Keep a list of mach segments around in case we need to
371 // get at data that isn't stored in the abstracted Sections.
372 m_mach_segments.push_back (load_cmd);
373
374 ConstString segment_name (load_cmd.segname, std::min<int>(strlen(load_cmd.segname), sizeof(load_cmd.segname)));
375 // Use a segment ID of the segment index shifted left by 8 so they
376 // never conflict with any of the sections.
377 SectionSP segment_sp;
378 if (segment_name)
379 {
380 segment_sp.reset(new Section (NULL,
381 GetModule(), // Module to which this section belongs
382 ++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
383 segment_name, // Name of this section
384 eSectionTypeContainer, // This section is a container of other sections.
385 load_cmd.vmaddr, // File VM address == addresses as they are found in the object file
386 load_cmd.vmsize, // VM size in bytes of this section
387 load_cmd.fileoff, // Offset to the data for this section in the file
388 load_cmd.filesize, // Size in bytes of this section as found in the the file
389 load_cmd.flags)); // Flags for this section
390
Greg Clayton414f5d32011-01-25 02:58:48 +0000391 segment_sp->SetIsEncrypted (segment_is_encrypted);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 m_sections_ap->AddSection(segment_sp);
393 }
394
395 struct section_64 sect64;
Greg Clayton72b77eb2011-02-04 21:13:05 +0000396 ::memset (&sect64, 0, sizeof(sect64));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397 // Push a section into our mach sections for the section at
Greg Claytonf4abd0d2010-10-06 01:26:32 +0000398 // index zero (NListSectionNoSection) if we don't have any
399 // mach sections yet...
400 if (m_mach_sections.empty())
401 m_mach_sections.push_back(sect64);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 uint32_t segment_sect_idx;
403 const lldb::user_id_t first_segment_sectID = sectID + 1;
404
405
Greg Claytone1a916a2010-07-21 22:12:05 +0000406 const uint32_t num_u32s = load_cmd.cmd == LoadCommandSegment32 ? 7 : 8;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407 for (segment_sect_idx=0; segment_sect_idx<load_cmd.nsects; ++segment_sect_idx)
408 {
409 if (m_data.GetU8(&offset, (uint8_t*)sect64.sectname, sizeof(sect64.sectname)) == NULL)
410 break;
411 if (m_data.GetU8(&offset, (uint8_t*)sect64.segname, sizeof(sect64.segname)) == NULL)
412 break;
413 sect64.addr = m_data.GetAddress(&offset);
414 sect64.size = m_data.GetAddress(&offset);
415
416 if (m_data.GetU32(&offset, &sect64.offset, num_u32s) == NULL)
417 break;
418
419 // Keep a list of mach sections around in case we need to
420 // get at data that isn't stored in the abstracted Sections.
421 m_mach_sections.push_back (sect64);
422
423 ConstString section_name (sect64.sectname, std::min<size_t>(strlen(sect64.sectname), sizeof(sect64.sectname)));
424 if (!segment_name)
425 {
426 // We have a segment with no name so we need to conjure up
427 // segments that correspond to the section's segname if there
428 // isn't already such a section. If there is such a section,
429 // we resize the section so that it spans all sections.
430 // We also mark these sections as fake so address matches don't
431 // hit if they land in the gaps between the child sections.
432 segment_name.SetTrimmedCStringWithLength(sect64.segname, sizeof(sect64.segname));
433 segment_sp = m_sections_ap->FindSectionByName (segment_name);
434 if (segment_sp.get())
435 {
436 Section *segment = segment_sp.get();
437 // Grow the section size as needed.
438 const lldb::addr_t sect64_min_addr = sect64.addr;
439 const lldb::addr_t sect64_max_addr = sect64_min_addr + sect64.size;
440 const lldb::addr_t curr_seg_byte_size = segment->GetByteSize();
441 const lldb::addr_t curr_seg_min_addr = segment->GetFileAddress();
442 const lldb::addr_t curr_seg_max_addr = curr_seg_min_addr + curr_seg_byte_size;
443 if (sect64_min_addr >= curr_seg_min_addr)
444 {
445 const lldb::addr_t new_seg_byte_size = sect64_max_addr - curr_seg_min_addr;
446 // Only grow the section size if needed
447 if (new_seg_byte_size > curr_seg_byte_size)
448 segment->SetByteSize (new_seg_byte_size);
449 }
450 else
451 {
452 // We need to change the base address of the segment and
453 // adjust the child section offsets for all existing children.
454 const lldb::addr_t slide_amount = sect64_min_addr - curr_seg_min_addr;
455 segment->Slide(slide_amount, false);
456 segment->GetChildren().Slide (-slide_amount, false);
457 segment->SetByteSize (curr_seg_max_addr - sect64_min_addr);
458 }
Greg Clayton8d38ac42010-06-28 23:51:11 +0000459
460 // Grow the section size as needed.
461 if (sect64.offset)
462 {
463 const lldb::addr_t segment_min_file_offset = segment->GetFileOffset();
464 const lldb::addr_t segment_max_file_offset = segment_min_file_offset + segment->GetFileSize();
465
466 const lldb::addr_t section_min_file_offset = sect64.offset;
467 const lldb::addr_t section_max_file_offset = section_min_file_offset + sect64.size;
468 const lldb::addr_t new_file_offset = std::min (section_min_file_offset, segment_min_file_offset);
469 const lldb::addr_t new_file_size = std::max (section_max_file_offset, segment_max_file_offset) - new_file_offset;
470 segment->SetFileOffset (new_file_offset);
471 segment->SetFileSize (new_file_size);
472 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473 }
474 else
475 {
476 // Create a fake section for the section's named segment
477 segment_sp.reset(new Section(segment_sp.get(), // Parent section
478 GetModule(), // Module to which this section belongs
479 ++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
480 segment_name, // Name of this section
481 eSectionTypeContainer, // This section is a container of other sections.
482 sect64.addr, // File VM address == addresses as they are found in the object file
483 sect64.size, // VM size in bytes of this section
484 sect64.offset, // Offset to the data for this section in the file
485 sect64.offset ? sect64.size : 0, // Size in bytes of this section as found in the the file
486 load_cmd.flags)); // Flags for this section
487 segment_sp->SetIsFake(true);
488 m_sections_ap->AddSection(segment_sp);
Greg Clayton414f5d32011-01-25 02:58:48 +0000489 segment_sp->SetIsEncrypted (segment_is_encrypted);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490 }
491 }
492 assert (segment_sp.get());
493
Greg Claytone1a916a2010-07-21 22:12:05 +0000494 uint32_t mach_sect_type = sect64.flags & SectionFlagMaskSectionType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000495 static ConstString g_sect_name_objc_data ("__objc_data");
496 static ConstString g_sect_name_objc_msgrefs ("__objc_msgrefs");
497 static ConstString g_sect_name_objc_selrefs ("__objc_selrefs");
498 static ConstString g_sect_name_objc_classrefs ("__objc_classrefs");
499 static ConstString g_sect_name_objc_superrefs ("__objc_superrefs");
500 static ConstString g_sect_name_objc_const ("__objc_const");
501 static ConstString g_sect_name_objc_classlist ("__objc_classlist");
502 static ConstString g_sect_name_cfstring ("__cfstring");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000503
504 static ConstString g_sect_name_dwarf_debug_abbrev ("__debug_abbrev");
505 static ConstString g_sect_name_dwarf_debug_aranges ("__debug_aranges");
506 static ConstString g_sect_name_dwarf_debug_frame ("__debug_frame");
507 static ConstString g_sect_name_dwarf_debug_info ("__debug_info");
508 static ConstString g_sect_name_dwarf_debug_line ("__debug_line");
509 static ConstString g_sect_name_dwarf_debug_loc ("__debug_loc");
510 static ConstString g_sect_name_dwarf_debug_macinfo ("__debug_macinfo");
511 static ConstString g_sect_name_dwarf_debug_pubnames ("__debug_pubnames");
512 static ConstString g_sect_name_dwarf_debug_pubtypes ("__debug_pubtypes");
513 static ConstString g_sect_name_dwarf_debug_ranges ("__debug_ranges");
514 static ConstString g_sect_name_dwarf_debug_str ("__debug_str");
Greg Clayton17674402011-09-28 17:06:40 +0000515 static ConstString g_sect_name_dwarf_apple_names ("__apple_names");
516 static ConstString g_sect_name_dwarf_apple_types ("__apple_types");
Greg Clayton7f995132011-10-04 22:41:51 +0000517 static ConstString g_sect_name_dwarf_apple_namespaces ("__apple_namespac");
Greg Clayton5009f9d2011-10-27 17:55:14 +0000518 static ConstString g_sect_name_dwarf_apple_objc ("__apple_objc");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000519 static ConstString g_sect_name_eh_frame ("__eh_frame");
Greg Clayton89411422010-10-08 00:21:05 +0000520 static ConstString g_sect_name_DATA ("__DATA");
521 static ConstString g_sect_name_TEXT ("__TEXT");
Greg Clayton4ceb9982010-07-21 22:54:26 +0000522
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523 SectionType sect_type = eSectionTypeOther;
524
Greg Clayton4ceb9982010-07-21 22:54:26 +0000525 if (section_name == g_sect_name_dwarf_debug_abbrev)
526 sect_type = eSectionTypeDWARFDebugAbbrev;
527 else if (section_name == g_sect_name_dwarf_debug_aranges)
528 sect_type = eSectionTypeDWARFDebugAranges;
529 else if (section_name == g_sect_name_dwarf_debug_frame)
530 sect_type = eSectionTypeDWARFDebugFrame;
531 else if (section_name == g_sect_name_dwarf_debug_info)
532 sect_type = eSectionTypeDWARFDebugInfo;
533 else if (section_name == g_sect_name_dwarf_debug_line)
534 sect_type = eSectionTypeDWARFDebugLine;
535 else if (section_name == g_sect_name_dwarf_debug_loc)
536 sect_type = eSectionTypeDWARFDebugLoc;
537 else if (section_name == g_sect_name_dwarf_debug_macinfo)
538 sect_type = eSectionTypeDWARFDebugMacInfo;
539 else if (section_name == g_sect_name_dwarf_debug_pubnames)
540 sect_type = eSectionTypeDWARFDebugPubNames;
541 else if (section_name == g_sect_name_dwarf_debug_pubtypes)
542 sect_type = eSectionTypeDWARFDebugPubTypes;
543 else if (section_name == g_sect_name_dwarf_debug_ranges)
544 sect_type = eSectionTypeDWARFDebugRanges;
545 else if (section_name == g_sect_name_dwarf_debug_str)
546 sect_type = eSectionTypeDWARFDebugStr;
Greg Clayton17674402011-09-28 17:06:40 +0000547 else if (section_name == g_sect_name_dwarf_apple_names)
548 sect_type = eSectionTypeDWARFAppleNames;
549 else if (section_name == g_sect_name_dwarf_apple_types)
550 sect_type = eSectionTypeDWARFAppleTypes;
Greg Clayton7f995132011-10-04 22:41:51 +0000551 else if (section_name == g_sect_name_dwarf_apple_namespaces)
552 sect_type = eSectionTypeDWARFAppleNamespaces;
Greg Clayton5009f9d2011-10-27 17:55:14 +0000553 else if (section_name == g_sect_name_dwarf_apple_objc)
554 sect_type = eSectionTypeDWARFAppleObjC;
Greg Clayton4ceb9982010-07-21 22:54:26 +0000555 else if (section_name == g_sect_name_objc_selrefs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000556 sect_type = eSectionTypeDataCStringPointers;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 else if (section_name == g_sect_name_objc_msgrefs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558 sect_type = eSectionTypeDataObjCMessageRefs;
Greg Clayton4ceb9982010-07-21 22:54:26 +0000559 else if (section_name == g_sect_name_eh_frame)
560 sect_type = eSectionTypeEHFrame;
561 else if (section_name == g_sect_name_cfstring)
562 sect_type = eSectionTypeDataObjCCFStrings;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563 else if (section_name == g_sect_name_objc_data ||
564 section_name == g_sect_name_objc_classrefs ||
565 section_name == g_sect_name_objc_superrefs ||
566 section_name == g_sect_name_objc_const ||
567 section_name == g_sect_name_objc_classlist)
568 {
569 sect_type = eSectionTypeDataPointers;
570 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571
572 if (sect_type == eSectionTypeOther)
573 {
574 switch (mach_sect_type)
575 {
576 // TODO: categorize sections by other flags for regular sections
Greg Clayton89411422010-10-08 00:21:05 +0000577 case SectionTypeRegular:
578 if (segment_sp->GetName() == g_sect_name_TEXT)
579 sect_type = eSectionTypeCode;
580 else if (segment_sp->GetName() == g_sect_name_DATA)
581 sect_type = eSectionTypeData;
582 else
583 sect_type = eSectionTypeOther;
584 break;
Greg Claytone1a916a2010-07-21 22:12:05 +0000585 case SectionTypeZeroFill: sect_type = eSectionTypeZeroFill; break;
586 case SectionTypeCStringLiterals: sect_type = eSectionTypeDataCString; break; // section with only literal C strings
587 case SectionType4ByteLiterals: sect_type = eSectionTypeData4; break; // section with only 4 byte literals
588 case SectionType8ByteLiterals: sect_type = eSectionTypeData8; break; // section with only 8 byte literals
589 case SectionTypeLiteralPointers: sect_type = eSectionTypeDataPointers; break; // section with only pointers to literals
590 case SectionTypeNonLazySymbolPointers: sect_type = eSectionTypeDataPointers; break; // section with only non-lazy symbol pointers
591 case SectionTypeLazySymbolPointers: sect_type = eSectionTypeDataPointers; break; // section with only lazy symbol pointers
592 case SectionTypeSymbolStubs: sect_type = eSectionTypeCode; break; // section with only symbol stubs, byte size of stub in the reserved2 field
593 case SectionTypeModuleInitFunctionPointers: sect_type = eSectionTypeDataPointers; break; // section with only function pointers for initialization
594 case SectionTypeModuleTermFunctionPointers: sect_type = eSectionTypeDataPointers; break; // section with only function pointers for termination
595 case SectionTypeCoalesced: sect_type = eSectionTypeOther; break;
596 case SectionTypeZeroFillLarge: sect_type = eSectionTypeZeroFill; break;
597 case SectionTypeInterposing: sect_type = eSectionTypeCode; break; // section with only pairs of function pointers for interposing
598 case SectionType16ByteLiterals: sect_type = eSectionTypeData16; break; // section with only 16 byte literals
599 case SectionTypeDTraceObjectFormat: sect_type = eSectionTypeDebug; break;
600 case SectionTypeLazyDylibSymbolPointers: sect_type = eSectionTypeDataPointers; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000601 default: break;
602 }
603 }
604
605 SectionSP section_sp(new Section(segment_sp.get(),
606 GetModule(),
607 ++sectID,
608 section_name,
609 sect_type,
610 sect64.addr - segment_sp->GetFileAddress(),
611 sect64.size,
612 sect64.offset,
613 sect64.offset == 0 ? 0 : sect64.size,
614 sect64.flags));
Greg Clayton414f5d32011-01-25 02:58:48 +0000615 // Set the section to be encrypted to match the segment
616 section_sp->SetIsEncrypted (segment_is_encrypted);
617
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618 segment_sp->GetChildren().AddSection(section_sp);
619
620 if (segment_sp->IsFake())
621 {
622 segment_sp.reset();
623 segment_name.Clear();
624 }
625 }
Greg Claytona63d08c2011-07-19 03:57:15 +0000626 if (segment_sp && m_header.filetype == HeaderFileTypeDSYM)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 {
628 if (first_segment_sectID <= sectID)
629 {
630 lldb::user_id_t sect_uid;
631 for (sect_uid = first_segment_sectID; sect_uid <= sectID; ++sect_uid)
632 {
633 SectionSP curr_section_sp(segment_sp->GetChildren().FindSectionByID (sect_uid));
634 SectionSP next_section_sp;
635 if (sect_uid + 1 <= sectID)
636 next_section_sp = segment_sp->GetChildren().FindSectionByID (sect_uid+1);
637
638 if (curr_section_sp.get())
639 {
640 if (curr_section_sp->GetByteSize() == 0)
641 {
642 if (next_section_sp.get() != NULL)
643 curr_section_sp->SetByteSize ( next_section_sp->GetFileAddress() - curr_section_sp->GetFileAddress() );
644 else
645 curr_section_sp->SetByteSize ( load_cmd.vmsize );
646 }
647 }
648 }
649 }
650 }
651 }
652 }
653 }
Greg Claytone1a916a2010-07-21 22:12:05 +0000654 else if (load_cmd.cmd == LoadCommandDynamicSymtabInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655 {
656 m_dysymtab.cmd = load_cmd.cmd;
657 m_dysymtab.cmdsize = load_cmd.cmdsize;
658 m_data.GetU32 (&offset, &m_dysymtab.ilocalsym, (sizeof(m_dysymtab) / sizeof(uint32_t)) - 2);
659 }
660
661 offset = load_cmd_offset + load_cmd.cmdsize;
662 }
663// if (dump_sections)
664// {
665// StreamFile s(stdout);
666// m_sections_ap->Dump(&s, true);
667// }
668 return sectID; // Return the number of sections we registered with the module
669}
670
671class MachSymtabSectionInfo
672{
673public:
674
675 MachSymtabSectionInfo (SectionList *section_list) :
676 m_section_list (section_list),
677 m_section_infos()
678 {
679 // Get the number of sections down to a depth of 1 to include
680 // all segments and their sections, but no other sections that
681 // may be added for debug map or
682 m_section_infos.resize(section_list->GetNumSections(1));
683 }
684
685
686 Section *
687 GetSection (uint8_t n_sect, addr_t file_addr)
688 {
689 if (n_sect == 0)
690 return NULL;
691 if (n_sect < m_section_infos.size())
692 {
693 if (m_section_infos[n_sect].section == NULL)
694 {
695 Section *section = m_section_list->FindSectionByID (n_sect).get();
696 m_section_infos[n_sect].section = section;
Greg Claytondda0d122011-07-10 17:32:33 +0000697 if (section != NULL)
698 {
699 m_section_infos[n_sect].vm_range.SetBaseAddress (section->GetFileAddress());
700 m_section_infos[n_sect].vm_range.SetByteSize (section->GetByteSize());
701 }
702 else
703 {
704 fprintf (stderr, "error: unable to find section for section %u\n", n_sect);
705 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 }
707 if (m_section_infos[n_sect].vm_range.Contains(file_addr))
Greg Clayton8f258512011-08-26 20:01:35 +0000708 {
709 // Symbol is in section.
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710 return m_section_infos[n_sect].section;
Greg Clayton8f258512011-08-26 20:01:35 +0000711 }
712 else if (m_section_infos[n_sect].vm_range.GetByteSize () == 0 &&
713 m_section_infos[n_sect].vm_range.GetBaseAddress() == file_addr)
714 {
715 // Symbol is in section with zero size, but has the same start
716 // address as the section. This can happen with linker symbols
717 // (symbols that start with the letter 'l' or 'L'.
718 return m_section_infos[n_sect].section;
719 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 }
721 return m_section_list->FindSectionContainingFileAddress(file_addr).get();
722 }
723
724protected:
725 struct SectionInfo
726 {
727 SectionInfo () :
728 vm_range(),
729 section (NULL)
730 {
731 }
732
733 VMRange vm_range;
734 Section *section;
735 };
736 SectionList *m_section_list;
737 std::vector<SectionInfo> m_section_infos;
738};
739
740
741
742size_t
743ObjectFileMachO::ParseSymtab (bool minimize)
744{
745 Timer scoped_timer(__PRETTY_FUNCTION__,
746 "ObjectFileMachO::ParseSymtab () module = %s",
747 m_file.GetFilename().AsCString(""));
748 struct symtab_command symtab_load_command;
749 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
750 uint32_t i;
751 for (i=0; i<m_header.ncmds; ++i)
752 {
753 const uint32_t cmd_offset = offset;
754 // Read in the load command and load command size
755 if (m_data.GetU32(&offset, &symtab_load_command, 2) == NULL)
756 break;
757 // Watch for the symbol table load command
Greg Claytone1a916a2010-07-21 22:12:05 +0000758 if (symtab_load_command.cmd == LoadCommandSymtab)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000759 {
760 // Read in the rest of the symtab load command
Jason Molendaea84e762010-07-06 22:38:03 +0000761 if (m_data.GetU32(&offset, &symtab_load_command.symoff, 4)) // fill in symoff, nsyms, stroff, strsize fields
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000762 {
763 Symtab *symtab = m_symtab_ap.get();
764 SectionList *section_list = GetSectionList();
765 assert(section_list);
766 const size_t addr_size = m_data.GetAddressByteSize();
767 const ByteOrder endian = m_data.GetByteOrder();
768 bool bit_width_32 = addr_size == 4;
769 const size_t nlist_size = bit_width_32 ? sizeof(struct nlist) : sizeof(struct nlist_64);
770
771 DataBufferSP symtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.symoff, symtab_load_command.nsyms * nlist_size));
772 DataBufferSP strtab_data_sp(m_file.ReadFileContents(m_offset + symtab_load_command.stroff, symtab_load_command.strsize));
773
774 const char *strtab_data = (const char *)strtab_data_sp->GetBytes();
775// DataExtractor symtab_data(symtab_data_sp, endian, addr_size);
776// DataExtractor strtab_data(strtab_data_sp, endian, addr_size);
777
778 static ConstString g_segment_name_TEXT ("__TEXT");
779 static ConstString g_segment_name_DATA ("__DATA");
780 static ConstString g_segment_name_OBJC ("__OBJC");
781 static ConstString g_section_name_eh_frame ("__eh_frame");
782 SectionSP text_section_sp(section_list->FindSectionByName(g_segment_name_TEXT));
783 SectionSP data_section_sp(section_list->FindSectionByName(g_segment_name_DATA));
784 SectionSP objc_section_sp(section_list->FindSectionByName(g_segment_name_OBJC));
785 SectionSP eh_frame_section_sp;
786 if (text_section_sp.get())
787 eh_frame_section_sp = text_section_sp->GetChildren().FindSectionByName (g_section_name_eh_frame);
788 else
789 eh_frame_section_sp = section_list->FindSectionByName (g_section_name_eh_frame);
790
Greg Claytone1a916a2010-07-21 22:12:05 +0000791 uint8_t TEXT_eh_frame_sectID = eh_frame_section_sp.get() ? eh_frame_section_sp->GetID() : NListSectionNoSection;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792 //uint32_t symtab_offset = 0;
793 const uint8_t* nlist_data = symtab_data_sp->GetBytes();
794 assert (symtab_data_sp->GetByteSize()/nlist_size >= symtab_load_command.nsyms);
795
796
Greg Clayton7fb56d02011-02-01 01:31:41 +0000797 if (endian != lldb::endian::InlHostByteOrder())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798 {
799 // ...
800 assert (!"UNIMPLEMENTED: Swap all nlist entries");
801 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000802 uint32_t N_SO_index = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000803
804 MachSymtabSectionInfo section_info (section_list);
805 std::vector<uint32_t> N_FUN_indexes;
806 std::vector<uint32_t> N_NSYM_indexes;
807 std::vector<uint32_t> N_INCL_indexes;
808 std::vector<uint32_t> N_BRAC_indexes;
809 std::vector<uint32_t> N_COMM_indexes;
Greg Clayton928d8292010-09-08 16:38:06 +0000810 typedef std::map <uint64_t, uint32_t> ValueToSymbolIndexMap;
Greg Clayton0c38b0d2010-09-12 05:25:16 +0000811 typedef std::map <uint32_t, uint32_t> NListIndexToSymbolIndexMap;
Greg Clayton928d8292010-09-08 16:38:06 +0000812 ValueToSymbolIndexMap N_FUN_addr_to_sym_idx;
813 ValueToSymbolIndexMap N_STSYM_addr_to_sym_idx;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000814 // Any symbols that get merged into another will get an entry
815 // in this map so we know
Greg Clayton0c38b0d2010-09-12 05:25:16 +0000816 NListIndexToSymbolIndexMap m_nlist_idx_to_sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000817 uint32_t nlist_idx = 0;
818 Symbol *symbol_ptr = NULL;
819
820 uint32_t sym_idx = 0;
821 Symbol *sym = symtab->Resize (symtab_load_command.nsyms + m_dysymtab.nindirectsyms);
822 uint32_t num_syms = symtab->GetNumSymbols();
823
824 //symtab->Reserve (symtab_load_command.nsyms + m_dysymtab.nindirectsyms);
825 for (nlist_idx = 0; nlist_idx < symtab_load_command.nsyms; ++nlist_idx)
826 {
827 struct nlist_64 nlist;
828 if (bit_width_32)
829 {
830 struct nlist* nlist32_ptr = (struct nlist*)(nlist_data + (nlist_idx * nlist_size));
Greg Claytone1a916a2010-07-21 22:12:05 +0000831 nlist.n_strx = nlist32_ptr->n_strx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832 nlist.n_type = nlist32_ptr->n_type;
833 nlist.n_sect = nlist32_ptr->n_sect;
834 nlist.n_desc = nlist32_ptr->n_desc;
835 nlist.n_value = nlist32_ptr->n_value;
836 }
837 else
838 {
839 nlist = *((struct nlist_64*)(nlist_data + (nlist_idx * nlist_size)));
840 }
841
842 SymbolType type = eSymbolTypeInvalid;
Greg Claytone1a916a2010-07-21 22:12:05 +0000843 const char* symbol_name = &strtab_data[nlist.n_strx];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000844 if (symbol_name[0] == '\0')
845 symbol_name = NULL;
846 Section* symbol_section = NULL;
847 bool add_nlist = true;
Greg Claytone1a916a2010-07-21 22:12:05 +0000848 bool is_debug = ((nlist.n_type & NlistMaskStab) != 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849
850 assert (sym_idx < num_syms);
851
852 sym[sym_idx].SetDebug (is_debug);
853
854 if (is_debug)
855 {
856 switch (nlist.n_type)
857 {
Greg Claytone1a916a2010-07-21 22:12:05 +0000858 case StabGlobalSymbol:
859 // N_GSYM -- global symbol: name,,NO_SECT,type,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000860 // Sometimes the N_GSYM value contains the address.
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000861 sym[sym_idx].SetExternal(true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000862 if (nlist.n_value != 0)
863 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000864 type = eSymbolTypeData;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000865 break;
866
Greg Claytone1a916a2010-07-21 22:12:05 +0000867 case StabFunctionName:
868 // N_FNAME -- procedure name (f77 kludge): name,,NO_SECT,0,0
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000869 type = eSymbolTypeCompiler;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 break;
871
Greg Claytone1a916a2010-07-21 22:12:05 +0000872 case StabFunction:
873 // N_FUN -- procedure: name,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 if (symbol_name)
875 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000876 type = eSymbolTypeCode;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Clayton928d8292010-09-08 16:38:06 +0000878
879 N_FUN_addr_to_sym_idx[nlist.n_value] = sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000880 // We use the current number of symbols in the symbol table in lieu of
881 // using nlist_idx in case we ever start trimming entries out
882 N_FUN_indexes.push_back(sym_idx);
883 }
884 else
885 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000886 type = eSymbolTypeCompiler;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000887
888 if ( !N_FUN_indexes.empty() )
889 {
890 // Copy the size of the function into the original STAB entry so we don't have
891 // to hunt for it later
892 symtab->SymbolAtIndex(N_FUN_indexes.back())->SetByteSize(nlist.n_value);
893 N_FUN_indexes.pop_back();
Jason Molendaea84e762010-07-06 22:38:03 +0000894 // We don't really need the end function STAB as it contains the size which
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895 // we already placed with the original symbol, so don't add it if we want a
896 // minimal symbol table
897 if (minimize)
898 add_nlist = false;
899 }
900 }
901 break;
902
Greg Claytone1a916a2010-07-21 22:12:05 +0000903 case StabStaticSymbol:
904 // N_STSYM -- static symbol: name,,n_sect,type,address
Greg Clayton928d8292010-09-08 16:38:06 +0000905 N_STSYM_addr_to_sym_idx[nlist.n_value] = sym_idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000906 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000907 type = eSymbolTypeData;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000908 break;
909
Greg Claytone1a916a2010-07-21 22:12:05 +0000910 case StabLocalCommon:
911 // N_LCSYM -- .lcomm symbol: name,,n_sect,type,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000912 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
913 type = eSymbolTypeCommonBlock;
914 break;
915
Greg Claytone1a916a2010-07-21 22:12:05 +0000916 case StabBeginSymbol:
917 // N_BNSYM
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000918 // We use the current number of symbols in the symbol table in lieu of
919 // using nlist_idx in case we ever start trimming entries out
920 if (minimize)
921 {
922 // Skip these if we want minimal symbol tables
923 add_nlist = false;
924 }
925 else
926 {
927 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
928 N_NSYM_indexes.push_back(sym_idx);
929 type = eSymbolTypeScopeBegin;
930 }
931 break;
932
Greg Claytone1a916a2010-07-21 22:12:05 +0000933 case StabEndSymbol:
934 // N_ENSYM
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000935 // Set the size of the N_BNSYM to the terminating index of this N_ENSYM
936 // so that we can always skip the entire symbol if we need to navigate
937 // more quickly at the source level when parsing STABS
938 if (minimize)
939 {
940 // Skip these if we want minimal symbol tables
941 add_nlist = false;
942 }
943 else
944 {
945 if ( !N_NSYM_indexes.empty() )
946 {
947 symbol_ptr = symtab->SymbolAtIndex(N_NSYM_indexes.back());
948 symbol_ptr->SetByteSize(sym_idx + 1);
949 symbol_ptr->SetSizeIsSibling(true);
950 N_NSYM_indexes.pop_back();
951 }
952 type = eSymbolTypeScopeEnd;
953 }
954 break;
955
956
Greg Claytone1a916a2010-07-21 22:12:05 +0000957 case StabSourceFileOptions:
958 // N_OPT - emitted with gcc2_compiled and in gcc source
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000959 type = eSymbolTypeCompiler;
960 break;
961
Greg Claytone1a916a2010-07-21 22:12:05 +0000962 case StabRegisterSymbol:
963 // N_RSYM - register sym: name,,NO_SECT,type,register
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000964 type = eSymbolTypeVariable;
965 break;
966
Greg Claytone1a916a2010-07-21 22:12:05 +0000967 case StabSourceLine:
968 // N_SLINE - src line: 0,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000969 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
970 type = eSymbolTypeLineEntry;
971 break;
972
Greg Claytone1a916a2010-07-21 22:12:05 +0000973 case StabStructureType:
974 // N_SSYM - structure elt: name,,NO_SECT,type,struct_offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000975 type = eSymbolTypeVariableType;
976 break;
977
Greg Claytone1a916a2010-07-21 22:12:05 +0000978 case StabSourceFileName:
979 // N_SO - source file name
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000980 type = eSymbolTypeSourceFile;
981 if (symbol_name == NULL)
982 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000983 if (minimize)
984 add_nlist = false;
985 if (N_SO_index != UINT32_MAX)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000986 {
987 // Set the size of the N_SO to the terminating index of this N_SO
988 // so that we can always skip the entire N_SO if we need to navigate
989 // more quickly at the source level when parsing STABS
990 symbol_ptr = symtab->SymbolAtIndex(N_SO_index);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000991 symbol_ptr->SetByteSize(sym_idx + (minimize ? 0 : 1));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000992 symbol_ptr->SetSizeIsSibling(true);
993 }
994 N_NSYM_indexes.clear();
995 N_INCL_indexes.clear();
996 N_BRAC_indexes.clear();
997 N_COMM_indexes.clear();
998 N_FUN_indexes.clear();
Greg Claytonbcf2cfb2010-09-11 03:13:28 +0000999 N_SO_index = UINT32_MAX;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001000 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001001 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001002 {
1003 // We use the current number of symbols in the symbol table in lieu of
1004 // using nlist_idx in case we ever start trimming entries out
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001005 if (symbol_name[0] == '/')
1006 N_SO_index = sym_idx;
Greg Clayton5cf21f52011-06-19 04:26:01 +00001007 else if (minimize && (N_SO_index == sym_idx - 1) && ((sym_idx - 1) < num_syms))
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001008 {
1009 const char *so_path = sym[sym_idx - 1].GetMangled().GetDemangledName().AsCString();
1010 if (so_path && so_path[0])
1011 {
1012 std::string full_so_path (so_path);
1013 if (*full_so_path.rbegin() != '/')
1014 full_so_path += '/';
1015 full_so_path += symbol_name;
1016 sym[sym_idx - 1].GetMangled().SetValue(full_so_path.c_str(), false);
1017 add_nlist = false;
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001018 m_nlist_idx_to_sym_idx[nlist_idx] = sym_idx - 1;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001019 }
1020 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001021 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001022
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 break;
1024
Greg Claytone1a916a2010-07-21 22:12:05 +00001025 case StabObjectFileName:
1026 // N_OSO - object file name: name,,0,0,st_mtime
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001027 type = eSymbolTypeObjectFile;
1028 break;
1029
Greg Claytone1a916a2010-07-21 22:12:05 +00001030 case StabLocalSymbol:
1031 // N_LSYM - local sym: name,,NO_SECT,type,offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032 type = eSymbolTypeLocal;
1033 break;
1034
1035 //----------------------------------------------------------------------
1036 // INCL scopes
1037 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001038 case StabBeginIncludeFileName:
1039 // N_BINCL - include file beginning: name,,NO_SECT,0,sum
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040 // We use the current number of symbols in the symbol table in lieu of
1041 // using nlist_idx in case we ever start trimming entries out
1042 N_INCL_indexes.push_back(sym_idx);
1043 type = eSymbolTypeScopeBegin;
1044 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045
Greg Claytone1a916a2010-07-21 22:12:05 +00001046 case StabEndIncludeFile:
1047 // N_EINCL - include file end: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048 // Set the size of the N_BINCL to the terminating index of this N_EINCL
1049 // so that we can always skip the entire symbol if we need to navigate
1050 // more quickly at the source level when parsing STABS
1051 if ( !N_INCL_indexes.empty() )
1052 {
1053 symbol_ptr = symtab->SymbolAtIndex(N_INCL_indexes.back());
1054 symbol_ptr->SetByteSize(sym_idx + 1);
1055 symbol_ptr->SetSizeIsSibling(true);
1056 N_INCL_indexes.pop_back();
1057 }
1058 type = eSymbolTypeScopeEnd;
1059 break;
1060
Greg Claytone1a916a2010-07-21 22:12:05 +00001061 case StabIncludeFileName:
1062 // N_SOL - #included file name: name,,n_sect,0,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001063 type = eSymbolTypeHeaderFile;
Greg Clayton49bd1c82010-09-07 17:36:17 +00001064
1065 // We currently don't use the header files on darwin
1066 if (minimize)
1067 add_nlist = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001068 break;
1069
Greg Claytone1a916a2010-07-21 22:12:05 +00001070 case StabCompilerParameters:
1071 // N_PARAMS - compiler parameters: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001072 type = eSymbolTypeCompiler;
1073 break;
1074
Greg Claytone1a916a2010-07-21 22:12:05 +00001075 case StabCompilerVersion:
1076 // N_VERSION - compiler version: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001077 type = eSymbolTypeCompiler;
1078 break;
1079
Greg Claytone1a916a2010-07-21 22:12:05 +00001080 case StabCompilerOptLevel:
1081 // N_OLEVEL - compiler -O level: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001082 type = eSymbolTypeCompiler;
1083 break;
1084
Greg Claytone1a916a2010-07-21 22:12:05 +00001085 case StabParameter:
1086 // N_PSYM - parameter: name,,NO_SECT,type,offset
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001087 type = eSymbolTypeVariable;
1088 break;
1089
Greg Claytone1a916a2010-07-21 22:12:05 +00001090 case StabAlternateEntry:
1091 // N_ENTRY - alternate entry: name,,n_sect,linenumber,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001092 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1093 type = eSymbolTypeLineEntry;
1094 break;
1095
1096 //----------------------------------------------------------------------
1097 // Left and Right Braces
1098 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001099 case StabLeftBracket:
1100 // N_LBRAC - left bracket: 0,,NO_SECT,nesting level,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001101 // We use the current number of symbols in the symbol table in lieu of
1102 // using nlist_idx in case we ever start trimming entries out
1103 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1104 N_BRAC_indexes.push_back(sym_idx);
1105 type = eSymbolTypeScopeBegin;
1106 break;
1107
Greg Claytone1a916a2010-07-21 22:12:05 +00001108 case StabRightBracket:
1109 // N_RBRAC - right bracket: 0,,NO_SECT,nesting level,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001110 // Set the size of the N_LBRAC to the terminating index of this N_RBRAC
1111 // so that we can always skip the entire symbol if we need to navigate
1112 // more quickly at the source level when parsing STABS
1113 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1114 if ( !N_BRAC_indexes.empty() )
1115 {
1116 symbol_ptr = symtab->SymbolAtIndex(N_BRAC_indexes.back());
1117 symbol_ptr->SetByteSize(sym_idx + 1);
1118 symbol_ptr->SetSizeIsSibling(true);
1119 N_BRAC_indexes.pop_back();
1120 }
1121 type = eSymbolTypeScopeEnd;
1122 break;
1123
Greg Claytone1a916a2010-07-21 22:12:05 +00001124 case StabDeletedIncludeFile:
1125 // N_EXCL - deleted include file: name,,NO_SECT,0,sum
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126 type = eSymbolTypeHeaderFile;
1127 break;
1128
1129 //----------------------------------------------------------------------
1130 // COMM scopes
1131 //----------------------------------------------------------------------
Greg Claytone1a916a2010-07-21 22:12:05 +00001132 case StabBeginCommon:
1133 // N_BCOMM - begin common: name,,NO_SECT,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001134 // We use the current number of symbols in the symbol table in lieu of
1135 // using nlist_idx in case we ever start trimming entries out
1136 type = eSymbolTypeScopeBegin;
1137 N_COMM_indexes.push_back(sym_idx);
1138 break;
1139
Greg Claytone1a916a2010-07-21 22:12:05 +00001140 case StabEndCommonLocal:
1141 // N_ECOML - end common (local name): 0,,n_sect,0,address
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001142 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1143 // Fall through
1144
Greg Claytone1a916a2010-07-21 22:12:05 +00001145 case StabEndCommon:
1146 // N_ECOMM - end common: name,,n_sect,0,0
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147 // Set the size of the N_BCOMM to the terminating index of this N_ECOMM/N_ECOML
1148 // so that we can always skip the entire symbol if we need to navigate
1149 // more quickly at the source level when parsing STABS
1150 if ( !N_COMM_indexes.empty() )
1151 {
1152 symbol_ptr = symtab->SymbolAtIndex(N_COMM_indexes.back());
1153 symbol_ptr->SetByteSize(sym_idx + 1);
1154 symbol_ptr->SetSizeIsSibling(true);
1155 N_COMM_indexes.pop_back();
1156 }
1157 type = eSymbolTypeScopeEnd;
1158 break;
1159
Greg Claytone1a916a2010-07-21 22:12:05 +00001160 case StabLength:
1161 // N_LENG - second stab entry with length information
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001162 type = eSymbolTypeAdditional;
1163 break;
1164
1165 default: break;
1166 }
1167 }
1168 else
1169 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001170 //uint8_t n_pext = NlistMaskPrivateExternal & nlist.n_type;
1171 uint8_t n_type = NlistMaskType & nlist.n_type;
1172 sym[sym_idx].SetExternal((NlistMaskExternal & nlist.n_type) != 0);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001173
1174 if (symbol_name && ::strstr (symbol_name, ".objc") == symbol_name)
1175 {
1176 type = eSymbolTypeRuntime;
1177 }
1178 else
1179 {
1180 switch (n_type)
1181 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001182 case NListTypeIndirect: // N_INDR - Fall through
1183 case NListTypePreboundUndefined:// N_PBUD - Fall through
1184 case NListTypeUndefined: // N_UNDF
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001185 type = eSymbolTypeExtern;
1186 break;
1187
Greg Claytone1a916a2010-07-21 22:12:05 +00001188 case NListTypeAbsolute: // N_ABS
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001189 type = eSymbolTypeAbsolute;
1190 break;
1191
Greg Claytone1a916a2010-07-21 22:12:05 +00001192 case NListTypeSection: // N_SECT
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001193 symbol_section = section_info.GetSection (nlist.n_sect, nlist.n_value);
1194
Greg Clayton8f258512011-08-26 20:01:35 +00001195 if (symbol_section == NULL)
1196 {
1197 // TODO: warn about this?
1198 add_nlist = false;
1199 break;
1200 }
1201
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001202 if (TEXT_eh_frame_sectID == nlist.n_sect)
1203 {
1204 type = eSymbolTypeException;
1205 }
1206 else
1207 {
Greg Clayton73b472d2010-10-27 03:32:59 +00001208 uint32_t section_type = symbol_section->Get() & SectionFlagMaskSectionType;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001209
1210 switch (section_type)
1211 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001212 case SectionTypeRegular: break; // regular section
1213 //case SectionTypeZeroFill: type = eSymbolTypeData; break; // zero fill on demand section
1214 case SectionTypeCStringLiterals: type = eSymbolTypeData; break; // section with only literal C strings
1215 case SectionType4ByteLiterals: type = eSymbolTypeData; break; // section with only 4 byte literals
1216 case SectionType8ByteLiterals: type = eSymbolTypeData; break; // section with only 8 byte literals
1217 case SectionTypeLiteralPointers: type = eSymbolTypeTrampoline; break; // section with only pointers to literals
1218 case SectionTypeNonLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only non-lazy symbol pointers
1219 case SectionTypeLazySymbolPointers: type = eSymbolTypeTrampoline; break; // section with only lazy symbol pointers
1220 case SectionTypeSymbolStubs: type = eSymbolTypeTrampoline; break; // section with only symbol stubs, byte size of stub in the reserved2 field
1221 case SectionTypeModuleInitFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for initialization
1222 case SectionTypeModuleTermFunctionPointers: type = eSymbolTypeCode; break; // section with only function pointers for termination
1223 //case SectionTypeCoalesced: type = eSymbolType; break; // section contains symbols that are to be coalesced
1224 //case SectionTypeZeroFillLarge: type = eSymbolTypeData; break; // zero fill on demand section (that can be larger than 4 gigabytes)
1225 case SectionTypeInterposing: type = eSymbolTypeTrampoline; break; // section with only pairs of function pointers for interposing
1226 case SectionType16ByteLiterals: type = eSymbolTypeData; break; // section with only 16 byte literals
1227 case SectionTypeDTraceObjectFormat: type = eSymbolTypeInstrumentation; break;
1228 case SectionTypeLazyDylibSymbolPointers: type = eSymbolTypeTrampoline; break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001229 default: break;
1230 }
1231
1232 if (type == eSymbolTypeInvalid)
1233 {
1234 const char *symbol_sect_name = symbol_section->GetName().AsCString();
1235 if (symbol_section->IsDescendant (text_section_sp.get()))
1236 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001237 if (symbol_section->IsClear(SectionAttrUserPureInstructions |
1238 SectionAttrUserSelfModifyingCode |
1239 SectionAttrSytemSomeInstructions))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240 type = eSymbolTypeData;
1241 else
1242 type = eSymbolTypeCode;
1243 }
1244 else
1245 if (symbol_section->IsDescendant(data_section_sp.get()))
1246 {
1247 if (symbol_sect_name && ::strstr (symbol_sect_name, "__objc") == symbol_sect_name)
1248 {
1249 type = eSymbolTypeRuntime;
1250 }
1251 else
1252 if (symbol_sect_name && ::strstr (symbol_sect_name, "__gcc_except_tab") == symbol_sect_name)
1253 {
1254 type = eSymbolTypeException;
1255 }
1256 else
1257 {
1258 type = eSymbolTypeData;
1259 }
1260 }
1261 else
1262 if (symbol_sect_name && ::strstr (symbol_sect_name, "__IMPORT") == symbol_sect_name)
1263 {
1264 type = eSymbolTypeTrampoline;
1265 }
1266 else
1267 if (symbol_section->IsDescendant(objc_section_sp.get()))
1268 {
1269 type = eSymbolTypeRuntime;
1270 }
1271 }
1272 }
1273 break;
Greg Clayton928d8292010-09-08 16:38:06 +00001274 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 }
1276 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277 if (add_nlist)
1278 {
1279 bool symbol_name_is_mangled = false;
1280 if (symbol_name && symbol_name[0] == '_')
1281 {
1282 symbol_name_is_mangled = symbol_name[1] == '_';
1283 symbol_name++; // Skip the leading underscore
1284 }
1285 uint64_t symbol_value = nlist.n_value;
Greg Clayton928d8292010-09-08 16:38:06 +00001286
1287 if (symbol_name)
1288 sym[sym_idx].GetMangled().SetValue(symbol_name, symbol_name_is_mangled);
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001289 if (is_debug == false)
Greg Clayton928d8292010-09-08 16:38:06 +00001290 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001291 if (type == eSymbolTypeCode)
Greg Clayton928d8292010-09-08 16:38:06 +00001292 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001293 // See if we can find a N_FUN entry for any code symbols.
1294 // If we do find a match, and the name matches, then we
1295 // can merge the two into just the function symbol to avoid
1296 // duplicate entries in the symbol table
1297 ValueToSymbolIndexMap::const_iterator pos = N_FUN_addr_to_sym_idx.find (nlist.n_value);
1298 if (pos != N_FUN_addr_to_sym_idx.end())
Greg Clayton928d8292010-09-08 16:38:06 +00001299 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001300 if ((symbol_name_is_mangled == true && sym[sym_idx].GetMangled().GetMangledName() == sym[pos->second].GetMangled().GetMangledName()) ||
1301 (symbol_name_is_mangled == false && sym[sym_idx].GetMangled().GetDemangledName() == sym[pos->second].GetMangled().GetDemangledName()))
1302 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001303 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001304 // We just need the flags from the linker symbol, so put these flags
1305 // into the N_FUN flags to avoid duplicate symbols in the symbol table
1306 sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1307 sym[sym_idx].Clear();
1308 continue;
1309 }
Greg Clayton928d8292010-09-08 16:38:06 +00001310 }
1311 }
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001312 else if (type == eSymbolTypeData)
Greg Clayton928d8292010-09-08 16:38:06 +00001313 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001314 // See if we can find a N_STSYM entry for any data symbols.
1315 // If we do find a match, and the name matches, then we
1316 // can merge the two into just the Static symbol to avoid
1317 // duplicate entries in the symbol table
1318 ValueToSymbolIndexMap::const_iterator pos = N_STSYM_addr_to_sym_idx.find (nlist.n_value);
1319 if (pos != N_STSYM_addr_to_sym_idx.end())
Greg Clayton928d8292010-09-08 16:38:06 +00001320 {
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001321 if ((symbol_name_is_mangled == true && sym[sym_idx].GetMangled().GetMangledName() == sym[pos->second].GetMangled().GetMangledName()) ||
1322 (symbol_name_is_mangled == false && sym[sym_idx].GetMangled().GetDemangledName() == sym[pos->second].GetMangled().GetDemangledName()))
1323 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001324 m_nlist_idx_to_sym_idx[nlist_idx] = pos->second;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001325 // We just need the flags from the linker symbol, so put these flags
1326 // into the N_STSYM flags to avoid duplicate symbols in the symbol table
1327 sym[pos->second].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1328 sym[sym_idx].Clear();
1329 continue;
1330 }
Greg Clayton928d8292010-09-08 16:38:06 +00001331 }
1332 }
1333 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001334 if (symbol_section != NULL)
1335 symbol_value -= symbol_section->GetFileAddress();
1336
1337 sym[sym_idx].SetID (nlist_idx);
1338 sym[sym_idx].SetType (type);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001339 sym[sym_idx].GetAddressRangeRef().GetBaseAddress().SetSection (symbol_section);
1340 sym[sym_idx].GetAddressRangeRef().GetBaseAddress().SetOffset (symbol_value);
1341 sym[sym_idx].SetFlags (nlist.n_type << 16 | nlist.n_desc);
1342
1343 ++sym_idx;
1344 }
1345 else
1346 {
1347 sym[sym_idx].Clear();
1348 }
1349
1350 }
1351
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001352 // STAB N_GSYM entries end up having a symbol type eSymbolTypeGlobal and when the symbol value
1353 // is zero, the address of the global ends up being in a non-STAB entry. Try and fix up all
1354 // such entries by figuring out what the address for the global is by looking up this non-STAB
1355 // entry and copying the value into the debug symbol's value to save us the hassle in the
1356 // debug symbol parser.
1357
1358 Symbol *global_symbol = NULL;
1359 for (nlist_idx = 0;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001360 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 +00001361 nlist_idx++)
1362 {
1363 if (global_symbol->GetValue().GetFileAddress() == 0)
1364 {
1365 std::vector<uint32_t> indexes;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001366 if (symtab->AppendSymbolIndexesWithName (global_symbol->GetMangled().GetName(), indexes) > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367 {
1368 std::vector<uint32_t>::const_iterator pos;
1369 std::vector<uint32_t>::const_iterator end = indexes.end();
1370 for (pos = indexes.begin(); pos != end; ++pos)
1371 {
1372 symbol_ptr = symtab->SymbolAtIndex(*pos);
1373 if (symbol_ptr != global_symbol && symbol_ptr->IsDebug() == false)
1374 {
1375 global_symbol->SetValue(symbol_ptr->GetValue());
1376 break;
1377 }
1378 }
1379 }
1380 }
1381 }
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001382
1383 // Trim our symbols down to just what we ended up with after
1384 // removing any symbols.
1385 if (sym_idx < num_syms)
1386 {
1387 num_syms = sym_idx;
1388 sym = symtab->Resize (num_syms);
1389 }
1390
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 // Now synthesize indirect symbols
1392 if (m_dysymtab.nindirectsyms != 0)
1393 {
1394 DataBufferSP indirect_symbol_indexes_sp(m_file.ReadFileContents(m_offset + m_dysymtab.indirectsymoff, m_dysymtab.nindirectsyms * 4));
1395
1396 if (indirect_symbol_indexes_sp && indirect_symbol_indexes_sp->GetByteSize())
1397 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001398 NListIndexToSymbolIndexMap::const_iterator end_index_pos = m_nlist_idx_to_sym_idx.end();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001399 DataExtractor indirect_symbol_index_data (indirect_symbol_indexes_sp, m_data.GetByteOrder(), m_data.GetAddressByteSize());
1400
1401 for (uint32_t sect_idx = 1; sect_idx < m_mach_sections.size(); ++sect_idx)
1402 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001403 if ((m_mach_sections[sect_idx].flags & SectionFlagMaskSectionType) == SectionTypeSymbolStubs)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404 {
1405 uint32_t symbol_stub_byte_size = m_mach_sections[sect_idx].reserved2;
1406 if (symbol_stub_byte_size == 0)
1407 continue;
1408
1409 const uint32_t num_symbol_stubs = m_mach_sections[sect_idx].size / symbol_stub_byte_size;
1410
1411 if (num_symbol_stubs == 0)
1412 continue;
1413
1414 const uint32_t symbol_stub_index_offset = m_mach_sections[sect_idx].reserved1;
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001415 uint32_t synthetic_stub_sym_id = symtab_load_command.nsyms;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001416 for (uint32_t stub_idx = 0; stub_idx < num_symbol_stubs; ++stub_idx)
1417 {
1418 const uint32_t symbol_stub_index = symbol_stub_index_offset + stub_idx;
1419 const lldb::addr_t symbol_stub_addr = m_mach_sections[sect_idx].addr + (stub_idx * symbol_stub_byte_size);
1420 uint32_t symbol_stub_offset = symbol_stub_index * 4;
1421 if (indirect_symbol_index_data.ValidOffsetForDataOfSize(symbol_stub_offset, 4))
1422 {
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001423 const uint32_t stub_sym_id = indirect_symbol_index_data.GetU32 (&symbol_stub_offset);
Greg Claytonf4abd0d2010-10-06 01:26:32 +00001424 if (stub_sym_id & (IndirectSymbolAbsolute | IndirectSymbolLocal))
1425 continue;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001426
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001427 NListIndexToSymbolIndexMap::const_iterator index_pos = m_nlist_idx_to_sym_idx.find (stub_sym_id);
1428 Symbol *stub_symbol = NULL;
Greg Claytonbcf2cfb2010-09-11 03:13:28 +00001429 if (index_pos != end_index_pos)
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001430 {
1431 // We have a remapping from the original nlist index to
1432 // a current symbol index, so just look this up by index
1433 stub_symbol = symtab->SymbolAtIndex (index_pos->second);
1434 }
1435 else
1436 {
1437 // We need to lookup a symbol using the original nlist
1438 // symbol index since this index is coming from the
1439 // S_SYMBOL_STUBS
1440 stub_symbol = symtab->FindSymbolByID (stub_sym_id);
1441 }
Greg Clayton49bd1c82010-09-07 17:36:17 +00001442
1443 assert (stub_symbol);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001444 if (stub_symbol)
1445 {
1446 Address so_addr(symbol_stub_addr, section_list);
1447
1448 if (stub_symbol->GetType() == eSymbolTypeExtern)
1449 {
1450 // Change the external symbol into a trampoline that makes sense
1451 // These symbols were N_UNDF N_EXT, and are useless to us, so we
1452 // can re-use them so we don't have to make up a synthetic symbol
1453 // for no good reason.
1454 stub_symbol->SetType (eSymbolTypeTrampoline);
1455 stub_symbol->SetExternal (false);
1456 stub_symbol->GetAddressRangeRef().GetBaseAddress() = so_addr;
1457 stub_symbol->GetAddressRangeRef().SetByteSize (symbol_stub_byte_size);
1458 }
1459 else
1460 {
1461 // Make a synthetic symbol to describe the trampoline stub
1462 if (sym_idx >= num_syms)
Greg Clayton0c38b0d2010-09-12 05:25:16 +00001463 sym = symtab->Resize (++num_syms);
1464 sym[sym_idx].SetID (synthetic_stub_sym_id++);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465 sym[sym_idx].GetMangled() = stub_symbol->GetMangled();
1466 sym[sym_idx].SetType (eSymbolTypeTrampoline);
1467 sym[sym_idx].SetIsSynthetic (true);
1468 sym[sym_idx].GetAddressRangeRef().GetBaseAddress() = so_addr;
1469 sym[sym_idx].GetAddressRangeRef().SetByteSize (symbol_stub_byte_size);
1470 ++sym_idx;
1471 }
1472 }
1473 }
1474 }
1475 }
1476 }
1477 }
1478 }
1479
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001480 return symtab->GetNumSymbols();
1481 }
1482 }
1483 offset = cmd_offset + symtab_load_command.cmdsize;
1484 }
1485 return 0;
1486}
1487
1488
1489void
1490ObjectFileMachO::Dump (Stream *s)
1491{
1492 lldb_private::Mutex::Locker locker(m_mutex);
Jason Molendafd54b362011-09-20 21:44:10 +00001493 s->Printf("%p: ", this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001494 s->Indent();
Greg Claytone1a916a2010-07-21 22:12:05 +00001495 if (m_header.magic == HeaderMagic64 || m_header.magic == HeaderMagic64Swapped)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 s->PutCString("ObjectFileMachO64");
1497 else
1498 s->PutCString("ObjectFileMachO32");
1499
Greg Clayton41f92322010-06-11 03:25:34 +00001500 ArchSpec header_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001501
Greg Clayton64195a22011-02-23 00:35:02 +00001502 *s << ", file = '" << m_file << "', arch = " << header_arch.GetArchitectureName() << "\n";
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001503
1504 if (m_sections_ap.get())
Greg Clayton10177aa2010-12-08 05:08:21 +00001505 m_sections_ap->Dump(s, NULL, true, UINT32_MAX);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001506
1507 if (m_symtab_ap.get())
Greg Clayton8087ca22010-10-08 04:20:14 +00001508 m_symtab_ap->Dump(s, NULL, eSortOrderNone);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001509}
1510
1511
1512bool
Greg Clayton60830262011-02-04 18:53:10 +00001513ObjectFileMachO::GetUUID (lldb_private::UUID* uuid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001514{
1515 lldb_private::Mutex::Locker locker(m_mutex);
1516 struct uuid_command load_cmd;
1517 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1518 uint32_t i;
1519 for (i=0; i<m_header.ncmds; ++i)
1520 {
1521 const uint32_t cmd_offset = offset;
1522 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1523 break;
1524
Greg Claytone1a916a2010-07-21 22:12:05 +00001525 if (load_cmd.cmd == LoadCommandUUID)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001526 {
1527 const uint8_t *uuid_bytes = m_data.PeekData(offset, 16);
1528 if (uuid_bytes)
1529 {
1530 uuid->SetBytes (uuid_bytes);
1531 return true;
1532 }
1533 return false;
1534 }
1535 offset = cmd_offset + load_cmd.cmdsize;
1536 }
1537 return false;
1538}
1539
1540
1541uint32_t
1542ObjectFileMachO::GetDependentModules (FileSpecList& files)
1543{
1544 lldb_private::Mutex::Locker locker(m_mutex);
1545 struct load_command load_cmd;
1546 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1547 uint32_t count = 0;
Greg Clayton9b72eb72011-05-24 23:06:02 +00001548 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 +00001549 uint32_t i;
1550 for (i=0; i<m_header.ncmds; ++i)
1551 {
1552 const uint32_t cmd_offset = offset;
1553 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1554 break;
1555
1556 switch (load_cmd.cmd)
1557 {
Greg Claytone1a916a2010-07-21 22:12:05 +00001558 case LoadCommandDylibLoad:
1559 case LoadCommandDylibLoadWeak:
1560 case LoadCommandDylibReexport:
1561 case LoadCommandDynamicLinkerLoad:
1562 case LoadCommandFixedVMShlibLoad:
Greg Clayton74f6e9f2010-10-09 00:48:53 +00001563 case LoadCommandDylibLoadUpward:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001564 {
1565 uint32_t name_offset = cmd_offset + m_data.GetU32(&offset);
1566 const char *path = m_data.PeekCStr(name_offset);
1567 // Skip any path that starts with '@' since these are usually:
1568 // @executable_path/.../file
1569 // @rpath/.../file
1570 if (path && path[0] != '@')
1571 {
Greg Clayton9b72eb72011-05-24 23:06:02 +00001572 FileSpec file_spec(path, resolve_path);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001573 if (files.AppendIfUnique(file_spec))
1574 count++;
1575 }
1576 }
1577 break;
1578
1579 default:
1580 break;
1581 }
1582 offset = cmd_offset + load_cmd.cmdsize;
1583 }
1584 return count;
1585}
1586
Jim Ingham672e6f52011-03-07 23:44:08 +00001587lldb_private::Address
1588ObjectFileMachO::GetEntryPointAddress ()
1589{
1590 // If the object file is not an executable it can't hold the entry point. m_entry_point_address
1591 // is initialized to an invalid address, so we can just return that.
1592 // If m_entry_point_address is valid it means we've found it already, so return the cached value.
1593
1594 if (!IsExecutable() || m_entry_point_address.IsValid())
1595 return m_entry_point_address;
1596
1597 // Otherwise, look for the UnixThread or Thread command. The data for the Thread command is given in
1598 // /usr/include/mach-o.h, but it is basically:
1599 //
1600 // uint32_t flavor - this is the flavor argument you would pass to thread_get_state
1601 // uint32_t count - this is the count of longs in the thread state data
1602 // struct XXX_thread_state state - this is the structure from <machine/thread_status.h> corresponding to the flavor.
1603 // <repeat this trio>
1604 //
1605 // So we just keep reading the various register flavors till we find the GPR one, then read the PC out of there.
1606 // FIXME: We will need to have a "RegisterContext data provider" class at some point that can get all the registers
1607 // out of data in this form & attach them to a given thread. That should underlie the MacOS X User process plugin,
1608 // and we'll also need it for the MacOS X Core File process plugin. When we have that we can also use it here.
1609 //
1610 // For now we hard-code the offsets and flavors we need:
1611 //
1612 //
1613
1614 lldb_private::Mutex::Locker locker(m_mutex);
1615 struct load_command load_cmd;
1616 uint32_t offset = MachHeaderSizeFromMagic(m_header.magic);
1617 uint32_t i;
1618 lldb::addr_t start_address = LLDB_INVALID_ADDRESS;
1619 bool done = false;
1620
1621 for (i=0; i<m_header.ncmds; ++i)
1622 {
1623 const uint32_t cmd_offset = offset;
1624 if (m_data.GetU32(&offset, &load_cmd, 2) == NULL)
1625 break;
1626
1627 switch (load_cmd.cmd)
1628 {
1629 case LoadCommandUnixThread:
1630 case LoadCommandThread:
1631 {
1632 while (offset < cmd_offset + load_cmd.cmdsize)
1633 {
1634 uint32_t flavor = m_data.GetU32(&offset);
1635 uint32_t count = m_data.GetU32(&offset);
1636 if (count == 0)
1637 {
1638 // We've gotten off somehow, log and exit;
1639 return m_entry_point_address;
1640 }
1641
1642 switch (m_header.cputype)
1643 {
1644 case llvm::MachO::CPUTypeARM:
1645 if (flavor == 1) // ARM_THREAD_STATE from mach/arm/thread_status.h
1646 {
1647 offset += 60; // This is the offset of pc in the GPR thread state data structure.
1648 start_address = m_data.GetU32(&offset);
1649 done = true;
1650 }
1651 break;
1652 case llvm::MachO::CPUTypeI386:
1653 if (flavor == 1) // x86_THREAD_STATE32 from mach/i386/thread_status.h
1654 {
1655 offset += 40; // This is the offset of eip in the GPR thread state data structure.
1656 start_address = m_data.GetU32(&offset);
1657 done = true;
1658 }
1659 break;
1660 case llvm::MachO::CPUTypeX86_64:
1661 if (flavor == 4) // x86_THREAD_STATE64 from mach/i386/thread_status.h
1662 {
1663 offset += 16 * 8; // This is the offset of rip in the GPR thread state data structure.
1664 start_address = m_data.GetU64(&offset);
1665 done = true;
1666 }
1667 break;
1668 default:
1669 return m_entry_point_address;
1670 }
1671 // Haven't found the GPR flavor yet, skip over the data for this flavor:
1672 if (done)
1673 break;
1674 offset += count * 4;
1675 }
1676 }
1677 break;
1678
1679 default:
1680 break;
1681 }
1682 if (done)
1683 break;
1684
1685 // Go to the next load command:
1686 offset = cmd_offset + load_cmd.cmdsize;
1687 }
1688
1689 if (start_address != LLDB_INVALID_ADDRESS)
1690 {
1691 // We got the start address from the load commands, so now resolve that address in the sections
1692 // of this ObjectFile:
1693 if (!m_entry_point_address.ResolveAddressUsingFileSections (start_address, GetSectionList()))
1694 {
1695 m_entry_point_address.Clear();
1696 }
1697 }
1698 else
1699 {
1700 // We couldn't read the UnixThread load command - maybe it wasn't there. As a fallback look for the
1701 // "start" symbol in the main executable.
1702
1703 SymbolContextList contexts;
1704 SymbolContext context;
Sean Callananb96ff332011-10-13 16:49:47 +00001705 if (!m_module->FindSymbolsWithNameAndType(ConstString ("start"), eSymbolTypeCode, contexts))
Jim Ingham672e6f52011-03-07 23:44:08 +00001706 return m_entry_point_address;
1707
1708 contexts.GetContextAtIndex(0, context);
1709
1710 m_entry_point_address = context.symbol->GetValue();
1711 }
1712
1713 return m_entry_point_address;
1714
1715}
1716
Greg Clayton9e00b6a652011-07-09 00:41:34 +00001717ObjectFile::Type
1718ObjectFileMachO::CalculateType()
1719{
1720 switch (m_header.filetype)
1721 {
1722 case HeaderFileTypeObject: // 0x1u MH_OBJECT
1723 if (GetAddressByteSize () == 4)
1724 {
1725 // 32 bit kexts are just object files, but they do have a valid
1726 // UUID load command.
1727 UUID uuid;
1728 if (GetUUID(&uuid))
1729 {
1730 // this checking for the UUID load command is not enough
1731 // we could eventually look for the symbol named
1732 // "OSKextGetCurrentIdentifier" as this is required of kexts
1733 if (m_strata == eStrataInvalid)
1734 m_strata = eStrataKernel;
1735 return eTypeSharedLibrary;
1736 }
1737 }
1738 return eTypeObjectFile;
1739
1740 case HeaderFileTypeExecutable: return eTypeExecutable; // 0x2u MH_EXECUTE
1741 case HeaderFileTypeFixedVMShlib: return eTypeSharedLibrary; // 0x3u MH_FVMLIB
1742 case HeaderFileTypeCore: return eTypeCoreFile; // 0x4u MH_CORE
1743 case HeaderFileTypePreloadedExecutable: return eTypeSharedLibrary; // 0x5u MH_PRELOAD
1744 case HeaderFileTypeDynamicShlib: return eTypeSharedLibrary; // 0x6u MH_DYLIB
1745 case HeaderFileTypeDynamicLinkEditor: return eTypeDynamicLinker; // 0x7u MH_DYLINKER
1746 case HeaderFileTypeBundle: return eTypeSharedLibrary; // 0x8u MH_BUNDLE
1747 case HeaderFileTypeDynamicShlibStub: return eTypeStubLibrary; // 0x9u MH_DYLIB_STUB
1748 case HeaderFileTypeDSYM: return eTypeDebugInfo; // 0xAu MH_DSYM
1749 case HeaderFileTypeKextBundle: return eTypeSharedLibrary; // 0xBu MH_KEXT_BUNDLE
1750 default:
1751 break;
1752 }
1753 return eTypeUnknown;
1754}
1755
1756ObjectFile::Strata
1757ObjectFileMachO::CalculateStrata()
1758{
1759 switch (m_header.filetype)
1760 {
1761 case HeaderFileTypeObject: // 0x1u MH_OBJECT
1762 {
1763 // 32 bit kexts are just object files, but they do have a valid
1764 // UUID load command.
1765 UUID uuid;
1766 if (GetUUID(&uuid))
1767 {
1768 // this checking for the UUID load command is not enough
1769 // we could eventually look for the symbol named
1770 // "OSKextGetCurrentIdentifier" as this is required of kexts
1771 if (m_type == eTypeInvalid)
1772 m_type = eTypeSharedLibrary;
1773
1774 return eStrataKernel;
1775 }
1776 }
1777 return eStrataUnknown;
1778
1779 case HeaderFileTypeExecutable: // 0x2u MH_EXECUTE
1780 // Check for the MH_DYLDLINK bit in the flags
1781 if (m_header.flags & HeaderFlagBitIsDynamicLinkObject)
1782 return eStrataUser;
1783 return eStrataKernel;
1784
1785 case HeaderFileTypeFixedVMShlib: return eStrataUser; // 0x3u MH_FVMLIB
1786 case HeaderFileTypeCore: return eStrataUnknown; // 0x4u MH_CORE
1787 case HeaderFileTypePreloadedExecutable: return eStrataUser; // 0x5u MH_PRELOAD
1788 case HeaderFileTypeDynamicShlib: return eStrataUser; // 0x6u MH_DYLIB
1789 case HeaderFileTypeDynamicLinkEditor: return eStrataUser; // 0x7u MH_DYLINKER
1790 case HeaderFileTypeBundle: return eStrataUser; // 0x8u MH_BUNDLE
1791 case HeaderFileTypeDynamicShlibStub: return eStrataUser; // 0x9u MH_DYLIB_STUB
1792 case HeaderFileTypeDSYM: return eStrataUnknown; // 0xAu MH_DSYM
1793 case HeaderFileTypeKextBundle: return eStrataKernel; // 0xBu MH_KEXT_BUNDLE
1794 default:
1795 break;
1796 }
1797 return eStrataUnknown;
1798}
1799
1800
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801bool
Greg Clayton514487e2011-02-15 21:59:32 +00001802ObjectFileMachO::GetArchitecture (ArchSpec &arch)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803{
1804 lldb_private::Mutex::Locker locker(m_mutex);
Greg Claytone0d378b2011-03-24 21:19:54 +00001805 arch.SetArchitecture (eArchTypeMachO, m_header.cputype, m_header.cpusubtype);
Greg Clayton593577a2011-09-21 03:57:31 +00001806
1807 // Files with type MH_PRELOAD are currently used in cases where the image
1808 // debugs at the addresses in the file itself. Below we set the OS to
1809 // unknown to make sure we use the DynamicLoaderStatic()...
1810 if (m_header.filetype == HeaderFileTypePreloadedExecutable)
1811 {
1812 arch.GetTriple().setOS (llvm::Triple::UnknownOS);
1813 }
1814
Greg Clayton514487e2011-02-15 21:59:32 +00001815 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001816}
1817
1818
1819//------------------------------------------------------------------
1820// PluginInterface protocol
1821//------------------------------------------------------------------
1822const char *
1823ObjectFileMachO::GetPluginName()
1824{
1825 return "ObjectFileMachO";
1826}
1827
1828const char *
1829ObjectFileMachO::GetShortPluginName()
1830{
1831 return GetPluginNameStatic();
1832}
1833
1834uint32_t
1835ObjectFileMachO::GetPluginVersion()
1836{
1837 return 1;
1838}
1839