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-size/llvm-size.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-size/llvm-size.cpp')
-rw-r--r-- | llvm/tools/llvm-size/llvm-size.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp index e3b487c388f..351a6b1bfbd 100644 --- a/llvm/tools/llvm-size/llvm-size.cpp +++ b/llvm/tools/llvm-size/llvm-size.cpp @@ -99,6 +99,29 @@ static bool error(std::error_code ec) { return true; } +// 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"; +} + /// Get the length of the string that represents @p num in Radix including the /// leading 0x or 0 for hexadecimal and octal respectively. static size_t getNumLengthAsString(uint64_t num) { @@ -480,9 +503,12 @@ static void printFileSectionSizes(StringRef file) { i != e; ++i) { if (error(i->getError())) exit(1); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); - if (error(ChildOrErr.getError())) + Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) + error(std::move(E), a->getFileName(), i->get()); continue; + } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); if (!checkMachOAndArchFlags(o, file)) @@ -542,9 +568,13 @@ static void printFileSectionSizes(StringRef file) { i != e; ++i) { if (error(i->getError())) exit(1); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); - if (error(ChildOrErr.getError())) + Expected<std::unique_ptr<Binary>> ChildOrErr = + i->get().getAsBinary(); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) + error(std::move(E), a->getFileName(), i->get()); continue; + } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); if (OutputFormat == sysv) @@ -618,9 +648,13 @@ static void printFileSectionSizes(StringRef file) { i != e; ++i) { if (error(i->getError())) exit(1); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); - if (error(ChildOrErr.getError())) + Expected<std::unique_ptr<Binary>> ChildOrErr = + i->get().getAsBinary(); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) + error(std::move(E), a->getFileName(), i->get()); continue; + } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); if (OutputFormat == sysv) @@ -681,9 +715,12 @@ static void printFileSectionSizes(StringRef file) { i != e; ++i) { if (error(i->getError())) exit(1); - ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); - if (error(ChildOrErr.getError())) + Expected<std::unique_ptr<Binary>> ChildOrErr = i->get().getAsBinary(); + if (!ChildOrErr) { + if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError())) + error(std::move(E), UA->getFileName(), i->get()); continue; + } if (ObjectFile *o = dyn_cast<ObjectFile>(&*ChildOrErr.get())) { MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o); if (OutputFormat == sysv) |