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

Shivam Gupta via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 08:32:26 PDT 2022


Author: Shivam Gupta
Date: 2022-08-30T21:01:19+05:30
New Revision: 25fdcb8e6ce362d2a5e9a2f113d744d2f68d3388

URL: https://github.com/llvm/llvm-project/commit/25fdcb8e6ce362d2a5e9a2f113d744d2f68d3388
DIFF: https://github.com/llvm/llvm-project/commit/25fdcb8e6ce362d2a5e9a2f113d744d2f68d3388.diff

LOG: [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 at 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 at 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

Added: 
    

Modified: 
    llvm/test/tools/llvm-size/archive.test
    llvm/test/tools/llvm-size/elf-m.test
    llvm/tools/llvm-size/llvm-size.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-size/archive.test b/llvm/test/tools/llvm-size/archive.test
index 23c4cd10c4912..bf69a077943fe 100644
--- a/llvm/test/tools/llvm-size/archive.test
+++ b/llvm/test/tools/llvm-size/archive.test
@@ -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

diff  --git a/llvm/test/tools/llvm-size/elf-m.test b/llvm/test/tools/llvm-size/elf-m.test
index c18184feb1226..dad3001ee385f 100644
--- a/llvm/test/tools/llvm-size/elf-m.test
+++ b/llvm/test/tools/llvm-size/elf-m.test
@@ -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:

diff  --git a/llvm/tools/llvm-size/llvm-size.cpp b/llvm/tools/llvm-size/llvm-size.cpp
index 1c7484ba5496b..d65505f3056dc 100644
--- a/llvm/tools/llvm-size/llvm-size.cpp
+++ b/llvm/tools/llvm-size/llvm-size.cpp
@@ -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();


        


More information about the llvm-commits mailing list