aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-size/llvm-size.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-size/llvm-size.cpp')
-rw-r--r--tools/llvm-size/llvm-size.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp
index 9a6e2c1ae4be..069cc621f615 100644
--- a/tools/llvm-size/llvm-size.cpp
+++ b/tools/llvm-size/llvm-size.cpp
@@ -1,4 +1,4 @@
-//===-- llvm-size.cpp - Print the size of each object section -------------===//
+//===-- llvm-size.cpp - Print the size of each object section ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -30,6 +30,7 @@
#include <algorithm>
#include <string>
#include <system_error>
+
using namespace llvm;
using namespace object;
@@ -98,7 +99,7 @@ static size_t getNumLengthAsString(uint64_t num) {
}
/// @brief Return the printing format for the Radix.
-static const char *getRadixFmt(void) {
+static const char *getRadixFmt() {
switch (Radix) {
case octal:
return PRIo64;
@@ -413,14 +414,6 @@ static bool checkMachOAndArchFlags(ObjectFile *o, StringRef file) {
/// @brief Print the section sizes for @p file. If @p file is an archive, print
/// the section sizes for each archive member.
static void PrintFileSectionSizes(StringRef file) {
- // If file is not stdin, check that it exists.
- if (file != "-") {
- if (!sys::fs::exists(file)) {
- errs() << ToolName << ": '" << file << "': "
- << "No such file\n";
- return;
- }
- }
// Attempt to open the binary.
ErrorOr<OwningBinary<Binary>> BinaryOrErr = createBinary(file);
@@ -435,7 +428,13 @@ static void PrintFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = a->child_begin(),
e = a->child_end();
i != e; ++i) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
+ if (i->getError()) {
+ errs() << ToolName << ": " << file << ": " << i->getError().message()
+ << ".\n";
+ exit(1);
+ }
+ auto &c = i->get();
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
continue;
@@ -497,7 +496,13 @@ static void PrintFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
+ if (std::error_code EC = i->getError()) {
+ errs() << ToolName << ": " << file << ": " << EC.message()
+ << ".\n";
+ exit(1);
+ }
+ auto &c = i->get();
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
@@ -574,7 +579,13 @@ static void PrintFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
+ if (std::error_code EC = i->getError()) {
+ errs() << ToolName << ": " << file << ": " << EC.message()
+ << ".\n";
+ exit(1);
+ }
+ auto &c = i->get();
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message()
<< ".\n";
@@ -638,7 +649,12 @@ static void PrintFileSectionSizes(StringRef file) {
for (object::Archive::child_iterator i = UA->child_begin(),
e = UA->child_end();
i != e; ++i) {
- ErrorOr<std::unique_ptr<Binary>> ChildOrErr = i->getAsBinary();
+ if (std::error_code EC = i->getError()) {
+ errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
+ exit(1);
+ }
+ auto &c = i->get();
+ ErrorOr<std::unique_ptr<Binary>> ChildOrErr = c.getAsBinary();
if (std::error_code EC = ChildOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
continue;