1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

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

This commit is contained in:
Fangrui Song 2020-01-17 10:04:00 -08:00
parent 8e90006f5a
commit e480c416f6
5 changed files with 40 additions and 29 deletions

View File

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

View File

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

View File

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

View File

@ -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{{$}}

View File

@ -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);
}