[llvm] r212235 - Add the -reverse-sort flag (aka -r) to llvm-nm
Kevin Enderby
enderby at apple.com
Wed Jul 2 16:23:58 PDT 2014
Author: enderby
Date: Wed Jul 2 18:23:58 2014
New Revision: 212235
URL: http://llvm.org/viewvc/llvm-project?rev=212235&view=rev
Log:
Add the -reverse-sort flag (aka -r) to llvm-nm
which exists in other Unix nm(1)’s.
Modified:
llvm/trunk/test/Object/nm-trivial-object.test
llvm/trunk/tools/llvm-nm/llvm-nm.cpp
Modified: llvm/trunk/test/Object/nm-trivial-object.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-trivial-object.test?rev=212235&r1=212234&r2=212235&view=diff
==============================================================================
--- llvm/trunk/test/Object/nm-trivial-object.test (original)
+++ llvm/trunk/test/Object/nm-trivial-object.test Wed Jul 2 18:23:58 2014
@@ -16,6 +16,8 @@ RUN: llvm-nm %p/Inputs/trivial-object-te
RUN: | FileCheck %s -check-prefix macho64
RUN: llvm-nm %p/Inputs/macho-text-data-bss.macho-x86_64 \
RUN: | FileCheck %s -check-prefix macho-tdb
+RUN: llvm-nm -r %p/Inputs/macho-text-data-bss.macho-x86_64 \
+RUN: | FileCheck %s -check-prefix macho-r
RUN: llvm-nm %p/Inputs/common.coff-i386 \
RUN: | FileCheck %s -check-prefix COFF-COMMON
RUN: llvm-nm %p/Inputs/relocatable-with-section-address.elf-x86-64 \
@@ -77,6 +79,12 @@ macho-tdb: 000000000000000c D _d
macho-tdb: 0000000000000000 T _t
macho-tdb: 0000000000000048 S _t.eh
+macho-r: 0000000000000048 S _t.eh
+macho-r-NEXT: 0000000000000000 T _t
+macho-r-NEXT: 000000000000000c D _d
+macho-r-NEXT: 0000000000000070 b _b
+macho-r-NEXT: 0000000000000030 s EH_frame0
+
Test that nm uses addresses even with ELF .o files.
ELF-SEC-ADDR64: 0000000000000058 D a
ELF-SEC-ADDR64-NEXT: 000000000000005c D b
Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=212235&r1=212234&r2=212235&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Wed Jul 2 18:23:58 2014
@@ -111,6 +111,10 @@ cl::alias NumericSortv("v", cl::desc("Al
cl::opt<bool> NoSort("no-sort", cl::desc("Show symbols in order encountered"));
cl::alias NoSortp("p", cl::desc("Alias for --no-sort"), cl::aliasopt(NoSort));
+cl::opt<bool> ReverseSort("reverse-sort", cl::desc("Sort in reverse order"));
+cl::alias ReverseSortr("r", cl::desc("Alias for --reverse-sort"),
+ cl::aliasopt(ReverseSort));
+
cl::opt<bool> PrintSize("print-size",
cl::desc("Show symbol size instead of address"));
cl::alias PrintSizeS("S", cl::desc("Alias for --print-size"),
@@ -157,36 +161,69 @@ struct NMSymbol {
}
static bool compareSymbolAddress(const NMSymbol &A, const NMSymbol &B) {
- if (A.Address < B.Address)
- return true;
- else if (A.Address == B.Address && A.Name < B.Name)
- return true;
- else if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
- return true;
- else
- return false;
+ if (!ReverseSort) {
+ if (A.Address < B.Address)
+ return true;
+ else if (A.Address == B.Address && A.Name < B.Name)
+ return true;
+ else if (A.Address == B.Address && A.Name == B.Name && A.Size < B.Size)
+ return true;
+ else
+ return false;
+ } else {
+ if (A.Address > B.Address)
+ return true;
+ else if (A.Address == B.Address && A.Name > B.Name)
+ return true;
+ else if (A.Address == B.Address && A.Name == B.Name && A.Size > B.Size)
+ return true;
+ else
+ return false;
+ }
}
static bool compareSymbolSize(const NMSymbol &A, const NMSymbol &B) {
- if (A.Size < B.Size)
- return true;
- else if (A.Size == B.Size && A.Name < B.Name)
- return true;
- else if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
- return true;
- else
- return false;
+ if (!ReverseSort) {
+ if (A.Size < B.Size)
+ return true;
+ else if (A.Size == B.Size && A.Name < B.Name)
+ return true;
+ else if (A.Size == B.Size && A.Name == B.Name && A.Address < B.Address)
+ return true;
+ else
+ return false;
+ } else {
+ if (A.Size > B.Size)
+ return true;
+ else if (A.Size == B.Size && A.Name > B.Name)
+ return true;
+ else if (A.Size == B.Size && A.Name == B.Name && A.Address > B.Address)
+ return true;
+ else
+ return false;
+ }
}
static bool compareSymbolName(const NMSymbol &A, const NMSymbol &B) {
- if (A.Name < B.Name)
- return true;
- else if (A.Name == B.Name && A.Size < B.Size)
- return true;
- else if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
- return true;
- else
- return false;
+ if (!ReverseSort) {
+ if (A.Name < B.Name)
+ return true;
+ else if (A.Name == B.Name && A.Size < B.Size)
+ return true;
+ else if (A.Name == B.Name && A.Size == B.Size && A.Address < B.Address)
+ return true;
+ else
+ return false;
+ } else {
+ if (A.Name > B.Name)
+ return true;
+ else if (A.Name == B.Name && A.Size > B.Size)
+ return true;
+ else if (A.Name == B.Name && A.Size == B.Size && A.Address > B.Address)
+ return true;
+ else
+ return false;
+ }
}
static char isSymbolList64Bit(SymbolicFile *Obj) {
More information about the llvm-commits
mailing list