/// specified name and return the File object for that member, or nullptr.
virtual const File *find(StringRef name, bool dataSymbolOnly) const = 0;
- virtual error_code
+ virtual std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) const = 0;
/// Returns a set of all defined symbols in the archive, i.e. all
virtual bool dump(raw_ostream &diagnostics) { return true; }
/// \brief parse the input element
- virtual error_code parse(const LinkingContext &, raw_ostream &) = 0;
+ virtual std::error_code parse(const LinkingContext &, raw_ostream &) = 0;
/// \brief functions for the resolver to use
}
/// \brief Parse the group members.
- error_code parse(const LinkingContext &ctx, raw_ostream &diag) override {
+ std::error_code parse(const LinkingContext &ctx, raw_ostream &diag) override {
for (std::unique_ptr<InputElement> &ei : _elements)
- if (error_code ec = ei->parse(ctx, diag))
+ if (std::error_code ec = ei->parse(ctx, diag))
return ec;
- return error_code();
+ return std::error_code();
}
/// If Resolver made a progress using the current file, it's ok to revisit
}
/// \brief create an error string for printing purposes
- virtual std::string errStr(error_code errc) {
+ virtual std::string errStr(std::error_code errc) {
std::string msg = errc.message();
Twine twine = Twine("Cannot open ") + _path + ": " + msg;
return twine.str();
protected:
/// \brief Read the file into _buffer.
- error_code getBuffer(StringRef filePath);
+ std::error_code getBuffer(StringRef filePath);
StringRef _path; // The path of the Input file
InputGraph::FileVectorT _files; // A vector of lld File objects
}
/// \brief parse the input element
- error_code parse(const LinkingContext &, raw_ostream &) override {
- return error_code();
+ std::error_code parse(const LinkingContext &, raw_ostream &) override {
+ return std::error_code();
}
/// \brief Return the next File thats part of this node to the
using llvm::SaveAndRestore;
using llvm::ErrorOr;
- using std::error_code;
using llvm::raw_ostream;
} // end namespace lld.
/// Calls through to the writeFile() method on the specified Writer.
///
/// \param linkedFile This is the merged/linked graph of all input file Atoms.
- virtual error_code writeFile(const File &linkedFile) const;
+ virtual std::error_code writeFile(const File &linkedFile) const;
/// Return the next ordinal and Increment it.
virtual uint64_t getNextOrdinalAndIncrement() const { return _nextOrdinal++; }
_passes.push_back(std::move(pass));
}
- error_code runOnFile(std::unique_ptr<MutableFile> &file) {
+ std::error_code runOnFile(std::unique_ptr<MutableFile> &file) {
for (std::unique_ptr<Pass> &pass : _passes)
pass->perform(file);
- return error_code();
+ return std::error_code();
}
private:
CoreFileNode(CoreLinkingContext &, StringRef path) : FileNode(path) {}
/// \brief Parse the input file to lld::File.
- error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) override {
+ std::error_code parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) override {
using std::make_error_code;
ErrorOr<StringRef> filePath = getPath(ctx);
if (filePath.getError() == std::errc::no_such_file_or_directory)
// Create a memory buffer
std::unique_ptr<MemoryBuffer> mb;
- if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, mb))
+ if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, mb))
return ec;
_buffer = std::move(mb);
: FileNode(path), _isWholeArchive(isWholeArchive) {}
/// \brief Parse the input file to lld::File.
- error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) override {
+ std::error_code parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) override {
ErrorOr<StringRef> filePath = getPath(ctx);
- if (error_code ec = filePath.getError())
+ if (std::error_code ec = filePath.getError())
return ec;
- if (error_code ec = getBuffer(*filePath))
+ if (std::error_code ec = getBuffer(*filePath))
return ec;
if (ctx.logInputFiles())
if (_isWholeArchive) {
std::vector<std::unique_ptr<File>> parsedFiles;
- error_code ec = ctx.registry().parseFile(_buffer, parsedFiles);
+ std::error_code ec = ctx.registry().parseFile(_buffer, parsedFiles);
if (ec)
return ec;
assert(parsedFiles.size() == 1);
} else {
// if --whole-archive is around non-archive, just use it as normal.
_files.push_back(std::move(f));
- return error_code();
+ return std::error_code();
}
}
return ctx.registry().parseFile(_buffer, _files);
ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
/// \brief create an error string for printing purposes
- std::string errStr(error_code) override;
+ std::string errStr(std::error_code) override;
/// \brief Dump the Input Element
bool dump(raw_ostream &diagnostics) override {
}
/// \brief Parse the input file to lld::File.
- error_code parse(const LinkingContext &, raw_ostream &) override;
+ std::error_code parse(const LinkingContext &, raw_ostream &) override;
/// \brief This is used by Group Nodes, when there is a need to reset the
/// the file to be processed next. When handling a group node that contains
: FileNode(userPath), _elfLinkingContext(ctx), _linkerScript(nullptr) {}
/// \brief Parse the linker script.
- error_code parse(const LinkingContext &, raw_ostream &) override;
+ std::error_code parse(const LinkingContext &, raw_ostream &) override;
protected:
ELFLinkingContext &_elfLinkingContext;
ELFGNULdScript(ELFLinkingContext &ctx, StringRef userPath)
: GNULdScript(ctx, userPath) {}
- error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) override;
+ std::error_code parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) override;
bool getReplacements(InputGraph::InputElementVectorT &result) override {
for (std::unique_ptr<InputElement> &elt : _expandElements)
ErrorOr<StringRef> getPath(const LinkingContext &ctx) const override;
/// \brief Parse the input file to lld::File.
- error_code parse(const LinkingContext &ctx, raw_ostream &diagnostics) override;
+ std::error_code parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) override;
ErrorOr<File &> getNextFile() override;
PECOFFGroup(PECOFFLinkingContext &ctx) : Group(), _ctx(ctx) {}
/// \brief Parse the group members.
- error_code parse(const LinkingContext &ctx, raw_ostream &diag) override {
+ std::error_code parse(const LinkingContext &ctx, raw_ostream &diag) override {
std::lock_guard<std::recursive_mutex> lock(_ctx.getMutex());
return Group::parse(ctx, diag);
}
/// file) and create a File object.
///
/// The resulting File object may take ownership of the MemoryBuffer.
- virtual error_code
+ virtual std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const = 0;
};
/// Walk the list of registered Readers and find one that can parse the
/// supplied file and parse it.
- error_code parseFile(std::unique_ptr<MemoryBuffer> &mb,
- std::vector<std::unique_ptr<File>> &result) const;
+ std::error_code parseFile(std::unique_ptr<MemoryBuffer> &mb,
+ std::vector<std::unique_ptr<File>> &result) const;
/// Walk the list of registered kind tables to convert a Reference Kind
/// name to a value.
virtual ~Writer();
/// \brief Write a file from the supplied File object
- virtual error_code writeFile(const File &linkedFile, StringRef path) = 0;
+ virtual std::error_code writeFile(const File &linkedFile, StringRef path) = 0;
/// \brief This method is called by Core Linking to give the Writer a chance
/// to add file format specific "files" to set of files to be linked. This is
}
/// \brief Read the file into _buffer.
-error_code FileNode::getBuffer(StringRef filePath) {
+std::error_code FileNode::getBuffer(StringRef filePath) {
// Create a memory buffer
std::unique_ptr<MemoryBuffer> mb;
- if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, mb))
+ if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, mb))
return ec;
_buffer = std::move(mb);
- return error_code();
+ return std::error_code();
}
/// \brief Return the next file that need to be processed by the resolver.
return validateImpl(diagnostics);
}
-error_code LinkingContext::writeFile(const File &linkedFile) const {
+std::error_code LinkingContext::writeFile(const File &linkedFile) const {
return this->writer().writeFile(linkedFile, _outputPath);
}
for (;;) {
ErrorOr<File &> file = _context.getInputGraph().getNextFile();
- error_code ec = file.getError();
+ std::error_code ec = file.getError();
if (ec == InputGraphError::no_more_files)
return true;
if (!file) {
std::string buf;
llvm::raw_string_ostream stream(buf);
- if (error_code ec = ie->parse(context, stream)) {
+ if (std::error_code ec = ie->parse(context, stream)) {
if (FileNode *fileNode = dyn_cast<FileNode>(ie.get()))
stream << fileNode->errStr(ec) << "\n";
else if (dyn_cast<Group>(ie.get()))
// Give linked atoms to Writer to generate output file.
ScopedTask writeTask(getDefaultDomain(), "Write");
- if (error_code ec = context.writeFile(*merged)) {
+ if (std::error_code ec = context.writeFile(*merged)) {
diagnostics << "Failed to write file '" << context.outputPath()
<< "': " << ec.message() << "\n";
return false;
}
// Get the Input file magic for creating appropriate InputGraph nodes.
-static error_code getFileMagic(ELFLinkingContext &ctx, StringRef path,
- llvm::sys::fs::file_magic &magic) {
- error_code ec = llvm::sys::fs::identify_magic(path, magic);
+static std::error_code getFileMagic(ELFLinkingContext &ctx, StringRef path,
+ llvm::sys::fs::file_magic &magic) {
+ std::error_code ec = llvm::sys::fs::identify_magic(path, magic);
if (ec)
return ec;
switch (magic) {
case llvm::sys::fs::file_magic::elf_relocatable:
case llvm::sys::fs::file_magic::elf_shared_object:
case llvm::sys::fs::file_magic::unknown:
- return error_code();
+ return std::error_code();
default:
break;
}
return _elfLinkingContext.searchFile(_path, _attributes._isSysRooted);
}
-std::string ELFFileNode::errStr(error_code errc) {
+std::string ELFFileNode::errStr(std::error_code errc) {
if (errc == std::errc::no_such_file_or_directory) {
if (_attributes._isDashlPrefix)
return (Twine("Unable to find library -l") + _path).str();
// FIXME: Calling getFileMagic() is expensive. It would be better to
// wire up the LdScript parser into the registry.
llvm::sys::fs::file_magic magic = llvm::sys::fs::file_magic::unknown;
- error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
+ std::error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
if (ec) {
diagnostics << "lld: unknown input file format for file " << userPath
<< "\n";
using namespace lld;
/// \brief Parse the input file to lld::File.
-error_code ELFFileNode::parse(const LinkingContext &ctx,
- raw_ostream &diagnostics) {
+std::error_code ELFFileNode::parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) {
ErrorOr<StringRef> filePath = getPath(ctx);
- if (error_code ec = filePath.getError())
+ if (std::error_code ec = filePath.getError())
return ec;
- if (error_code ec = getBuffer(*filePath))
+ if (std::error_code ec = getBuffer(*filePath))
return ec;
if (ctx.logInputFiles())
diagnostics << *filePath << "\n";
if (_attributes._isWholeArchive) {
std::vector<std::unique_ptr<File>> parsedFiles;
- if (error_code ec = ctx.registry().parseFile(_buffer, parsedFiles))
+ if (std::error_code ec = ctx.registry().parseFile(_buffer, parsedFiles))
return ec;
assert(parsedFiles.size() == 1);
std::unique_ptr<File> f(parsedFiles[0].release());
}
// if --whole-archive is around non-archive, just use it as normal.
_files.push_back(std::move(f));
- return error_code();
+ return std::error_code();
}
return ctx.registry().parseFile(_buffer, _files);
}
/// \brief Parse the GnuLD Script
-error_code GNULdScript::parse(const LinkingContext &ctx,
- raw_ostream &diagnostics) {
+std::error_code GNULdScript::parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) {
ErrorOr<StringRef> filePath = getPath(ctx);
- if (error_code ec = filePath.getError())
+ if (std::error_code ec = filePath.getError())
return ec;
- if (error_code ec = getBuffer(*filePath))
+ if (std::error_code ec = getBuffer(*filePath))
return ec;
if (ctx.logInputFiles())
if (!_linkerScript)
return LinkerScriptReaderError::parse_error;
- return error_code();
+ return std::error_code();
}
static bool isPathUnderSysroot(StringRef sysroot, StringRef path) {
}
/// \brief Handle GnuLD script for ELF.
-error_code ELFGNULdScript::parse(const LinkingContext &ctx,
- raw_ostream &diagnostics) {
+std::error_code ELFGNULdScript::parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) {
ELFFileNode::Attributes attributes;
- if (error_code ec = GNULdScript::parse(ctx, diagnostics))
+ if (std::error_code ec = GNULdScript::parse(ctx, diagnostics))
return ec;
StringRef sysRoot = _elfLinkingContext.getSysroot();
if (!sysRoot.empty() && isPathUnderSysroot(sysRoot, *getPath(ctx)))
}
_expandElements.push_back(std::move(groupStart));
}
- return error_code();
+ return std::error_code();
}
}
/// \brief Parse the input file to lld::File.
-error_code PECOFFFileNode::parse(const LinkingContext &ctx,
- raw_ostream &diagnostics) {
+std::error_code PECOFFFileNode::parse(const LinkingContext &ctx,
+ raw_ostream &diagnostics) {
if (_parsed)
- return error_code();
+ return std::error_code();
_parsed = true;
ErrorOr<StringRef> filePath = getPath(ctx);
- if (error_code ec = filePath.getError()) {
+ if (std::error_code ec = filePath.getError()) {
diagnostics << "File not found: " << _path << "\n";
return ec;
}
- if (error_code ec = getBuffer(*filePath)) {
+ if (std::error_code ec = getBuffer(*filePath)) {
diagnostics << "Cannot open file: " << *filePath << "\n";
return ec;
}
if (MemoryBuffer::getFile(tmpNativeFile.str(), mb))
return;
- error_code ec = _context.registry().parseFile(mb, _nativeFile);
+ std::error_code ec = _context.registry().parseFile(mb, _nativeFile);
if (ec) {
// Note: we need a way for Passes to report errors.
llvm_unreachable("native reader not registered or read error");
if (MemoryBuffer::getFile(tmpYAMLFile.str(), mb))
return;
- error_code ec = _context.registry().parseFile(mb, _yamlFile);
+ std::error_code ec = _context.registry().parseFile(mb, _yamlFile);
if (ec) {
// Note: we need a way for Passes to report errors.
llvm_unreachable("yaml reader not registered or read error");
bool useShlibUndefines) {
std::unique_ptr<DynamicFile> file(new DynamicFile(mb->getBufferIdentifier()));
- error_code ec;
+ std::error_code ec;
file->_objFile.reset(new llvm::object::ELFFile<ELFT>(mb.release(), ec));
if (ec)
/// \brief Read input sections and populate necessary data structures
/// to read them later and create atoms
- virtual error_code createAtomizableSections();
+ virtual std::error_code createAtomizableSections();
/// \brief Create mergeable atoms from sections that have the merge attribute
/// set
- virtual error_code createMergeableAtoms();
+ virtual std::error_code createMergeableAtoms();
/// \brief Add the symbols that the sections contain. The symbols will be
/// converted to atoms for
/// Undefined symbols, absolute symbols
- virtual error_code createSymbolsFromAtomizableSections();
+ virtual std::error_code createSymbolsFromAtomizableSections();
/// \brief Create individual atoms
- virtual error_code createAtoms();
+ virtual std::error_code createAtoms();
const atom_collection<DefinedAtom> &defined() const override {
return _definedAtoms;
template <class ELFT>
ErrorOr<std::unique_ptr<ELFFile<ELFT>>>
ELFFile<ELFT>::create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- error_code ec;
+ std::error_code ec;
std::unique_ptr<ELFFile<ELFT>> file(
new ELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
llvm_unreachable("unsupported e_machine value");
}
-template <class ELFT> error_code ELFFile<ELFT>::createAtomizableSections() {
+template <class ELFT>
+std::error_code ELFFile<ELFT>::createAtomizableSections() {
// Handle: SHT_REL and SHT_RELA sections:
// Increment over the sections, when REL/RELA section types are found add
// the contents to the RelocationReferences map.
auto sHdr = _objFile->getSection(section.sh_info);
auto sectionName = _objFile->getSectionName(sHdr);
- if (error_code ec = sectionName.getError())
+ if (std::error_code ec = sectionName.getError())
return ec;
auto rai(_objFile->begin_rela(§ion));
auto sHdr = _objFile->getSection(section.sh_info);
auto sectionName = _objFile->getSectionName(sHdr);
- if (error_code ec = sectionName.getError())
+ if (std::error_code ec = sectionName.getError())
return ec;
auto ri(_objFile->begin_rel(§ion));
}
}
_references.reserve(totalRelocs);
- return error_code();
+ return std::error_code();
}
-template <class ELFT> error_code ELFFile<ELFT>::createMergeableAtoms() {
+template <class ELFT> std::error_code ELFFile<ELFT>::createMergeableAtoms() {
// Divide the section that contains mergeable strings into tokens
// TODO
// a) add resolver support to recognize multibyte chars
std::vector<MergeString *> tokens;
for (const Elf_Shdr *msi : _mergeStringSections) {
auto sectionName = getSectionName(msi);
- if (error_code ec = sectionName.getError())
+ if (std::error_code ec = sectionName.getError())
return ec;
auto sectionContents = getSectionContents(msi);
- if (error_code ec = sectionContents.getError())
+ if (std::error_code ec = sectionContents.getError())
return ec;
StringRef secCont(reinterpret_cast<const char *>(sectionContents->begin()),
_definedAtoms._atoms.push_back(*mergeAtom);
_mergeAtoms.push_back(*mergeAtom);
}
- return error_code();
+ return std::error_code();
}
template <class ELFT>
-error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() {
+std::error_code ELFFile<ELFT>::createSymbolsFromAtomizableSections() {
// Increment over all the symbols collecting atoms and symbol names for
// later use.
auto SymI = _objFile->begin_symbols(), SymE = _objFile->end_symbols();
const Elf_Shdr *section = _objFile->getSection(&*SymI);
auto symbolName = _objFile->getSymbolName(SymI);
- if (error_code ec = symbolName.getError())
+ if (std::error_code ec = symbolName.getError())
return ec;
if (isAbsoluteSymbol(&*SymI)) {
}
}
- return error_code();
+ return std::error_code();
}
-template <class ELFT> error_code ELFFile<ELFT>::createAtoms() {
+template <class ELFT> std::error_code ELFFile<ELFT>::createAtoms() {
for (auto &i : _sectionSymbols) {
const Elf_Shdr *section = i.first;
Elf_Sym_Iter B) { return A->st_value < B->st_value; });
ErrorOr<StringRef> sectionName = this->getSectionName(section);
- if (error_code ec = sectionName.getError())
+ if (std::error_code ec = sectionName.getError())
return ec;
auto sectionContents = getSectionContents(section);
- if (error_code ec = sectionContents.getError())
+ if (std::error_code ec = sectionContents.getError())
return ec;
if (handleSectionWithNoSymbols(section, symbols)) {
StringRef symbolName = "";
if (symbol->getType() != llvm::ELF::STT_SECTION) {
auto symName = _objFile->getSymbolName(symbol);
- if (error_code ec = symName.getError())
+ if (std::error_code ec = symName.getError())
return ec;
symbolName = *symName;
}
}
updateReferences();
- return error_code();
+ return std::error_code();
}
template <class ELFT>
return (magic == llvm::sys::fs::file_magic::elf_relocatable);
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment =
auto f = createELF<ELFFileCreateELFTraits>(
llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
_atomizeStrings);
- if (error_code ec = f.getError())
+ if (std::error_code ec = f.getError())
return ec;
result.push_back(std::move(*f));
- return error_code();
+ return std::error_code();
}
protected:
return (magic == llvm::sys::fs::file_magic::elf_shared_object);
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
std::size_t maxAlignment =
auto f = createELF<DynamicFileCreateELFTraits>(
llvm::object::getElfArchType(&*mb), maxAlignment, std::move(mb),
_useUndefines);
- if (error_code ec = f.getError())
+ if (std::error_code ec = f.getError())
return ec;
result.push_back(std::move(*f));
- return error_code();
+ return std::error_code();
}
protected:
: ELFFile<ELFT>(name, atomizeStrings) {}
MipsELFFile(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings,
- error_code &ec)
+ std::error_code &ec)
: ELFFile<ELFT>(std::move(mb), atomizeStrings, ec) {}
static ErrorOr<std::unique_ptr<MipsELFFile>>
create(std::unique_ptr<MemoryBuffer> mb, bool atomizeStrings) {
- error_code ec;
+ std::error_code ec;
std::unique_ptr<MipsELFFile<ELFT>> file(
new MipsELFFile<ELFT>(mb->getBufferIdentifier(), atomizeStrings));
referenceStart, referenceEnd, referenceList);
}
- error_code readAuxData() {
+ std::error_code readAuxData() {
typedef llvm::object::Elf_RegInfo<ELFT> Elf_RegInfo;
for (const Elf_Shdr §ion : this->_objFile->sections()) {
if (!_gp0.hasValue() && section.sh_type == llvm::ELF::SHT_MIPS_REGINFO) {
auto contents = this->getSectionContents(§ion);
- if (error_code ec = contents.getError())
+ if (std::error_code ec = contents.getError())
return ec;
ArrayRef<uint8_t> raw = contents.get();
_dtpOff = section.sh_addr + DTP_OFFSET;
}
}
- return error_code();
+ return std::error_code();
}
void createRelocationReferences(const Elf_Sym &symbol,
template <class ELFT> class TargetRelocationHandler {
public:
- virtual error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
- const lld::AtomLayout &,
- const Reference &) const = 0;
+ virtual std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &,
+ const lld::AtomLayout &,
+ const Reference &) const = 0;
virtual ~TargetRelocationHandler() {}
};
virtual void buildChunks(const File &file) = 0;
/// \brief Writes the chunks into the output file specified by path
- virtual error_code writeFile(const File &file, StringRef path) = 0;
+ virtual std::error_code writeFile(const File &file, StringRef path) = 0;
/// \brief Get the virtual address of \p atom after layout.
virtual uint64_t addressOfAtom(const Atom *atom) = 0;
virtual bool isWholeArchive() const { return _isWholeArchive; }
/// \brief parse each member
- error_code
+ std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override {
for (auto mf = _archive->child_begin(), me = _archive->child_end();
mf != me; ++mf) {
- if (error_code ec = instantiateMember(mf, result))
+ if (std::error_code ec = instantiateMember(mf, result))
return ec;
}
- return error_code();
+ return std::error_code();
}
const atom_collection<DefinedAtom> &defined() const override {
return _absoluteAtoms;
}
- error_code buildTableOfContents() {
+ std::error_code buildTableOfContents() {
DEBUG_WITH_TYPE("FileArchive", llvm::dbgs()
<< "Table of contents for archive '"
<< _archive->getFileName() << "':\n");
i != e; ++i) {
StringRef name;
Archive::child_iterator member;
- if (error_code ec = i->getName(name))
+ if (std::error_code ec = i->getName(name))
return ec;
- if (error_code ec = i->getMember(member))
+ if (std::error_code ec = i->getMember(member))
return ec;
DEBUG_WITH_TYPE(
"FileArchive",
<< "'" << name << "'\n");
_symbolMemberMap[name] = member;
}
- return error_code();
+ return std::error_code();
}
/// Returns a set of all defined symbols in the archive.
}
protected:
- error_code
+ std::error_code
instantiateMember(Archive::child_iterator member,
std::vector<std::unique_ptr<File>> &result) const {
std::unique_ptr<MemoryBuffer> mb;
- if (error_code ec = member->getMemoryBuffer(mb, true))
+ if (std::error_code ec = member->getMemoryBuffer(mb, true))
return ec;
if (_logLoading)
llvm::outs() << mb->getBufferIdentifier() << "\n";
_registry.parseFile(mb, result);
const char *memberStart = member->getBuffer().data();
_membersInstantiated.insert(memberStart);
- return error_code();
+ return std::error_code();
}
// Parses the given memory buffer as an object file, and returns success error
// code if the given symbol is a data symbol. If the symbol is not a data
// symbol or does not exist, returns a failure.
- error_code isDataSymbol(std::unique_ptr<MemoryBuffer> mb, StringRef symbol) const {
+ std::error_code isDataSymbol(std::unique_ptr<MemoryBuffer> mb,
+ StringRef symbol) const {
auto objOrErr(ObjectFile::createObjectFile(mb.release()));
if (auto ec = objOrErr.getError())
return ec;
for (symbol_iterator i = ibegin; i != iend; ++i) {
// Get symbol name
- if (error_code ec = i->getName(symbolname))
+ if (std::error_code ec = i->getName(symbolname))
return ec;
if (symbolname != symbol)
continue;
continue;
// Get Symbol Type
- if (error_code ec = i->getType(symtype))
+ if (std::error_code ec = i->getType(symtype))
return ec;
if (symtype == SymbolRef::ST_Data)
- return error_code();
+ return std::error_code();
}
return object_error::parse_failed;
}
return (magic == llvm::sys::fs::file_magic::archive);
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®,
std::vector<std::unique_ptr<File>> &result) const override {
// Make Archive object which will be owned by FileArchive object.
- error_code ec;
+ std::error_code ec;
Archive *archive = new Archive(mb.get(), ec);
if (ec)
return ec;
mb.release();
result.push_back(std::move(file));
- return error_code();
+ return std::error_code();
}
private:
const MachOLinkingContext::Arch arch);
/// Takes in-memory normalized view and writes a mach-o object file.
-error_code
-writeBinary(const NormalizedFile &file, StringRef path);
+std::error_code writeBinary(const NormalizedFile &file, StringRef path);
size_t headerAndLoadCommandsSize(const NormalizedFile &file);
readYaml(std::unique_ptr<MemoryBuffer> &mb);
/// Writes a yaml encoded mach-o files given an in-memory normalized view.
-error_code
-writeYaml(const NormalizedFile &file, raw_ostream &out);
-
+std::error_code writeYaml(const NormalizedFile &file, raw_ostream &out);
/// Takes in-memory normalized dylib or object and parses it into lld::File
ErrorOr<std::unique_ptr<lld::File>>
namespace normalized {
// Utility to call a lambda expression on each load command.
-static error_code
-forEachLoadCommand(StringRef lcRange, unsigned lcCount, bool swap, bool is64,
- std::function<bool (uint32_t cmd, uint32_t size,
- const char* lc)> func) {
+static std::error_code forEachLoadCommand(
+ StringRef lcRange, unsigned lcCount, bool swap, bool is64,
+ std::function<bool(uint32_t cmd, uint32_t size, const char *lc)> func) {
const char* p = lcRange.begin();
for (unsigned i=0; i < lcCount; ++i) {
const load_command *lc = reinterpret_cast<const load_command*>(p);
return std::make_error_code(std::errc::executable_format_error);
if (func(slc->cmd, slc->cmdsize, p))
- return error_code();
+ return std::error_code();
p += slc->cmdsize;
}
- return error_code();
+ return std::error_code();
}
-
-static error_code
-appendRelocations(Relocations &relocs, StringRef buffer, bool swap,
- bool bigEndian, uint32_t reloff, uint32_t nreloc) {
+static std::error_code appendRelocations(Relocations &relocs, StringRef buffer,
+ bool swap, bool bigEndian,
+ uint32_t reloff, uint32_t nreloc) {
if ((reloff + nreloc*8) > buffer.size())
return std::make_error_code(std::errc::executable_format_error);
const any_relocation_info* relocsArray =
for(uint32_t i=0; i < nreloc; ++i) {
relocs.push_back(unpackRelocation(relocsArray[i], swap, bigEndian));
}
- return error_code();
+ return std::error_code();
}
-static error_code
+static std::error_code
appendIndirectSymbols(IndirectSymbols &isyms, StringRef buffer, bool swap,
bool bigEndian, uint32_t istOffset, uint32_t istCount,
uint32_t startIndex, uint32_t count) {
for(uint32_t i=0; i < count; ++i) {
isyms.push_back(read32(swap, indirectSymbolArray[startIndex+i]));
}
- return error_code();
+ return std::error_code();
}
// Pre-scan load commands looking for indirect symbol table.
uint32_t indirectSymbolTableOffset = 0;
uint32_t indirectSymbolTableCount = 0;
- error_code ec = forEachLoadCommand(lcRange, lcCount, swap, is64,
- [&] (uint32_t cmd, uint32_t size, const char* lc) -> bool {
+ std::error_code ec = forEachLoadCommand(lcRange, lcCount, swap, is64,
+ [&](uint32_t cmd, uint32_t size,
+ const char *lc) -> bool {
if (cmd == LC_DYSYMTAB) {
const dysymtab_command *d = reinterpret_cast<const dysymtab_command*>(lc);
indirectSymbolTableOffset = read32(swap, d->indirectsymoff);
return true;
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry,
- std::vector<std::unique_ptr<File> > &result) const override {
+ std::vector<std::unique_ptr<File>> &result) const override {
// Convert binary file to normalized mach-o.
auto normFile = readBinary(mb, _arch);
- if (error_code ec = normFile.getError())
+ if (std::error_code ec = normFile.getError())
return ec;
// Convert normalized mach-o to atoms.
auto file = normalizedToAtoms(**normFile, mb->getBufferIdentifier(), false);
- if (error_code ec = file.getError())
+ if (std::error_code ec = file.getError())
return ec;
result.push_back(std::move(*file));
- return error_code();
+ return std::error_code();
}
private:
MachOLinkingContext::Arch _arch;
/// Writes the normalized file as a binary mach-o file to the specified
/// path. This does not have a stream interface because the generated
/// file may need the 'x' bit set.
- error_code writeBinary(StringRef path);
+ std::error_code writeBinary(StringRef path);
private:
uint32_t loadCommandsSize(uint32_t &count);
void buildFileOffsets();
void writeMachHeader();
- error_code writeLoadCommands();
+ std::error_code writeLoadCommands();
void writeSectionContent();
void writeRelocations();
void writeSymbolTable();
};
template <typename T>
- error_code writeSingleSegmentLoadCommand(uint8_t *&lc);
- template <typename T>
- error_code writeSegmentLoadCommands(uint8_t *&lc);
+ std::error_code writeSingleSegmentLoadCommand(uint8_t *&lc);
+ template <typename T> std::error_code writeSegmentLoadCommands(uint8_t *&lc);
uint32_t pointerAlign(uint32_t value);
static StringRef dyldPath();
typedef std::map<const Section*, SectionExtraInfo> SectionMap;
const NormalizedFile &_file;
- error_code _ec;
+ std::error_code _ec;
uint8_t *_buffer;
const bool _is64;
const bool _swap;
return sect.content.size() / sect.indirectSymbols.size();
}
-
-
template <typename T>
-error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
+std::error_code MachOFileLayout::writeSingleSegmentLoadCommand(uint8_t *&lc) {
typename T::command* seg = reinterpret_cast<typename T::command*>(lc);
seg->cmd = T::LC;
seg->cmdsize = sizeof(typename T::command)
++sout;
}
lc = next;
- return error_code();
+ return std::error_code();
}
-
template <typename T>
-error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
+std::error_code MachOFileLayout::writeSegmentLoadCommands(uint8_t *&lc) {
uint32_t indirectSymRunningIndex = 0;
for (const Segment &seg : _file.segments) {
// Write segment command with trailing sections.
if (_swap)
swapStruct(*cmd);
lc = next;
- return error_code();
+ return std::error_code();
}
-
-error_code MachOFileLayout::writeLoadCommands() {
- error_code ec;
+std::error_code MachOFileLayout::writeLoadCommands() {
+ std::error_code ec;
uint8_t *lc = &_buffer[_startOfLoadCommands];
if (_file.fileType == llvm::MachO::MH_OBJECT) {
// Object files have one unnamed segment which holds all sections.
}
}
-
-error_code MachOFileLayout::writeBinary(StringRef path) {
+std::error_code MachOFileLayout::writeBinary(StringRef path) {
// Check for pending error from constructor.
if (_ec)
return _ec;
unsigned flags = 0;
if (_file.fileType != llvm::MachO::MH_OBJECT)
flags = llvm::FileOutputBuffer::F_executable;
- error_code ec;
+ std::error_code ec;
ec = llvm::FileOutputBuffer::create(path, size(), fob, flags);
if (ec)
return ec;
writeLinkEditContent();
fob->commit();
- return error_code();
+ return std::error_code();
}
/// Takes in-memory normalized view and writes a mach-o object file.
-error_code
-writeBinary(const NormalizedFile &file, StringRef path) {
+std::error_code writeBinary(const NormalizedFile &file, StringRef path) {
MachOFileLayout layout(file);
return layout.writeBinary(path);
}
}
}
-error_code processSymboledSection(DefinedAtom::ContentType atomType,
- const Section §ion,
- const NormalizedFile &normalizedFile,
- MachOFile &file, bool copyRefs) {
+std::error_code processSymboledSection(DefinedAtom::ContentType atomType,
+ const Section §ion,
+ const NormalizedFile &normalizedFile,
+ MachOFile &file, bool copyRefs) {
// Find section's index.
uint32_t sectIndex = 1;
for (auto § : normalizedFile.sections) {
// If section has no symbols and no content, there are no atoms.
if (symbols.empty() && section.content.empty())
- return error_code();
+ return std::error_code();
const uint64_t firstSymbolAddr = symbols.front()->value;
if (firstSymbolAddr != section.address) {
lastSym->desc, atomScope(lastSym->scope),
section.address + section.content.size(), copyRefs);
}
- return error_code();
+ return std::error_code();
}
-error_code processSection(DefinedAtom::ContentType atomType,
- const Section §ion,
- const NormalizedFile &normalizedFile,
- MachOFile &file, bool copyRefs) {
+std::error_code processSection(DefinedAtom::ContentType atomType,
+ const Section §ion,
+ const NormalizedFile &normalizedFile,
+ MachOFile &file, bool copyRefs) {
const bool is64 = MachOLinkingContext::is64Bit(normalizedFile.arch);
const bool swap = !MachOLinkingContext::isHostEndian(normalizedFile.arch);
offset += size;
}
}
- return error_code();
+ return std::error_code();
}
ErrorOr<std::unique_ptr<lld::File>>
// Create atoms from each section.
for (auto § : normalizedFile.sections) {
DefinedAtom::ContentType atomType = atomTypeFromSection(sect);
- if (error_code ec = processSection(atomType, sect, normalizedFile, *file,
- copyRefs))
+ if (std::error_code ec =
+ processSection(atomType, sect, normalizedFile, *file, copyRefs))
return ec;
}
// Create atoms from undefined symbols.
public:
MachOWriter(const MachOLinkingContext &ctxt) : _context(ctxt) { }
- error_code writeFile(const lld::File &file, StringRef path) override {
+ std::error_code writeFile(const lld::File &file, StringRef path) override {
// Construct empty normalized file from atoms.
ErrorOr<std::unique_ptr<NormalizedFile>> nFile =
normalized::normalizedFromAtoms(file, _context);
- if (error_code ec = nFile.getError())
+ if (std::error_code ec = nFile.getError())
return ec;
// For testing, write out yaml form of normalized file.
/// Instantiates a File object from a native object file. Ownership
/// of the MemoryBuffer is transferred to the resulting File object.
- static error_code make(std::unique_ptr<MemoryBuffer> mb,
- std::vector<std::unique_ptr<lld::File>> &result) {
+ static std::error_code make(std::unique_ptr<MemoryBuffer> mb,
+ std::vector<std::unique_ptr<lld::File>> &result) {
const uint8_t *const base =
reinterpret_cast<const uint8_t *>(mb->getBufferStart());
StringRef path(mb->getBufferIdentifier());
// process each chunk
for (uint32_t i = 0; i < header->chunkCount; ++i) {
- error_code ec;
+ std::error_code ec;
const NativeChunk* chunk = &chunks[i];
// sanity check chunk is within file
if ( chunk->fileOffset > fileSize )
friend NativeReferenceV2;
// instantiate array of DefinedAtoms from v1 ivar data in file
- error_code processDefinedAtomsV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processDefinedAtomsV1(const uint8_t *base,
+ const NativeChunk *chunk) {
const size_t atomSize = sizeof(NativeDefinedAtomV1);
size_t atomsArraySize = chunk->elementCount * atomSize;
uint8_t* atomsStart = reinterpret_cast<uint8_t*>
// set up pointers to attributes array
- error_code processAttributesV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processAttributesV1(const uint8_t *base,
+ const NativeChunk *chunk) {
this->_attributes = base + chunk->fileOffset;
this->_attributesMaxOffset = chunk->fileSize;
DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs()
}
// set up pointers to attributes array
- error_code processAbsoluteAttributesV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processAbsoluteAttributesV1(const uint8_t *base,
+ const NativeChunk *chunk) {
this->_absAttributes = base + chunk->fileOffset;
this->_absAbsoluteMaxOffset = chunk->fileSize;
DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs()
}
// instantiate array of UndefinedAtoms from v1 ivar data in file
- error_code processUndefinedAtomsV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processUndefinedAtomsV1(const uint8_t *base,
+ const NativeChunk *chunk) {
const size_t atomSize = sizeof(NativeUndefinedAtomV1);
size_t atomsArraySize = chunk->elementCount * atomSize;
uint8_t* atomsStart = reinterpret_cast<uint8_t*>
// instantiate array of ShareLibraryAtoms from v1 ivar data in file
- error_code processSharedLibraryAtomsV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processSharedLibraryAtomsV1(const uint8_t *base,
+ const NativeChunk *chunk) {
const size_t atomSize = sizeof(NativeSharedLibraryAtomV1);
size_t atomsArraySize = chunk->elementCount * atomSize;
uint8_t* atomsStart = reinterpret_cast<uint8_t*>
// instantiate array of AbsoluteAtoms from v1 ivar data in file
- error_code processAbsoluteAtomsV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processAbsoluteAtomsV1(const uint8_t *base,
+ const NativeChunk *chunk) {
const size_t atomSize = sizeof(NativeAbsoluteAtomV1);
size_t atomsArraySize = chunk->elementCount * atomSize;
uint8_t* atomsStart = reinterpret_cast<uint8_t*>
return make_error_code(NativeReaderError::success);
}
- template<class T, class U>
- error_code processReferences(const uint8_t *base, const NativeChunk *chunk,
- uint8_t *&refsStart, uint8_t *&refsEnd) const {
+ template <class T, class U>
+ std::error_code
+ processReferences(const uint8_t *base, const NativeChunk *chunk,
+ uint8_t *&refsStart, uint8_t *&refsEnd) const {
if (chunk->elementCount == 0)
return make_error_code(NativeReaderError::success);
size_t refsArraySize = chunk->elementCount * sizeof(T);
}
// instantiate array of References from v1 ivar data in file
- error_code processReferencesV1(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processReferencesV1(const uint8_t *base,
+ const NativeChunk *chunk) {
uint8_t *refsStart, *refsEnd;
- if (error_code ec
- = processReferences<NativeReferenceV1, NativeReferenceIvarsV1>(
+ if (std::error_code ec =
+ processReferences<NativeReferenceV1, NativeReferenceIvarsV1>(
base, chunk, refsStart, refsEnd))
return ec;
this->_referencesV1.arrayStart = refsStart;
}
// instantiate array of References from v2 ivar data in file
- error_code processReferencesV2(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processReferencesV2(const uint8_t *base,
+ const NativeChunk *chunk) {
uint8_t *refsStart, *refsEnd;
- if (error_code ec
- = processReferences<NativeReferenceV2, NativeReferenceIvarsV2>(
+ if (std::error_code ec =
+ processReferences<NativeReferenceV2, NativeReferenceIvarsV2>(
base, chunk, refsStart, refsEnd))
return ec;
this->_referencesV2.arrayStart = refsStart;
}
// set up pointers to target table
- error_code processTargetsTable(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processTargetsTable(const uint8_t *base,
+ const NativeChunk *chunk) {
const uint32_t* targetIndexes = reinterpret_cast<const uint32_t*>
(base + chunk->fileOffset);
this->_targetsTableCount = chunk->elementCount;
// set up pointers to addend pool in file
- error_code processAddendsTable(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processAddendsTable(const uint8_t *base,
+ const NativeChunk *chunk) {
this->_addends = reinterpret_cast<const Reference::Addend*>
(base + chunk->fileOffset);
this->_addendsMaxIndex = chunk->elementCount;
}
// set up pointers to string pool in file
- error_code processStrings(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processStrings(const uint8_t *base,
+ const NativeChunk *chunk) {
this->_strings = reinterpret_cast<const char*>(base + chunk->fileOffset);
this->_stringsMaxOffset = chunk->fileSize;
DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs()
}
// set up pointers to content area in file
- error_code processContent(const uint8_t *base,
- const NativeChunk *chunk) {
+ std::error_code processContent(const uint8_t *base,
+ const NativeChunk *chunk) {
this->_contentStart = base + chunk->fileOffset;
this->_contentEnd = base + chunk->fileOffset + chunk->fileSize;
DEBUG_WITH_TYPE("ReaderNative", llvm::dbgs()
sizeof(header->magic)) == 0);
}
- virtual error_code
+ virtual std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
return lld::native::File::make(std::move(mb), result);
- return error_code();
+ return std::error_code();
}
};
}
public:
Writer(const LinkingContext &context) {}
- error_code writeFile(const lld::File &file, StringRef outPath) override {
+ std::error_code writeFile(const lld::File &file, StringRef outPath) override {
// reserve first byte for unnamed atoms
_stringPool.push_back('\0');
// visit all atoms
llvm::raw_fd_ostream out(outPath.data(), errorInfo,
llvm::sys::fs::F_None);
if (!errorInfo.empty())
- return error_code(); // FIXME
+ return std::error_code(); // FIXME
this->write(out);
- return error_code();
+ return std::error_code();
}
virtual ~Writer() {
return _absoluteAtoms;
}
- error_code
+ std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override {
- return error_code();
+ return std::error_code();
}
private:
public:
typedef const std::map<std::string, std::string> StringMap;
- FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec);
+ FileCOFF(std::unique_ptr<MemoryBuffer> mb, std::error_code &ec);
- error_code parse();
+ std::error_code parse();
StringRef getLinkerDirectives() const { return _directives; }
bool isCompatibleWithSEH() const { return _compatibleWithSEH; }
mutable llvm::BumpPtrAllocator _alloc;
private:
- error_code readSymbolTable(std::vector<const coff_symbol *> &result);
+ std::error_code readSymbolTable(std::vector<const coff_symbol *> &result);
void createAbsoluteAtoms(const SymbolVectorT &symbols,
std::vector<const AbsoluteAtom *> &result);
- error_code createUndefinedAtoms(const SymbolVectorT &symbols,
- std::vector<const UndefinedAtom *> &result);
+ std::error_code
+ createUndefinedAtoms(const SymbolVectorT &symbols,
+ std::vector<const UndefinedAtom *> &result);
- error_code createDefinedSymbols(const SymbolVectorT &symbols,
- std::vector<const DefinedAtom *> &result);
+ std::error_code
+ createDefinedSymbols(const SymbolVectorT &symbols,
+ std::vector<const DefinedAtom *> &result);
- error_code cacheSectionAttributes();
- error_code maybeCreateSXDataAtoms();
+ std::error_code cacheSectionAttributes();
+ std::error_code maybeCreateSXDataAtoms();
- error_code
+ std::error_code
AtomizeDefinedSymbolsInSection(const coff_section *section,
std::vector<const coff_symbol *> &symbols,
std::vector<COFFDefinedFileAtom *> &atoms);
- error_code
+ std::error_code
AtomizeDefinedSymbols(SectionToSymbolsT &definedSymbols,
std::vector<const DefinedAtom *> &definedAtoms);
- error_code findAtomAt(const coff_section *section, uint32_t targetAddress,
- COFFDefinedFileAtom *&result, uint32_t &offsetInAtom);
+ std::error_code findAtomAt(const coff_section *section,
+ uint32_t targetAddress,
+ COFFDefinedFileAtom *&result,
+ uint32_t &offsetInAtom);
- error_code getAtomBySymbolIndex(uint32_t index, Atom *&ret);
+ std::error_code getAtomBySymbolIndex(uint32_t index, Atom *&ret);
- error_code
+ std::error_code
addRelocationReference(const coff_relocation *rel,
const coff_section *section,
const std::vector<COFFDefinedFileAtom *> &atoms);
- error_code getSectionContents(StringRef sectionName,
- ArrayRef<uint8_t> &result);
- error_code getReferenceArch(Reference::KindArch &result);
- error_code addRelocationReferenceToAtoms();
- error_code findSection(StringRef name, const coff_section *&result);
+ std::error_code getSectionContents(StringRef sectionName,
+ ArrayRef<uint8_t> &result);
+ std::error_code getReferenceArch(Reference::KindArch &result);
+ std::error_code addRelocationReferenceToAtoms();
+ std::error_code findSection(StringRef name, const coff_section *&result);
StringRef ArrayRefToString(ArrayRef<uint8_t> array);
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
}
}
-FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec)
+FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, std::error_code &ec)
: File(mb->getBufferIdentifier(), kindObject), _compatibleWithSEH(false),
_ordinal(0) {
auto binaryOrErr = llvm::object::createBinary(mb.release());
_directives = ArrayRefToString(directives);
}
-error_code FileCOFF::parse() {
- if (error_code ec = getReferenceArch(_referenceArch))
+std::error_code FileCOFF::parse() {
+ if (std::error_code ec = getReferenceArch(_referenceArch))
return ec;
// Read the symbol table and atomize them if possible. Defined atoms
// cannot be atomized in one pass, so they will be not be atomized but
// added to symbolToAtom.
SymbolVectorT symbols;
- if (error_code ec = readSymbolTable(symbols))
+ if (std::error_code ec = readSymbolTable(symbols))
return ec;
createAbsoluteAtoms(symbols, _absoluteAtoms._atoms);
- if (error_code ec = createUndefinedAtoms(symbols, _undefinedAtoms._atoms))
+ if (std::error_code ec =
+ createUndefinedAtoms(symbols, _undefinedAtoms._atoms))
return ec;
- if (error_code ec = createDefinedSymbols(symbols, _definedAtoms._atoms))
+ if (std::error_code ec = createDefinedSymbols(symbols, _definedAtoms._atoms))
return ec;
- if (error_code ec = addRelocationReferenceToAtoms())
+ if (std::error_code ec = addRelocationReferenceToAtoms())
return ec;
- if (error_code ec = maybeCreateSXDataAtoms())
+ if (std::error_code ec = maybeCreateSXDataAtoms())
return ec;
- return error_code();
+ return std::error_code();
}
/// Iterate over the symbol table to retrieve all symbols.
-error_code FileCOFF::readSymbolTable(std::vector<const coff_symbol *> &result) {
+std::error_code
+FileCOFF::readSymbolTable(std::vector<const coff_symbol *> &result) {
const llvm::object::coff_file_header *header = nullptr;
- if (error_code ec = _obj->getHeader(header))
+ if (std::error_code ec = _obj->getHeader(header))
return ec;
for (uint32_t i = 0, e = header->NumberOfSymbols; i != e; ++i) {
// Retrieve the symbol.
const coff_symbol *sym;
StringRef name;
- if (error_code ec = _obj->getSymbol(i, sym))
+ if (std::error_code ec = _obj->getSymbol(i, sym))
return ec;
if (sym->SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
goto next;
result.push_back(sym);
- if (error_code ec = _obj->getSymbolName(sym, name))
+ if (std::error_code ec = _obj->getSymbolName(sym, name))
return ec;
// Existence of the symbol @feat.00 indicates that object file is compatible
// store it to _auxSymbol.
if (sym->NumberOfAuxSymbols > 0) {
const coff_symbol *aux = nullptr;
- if (error_code ec = _obj->getAuxSymbol(i + 1, aux))
+ if (std::error_code ec = _obj->getAuxSymbol(i + 1, aux))
return ec;
_auxSymbol[sym] = aux;
}
next:
i += sym->NumberOfAuxSymbols;
}
- return error_code();
+ return std::error_code();
}
/// Create atoms for the absolute symbols.
/// it's linked normally. If not, sym1 is resolved as if it has sym2's
/// name. This relationship between sym1 and sym2 is represented using
/// fallback mechanism of undefined symbol.
-error_code
+std::error_code
FileCOFF::createUndefinedAtoms(const SymbolVectorT &symbols,
std::vector<const UndefinedAtom *> &result) {
// Sort out undefined symbols from all symbols.
const coff_aux_weak_external *aux =
reinterpret_cast<const coff_aux_weak_external *>(iter->second);
const coff_symbol *sym2;
- if (error_code ec = _obj->getSymbol(aux->TagIndex, sym2))
+ if (std::error_code ec = _obj->getSymbol(aux->TagIndex, sym2))
return ec;
weakExternal[sym] = sym2;
}
result.push_back(atom);
_symbolAtom[sym] = atom;
}
- return error_code();
+ return std::error_code();
}
/// Create atoms for the defined symbols. This pass is a bit complicated than
/// the other two, because in order to create the atom for the defined symbol
/// we need to know the adjacent symbols.
-error_code
+std::error_code
FileCOFF::createDefinedSymbols(const SymbolVectorT &symbols,
std::vector<const DefinedAtom *> &result) {
// A defined atom can be merged if its section attribute allows its contents
// to be merged. In COFF, it's not very easy to get the section attribute
// for the symbol, so scan all sections in advance and cache the attributes
// for later use.
- if (error_code ec = cacheSectionAttributes())
+ if (std::error_code ec = cacheSectionAttributes())
return ec;
// Filter non-defined atoms, and group defined atoms by its section.
continue;
const coff_section *sec;
- if (error_code ec = _obj->getSection(sym->SectionNumber, sec))
+ if (std::error_code ec = _obj->getSection(sym->SectionNumber, sec))
return ec;
assert(sec && "SectionIndex > 0, Sec must be non-null!");
// multiple COMDAT sections whose section name are the same. We don't want
// to make atoms for them as they would become duplicate symbols.
StringRef sectionName;
- if (error_code ec = _obj->getSectionName(sec, sectionName))
+ if (std::error_code ec = _obj->getSectionName(sec, sectionName))
return ec;
if (_symbolName[sym] == sectionName && sym->Value == 0 &&
_merge[sec] != DefinedAtom::mergeNo)
}
// Atomize the defined symbols.
- if (error_code ec = AtomizeDefinedSymbols(definedSymbols, result))
+ if (std::error_code ec = AtomizeDefinedSymbols(definedSymbols, result))
return ec;
- return error_code();
+ return std::error_code();
}
// Cache the COMDAT attributes, which indicate whether the symbols in the
// section can be merged or not.
-error_code FileCOFF::cacheSectionAttributes() {
+std::error_code FileCOFF::cacheSectionAttributes() {
// The COMDAT section attribute is not an attribute of coff_section, but is
// stored in the auxiliary symbol for the first symbol referring a COMDAT
// section. It feels to me that it's unnecessarily complicated, but this is
continue;
const coff_section *sec;
- if (error_code ec = _obj->getSection(sym->SectionNumber, sec))
+ if (std::error_code ec = _obj->getSection(sym->SectionNumber, sec))
return ec;
if (_merge.count(sec))
if (!_merge.count(sec))
_merge[sec] = DefinedAtom::mergeNo;
}
- return error_code();
+ return std::error_code();
}
/// Atomize \p symbols and append the results to \p atoms. The symbols are
/// assumed to have been defined in the \p section.
-error_code FileCOFF::AtomizeDefinedSymbolsInSection(
+std::error_code FileCOFF::AtomizeDefinedSymbolsInSection(
const coff_section *section, std::vector<const coff_symbol *> &symbols,
std::vector<COFFDefinedFileAtom *> &atoms) {
// Sort symbols by position.
-> bool { return a->Value < b->Value; }));
StringRef sectionName;
- if (error_code ec = _obj->getSectionName(section, sectionName))
+ if (std::error_code ec = _obj->getSectionName(section, sectionName))
return ec;
// BSS section does not have contents. If this is the BSS section, create
atoms.push_back(atom);
_symbolAtom[sym] = atom;
}
- return error_code();
+ return std::error_code();
}
ArrayRef<uint8_t> secData;
- if (error_code ec = _obj->getSectionContents(section, secData))
+ if (std::error_code ec = _obj->getSectionContents(section, secData))
return ec;
// A section with IMAGE_SCN_LNK_{INFO,REMOVE} attribute will never become
// a part of the output image. That's what the COFF spec says.
if (section->Characteristics & llvm::COFF::IMAGE_SCN_LNK_INFO ||
section->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE)
- return error_code();
+ return std::error_code();
// Supporting debug info needs more work than just linking and combining
// .debug sections. We don't support it yet. Let's discard .debug sections at
// blobs that nobody would understand.
if ((section->Characteristics & llvm::COFF::IMAGE_SCN_MEM_DISCARDABLE) &&
(sectionName == ".debug" || sectionName.startswith(".debug$"))) {
- return error_code();
+ return std::error_code();
}
DefinedAtom::ContentType type = getContentType(section);
perms, _merge[section], data, _ordinal++);
atoms.push_back(atom);
_definedAtomLocations[section][0].push_back(atom);
- return error_code();
+ return std::error_code();
}
// Create an unnamed atom if the first atom isn't at the start of the
// Finally, set alignment to the first atom so that the section contents
// will be aligned as specified by the object section header.
_definedAtomLocations[section][0][0]->setAlignment(getAlignment(section));
- return error_code();
+ return std::error_code();
}
-error_code FileCOFF::AtomizeDefinedSymbols(
+std::error_code FileCOFF::AtomizeDefinedSymbols(
SectionToSymbolsT &definedSymbols,
std::vector<const DefinedAtom *> &definedAtoms) {
// For each section, make atoms for all the symbols defined in the
const coff_section *section = i.first;
std::vector<const coff_symbol *> &symbols = i.second;
std::vector<COFFDefinedFileAtom *> atoms;
- if (error_code ec = AtomizeDefinedSymbolsInSection(section, symbols, atoms))
+ if (std::error_code ec =
+ AtomizeDefinedSymbolsInSection(section, symbols, atoms))
return ec;
// Connect atoms with layout-before/layout-after edges.
definedAtoms.push_back(atom);
}
}
- return error_code();
+ return std::error_code();
}
/// Find the atom that is at \p targetAddress in \p section.
-error_code FileCOFF::findAtomAt(const coff_section *section,
- uint32_t targetAddress,
- COFFDefinedFileAtom *&result,
- uint32_t &offsetInAtom) {
+std::error_code FileCOFF::findAtomAt(const coff_section *section,
+ uint32_t targetAddress,
+ COFFDefinedFileAtom *&result,
+ uint32_t &offsetInAtom) {
for (auto i : _definedAtomLocations[section]) {
uint32_t atomAddress = i.first;
std::vector<COFFDefinedAtom *> &atomsAtSameLocation = i.second;
targetAddress < atomAddress + atom->size()) {
result = atom;
offsetInAtom = targetAddress - atomAddress;
- return error_code();
+ return std::error_code();
}
}
// Relocation target is out of range
/// Find the atom for the symbol that was at the \p index in the symbol
/// table.
-error_code FileCOFF::getAtomBySymbolIndex(uint32_t index, Atom *&ret) {
+std::error_code FileCOFF::getAtomBySymbolIndex(uint32_t index, Atom *&ret) {
const coff_symbol *symbol;
- if (error_code ec = _obj->getSymbol(index, symbol))
+ if (std::error_code ec = _obj->getSymbol(index, symbol))
return ec;
ret = _symbolAtom[symbol];
assert(ret);
- return error_code();
+ return std::error_code();
}
/// Add relocation information to an atom based on \p rel. \p rel is an
/// relocation entry for the \p section, and \p atoms are all the atoms
/// defined in the \p section.
-error_code FileCOFF::addRelocationReference(
+std::error_code FileCOFF::addRelocationReference(
const coff_relocation *rel, const coff_section *section,
const std::vector<COFFDefinedFileAtom *> &atoms) {
assert(atoms.size() > 0);
uint32_t itemAddress = rel->VirtualAddress + section->VirtualAddress;
Atom *targetAtom = nullptr;
- if (error_code ec = getAtomBySymbolIndex(rel->SymbolTableIndex, targetAtom))
+ if (std::error_code ec =
+ getAtomBySymbolIndex(rel->SymbolTableIndex, targetAtom))
return ec;
COFFDefinedFileAtom *atom;
uint32_t offsetInAtom;
- if (error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom))
+ if (std::error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom))
return ec;
atom->addReference(std::unique_ptr<COFFReference>(
new COFFReference(targetAtom, offsetInAtom, rel->Type,
Reference::KindNamespace::COFF, _referenceArch)));
- return error_code();
+ return std::error_code();
}
// Read section contents.
-error_code FileCOFF::getSectionContents(StringRef sectionName,
- ArrayRef<uint8_t> &result) {
+std::error_code FileCOFF::getSectionContents(StringRef sectionName,
+ ArrayRef<uint8_t> &result) {
const coff_section *section = nullptr;
- if (error_code ec = findSection(sectionName, section))
+ if (std::error_code ec = findSection(sectionName, section))
return ec;
if (!section)
- return error_code();
- if (error_code ec = _obj->getSectionContents(section, result))
+ return std::error_code();
+ if (std::error_code ec = _obj->getSectionContents(section, result))
return ec;
- return error_code();
+ return std::error_code();
}
/// Returns the target machine type of the current object file.
-error_code FileCOFF::getReferenceArch(Reference::KindArch &result) {
+std::error_code FileCOFF::getReferenceArch(Reference::KindArch &result) {
const llvm::object::coff_file_header *header = nullptr;
- if (error_code ec = _obj->getHeader(header))
+ if (std::error_code ec = _obj->getHeader(header))
return ec;
switch (header->Machine) {
case llvm::COFF::IMAGE_FILE_MACHINE_I386:
result = Reference::KindArch::x86;
- return error_code();
+ return std::error_code();
case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
result = Reference::KindArch::x86_64;
- return error_code();
+ return std::error_code();
case llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN:
result = Reference::KindArch::all;
- return error_code();
+ return std::error_code();
}
llvm::errs() << "Unsupported machine type: " << header->Machine << "\n";
return llvm::object::object_error::parse_failed;
}
/// Add relocation information to atoms.
-error_code FileCOFF::addRelocationReferenceToAtoms() {
+std::error_code FileCOFF::addRelocationReferenceToAtoms() {
// Relocation entries are defined for each section.
for (const auto &sec : _obj->sections()) {
const coff_section *section = _obj->getCOFFSection(sec);
return ec;
}
}
- return error_code();
+ return std::error_code();
}
// Read .sxdata section if exists. .sxdata is a x86-only section that contains a
// What we want to emit from the linker is a vector of SEH handler VAs, but here
// we have a vector of offsets to the symbol table. So we convert the latter to
// the former.
-error_code FileCOFF::maybeCreateSXDataAtoms() {
+std::error_code FileCOFF::maybeCreateSXDataAtoms() {
ArrayRef<uint8_t> sxdata;
- if (error_code ec = getSectionContents(".sxdata", sxdata))
+ if (std::error_code ec = getSectionContents(".sxdata", sxdata))
return ec;
if (sxdata.empty())
- return error_code();
+ return std::error_code();
std::vector<uint8_t> atomContent =
*new (_alloc) std::vector<uint8_t>((size_t)sxdata.size());
for (int i = 0; i < numSymbols; ++i) {
Atom *handlerFunc;
- if (error_code ec = getAtomBySymbolIndex(symbolIndex[i], handlerFunc))
+ if (std::error_code ec = getAtomBySymbolIndex(symbolIndex[i], handlerFunc))
return ec;
int offsetInAtom = i * sizeof(uint32_t);
atom->addReference(std::unique_ptr<COFFReference>(new COFFReference(
}
_definedAtoms._atoms.push_back(atom);
- return error_code();
+ return std::error_code();
}
/// Find a section by name.
-error_code FileCOFF::findSection(StringRef name, const coff_section *&result) {
+std::error_code FileCOFF::findSection(StringRef name,
+ const coff_section *&result) {
for (const auto &sec : _obj->sections()) {
const coff_section *section = _obj->getCOFFSection(sec);
StringRef sectionName;
return ec;
if (sectionName == name) {
result = section;
- return error_code();
+ return std::error_code();
}
}
// Section was not found, but it's not an error. This method returns
// an error only when there's a read error.
- return error_code();
+ return std::error_code();
}
// Convert ArrayRef<uint8_t> to std::string. The array contains a string which
return (magic == llvm::sys::fs::file_magic::windows_resource);
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
// Convert RC file to COFF
ErrorOr<std::string> coffPath = convertResourceFileToCOFF(std::move(mb));
- if (error_code ec = coffPath.getError())
+ if (std::error_code ec = coffPath.getError())
return ec;
llvm::FileRemover coffFileRemover(*coffPath);
// Read and parse the COFF
std::unique_ptr<MemoryBuffer> newmb;
- if (error_code ec = MemoryBuffer::getFile(*coffPath, newmb))
+ if (std::error_code ec = MemoryBuffer::getFile(*coffPath, newmb))
return ec;
- error_code ec;
+ std::error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(newmb), ec));
if (ec)
return ec;
- if (error_code ec = file->parse())
+ if (std::error_code ec = file->parse())
return ec;
result.push_back(std::move(file));
- return error_code();
+ return std::error_code();
}
private:
writeResToTemporaryFile(std::unique_ptr<MemoryBuffer> mb) {
// Get a temporary file path for .res file.
SmallString<128> tempFilePath;
- if (error_code ec =
+ if (std::error_code ec =
llvm::sys::fs::createTemporaryFile("tmp", "res", tempFilePath))
return ec;
// Write the memory buffer contents to .res file, so that we can run
// cvtres.exe on it.
std::unique_ptr<llvm::FileOutputBuffer> buffer;
- if (error_code ec = llvm::FileOutputBuffer::create(
+ if (std::error_code ec = llvm::FileOutputBuffer::create(
tempFilePath.str(), mb->getBufferSize(), buffer))
return ec;
memcpy(buffer->getBufferStart(), mb->getBufferStart(), mb->getBufferSize());
- if (error_code ec = buffer->commit())
+ if (std::error_code ec = buffer->commit())
return ec;
// Convert SmallString -> StringRef -> std::string.
convertResourceFileToCOFF(std::unique_ptr<MemoryBuffer> mb) {
// Write the resource file to a temporary file.
ErrorOr<std::string> inFilePath = writeResToTemporaryFile(std::move(mb));
- if (error_code ec = inFilePath.getError())
+ if (std::error_code ec = inFilePath.getError())
return ec;
llvm::FileRemover inFileRemover(*inFilePath);
// Create an output file path.
SmallString<128> outFilePath;
- if (error_code ec =
+ if (std::error_code ec =
llvm::sys::fs::createTemporaryFile("tmp", "obj", outFilePath))
return ec;
std::string outFileArg = ("/out:" + outFilePath).str();
return magic == llvm::sys::fs::file_magic::coff_object;
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry,
std::vector<std::unique_ptr<File>> &result) const override {
// Parse the memory buffer as PECOFF file.
const char *mbName = mb->getBufferIdentifier();
- error_code ec;
+ std::error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(mb), ec));
if (ec)
return ec;
// Interpret .drectve section if the section has contents.
StringRef directives = file->getLinkerDirectives();
if (!directives.empty())
- if (error_code ec = handleDirectiveSection(registry, directives))
+ if (std::error_code ec = handleDirectiveSection(registry, directives))
return ec;
- if (error_code ec = file->parse())
+ if (std::error_code ec = file->parse())
return ec;
// Check for /SAFESEH.
createAlternateNameAtoms(*file);
result.push_back(std::move(file));
- return error_code();
+ return std::error_code();
}
private:
//
// The section mainly contains /defaultlib (-l in Unix), but can contain any
// options as long as they are valid.
- error_code handleDirectiveSection(const Registry ®istry,
- StringRef directives) const {
+ std::error_code handleDirectiveSection(const Registry ®istry,
+ StringRef directives) const {
DEBUG(llvm::dbgs() << ".drectve: " << directives << "\n");
// Split the string into tokens, as the shell would do for argv.
if (!errorMessage.empty()) {
llvm::errs() << "lld warning: " << errorMessage << "\n";
}
- return error_code();
+ return std::error_code();
}
AliasAtom *createAlias(FileCOFF &file, StringRef name,
namespace pecoff {
-error_code parseCOFFImportLibrary(const LinkingContext &context,
- std::unique_ptr<MemoryBuffer> &mb,
- std::vector<std::unique_ptr<File> > &result);
+std::error_code
+parseCOFFImportLibrary(const LinkingContext &context,
+ std::unique_ptr<MemoryBuffer> &mb,
+ std::vector<std::unique_ptr<File>> &result);
}
}
_imageSizeOnDisk(0) {}
template <class PEHeader> void build(const File &linkedFile);
- error_code writeFile(const File &linkedFile, StringRef path) override;
+ std::error_code writeFile(const File &linkedFile, StringRef path) override;
private:
void applyAllRelocations(uint8_t *bufferStart);
peHeader->setSizeOfHeaders(sectionTable->fileOffset() + sectionTable->size());
}
-error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) {
+std::error_code PECOFFWriter::writeFile(const File &linkedFile,
+ StringRef path) {
if (_ctx.is64Bit()) {
this->build<llvm::object::pe32plus_header>(linkedFile);
} else {
uint64_t totalSize = _chunks.back()->fileOffset() + _chunks.back()->size();
std::unique_ptr<llvm::FileOutputBuffer> buffer;
- error_code ec = llvm::FileOutputBuffer::create(
+ std::error_code ec = llvm::FileOutputBuffer::create(
path, totalSize, buffer, llvm::FileOutputBuffer::F_executable);
if (ec)
return ec;
_yamlHandlers.push_back(std::move(handler));
}
-error_code
+std::error_code
Registry::parseFile(std::unique_ptr<MemoryBuffer> &mb,
std::vector<std::unique_ptr<File>> &result) const {
// Get file type.
return nullptr;
}
- virtual error_code
+ virtual std::error_code
parseAllMembers(std::vector<std::unique_ptr<File>> &result) const override {
- return error_code();
+ return std::error_code();
}
StringRef _path;
public:
Writer(const LinkingContext &context) : _context(context) {}
- error_code writeFile(const lld::File &file, StringRef outPath) override {
+ std::error_code writeFile(const lld::File &file, StringRef outPath) override {
// Create stream to path.
std::string errorInfo;
llvm::raw_fd_ostream out(outPath.data(), errorInfo, llvm::sys::fs::F_Text);
const lld::File *fileRef = &file;
yout << fileRef;
- return error_code();
+ return std::error_code();
}
private:
return (ext.equals(".objtxt") || ext.equals(".yaml"));
}
- error_code
+ std::error_code
parseFile(std::unique_ptr<MemoryBuffer> &mb, const class Registry &,
std::vector<std::unique_ptr<File>> &result) const override {
// Note: we do not take ownership of the MemoryBuffer. That is