# Test case where input file does not exit.
RUN: not llvm-readobj %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
-ENOENT: '{{.*}}.blah': {{[Nn]}}o such file or directory
+ENOENT: {{.*}}.blah: {{[Nn]}}o such file or directory
# Test case where input file is too small to be a recognised object file.
RUN: touch %t.empty
RUN: not llvm-readobj %t.empty 2>&1 | FileCheck --check-prefix=EMPTY %s
-EMPTY: '{{.*}}.empty': The file was not recognized as a valid object file
+EMPTY: {{.*}}.empty: The file was not recognized as a valid object file
# Test that unrecognised files in archives are ignored.
RUN: rm -f %t.a
; RUN: not llvm-readobj -codeview-merged-types %S/Inputs/codeview-cycle.obj 2>&1 | FileCheck %s
-; CHECK: error{{.*}} Input type graph contains cycles
+; CHECK: Error{{.*}} Input type graph contains cycles
; To reproduce codeview-cycle.obj:
; $ cat codeview-cycle.asm
# RUN: not llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
# RUN: not llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
-# ERR-SIZE: error: Invalid entity size
+# ERR-SIZE: Error reading file: Invalid entity size.
--- !ELF
FileHeader:
# RUN: not llvm-readobj --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
# RUN: not llvm-readelf --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
-# BAD-STRING: Invalid dynamic string table reference
+# BAD-STRING: Error reading file: Invalid dynamic string table reference.
--- !ELF
FileHeader:
# RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0xFFF)"
# RUN: not llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s
-# CHECK: error: Invalid data was encountered while parsing the file
+# CHECK: Error reading file: Invalid data was encountered while parsing the file.
--- !ELF
FileHeader:
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
-// CHECK: error: invalid packed relocation header
+// CHECK: Error reading file: invalid packed relocation header
.section .rela.dyn, "a", @0x60000001
.ascii "APS9"
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
-// CHECK: error: malformed sleb128, extends past end
+// CHECK: Error reading file: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
-// CHECK: error: malformed sleb128, extends past end
+// CHECK: Error reading file: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
-// CHECK: error: malformed sleb128, extends past end
+// CHECK: Error reading file: malformed sleb128, extends past end
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"
// REQUIRES: x86-registered-target
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
-// CHECK: error: relocation group unexpectedly large
+// CHECK: Error reading file: relocation group unexpectedly large
.section .rela.dyn, "a", @0x60000001
.ascii "APS2"
RUN: --elf-output-style=GNU | \
RUN: FileCheck %s -check-prefix GNU-GOT-STATIC
-GOT-OBJ: error: Cannot find .got section
+GOT-OBJ: Error reading file: Cannot find .got section.
GOT-EXE: Primary GOT {
GOT-EXE-NEXT: Canonical gp value: 0x418880
GOT-STATIC-NEXT: ]
GOT-STATIC-NEXT: }
-GNU-GOT-OBJ: error: Cannot find .got section
+GNU-GOT-OBJ: Error reading file: Cannot find .got section.
GNU-GOT-EXE: Primary GOT:
GNU-GOT-EXE-NEXT: Canonical gp value: 00418880
# CHECK-NEXT: [ 3] null{{$}}
# CHECK-NOT: {{.}}
-# RUN: not llvm-readobj --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR1
-# RUN: not llvm-readobj --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-readobj --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-readobj --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR
-# RUN: not llvm-readelf --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR1
-# RUN: not llvm-readelf --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR2
+# RUN: not llvm-readelf --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-readelf --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR
-# ERR1: error: could not find section 'does_not_exist'
-# ERR2: error: could not find section '42'
+# ERR: Error reading file: invalid section reference.
--- !ELF
FileHeader:
# RUN: rm a/b/1.o
# RUN: not llvm-readobj --file-headers a/relative.a 2>&1 | FileCheck %s --check-prefix=ERR1
# RUN: not llvm-readelf --file-headers a/relative.a 2>&1 | FileCheck %s --check-prefix=ERR1
-# ERR1: error: 'a/relative.a': 'b/1.o': {{[Nn]}}o such file or directory
+# ERR1: Error reading file: a/relative.a: 'b/1.o': {{[Nn]}}o such file or directory
# RUN: mkdir -p %t/c
# RUN: cp %p/Inputs/trivial.obj.elf-x86-64 a/b/1.o
# RUN: rm a/b/1.o
# RUN: not llvm-readobj --file-headers %t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%t
# RUN: not llvm-readelf --file-headers %t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%t
-# ERR2: error: '[[DIR]]/c/absolute.a': '[[DIR]]/a/b/1.o': {{[Nn]}}o such file or directory
+# ERR2: Error reading file: [[DIR]]/c/absolute.a: '[[DIR]]/a/b/1.o': {{[Nn]}}o such file or directory
# MISSING: File: {{.*}}1.o
# MISSING: SectionHeaderCount: 10
# MISSING-NOT: File: {{.*}}3.o
-# ERR: error: '{{.*}}.a': '{{.*}}2.o': {{[Nn]}}o such file or directory
+# ERR: Error reading file: {{.*}}.a: '{{.*}}2.o': {{[Nn]}}o such file or directory
FileHeader:
Version: 0x0000000c
-# CHECK: error: '<stdin>': Bad version number
+# CHECK: Error reading file: <stdin>: Bad version number
#include "llvm-readobj.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/raw_ostream.h"
SecIndex++;
}
- return make_error<StringError>(
- formatv("could not find section '{0}'", SecName),
- object::object_error::parse_failed);
+ return make_error<StringError>("invalid section reference",
+ object::object_error::parse_failed);
}
void ObjDumper::printSectionAsString(const object::ObjectFile *Obj,
#include "llvm/Support/Path.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/WithColor.h"
using namespace llvm;
using namespace llvm::object;
namespace llvm {
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
- errs() << "\n";
- WithColor::error(errs()) << Msg << "\n";
+ errs() << "\nError reading file: " << Msg << ".\n";
+ errs().flush();
exit(1);
}
} // namespace llvm
-static void reportError(StringRef Input, Error Err) {
+static void reportError(StringRef Input, std::error_code EC) {
if (Input == "-")
Input = "<stdin>";
- error(createFileError(Input, std::move(Err)));
+
+ reportError(Twine(Input) + ": " + EC.message());
}
-static void reportError(StringRef Input, std::error_code EC) {
- reportError(Input, errorCodeToError(EC));
+static void reportError(StringRef Input, Error Err) {
+ if (Input == "-")
+ Input = "<stdin>";
+ std::string ErrMsg;
+ {
+ raw_string_ostream ErrStream(ErrMsg);
+ logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");
+ }
+ reportError(ErrMsg);
}
static bool isMipsArch(unsigned Arch) {