diff options
Diffstat (limited to 'lib/Core')
| -rw-r--r-- | lib/Core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lib/Core/DefinedAtom.cpp | 12 | ||||
| -rw-r--r-- | lib/Core/Error.cpp | 6 | ||||
| -rw-r--r-- | lib/Core/File.cpp | 5 | ||||
| -rw-r--r-- | lib/Core/LinkingContext.cpp | 11 | ||||
| -rw-r--r-- | lib/Core/Reader.cpp | 10 | ||||
| -rw-r--r-- | lib/Core/Reproduce.cpp | 128 | ||||
| -rw-r--r-- | lib/Core/Resolver.cpp | 2 | ||||
| -rw-r--r-- | lib/Core/SymbolTable.cpp | 32 | ||||
| -rw-r--r-- | lib/Core/Writer.cpp | 9 |
10 files changed, 153 insertions, 63 deletions
diff --git a/lib/Core/CMakeLists.txt b/lib/Core/CMakeLists.txt index 41e0e7661b9c..d89ca4a63d72 100644 --- a/lib/Core/CMakeLists.txt +++ b/lib/Core/CMakeLists.txt @@ -4,6 +4,7 @@ add_lld_library(lldCore File.cpp LinkingContext.cpp Reader.cpp + Reproduce.cpp Resolver.cpp SymbolTable.cpp Writer.cpp diff --git a/lib/Core/DefinedAtom.cpp b/lib/Core/DefinedAtom.cpp index 8dc4d4a16f96..177cae7fcbf0 100644 --- a/lib/Core/DefinedAtom.cpp +++ b/lib/Core/DefinedAtom.cpp @@ -79,16 +79,4 @@ DefinedAtom::ContentPermissions DefinedAtom::permissions(ContentType type) { llvm_unreachable("unknown content type"); } -bool DefinedAtom::compareByPosition(const DefinedAtom *lhs, - const DefinedAtom *rhs) { - if (lhs == rhs) - return false; - const File *lhsFile = &lhs->file(); - const File *rhsFile = &rhs->file(); - if (lhsFile->ordinal() != rhsFile->ordinal()) - return lhsFile->ordinal() < rhsFile->ordinal(); - assert(lhs->ordinal() != rhs->ordinal()); - return lhs->ordinal() < rhs->ordinal(); -} - } // namespace diff --git a/lib/Core/Error.cpp b/lib/Core/Error.cpp index 4df1ce120bd9..6fc76f7ca3d0 100644 --- a/lib/Core/Error.cpp +++ b/lib/Core/Error.cpp @@ -16,9 +16,10 @@ using namespace lld; +namespace { class _YamlReaderErrorCategory : public std::error_category { public: - const char* name() const LLVM_NOEXCEPT override { + const char* name() const noexcept override { return "lld.yaml.reader"; } @@ -33,6 +34,7 @@ public: "message defined."); } }; +} // end anonymous namespace const std::error_category &lld::YamlReaderCategory() { static _YamlReaderErrorCategory o; @@ -48,7 +50,7 @@ class dynamic_error_category : public std::error_category { public: ~dynamic_error_category() override = default; - const char *name() const LLVM_NOEXCEPT override { + const char *name() const noexcept override { return "lld.dynamic_error"; } diff --git a/lib/Core/File.cpp b/lib/Core/File.cpp index b84132bfecd5..30ded091a92a 100644 --- a/lib/Core/File.cpp +++ b/lib/Core/File.cpp @@ -8,12 +8,11 @@ //===----------------------------------------------------------------------===// #include "lld/Core/File.h" -#include "lld/Core/LLVM.h" #include <mutex> namespace lld { -File::~File() { } +File::~File() = default; File::AtomVector<DefinedAtom> File::_noDefinedAtoms; File::AtomVector<UndefinedAtom> File::_noUndefinedAtoms; @@ -27,4 +26,4 @@ std::error_code File::parse() { return _lastError.getValue(); } -} // namespace lld +} // end namespace lld diff --git a/lib/Core/LinkingContext.cpp b/lib/Core/LinkingContext.cpp index 2732543d306e..5de863aa7f37 100644 --- a/lib/Core/LinkingContext.cpp +++ b/lib/Core/LinkingContext.cpp @@ -8,16 +8,17 @@ //===----------------------------------------------------------------------===// #include "lld/Core/LinkingContext.h" -#include "lld/Core/Resolver.h" +#include "lld/Core/File.h" +#include "lld/Core/Node.h" #include "lld/Core/Simple.h" #include "lld/Core/Writer.h" -#include "llvm/ADT/Triple.h" +#include <algorithm> namespace lld { -LinkingContext::LinkingContext() {} +LinkingContext::LinkingContext() = default; -LinkingContext::~LinkingContext() {} +LinkingContext::~LinkingContext() = default; bool LinkingContext::validate(raw_ostream &diagnostics) { return validateImpl(diagnostics); @@ -59,7 +60,7 @@ LinkingContext::createUndefinedSymbolFile(StringRef filename) const { } void LinkingContext::createInternalFiles( - std::vector<std::unique_ptr<File> > &result) const { + std::vector<std::unique_ptr<File>> &result) const { if (std::unique_ptr<File> file = createEntrySymbolFile()) result.push_back(std::move(file)); if (std::unique_ptr<File> file = createUndefinedSymbolFile()) diff --git a/lib/Core/Reader.cpp b/lib/Core/Reader.cpp index 107db07891da..24652abec688 100644 --- a/lib/Core/Reader.cpp +++ b/lib/Core/Reader.cpp @@ -7,18 +7,19 @@ // //===----------------------------------------------------------------------===// -#include "lld/Core/File.h" #include "lld/Core/Reader.h" +#include "lld/Core/File.h" +#include "lld/Core/Reference.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Errc.h" -#include "llvm/Support/FileUtilities.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" +#include <algorithm> #include <memory> -#include <system_error> namespace lld { -YamlIOTaggedDocumentHandler::~YamlIOTaggedDocumentHandler() {} +YamlIOTaggedDocumentHandler::~YamlIOTaggedDocumentHandler() = default; void Registry::add(std::unique_ptr<Reader> reader) { _readers.push_back(std::move(reader)); @@ -63,7 +64,6 @@ bool Registry::handleTaggedDoc(llvm::yaml::IO &io, return false; } - void Registry::addKindTable(Reference::KindNamespace ns, Reference::KindArch arch, const KindStrings array[]) { diff --git a/lib/Core/Reproduce.cpp b/lib/Core/Reproduce.cpp new file mode 100644 index 000000000000..39b0e41c44e5 --- /dev/null +++ b/lib/Core/Reproduce.cpp @@ -0,0 +1,128 @@ +//===- Reproduce.cpp - Utilities for creating reproducers -----------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lld/Core/Reproduce.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Option/Arg.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/Path.h" + +using namespace lld; +using namespace llvm; +using namespace sys; + +CpioFile::CpioFile(std::unique_ptr<raw_fd_ostream> OS, StringRef S) + : OS(std::move(OS)), Basename(S) {} + +ErrorOr<CpioFile *> CpioFile::create(StringRef OutputPath) { + std::string Path = (OutputPath + ".cpio").str(); + std::error_code EC; + auto OS = llvm::make_unique<raw_fd_ostream>(Path, EC, sys::fs::F_None); + if (EC) + return EC; + return new CpioFile(std::move(OS), path::filename(OutputPath)); +} + +static void writeMember(raw_fd_ostream &OS, StringRef Path, StringRef Data) { + // The c_dev/c_ino pair should be unique according to the spec, + // but no one seems to care. + OS << "070707"; // c_magic + OS << "000000"; // c_dev + OS << "000000"; // c_ino + OS << "100664"; // c_mode: C_ISREG | rw-rw-r-- + OS << "000000"; // c_uid + OS << "000000"; // c_gid + OS << "000001"; // c_nlink + OS << "000000"; // c_rdev + OS << "00000000000"; // c_mtime + OS << format("%06o", Path.size() + 1); // c_namesize + OS << format("%011o", Data.size()); // c_filesize + OS << Path << '\0'; // c_name + OS << Data; // c_filedata +} + +void CpioFile::append(StringRef Path, StringRef Data) { + if (!Seen.insert(Path).second) + return; + + // Construct an in-archive filename so that /home/foo/bar is stored + // as baz/home/foo/bar where baz is the basename of the output file. + // (i.e. in that case we are creating baz.cpio.) + SmallString<128> Fullpath; + path::append(Fullpath, Basename, Path); + + writeMember(*OS, convertToUnixPathSeparator(Fullpath), Data); + + // Print the trailer and seek back. + // This way we have a valid archive if we crash. + uint64_t Pos = OS->tell(); + writeMember(*OS, "TRAILER!!!", ""); + OS->seek(Pos); +} + +// Makes a given pathname an absolute path first, and then remove +// beginning /. For example, "../foo.o" is converted to "home/john/foo.o", +// assuming that the current directory is "/home/john/bar". +// Returned string is a forward slash separated path even on Windows to avoid +// a mess with backslash-as-escape and backslash-as-path-separator. +std::string lld::relativeToRoot(StringRef Path) { + SmallString<128> Abs = Path; + if (sys::fs::make_absolute(Abs)) + return Path; + path::remove_dots(Abs, /*remove_dot_dot=*/true); + + // This is Windows specific. root_name() returns a drive letter + // (e.g. "c:") or a UNC name (//net). We want to keep it as part + // of the result. + SmallString<128> Res; + StringRef Root = path::root_name(Abs); + if (Root.endswith(":")) + Res = Root.drop_back(); + else if (Root.startswith("//")) + Res = Root.substr(2); + + path::append(Res, path::relative_path(Abs)); + return convertToUnixPathSeparator(Res); +} + +// Quote a given string if it contains a space character. +std::string lld::quote(StringRef S) { + if (S.find(' ') == StringRef::npos) + return S; + return ("\"" + S + "\"").str(); +} + +std::string lld::rewritePath(StringRef S) { + if (fs::exists(S)) + return relativeToRoot(S); + return S; +} + +std::string lld::stringize(opt::Arg *Arg) { + std::string K = Arg->getSpelling(); + if (Arg->getNumValues() == 0) + return K; + std::string V = quote(Arg->getValue()); + if (Arg->getOption().getRenderStyle() == opt::Option::RenderJoinedStyle) + return K + V; + return K + " " + V; +} + +std::string lld::convertToUnixPathSeparator(StringRef S) { +#ifdef LLVM_ON_WIN32 + std::string Ret = S.str(); + std::replace(Ret.begin(), Ret.end(), '\\', '/'); + return Ret; +#else + return S; +#endif +} diff --git a/lib/Core/Resolver.cpp b/lib/Core/Resolver.cpp index ef694fd972fc..e7cfaaac7835 100644 --- a/lib/Core/Resolver.cpp +++ b/lib/Core/Resolver.cpp @@ -100,7 +100,7 @@ llvm::Error Resolver::handleSharedLibrary(File &file) { if (auto ec = undefAddedOrError.takeError()) return ec; - return llvm::Error(); + return llvm::Error::success(); } bool Resolver::doUndefinedAtom(OwningAtomPtr<UndefinedAtom> atom) { diff --git a/lib/Core/SymbolTable.cpp b/lib/Core/SymbolTable.cpp index 44631a5d40dc..cacea5f30847 100644 --- a/lib/Core/SymbolTable.cpp +++ b/lib/Core/SymbolTable.cpp @@ -223,13 +223,9 @@ bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, const DefinedAtom * const r) { if (l == r) return true; - if (l == getEmptyKey()) + if (l == getEmptyKey() || r == getEmptyKey()) return false; - if (r == getEmptyKey()) - return false; - if (l == getTombstoneKey()) - return false; - if (r == getTombstoneKey()) + if (l == getTombstoneKey() || r == getTombstoneKey()) return false; if (l->contentType() != r->contentType()) return false; @@ -265,17 +261,6 @@ const Atom *SymbolTable::findByName(StringRef sym) { return pos->second; } -bool SymbolTable::isDefined(StringRef sym) { - if (const Atom *atom = findByName(sym)) - return !isa<UndefinedAtom>(atom); - return false; -} - -void SymbolTable::addReplacement(const Atom *replaced, - const Atom *replacement) { - _replacedAtoms[replaced] = replacement; -} - const Atom *SymbolTable::replacement(const Atom *atom) { // Find the replacement for a given atom. Atoms in _replacedAtoms // may be chained, so find the last one. @@ -303,17 +288,4 @@ std::vector<const UndefinedAtom *> SymbolTable::undefines() { return ret; } -std::vector<StringRef> SymbolTable::tentativeDefinitions() { - std::vector<StringRef> ret; - for (auto entry : _nameTable) { - const Atom *atom = entry.second; - StringRef name = entry.first; - assert(atom != nullptr); - if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom)) - if (defAtom->merge() == DefinedAtom::mergeAsTentative) - ret.push_back(name); - } - return ret; -} - } // namespace lld diff --git a/lib/Core/Writer.cpp b/lib/Core/Writer.cpp index 93e6438a28f5..51f95bc5053a 100644 --- a/lib/Core/Writer.cpp +++ b/lib/Core/Writer.cpp @@ -7,13 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "lld/Core/File.h" #include "lld/Core/Writer.h" namespace lld { -Writer::Writer() { -} -Writer::~Writer() { -} +Writer::Writer() = default; + +Writer::~Writer() = default; + } // end namespace lld |
