[lld] bd7defe - llvm-nm: Implement --special-syms.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 13:07:55 PDT 2020
Author: Peter Collingbourne
Date: 2020-06-22T13:05:47-07:00
New Revision: bd7defeb94090bb2af7104b70bc33bc64d754d1f
URL: https://github.com/llvm/llvm-project/commit/bd7defeb94090bb2af7104b70bc33bc64d754d1f
DIFF: https://github.com/llvm/llvm-project/commit/bd7defeb94090bb2af7104b70bc33bc64d754d1f.diff
LOG: llvm-nm: Implement --special-syms.
Differential Revision: https://reviews.llvm.org/D82251
Added:
Modified:
lld/test/ELF/aarch64-thunk-script.s
llvm/docs/CommandGuide/llvm-nm.rst
llvm/docs/ReleaseNotes.rst
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
Removed:
################################################################################
diff --git a/lld/test/ELF/aarch64-thunk-script.s b/lld/test/ELF/aarch64-thunk-script.s
index b1a7aab18e1e..0c376b1553a2 100644
--- a/lld/test/ELF/aarch64-thunk-script.s
+++ b/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.
diff --git a/llvm/docs/CommandGuide/llvm-nm.rst b/llvm/docs/CommandGuide/llvm-nm.rst
index c47be8034efc..607c871ff7a1 100644
--- a/llvm/docs/CommandGuide/llvm-nm.rst
+++ b/llvm/docs/CommandGuide/llvm-nm.rst
@@ -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
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 7d71d0c58a4c..8d8da954ece3 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -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
===============
diff --git a/llvm/test/MC/AArch64/mapping-within-section.s b/llvm/test/MC/AArch64/mapping-within-section.s
index c7c3bbe08bed..07a2d3cc0fed 100644
--- a/llvm/test/MC/AArch64/mapping-within-section.s
+++ b/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
diff --git a/llvm/test/tools/llvm-nm/AArch64/special-syms.test b/llvm/test/tools/llvm-nm/AArch64/special-syms.test
index 8322cc4df86f..75d1dfc3b6c9 100644
--- a/llvm/test/tools/llvm-nm/AArch64/special-syms.test
+++ b/llvm/test/tools/llvm-nm/AArch64/special-syms.test
@@ -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
diff --git a/llvm/test/tools/llvm-nm/debug-syms.test b/llvm/test/tools/llvm-nm/debug-syms.test
index e58176588d30..0f970916499f 100644
--- a/llvm/test/tools/llvm-nm/debug-syms.test
+++ b/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
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 4385e2aaa287..ecd1e21e15bf 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -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);
More information about the llvm-commits
mailing list