forked from OSchip/llvm-project
[llvm-nm] Print an explicit "no symbols" message when an object file has no symbols
Summary: GNU nm (and other nm implementations, such as "go tool nm") prints an explicit "no symbols" message when an object file has no symbols. Currently llvm-nm just doesn't print anything. Adding an explicit "no symbols" message will allow llvm-nm to be used in place of nm: some scripts and build processes use `nm <file> | grep "no symbols"` as a test to see if a file has no symbols. It will also be more familiar to anyone used to nm. That said, the format implemented here is slightly different, in that it doesn't print the tool name in the message (which IMHO is not useful to include). Demo: ``` $ for nm in nm bin/llvm-nm ; do echo "nm implementation: $nm"; $nm /tmp/foo{1,2}.o; echo; done nm implementation: nm /tmp/foo1.o: nm: /tmp/foo1.o: no symbols /tmp/foo2.o: 0000000000000000 T foo2 nm implementation: bin/llvm-nm /tmp/foo1.o: no symbols /tmp/foo2.o: 0000000000000000 T foo2 ``` Reviewers: MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D52810 llvm-svn: 343742
This commit is contained in:
parent
5ac0a2fc48
commit
53cb573564
|
@ -30,4 +30,5 @@ RUN: | FileCheck %s -check-prefix ERROR
|
|||
|
||||
ERROR: File format has no dynamic symbol table.
|
||||
|
||||
RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 | count 0
|
||||
RUN: llvm-nm -D %p/Inputs/trivial-object-test.elf-i386 | FileCheck %s -check-prefix=NO-SYMBOLS
|
||||
NO-SYMBOLS: no symbols
|
||||
|
|
|
@ -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 | count 0
|
||||
; RUN: llvm-nm %t2.0 | FileCheck %s -check-prefix=NO-SYMBOLS
|
||||
; NO-SYMBOLS: no symbols
|
||||
|
||||
; CHECK: Format: ELF64-x86-64
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
; RUN: llvm-as -o %t/bcsection.bc %s
|
||||
|
||||
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-unknown-unknown -o %t/bcsection.bco %p/Inputs/bcsection.s
|
||||
; RUN: llvm-nm -no-llvm-bc %t/bcsection.bco | count 0
|
||||
; RUN: llvm-nm -no-llvm-bc %t/bcsection.bco | FileCheck %s -check-prefix=NO-SYMBOLS
|
||||
; NO-SYMBOLS: no symbols
|
||||
|
||||
; RUN: %gold -r -o %t/bcsection.o -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext %t/bcsection.bco
|
||||
; RUN: llvm-nm -no-llvm-bc %t/bcsection.o | FileCheck %s
|
||||
|
||||
|
|
|
@ -83,7 +83,8 @@
|
|||
; RUN: --plugin-opt=obj-path=%t5.o \
|
||||
; RUN: -shared %t.o %t2.o -o %t4
|
||||
; RUN: llvm-readobj -h %t5.o | FileCheck %s --check-prefix=FORMAT
|
||||
; RUN: llvm-nm %t5.o | count 0
|
||||
; RUN: llvm-nm %t5.o | FileCheck %s -check-prefix=NO-SYMBOLS
|
||||
; NO-SYMBOLS: no symbols
|
||||
|
||||
; NM: T f
|
||||
; NM2: T {{f|g}}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# RUN: yaml2obj %s > %t.o
|
||||
# RUN: llvm-nm %t.o | FileCheck %s
|
||||
# RUN: llvm-nm --print-file-name %t.o | FileCheck %s --check-prefix=CHECK-PRINT-FILE-NAME
|
||||
|
||||
!ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
|
||||
# CHECK: {{^}}no symbols{{$}}
|
||||
|
||||
# CHECK-PRINT-FILE-NAME: nm-no-symbols.test{{.*}}.o: no symbols{{$}}
|
|
@ -757,6 +757,24 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
|
|||
}
|
||||
}
|
||||
|
||||
auto writeFileName = [&]() {
|
||||
if (!ArchitectureName.empty())
|
||||
outs() << "(for architecture " << ArchitectureName << "):";
|
||||
if (OutputFormat == posix && !ArchiveName.empty())
|
||||
outs() << ArchiveName << "[" << CurrentFilename << "]: ";
|
||||
else {
|
||||
if (!ArchiveName.empty())
|
||||
outs() << ArchiveName << ":";
|
||||
outs() << CurrentFilename << ": ";
|
||||
}
|
||||
};
|
||||
|
||||
if (SymbolList.empty()) {
|
||||
if (PrintFileName)
|
||||
writeFileName();
|
||||
outs() << "no symbols\n";
|
||||
}
|
||||
|
||||
for (SymbolListT::iterator I = SymbolList.begin(), E = SymbolList.end();
|
||||
I != E; ++I) {
|
||||
uint32_t SymFlags;
|
||||
|
@ -778,17 +796,8 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
|
|||
(!Global && ExternalOnly) || (SizeSort && !PrintAddress) ||
|
||||
(Weak && NoWeakSymbols))
|
||||
continue;
|
||||
if (PrintFileName) {
|
||||
if (!ArchitectureName.empty())
|
||||
outs() << "(for architecture " << ArchitectureName << "):";
|
||||
if (OutputFormat == posix && !ArchiveName.empty())
|
||||
outs() << ArchiveName << "[" << CurrentFilename << "]: ";
|
||||
else {
|
||||
if (!ArchiveName.empty())
|
||||
outs() << ArchiveName << ":";
|
||||
outs() << CurrentFilename << ": ";
|
||||
}
|
||||
}
|
||||
if (PrintFileName)
|
||||
writeFileName();
|
||||
if ((JustSymbolName ||
|
||||
(UndefinedOnly && MachO && OutputFormat != darwin)) &&
|
||||
OutputFormat != posix) {
|
||||
|
|
Loading…
Reference in New Issue