Implemented the code to make llvm-nm’s -g option work.
authorKevin Enderby <enderby@apple.com>
Fri, 30 Oct 2015 19:55:32 +0000 (19:55 +0000)
committerKevin Enderby <enderby@apple.com>
Fri, 30 Oct 2015 19:55:32 +0000 (19:55 +0000)
While llvm-nm parses the -g option and has help that describes it as:

  -extern-only            - Show only external symbols

There is no code in the program to use the boolean valve it sets from the
command line.

rdar://23261095

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251718 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-nm/X86/Inputs/hello.obj.macho-x86_64 [new file with mode: 0644]
test/tools/llvm-nm/X86/externalonly.test [new file with mode: 0644]
test/tools/llvm-nm/lit.local.cfg [new file with mode: 0644]
tools/llvm-nm/llvm-nm.cpp

diff --git a/test/tools/llvm-nm/X86/Inputs/hello.obj.macho-x86_64 b/test/tools/llvm-nm/X86/Inputs/hello.obj.macho-x86_64
new file mode 100644 (file)
index 0000000..2b59a1c
Binary files /dev/null and b/test/tools/llvm-nm/X86/Inputs/hello.obj.macho-x86_64 differ
diff --git a/test/tools/llvm-nm/X86/externalonly.test b/test/tools/llvm-nm/X86/externalonly.test
new file mode 100644 (file)
index 0000000..c374129
--- /dev/null
@@ -0,0 +1,4 @@
+# RUN: llvm-nm -g %p/Inputs/hello.obj.macho-x86_64 | FileCheck %s
+
+# CHECK-NOT: EH_frame0
+# CHECK: _main
diff --git a/test/tools/llvm-nm/lit.local.cfg b/test/tools/llvm-nm/lit.local.cfg
new file mode 100644 (file)
index 0000000..c8625f4
--- /dev/null
@@ -0,0 +1,2 @@
+if not 'X86' in config.root.targets:
+    config.unsupported = True
index a0b5e9b4eaa477d90b26a6351eaf3537eaf23d1e..9d0cc57584378f86e5fa553e0e91bceb3c7f93ea 100644 (file)
@@ -529,6 +529,9 @@ static void sortAndPrintSymbolList(SymbolicFile &Obj, bool printName,
       continue;
     if (Undefined && DefinedOnly)
       continue;
+    bool Global = SymFlags & SymbolRef::SF_Global;
+    if (!Global && ExternalOnly)
+      continue;
     if (SizeSort && !PrintAddress)
       continue;
     if (PrintFileName) {