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

This reverts commit ab974161ba.

This change broke several tests, and the pre-commit bot even warning
me that it would. Doh!
This commit is contained in:
Sam Clegg 2020-01-17 09:55:18 -08:00
parent 03689fe97f
commit 2754a67ba9
5 changed files with 29 additions and 40 deletions

View File

@ -3,7 +3,8 @@
; RUN: rm -f %t2.0 ; RUN: rm -f %t2.0
; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,pl -o %t2 -thinlto-distributed-indexes ; 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-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 ; CHECK: Format: ELF64-x86-64

View File

@ -3,7 +3,7 @@
; RUN: llvm-lto -thinlto-action=run %t.bc %t2.bc -exported-symbol=__llvm_profile_filename ; 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 - < %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 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" 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 @__llvm_profile_filename = constant [19 x i8] c"default_%m.profraw\00", comdat
; EXPORTED: R __llvm_profile_filename ; EXPORTED: R __llvm_profile_filename
; NOT_EXPORTED-NOT: R __llvm_profile_filename

View File

@ -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

View File

@ -1,5 +1,6 @@
# RUN: yaml2obj %s > %t.o # 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 !ELF
FileHeader: FileHeader:
@ -8,4 +9,6 @@ FileHeader:
Type: ET_REL Type: ET_REL
Machine: EM_X86_64 Machine: EM_X86_64
# CHECK: [[FILE]]: no symbols{{$}} # CHECK: {{^}}no symbols{{$}}
# CHECK-PRINT-FILE-NAME: nm-no-symbols.test{{.*}}.o: no symbols{{$}}

View File

@ -707,19 +707,6 @@ static bool symbolIsDefined(const NMSymbol &Sym) {
return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v'; 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, static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
StringRef ArchiveName, StringRef ArchiveName,
StringRef ArchitectureName) { 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) { for (const NMSymbol &S : SymbolList) {
uint32_t SymFlags; uint32_t SymFlags;
std::string Name = S.Name.str(); std::string Name = S.Name.str();
@ -806,7 +811,7 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
(!Global && ExternalOnly) || (Weak && NoWeakSymbols)) (!Global && ExternalOnly) || (Weak && NoWeakSymbols))
continue; continue;
if (PrintFileName) if (PrintFileName)
writeFileName(outs(), ArchiveName, ArchitectureName); writeFileName(outs());
if ((JustSymbolName || if ((JustSymbolName ||
(UndefinedOnly && MachO && OutputFormat != darwin)) && (UndefinedOnly && MachO && OutputFormat != darwin)) &&
OutputFormat != posix) { OutputFormat != posix) {
@ -1203,7 +1208,7 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
if (Nsect == 0) if (Nsect == 0)
return; return;
} }
if (!(MachO && DyldInfoOnly)) { if (!MachO || !DyldInfoOnly) {
for (BasicSymbolRef Sym : Symbols) { for (BasicSymbolRef Sym : Symbols) {
uint32_t SymFlags = Sym.getFlags(); uint32_t SymFlags = Sym.getFlags();
if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific)) if (!DebugSyms && (SymFlags & SymbolRef::SF_FormatSpecific))
@ -1733,12 +1738,6 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName,
} }
CurrentFilename = Obj.getFileName(); CurrentFilename = Obj.getFileName();
if (Symbols.empty() && SymbolList.empty()) {
writeFileName(errs(), ArchiveName, ArchitectureName);
errs() << "no symbols\n";
}
sortAndPrintSymbolList(Obj, printName, ArchiveName, ArchitectureName); sortAndPrintSymbolList(Obj, printName, ArchiveName, ArchitectureName);
} }