[PATCH] D82251: llvm-nm: Implement --special-syms.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 19 19:32:13 PDT 2020
pcc created this revision.
pcc added reviewers: jhenderson, evgeny777, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82251
Files:
lld/test/ELF/aarch64-thunk-script.s
llvm/test/MC/AArch64/mapping-within-section.s
llvm/test/tools/llvm-nm/AArch64/special-syms.test
llvm/test/tools/llvm-nm/debug-syms.test
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -182,8 +182,10 @@
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 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[0] == '$';
+}
+
static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
StringRef ArchiveName,
StringRef ArchitectureName) {
@@ -822,7 +834,8 @@
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);
Index: llvm/test/tools/llvm-nm/debug-syms.test
===================================================================
--- llvm/test/tools/llvm-nm/debug-syms.test
+++ llvm/test/tools/llvm-nm/debug-syms.test
@@ -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
Index: llvm/test/tools/llvm-nm/AArch64/special-syms.test
===================================================================
--- llvm/test/tools/llvm-nm/AArch64/special-syms.test
+++ llvm/test/tools/llvm-nm/AArch64/special-syms.test
@@ -1,10 +1,7 @@
# 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
+# Test --special-syms flag.
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm %t | count 0
# RUN: llvm-nm %t --special-syms | FileCheck %s
!ELF
Index: llvm/test/MC/AArch64/mapping-within-section.s
===================================================================
--- llvm/test/MC/AArch64/mapping-within-section.s
+++ llvm/test/MC/AArch64/mapping-within-section.s
@@ -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
Index: lld/test/ELF/aarch64-thunk-script.s
===================================================================
--- lld/test/ELF/aarch64-thunk-script.s
+++ lld/test/ELF/aarch64-thunk-script.s
@@ -6,7 +6,7 @@
// RUN: } " > %t.script
// RUN: ld.lld --script %t.script %t.o -o %t
// RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s
-// RUN: llvm-nm --no-sort %t | FileCheck --check-prefix=NM %s
+// RUN: llvm-nm --no-sort --special-syms %t | FileCheck --check-prefix=NM %s
// Check that we have the out of branch range calculation right. The immediate
// field is signed so we have a slightly higher negative displacement.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82251.272226.patch
Type: text/x-patch
Size: 4362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200620/65c7bba5/attachment.bin>
More information about the llvm-commits
mailing list