Index: lib/ReaderWriter/MachO/ArchHandler.h =================================================================== --- lib/ReaderWriter/MachO/ArchHandler.h +++ lib/ReaderWriter/MachO/ArchHandler.h @@ -205,7 +205,7 @@ virtual bool isThumbFunction(const DefinedAtom &atom) { return false; } /// Only relevant for 32-bit arm archs. - virtual const DefinedAtom *createShim(MachOFile &file, bool thumbToArm, + virtual const DefinedAtom *createShim(const File &file, bool thumbToArm, const DefinedAtom &) { llvm_unreachable("shims only support on arm"); } Index: lib/ReaderWriter/MachO/ArchHandler_arm.cpp =================================================================== --- lib/ReaderWriter/MachO/ArchHandler_arm.cpp +++ lib/ReaderWriter/MachO/ArchHandler_arm.cpp @@ -129,7 +129,7 @@ } bool isThumbFunction(const DefinedAtom &atom) override; - const DefinedAtom *createShim(MachOFile &file, bool thumbToArm, + const DefinedAtom *createShim(const File &file, bool thumbToArm, const DefinedAtom &) override; private: @@ -1411,7 +1411,7 @@ class Thumb2ToArmShimAtom : public SimpleDefinedAtom { public: - Thumb2ToArmShimAtom(MachOFile &file, StringRef targetName, + Thumb2ToArmShimAtom(const File &file, StringRef targetName, const DefinedAtom &target) : SimpleDefinedAtom(file) { addReference(Reference::KindNamespace::mach_o, Reference::KindArch::ARM, @@ -1459,7 +1459,7 @@ class ArmToThumbShimAtom : public SimpleDefinedAtom { public: - ArmToThumbShimAtom(MachOFile &file, StringRef targetName, + ArmToThumbShimAtom(const File &file, StringRef targetName, const DefinedAtom &target) : SimpleDefinedAtom(file) { addReference(Reference::KindNamespace::mach_o, Reference::KindArch::ARM, @@ -1502,7 +1502,7 @@ StringRef _name; }; -const DefinedAtom *ArchHandler_arm::createShim(MachOFile &file, +const DefinedAtom *ArchHandler_arm::createShim(const File &file, bool thumbToArm, const DefinedAtom &target) { bool isStub = (target.contentType() == DefinedAtom::typeStub); Index: lib/ReaderWriter/MachO/CompactUnwindPass.cpp =================================================================== --- lib/ReaderWriter/MachO/CompactUnwindPass.cpp +++ lib/ReaderWriter/MachO/CompactUnwindPass.cpp @@ -274,7 +274,6 @@ public: CompactUnwindPass(const MachOLinkingContext &context) : _context(context), _archHandler(_context.archHandler()), - _file(""), _isBig(MachOLinkingContext::isBigEndian(_context.arch())) {} private: @@ -340,8 +339,8 @@ << " has " << entriesInPage << " entries\n"); } while (pageStart < unwindInfos.size()); - UnwindInfoAtom *unwind = new (_file.allocator()) - UnwindInfoAtom(_archHandler, _file, _isBig, personalities, + UnwindInfoAtom *unwind = new (mergedFile->allocator()) + UnwindInfoAtom(_archHandler, *mergedFile, _isBig, personalities, commonEncodings, pages, numLSDAs); mergedFile->addAtom(*unwind); @@ -515,7 +514,6 @@ const MachOLinkingContext &_context; mach_o::ArchHandler &_archHandler; - MachOFile _file; bool _isBig; }; Index: lib/ReaderWriter/MachO/GOTPass.cpp =================================================================== --- lib/ReaderWriter/MachO/GOTPass.cpp +++ lib/ReaderWriter/MachO/GOTPass.cpp @@ -92,8 +92,7 @@ class GOTPass : public Pass { public: GOTPass(const MachOLinkingContext &context) - : _context(context), _archHandler(_context.archHandler()), - _file("") { } + : _context(context), _archHandler(_context.archHandler()) { } private: @@ -113,7 +112,7 @@ _archHandler.updateReferenceToGOT(ref, false); } else { // Replace the target with a reference to a GOT entry. - const DefinedAtom *gotEntry = makeGOTEntry(target); + const DefinedAtom *gotEntry = makeGOTEntry(*mergedFile, target); const_cast(ref)->setTarget(gotEntry); // Update reference kind to reflect that target is now a GOT entry. _archHandler.updateReferenceToGOT(ref, true); @@ -151,11 +150,11 @@ return !canBypassGOT; } - const DefinedAtom *makeGOTEntry(const Atom *target) { + const DefinedAtom *makeGOTEntry(const File &file, const Atom *target) { auto pos = _targetToGOT.find(target); if (pos == _targetToGOT.end()) { - GOTEntryAtom *gotEntry = new (_file.allocator()) - GOTEntryAtom(_file, _context.is64Bit(), target->name()); + GOTEntryAtom *gotEntry = new (file.allocator()) + GOTEntryAtom(file, _context.is64Bit(), target->name()); _targetToGOT[target] = gotEntry; const ArchHandler::ReferenceInfo &nlInfo = _archHandler.stubInfo(). nonLazyPointerReferenceToBinder; @@ -169,7 +168,6 @@ const MachOLinkingContext &_context; mach_o::ArchHandler &_archHandler; - MachOFile _file; llvm::DenseMap _targetToGOT; }; Index: lib/ReaderWriter/MachO/ShimPass.cpp =================================================================== --- lib/ReaderWriter/MachO/ShimPass.cpp +++ lib/ReaderWriter/MachO/ShimPass.cpp @@ -43,8 +43,7 @@ ShimPass(const MachOLinkingContext &context) : _context(context) , _archHandler(_context.archHandler()) - , _stubInfo(_archHandler.stubInfo()) - , _file("") { + , _stubInfo(_archHandler.stubInfo()) { } @@ -61,7 +60,7 @@ bool atomIsThumb = _archHandler.isThumbFunction(*atom); bool targetIsThumb = _archHandler.isThumbFunction(*daTarget); if (atomIsThumb != targetIsThumb) - updateBranchToUseShim(atomIsThumb, *daTarget, ref); + updateBranchToUseShim(*mergedFile, atomIsThumb, *daTarget, ref); } } } @@ -88,16 +87,17 @@ private: - void updateBranchToUseShim(bool thumbToArm, const DefinedAtom& target, - const Reference *ref) { + void updateBranchToUseShim(const File &file, bool thumbToArm, + const DefinedAtom& target, const Reference *ref) { // Make file-format specific stub and other support atoms. - const DefinedAtom *shim = this->getShim(thumbToArm, target); + const DefinedAtom *shim = this->getShim(file, thumbToArm, target); assert(shim != nullptr); // Switch branch site to target shim atom. const_cast(ref)->setTarget(shim); } - const DefinedAtom* getShim(bool thumbToArm, const DefinedAtom& target) { + const DefinedAtom* getShim(const File &file, bool thumbToArm, + const DefinedAtom& target) { auto pos = _targetToShim.find(&target); if ( pos != _targetToShim.end() ) { // Reuse an existing shim. @@ -105,7 +105,7 @@ return pos->second; } else { // There is no existing shim, so create a new one. - const DefinedAtom *shim = _archHandler.createShim(_file, thumbToArm, + const DefinedAtom *shim = _archHandler.createShim(file, thumbToArm, target); _targetToShim[&target] = shim; return shim; @@ -115,7 +115,6 @@ const MachOLinkingContext &_context; mach_o::ArchHandler &_archHandler; const ArchHandler::StubInfo &_stubInfo; - MachOFile _file; llvm::DenseMap _targetToShim; }; Index: lib/ReaderWriter/MachO/StubsPass.cpp =================================================================== --- lib/ReaderWriter/MachO/StubsPass.cpp +++ lib/ReaderWriter/MachO/StubsPass.cpp @@ -207,7 +207,7 @@ public: StubsPass(const MachOLinkingContext &context) : _context(context), _archHandler(_context.archHandler()), - _stubInfo(_archHandler.stubInfo()), _file("") { } + _stubInfo(_archHandler.stubInfo()) { } void perform(std::unique_ptr &mergedFile) override { @@ -244,11 +244,14 @@ // First add help-common and GOT slots used by lazy binding. SimpleDefinedAtom *helperCommonAtom = - new (_file.allocator()) StubHelperCommonAtom(_file, _stubInfo); + new (mergedFile->allocator()) StubHelperCommonAtom(*mergedFile, + _stubInfo); SimpleDefinedAtom *helperCacheNLPAtom = - new (_file.allocator()) NonLazyPointerAtom(_file, _context.is64Bit()); + new (mergedFile->allocator()) NonLazyPointerAtom(*mergedFile, + _context.is64Bit()); SimpleDefinedAtom *helperBinderNLPAtom = - new (_file.allocator()) NonLazyPointerAtom(_file, _context.is64Bit()); + new (mergedFile->allocator()) NonLazyPointerAtom(*mergedFile, + _context.is64Bit()); addReference(helperCommonAtom, _stubInfo.stubHelperCommonReferenceToCache, helperCacheNLPAtom); addOptReference( @@ -287,11 +290,14 @@ // Make and append stubs, lazy pointers, and helpers in alphabetical order. unsigned lazyOffset = 0; for (const Atom *target : targetsNeedingStubs) { - StubAtom *stub = new (_file.allocator()) StubAtom(_file, _stubInfo); + StubAtom *stub = new (mergedFile->allocator()) StubAtom(*mergedFile, + _stubInfo); LazyPointerAtom *lp = - new (_file.allocator()) LazyPointerAtom(_file, _context.is64Bit()); + new (mergedFile->allocator()) LazyPointerAtom(*mergedFile, + _context.is64Bit()); StubHelperAtom *helper = - new (_file.allocator()) StubHelperAtom(_file, _stubInfo); + new (mergedFile->allocator()) StubHelperAtom(*mergedFile, + _stubInfo); addReference(stub, _stubInfo.stubReferenceToLP, lp); addOptReference(stub, _stubInfo.stubReferenceToLP, @@ -362,7 +368,6 @@ const MachOLinkingContext &_context; mach_o::ArchHandler &_archHandler; const ArchHandler::StubInfo &_stubInfo; - MachOFile _file; TargetToUses _targetToUses; };