diff options
Diffstat (limited to 'lib/ReaderWriter/MachO/StubsPass.cpp')
| -rw-r--r-- | lib/ReaderWriter/MachO/StubsPass.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/ReaderWriter/MachO/StubsPass.cpp b/lib/ReaderWriter/MachO/StubsPass.cpp index 1f61256a5b79..d53b78b24d14 100644 --- a/lib/ReaderWriter/MachO/StubsPass.cpp +++ b/lib/ReaderWriter/MachO/StubsPass.cpp @@ -37,6 +37,8 @@ public: LazyPointerAtom(const File &file, bool is64) : SimpleDefinedAtom(file), _is64(is64) { } + ~LazyPointerAtom() override = default; + ContentType contentType() const override { return DefinedAtom::typeLazyPointer; } @@ -68,11 +70,13 @@ private: // class NonLazyPointerAtom : public SimpleDefinedAtom { public: - NonLazyPointerAtom(const File &file, bool is64) - : SimpleDefinedAtom(file), _is64(is64) { } + NonLazyPointerAtom(const File &file, bool is64, ContentType contentType) + : SimpleDefinedAtom(file), _is64(is64), _contentType(contentType) { } + + ~NonLazyPointerAtom() override = default; ContentType contentType() const override { - return DefinedAtom::typeGOT; + return _contentType; } Alignment alignment() const override { @@ -95,6 +99,7 @@ public: private: const bool _is64; + const ContentType _contentType; }; // @@ -105,6 +110,8 @@ public: StubAtom(const File &file, const ArchHandler::StubInfo &stubInfo) : SimpleDefinedAtom(file), _stubInfo(stubInfo){ } + ~StubAtom() override = default; + ContentType contentType() const override { return DefinedAtom::typeStub; } @@ -137,6 +144,8 @@ public: StubHelperAtom(const File &file, const ArchHandler::StubInfo &stubInfo) : SimpleDefinedAtom(file), _stubInfo(stubInfo) { } + ~StubHelperAtom() override = default; + ContentType contentType() const override { return DefinedAtom::typeStubHelper; } @@ -170,12 +179,14 @@ public: StubHelperCommonAtom(const File &file, const ArchHandler::StubInfo &stubInfo) : SimpleDefinedAtom(file), _stubInfo(stubInfo) { } + ~StubHelperCommonAtom() override = default; + ContentType contentType() const override { return DefinedAtom::typeStubHelper; } Alignment alignment() const override { - return 1 << _stubInfo.codeAlignment; + return 1 << _stubInfo.stubHelperCommonAlignment; } uint64_t size() const override { @@ -199,12 +210,15 @@ class StubsPass : public Pass { public: StubsPass(const MachOLinkingContext &context) : _ctx(context), _archHandler(_ctx.archHandler()), - _stubInfo(_archHandler.stubInfo()), _file("<mach-o Stubs pass>") {} + _stubInfo(_archHandler.stubInfo()), + _file(*_ctx.make_file<MachOFile>("<mach-o Stubs pass>")) { + _file.setOrdinal(_ctx.getNextOrdinalAndIncrement()); + } - std::error_code perform(SimpleFile &mergedFile) override { + llvm::Error perform(SimpleFile &mergedFile) override { // Skip this pass if output format uses text relocations instead of stubs. if (!this->noTextRelocs()) - return std::error_code(); + return llvm::Error(); // Scan all references in all atoms. for (const DefinedAtom *atom : mergedFile.defined()) { @@ -231,15 +245,17 @@ public: // Exit early if no stubs needed. if (_targetToUses.empty()) - return std::error_code(); + return llvm::Error(); // First add help-common and GOT slots used by lazy binding. SimpleDefinedAtom *helperCommonAtom = new (_file.allocator()) StubHelperCommonAtom(_file, _stubInfo); SimpleDefinedAtom *helperCacheNLPAtom = - new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit()); + new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit(), + _stubInfo.stubHelperImageCacheContentType); SimpleDefinedAtom *helperBinderNLPAtom = - new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit()); + new (_file.allocator()) NonLazyPointerAtom(_file, _ctx.is64Bit(), + _stubInfo.stubHelperImageCacheContentType); addReference(helperCommonAtom, _stubInfo.stubHelperCommonReferenceToCache, helperCacheNLPAtom); addOptReference( @@ -307,7 +323,7 @@ public: lazyOffset += target->name().size() + 12; } - return std::error_code(); + return llvm::Error(); } private: @@ -351,7 +367,7 @@ private: const MachOLinkingContext &_ctx; mach_o::ArchHandler &_archHandler; const ArchHandler::StubInfo &_stubInfo; - MachOFile _file; + MachOFile &_file; TargetToUses _targetToUses; }; |
