[llvm] a9f0025 - Reland "[llvm-nm] Don't report "no symbols" error for files that contain symbols"
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 10:09:03 PST 2020
Author: Fangrui Song
Date: 2020-01-17T10:08:42-08:00
New Revision: a9f0025acd2235dccec51cf42d1e604675639343
URL: https://github.com/llvm/llvm-project/commit/a9f0025acd2235dccec51cf42d1e604675639343
DIFF: https://github.com/llvm/llvm-project/commit/a9f0025acd2235dccec51cf42d1e604675639343.diff
LOG: Reland "[llvm-nm] Don't report "no symbols" error for files that contain symbols"
Added:
llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
Modified:
clang/test/InterfaceStubs/function-template-specialization.cpp
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:
################################################################################
diff --git a/clang/test/InterfaceStubs/function-template-specialization.cpp b/clang/test/InterfaceStubs/function-template-specialization.cpp
index 5198bafa2e5c..358f9457024e 100644
--- a/clang/test/InterfaceStubs/function-template-specialization.cpp
+++ b/clang/test/InterfaceStubs/function-template-specialization.cpp
@@ -10,8 +10,7 @@
// RUN: -DSPECIALIZE_TEMPLATE_FUNCTION=1 %s | \
// RUN: FileCheck -check-prefix=CHECK-SPECIALIZES-TEMPLATE-FUNCTION %s
-// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
-// RUN: %s | llvm-nm - 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | count 0
// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c \
// RUN: -DUSE_TEMPLATE_FUNCTION=1 %s | llvm-nm - 2>&1 | \
diff --git a/llvm/test/ThinLTO/X86/empty-module.ll b/llvm/test/ThinLTO/X86/empty-module.ll
index 01e7089415f3..0f4543446d35 100644
--- a/llvm/test/ThinLTO/X86/empty-module.ll
+++ b/llvm/test/ThinLTO/X86/empty-module.ll
@@ -3,8 +3,7 @@
; 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 | FileCheck %s -check-prefix=NO-SYMBOLS
-; NO-SYMBOLS: no symbols
+; RUN: llvm-nm %t2.0 2>&1 | count 0
; 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 4fd72cf3f05c..d70a674aff40 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 | FileCheck %s --check-prefix=NOT_EXPORTED
+; RUN: llvm-nm -o - < %t2.bc.thinlto.o 2>&1 | count 0
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,4 +13,3 @@ $__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
new file mode 100644
index 000000000000..10441661cd25
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/X86/nm-no-symbols-local-only.yaml
@@ -0,0 +1,15 @@
+## 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 808a9b1301f9..bb4f0b03a47e 100644
--- a/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
+++ b/llvm/test/tools/llvm-nm/X86/nm-no-symbols.test
@@ -1,6 +1,5 @@
# RUN: yaml2obj %s > %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
+# RUN: llvm-nm %t.o 2>&1 | FileCheck %s -DFILE=%t.o
!ELF
FileHeader:
@@ -9,6 +8,4 @@ FileHeader:
Type: ET_REL
Machine: EM_X86_64
-# CHECK: {{^}}no symbols{{$}}
-
-# CHECK-PRINT-FILE-NAME: nm-no-symbols.test{{.*}}.o: no symbols{{$}}
+# CHECK: [[FILE]]: no symbols{{$}}
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 28f30a7b37b5..2cd74af08c88 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -707,6 +707,19 @@ 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) {
@@ -773,24 +786,6 @@ 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();
@@ -811,7 +806,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
(!Global && ExternalOnly) || (Weak && NoWeakSymbols))
continue;
if (PrintFileName)
- writeFileName(outs());
+ writeFileName(outs(), ArchiveName, ArchitectureName);
if ((JustSymbolName ||
(UndefinedOnly && MachO && OutputFormat != darwin)) &&
OutputFormat != posix) {
@@ -1208,7 +1203,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))
@@ -1738,6 +1733,12 @@ 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