[mach-o] set ordinal in n_desc for undefined symbols

Mach-o uses "two-level namespace" where each undefined symbols is associated
with a specific dylib. This means at runtime the loader (dyld) does need to
search all loaded dylibs for that symbol but rather just the one specified.

Now that llvm-nm -m prints out that info, properly set that info, and test
it in the hello world test cases.

llvm-svn: 215598
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
index 9f8fa42..efb9d9c 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
@@ -761,11 +761,16 @@
   const uint32_t start = file.globalSymbols.size() + file.localSymbols.size();
   for (AtomAndIndex &ai : undefs) {
     Symbol sym;
+    uint16_t desc = 0;
+    if (!rMode) {
+      uint8_t ordinal = dylibOrdinal(dyn_cast<SharedLibraryAtom>(ai.atom));
+      llvm::MachO::SET_LIBRARY_ORDINAL(desc, ordinal);
+    }
     sym.name  = ai.atom->name();
     sym.type  = N_UNDF;
     sym.scope = N_EXT;
     sym.sect  = 0;
-    sym.desc  = 0;
+    sym.desc  = desc;
     sym.value = 0;
     _atomToSymbolIndex[ai.atom] = file.undefinedSymbols.size() + start;
     file.undefinedSymbols.push_back(sym);
diff --git a/lld/test/mach-o/hello-world-armv6.yaml b/lld/test/mach-o/hello-world-armv6.yaml
index 43beabf..f1d3803 100644
--- a/lld/test/mach-o/hello-world-armv6.yaml
+++ b/lld/test/mach-o/hello-world-armv6.yaml
@@ -1,5 +1,5 @@
 # RUN: lld -flavor darwin -arch armv6 -ios_version_min 7.0 %s -o %t  && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m %t | FileCheck %s
 #
 # Test that armv6 (arm) hello-world can be linked into a mach-o executable
 #
@@ -85,6 +85,6 @@
 
 ...
 
-# CHECK:	{{[0-9a-f]+}} T _main
-# CHECK:	U _printf
-# CHECK:	U dyld_stub_binder
+# CHECK:	{{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK:	(undefined) external _printf (from libSystem)
+# CHECK:	(undefined) external dyld_stub_binder (from libSystem)
diff --git a/lld/test/mach-o/hello-world-armv7.yaml b/lld/test/mach-o/hello-world-armv7.yaml
index ac985b4..b6e908c 100644
--- a/lld/test/mach-o/hello-world-armv7.yaml
+++ b/lld/test/mach-o/hello-world-armv7.yaml
@@ -1,5 +1,5 @@
 # RUN: lld -flavor darwin -arch armv7 -ios_version_min 7.0 %s -o %t  && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m -n %t | FileCheck %s
 #
 # Test that armv7 (thumb) hello-world can be linked into a mach-o executable
 #
@@ -98,6 +98,6 @@
 
 ...
 
-# CHECK:	{{[0-9a-f]+}} T _main
-# CHECK:	U _printf
-# CHECK:	U dyld_stub_binder
+# CHECK:	{{[0-9a-f]+}} (__TEXT,__text) external [Thumb] _main
+# CHECK:	(undefined) external _printf (from libSystem)
+# CHECK:	(undefined) external dyld_stub_binder (from libSystem)
diff --git a/lld/test/mach-o/hello-world-x86.yaml b/lld/test/mach-o/hello-world-x86.yaml
index f19e3ea..ce25b9e 100644
--- a/lld/test/mach-o/hello-world-x86.yaml
+++ b/lld/test/mach-o/hello-world-x86.yaml
@@ -1,5 +1,5 @@
 # RUN: lld -flavor darwin -arch i386 -macosx_version_min 10.8 %s -o %t  && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m %t | FileCheck %s
 #
 # Test that i386 hello-world can be linked into a mach-o executable
 #
@@ -83,6 +83,6 @@
 
 ...
 
-# CHECK:	{{[0-9a-f]+}} T _main
-# CHECK:	U _printf
-# CHECK:	U dyld_stub_binder
+# CHECK:	{{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK:	(undefined) external _printf (from libSystem)
+# CHECK:	(undefined) external dyld_stub_binder (from libSystem)
diff --git a/lld/test/mach-o/hello-world-x86_64.yaml b/lld/test/mach-o/hello-world-x86_64.yaml
index 4ab4be9..689a5d2 100644
--- a/lld/test/mach-o/hello-world-x86_64.yaml
+++ b/lld/test/mach-o/hello-world-x86_64.yaml
@@ -1,5 +1,5 @@
 # RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.8 %s -o %t  && \
-# RUN: llvm-nm %t | FileCheck %s
+# RUN: llvm-nm -m -n %t | FileCheck %s
 #
 # Test that x86_64 hello-world can be linked into a mach-o executable
 #
@@ -138,7 +138,7 @@
 
 ...
 
-# CHECK:	U ___stdoutp
-# CHECK:	U _fprintf
-# CHECK:	{{[0-9a-f]+}} T _main
-# CHECK:	U dyld_stub_binder
+# CHECK:	{{[0-9a-f]+}} (__TEXT,__text) external _main
+# CHECK:	(undefined) external ___stdoutp (from libSystem)
+# CHECK:	(undefined) external _fprintf (from libSystem)
+# CHECK:	(undefined) external dyld_stub_binder (from libSystem)