1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

llvm-nm: Implement --special-syms.

Differential Revision: https://reviews.llvm.org/D82251
This commit is contained in:
Peter Collingbourne 2020-06-19 19:06:14 -07:00
parent 252036e8bf
commit 7d1cbe5a8a
6 changed files with 26 additions and 12 deletions

View File

@ -219,7 +219,7 @@ OPTIONS
.. option:: --special-syms
Ignored. For GNU compatibility only.
Do not filter special symbols from the output.
.. option:: --undefined-only, -u

View File

@ -187,6 +187,10 @@ Changes to the LLVM tools
* Added an option (--show-section-sizes) to llvm-dwarfdump to show the sizes
of all debug sections within a file.
* llvm-nm now implements the flag ``--special-syms`` and will filter out special
symbols, i.e. mapping symbols on ARM and AArch64, by default. This matches
the GNU nm behavior.
Changes to LLDB
===============

View File

@ -1,4 +1,4 @@
// RUN: llvm-mc -triple=aarch64-none-linux-gnu -filetype=obj %s | llvm-nm - | FileCheck %s
// RUN: llvm-mc -triple=aarch64-none-linux-gnu -filetype=obj %s | llvm-nm --special-syms - | FileCheck %s
.text
// $x at 0x0000

View File

@ -1,10 +1,7 @@
## Test --special-syms flag.
# RUN: yaml2obj %s -o %t
# Test --special-syms flag. Currently this flag is a no-op, so outputs with and without
# this flag should be identical. GNU nm doesn't show ARM and AArch64 special symbols
# without --special-syms, so this test is to be changed when/if we decide to implement
# GNU nm-like behavior in llvm-nm
# RUN: llvm-nm %t | FileCheck %s
# RUN: llvm-nm %t | count 0
# RUN: llvm-nm %t --special-syms | FileCheck %s
!ELF

View File

@ -1,6 +1,6 @@
# RUN: yaml2obj %s -o %t.o
# RUN: llvm-nm --debug-syms %t.o | FileCheck %s --implicit-check-not {{.}} --check-prefix SYMBOL
# RUN: llvm-nm -a %t.o | FileCheck %s --implicit-check-not {{.}} --check-prefix SYMBOL
# RUN: llvm-nm --special-syms --debug-syms %t.o | FileCheck %s --implicit-check-not {{.}} --check-prefix SYMBOL
# RUN: llvm-nm --special-syms -a %t.o | FileCheck %s --implicit-check-not {{.}} --check-prefix SYMBOL
# SYMBOL: 0000000000000000 n $a
# SYMBOL-NEXT: 0000000000000000 n $d

View File

@ -182,8 +182,10 @@ cl::opt<bool> JustSymbolName("just-symbol-name",
cl::alias JustSymbolNames("j", cl::desc("Alias for --just-symbol-name"),
cl::aliasopt(JustSymbolName), cl::Grouping);
cl::opt<bool> SpecialSyms("special-syms",
cl::desc("No-op. Used for GNU compatibility only"));
cl::opt<bool>
SpecialSyms("special-syms",
cl::desc("Do not filter special symbols from the output"),
cl::cat(NMCat));
cl::list<std::string> SegSect("s", cl::multi_val(2), cl::ZeroOrMore,
cl::value_desc("segment section"), cl::Hidden,
@ -733,6 +735,16 @@ static void writeFileName(raw_ostream &S, StringRef ArchiveName,
}
}
static bool isSpecialSym(SymbolicFile &Obj, StringRef Name) {
auto *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj);
if (!ELFObj)
return false;
uint16_t EMachine = ELFObj->getEMachine();
if (EMachine != ELF::EM_ARM && EMachine != ELF::EM_AARCH64)
return false;
return !Name.empty() && Name[0] == '$';
}
static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
StringRef ArchiveName,
StringRef ArchitectureName) {
@ -822,7 +834,8 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
bool Global = SymFlags & SymbolRef::SF_Global;
bool Weak = SymFlags & SymbolRef::SF_Weak;
if ((!Undefined && UndefinedOnly) || (Undefined && DefinedOnly) ||
(!Global && ExternalOnly) || (Weak && NoWeakSymbols))
(!Global && ExternalOnly) || (Weak && NoWeakSymbols) ||
(!SpecialSyms && isSpecialSym(Obj, Name)))
continue;
if (PrintFileName)
writeFileName(outs(), ArchiveName, ArchitectureName);