Tweak llvm-nm’s -undefined-only (aka -u) printing for Mach-O files
authorKevin Enderby <enderby@apple.com>
Mon, 28 Jul 2014 23:17:38 +0000 (23:17 +0000)
committerKevin Enderby <enderby@apple.com>
Mon, 28 Jul 2014 23:17:38 +0000 (23:17 +0000)
to just print the symbol name.  So it matches darwin’s nm(1) -u option.

llvm-svn: 214143

llvm/test/Object/nm-trivial-object.test
llvm/tools/llvm-nm/llvm-nm.cpp

index a7bb7ca..4e44b7b 100644 (file)
@@ -6,6 +6,8 @@ RUN: llvm-nm %p/Inputs/trivial-object-test.elf-i386 \
 RUN:         | FileCheck %s -check-prefix ELF
 RUN: llvm-nm -o %p/Inputs/trivial-object-test.elf-i386 \
 RUN:         | FileCheck %s -check-prefix ELF-o
+RUN: llvm-nm -u %p/Inputs/trivial-object-test.elf-i386 \
+RUN:         | FileCheck %s -check-prefix ELF-u
 RUN: llvm-nm %p/Inputs/trivial-object-test.elf-x86-64 \
 RUN:         | FileCheck %s -check-prefix ELF64
 RUN: llvm-nm %p/Inputs/weak.elf-x86-64 \
@@ -32,6 +34,8 @@ RUN: llvm-nm -o %p/Inputs/macho-text-data-bss.macho-x86_64 \
 RUN:         | FileCheck %s -check-prefix macho-o
 RUN: llvm-nm -p -a %p/Inputs/macho-hello-g.macho-x86_64 \
 RUN:         | FileCheck %s -check-prefix macho-pa
+RUN: llvm-nm -u %p/Inputs/macho-hello-g.macho-x86_64 \
+RUN:         | FileCheck %s -check-prefix macho-u
 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 \
@@ -70,6 +74,9 @@ ELF-o: {{.*}}/trivial-object-test.elf-i386:          U SomeOtherFunction
 ELF-o: {{.*}}/trivial-object-test.elf-i386: 00000000 T main
 ELF-o: {{.*}}/trivial-object-test.elf-i386:          U puts
 
+ELF-u:          U SomeOtherFunction
+ELF-u:          U puts
+
 ELF64:                  U SomeOtherFunction
 ELF64: 0000000000000000 T main
 ELF64:                  U puts
@@ -145,6 +152,9 @@ macho-pa: 0000000100000f30 T _main
 macho-pa:                  U _printf
 macho-pa:                  U dyld_stub_binder
 
+macho-u: _printf
+macho-u: dyld_stub_binder
+
 Test that nm uses addresses even with ELF .o files.
 ELF-SEC-ADDR64:      0000000000000058 D a
 ELF-SEC-ADDR64-NEXT: 000000000000005c D b
index 38c945c..07a85c4 100644 (file)
@@ -583,7 +583,7 @@ static void sortAndPrintSymbolList(SymbolicFile *Obj, bool printName,
         outs() << ArchiveName << ":";
       outs() << CurrentFilename << ": ";
     }
-    if (JustSymbolName) {
+    if (JustSymbolName || (UndefinedOnly && isa<MachOObjectFile>(Obj))) {
       outs() << I->Name << "\n";
       continue;
     }