blob: ad45bacefce070a32bdde22b3896c9a8cb74bdf5 [file] [log] [blame]
Nick Kledzike34182f2013-11-06 21:36:55 +00001//===- lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.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 Converts from in-memory Atoms to in-memory normalized mach-o.
12///
13/// +------------+
14/// | normalized |
15/// +------------+
16/// ^
17/// |
18/// |
Shankar Easwaran3d8de472014-01-27 03:09:26 +000019/// +-------+
Nick Kledzike34182f2013-11-06 21:36:55 +000020/// | Atoms |
Shankar Easwaran3d8de472014-01-27 03:09:26 +000021/// +-------+
Nick Kledzike34182f2013-11-06 21:36:55 +000022
23#include "MachONormalizedFile.h"
Nick Kledzikec140832014-06-10 01:50:00 +000024#include "MachONormalizedFileBinaryUtils.h"
Nick Kledzike34182f2013-11-06 21:36:55 +000025#include "ReferenceKinds.h"
Nick Kledzike34182f2013-11-06 21:36:55 +000026#include "lld/Core/Error.h"
27#include "lld/Core/LLVM.h"
Nick Kledzike34182f2013-11-06 21:36:55 +000028#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/StringSwitch.h"
30#include "llvm/Support/Casting.h"
31#include "llvm/Support/Debug.h"
32#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/Format.h"
34#include "llvm/Support/MachO.h"
Nick Kledzike34182f2013-11-06 21:36:55 +000035#include <map>
Rafael Espindola54427cc2014-06-12 17:15:58 +000036#include <system_error>
Nick Kledzike34182f2013-11-06 21:36:55 +000037
38using llvm::StringRef;
Nick Kledzike34182f2013-11-06 21:36:55 +000039using llvm::isa;
40using namespace llvm::MachO;
41using namespace lld::mach_o::normalized;
42using namespace lld;
43
44namespace {
45
46struct AtomInfo {
47 const DefinedAtom *atom;
48 uint64_t offsetInSection;
49};
50
51struct SectionInfo {
52 SectionInfo(StringRef seg, StringRef sect, SectionType type, uint32_t attr=0);
Shankar Easwaran3d8de472014-01-27 03:09:26 +000053
Nick Kledzike34182f2013-11-06 21:36:55 +000054 StringRef segmentName;
55 StringRef sectionName;
56 SectionType type;
57 uint32_t attributes;
58 uint64_t address;
59 uint64_t size;
60 uint32_t alignment;
61 std::vector<AtomInfo> atomsAndOffsets;
62 uint32_t normalizedSectionIndex;
63 uint32_t finalSectionIndex;
64};
65
Shankar Easwaran3d8de472014-01-27 03:09:26 +000066SectionInfo::SectionInfo(StringRef sg, StringRef sct, SectionType t, uint32_t a)
67 : segmentName(sg), sectionName(sct), type(t), attributes(a),
68 address(0), size(0), alignment(0),
Nick Kledzike34182f2013-11-06 21:36:55 +000069 normalizedSectionIndex(0), finalSectionIndex(0) {
70}
71
72struct SegmentInfo {
73 SegmentInfo(StringRef name);
Shankar Easwaran3d8de472014-01-27 03:09:26 +000074
Nick Kledzike34182f2013-11-06 21:36:55 +000075 StringRef name;
76 uint64_t address;
77 uint64_t size;
78 uint32_t access;
79 std::vector<SectionInfo*> sections;
80};
81
Shankar Easwaran3d8de472014-01-27 03:09:26 +000082SegmentInfo::SegmentInfo(StringRef n)
Nick Kledzike34182f2013-11-06 21:36:55 +000083 : name(n), address(0), size(0), access(0) {
84}
85
86
87class Util {
88public:
89 Util(const MachOLinkingContext &ctxt) : _context(ctxt), _entryAtom(nullptr) {}
90
91 void assignAtomsToSections(const lld::File &atomFile);
92 void organizeSections();
93 void assignAddressesToSections();
94 uint32_t fileFlags();
95 void copySegmentInfo(NormalizedFile &file);
96 void copySections(NormalizedFile &file);
97 void buildAtomToAddressMap();
98 void addSymbols(const lld::File &atomFile, NormalizedFile &file);
99 void addIndirectSymbols(const lld::File &atomFile, NormalizedFile &file);
100 void addRebaseAndBindingInfo(const lld::File &, NormalizedFile &file);
101 void addSectionRelocs(const lld::File &, NormalizedFile &file);
102 void addDependentDylibs(const lld::File &, NormalizedFile &file);
103 void copyEntryPointAddress(NormalizedFile &file);
104
105private:
106 typedef std::map<DefinedAtom::ContentType, SectionInfo*> TypeToSection;
107 typedef llvm::DenseMap<const Atom*, uint64_t> AtomToAddress;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000108
Nick Kledzike34182f2013-11-06 21:36:55 +0000109 struct DylibInfo { int ordinal; bool hasWeak; bool hasNonWeak; };
110 typedef llvm::StringMap<DylibInfo> DylibPathToInfo;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000111
Nick Kledzike34182f2013-11-06 21:36:55 +0000112 SectionInfo *sectionForAtom(const DefinedAtom*);
Nick Kledzik936d5202014-06-11 01:30:55 +0000113 SectionInfo *getRelocatableSection(DefinedAtom::ContentType type);
114 SectionInfo *getFinalSection(DefinedAtom::ContentType type);
Nick Kledzike34182f2013-11-06 21:36:55 +0000115 void appendAtom(SectionInfo *sect, const DefinedAtom *atom);
116 SegmentInfo *segmentForName(StringRef segName);
117 void layoutSectionsInSegment(SegmentInfo *seg, uint64_t &addr);
118 void layoutSectionsInTextSegment(SegmentInfo *seg, uint64_t &addr);
119 void copySectionContent(SectionInfo *si, ContentBytes &content);
120 uint8_t scopeBits(const DefinedAtom* atom);
Nick Kledzik60855392014-06-11 00:24:16 +0000121 uint16_t descBits(const DefinedAtom* atom);
Nick Kledzike34182f2013-11-06 21:36:55 +0000122 int dylibOrdinal(const SharedLibraryAtom *sa);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000123 void segIndexForSection(const SectionInfo *sect,
Nick Kledzike34182f2013-11-06 21:36:55 +0000124 uint8_t &segmentIndex, uint64_t &segmentStartAddr);
125 const Atom *targetOfLazyPointer(const DefinedAtom *lpAtom);
126 const Atom *targetOfStub(const DefinedAtom *stubAtom);
127 bool belongsInGlobalSymbolsSection(const DefinedAtom* atom);
128 void appendSection(SectionInfo *si, NormalizedFile &file);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000129 void appendReloc(const DefinedAtom *atom, const Reference *ref,
Nick Kledzike34182f2013-11-06 21:36:55 +0000130 Relocations &relocations);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000131
Nick Kledzike34182f2013-11-06 21:36:55 +0000132 static uint64_t alignTo(uint64_t value, uint8_t align2);
133 typedef llvm::DenseMap<const Atom*, uint32_t> AtomToIndex;
134 struct AtomAndIndex { const Atom *atom; uint32_t index; };
Joey Gouly9d263e02013-12-25 19:39:08 +0000135 struct AtomSorter {
136 bool operator()(const AtomAndIndex &left, const AtomAndIndex &right);
Nick Kledzike34182f2013-11-06 21:36:55 +0000137 };
Joey Gouly9d263e02013-12-25 19:39:08 +0000138 struct SegmentSorter {
139 bool operator()(const SegmentInfo *left, const SegmentInfo *right);
Nick Kledzike34182f2013-11-06 21:36:55 +0000140 static unsigned weight(const SegmentInfo *);
141 };
Joey Gouly9d263e02013-12-25 19:39:08 +0000142 struct TextSectionSorter {
143 bool operator()(const SectionInfo *left, const SectionInfo *right);
Nick Kledzike34182f2013-11-06 21:36:55 +0000144 static unsigned weight(const SectionInfo *);
145 };
146
147 const MachOLinkingContext &_context;
148 llvm::BumpPtrAllocator _allocator;
149 std::vector<SectionInfo*> _sectionInfos;
150 std::vector<SegmentInfo*> _segmentInfos;
151 TypeToSection _sectionMap;
Nick Kledzikacfad802014-05-30 22:51:04 +0000152 std::vector<SectionInfo*> _customSections;
Nick Kledzike34182f2013-11-06 21:36:55 +0000153 AtomToAddress _atomToAddress;
154 DylibPathToInfo _dylibInfo;
155 const DefinedAtom *_entryAtom;
156 AtomToIndex _atomToSymbolIndex;
157};
158
Nick Kledzikec140832014-06-10 01:50:00 +0000159
Nick Kledzik936d5202014-06-11 01:30:55 +0000160SectionInfo *Util::getRelocatableSection(DefinedAtom::ContentType type) {
Nick Kledzikec140832014-06-10 01:50:00 +0000161 StringRef segmentName;
162 StringRef sectionName;
163 SectionType sectionType;
164 SectionAttr sectionAttrs;
165
166 // Use same table used by when parsing .o files.
167 relocatableSectionInfoForContentType(type, segmentName, sectionName,
168 sectionType, sectionAttrs);
169 // If we already have a SectionInfo with this name, re-use it.
170 // This can happen if two ContentType map to the same mach-o section.
171 for (auto sect : _sectionMap) {
172 if (sect.second->sectionName.equals(sectionName) &&
173 sect.second->segmentName.equals(segmentName)) {
174 return sect.second;
175 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000176 }
Nick Kledzikec140832014-06-10 01:50:00 +0000177 // Otherwise allocate new SectionInfo object.
Nick Kledzik936d5202014-06-11 01:30:55 +0000178 SectionInfo *sect = new (_allocator) SectionInfo(segmentName, sectionName,
179 sectionType, sectionAttrs);
180 _sectionInfos.push_back(sect);
181 _sectionMap[type] = sect;
182 return sect;
Nick Kledzikec140832014-06-10 01:50:00 +0000183}
184
185#define ENTRY(seg, sect, type, atomType) \
186 {seg, sect, type, DefinedAtom::atomType }
187
188struct MachOFinalSectionFromAtomType {
189 StringRef segmentName;
190 StringRef sectionName;
191 SectionType sectionType;
192 DefinedAtom::ContentType atomType;
193};
194
195const MachOFinalSectionFromAtomType sectsToAtomType[] = {
196 ENTRY("__TEXT", "__text", S_REGULAR, typeCode),
197 ENTRY("__TEXT", "__cstring", S_CSTRING_LITERALS, typeCString),
198 ENTRY("__TEXT", "__ustring", S_REGULAR, typeUTF16String),
199 ENTRY("__TEXT", "__const", S_REGULAR, typeConstant),
200 ENTRY("__TEXT", "__const", S_4BYTE_LITERALS, typeLiteral4),
201 ENTRY("__TEXT", "__const", S_8BYTE_LITERALS, typeLiteral8),
202 ENTRY("__TEXT", "__const", S_16BYTE_LITERALS, typeLiteral16),
203 ENTRY("__TEXT", "__stubs", S_SYMBOL_STUBS, typeStub),
204 ENTRY("__TEXT", "__stub_helper", S_REGULAR, typeStubHelper),
205 ENTRY("__TEXT", "__gcc_except_tab", S_REGULAR, typeLSDA),
206 ENTRY("__TEXT", "__eh_frame", S_COALESCED, typeCFI),
207 ENTRY("__DATA", "__data", S_REGULAR, typeData),
208 ENTRY("__DATA", "__const", S_REGULAR, typeConstData),
209 ENTRY("__DATA", "__cfstring", S_REGULAR, typeCFString),
210 ENTRY("__DATA", "__la_symbol_ptr", S_LAZY_SYMBOL_POINTERS,
211 typeLazyPointer),
212 ENTRY("__DATA", "__mod_init_func", S_MOD_INIT_FUNC_POINTERS,
213 typeInitializerPtr),
214 ENTRY("__DATA", "__mod_term_func", S_MOD_TERM_FUNC_POINTERS,
215 typeTerminatorPtr),
216 ENTRY("__DATA", "___got", S_NON_LAZY_SYMBOL_POINTERS,
217 typeGOT),
218 ENTRY("__DATA", "___bss", S_ZEROFILL, typeZeroFill)
219};
220#undef ENTRY
221
222
Nick Kledzik936d5202014-06-11 01:30:55 +0000223SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) {
Nick Kledzikec140832014-06-10 01:50:00 +0000224 for (const MachOFinalSectionFromAtomType *p = sectsToAtomType ;
225 p->atomType != DefinedAtom::typeUnknown; ++p) {
226 if (p->atomType != atomType)
227 continue;
228 SectionAttr sectionAttrs = 0;
229 switch (atomType) {
230 case DefinedAtom::typeCode:
231 case DefinedAtom::typeStub:
232 sectionAttrs = S_ATTR_PURE_INSTRUCTIONS;
233 break;
234 default:
235 break;
236 }
237 // If we already have a SectionInfo with this name, re-use it.
238 // This can happen if two ContentType map to the same mach-o section.
239 for (auto sect : _sectionMap) {
240 if (sect.second->sectionName.equals(p->sectionName) &&
241 sect.second->segmentName.equals(p->segmentName)) {
242 return sect.second;
243 }
244 }
245 // Otherwise allocate new SectionInfo object.
Nick Kledzik936d5202014-06-11 01:30:55 +0000246 SectionInfo *sect = new (_allocator) SectionInfo(p->segmentName,
247 p->sectionName,
248 p->sectionType,
249 sectionAttrs);
250 _sectionInfos.push_back(sect);
251 _sectionMap[atomType] = sect;
252 return sect;
Nick Kledzikec140832014-06-10 01:50:00 +0000253 }
254 llvm_unreachable("content type not yet supported");
Nick Kledzike34182f2013-11-06 21:36:55 +0000255}
256
257
258
259SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) {
Nick Kledzikacfad802014-05-30 22:51:04 +0000260 if (atom->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
261 // Section for this atom is derived from content type.
262 DefinedAtom::ContentType type = atom->contentType();
263 auto pos = _sectionMap.find(type);
264 if ( pos != _sectionMap.end() )
265 return pos->second;
Tim Northoverd30a1f22014-06-20 15:59:00 +0000266 bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT);
Nick Kledzik936d5202014-06-11 01:30:55 +0000267 return rMode ? getRelocatableSection(type) : getFinalSection(type);
Nick Kledzikacfad802014-05-30 22:51:04 +0000268 } else {
269 // This atom needs to be in a custom section.
270 StringRef customName = atom->customSectionName();
271 // Look to see if we have already allocated the needed custom section.
272 for(SectionInfo *sect : _customSections) {
273 const DefinedAtom *firstAtom = sect->atomsAndOffsets.front().atom;
274 if (firstAtom->customSectionName().equals(customName)) {
275 return sect;
276 }
277 }
278 // Not found, so need to create a new custom section.
279 size_t seperatorIndex = customName.find('/');
280 assert(seperatorIndex != StringRef::npos);
Tim Northover7b0a1302014-06-30 09:49:33 +0000281 StringRef segName = customName.slice(0, seperatorIndex);
282 StringRef sectName = customName.drop_front(seperatorIndex + 1);
Nick Kledzikacfad802014-05-30 22:51:04 +0000283 SectionInfo *sect = new (_allocator) SectionInfo(segName, sectName,
284 S_REGULAR);
285 _customSections.push_back(sect);
Tim Northover7b0a1302014-06-30 09:49:33 +0000286 _sectionInfos.push_back(sect);
Nick Kledzikacfad802014-05-30 22:51:04 +0000287 return sect;
288 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000289}
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000290
Nick Kledzike34182f2013-11-06 21:36:55 +0000291
292void Util::appendAtom(SectionInfo *sect, const DefinedAtom *atom) {
293 // Figure out offset for atom in this section given alignment constraints.
294 uint64_t offset = sect->size;
295 DefinedAtom::Alignment atomAlign = atom->alignment();
296 uint64_t align2 = 1 << atomAlign.powerOf2;
297 uint64_t requiredModulus = atomAlign.modulus;
298 uint64_t currentModulus = (offset % align2);
299 if ( currentModulus != requiredModulus ) {
300 if ( requiredModulus > currentModulus )
301 offset += requiredModulus-currentModulus;
302 else
303 offset += align2+requiredModulus-currentModulus;
304 }
305 // Record max alignment of any atom in this section.
306 if ( atomAlign.powerOf2 > sect->alignment )
307 sect->alignment = atomAlign.powerOf2;
308 // Assign atom to this section with this offset.
309 AtomInfo ai = {atom, offset};
310 sect->atomsAndOffsets.push_back(ai);
311 // Update section size to include this atom.
312 sect->size = offset + atom->size();
313}
314
315void Util::assignAtomsToSections(const lld::File &atomFile) {
316 for (const DefinedAtom *atom : atomFile.defined()) {
317 appendAtom(sectionForAtom(atom), atom);
318 }
319}
320
321SegmentInfo *Util::segmentForName(StringRef segName) {
322 for (SegmentInfo *si : _segmentInfos) {
323 if ( si->name.equals(segName) )
324 return si;
325 }
326 SegmentInfo *info = new (_allocator) SegmentInfo(segName);
327 if (segName.equals("__TEXT"))
328 info->access = VM_PROT_READ | VM_PROT_EXECUTE;
329 else if (segName.equals("__DATA"))
330 info->access = VM_PROT_READ | VM_PROT_WRITE;
331 else if (segName.equals("__PAGEZERO"))
332 info->access = 0;
333 _segmentInfos.push_back(info);
334 return info;
335}
336
337unsigned Util::SegmentSorter::weight(const SegmentInfo *seg) {
338 return llvm::StringSwitch<unsigned>(seg->name)
339 .Case("__PAGEZERO", 1)
340 .Case("__TEXT", 2)
341 .Case("__DATA", 3)
342 .Default(100);
343}
344
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000345bool Util::SegmentSorter::operator()(const SegmentInfo *left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000346 const SegmentInfo *right) {
347 return (weight(left) < weight(right));
348}
349
350unsigned Util::TextSectionSorter::weight(const SectionInfo *sect) {
351 return llvm::StringSwitch<unsigned>(sect->sectionName)
352 .Case("__text", 1)
353 .Case("__stubs", 2)
354 .Case("__stub_helper", 3)
355 .Case("__const", 4)
356 .Case("__cstring", 5)
357 .Case("__unwind_info", 98)
358 .Case("__eh_frame", 99)
359 .Default(10);
360}
361
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000362bool Util::TextSectionSorter::operator()(const SectionInfo *left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000363 const SectionInfo *right) {
364 return (weight(left) < weight(right));
365}
366
367
368void Util::organizeSections() {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000369 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000370 // Leave sections ordered as normalized file specified.
371 uint32_t sectionIndex = 1;
372 for (SectionInfo *si : _sectionInfos) {
373 si->finalSectionIndex = sectionIndex++;
374 }
375 } else {
376 // Main executables, need a zero-page segment
Tim Northoverd30a1f22014-06-20 15:59:00 +0000377 if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE)
Nick Kledzike34182f2013-11-06 21:36:55 +0000378 segmentForName("__PAGEZERO");
379 // Group sections into segments.
380 for (SectionInfo *si : _sectionInfos) {
381 SegmentInfo *seg = segmentForName(si->segmentName);
382 seg->sections.push_back(si);
383 }
384 // Sort segments.
385 std::sort(_segmentInfos.begin(), _segmentInfos.end(), SegmentSorter());
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000386
Nick Kledzike34182f2013-11-06 21:36:55 +0000387 // Sort sections within segments.
388 for (SegmentInfo *seg : _segmentInfos) {
389 if (seg->name.equals("__TEXT")) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000390 std::sort(seg->sections.begin(), seg->sections.end(),
Nick Kledzike34182f2013-11-06 21:36:55 +0000391 TextSectionSorter());
392 }
393 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000394
Nick Kledzike34182f2013-11-06 21:36:55 +0000395 // Record final section indexes.
396 uint32_t sectionIndex = 1;
397 for (SegmentInfo *seg : _segmentInfos) {
398 for (SectionInfo *sect : seg->sections) {
399 sect->finalSectionIndex = sectionIndex++;
400 }
401 }
402 }
403
404}
405
406uint64_t Util::alignTo(uint64_t value, uint8_t align2) {
407 return llvm::RoundUpToAlignment(value, 1 << align2);
408}
409
410
411void Util::layoutSectionsInSegment(SegmentInfo *seg, uint64_t &addr) {
412 seg->address = addr;
413 for (SectionInfo *sect : seg->sections) {
414 sect->address = alignTo(addr, sect->alignment);
415 addr += sect->size;
416 }
417 seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize());
418}
419
420
421// __TEXT segment lays out backwards so padding is at front after load commands.
422void Util::layoutSectionsInTextSegment(SegmentInfo *seg, uint64_t &addr) {
423 seg->address = addr;
424 // Walks sections starting at end to calculate padding for start.
425 int64_t taddr = 0;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000426 for (auto it = seg->sections.rbegin(); it != seg->sections.rend(); ++it) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000427 SectionInfo *sect = *it;
428 taddr -= sect->size;
429 taddr = taddr & (0 - (1 << sect->alignment));
430 }
431 int64_t padding = taddr;
432 while (padding < 0)
433 padding += _context.pageSize();
434 // Start assigning section address starting at padded offset.
435 addr += padding;
436 for (SectionInfo *sect : seg->sections) {
437 sect->address = alignTo(addr, sect->alignment);
438 addr = sect->address + sect->size;
439 }
440 seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize());
441}
442
443
444void Util::assignAddressesToSections() {
445 uint64_t address = 0; // FIXME
Tim Northoverd30a1f22014-06-20 15:59:00 +0000446 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000447 for (SegmentInfo *seg : _segmentInfos) {
448 if (seg->name.equals("__PAGEZERO")) {
449 seg->size = _context.pageZeroSize();
450 address += seg->size;
451 }
452 else if (seg->name.equals("__TEXT"))
453 layoutSectionsInTextSegment(seg, address);
454 else
455 layoutSectionsInSegment(seg, address);
Tim Northover7b0a1302014-06-30 09:49:33 +0000456
457 address = llvm::RoundUpToAlignment(address, _context.pageSize());
Nick Kledzike34182f2013-11-06 21:36:55 +0000458 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000459 DEBUG_WITH_TYPE("WriterMachO-norm",
Nick Kledzik020a49c2013-11-06 21:57:52 +0000460 llvm::dbgs() << "assignAddressesToSections()\n";
461 for (SegmentInfo *sgi : _segmentInfos) {
462 llvm::dbgs() << " address=" << llvm::format("0x%08llX", sgi->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000463 << ", size=" << llvm::format("0x%08llX", sgi->size)
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000464 << ", segment-name='" << sgi->name
Nick Kledzik020a49c2013-11-06 21:57:52 +0000465 << "'\n";
466 for (SectionInfo *si : sgi->sections) {
467 llvm::dbgs()<< " addr=" << llvm::format("0x%08llX", si->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000468 << ", size=" << llvm::format("0x%08llX", si->size)
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000469 << ", section-name='" << si->sectionName
Nick Kledzik020a49c2013-11-06 21:57:52 +0000470 << "\n";
471 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000472 }
Nick Kledzik020a49c2013-11-06 21:57:52 +0000473 );
Nick Kledzike34182f2013-11-06 21:36:55 +0000474 } else {
475 for (SectionInfo *sect : _sectionInfos) {
476 sect->address = alignTo(address, sect->alignment);
477 address = sect->address + sect->size;
478 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000479 DEBUG_WITH_TYPE("WriterMachO-norm",
Nick Kledzik020a49c2013-11-06 21:57:52 +0000480 llvm::dbgs() << "assignAddressesToSections()\n";
481 for (SectionInfo *si : _sectionInfos) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000482 llvm::dbgs() << " section=" << si->sectionName
Nick Kledzike34182f2013-11-06 21:36:55 +0000483 << " address= " << llvm::format("0x%08X", si->address)
484 << " size= " << llvm::format("0x%08X", si->size)
Nick Kledzik020a49c2013-11-06 21:57:52 +0000485 << "\n";
486 }
487 );
Nick Kledzike34182f2013-11-06 21:36:55 +0000488 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000489}
490
491
492void Util::copySegmentInfo(NormalizedFile &file) {
493 for (SegmentInfo *sgi : _segmentInfos) {
494 Segment seg;
495 seg.name = sgi->name;
496 seg.address = sgi->address;
497 seg.size = sgi->size;
498 seg.access = sgi->access;
499 file.segments.push_back(seg);
500 }
501}
502
503void Util::appendSection(SectionInfo *si, NormalizedFile &file) {
Nick Kledzik3f690762014-06-27 18:25:01 +0000504 const bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT);
Nick Kledzike34182f2013-11-06 21:36:55 +0000505 // Add new empty section to end of file.sections.
506 Section temp;
507 file.sections.push_back(std::move(temp));
508 Section* normSect = &file.sections.back();
509 // Copy fields to normalized section.
510 normSect->segmentName = si->segmentName;
511 normSect->sectionName = si->sectionName;
512 normSect->type = si->type;
513 normSect->attributes = si->attributes;
514 normSect->address = si->address;
515 normSect->alignment = si->alignment;
516 // Record where normalized section is.
517 si->normalizedSectionIndex = file.sections.size()-1;
518 // Copy content from atoms to content buffer for section.
Nick Kledzik61fdef62014-05-15 20:59:23 +0000519 if (si->type == llvm::MachO::S_ZEROFILL)
520 return;
Nick Kledzik6edd7222014-01-11 01:07:43 +0000521 uint8_t *sectionContent = file.ownedAllocations.Allocate<uint8_t>(si->size);
522 normSect->content = llvm::makeArrayRef(sectionContent, si->size);
Nick Kledzike34182f2013-11-06 21:36:55 +0000523 for (AtomInfo &ai : si->atomsAndOffsets) {
524 // Copy raw bytes.
525 uint8_t *atomContent = reinterpret_cast<uint8_t*>
526 (&sectionContent[ai.offsetInSection]);
527 memcpy(atomContent, ai.atom->rawContent().data(), ai.atom->size());
528 // Apply fix-ups.
529 for (const Reference *ref : *ai.atom) {
530 uint32_t offset = ref->offsetInAtom();
531 uint64_t targetAddress = 0;
532 if ( ref->target() != nullptr )
533 targetAddress = _atomToAddress[ref->target()];
534 uint64_t fixupAddress = _atomToAddress[ai.atom] + offset;
Nick Kledzik3f690762014-06-27 18:25:01 +0000535 if ( rMode ) {
536 // FIXME: Need a handler method to update content for .o file
537 // output and any needed section relocations.
538 } else {
539 _context.kindHandler().applyFixup(
Rui Ueyama170a1a82013-12-20 07:48:29 +0000540 ref->kindNamespace(), ref->kindArch(), ref->kindValue(),
541 ref->addend(), &atomContent[offset], fixupAddress, targetAddress);
Nick Kledzik3f690762014-06-27 18:25:01 +0000542 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000543 }
544 }
545}
546
547void Util::copySections(NormalizedFile &file) {
548 file.sections.reserve(_sectionInfos.size());
549 // For final linked images, write sections grouped by segment.
Tim Northoverd30a1f22014-06-20 15:59:00 +0000550 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000551 for (SegmentInfo *sgi : _segmentInfos) {
552 for (SectionInfo *si : sgi->sections) {
553 appendSection(si, file);
554 }
555 }
556 } else {
557 // Object files write sections in default order.
558 for (SectionInfo *si : _sectionInfos) {
559 appendSection(si, file);
560 }
561 }
562}
563
564void Util::copyEntryPointAddress(NormalizedFile &nFile) {
565 if (_context.outputTypeHasEntry()) {
566 nFile.entryAddress = _atomToAddress[_entryAtom];
567 }
568}
569
570void Util::buildAtomToAddressMap() {
571 DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs()
572 << "assign atom addresses:\n");
573 const bool lookForEntry = _context.outputTypeHasEntry();
574 for (SectionInfo *sect : _sectionInfos) {
575 for (const AtomInfo &info : sect->atomsAndOffsets) {
576 _atomToAddress[info.atom] = sect->address + info.offsetInSection;
577 if (lookForEntry && (info.atom->contentType() == DefinedAtom::typeCode) &&
578 (info.atom->size() != 0) &&
579 info.atom->name() == _context.entrySymbolName()) {
580 _entryAtom = info.atom;
581 }
582 DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs()
583 << " address="
584 << llvm::format("0x%016X", _atomToAddress[info.atom])
585 << " atom=" << info.atom
586 << " name=" << info.atom->name() << "\n");
587 }
588 }
589}
590
591uint8_t Util::scopeBits(const DefinedAtom* atom) {
592 switch (atom->scope()) {
593 case Atom::scopeTranslationUnit:
594 return 0;
595 case Atom::scopeLinkageUnit:
596 return N_PEXT | N_EXT;
597 case Atom::scopeGlobal:
598 return N_EXT;
599 }
Nick Kledzik020fa7f2013-11-06 22:18:09 +0000600 llvm_unreachable("Unknown scope");
Nick Kledzike34182f2013-11-06 21:36:55 +0000601}
602
Nick Kledzik60855392014-06-11 00:24:16 +0000603uint16_t Util::descBits(const DefinedAtom* atom) {
604 uint16_t desc = 0;
605 switch (atom->merge()) {
606 case lld::DefinedAtom::mergeNo:
607 case lld::DefinedAtom::mergeAsTentative:
608 break;
609 case lld::DefinedAtom::mergeAsWeak:
610 case lld::DefinedAtom::mergeAsWeakAndAddressUsed:
611 desc |= N_WEAK_DEF;
612 break;
613 case lld::DefinedAtom::mergeSameNameAndSize:
614 case lld::DefinedAtom::mergeByLargestSection:
615 case lld::DefinedAtom::mergeByContent:
616 llvm_unreachable("Unsupported DefinedAtom::merge()");
617 break;
618 }
619 if (atom->contentType() == lld::DefinedAtom::typeResolver)
620 desc |= N_SYMBOL_RESOLVER;
621 return desc;
622}
623
624
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000625bool Util::AtomSorter::operator()(const AtomAndIndex &left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000626 const AtomAndIndex &right) {
627 return (left.atom->name().compare(right.atom->name()) < 0);
628}
629
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000630
Nick Kledzike34182f2013-11-06 21:36:55 +0000631bool Util::belongsInGlobalSymbolsSection(const DefinedAtom* atom) {
Nick Kledzik936d5202014-06-11 01:30:55 +0000632 // ScopeLinkageUnit symbols are in globals area of symbol table
633 // in object files, but in locals area for final linked images.
Tim Northoverd30a1f22014-06-20 15:59:00 +0000634 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT)
Nick Kledzik936d5202014-06-11 01:30:55 +0000635 return (atom->scope() != Atom::scopeTranslationUnit);
636 else
637 return (atom->scope() == Atom::scopeGlobal);
Nick Kledzike34182f2013-11-06 21:36:55 +0000638}
639
640void Util::addSymbols(const lld::File &atomFile, NormalizedFile &file) {
641 // Mach-O symbol table has three regions: locals, globals, undefs.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000642
Nick Kledzike34182f2013-11-06 21:36:55 +0000643 // Add all local (non-global) symbols in address order
644 std::vector<AtomAndIndex> globals;
645 globals.reserve(512);
646 for (SectionInfo *sect : _sectionInfos) {
647 for (const AtomInfo &info : sect->atomsAndOffsets) {
648 const DefinedAtom *atom = info.atom;
649 if (!atom->name().empty()) {
650 if (belongsInGlobalSymbolsSection(atom)) {
651 AtomAndIndex ai = { atom, sect->finalSectionIndex };
652 globals.push_back(ai);
653 } else {
654 Symbol sym;
655 sym.name = atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000656 sym.type = N_SECT;
Nick Kledzike34182f2013-11-06 21:36:55 +0000657 sym.scope = scopeBits(atom);
658 sym.sect = sect->finalSectionIndex;
659 sym.desc = 0;
660 sym.value = _atomToAddress[atom];
661 file.localSymbols.push_back(sym);
662 }
663 }
664 }
665 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000666
Nick Kledzike34182f2013-11-06 21:36:55 +0000667 // Sort global symbol alphabetically, then add to symbol table.
668 std::sort(globals.begin(), globals.end(), AtomSorter());
669 for (AtomAndIndex &ai : globals) {
670 Symbol sym;
671 sym.name = ai.atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000672 sym.type = N_SECT;
Nick Kledzike34182f2013-11-06 21:36:55 +0000673 sym.scope = scopeBits(static_cast<const DefinedAtom*>(ai.atom));
674 sym.sect = ai.index;
Nick Kledzik60855392014-06-11 00:24:16 +0000675 sym.desc = descBits(static_cast<const DefinedAtom*>(ai.atom));
Nick Kledzike34182f2013-11-06 21:36:55 +0000676 sym.value = _atomToAddress[ai.atom];
677 file.globalSymbols.push_back(sym);
678 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000679
680
Nick Kledzike34182f2013-11-06 21:36:55 +0000681 // Sort undefined symbol alphabetically, then add to symbol table.
682 std::vector<AtomAndIndex> undefs;
683 undefs.reserve(128);
684 for (const UndefinedAtom *atom : atomFile.undefined()) {
685 AtomAndIndex ai = { atom, 0 };
686 undefs.push_back(ai);
687 }
688 for (const SharedLibraryAtom *atom : atomFile.sharedLibrary()) {
689 AtomAndIndex ai = { atom, 0 };
690 undefs.push_back(ai);
691 }
692 std::sort(undefs.begin(), undefs.end(), AtomSorter());
693 const uint32_t start = file.globalSymbols.size() + file.localSymbols.size();
694 for (AtomAndIndex &ai : undefs) {
695 Symbol sym;
696 sym.name = ai.atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000697 sym.type = N_UNDF;
Nick Kledzike34182f2013-11-06 21:36:55 +0000698 sym.scope = N_EXT;
699 sym.sect = 0;
700 sym.desc = 0;
701 sym.value = 0;
702 _atomToSymbolIndex[ai.atom] = file.undefinedSymbols.size() + start;
703 file.undefinedSymbols.push_back(sym);
704 }
705}
706
707const Atom *Util::targetOfLazyPointer(const DefinedAtom *lpAtom) {
708 for (const Reference *ref : *lpAtom) {
Nick Kledzike5552772013-12-19 21:58:00 +0000709 if (_context.kindHandler().isLazyTarget(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000710 return ref->target();
711 }
712 }
713 return nullptr;
714}
715
716const Atom *Util::targetOfStub(const DefinedAtom *stubAtom) {
717 for (const Reference *ref : *stubAtom) {
718 if (const Atom *ta = ref->target()) {
719 if (const DefinedAtom *lpAtom = dyn_cast<DefinedAtom>(ta)) {
720 const Atom *target = targetOfLazyPointer(lpAtom);
721 if (target)
722 return target;
723 }
724 }
725 }
726 return nullptr;
727}
728
729
730void Util::addIndirectSymbols(const lld::File &atomFile, NormalizedFile &file) {
731 for (SectionInfo *si : _sectionInfos) {
732 Section &normSect = file.sections[si->normalizedSectionIndex];
733 switch (si->type) {
734 case llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS:
735 for (const AtomInfo &info : si->atomsAndOffsets) {
736 bool foundTarget = false;
737 for (const Reference *ref : *info.atom) {
738 const Atom *target = ref->target();
739 if (target) {
740 if (isa<const SharedLibraryAtom>(target)) {
741 uint32_t index = _atomToSymbolIndex[target];
742 normSect.indirectSymbols.push_back(index);
743 foundTarget = true;
744 } else {
745 normSect.indirectSymbols.push_back(
746 llvm::MachO::INDIRECT_SYMBOL_LOCAL);
747 }
748 }
749 }
750 if (!foundTarget) {
751 normSect.indirectSymbols.push_back(
752 llvm::MachO::INDIRECT_SYMBOL_ABS);
753 }
754 }
755 break;
756 case llvm::MachO::S_LAZY_SYMBOL_POINTERS:
757 for (const AtomInfo &info : si->atomsAndOffsets) {
758 const Atom *target = targetOfLazyPointer(info.atom);
759 if (target) {
760 uint32_t index = _atomToSymbolIndex[target];
761 normSect.indirectSymbols.push_back(index);
762 }
763 }
764 break;
765 case llvm::MachO::S_SYMBOL_STUBS:
766 for (const AtomInfo &info : si->atomsAndOffsets) {
767 const Atom *target = targetOfStub(info.atom);
768 if (target) {
769 uint32_t index = _atomToSymbolIndex[target];
770 normSect.indirectSymbols.push_back(index);
771 }
772 }
773 break;
774 default:
775 break;
776 }
777 }
778
779}
780
781void Util::addDependentDylibs(const lld::File &atomFile,NormalizedFile &nFile) {
782 // Scan all imported symbols and build up list of dylibs they are from.
783 int ordinal = 1;
784 for (const SharedLibraryAtom *slAtom : atomFile.sharedLibrary()) {
785 StringRef loadPath = slAtom->loadName();
786 DylibPathToInfo::iterator pos = _dylibInfo.find(loadPath);
787 if (pos == _dylibInfo.end()) {
788 DylibInfo info;
789 info.ordinal = ordinal++;
790 info.hasWeak = slAtom->canBeNullAtRuntime();
791 info.hasNonWeak = !info.hasWeak;
792 _dylibInfo[loadPath] = info;
793 DependentDylib depInfo;
794 depInfo.path = loadPath;
795 depInfo.kind = llvm::MachO::LC_LOAD_DYLIB;
796 nFile.dependentDylibs.push_back(depInfo);
797 } else {
798 if ( slAtom->canBeNullAtRuntime() )
799 pos->second.hasWeak = true;
800 else
801 pos->second.hasNonWeak = true;
802 }
803 }
804 // Automatically weak link dylib in which all symbols are weak (canBeNull).
805 for (DependentDylib &dep : nFile.dependentDylibs) {
806 DylibInfo &info = _dylibInfo[dep.path];
807 if (info.hasWeak && !info.hasNonWeak)
808 dep.kind = llvm::MachO::LC_LOAD_WEAK_DYLIB;
809 }
810}
811
812
813int Util::dylibOrdinal(const SharedLibraryAtom *sa) {
814 return _dylibInfo[sa->loadName()].ordinal;
815}
816
817void Util::segIndexForSection(const SectionInfo *sect, uint8_t &segmentIndex,
818 uint64_t &segmentStartAddr) {
819 segmentIndex = 0;
820 for (const SegmentInfo *seg : _segmentInfos) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000821 if ((seg->address <= sect->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000822 && (seg->address+seg->size >= sect->address+sect->size)) {
823 segmentStartAddr = seg->address;
824 return;
825 }
826 ++segmentIndex;
827 }
828 llvm_unreachable("section not in any segment");
829}
830
831
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000832void Util::appendReloc(const DefinedAtom *atom, const Reference *ref,
Nick Kledzike34182f2013-11-06 21:36:55 +0000833 Relocations &relocations) {
834 // TODO: convert Reference to normalized relocation
835}
836
837void Util::addSectionRelocs(const lld::File &, NormalizedFile &file) {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000838 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT)
Nick Kledzike34182f2013-11-06 21:36:55 +0000839 return;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000840
Nick Kledzike34182f2013-11-06 21:36:55 +0000841 for (SectionInfo *si : _sectionInfos) {
842 Section &normSect = file.sections[si->normalizedSectionIndex];
843 for (const AtomInfo &info : si->atomsAndOffsets) {
844 const DefinedAtom *atom = info.atom;
845 for (const Reference *ref : *atom) {
846 appendReloc(atom, ref, normSect.relocations);
847 }
848 }
849 }
850}
851
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000852void Util::addRebaseAndBindingInfo(const lld::File &atomFile,
Nick Kledzike34182f2013-11-06 21:36:55 +0000853 NormalizedFile &nFile) {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000854 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT)
Nick Kledzike34182f2013-11-06 21:36:55 +0000855 return;
856
857 uint8_t segmentIndex;
858 uint64_t segmentStartAddr;
859 for (SectionInfo *sect : _sectionInfos) {
860 segIndexForSection(sect, segmentIndex, segmentStartAddr);
861 for (const AtomInfo &info : sect->atomsAndOffsets) {
862 const DefinedAtom *atom = info.atom;
863 for (const Reference *ref : *atom) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000864 uint64_t segmentOffset = _atomToAddress[atom] + ref->offsetInAtom()
Nick Kledzike34182f2013-11-06 21:36:55 +0000865 - segmentStartAddr;
866 const Atom* targ = ref->target();
Nick Kledzike5552772013-12-19 21:58:00 +0000867 if (_context.kindHandler().isPointer(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000868 // A pointer to a DefinedAtom requires rebasing.
869 if (dyn_cast<DefinedAtom>(targ)) {
870 RebaseLocation rebase;
871 rebase.segIndex = segmentIndex;
872 rebase.segOffset = segmentOffset;
873 rebase.kind = llvm::MachO::REBASE_TYPE_POINTER;
874 nFile.rebasingInfo.push_back(rebase);
875 }
876 // A pointer to an SharedLibraryAtom requires binding.
877 if (const SharedLibraryAtom *sa = dyn_cast<SharedLibraryAtom>(targ)) {
878 BindLocation bind;
879 bind.segIndex = segmentIndex;
880 bind.segOffset = segmentOffset;
881 bind.kind = llvm::MachO::BIND_TYPE_POINTER;
882 bind.canBeNull = sa->canBeNullAtRuntime();
883 bind.ordinal = dylibOrdinal(sa);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000884 bind.symbolName = targ->name();
Nick Kledzike34182f2013-11-06 21:36:55 +0000885 bind.addend = ref->addend();
886 nFile.bindingInfo.push_back(bind);
887 }
888 }
Nick Kledzike5552772013-12-19 21:58:00 +0000889 if (_context.kindHandler().isLazyTarget(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000890 BindLocation bind;
891 bind.segIndex = segmentIndex;
892 bind.segOffset = segmentOffset;
893 bind.kind = llvm::MachO::BIND_TYPE_POINTER;
894 bind.canBeNull = false; //sa->canBeNullAtRuntime();
895 bind.ordinal = 1;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000896 bind.symbolName = targ->name();
Nick Kledzike34182f2013-11-06 21:36:55 +0000897 bind.addend = ref->addend();
898 nFile.lazyBindingInfo.push_back(bind);
899 }
900 }
901 }
902 }
903}
904
905uint32_t Util::fileFlags() {
906 return 0; //FIX ME
907}
908
909} // end anonymous namespace
910
911
912namespace lld {
913namespace mach_o {
914namespace normalized {
915
916/// Convert a set of Atoms into a normalized mach-o file.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000917ErrorOr<std::unique_ptr<NormalizedFile>>
918normalizedFromAtoms(const lld::File &atomFile,
Nick Kledzike34182f2013-11-06 21:36:55 +0000919 const MachOLinkingContext &context) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000920 // The util object buffers info until the normalized file can be made.
Nick Kledzike34182f2013-11-06 21:36:55 +0000921 Util util(context);
922 util.assignAtomsToSections(atomFile);
923 util.organizeSections();
924 util.assignAddressesToSections();
925 util.buildAtomToAddressMap();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000926
Nick Kledzike34182f2013-11-06 21:36:55 +0000927 std::unique_ptr<NormalizedFile> f(new NormalizedFile());
928 NormalizedFile &normFile = *f.get();
929 f->arch = context.arch();
Tim Northoverd30a1f22014-06-20 15:59:00 +0000930 f->fileType = context.outputMachOType();
Nick Kledzike34182f2013-11-06 21:36:55 +0000931 f->flags = util.fileFlags();
932 util.copySegmentInfo(normFile);
933 util.copySections(normFile);
934 util.addDependentDylibs(atomFile, normFile);
935 util.addSymbols(atomFile, normFile);
936 util.addIndirectSymbols(atomFile, normFile);
937 util.addRebaseAndBindingInfo(atomFile, normFile);
938 util.addSectionRelocs(atomFile, normFile);
939 util.copyEntryPointAddress(normFile);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000940
Nick Kledzike34182f2013-11-06 21:36:55 +0000941 return std::move(f);
942}
943
944
945} // namespace normalized
946} // namespace mach_o
947} // namespace lld
948