diff --git a/llvm/test/tools/llvm-readobj/archive.test b/llvm/test/tools/llvm-readobj/archive.test --- a/llvm/test/tools/llvm-readobj/archive.test +++ b/llvm/test/tools/llvm-readobj/archive.test @@ -2,10 +2,11 @@ # RUN: rm -f %t.a # RUN: llvm-ar rc %t.a %p/Inputs/trivial.obj.elf-x86-64 %p/Inputs/trivial.obj.elf-i386 %p/Inputs/trivial.obj.coff-arm -# RUN: llvm-readobj --all %t.a | FileCheck %s --check-prefixes=LLVM,COFF -# RUN: llvm-readelf --all %t.a | FileCheck %s --check-prefixes=GNU,COFF +# RUN: llvm-readobj --all %t.a | FileCheck %s --DARFILE="%t.a" --check-prefixes=HEADER,LLVM,COFF +# RUN: llvm-readelf --all %t.a | FileCheck %s --DARFILE="%t.a" --check-prefixes=HEADER,GNU,COFF + +# HEADER: File: [[ARFILE]](trivial.obj.elf-x86-64) -# LLVM: File: trivial.obj.elf-x86-64 # LLVM: Format: ELF64-x86-64 # LLVM: ElfHeader { # LLVM: Machine: EM_X86_64 @@ -19,7 +20,8 @@ # GNU: Relocation section '.rela.text' # GNU: Symbol table '.symtab' -# LLVM: File: trivial.obj.elf-i386 +# HEADER: File: [[ARFILE]](trivial.obj.elf-i386) + # LLVM: Format: ELF32-i386 # LLVM: ElfHeader { # LLVM: Machine: EM_386 @@ -33,7 +35,8 @@ # GNU: Relocation section '.rel.text' # GNU: Symbol table '.symtab' -# LLVM: File: trivial.obj.coff-arm +# HEADER: File: [[ARFILE]](trivial.obj.coff-arm) + # LLVM: Format: COFF-ARM # COFF: ImageFileHeader { # COFF: Machine: IMAGE_FILE_MACHINE_ARMNT diff --git a/llvm/test/tools/llvm-readobj/macho-universal-x86_64.i386.test b/llvm/test/tools/llvm-readobj/macho-universal-x86_64.i386.test --- a/llvm/test/tools/llvm-readobj/macho-universal-x86_64.i386.test +++ b/llvm/test/tools/llvm-readobj/macho-universal-x86_64.i386.test @@ -5,10 +5,12 @@ RUN: | FileCheck %s -check-prefix MULTISECTIONS RUN: llvm-readobj -h %p/Inputs/macho-universal-archive.x86_64.i386 \ -RUN: | FileCheck %s -check-prefix MULTIHEADER-ARCHIVE +RUN: | FileCheck %s -check-prefix MULTIHEADER-ARCHIVE \ +RUN: -DARFILE="%p/Inputs/macho-universal-archive.x86_64.i386" RUN: llvm-readobj --sections %p/Inputs/macho-universal-archive.x86_64.i386 \ -RUN: | FileCheck %s -check-prefix MULTISECTIONS-ARCHIVE +RUN: | FileCheck %s -check-prefix MULTISECTIONS-ARCHIVE \ +RUN: -DARFILE="%p/Inputs/macho-universal-archive.x86_64.i386" MULTIHEADER: Format: Mach-O 64-bit x86-64 MULTIHEADER: Arch: x86_64 @@ -146,7 +148,7 @@ MULTISECTIONS: } MULTISECTIONS: ] -MULTIHEADER-ARCHIVE: File: hello.o +MULTIHEADER-ARCHIVE: File: [[ARFILE]](hello.o) MULTIHEADER-ARCHIVE: Format: Mach-O 64-bit x86-64 MULTIHEADER-ARCHIVE: Arch: x86_64 MULTIHEADER-ARCHIVE: AddressSize: 64bit @@ -162,7 +164,8 @@ MULTIHEADER-ARCHIVE: ] MULTIHEADER-ARCHIVE: Reserved: 0x0 MULTIHEADER-ARCHIVE: } -MULTIHEADER-ARCHIVE: File: foo.o +MULTIHEADER-ARCHIVE-EMPTY: +MULTIHEADER-ARCHIVE-NEXT: File: [[ARFILE]](foo.o) MULTIHEADER-ARCHIVE: Format: Mach-O 32-bit i386 MULTIHEADER-ARCHIVE: Arch: i386 MULTIHEADER-ARCHIVE: AddressSize: 32bit @@ -178,7 +181,7 @@ MULTIHEADER-ARCHIVE: ] MULTIHEADER-ARCHIVE: } -MULTISECTIONS-ARCHIVE: File: hello.o +MULTISECTIONS-ARCHIVE: File: [[ARFILE]](hello.o) MULTISECTIONS-ARCHIVE: Format: Mach-O 64-bit x86-64 MULTISECTIONS-ARCHIVE: Arch: x86_64 MULTISECTIONS-ARCHIVE: AddressSize: 64bit @@ -254,7 +257,7 @@ MULTISECTIONS-ARCHIVE: Reserved2: 0x0 MULTISECTIONS-ARCHIVE: } MULTISECTIONS-ARCHIVE: ] -MULTISECTIONS-ARCHIVE: File: foo.o +MULTISECTIONS-ARCHIVE: File: [[ARFILE]](foo.o) MULTISECTIONS-ARCHIVE: Format: Mach-O 32-bit i386 MULTISECTIONS-ARCHIVE: Arch: i386 MULTISECTIONS-ARCHIVE: AddressSize: 32bit diff --git a/llvm/test/tools/llvm-readobj/thin-archive-paths.test b/llvm/test/tools/llvm-readobj/thin-archive-paths.test --- a/llvm/test/tools/llvm-readobj/thin-archive-paths.test +++ b/llvm/test/tools/llvm-readobj/thin-archive-paths.test @@ -8,8 +8,8 @@ # RUN: llvm-ar rcT a/relative.a a/b/1.o # Show that relative paths in the file header printing look sensible. -# RUN: llvm-readobj --file-headers a/relative.a | FileCheck %s --check-prefix=REL -# REL: File: b/1.o +# RUN: llvm-readobj --file-headers a/relative.a | FileCheck %s --DARFILE="a/relative.a" --check-prefix=REL +# REL: File: [[ARFILE]](b/1.o) # Show that relative paths in an error message for both archive and member look # sensible. @@ -23,8 +23,8 @@ # RUN: llvm-ar rcT c/absolute.a %t/a/b/1.o # Show that absolute paths in the file header printing are correct. -# RUN: llvm-readobj --file-headers c/absolute.a | FileCheck %s --check-prefix=ABS -DDIR=%/t -# ABS: File: [[DIR]]/a/b/1.o +# RUN: llvm-readobj --file-headers c/absolute.a | FileCheck %s --check-prefix=ABS -DARFILE="c/absolute.a" -DDIR=%/t +# ABS: File: [[ARFILE]]([[DIR]]/a/b/1.o) # Show that absolute paths in an error message for both archive and member are correct. # RUN: rm a/b/1.o diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -461,20 +461,27 @@ } /// Dumps the specified object file. -static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer) { +static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer, + const Archive *A = nullptr) { + std::string FileStr = + A ? Twine(A->getFileName() + "(" + Obj->getFileName() + ")").str() + : Obj->getFileName().str(); + std::unique_ptr Dumper; if (std::error_code EC = createDumper(Obj, Writer, Dumper)) - reportError(Obj->getFileName(), EC); + reportError(FileStr, EC); + Writer.startLine() << "\n"; if (opts::Output == opts::LLVM) { - Writer.startLine() << "\n"; - Writer.printString("File", Obj->getFileName()); + Writer.printString("File", FileStr); 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) @@ -588,7 +595,7 @@ continue; } if (ObjectFile *Obj = dyn_cast(&*ChildOrErr.get())) - dumpObject(Obj, Writer); + dumpObject(Obj, Writer, Arc); else if (COFFImportFile *Imp = dyn_cast(&*ChildOrErr.get())) dumpCOFFImportFile(Imp, Writer); else