[llvm] 2754a67 - Revert "[llvm-nm] Don't report "no symbols" error for files that contain symbols"

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 17 09:58:52 PST 2020


Author: Sam Clegg
Date: 2020-01-17T09:57:32-08:00
New Revision: 2754a67ba9e9e3fecd4c8f01a5a2c4ef286d206d

URL: https://github.com/llvm/llvm-project/commit/2754a67ba9e9e3fecd4c8f01a5a2c4ef286d206d
DIFF: https://github.com/llvm/llvm-project/commit/2754a67ba9e9e3fecd4c8f01a5a2c4ef286d206d.diff

LOG: Revert "[llvm-nm] Don't report "no symbols" error for files that contain symbols"

This reverts commit ab974161ba699534f3e30b1f4b036eec9c33053c.

This change broke several tests, and the pre-commit bot even warning
me that it would. Doh!

Added: 
    

Modified: 
    llvm/test/ThinLTO/X86/empty-module.ll
    llvm/test/ThinLTO/X86/strong_non_prevailing.ll
    llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
    llvm/tools/llvm-nm/llvm-nm.cpp

Removed: 
    llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml


################################################################################
diff  --git a/llvm/test/ThinLTO/X86/empty-module.ll b/llvm/test/ThinLTO/X86/empty-module.ll
index 0f4543446d35..01e7089415f3 100644
--- a/llvm/test/ThinLTO/X86/empty-module.ll
+++ b/llvm/test/ThinLTO/X86/empty-module.ll
@@ -3,7 +3,8 @@
 ; RUN: rm -f %t2.0
 ; RUN: llvm-lto2 run  %t.bc -r %t.bc,foo,pl -o %t2 -thinlto-distributed-indexes
 ; RUN: llvm-readobj -h %t2.0 | FileCheck %s
-; RUN: llvm-nm %t2.0 2>&1 | count 0
+; RUN: llvm-nm %t2.0 2>&1 | FileCheck %s -check-prefix=NO-SYMBOLS
+; NO-SYMBOLS: no symbols
 
 ; CHECK: Format: ELF64-x86-64
 

diff  --git a/llvm/test/ThinLTO/X86/strong_non_prevailing.ll b/llvm/test/ThinLTO/X86/strong_non_prevailing.ll
index d70a674aff40..4fd72cf3f05c 100644
--- a/llvm/test/ThinLTO/X86/strong_non_prevailing.ll
+++ b/llvm/test/ThinLTO/X86/strong_non_prevailing.ll
@@ -3,7 +3,7 @@
 
 ; RUN: llvm-lto -thinlto-action=run %t.bc %t2.bc -exported-symbol=__llvm_profile_filename
 ; RUN: llvm-nm -o - < %t.bc.thinlto.o | FileCheck %s --check-prefix=EXPORTED
-; RUN: llvm-nm -o - < %t2.bc.thinlto.o 2>&1 | count 0
+; RUN: llvm-nm -o - < %t2.bc.thinlto.o 2>&1 | FileCheck %s --check-prefix=NOT_EXPORTED
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
@@ -13,3 +13,4 @@ $__llvm_profile_filename = comdat any
 @__llvm_profile_filename = constant [19 x i8] c"default_%m.profraw\00", comdat
 
 ; EXPORTED: R __llvm_profile_filename
+; NOT_EXPORTED-NOT: R __llvm_profile_filename

diff  --git a/llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml b/llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
deleted file mode 100644
index 10441661cd25..000000000000
--- a/llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
+++ /dev/null
@@ -1,15 +0,0 @@
-## When a file contains only local symbols the "no symbols" error should not
-## be shown, so we expect the output to be completely empty.
-# RUN: yaml2obj %s > %t.o
-# RUN: llvm-nm %t.o 2>&1 | count 0
-
-!ELF
-FileHeader:
-  Class:   ELFCLASS64
-  Data:    ELFDATA2LSB
-  Type:    ET_REL
-  Machine: EM_X86_64
-Symbols:
-  - Name:  foo.c
-    Type:  STT_FILE
-    Index: SHN_ABS

diff  --git a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
index bb4f0b03a47e..808a9b1301f9 100644
--- a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
+++ b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
@@ -1,5 +1,6 @@
 # RUN: yaml2obj %s > %t.o
-# RUN: llvm-nm %t.o 2>&1 | FileCheck %s -DFILE=%t.o
+# RUN: llvm-nm %t.o 2>&1 | FileCheck %s
+# RUN: llvm-nm --print-file-name %t.o 2>&1 | FileCheck %s --check-prefix=CHECK-PRINT-FILE-NAME
 
 !ELF
 FileHeader:
@@ -8,4 +9,6 @@ FileHeader:
   Type:            ET_REL
   Machine:         EM_X86_64
 
-# CHECK: [[FILE]]: no symbols{{$}}
+# CHECK: {{^}}no symbols{{$}}
+
+# CHECK-PRINT-FILE-NAME: nm-no-symbols.test{{.*}}.o: no symbols{{$}}

diff  --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 2cd74af08c88..28f30a7b37b5 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -707,19 +707,6 @@ static bool symbolIsDefined(const NMSymbol &Sym) {
   return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v';
 }
 
-static void writeFileName(raw_ostream &S, StringRef ArchiveName,
-                          StringRef ArchitectureName) {
-  if (!ArchitectureName.empty())
-    S << "(for architecture " << ArchitectureName << "):";
-  if (OutputFormat == posix && !ArchiveName.empty())
-    S << ArchiveName << "[" << CurrentFilename << "]: ";
-  else {
-    if (!ArchiveName.empty())
-      S << ArchiveName << ":";
-    S << CurrentFilename << ": ";
-  }
-}
-
 static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
                                    StringRef ArchiveName,
                                    StringRef ArchitectureName) {
@@ -786,6 +773,24 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
     }
   }
 
+  auto writeFileName = [&](raw_ostream &S) {
+    if (!ArchitectureName.empty())
+      S << "(for architecture " << ArchitectureName << "):";
+    if (OutputFormat == posix && !ArchiveName.empty())
+      S << ArchiveName << "[" << CurrentFilename << "]: ";
+    else {
+      if (!ArchiveName.empty())
+        S << ArchiveName << ":";
+      S << CurrentFilename << ": ";
+    }
+  };
+
+  if (SymbolList.empty()) {
+    if (PrintFileName)
+      writeFileName(errs());
+    errs() << "no symbols\n";
+  }
+
   for (const NMSymbol &S : SymbolList) {
     uint32_t SymFlags;
     std::string Name = S.Name.str();
@@ -806,7 +811,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
         (!Global && ExternalOnly) || (Weak && NoWeakSymbols))
       continue;
     if (PrintFileName)
-      writeFileName(outs(), ArchiveName, ArchitectureName);
+      writeFileName(outs());
     if ((JustSymbolName ||
          (UndefinedOnly && MachO && OutputFormat != darwin)) &&
         OutputFormat != posix) {
@@ -1203,7 +1208,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
     if (Nsect == 0)
       return;
   }
-  if (!(MachO && DyldInfoOnly)) {
+  if (!MachO || !DyldInfoOnly) {
     for (BasicSymbolRef Sym : Symbols) {
       uint32_t SymFlags = Sym.getFlags();
       if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific))
@@ -1733,12 +1738,6 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
   }
 
   CurrentFilename = Obj.getFileName();
-
-  if (Symbols.empty() && SymbolList.empty()) {
-    writeFileName(errs(), ArchiveName, ArchitectureName);
-    errs() << "no symbols\n";
-  }
-
   sortAndPrintSymbolList(Obj, printName, ArchiveName, ArchitectureName);
 }
 


        


More information about the llvm-commits mailing list