Index: test/tools/llvm-readobj/elf-dynamic-malformed.test =================================================================== --- test/tools/llvm-readobj/elf-dynamic-malformed.test +++ test/tools/llvm-readobj/elf-dynamic-malformed.test @@ -20,7 +20,6 @@ # WARN-GNU-NOT: warning # WARN-GNU: warning: invalid section size (4) or entity size (16) -# WARN-GNU-EMPTY: # WARN-GNU-NEXT: ELF Header: # WARN-GNU: Symbol table '.symtab' contains 1 entries: # WARN-GNU: 0: Index: test/tools/llvm-readobj/file-name.test =================================================================== --- test/tools/llvm-readobj/file-name.test +++ test/tools/llvm-readobj/file-name.test @@ -0,0 +1,44 @@ +## This test shows that the name of the file is printed under the right +## circumstances and with the correct formatting for object inputs. + +# RUN: yaml2obj %s -o %t1 +# RUN: cp %t1 %t2 + +## Show that the file name is not printed for a single input for GNU output. +# RUN: llvm-readelf --file-headers %t1 \ +# RUN: | FileCheck %s --implicit-check-not=File: --check-prefix=GNU-SINGLE + +## Show that the very first line of the output is the one with "ELF Header" on. +# GNU-SINGLE: {{^}} +# GNU-SINGLE-SAME: ELF Header: + +## Show that the file names are printed for all inputs for GNU output. +# RUN: llvm-readelf --file-headers %t1 %t2 \ +# RUN: | FileCheck %s --check-prefixes=NAME1,GNU,NAME2 -DFILE1=%t1 -DFILE2=%t2 + +## Show that the file name is printed for a single input for LLVM output. +# RUN: llvm-readobj --file-headers %t1 | FileCheck %s --check-prefix=NAME1 -DFILE1=%t1 + +## Show that the file name is printed with correct spacing for multiple inputs +## with LLVM output. +# RUN: llvm-readobj --file-headers %t1 %t2 \ +# RUN: | FileCheck %s --check-prefixes=NAME1,LLVM,NAME2 -DFILE1=%t1 -DFILE2=%t2 + +## The very first line should be blank. CHECK-EMPTY isn't allowed on the first line. +# NAME1: {{^}} +# NAME1-NOT: {{.}} +# NAME1-SAME: {{$}} +# NAME1-NEXT: {{^}}File: [[FILE1]]{{$}} + +# GNU: Section header string table index: +# LLVM: StringTableSectionIndex: +# LLVM-NEXT: } +# NAME2-EMPTY: +# NAME2-NEXT: {{^}}File: [[FILE2]]{{$}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 Index: test/tools/llvm-readobj/stack-sizes.test =================================================================== --- test/tools/llvm-readobj/stack-sizes.test +++ test/tools/llvm-readobj/stack-sizes.test @@ -322,11 +322,13 @@ ## tables. # RUN: llvm-ar rc %t1.a %t01 %t02 -# RUN: llvm-readelf --stack-sizes %t01 %t02 | FileCheck %s --check-prefix=MULTIPLE +# RUN: llvm-readelf --stack-sizes %t01 %t02 \ +# RUN: | FileCheck %s --check-prefixes=MULTIPLE,OBJECT -DFILE1=%t01 -DFILE2=%t02 # RUN: llvm-readelf --stack-sizes %t1.a \ -# RUN: | FileCheck %s --check-prefix=MULTIPLE --check-prefix=ARCHIVE --strict-whitespace\ +# RUN: | FileCheck %s --check-prefixes=MULTIPLE,ARCHIVE --strict-whitespace\ # RUN: --match-full-lines -DFILE=%t1.a +# OBJECT:File: [[FILE1]] # ARCHIVE:File: [[FILE]]({{.*01}}) # MULTIPLE:Stack Sizes: # MULTIPLE-NEXT: Size Function @@ -334,6 +336,7 @@ # MULTIPLE-NEXT: 32 referenced_via_section_bar # MULTIPLE-NEXT: 8 separate_text_section_baz # MULTIPLE-EMPTY: +# OBJECT:File: [[FILE2]] # ARCHIVE:File: [[FILE]]({{.*02}}) # MULTIPLE-EMPTY: # MULTIPLE-NEXT:Stack Sizes: Index: tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- tools/llvm-readobj/llvm-readobj.cpp +++ tools/llvm-readobj/llvm-readobj.cpp @@ -484,17 +484,17 @@ if (std::error_code EC = createDumper(Obj, Writer, Dumper)) reportError(FileStr, EC); - Writer.startLine() << "\n"; - if (opts::Output == opts::LLVM) { + if (opts::Output == opts::LLVM || opts::InputFilenames.size() > 1 || A) { + Writer.startLine() << "\n"; Writer.printString("File", FileStr); + } + if (opts::Output == opts::LLVM) { Writer.printString("Format", Obj->getFileFormatName()); Writer.printString("Arch", Triple::getArchTypeName( (llvm::Triple::ArchType)Obj->getArch())); Writer.printString("AddressSize", formatv("{0}bit", 8 * Obj->getBytesInAddress())); Dumper->printLoadName(); - } else if (opts::Output == opts::GNU && A) { - Writer.printString("File", FileStr); } if (opts::FileHeaders)