llvm.org GIT mirror llvm / afee284
Revert "[llvm-readobj] Improve error message for --string-dump" This reverts commit 681b0798dbbc6b3500c9930977ec8a274b142acb. Reverted due to causing build failures: llvm-svn: 357772 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357774 91177308-0d34-0410-b5e6-96231b3b80d8 Stephen Tozer 1 year, 6 months ago
16 changed file(s) with 39 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
0 # Test case where input file does not exit.
11 RUN: not llvm-readobj %t.blah 2>&1 | FileCheck --check-prefix=ENOENT %s
2 ENOENT: '{{.*}}.blah': {{[Nn]}}o such file or directory
2 ENOENT: {{.*}}.blah: {{[Nn]}}o such file or directory
33
44 # Test case where input file is too small to be a recognised object file.
55 RUN: touch %t.empty
66 RUN: not llvm-readobj %t.empty 2>&1 | FileCheck --check-prefix=EMPTY %s
7 EMPTY: '{{.*}}.empty': The file was not recognized as a valid object file
7 EMPTY: {{.*}}.empty: The file was not recognized as a valid object file
88
99 # Test that unrecognised files in archives are ignored.
1010 RUN: rm -f %t.a
0 ; RUN: not llvm-readobj -codeview-merged-types %S/Inputs/codeview-cycle.obj 2>&1 | FileCheck %s
11
2 ; CHECK: error{{.*}} Input type graph contains cycles
2 ; CHECK: Error{{.*}} Input type graph contains cycles
33
44 ; To reproduce codeview-cycle.obj:
55 ; $ cat codeview-cycle.asm
22 # RUN: not llvm-readobj --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
33 # RUN: not llvm-readelf --dynamic-table %t.bad-size 2>&1 | FileCheck %s --check-prefix ERR-SIZE
44
5 # ERR-SIZE: error: Invalid entity size
5 # ERR-SIZE: Error reading file: Invalid entity size.
66
77 --- !ELF
88 FileHeader:
6868 # RUN: not llvm-readobj --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
6969 # RUN: not llvm-readelf --dynamic-table %t.bad-string 2>&1 | FileCheck %s --check-prefix BAD-STRING
7070
71 # BAD-STRING: Invalid dynamic string table reference
71 # BAD-STRING: Error reading file: Invalid dynamic string table reference.
7272
7373 --- !ELF
7474 FileHeader:
2020 # RUN: %python -c "with open(r'%t.truncated2', 'r+') as f: f.truncate(0xFFF)"
2121 # RUN: not llvm-readobj %t.truncated2 --dynamic-table 2>&1 | FileCheck %s
2222
23 # CHECK: error: Invalid data was encountered while parsing the file
23 # CHECK: Error reading file: Invalid data was encountered while parsing the file.
2424
2525 --- !ELF
2626 FileHeader:
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
22
3 // CHECK: error: invalid packed relocation header
3 // CHECK: Error reading file: invalid packed relocation header
44
55 .section .rela.dyn, "a", @0x60000001
66 .ascii "APS9"
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
22
3 // CHECK: error: malformed sleb128, extends past end
3 // CHECK: Error reading file: malformed sleb128, extends past end
44
55 .section .rela.dyn, "a", @0x60000001
66 .ascii "APS2"
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
22
3 // CHECK: error: malformed sleb128, extends past end
3 // CHECK: Error reading file: malformed sleb128, extends past end
44
55 .section .rela.dyn, "a", @0x60000001
66 .ascii "APS2"
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
22
3 // CHECK: error: malformed sleb128, extends past end
3 // CHECK: Error reading file: malformed sleb128, extends past end
44
55 .section .rela.dyn, "a", @0x60000001
66 .ascii "APS2"
0 // REQUIRES: x86-registered-target
11 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s
22
3 // CHECK: error: relocation group unexpectedly large
3 // CHECK: Error reading file: relocation group unexpectedly large
44
55 .section .rela.dyn, "a", @0x60000001
66 .ascii "APS2"
2929 RUN: --elf-output-style=GNU | \
3030 RUN: FileCheck %s -check-prefix GNU-GOT-STATIC
3131
32 GOT-OBJ: error: Cannot find .got section
32 GOT-OBJ: Error reading file: Cannot find .got section.
3333
3434 GOT-EXE: Primary GOT {
3535 GOT-EXE-NEXT: Canonical gp value: 0x418880
385385 GOT-STATIC-NEXT: ]
386386 GOT-STATIC-NEXT: }
387387
388 GNU-GOT-OBJ: error: Cannot find .got section
388 GNU-GOT-OBJ: Error reading file: Cannot find .got section.
389389
390390 GNU-GOT-EXE: Primary GOT:
391391 GNU-GOT-EXE-NEXT: Canonical gp value: 00418880
4949 # CHECK-NEXT: [ 3] null{{$}}
5050 # CHECK-NOT: {{.}}
5151
52 # RUN: not llvm-readobj --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR1
53 # RUN: not llvm-readobj --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR2
52 # RUN: not llvm-readobj --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR
53 # RUN: not llvm-readobj --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR
5454
55 # RUN: not llvm-readelf --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR1
56 # RUN: not llvm-readelf --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR2
55 # RUN: not llvm-readelf --string-dump=does_not_exist %t 2>&1 | FileCheck %s --check-prefix=ERR
56 # RUN: not llvm-readelf --string-dump=42 %t 2>&1 | FileCheck %s --check-prefix=ERR
5757
58 # ERR1: error: could not find section 'does_not_exist'
59 # ERR2: error: could not find section '42'
58 # ERR: Error reading file: invalid section reference.
6059
6160 --- !ELF
6261 FileHeader:
1515 # RUN: rm a/b/1.o
1616 # RUN: not llvm-readobj --file-headers a/relative.a 2>&1 | FileCheck %s --check-prefix=ERR1
1717 # RUN: not llvm-readelf --file-headers a/relative.a 2>&1 | FileCheck %s --check-prefix=ERR1
18 # ERR1: error: 'a/relative.a': 'b/1.o': {{[Nn]}}o such file or directory
18 # ERR1: Error reading file: a/relative.a: 'b/1.o': {{[Nn]}}o such file or directory
1919
2020 # RUN: mkdir -p %t/c
2121 # RUN: cp %p/Inputs/trivial.obj.elf-x86-64 a/b/1.o
2929 # RUN: rm a/b/1.o
3030 # RUN: not llvm-readobj --file-headers %t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%t
3131 # RUN: not llvm-readelf --file-headers %t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%t
32 # ERR2: error: '[[DIR]]/c/absolute.a': '[[DIR]]/a/b/1.o': {{[Nn]}}o such file or directory
32 # ERR2: Error reading file: [[DIR]]/c/absolute.a: '[[DIR]]/a/b/1.o': {{[Nn]}}o such file or directory
6666 # MISSING: File: {{.*}}1.o
6767 # MISSING: SectionHeaderCount: 10
6868 # MISSING-NOT: File: {{.*}}3.o
69 # ERR: error: '{{.*}}.a': '{{.*}}2.o': {{[Nn]}}o such file or directory
69 # ERR: Error reading file: {{.*}}.a: '{{.*}}2.o': {{[Nn]}}o such file or directory
33 FileHeader:
44 Version: 0x0000000c
55
6 # CHECK: error: '': Bad version number
6 # CHECK: Error reading file: : Bad version number
1515 #include "llvm-readobj.h"
1616 #include "llvm/Object/ObjectFile.h"
1717 #include "llvm/Support/Error.h"
18 #include "llvm/Support/FormatVariadic.h"
1918 #include "llvm/Support/ScopedPrinter.h"
2019 #include "llvm/Support/raw_ostream.h"
2120
5453
5554 SecIndex++;
5655 }
57 return make_error(
58 formatv("could not find section '{0}'", SecName),
59 object::object_error::parse_failed);
56 return make_error("invalid section reference",
57 object::object_error::parse_failed);
6058 }
6159
6260 void ObjDumper::printSectionAsString(const object::ObjectFile *Obj,
3838 #include "llvm/Support/Path.h"
3939 #include "llvm/Support/ScopedPrinter.h"
4040 #include "llvm/Support/TargetRegistry.h"
41 #include "llvm/Support/WithColor.h"
4241
4342 using namespace llvm;
4443 using namespace llvm::object;
367366 namespace llvm {
368367
369368 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
370 errs() << "\n";
371 WithColor::error(errs()) << Msg << "\n";
369 errs() << "\nError reading file: " << Msg << ".\n";
370 errs().flush();
372371 exit(1);
373372 }
374373
391390
392391 } // namespace llvm
393392
393 static void reportError(StringRef Input, std::error_code EC) {
394 if (Input == "-")
395 Input = "";
396
397 reportError(Twine(Input) + ": " + EC.message());
398 }
399
394400 static void reportError(StringRef Input, Error Err) {
395401 if (Input == "-")
396402 Input = "";
397 error(createFileError(Input, std::move(Err)));
398 }
399
400 static void reportError(StringRef Input, std::error_code EC) {
401 reportError(Input, errorCodeToError(EC));
403 std::string ErrMsg;
404 {
405 raw_string_ostream ErrStream(ErrMsg);
406 logAllUnhandledErrors(std::move(Err), ErrStream, Input + ": ");
407 }
408 reportError(ErrMsg);
402409 }
403410
404411 static bool isMipsArch(unsigned Arch) {