diff options
| author | Rui Ueyama <ruiu@google.com> | 2019-11-15 14:06:57 +0900 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2019-11-18 11:18:06 +0900 |
| commit | b11386f9be9b2dc7276a758d64f66833da10bdea (patch) | |
| tree | a2b86a5ace890513090fea13c704acf2e149de0e /lld/lib | |
| parent | 5d67d81f484f935b709918ad99462e32efa3b17a (diff) | |
| download | bcm5719-llvm-b11386f9be9b2dc7276a758d64f66833da10bdea.tar.gz bcm5719-llvm-b11386f9be9b2dc7276a758d64f66833da10bdea.zip | |
Make it possible to redirect not only errs() but also outs()
This change is for those who use lld as a library. Context:
https://reviews.llvm.org/D70287
This patch adds a new parmeter to lld::*::link() so that we can pass
an raw_ostream object representing stdout. Previously, lld::*::link()
took only an stderr object.
Justification for making stdoutOS and stderrOS mandatory: I wanted to
make link() functions to take stdout and stderr in that order.
However, if we change the function signature from
bool link(ArrayRef<const char *> args, bool canExitEarly,
raw_ostream &stderrOS = llvm::errs());
to
bool link(ArrayRef<const char *> args, bool canExitEarly,
raw_ostream &stdoutOS = llvm::outs(),
raw_ostream &stderrOS = llvm::errs());
, then the meaning of existing code that passes stderrOS silently
changes (stderrOS would be interpreted as stdoutOS). So, I chose to
make existing code not to compile, so that developers can fix their
code.
Differential Revision: https://reviews.llvm.org/D70292
Diffstat (limited to 'lld/lib')
| -rw-r--r-- | lld/lib/Core/Resolver.cpp | 23 | ||||
| -rw-r--r-- | lld/lib/Core/SymbolTable.cpp | 20 | ||||
| -rw-r--r-- | lld/lib/Driver/DarwinLdDriver.cpp | 25 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/FileArchive.cpp | 2 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/LayoutPass.cpp | 4 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 2 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp | 4 |
7 files changed, 36 insertions, 44 deletions
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 7e6d95f8223..182f9caa985 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -223,8 +223,8 @@ bool Resolver::resolveUndefines() { if (!file) return true; if (std::error_code ec = file->parse()) { - llvm::errs() << "Cannot open " + file->path() - << ": " << ec.message() << "\n"; + lld::errs() << "Cannot open " + file->path() << ": " << ec.message() + << "\n"; return false; } DEBUG_WITH_TYPE("resolver", @@ -252,8 +252,8 @@ bool Resolver::resolveUndefines() { if (auto EC = undefAddedOrError.takeError()) { // FIXME: This should be passed to logAllUnhandledErrors but it needs // to be passed a Twine instead of a string. - llvm::errs() << "Error in " + file->path() << ": "; - logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); + lld::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), lld::errs(), std::string()); return false; } undefAdded = undefAddedOrError.get(); @@ -266,8 +266,8 @@ bool Resolver::resolveUndefines() { if (auto EC = undefAddedOrError.takeError()) { // FIXME: This should be passed to logAllUnhandledErrors but it needs // to be passed a Twine instead of a string. - llvm::errs() << "Error in " + file->path() << ": "; - logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); + lld::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), lld::errs(), std::string()); return false; } undefAdded = undefAddedOrError.get(); @@ -279,8 +279,8 @@ bool Resolver::resolveUndefines() { if (auto EC = handleSharedLibrary(*file)) { // FIXME: This should be passed to logAllUnhandledErrors but it needs // to be passed a Twine instead of a string. - llvm::errs() << "Error in " + file->path() << ": "; - logAllUnhandledErrors(std::move(EC), llvm::errs(), std::string()); + lld::errs() << "Error in " + file->path() << ": "; + logAllUnhandledErrors(std::move(EC), lld::errs(), std::string()); return false; } break; @@ -424,15 +424,14 @@ bool Resolver::checkUndefines() { // Seems like this symbol is undefined. Warn that. foundUndefines = true; if (_ctx.printRemainingUndefines()) { - llvm::errs() << "Undefined symbol: " << undef->file().path() - << ": " << _ctx.demangle(undef->name()) - << "\n"; + lld::errs() << "Undefined symbol: " << undef->file().path() << ": " + << _ctx.demangle(undef->name()) << "\n"; } } if (!foundUndefines) return false; if (_ctx.printRemainingUndefines()) - llvm::errs() << "symbol(s) not found\n"; + lld::errs() << "symbol(s) not found\n"; return true; } diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index 55cc27c38a6..7ccd1ce0ab2 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -157,21 +157,15 @@ bool SymbolTable::addByName(const Atom &newAtom) { useNew = true; break; } - llvm::errs() << "Size mismatch: " - << existing->name() << " (" << existingSize << ") " - << newAtom.name() << " (" << newSize << ")\n"; + lld::errs() << "Size mismatch: " << existing->name() << " (" + << existingSize << ") " << newAtom.name() << " (" << newSize + << ")\n"; LLVM_FALLTHROUGH; } case MCR_Error: - llvm::errs() << "Duplicate symbols: " - << existing->name() - << ":" - << existing->file().path() - << " and " - << newAtom.name() - << ":" - << newAtom.file().path() - << "\n"; + lld::errs() << "Duplicate symbols: " << existing->name() << ":" + << existing->file().path() << " and " << newAtom.name() << ":" + << newAtom.file().path() << "\n"; llvm::report_fatal_error("duplicate symbol error"); break; } @@ -193,7 +187,7 @@ bool SymbolTable::addByName(const Atom &newAtom) { break; } case NCR_Error: - llvm::errs() << "SymbolTable: error while merging " << name << "\n"; + lld::errs() << "SymbolTable: error while merging " << name << "\n"; llvm::report_fatal_error("duplicate symbol error"); break; } diff --git a/lld/lib/Driver/DarwinLdDriver.cpp b/lld/lib/Driver/DarwinLdDriver.cpp index 8566ababc65..60515d21a92 100644 --- a/lld/lib/Driver/DarwinLdDriver.cpp +++ b/lld/lib/Driver/DarwinLdDriver.cpp @@ -232,7 +232,7 @@ static std::error_code parseOrderFile(StringRef orderFilePath, sym = prefixAndSym.first; if (!sym.empty()) { ctx.appendOrderedSymbol(sym, prefix); - //llvm::errs() << sym << ", prefix=" << prefix << "\n"; + // lld::errs() << sym << ", prefix=" << prefix << "\n"; } } return std::error_code(); @@ -382,7 +382,7 @@ bool parse(llvm::ArrayRef<const char *> args, MachOLinkingContext &ctx) { !parsedArgs.getLastArg(OPT_test_file_usage)) { // If no -arch and no options at all, print usage message. if (parsedArgs.size() == 0) { - table.PrintHelp(llvm::outs(), + table.PrintHelp(lld::outs(), (std::string(args[0]) + " [options] file...").c_str(), "LLVM Linker", false); } else { @@ -1144,14 +1144,16 @@ static void createFiles(MachOLinkingContext &ctx, bool Implicit) { /// This is where the link is actually performed. bool link(llvm::ArrayRef<const char *> args, bool CanExitEarly, - raw_ostream &Error) { + raw_ostream &StdoutOS, raw_ostream &StderrOS) { errorHandler().logName = args::getFilenameWithoutExe(args[0]); errorHandler().errorLimitExceededMsg = "too many errors emitted, stopping now (use " "'-error-limit 0' to see all errors)"; - errorHandler().errorOS = &Error; errorHandler().exitEarly = CanExitEarly; - enableColors(Error.has_colors()); + enableColors(StderrOS.has_colors()); + + lld::stdoutOS = &StdoutOS; + lld::stderrOS = &StderrOS; MachOLinkingContext ctx; if (!parse(args, ctx)) @@ -1196,10 +1198,9 @@ bool link(llvm::ArrayRef<const char *> args, bool CanExitEarly, if (auto ec = pm.runOnFile(*merged)) { // FIXME: This should be passed to logAllUnhandledErrors but it needs // to be passed a Twine instead of a string. - *errorHandler().errorOS << "Failed to run passes on file '" - << ctx.outputPath() << "': "; - logAllUnhandledErrors(std::move(ec), *errorHandler().errorOS, - std::string()); + lld::errs() << "Failed to run passes on file '" << ctx.outputPath() + << "': "; + logAllUnhandledErrors(std::move(ec), lld::errs(), std::string()); return false; } @@ -1210,10 +1211,8 @@ bool link(llvm::ArrayRef<const char *> args, bool CanExitEarly, if (auto ec = ctx.writeFile(*merged)) { // FIXME: This should be passed to logAllUnhandledErrors but it needs // to be passed a Twine instead of a string. - *errorHandler().errorOS << "Failed to write file '" << ctx.outputPath() - << "': "; - logAllUnhandledErrors(std::move(ec), *errorHandler().errorOS, - std::string()); + lld::errs() << "Failed to write file '" << ctx.outputPath() << "': "; + logAllUnhandledErrors(std::move(ec), lld::errs(), std::string()); return false; } diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index 98f4d06ee21..d73711cfb3d 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -145,7 +145,7 @@ private: + mb.getBufferIdentifier() + ")").str(); if (_logLoading) - llvm::errs() << memberPath << "\n"; + lld::errs() << memberPath << "\n"; std::unique_ptr<MemoryBuffer> memberMB(MemoryBuffer::getMemBuffer( mb.getBuffer(), mb.getBufferIdentifier(), false)); diff --git a/lld/lib/ReaderWriter/MachO/LayoutPass.cpp b/lld/lib/ReaderWriter/MachO/LayoutPass.cpp index 8db6ffb958a..ea54c2d4cc3 100644 --- a/lld/lib/ReaderWriter/MachO/LayoutPass.cpp +++ b/lld/lib/ReaderWriter/MachO/LayoutPass.cpp @@ -241,8 +241,8 @@ static bool compareAtomsSub(const LayoutPass::SortKey &lc, return leftOrdinal < rightOrdinal; } - llvm::errs() << "Unordered: <" << left->name() << "> <" - << right->name() << ">\n"; + lld::errs() << "Unordered: <" << left->name() << "> <" << right->name() + << ">\n"; llvm_unreachable("Atoms with Same Ordinal!"); } diff --git a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 221d895a40d..812f89696f6 100644 --- a/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -825,7 +825,7 @@ bool MachOLinkingContext::sectionAligned(StringRef seg, StringRef sect, void MachOLinkingContext::addExportSymbol(StringRef sym) { // Support old crufty export lists with bogus entries. if (sym.endswith(".eh") || sym.startswith(".objc_category_name_")) { - llvm::errs() << "warning: ignoring " << sym << " in export list\n"; + lld::errs() << "warning: ignoring " << sym << " in export list\n"; return; } // Only i386 MacOSX uses old ABI, so don't change those. diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp index f34857b9967..3e70a1db7b1 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -316,8 +316,8 @@ llvm::Error processSymboledSection(DefinedAtom::ContentType atomType, }); // Debug logging of symbols. - //for (const Symbol *sym : symbols) - // llvm::errs() << " sym: " + // for (const Symbol *sym : symbols) + // lld::errs() << " sym: " // << llvm::format("0x%08llx ", (uint64_t)sym->value) // << ", " << sym->name << "\n"; |

