diff --git a/lld/include/lld/Core/LinkingContext.h b/lld/include/lld/Core/LinkingContext.h index 47805f44c271..525e1fe5d97c 100644 --- a/lld/include/lld/Core/LinkingContext.h +++ b/lld/include/lld/Core/LinkingContext.h @@ -305,14 +305,14 @@ public: /// the resolver operates. This uses the currentInputElement. When there are /// no more files to be processed an appropriate input_graph_error is /// returned. - virtual ErrorOr nextFile() const; + virtual ErrorOr nextFile(); /// Set the resolver state for the current Input element This is used by the /// InputGraph to decide the next file that needs to be processed for various /// types of nodes in the InputGraph. The resolver state is nothing but a /// bitmask of various types of states that the resolver handles when adding /// atoms. - virtual void setResolverState(uint32_t resolverState) const; + virtual void setResolverState(uint32_t resolverState); /// @} @@ -362,7 +362,7 @@ protected: StringRefVector _initialUndefinedSymbols; std::unique_ptr _inputGraph; mutable llvm::BumpPtrAllocator _allocator; - mutable InputElement *_currentInputElement; + InputElement *_currentInputElement; private: /// Validate the subclass bits. Only called by validate. diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index b94486fc3400..b0dc268efc3f 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -36,7 +36,7 @@ public: StateNewAbsoluteAtoms = 8 // New absolute atoms were added }; - Resolver(const LinkingContext &context) + Resolver(LinkingContext &context) : _context(context), _symbolTable(context), _result(context), _haveLLVMObjs(false), _addToFinalSection(false) {} @@ -111,7 +111,7 @@ private: atom_collection_vector _absoluteAtoms; }; - const LinkingContext &_context; + LinkingContext &_context; SymbolTable _symbolTable; std::vector _atoms; std::set _deadStripRoots; diff --git a/lld/include/lld/Driver/Driver.h b/lld/include/lld/Driver/Driver.h index 72d4fcca339f..a2773d68d944 100644 --- a/lld/include/lld/Driver/Driver.h +++ b/lld/include/lld/Driver/Driver.h @@ -38,7 +38,7 @@ class Driver { protected: /// Performs link using specified options - static bool link(const LinkingContext &context, + static bool link(LinkingContext &context, raw_ostream &diagnostics = llvm::errs()); private: diff --git a/lld/include/lld/ReaderWriter/CoreLinkingContext.h b/lld/include/lld/ReaderWriter/CoreLinkingContext.h index d7200a627de4..9f6fcdd05745 100644 --- a/lld/include/lld/ReaderWriter/CoreLinkingContext.h +++ b/lld/include/lld/ReaderWriter/CoreLinkingContext.h @@ -35,8 +35,8 @@ protected: virtual Writer &writer() const; private: - mutable std::unique_ptr _reader; - mutable std::unique_ptr _writer; + std::unique_ptr _reader; + std::unique_ptr _writer; std::vector _passNames; }; diff --git a/lld/include/lld/ReaderWriter/ELFLinkingContext.h b/lld/include/lld/ReaderWriter/ELFLinkingContext.h index ec933706a058..9a244300ccda 100644 --- a/lld/include/lld/ReaderWriter/ELFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/ELFLinkingContext.h @@ -230,7 +230,6 @@ protected: bool _noAllowDynamicLibraries; OutputMagic _outputMagic; StringRefVector _inputSearchPaths; - mutable llvm::BumpPtrAllocator _alloc; std::unique_ptr _elfReader; std::unique_ptr _writer; std::unique_ptr _linkerScriptReader; diff --git a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h index f626c7cec09f..4f09d14ee838 100644 --- a/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h +++ b/lld/include/lld/ReaderWriter/PECOFFLinkingContext.h @@ -162,7 +162,7 @@ public: virtual ErrorOr stringFromRelocKind(Reference::Kind kind) const; StringRef allocateString(StringRef ref) const { - char *x = _alloc.Allocate(ref.size() + 1); + char *x = _allocator.Allocate(ref.size() + 1); memcpy(x, ref.data(), ref.size()); x[ref.size()] = '\0'; return x; @@ -211,9 +211,8 @@ private: std::set _noDefaultLibs; std::vector _inputSearchPaths; - mutable std::unique_ptr _reader; - mutable std::unique_ptr _writer; - mutable llvm::BumpPtrAllocator _alloc; + std::unique_ptr _reader; + std::unique_ptr _writer; }; } // end namespace lld diff --git a/lld/lib/Core/LinkingContext.cpp b/lld/lib/Core/LinkingContext.cpp index 5d5d34fb1492..22a9ccf6e051 100644 --- a/lld/lib/Core/LinkingContext.cpp +++ b/lld/lib/Core/LinkingContext.cpp @@ -76,11 +76,11 @@ bool LinkingContext::createInternalFiles( return true; } -void LinkingContext::setResolverState(uint32_t state) const { +void LinkingContext::setResolverState(uint32_t state) { _currentInputElement->setResolverState(state); } -ErrorOr LinkingContext::nextFile() const { +ErrorOr LinkingContext::nextFile() { // When nextFile() is called for the first time, _currentInputElement is not // initialized. Initialize it with the first element of the input graph. if (_currentInputElement == nullptr) { diff --git a/lld/lib/Driver/Driver.cpp b/lld/lib/Driver/Driver.cpp index 077afdaa6542..e0b81eae8593 100644 --- a/lld/lib/Driver/Driver.cpp +++ b/lld/lib/Driver/Driver.cpp @@ -28,7 +28,7 @@ namespace lld { /// This is where the link is actually performed. -bool Driver::link(const LinkingContext &context, raw_ostream &diagnostics) { +bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) { // Honor -mllvm if (!context.llvmOptions().empty()) { unsigned numArgs = context.llvmOptions().size(); diff --git a/lld/lib/ReaderWriter/CoreLinkingContext.cpp b/lld/lib/ReaderWriter/CoreLinkingContext.cpp index bc9a009673de..db17d57d43ed 100644 --- a/lld/lib/ReaderWriter/CoreLinkingContext.cpp +++ b/lld/lib/ReaderWriter/CoreLinkingContext.cpp @@ -271,8 +271,9 @@ private: CoreLinkingContext::CoreLinkingContext() {} -bool CoreLinkingContext::validateImpl(raw_ostream &diagnostics) { +bool CoreLinkingContext::validateImpl(raw_ostream &) { _reader = createReaderYAML(*this); + _writer = createWriterYAML(*this); return true; } @@ -289,11 +290,7 @@ void CoreLinkingContext::addPasses(PassManager &pm) const { } } -Writer &CoreLinkingContext::writer() const { - if (!_writer) - _writer = createWriterYAML(*this); - return *_writer; -} +Writer &CoreLinkingContext::writer() const { return *_writer; } ErrorOr CoreLinkingContext::relocKindFromString(StringRef str) const { diff --git a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp index 6d7f786e002e..bf1a4a7c3b8a 100644 --- a/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ b/lld/lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -167,7 +167,7 @@ llvm::ErrorOr ELFLinkingContext::searchLibrary( } } if (foundFile) - return StringRef(*new (_alloc) std::string(pathref)); + return StringRef(*new (_allocator) std::string(pathref)); } if (!llvm::sys::fs::exists(libName)) return llvm::make_error_code(llvm::errc::no_such_file_or_directory);