This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by xgupta on Aug 22 2022, 3:03 AM.

Details

Summary

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

Diff Detail

Event Timeline

xgupta created this revision.Aug 22 2022, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 3:03 AM
xgupta requested review of this revision.Aug 22 2022, 3:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2022, 3:03 AM

Thanks for the patch @xgupta. Please could you write a new test (or update an existing one) in the lit testsuite at llvm\test\tools\llvm-size, to make sure this fix is covered by a test.

llvm/tools/llvm-size/llvm-size.cpp
512–513

I'm not sure this is the right place for this patch. The filenames are usually printed elsewhere, at the call site.

xgupta updated this revision to Diff 455555.Aug 25 2022, 5:56 AM
xgupta edited the summary of this revision. (Show Details)

Address comment and update test case

xgupta marked an inline comment as done.Aug 25 2022, 5:57 AM

There are several other call sites to printObjectSectionSizes in llvm-size. At least one of those (to do with printing archive members) needs updating too (and a corresponding test added). There may be others too, but I think most of the other call sites would result in darwin format printing, since they are for handling Mach-O files or variations thereof. However, you should check.

llvm/test/tools/llvm-size/elf-m.test
9

It might be worth adding {{$}} to the end of this line. This will prevent FileCheck from matching successfully, if there's garbage after the filename.

xgupta updated this revision to Diff 455877.Aug 26 2022, 5:29 AM

Address comment for printing archive statistics

jhenderson accepted this revision.Aug 30 2022, 2:34 AM

Looks good to me, thanks! Do you have commit access?

This revision is now accepted and ready to land.Aug 30 2022, 2:34 AM

Looks good to me, thanks! Do you have commit access?

Thank you very much for the review. I do have commit access. I will run check-llvm and then commit it.