[llvm-size] Fix missing file name for darwin output format with non-Mach-O

llvm-size falls back to printing in Berkeley format, if --format=darwin is specified and a non-Mach-O object has been provided. However, it does not print the input filename when it should:

Before -
(base) xgupta@archlinux ~/llvm/llvm-project/build (main*) $ llvm-size ~/hello.o --format=darwin
   text	   data	    bss	    dec	    hex	filename
    291	      0	      0	    291	    123	%

After -
(base) xgupta@archlinux ~/llvm/llvm-project/build (main*) $ bin/llvm-size ~/hello.o --format=darwin
   text	   data	    bss	    dec	    hex	filename
    291	      0	      0	    291	    123	/home/xgupta/hello.o

Fix #42316

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D132364
This commit is contained in:
Shivam Gupta 2022-08-30 18:47:24 +05:30
parent 519847fefc
commit 25fdcb8e6c
3 changed files with 20 additions and 5 deletions

View File

@ -16,6 +16,7 @@
# RUN: llvm-size -B %t2.a | FileCheck %s -DARCHIVE=%t2.a --check-prefix=BERKELEY-1
# RUN: llvm-size -A %t2.a | FileCheck %s -DARCHIVE=%t2.a --check-prefix=SYSV-1
# RUN: llvm-size -m %t2.a | FileCheck %s -DARCHIVE=%t2.a --check-prefix=DARWIN-1
## Case 3: Multiple members.
# RUN: rm -f %t3.a
@ -23,6 +24,7 @@
# RUN: llvm-size -B %t3.a | FileCheck %s -DARCHIVE=%t3.a --check-prefixes=BERKELEY-1,BERKELEY-2
# RUN: llvm-size -A %t3.a | FileCheck %s -DARCHIVE=%t3.a --check-prefixes=SYSV-1,SYSV-2
# RUN: llvm-size -m %t3.a | FileCheck %s -DARCHIVE=%t3.a --check-prefixes=DARWIN-1,DARWIN-2
## Case 4: Mixing archives and non-archives produces sensible output:
# RUN: llvm-size -B %t1 %t2.a %t2 %t3.a \
@ -31,6 +33,9 @@
# RUN: llvm-size -A %t1 %t2.a %t2 %t3.a \
# RUN: | FileCheck %s -DARCHIVE=%t3.a -DARCHIVE2=%t2.a -DFILE1=%t1 -DFILE2=%t2 \
# RUN: --check-prefixes=SYSV-1,SYSV-2,SYSV-3
# RUN: llvm-size -B %t1 %t2.a %t2 %t3.a \
# RUN: | FileCheck %s -DARCHIVE=%t3.a -DARCHIVE2=%t2.a -DFILE1=%t1 -DFILE2=%t2 \
# RUN: --check-prefixes=DARWIN-1,DARWIN-2,DARWIN-3
# BERKELEY-1: text data bss dec hex filename
# BERKELEY-3-NEXT: 1 2 4 7 7 [[FILE1]]
@ -81,6 +86,14 @@
# SYSV-2-NEXT: Total 56
# SYSV-1-NOT:{{.}}
# DARWIN-1: text data bss dec hex filename
# DARWIN-3-NEXT: 1 2 4 7 7 [[FILE1]]
# DARWIN-3-NEXT: 1 2 4 7 7 archive.test.tmp1 (ex [[ARCHIVE2]])
# DARWIN-3-NEXT: 8 16 32 56 38 [[FILE2]]
# DARWIN-1-NEXT: 1 2 4 7 7 archive.test.tmp1 (ex [[ARCHIVE]])
# DARWIN-2-NEXT: 8 16 32 56 38 archive.test.tmp2 (ex [[ARCHIVE]])
# DARWIN-1-NOT:{{.}}
--- !ELF
FileHeader:
Class: ELFCLASS64

View File

@ -2,13 +2,11 @@
## specified and the input is not Mach-O.
# RUN: yaml2obj %s -o %t
# RUN: llvm-size -m %t | FileCheck %s
# RUN: llvm-size --format=darwin %t | FileCheck %s
# RUN: llvm-size -m %t | FileCheck -DFILE=%t %s
# RUN: llvm-size --format=darwin %t | FileCheck -DFILE=%t %s
## FIXME: The input filename should be printed but isn't currently due to
## https://bugs.llvm.org/show_bug.cgi?id=42971.
# CHECK: text data bss dec hex filename
# CHECK-NEXT: 0 0 0 0 0
# CHECK-NEXT: 0 0 0 0 0 [[FILE]]{{$}}
--- !ELF
FileHeader:

View File

@ -570,6 +570,8 @@ static void printFileSectionSizes(StringRef file) {
else if (MachO && OutputFormat == darwin)
outs() << a->getFileName() << "(" << o->getFileName() << "):\n";
printObjectSectionSizes(o);
if (!MachO && OutputFormat == darwin)
outs() << o->getFileName() << " (ex " << a->getFileName() << ")\n";
if (OutputFormat == berkeley) {
if (MachO)
outs() << a->getFileName() << "(" << o->getFileName() << ")\n";
@ -836,6 +838,8 @@ static void printFileSectionSizes(StringRef file) {
else if (MachO && OutputFormat == darwin && MoreThanOneFile)
outs() << o->getFileName() << ":\n";
printObjectSectionSizes(o);
if (!MachO && OutputFormat == darwin)
outs() << o->getFileName() << "\n";
if (OutputFormat == berkeley) {
if (!MachO || MoreThanOneFile)
outs() << o->getFileName();