blob: bb1b5dd107deb6a2e3872282e5055a886a9d1d8b [file] [log] [blame]
Nick Kledzike34182f2013-11-06 21:36:55 +00001//===- lib/ReaderWriter/MachO/MachONormalizedFileBinaryReader.cpp ---------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10///
11/// \file For mach-o object files, this implementation converts from
12/// mach-o on-disk binary format to in-memory normalized mach-o.
13///
14/// +---------------+
15/// | binary mach-o |
16/// +---------------+
17/// |
18/// |
19/// v
20/// +------------+
21/// | normalized |
22/// +------------+
23
24#include "MachONormalizedFile.h"
25#include "MachONormalizedFileBinaryUtils.h"
Nick Kledzike5552772013-12-19 21:58:00 +000026#include "ReferenceKinds.h"
Nick Kledzike34182f2013-11-06 21:36:55 +000027
28#include "lld/Core/Error.h"
29#include "lld/Core/LLVM.h"
30
31#include "llvm/ADT/SmallString.h"
32#include "llvm/ADT/StringRef.h"
33#include "llvm/ADT/StringSwitch.h"
34#include "llvm/ADT/Twine.h"
35#include "llvm/Support/Casting.h"
36#include "llvm/Support/ErrorHandling.h"
37#include "llvm/Support/FileOutputBuffer.h"
38#include "llvm/Support/Host.h"
39#include "llvm/Support/MachO.h"
40#include "llvm/Support/MemoryBuffer.h"
41#include "llvm/Support/raw_ostream.h"
42#include "llvm/Support/system_error.h"
43
44#include <functional>
45
46using namespace llvm::MachO;
47
48namespace lld {
49namespace mach_o {
50namespace normalized {
51
52// Utility to call a lambda expression on each load command.
Shankar Easwaran3d8de472014-01-27 03:09:26 +000053static error_code
Nick Kledzike34182f2013-11-06 21:36:55 +000054forEachLoadCommand(StringRef lcRange, unsigned lcCount, bool swap, bool is64,
Shankar Easwaran3d8de472014-01-27 03:09:26 +000055 std::function<bool (uint32_t cmd, uint32_t size,
Nick Kledzike34182f2013-11-06 21:36:55 +000056 const char* lc)> func) {
57 const char* p = lcRange.begin();
58 for (unsigned i=0; i < lcCount; ++i) {
59 const load_command *lc = reinterpret_cast<const load_command*>(p);
60 load_command lcCopy;
61 const load_command *slc = lc;
62 if (swap) {
63 memcpy(&lcCopy, lc, sizeof(load_command));
64 swapStruct(lcCopy);
65 slc = &lcCopy;
66 }
67 if ( (p + slc->cmdsize) > lcRange.end() )
68 return llvm::make_error_code(llvm::errc::executable_format_error);
Shankar Easwaran3d8de472014-01-27 03:09:26 +000069
Nick Kledzike34182f2013-11-06 21:36:55 +000070 if (func(slc->cmd, slc->cmdsize, p))
71 return error_code::success();
Shankar Easwaran3d8de472014-01-27 03:09:26 +000072
Nick Kledzike34182f2013-11-06 21:36:55 +000073 p += slc->cmdsize;
Shankar Easwaran3d8de472014-01-27 03:09:26 +000074 }
75
Nick Kledzike34182f2013-11-06 21:36:55 +000076 return error_code::success();
77}
78
79
Shankar Easwaran3d8de472014-01-27 03:09:26 +000080static error_code
81appendRelocations(Relocations &relocs, StringRef buffer, bool swap,
Nick Kledzike34182f2013-11-06 21:36:55 +000082 bool bigEndian, uint32_t reloff, uint32_t nreloc) {
83 if ((reloff + nreloc*8) > buffer.size())
84 return llvm::make_error_code(llvm::errc::executable_format_error);
Shankar Easwaran3d8de472014-01-27 03:09:26 +000085 const any_relocation_info* relocsArray =
Joey Gouly010b3762014-01-14 22:32:38 +000086 reinterpret_cast<const any_relocation_info*>(buffer.begin()+reloff);
Shankar Easwaran3d8de472014-01-27 03:09:26 +000087
Nick Kledzike34182f2013-11-06 21:36:55 +000088 for(uint32_t i=0; i < nreloc; ++i) {
89 relocs.push_back(unpackRelocation(relocsArray[i], swap, bigEndian));
90 }
91 return error_code::success();
92}
93
Nick Kledzik388f3d02014-05-28 01:16:35 +000094static error_code
95appendIndirectSymbols(IndirectSymbols &isyms, StringRef buffer, bool swap,
96 bool bigEndian, uint32_t istOffset, uint32_t istCount,
97 uint32_t startIndex, uint32_t count) {
98 if ((istOffset + istCount*4) > buffer.size())
99 return llvm::make_error_code(llvm::errc::executable_format_error);
100 if (startIndex+count > istCount)
101 return llvm::make_error_code(llvm::errc::executable_format_error);
102 const uint32_t *indirectSymbolArray =
103 reinterpret_cast<const uint32_t*>(buffer.begin()+istOffset);
104
105 for(uint32_t i=0; i < count; ++i) {
106 isyms.push_back(read32(swap, indirectSymbolArray[startIndex+i]));
107 }
108 return error_code::success();
109}
110
111
Joey Gouly010b3762014-01-14 22:32:38 +0000112template <typename T> static T readBigEndian(T t) {
113 if (llvm::sys::IsLittleEndianHost)
114 return SwapByteOrder(t);
115 return t;
116}
Nick Kledzike34182f2013-11-06 21:36:55 +0000117
118/// Reads a mach-o file and produces an in-memory normalized view.
Joey Gouly010b3762014-01-14 22:32:38 +0000119ErrorOr<std::unique_ptr<NormalizedFile>>
120readBinary(std::unique_ptr<MemoryBuffer> &mb,
121 const MachOLinkingContext::Arch arch) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000122 // Make empty NormalizedFile.
123 std::unique_ptr<NormalizedFile> f(new NormalizedFile());
124
Joey Gouly010b3762014-01-14 22:32:38 +0000125 const char *start = mb->getBufferStart();
126 size_t objSize = mb->getBufferSize();
127
Nick Kledzike34182f2013-11-06 21:36:55 +0000128 // Determine endianness and pointer size for mach-o file.
Joey Gouly010b3762014-01-14 22:32:38 +0000129 const mach_header *mh = reinterpret_cast<const mach_header *>(start);
130 bool isFat = mh->magic == llvm::MachO::FAT_CIGAM ||
131 mh->magic == llvm::MachO::FAT_MAGIC;
132 if (isFat) {
133 uint32_t cputype = MachOLinkingContext::cpuTypeFromArch(arch);
134 uint32_t cpusubtype = MachOLinkingContext::cpuSubtypeFromArch(arch);
135 const fat_header *fh = reinterpret_cast<const fat_header *>(start);
136 uint32_t nfat_arch = readBigEndian(fh->nfat_arch);
137 const fat_arch *fa =
138 reinterpret_cast<const fat_arch *>(start + sizeof(fat_header));
139 bool foundArch = false;
140 while (nfat_arch-- > 0) {
141 if (readBigEndian(fa->cputype) == cputype &&
142 readBigEndian(fa->cpusubtype) == cpusubtype) {
143 foundArch = true;
144 break;
145 }
146 fa++;
147 }
148 if (!foundArch) {
149 return llvm::make_error_code(llvm::errc::executable_format_error);
150 }
151 objSize = readBigEndian(fa->size);
152 uint32_t offset = readBigEndian(fa->offset);
153 if ((offset + objSize) > mb->getBufferSize())
154 return llvm::make_error_code(llvm::errc::executable_format_error);
155 start += offset;
156 mh = reinterpret_cast<const mach_header *>(start);
157 }
158
Nick Kledzike34182f2013-11-06 21:36:55 +0000159 bool is64, swap;
160 switch (mh->magic) {
161 case llvm::MachO::MH_MAGIC:
162 is64 = false;
163 swap = false;
164 break;
165 case llvm::MachO::MH_MAGIC_64:
166 is64 = true;
167 swap = false;
168 break;
169 case llvm::MachO::MH_CIGAM:
170 is64 = false;
171 swap = true;
172 break;
173 case llvm::MachO::MH_CIGAM_64:
174 is64 = true;
175 swap = true;
176 break;
177 default:
178 return llvm::make_error_code(llvm::errc::executable_format_error);
179 }
180
181 // Endian swap header, if needed.
182 mach_header headerCopy;
183 const mach_header *smh = mh;
184 if (swap) {
185 memcpy(&headerCopy, mh, sizeof(mach_header));
186 swapStruct(headerCopy);
187 smh = &headerCopy;
188 }
189
190 // Validate head and load commands fit in buffer.
191 const uint32_t lcCount = smh->ncmds;
Joey Gouly010b3762014-01-14 22:32:38 +0000192 const char *lcStart =
193 start + (is64 ? sizeof(mach_header_64) : sizeof(mach_header));
Nick Kledzike34182f2013-11-06 21:36:55 +0000194 StringRef lcRange(lcStart, smh->sizeofcmds);
Joey Gouly010b3762014-01-14 22:32:38 +0000195 if (lcRange.end() > (start + objSize))
Nick Kledzike34182f2013-11-06 21:36:55 +0000196 return llvm::make_error_code(llvm::errc::executable_format_error);
197
198 // Normalize architecture
199 f->arch = MachOLinkingContext::archFromCpuType(smh->cputype, smh->cpusubtype);
200 bool isBigEndianArch = MachOLinkingContext::isBigEndian(f->arch);
201 // Copy file type and flags
202 f->fileType = HeaderFileType(smh->filetype);
203 f->flags = smh->flags;
204
205
Nick Kledzik388f3d02014-05-28 01:16:35 +0000206 // Pre-scan load commands looking for indirect symbol table.
207 uint32_t indirectSymbolTableOffset = 0;
208 uint32_t indirectSymbolTableCount = 0;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000209 error_code ec = forEachLoadCommand(lcRange, lcCount, swap, is64,
Nick Kledzike34182f2013-11-06 21:36:55 +0000210 [&] (uint32_t cmd, uint32_t size, const char* lc) -> bool {
Nick Kledzik388f3d02014-05-28 01:16:35 +0000211 if (cmd == LC_DYSYMTAB) {
212 const dysymtab_command *d = reinterpret_cast<const dysymtab_command*>(lc);
213 indirectSymbolTableOffset = read32(swap, d->indirectsymoff);
214 indirectSymbolTableCount = read32(swap, d->nindirectsyms);
215 return true;
216 }
217 return false;
218 });
219 if (ec)
220 return ec;
221
222 // Walk load commands looking for segments/sections and the symbol table.
223 ec = forEachLoadCommand(lcRange, lcCount, swap, is64,
224 [&] (uint32_t cmd, uint32_t size, const char* lc) -> bool {
Nick Kledzike34182f2013-11-06 21:36:55 +0000225 if (is64) {
226 if (cmd == LC_SEGMENT_64) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000227 const segment_command_64 *seg =
Nick Kledzike34182f2013-11-06 21:36:55 +0000228 reinterpret_cast<const segment_command_64*>(lc);
229 const unsigned sectionCount = (swap ? SwapByteOrder(seg->nsects)
230 : seg->nsects);
231 const section_64 *sects = reinterpret_cast<const section_64*>
232 (lc + sizeof(segment_command_64));
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000233 const unsigned lcSize = sizeof(segment_command_64)
Nick Kledzike34182f2013-11-06 21:36:55 +0000234 + sectionCount*sizeof(section_64);
235 // Verify sections don't extend beyond end of segment load command.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000236 if (lcSize > size)
Nick Kledzike34182f2013-11-06 21:36:55 +0000237 return llvm::make_error_code(llvm::errc::executable_format_error);
238 for (unsigned i=0; i < sectionCount; ++i) {
239 const section_64 *sect = &sects[i];
240 Section section;
241 section.segmentName = getString16(sect->segname);
242 section.sectionName = getString16(sect->sectname);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000243 section.type = (SectionType)(read32(swap, sect->flags)
Nick Kledzike34182f2013-11-06 21:36:55 +0000244 & SECTION_TYPE);
245 section.attributes = read32(swap, sect->flags) & SECTION_ATTRIBUTES;
246 section.alignment = read32(swap, sect->align);
247 section.address = read64(swap, sect->addr);
Joey Gouly010b3762014-01-14 22:32:38 +0000248 const uint8_t *content =
249 (uint8_t *)start + read32(swap, sect->offset);
Nick Kledzike34182f2013-11-06 21:36:55 +0000250 size_t contentSize = read64(swap, sect->size);
251 // Note: this assign() is copying the content bytes. Ideally,
252 // we can use a custom allocator for vector to avoid the copy.
Nick Kledzik6edd7222014-01-11 01:07:43 +0000253 section.content = llvm::makeArrayRef(content, contentSize);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000254 appendRelocations(section.relocations, mb->getBuffer(),
255 swap, isBigEndianArch, read32(swap, sect->reloff),
Nick Kledzike34182f2013-11-06 21:36:55 +0000256 read32(swap, sect->nreloc));
Nick Kledzik388f3d02014-05-28 01:16:35 +0000257 if (section.type == S_NON_LAZY_SYMBOL_POINTERS) {
258 appendIndirectSymbols(section.indirectSymbols, mb->getBuffer(),
259 swap, isBigEndianArch,
260 indirectSymbolTableOffset,
261 indirectSymbolTableCount,
262 read32(swap, sect->reserved1), contentSize/4);
263 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000264 f->sections.push_back(section);
265 }
266 }
267 } else {
268 if (cmd == LC_SEGMENT) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000269 const segment_command *seg =
Nick Kledzike34182f2013-11-06 21:36:55 +0000270 reinterpret_cast<const segment_command*>(lc);
271 const unsigned sectionCount = (swap ? SwapByteOrder(seg->nsects)
272 : seg->nsects);
273 const section *sects = reinterpret_cast<const section*>
274 (lc + sizeof(segment_command));
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000275 const unsigned lcSize = sizeof(segment_command)
Nick Kledzike34182f2013-11-06 21:36:55 +0000276 + sectionCount*sizeof(section);
277 // Verify sections don't extend beyond end of segment load command.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000278 if (lcSize > size)
Nick Kledzike34182f2013-11-06 21:36:55 +0000279 return llvm::make_error_code(llvm::errc::executable_format_error);
280 for (unsigned i=0; i < sectionCount; ++i) {
281 const section *sect = &sects[i];
282 Section section;
283 section.segmentName = getString16(sect->segname);
284 section.sectionName = getString16(sect->sectname);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000285 section.type = (SectionType)(read32(swap, sect->flags)
Nick Kledzike34182f2013-11-06 21:36:55 +0000286 & SECTION_TYPE);
287 section.attributes = read32(swap, sect->flags) & SECTION_ATTRIBUTES;
288 section.alignment = read32(swap, sect->align);
289 section.address = read32(swap, sect->addr);
Joey Gouly010b3762014-01-14 22:32:38 +0000290 const uint8_t *content =
291 (uint8_t *)start + read32(swap, sect->offset);
Nick Kledzike34182f2013-11-06 21:36:55 +0000292 size_t contentSize = read32(swap, sect->size);
293 // Note: this assign() is copying the content bytes. Ideally,
294 // we can use a custom allocator for vector to avoid the copy.
Nick Kledzik6edd7222014-01-11 01:07:43 +0000295 section.content = llvm::makeArrayRef(content, contentSize);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000296 appendRelocations(section.relocations, mb->getBuffer(),
297 swap, isBigEndianArch, read32(swap, sect->reloff),
Nick Kledzike34182f2013-11-06 21:36:55 +0000298 read32(swap, sect->nreloc));
Nick Kledzik388f3d02014-05-28 01:16:35 +0000299 if (section.type == S_NON_LAZY_SYMBOL_POINTERS) {
300 appendIndirectSymbols(section.indirectSymbols, mb->getBuffer(),
301 swap, isBigEndianArch,
302 indirectSymbolTableOffset,
303 indirectSymbolTableCount,
304 read32(swap, sect->reserved1), contentSize/4);
305 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000306 f->sections.push_back(section);
307 }
308 }
309 }
310 if (cmd == LC_SYMTAB) {
311 const symtab_command *st = reinterpret_cast<const symtab_command*>(lc);
Joey Gouly010b3762014-01-14 22:32:38 +0000312 const char *strings = start + read32(swap, st->stroff);
Nick Kledzike34182f2013-11-06 21:36:55 +0000313 const uint32_t strSize = read32(swap, st->strsize);
314 // Validate string pool and symbol table all in buffer.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000315 if ( read32(swap, st->stroff)+read32(swap, st->strsize)
Joey Gouly010b3762014-01-14 22:32:38 +0000316 > objSize )
Nick Kledzike34182f2013-11-06 21:36:55 +0000317 return llvm::make_error_code(llvm::errc::executable_format_error);
318 if (is64) {
319 const uint32_t symOffset = read32(swap, st->symoff);
320 const uint32_t symCount = read32(swap, st->nsyms);
Joey Gouly010b3762014-01-14 22:32:38 +0000321 if ( symOffset+(symCount*sizeof(nlist_64)) > objSize)
Nick Kledzike34182f2013-11-06 21:36:55 +0000322 return llvm::make_error_code(llvm::errc::executable_format_error);
Joey Gouly010b3762014-01-14 22:32:38 +0000323 const nlist_64 *symbols =
324 reinterpret_cast<const nlist_64 *>(start + symOffset);
Nick Kledzike34182f2013-11-06 21:36:55 +0000325 // Convert each nlist_64 to a lld::mach_o::normalized::Symbol.
326 for(uint32_t i=0; i < symCount; ++i) {
327 const nlist_64 *sin = &symbols[i];
328 nlist_64 tempSym;
329 if (swap) {
330 tempSym = *sin; swapStruct(tempSym); sin = &tempSym;
331 }
332 Symbol sout;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000333 if (sin->n_strx > strSize)
Nick Kledzike34182f2013-11-06 21:36:55 +0000334 return llvm::make_error_code(llvm::errc::executable_format_error);
335 sout.name = &strings[sin->n_strx];
336 sout.type = (NListType)(sin->n_type & N_TYPE);
337 sout.scope = (sin->n_type & (N_PEXT|N_EXT));
338 sout.sect = sin->n_sect;
339 sout.desc = sin->n_desc;
340 sout.value = sin->n_value;
341 if (sout.type == N_UNDF)
342 f->undefinedSymbols.push_back(sout);
343 else if (sout.scope == (SymbolScope)N_EXT)
344 f->globalSymbols.push_back(sout);
345 else
346 f->localSymbols.push_back(sout);
347 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000348 } else {
Nick Kledzike34182f2013-11-06 21:36:55 +0000349 const uint32_t symOffset = read32(swap, st->symoff);
350 const uint32_t symCount = read32(swap, st->nsyms);
Joey Gouly010b3762014-01-14 22:32:38 +0000351 if ( symOffset+(symCount*sizeof(nlist)) > objSize)
Nick Kledzike34182f2013-11-06 21:36:55 +0000352 return llvm::make_error_code(llvm::errc::executable_format_error);
Joey Gouly010b3762014-01-14 22:32:38 +0000353 const nlist *symbols =
354 reinterpret_cast<const nlist *>(start + symOffset);
Nick Kledzike34182f2013-11-06 21:36:55 +0000355 // Convert each nlist to a lld::mach_o::normalized::Symbol.
356 for(uint32_t i=0; i < symCount; ++i) {
357 const nlist *sin = &symbols[i];
358 nlist tempSym;
359 if (swap) {
360 tempSym = *sin; swapStruct(tempSym); sin = &tempSym;
361 }
362 Symbol sout;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000363 if (sin->n_strx > strSize)
Nick Kledzike34182f2013-11-06 21:36:55 +0000364 return llvm::make_error_code(llvm::errc::executable_format_error);
365 sout.name = &strings[sin->n_strx];
366 sout.type = (NListType)(sin->n_type & N_TYPE);
367 sout.scope = (sin->n_type & (N_PEXT|N_EXT));
368 sout.sect = sin->n_sect;
369 sout.desc = sin->n_desc;
370 sout.value = sin->n_value;
371 if (sout.type == N_UNDF)
372 f->undefinedSymbols.push_back(sout);
373 else if (sout.scope == (SymbolScope)N_EXT)
374 f->globalSymbols.push_back(sout);
375 else
376 f->localSymbols.push_back(sout);
377 }
378 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000379 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000380 return false;
381 });
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000382 if (ec)
Nick Kledzike34182f2013-11-06 21:36:55 +0000383 return ec;
384
385 return std::move(f);
386}
387
388
Nick Kledzikcc28bc12014-05-30 01:13:49 +0000389
390class MachOReader : public Reader {
391public:
392 MachOReader(MachOLinkingContext::Arch arch) : _arch(arch) {}
393
394 bool canParse(file_magic magic, StringRef ext,
395 const MemoryBuffer &mb) const override {
396 if (magic != llvm::sys::fs::file_magic::macho_object)
397 return false;
398 if (mb.getBufferSize() < 32)
399 return false;
400 const char *start = mb.getBufferStart();
401 const mach_header *mh = reinterpret_cast<const mach_header *>(start);
402 const bool swap = (mh->magic == llvm::MachO::MH_CIGAM) ||
403 (mh->magic == llvm::MachO::MH_CIGAM_64);
404 const uint32_t filesCpuType = read32(swap, mh->cputype);
405 const uint32_t filesCpuSubtype = read32(swap, mh->cpusubtype);
406 if (filesCpuType != MachOLinkingContext::cpuTypeFromArch(_arch))
407 return false;
408 if (filesCpuSubtype != MachOLinkingContext::cpuSubtypeFromArch(_arch))
409 return false;
410
411 // Is mach-o file with correct cpu type/subtype.
412 return true;
413 }
414
415 error_code
416 parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry &registry,
417 std::vector<std::unique_ptr<File> > &result) const override {
418 // Convert binary file to normalized mach-o.
419 auto normFile = readBinary(mb, _arch);
420 if (error_code ec = normFile.getError())
421 return ec;
422 // Convert normalized mach-o to atoms.
423 auto file = normalizedToAtoms(**normFile, mb->getBufferIdentifier(), false);
424 if (error_code ec = file.getError())
425 return ec;
426
427 result.push_back(std::move(*file));
428
429 return error_code::success();
430 }
431private:
432 MachOLinkingContext::Arch _arch;
433};
434
435
Nick Kledzike34182f2013-11-06 21:36:55 +0000436} // namespace normalized
437} // namespace mach_o
Nick Kledzike5552772013-12-19 21:58:00 +0000438
439void Registry::addSupportMachOObjects(StringRef archName) {
440 MachOLinkingContext::Arch arch = MachOLinkingContext::archFromName(archName);
Nick Kledzikcc28bc12014-05-30 01:13:49 +0000441 add(std::unique_ptr<Reader>(new mach_o::normalized::MachOReader(arch)));
Nick Kledzike5552772013-12-19 21:58:00 +0000442 switch (arch) {
443 case MachOLinkingContext::arch_x86_64:
Rui Ueyama170a1a82013-12-20 07:48:29 +0000444 addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::x86_64,
Nick Kledzike5552772013-12-19 21:58:00 +0000445 mach_o::KindHandler_x86_64::kindStrings);
446 break;
447 case MachOLinkingContext::arch_x86:
Rui Ueyama170a1a82013-12-20 07:48:29 +0000448 addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::x86,
Nick Kledzike5552772013-12-19 21:58:00 +0000449 mach_o::KindHandler_x86::kindStrings);
450 break;
451 case MachOLinkingContext::arch_armv6:
452 case MachOLinkingContext::arch_armv7:
453 case MachOLinkingContext::arch_armv7s:
Rui Ueyama170a1a82013-12-20 07:48:29 +0000454 addKindTable(Reference::KindNamespace::mach_o, Reference::KindArch::ARM,
Nick Kledzike5552772013-12-19 21:58:00 +0000455 mach_o::KindHandler_arm::kindStrings);
456 break;
457 default:
458 llvm_unreachable("mach-o arch not supported");
459 }
Nick Kledzik6edd7222014-01-11 01:07:43 +0000460 add(std::unique_ptr<YamlIOTaggedDocumentHandler>(
461 new mach_o::MachOYamlIOTaggedDocumentHandler()));
Nick Kledzike5552772013-12-19 21:58:00 +0000462}
463
Nick Kledzike34182f2013-11-06 21:36:55 +0000464} // namespace lld
465