blob: 5bc1b3d7060f2edb356e852842bc60587e22cf35 [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),
Tim Northover9ee99352014-06-30 09:49:37 +0000218 ENTRY("__DATA", "___bss", S_ZEROFILL, typeZeroFill),
219
220 // FIXME: __compact_unwind actually needs to be processed by a pass and put
221 // into __TEXT,__unwind_info. For now, forwarding it back to
222 // __LD,__compact_unwind is harmless (it's ignored by the unwinder, which then
223 // proceeds to process __TEXT,__eh_frame for its instructions).
224 ENTRY("__LD", "__compact_unwind", S_REGULAR, typeCompactUnwindInfo),
Nick Kledzikec140832014-06-10 01:50:00 +0000225};
226#undef ENTRY
227
228
Nick Kledzik936d5202014-06-11 01:30:55 +0000229SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) {
Nick Kledzikec140832014-06-10 01:50:00 +0000230 for (const MachOFinalSectionFromAtomType *p = sectsToAtomType ;
231 p->atomType != DefinedAtom::typeUnknown; ++p) {
232 if (p->atomType != atomType)
233 continue;
234 SectionAttr sectionAttrs = 0;
235 switch (atomType) {
236 case DefinedAtom::typeCode:
237 case DefinedAtom::typeStub:
238 sectionAttrs = S_ATTR_PURE_INSTRUCTIONS;
239 break;
240 default:
241 break;
242 }
243 // If we already have a SectionInfo with this name, re-use it.
244 // This can happen if two ContentType map to the same mach-o section.
245 for (auto sect : _sectionMap) {
246 if (sect.second->sectionName.equals(p->sectionName) &&
247 sect.second->segmentName.equals(p->segmentName)) {
248 return sect.second;
249 }
250 }
251 // Otherwise allocate new SectionInfo object.
Nick Kledzik936d5202014-06-11 01:30:55 +0000252 SectionInfo *sect = new (_allocator) SectionInfo(p->segmentName,
253 p->sectionName,
254 p->sectionType,
255 sectionAttrs);
256 _sectionInfos.push_back(sect);
257 _sectionMap[atomType] = sect;
258 return sect;
Nick Kledzikec140832014-06-10 01:50:00 +0000259 }
260 llvm_unreachable("content type not yet supported");
Nick Kledzike34182f2013-11-06 21:36:55 +0000261}
262
263
264
265SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) {
Nick Kledzikacfad802014-05-30 22:51:04 +0000266 if (atom->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
267 // Section for this atom is derived from content type.
268 DefinedAtom::ContentType type = atom->contentType();
269 auto pos = _sectionMap.find(type);
270 if ( pos != _sectionMap.end() )
271 return pos->second;
Tim Northoverd30a1f22014-06-20 15:59:00 +0000272 bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT);
Nick Kledzik936d5202014-06-11 01:30:55 +0000273 return rMode ? getRelocatableSection(type) : getFinalSection(type);
Nick Kledzikacfad802014-05-30 22:51:04 +0000274 } else {
275 // This atom needs to be in a custom section.
276 StringRef customName = atom->customSectionName();
277 // Look to see if we have already allocated the needed custom section.
278 for(SectionInfo *sect : _customSections) {
279 const DefinedAtom *firstAtom = sect->atomsAndOffsets.front().atom;
280 if (firstAtom->customSectionName().equals(customName)) {
281 return sect;
282 }
283 }
284 // Not found, so need to create a new custom section.
285 size_t seperatorIndex = customName.find('/');
286 assert(seperatorIndex != StringRef::npos);
Tim Northover7b0a1302014-06-30 09:49:33 +0000287 StringRef segName = customName.slice(0, seperatorIndex);
288 StringRef sectName = customName.drop_front(seperatorIndex + 1);
Nick Kledzikacfad802014-05-30 22:51:04 +0000289 SectionInfo *sect = new (_allocator) SectionInfo(segName, sectName,
290 S_REGULAR);
291 _customSections.push_back(sect);
Tim Northover7b0a1302014-06-30 09:49:33 +0000292 _sectionInfos.push_back(sect);
Nick Kledzikacfad802014-05-30 22:51:04 +0000293 return sect;
294 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000295}
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000296
Nick Kledzike34182f2013-11-06 21:36:55 +0000297
298void Util::appendAtom(SectionInfo *sect, const DefinedAtom *atom) {
299 // Figure out offset for atom in this section given alignment constraints.
300 uint64_t offset = sect->size;
301 DefinedAtom::Alignment atomAlign = atom->alignment();
302 uint64_t align2 = 1 << atomAlign.powerOf2;
303 uint64_t requiredModulus = atomAlign.modulus;
304 uint64_t currentModulus = (offset % align2);
305 if ( currentModulus != requiredModulus ) {
306 if ( requiredModulus > currentModulus )
307 offset += requiredModulus-currentModulus;
308 else
309 offset += align2+requiredModulus-currentModulus;
310 }
311 // Record max alignment of any atom in this section.
312 if ( atomAlign.powerOf2 > sect->alignment )
313 sect->alignment = atomAlign.powerOf2;
314 // Assign atom to this section with this offset.
315 AtomInfo ai = {atom, offset};
316 sect->atomsAndOffsets.push_back(ai);
317 // Update section size to include this atom.
318 sect->size = offset + atom->size();
319}
320
321void Util::assignAtomsToSections(const lld::File &atomFile) {
322 for (const DefinedAtom *atom : atomFile.defined()) {
323 appendAtom(sectionForAtom(atom), atom);
324 }
325}
326
327SegmentInfo *Util::segmentForName(StringRef segName) {
328 for (SegmentInfo *si : _segmentInfos) {
329 if ( si->name.equals(segName) )
330 return si;
331 }
332 SegmentInfo *info = new (_allocator) SegmentInfo(segName);
333 if (segName.equals("__TEXT"))
334 info->access = VM_PROT_READ | VM_PROT_EXECUTE;
335 else if (segName.equals("__DATA"))
336 info->access = VM_PROT_READ | VM_PROT_WRITE;
337 else if (segName.equals("__PAGEZERO"))
338 info->access = 0;
339 _segmentInfos.push_back(info);
340 return info;
341}
342
343unsigned Util::SegmentSorter::weight(const SegmentInfo *seg) {
344 return llvm::StringSwitch<unsigned>(seg->name)
345 .Case("__PAGEZERO", 1)
346 .Case("__TEXT", 2)
347 .Case("__DATA", 3)
348 .Default(100);
349}
350
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000351bool Util::SegmentSorter::operator()(const SegmentInfo *left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000352 const SegmentInfo *right) {
353 return (weight(left) < weight(right));
354}
355
356unsigned Util::TextSectionSorter::weight(const SectionInfo *sect) {
357 return llvm::StringSwitch<unsigned>(sect->sectionName)
358 .Case("__text", 1)
359 .Case("__stubs", 2)
360 .Case("__stub_helper", 3)
361 .Case("__const", 4)
362 .Case("__cstring", 5)
363 .Case("__unwind_info", 98)
364 .Case("__eh_frame", 99)
365 .Default(10);
366}
367
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000368bool Util::TextSectionSorter::operator()(const SectionInfo *left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000369 const SectionInfo *right) {
370 return (weight(left) < weight(right));
371}
372
373
374void Util::organizeSections() {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000375 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000376 // Leave sections ordered as normalized file specified.
377 uint32_t sectionIndex = 1;
378 for (SectionInfo *si : _sectionInfos) {
379 si->finalSectionIndex = sectionIndex++;
380 }
381 } else {
382 // Main executables, need a zero-page segment
Tim Northoverd30a1f22014-06-20 15:59:00 +0000383 if (_context.outputMachOType() == llvm::MachO::MH_EXECUTE)
Nick Kledzike34182f2013-11-06 21:36:55 +0000384 segmentForName("__PAGEZERO");
385 // Group sections into segments.
386 for (SectionInfo *si : _sectionInfos) {
387 SegmentInfo *seg = segmentForName(si->segmentName);
388 seg->sections.push_back(si);
389 }
390 // Sort segments.
391 std::sort(_segmentInfos.begin(), _segmentInfos.end(), SegmentSorter());
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000392
Nick Kledzike34182f2013-11-06 21:36:55 +0000393 // Sort sections within segments.
394 for (SegmentInfo *seg : _segmentInfos) {
395 if (seg->name.equals("__TEXT")) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000396 std::sort(seg->sections.begin(), seg->sections.end(),
Nick Kledzike34182f2013-11-06 21:36:55 +0000397 TextSectionSorter());
398 }
399 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000400
Nick Kledzike34182f2013-11-06 21:36:55 +0000401 // Record final section indexes.
402 uint32_t sectionIndex = 1;
403 for (SegmentInfo *seg : _segmentInfos) {
404 for (SectionInfo *sect : seg->sections) {
405 sect->finalSectionIndex = sectionIndex++;
406 }
407 }
408 }
409
410}
411
412uint64_t Util::alignTo(uint64_t value, uint8_t align2) {
413 return llvm::RoundUpToAlignment(value, 1 << align2);
414}
415
416
417void Util::layoutSectionsInSegment(SegmentInfo *seg, uint64_t &addr) {
418 seg->address = addr;
419 for (SectionInfo *sect : seg->sections) {
420 sect->address = alignTo(addr, sect->alignment);
421 addr += sect->size;
422 }
423 seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize());
424}
425
426
427// __TEXT segment lays out backwards so padding is at front after load commands.
428void Util::layoutSectionsInTextSegment(SegmentInfo *seg, uint64_t &addr) {
429 seg->address = addr;
430 // Walks sections starting at end to calculate padding for start.
431 int64_t taddr = 0;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000432 for (auto it = seg->sections.rbegin(); it != seg->sections.rend(); ++it) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000433 SectionInfo *sect = *it;
434 taddr -= sect->size;
435 taddr = taddr & (0 - (1 << sect->alignment));
436 }
437 int64_t padding = taddr;
438 while (padding < 0)
439 padding += _context.pageSize();
440 // Start assigning section address starting at padded offset.
441 addr += padding;
442 for (SectionInfo *sect : seg->sections) {
443 sect->address = alignTo(addr, sect->alignment);
444 addr = sect->address + sect->size;
445 }
446 seg->size = llvm::RoundUpToAlignment(addr - seg->address,_context.pageSize());
447}
448
449
450void Util::assignAddressesToSections() {
451 uint64_t address = 0; // FIXME
Tim Northoverd30a1f22014-06-20 15:59:00 +0000452 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000453 for (SegmentInfo *seg : _segmentInfos) {
454 if (seg->name.equals("__PAGEZERO")) {
455 seg->size = _context.pageZeroSize();
456 address += seg->size;
457 }
458 else if (seg->name.equals("__TEXT"))
459 layoutSectionsInTextSegment(seg, address);
460 else
461 layoutSectionsInSegment(seg, address);
Tim Northover7b0a1302014-06-30 09:49:33 +0000462
463 address = llvm::RoundUpToAlignment(address, _context.pageSize());
Nick Kledzike34182f2013-11-06 21:36:55 +0000464 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000465 DEBUG_WITH_TYPE("WriterMachO-norm",
Nick Kledzik020a49c2013-11-06 21:57:52 +0000466 llvm::dbgs() << "assignAddressesToSections()\n";
467 for (SegmentInfo *sgi : _segmentInfos) {
468 llvm::dbgs() << " address=" << llvm::format("0x%08llX", sgi->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000469 << ", size=" << llvm::format("0x%08llX", sgi->size)
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000470 << ", segment-name='" << sgi->name
Nick Kledzik020a49c2013-11-06 21:57:52 +0000471 << "'\n";
472 for (SectionInfo *si : sgi->sections) {
473 llvm::dbgs()<< " addr=" << llvm::format("0x%08llX", si->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000474 << ", size=" << llvm::format("0x%08llX", si->size)
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000475 << ", section-name='" << si->sectionName
Nick Kledzik020a49c2013-11-06 21:57:52 +0000476 << "\n";
477 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000478 }
Nick Kledzik020a49c2013-11-06 21:57:52 +0000479 );
Nick Kledzike34182f2013-11-06 21:36:55 +0000480 } else {
481 for (SectionInfo *sect : _sectionInfos) {
482 sect->address = alignTo(address, sect->alignment);
483 address = sect->address + sect->size;
484 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000485 DEBUG_WITH_TYPE("WriterMachO-norm",
Nick Kledzik020a49c2013-11-06 21:57:52 +0000486 llvm::dbgs() << "assignAddressesToSections()\n";
487 for (SectionInfo *si : _sectionInfos) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000488 llvm::dbgs() << " section=" << si->sectionName
Nick Kledzike34182f2013-11-06 21:36:55 +0000489 << " address= " << llvm::format("0x%08X", si->address)
490 << " size= " << llvm::format("0x%08X", si->size)
Nick Kledzik020a49c2013-11-06 21:57:52 +0000491 << "\n";
492 }
493 );
Nick Kledzike34182f2013-11-06 21:36:55 +0000494 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000495}
496
497
498void Util::copySegmentInfo(NormalizedFile &file) {
499 for (SegmentInfo *sgi : _segmentInfos) {
500 Segment seg;
501 seg.name = sgi->name;
502 seg.address = sgi->address;
503 seg.size = sgi->size;
504 seg.access = sgi->access;
505 file.segments.push_back(seg);
506 }
507}
508
509void Util::appendSection(SectionInfo *si, NormalizedFile &file) {
Nick Kledzik3f690762014-06-27 18:25:01 +0000510 const bool rMode = (_context.outputMachOType() == llvm::MachO::MH_OBJECT);
Nick Kledzike34182f2013-11-06 21:36:55 +0000511 // Add new empty section to end of file.sections.
512 Section temp;
513 file.sections.push_back(std::move(temp));
514 Section* normSect = &file.sections.back();
515 // Copy fields to normalized section.
516 normSect->segmentName = si->segmentName;
517 normSect->sectionName = si->sectionName;
518 normSect->type = si->type;
519 normSect->attributes = si->attributes;
520 normSect->address = si->address;
521 normSect->alignment = si->alignment;
522 // Record where normalized section is.
523 si->normalizedSectionIndex = file.sections.size()-1;
524 // Copy content from atoms to content buffer for section.
Nick Kledzik61fdef62014-05-15 20:59:23 +0000525 if (si->type == llvm::MachO::S_ZEROFILL)
526 return;
Nick Kledzik6edd7222014-01-11 01:07:43 +0000527 uint8_t *sectionContent = file.ownedAllocations.Allocate<uint8_t>(si->size);
528 normSect->content = llvm::makeArrayRef(sectionContent, si->size);
Nick Kledzike34182f2013-11-06 21:36:55 +0000529 for (AtomInfo &ai : si->atomsAndOffsets) {
530 // Copy raw bytes.
531 uint8_t *atomContent = reinterpret_cast<uint8_t*>
532 (&sectionContent[ai.offsetInSection]);
533 memcpy(atomContent, ai.atom->rawContent().data(), ai.atom->size());
534 // Apply fix-ups.
535 for (const Reference *ref : *ai.atom) {
536 uint32_t offset = ref->offsetInAtom();
537 uint64_t targetAddress = 0;
538 if ( ref->target() != nullptr )
539 targetAddress = _atomToAddress[ref->target()];
540 uint64_t fixupAddress = _atomToAddress[ai.atom] + offset;
Nick Kledzik3f690762014-06-27 18:25:01 +0000541 if ( rMode ) {
542 // FIXME: Need a handler method to update content for .o file
543 // output and any needed section relocations.
544 } else {
545 _context.kindHandler().applyFixup(
Rui Ueyama170a1a82013-12-20 07:48:29 +0000546 ref->kindNamespace(), ref->kindArch(), ref->kindValue(),
547 ref->addend(), &atomContent[offset], fixupAddress, targetAddress);
Nick Kledzik3f690762014-06-27 18:25:01 +0000548 }
Nick Kledzike34182f2013-11-06 21:36:55 +0000549 }
550 }
551}
552
553void Util::copySections(NormalizedFile &file) {
554 file.sections.reserve(_sectionInfos.size());
555 // For final linked images, write sections grouped by segment.
Tim Northoverd30a1f22014-06-20 15:59:00 +0000556 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000557 for (SegmentInfo *sgi : _segmentInfos) {
558 for (SectionInfo *si : sgi->sections) {
559 appendSection(si, file);
560 }
561 }
562 } else {
563 // Object files write sections in default order.
564 for (SectionInfo *si : _sectionInfos) {
565 appendSection(si, file);
566 }
567 }
568}
569
570void Util::copyEntryPointAddress(NormalizedFile &nFile) {
571 if (_context.outputTypeHasEntry()) {
572 nFile.entryAddress = _atomToAddress[_entryAtom];
573 }
574}
575
576void Util::buildAtomToAddressMap() {
577 DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs()
578 << "assign atom addresses:\n");
579 const bool lookForEntry = _context.outputTypeHasEntry();
580 for (SectionInfo *sect : _sectionInfos) {
581 for (const AtomInfo &info : sect->atomsAndOffsets) {
582 _atomToAddress[info.atom] = sect->address + info.offsetInSection;
583 if (lookForEntry && (info.atom->contentType() == DefinedAtom::typeCode) &&
584 (info.atom->size() != 0) &&
585 info.atom->name() == _context.entrySymbolName()) {
586 _entryAtom = info.atom;
587 }
588 DEBUG_WITH_TYPE("WriterMachO-address", llvm::dbgs()
589 << " address="
590 << llvm::format("0x%016X", _atomToAddress[info.atom])
591 << " atom=" << info.atom
592 << " name=" << info.atom->name() << "\n");
593 }
594 }
595}
596
597uint8_t Util::scopeBits(const DefinedAtom* atom) {
598 switch (atom->scope()) {
599 case Atom::scopeTranslationUnit:
600 return 0;
601 case Atom::scopeLinkageUnit:
602 return N_PEXT | N_EXT;
603 case Atom::scopeGlobal:
604 return N_EXT;
605 }
Nick Kledzik020fa7f2013-11-06 22:18:09 +0000606 llvm_unreachable("Unknown scope");
Nick Kledzike34182f2013-11-06 21:36:55 +0000607}
608
Nick Kledzik60855392014-06-11 00:24:16 +0000609uint16_t Util::descBits(const DefinedAtom* atom) {
610 uint16_t desc = 0;
611 switch (atom->merge()) {
612 case lld::DefinedAtom::mergeNo:
613 case lld::DefinedAtom::mergeAsTentative:
614 break;
615 case lld::DefinedAtom::mergeAsWeak:
616 case lld::DefinedAtom::mergeAsWeakAndAddressUsed:
617 desc |= N_WEAK_DEF;
618 break;
619 case lld::DefinedAtom::mergeSameNameAndSize:
620 case lld::DefinedAtom::mergeByLargestSection:
621 case lld::DefinedAtom::mergeByContent:
622 llvm_unreachable("Unsupported DefinedAtom::merge()");
623 break;
624 }
625 if (atom->contentType() == lld::DefinedAtom::typeResolver)
626 desc |= N_SYMBOL_RESOLVER;
627 return desc;
628}
629
630
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000631bool Util::AtomSorter::operator()(const AtomAndIndex &left,
Nick Kledzike34182f2013-11-06 21:36:55 +0000632 const AtomAndIndex &right) {
633 return (left.atom->name().compare(right.atom->name()) < 0);
634}
635
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000636
Nick Kledzike34182f2013-11-06 21:36:55 +0000637bool Util::belongsInGlobalSymbolsSection(const DefinedAtom* atom) {
Nick Kledzik936d5202014-06-11 01:30:55 +0000638 // ScopeLinkageUnit symbols are in globals area of symbol table
639 // in object files, but in locals area for final linked images.
Tim Northoverd30a1f22014-06-20 15:59:00 +0000640 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT)
Nick Kledzik936d5202014-06-11 01:30:55 +0000641 return (atom->scope() != Atom::scopeTranslationUnit);
642 else
643 return (atom->scope() == Atom::scopeGlobal);
Nick Kledzike34182f2013-11-06 21:36:55 +0000644}
645
646void Util::addSymbols(const lld::File &atomFile, NormalizedFile &file) {
647 // Mach-O symbol table has three regions: locals, globals, undefs.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000648
Nick Kledzike34182f2013-11-06 21:36:55 +0000649 // Add all local (non-global) symbols in address order
650 std::vector<AtomAndIndex> globals;
651 globals.reserve(512);
652 for (SectionInfo *sect : _sectionInfos) {
653 for (const AtomInfo &info : sect->atomsAndOffsets) {
654 const DefinedAtom *atom = info.atom;
655 if (!atom->name().empty()) {
656 if (belongsInGlobalSymbolsSection(atom)) {
657 AtomAndIndex ai = { atom, sect->finalSectionIndex };
658 globals.push_back(ai);
659 } else {
660 Symbol sym;
661 sym.name = atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000662 sym.type = N_SECT;
Nick Kledzike34182f2013-11-06 21:36:55 +0000663 sym.scope = scopeBits(atom);
664 sym.sect = sect->finalSectionIndex;
665 sym.desc = 0;
666 sym.value = _atomToAddress[atom];
667 file.localSymbols.push_back(sym);
668 }
669 }
670 }
671 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000672
Nick Kledzike34182f2013-11-06 21:36:55 +0000673 // Sort global symbol alphabetically, then add to symbol table.
674 std::sort(globals.begin(), globals.end(), AtomSorter());
675 for (AtomAndIndex &ai : globals) {
676 Symbol sym;
677 sym.name = ai.atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000678 sym.type = N_SECT;
Nick Kledzike34182f2013-11-06 21:36:55 +0000679 sym.scope = scopeBits(static_cast<const DefinedAtom*>(ai.atom));
680 sym.sect = ai.index;
Nick Kledzik60855392014-06-11 00:24:16 +0000681 sym.desc = descBits(static_cast<const DefinedAtom*>(ai.atom));
Nick Kledzike34182f2013-11-06 21:36:55 +0000682 sym.value = _atomToAddress[ai.atom];
683 file.globalSymbols.push_back(sym);
684 }
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000685
686
Nick Kledzike34182f2013-11-06 21:36:55 +0000687 // Sort undefined symbol alphabetically, then add to symbol table.
688 std::vector<AtomAndIndex> undefs;
689 undefs.reserve(128);
690 for (const UndefinedAtom *atom : atomFile.undefined()) {
691 AtomAndIndex ai = { atom, 0 };
692 undefs.push_back(ai);
693 }
694 for (const SharedLibraryAtom *atom : atomFile.sharedLibrary()) {
695 AtomAndIndex ai = { atom, 0 };
696 undefs.push_back(ai);
697 }
698 std::sort(undefs.begin(), undefs.end(), AtomSorter());
699 const uint32_t start = file.globalSymbols.size() + file.localSymbols.size();
700 for (AtomAndIndex &ai : undefs) {
701 Symbol sym;
702 sym.name = ai.atom->name();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000703 sym.type = N_UNDF;
Nick Kledzike34182f2013-11-06 21:36:55 +0000704 sym.scope = N_EXT;
705 sym.sect = 0;
706 sym.desc = 0;
707 sym.value = 0;
708 _atomToSymbolIndex[ai.atom] = file.undefinedSymbols.size() + start;
709 file.undefinedSymbols.push_back(sym);
710 }
711}
712
713const Atom *Util::targetOfLazyPointer(const DefinedAtom *lpAtom) {
714 for (const Reference *ref : *lpAtom) {
Nick Kledzike5552772013-12-19 21:58:00 +0000715 if (_context.kindHandler().isLazyTarget(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000716 return ref->target();
717 }
718 }
719 return nullptr;
720}
721
722const Atom *Util::targetOfStub(const DefinedAtom *stubAtom) {
723 for (const Reference *ref : *stubAtom) {
724 if (const Atom *ta = ref->target()) {
725 if (const DefinedAtom *lpAtom = dyn_cast<DefinedAtom>(ta)) {
726 const Atom *target = targetOfLazyPointer(lpAtom);
727 if (target)
728 return target;
729 }
730 }
731 }
732 return nullptr;
733}
734
735
736void Util::addIndirectSymbols(const lld::File &atomFile, NormalizedFile &file) {
737 for (SectionInfo *si : _sectionInfos) {
738 Section &normSect = file.sections[si->normalizedSectionIndex];
739 switch (si->type) {
740 case llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS:
741 for (const AtomInfo &info : si->atomsAndOffsets) {
742 bool foundTarget = false;
743 for (const Reference *ref : *info.atom) {
744 const Atom *target = ref->target();
745 if (target) {
746 if (isa<const SharedLibraryAtom>(target)) {
747 uint32_t index = _atomToSymbolIndex[target];
748 normSect.indirectSymbols.push_back(index);
749 foundTarget = true;
750 } else {
751 normSect.indirectSymbols.push_back(
752 llvm::MachO::INDIRECT_SYMBOL_LOCAL);
753 }
754 }
755 }
756 if (!foundTarget) {
757 normSect.indirectSymbols.push_back(
758 llvm::MachO::INDIRECT_SYMBOL_ABS);
759 }
760 }
761 break;
762 case llvm::MachO::S_LAZY_SYMBOL_POINTERS:
763 for (const AtomInfo &info : si->atomsAndOffsets) {
764 const Atom *target = targetOfLazyPointer(info.atom);
765 if (target) {
766 uint32_t index = _atomToSymbolIndex[target];
767 normSect.indirectSymbols.push_back(index);
768 }
769 }
770 break;
771 case llvm::MachO::S_SYMBOL_STUBS:
772 for (const AtomInfo &info : si->atomsAndOffsets) {
773 const Atom *target = targetOfStub(info.atom);
774 if (target) {
775 uint32_t index = _atomToSymbolIndex[target];
776 normSect.indirectSymbols.push_back(index);
777 }
778 }
779 break;
780 default:
781 break;
782 }
783 }
784
785}
786
787void Util::addDependentDylibs(const lld::File &atomFile,NormalizedFile &nFile) {
788 // Scan all imported symbols and build up list of dylibs they are from.
789 int ordinal = 1;
790 for (const SharedLibraryAtom *slAtom : atomFile.sharedLibrary()) {
791 StringRef loadPath = slAtom->loadName();
792 DylibPathToInfo::iterator pos = _dylibInfo.find(loadPath);
793 if (pos == _dylibInfo.end()) {
794 DylibInfo info;
795 info.ordinal = ordinal++;
796 info.hasWeak = slAtom->canBeNullAtRuntime();
797 info.hasNonWeak = !info.hasWeak;
798 _dylibInfo[loadPath] = info;
799 DependentDylib depInfo;
800 depInfo.path = loadPath;
801 depInfo.kind = llvm::MachO::LC_LOAD_DYLIB;
802 nFile.dependentDylibs.push_back(depInfo);
803 } else {
804 if ( slAtom->canBeNullAtRuntime() )
805 pos->second.hasWeak = true;
806 else
807 pos->second.hasNonWeak = true;
808 }
809 }
810 // Automatically weak link dylib in which all symbols are weak (canBeNull).
811 for (DependentDylib &dep : nFile.dependentDylibs) {
812 DylibInfo &info = _dylibInfo[dep.path];
813 if (info.hasWeak && !info.hasNonWeak)
814 dep.kind = llvm::MachO::LC_LOAD_WEAK_DYLIB;
815 }
816}
817
818
819int Util::dylibOrdinal(const SharedLibraryAtom *sa) {
820 return _dylibInfo[sa->loadName()].ordinal;
821}
822
823void Util::segIndexForSection(const SectionInfo *sect, uint8_t &segmentIndex,
824 uint64_t &segmentStartAddr) {
825 segmentIndex = 0;
826 for (const SegmentInfo *seg : _segmentInfos) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000827 if ((seg->address <= sect->address)
Nick Kledzike34182f2013-11-06 21:36:55 +0000828 && (seg->address+seg->size >= sect->address+sect->size)) {
829 segmentStartAddr = seg->address;
830 return;
831 }
832 ++segmentIndex;
833 }
834 llvm_unreachable("section not in any segment");
835}
836
837
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000838void Util::appendReloc(const DefinedAtom *atom, const Reference *ref,
Nick Kledzike34182f2013-11-06 21:36:55 +0000839 Relocations &relocations) {
840 // TODO: convert Reference to normalized relocation
841}
842
843void Util::addSectionRelocs(const lld::File &, NormalizedFile &file) {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000844 if (_context.outputMachOType() != llvm::MachO::MH_OBJECT)
Nick Kledzike34182f2013-11-06 21:36:55 +0000845 return;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000846
Nick Kledzike34182f2013-11-06 21:36:55 +0000847 for (SectionInfo *si : _sectionInfos) {
848 Section &normSect = file.sections[si->normalizedSectionIndex];
849 for (const AtomInfo &info : si->atomsAndOffsets) {
850 const DefinedAtom *atom = info.atom;
851 for (const Reference *ref : *atom) {
852 appendReloc(atom, ref, normSect.relocations);
853 }
854 }
855 }
856}
857
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000858void Util::addRebaseAndBindingInfo(const lld::File &atomFile,
Nick Kledzike34182f2013-11-06 21:36:55 +0000859 NormalizedFile &nFile) {
Tim Northoverd30a1f22014-06-20 15:59:00 +0000860 if (_context.outputMachOType() == llvm::MachO::MH_OBJECT)
Nick Kledzike34182f2013-11-06 21:36:55 +0000861 return;
862
863 uint8_t segmentIndex;
864 uint64_t segmentStartAddr;
865 for (SectionInfo *sect : _sectionInfos) {
866 segIndexForSection(sect, segmentIndex, segmentStartAddr);
867 for (const AtomInfo &info : sect->atomsAndOffsets) {
868 const DefinedAtom *atom = info.atom;
869 for (const Reference *ref : *atom) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000870 uint64_t segmentOffset = _atomToAddress[atom] + ref->offsetInAtom()
Nick Kledzike34182f2013-11-06 21:36:55 +0000871 - segmentStartAddr;
872 const Atom* targ = ref->target();
Nick Kledzike5552772013-12-19 21:58:00 +0000873 if (_context.kindHandler().isPointer(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000874 // A pointer to a DefinedAtom requires rebasing.
875 if (dyn_cast<DefinedAtom>(targ)) {
876 RebaseLocation rebase;
877 rebase.segIndex = segmentIndex;
878 rebase.segOffset = segmentOffset;
879 rebase.kind = llvm::MachO::REBASE_TYPE_POINTER;
880 nFile.rebasingInfo.push_back(rebase);
881 }
882 // A pointer to an SharedLibraryAtom requires binding.
883 if (const SharedLibraryAtom *sa = dyn_cast<SharedLibraryAtom>(targ)) {
884 BindLocation bind;
885 bind.segIndex = segmentIndex;
886 bind.segOffset = segmentOffset;
887 bind.kind = llvm::MachO::BIND_TYPE_POINTER;
888 bind.canBeNull = sa->canBeNullAtRuntime();
889 bind.ordinal = dylibOrdinal(sa);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000890 bind.symbolName = targ->name();
Nick Kledzike34182f2013-11-06 21:36:55 +0000891 bind.addend = ref->addend();
892 nFile.bindingInfo.push_back(bind);
893 }
894 }
Nick Kledzike5552772013-12-19 21:58:00 +0000895 if (_context.kindHandler().isLazyTarget(*ref)) {
Nick Kledzike34182f2013-11-06 21:36:55 +0000896 BindLocation bind;
897 bind.segIndex = segmentIndex;
898 bind.segOffset = segmentOffset;
899 bind.kind = llvm::MachO::BIND_TYPE_POINTER;
900 bind.canBeNull = false; //sa->canBeNullAtRuntime();
901 bind.ordinal = 1;
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000902 bind.symbolName = targ->name();
Nick Kledzike34182f2013-11-06 21:36:55 +0000903 bind.addend = ref->addend();
904 nFile.lazyBindingInfo.push_back(bind);
905 }
906 }
907 }
908 }
909}
910
911uint32_t Util::fileFlags() {
912 return 0; //FIX ME
913}
914
915} // end anonymous namespace
916
917
918namespace lld {
919namespace mach_o {
920namespace normalized {
921
922/// Convert a set of Atoms into a normalized mach-o file.
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000923ErrorOr<std::unique_ptr<NormalizedFile>>
924normalizedFromAtoms(const lld::File &atomFile,
Nick Kledzike34182f2013-11-06 21:36:55 +0000925 const MachOLinkingContext &context) {
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000926 // The util object buffers info until the normalized file can be made.
Nick Kledzike34182f2013-11-06 21:36:55 +0000927 Util util(context);
928 util.assignAtomsToSections(atomFile);
929 util.organizeSections();
930 util.assignAddressesToSections();
931 util.buildAtomToAddressMap();
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000932
Nick Kledzike34182f2013-11-06 21:36:55 +0000933 std::unique_ptr<NormalizedFile> f(new NormalizedFile());
934 NormalizedFile &normFile = *f.get();
935 f->arch = context.arch();
Tim Northoverd30a1f22014-06-20 15:59:00 +0000936 f->fileType = context.outputMachOType();
Nick Kledzike34182f2013-11-06 21:36:55 +0000937 f->flags = util.fileFlags();
938 util.copySegmentInfo(normFile);
939 util.copySections(normFile);
940 util.addDependentDylibs(atomFile, normFile);
941 util.addSymbols(atomFile, normFile);
942 util.addIndirectSymbols(atomFile, normFile);
943 util.addRebaseAndBindingInfo(atomFile, normFile);
944 util.addSectionRelocs(atomFile, normFile);
945 util.copyEntryPointAddress(normFile);
Shankar Easwaran3d8de472014-01-27 03:09:26 +0000946
Nick Kledzike34182f2013-11-06 21:36:55 +0000947 return std::move(f);
948}
949
950
951} // namespace normalized
952} // namespace mach_o
953} // namespace lld
954