From dff123d1a1092d1181aceedb560fedc29cb5b3ca Mon Sep 17 00:00:00 2001 From: Saurabh Badhwar Date: Wed, 16 Jan 2019 14:38:22 +0000 Subject: [PATCH] [llvm-nm] Allow --size-sort to print symbols with only Symbol size Summary: When llvm-nm is passed only the --size-sort option for an object file, there is no output generated. The commit modifies the behavior to print the symbols sorted and their size which is also inline with the output of the GNU nm tool. Signed-off-by: Saurabh Badhwar Reviewers: enderby, rupprecht Reviewed By: rupprecht Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D56063 llvm-svn: 351347 --- test/tools/llvm-nm/X86/size-sort.test | 12 ++++++++++++ tools/llvm-nm/llvm-nm.cpp | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/tools/llvm-nm/X86/size-sort.test diff --git a/test/tools/llvm-nm/X86/size-sort.test b/test/tools/llvm-nm/X86/size-sort.test new file mode 100644 index 00000000000..64ea99e35b1 --- /dev/null +++ b/test/tools/llvm-nm/X86/size-sort.test @@ -0,0 +1,12 @@ +# RUN: llvm-nm --size-sort %p/Inputs/hello.obj.elf-x86_64 | FileCheck --check-prefix=SIZE-SORT-NO-ADDR %s +# RUN: llvm-nm --size-sort -S %p/Inputs/hello.obj.elf-x86_64 | FileCheck --check-prefix=SIZE-SORT-PRINT-ADDR %s +# RUN: llvm-nm -S %p/Inputs/hello.obj.elf-x86_64 | FileCheck --check-prefix=NO-SIZE-SORT-PRINT-ADDR %s + +# SIZE-SORT-NO-ADDR: U puts +# SIZE-SORT-NO-ADDR: 0000000000000015 T main + +# SIZE-SORT-PRINT-ADDR: U puts +# SIZE-SORT-PRINT-ADDR: 0000000000000000 0000000000000015 T main + +# NO-SIZE-SORT-PRINT-ADDR: 0000000000000000 0000000000000015 T main +# NO-SIZE-SORT-PRINT-ADDR: U puts diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 042e284e836..084e30540a1 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -798,8 +798,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName, bool Global = SymFlags & SymbolRef::SF_Global; bool Weak = SymFlags & SymbolRef::SF_Weak; if ((!Undefined && UndefinedOnly) || (Undefined && DefinedOnly) || - (!Global && ExternalOnly) || (SizeSort && !PrintAddress) || - (Weak && NoWeakSymbols)) + (!Global && ExternalOnly) || (Weak && NoWeakSymbols)) continue; if (PrintFileName) writeFileName(outs());