diff options
author | Kevin Enderby <enderby@apple.com> | 2016-05-17 17:10:12 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-05-17 17:10:12 +0000 |
commit | ac9e15551dfccb2996708534648e6b7e8d4fee8a (patch) | |
tree | 2c0c21fb4b4d25171654d1e0800555a949c4f355 /llvm/tools/llvm-nm/llvm-nm.cpp | |
parent | 75259bb3cb719446b3b705bd85ddb7ad3cb9cce7 (diff) | |
download | bcm5719-llvm-ac9e15551dfccb2996708534648e6b7e8d4fee8a.tar.gz bcm5719-llvm-ac9e15551dfccb2996708534648e6b7e8d4fee8a.zip |
Change llvm-objdump, llvm-nm and llvm-size when reporting an object file error
when the object is in an archive to use something like libx.a(foo.o) as part of
the error message.
Also changed llvm-objdump and llvm-size to be like llvm-nm and ignore non-object
files in archives and not produce any error message.
To do this Archive::Child::getAsBinary() was changed from ErrorOr<...> to
Expected<...> then that was threaded up to its users.
Converting this interface to Expected<> from ErrorOr<> does involve
touching a number of places. To contain the changes for now the use of
errorToErrorCode() is still used in one place yet to be fully converted.
Again there some were bugs in the existing code that did not deal with the
old ErrorOr<> return values. So now with Expected<> since they must be
checked and the error handled, I added a TODO and a comments for those.
llvm-svn: 269784
Diffstat (limited to 'llvm/tools/llvm-nm/llvm-nm.cpp')
-rw-r--r-- | llvm/tools/llvm-nm/llvm-nm.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index 4c0d7535ec2..a9234229062 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -190,6 +190,29 @@ static bool error(std::error_code EC, Twine Path = Twine()) { return false; } +// This version of error() prints the archive name and member name, for example: +// "libx.a(foo.o)" after the ToolName before the error message. It sets +// HadError but returns allowing the code to move on to other archive members. +static void error(llvm::Error E, StringRef FileName, const Archive::Child &C) { + HadError = true; + errs() << ToolName << ": " << FileName; + + ErrorOr<StringRef> NameOrErr = C.getName(); + // TODO: if we have a error getting the name then it would be nice to print + // the index of which archive member this is and or its offset in the + // archive instead of "???" as the name. + if (NameOrErr.getError()) + errs() << "(" << "???" << ")"; + else + errs() << "(" << NameOrErr.get() << ")"; + + std::string Buf; + raw_string_ostream OS(Buf); + logAllUnhandledErrors(std::move(E), OS, ""); + OS.flush(); + errs() << " " << Buf << "\n"; +} + namespace { struct NMSymbol { uint64_t Address; @@ -1066,9 +1089,12 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (error(I->getError())) return; auto &C = I->get(); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); - if (ChildOrErr.getError()) + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) + error(std::move(E), Filename, C); continue; + } if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { if (!checkMachOAndArchFlags(O, Filename)) return; @@ -1124,10 +1150,14 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (error(AI->getError())) return; auto &C = AI->get(); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); - if (ChildOrErr.getError()) + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType( + ChildOrErr.takeError())) + error(std::move(E), Filename, C); continue; + } if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { if (PrintFileName) { @@ -1181,10 +1211,14 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (error(AI->getError())) return; auto &C = AI->get(); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); - if (ChildOrErr.getError()) + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType( + ChildOrErr.takeError())) + error(std::move(E), Filename, C); continue; + } if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { if (PrintFileName) @@ -1233,9 +1267,13 @@ static void dumpSymbolNamesFromFile(std::string &Filename) { if (error(AI->getError())) return; auto &C = AI->get(); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); - if (ChildOrErr.getError()) + Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType( + ChildOrErr.takeError())) + error(std::move(E), Filename, C); continue; + } if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) { if (PrintFileName) { ArchiveName = A->getFileName(); |