[llvm] r366147 - [llvm-readelf] Print "File: lib.a(file.o)" info when dumping archive files.
Yuanfang Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 15 15:52:01 PDT 2019
Author: yuanfang
Date: Mon Jul 15 15:52:01 2019
New Revision: 366147
URL: http://llvm.org/viewvc/llvm-project?rev=366147&view=rev
Log:
[llvm-readelf] Print "File: lib.a(file.o)" info when dumping archive files.
Match GNU readelf.
https://bugs.llvm.org/show_bug.cgi?id=35351
Reviewers: jhenderson, grimar, MaskRay, rupprecht
Reviewed by: jhenderson, MaskRay, grimar
Differential Revision: https://reviews.llvm.org/D64361
Modified:
llvm/trunk/test/tools/llvm-readobj/archive.test
llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test
llvm/trunk/test/tools/llvm-readobj/macho-universal-x86_64.i386.test
llvm/trunk/test/tools/llvm-readobj/thin-archive-paths.test
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/archive.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/archive.test?rev=366147&r1=366146&r2=366147&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/archive.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/archive.test Mon Jul 15 15:52:01 2019
@@ -2,39 +2,54 @@
# 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
-# LLVM: File: trivial.obj.elf-x86-64
+# LLVM: {{^$}}
+# LLVM-NEXT: File: [[ARFILE]](trivial.obj.elf-x86-64)
# LLVM: Format: ELF64-x86-64
# LLVM: ElfHeader {
# LLVM: Machine: EM_X86_64
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
+# LLVM: Notes [
+# LLVM: ]
+# GNU: {{^$}}
+# GNU-NEXT: File: [[ARFILE]](trivial.obj.elf-x86-64)
# GNU: ELF Header:
# GNU: Machine: Advanced Micro Devices X86-64
# GNU: Section Headers:
# GNU: Relocation section '.rela.text'
# GNU: Symbol table '.symtab'
+# GNU: There are no section groups in this file.
-# LLVM: File: trivial.obj.elf-i386
+# LLVM-EMPTY:
+# LLVM-NEXT: File: [[ARFILE]](trivial.obj.elf-i386)
# LLVM: Format: ELF32-i386
# LLVM: ElfHeader {
# LLVM: Machine: EM_386
# LLVM: Sections [
# LLVM: Relocations [
# LLVM: Symbols [
+# LLVM: Notes [
+# LLVM: ]
+# GNU-EMPTY:
+# GNU-NEXT: File: [[ARFILE]](trivial.obj.elf-i386)
# GNU: ELF Header:
# GNU: Machine: Intel 80386
# GNU: Section Headers:
# GNU: Relocation section '.rel.text'
# GNU: Symbol table '.symtab'
+# GNU: There are no section groups in this file.
-# LLVM: File: trivial.obj.coff-arm
+# LLVM-EMPTY:
+# LLVM-NEXT: File: [[ARFILE]](trivial.obj.coff-arm)
# LLVM: Format: COFF-ARM
+# GNU-EMPTY:
+# GNU-NEXT: File: [[ARFILE]](trivial.obj.coff-arm)
# COFF: ImageFileHeader {
# COFF: Machine: IMAGE_FILE_MACHINE_ARMNT
# COFF: Sections [
Modified: llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test?rev=366147&r1=366146&r2=366147&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-dynamic-malformed.test Mon Jul 15 15:52:01 2019
@@ -20,6 +20,7 @@
# 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:
Modified: llvm/trunk/test/tools/llvm-readobj/macho-universal-x86_64.i386.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/macho-universal-x86_64.i386.test?rev=366147&r1=366146&r2=366147&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/macho-universal-x86_64.i386.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/macho-universal-x86_64.i386.test Mon Jul 15 15:52:01 2019
@@ -5,10 +5,12 @@ RUN: llvm-readobj --sections %p/Inputs/m
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,8 @@ MULTISECTIONS: Reserved2: 0x0
MULTISECTIONS: }
MULTISECTIONS: ]
-MULTIHEADER-ARCHIVE: File: hello.o
+MULTIHEADER-ARCHIVE: {{^$}}
+MULTIHEADER-ARCHIVE-NEXT: File: [[ARFILE]](hello.o)
MULTIHEADER-ARCHIVE: Format: Mach-O 64-bit x86-64
MULTIHEADER-ARCHIVE: Arch: x86_64
MULTIHEADER-ARCHIVE: AddressSize: 64bit
@@ -162,7 +165,8 @@ MULTIHEADER-ARCHIVE: MH_SUBSECTIONS_
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 +182,8 @@ MULTIHEADER-ARCHIVE: MH_SUBSECTIONS_
MULTIHEADER-ARCHIVE: ]
MULTIHEADER-ARCHIVE: }
-MULTISECTIONS-ARCHIVE: File: hello.o
+MULTISECTIONS-ARCHIVE: {{^$}}
+MULTISECTIONS-ARCHIVE-NEXT: File: [[ARFILE]](hello.o)
MULTISECTIONS-ARCHIVE: Format: Mach-O 64-bit x86-64
MULTISECTIONS-ARCHIVE: Arch: x86_64
MULTISECTIONS-ARCHIVE: AddressSize: 64bit
@@ -254,7 +259,8 @@ MULTISECTIONS-ARCHIVE: Reserved1: 0x
MULTISECTIONS-ARCHIVE: Reserved2: 0x0
MULTISECTIONS-ARCHIVE: }
MULTISECTIONS-ARCHIVE: ]
-MULTISECTIONS-ARCHIVE: File: foo.o
+MULTISECTIONS-ARCHIVE-EMPTY:
+MULTISECTIONS-ARCHIVE-NEXT: File: [[ARFILE]](foo.o)
MULTISECTIONS-ARCHIVE: Format: Mach-O 32-bit i386
MULTISECTIONS-ARCHIVE: Arch: i386
MULTISECTIONS-ARCHIVE: AddressSize: 32bit
Modified: llvm/trunk/test/tools/llvm-readobj/thin-archive-paths.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/thin-archive-paths.test?rev=366147&r1=366146&r2=366147&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/thin-archive-paths.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/thin-archive-paths.test Mon Jul 15 15:52:01 2019
@@ -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
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=366147&r1=366146&r2=366147&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Mon Jul 15 15:52:01 2019
@@ -462,20 +462,27 @@ static std::error_code createDumper(cons
}
/// 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<ObjDumper> 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)
@@ -589,7 +596,7 @@ static void dumpArchive(const Archive *A
continue;
}
if (ObjectFile *Obj = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
- dumpObject(Obj, Writer);
+ dumpObject(Obj, Writer, Arc);
else if (COFFImportFile *Imp = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
dumpCOFFImportFile(Imp, Writer);
else
More information about the llvm-commits
mailing list