[MachO] Add basic support for local symbols.

llvm-svn: 199155
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
index b53d0de..b91e3a8 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -50,9 +50,30 @@
     if (sValue < closestAddr)
       closestAddr = s.value;
   }
+  for (const Symbol &s : normalizedFile.localSymbols) {
+    if (s.sect != symbolSectionIndex)
+      continue;
+    uint64_t sValue = s.value;
+    if (sValue <= symbolAddr)
+      continue;
+    if (sValue < closestAddr)
+      closestAddr = s.value;
+  }
   return closestAddr;
 }
 
+static Atom::Scope atomScope(uint8_t scope) {
+  switch (scope) {
+  case N_EXT:
+    return Atom::scopeGlobal;
+  case N_PEXT | N_EXT:
+    return Atom::scopeLinkageUnit;
+  case 0:
+    return Atom::scopeTranslationUnit;
+  }
+  llvm_unreachable("unknown scope value!");
+}
+
 static void processSymbol(const NormalizedFile &normalizedFile, MachOFile &file,
                           const Symbol &sym, bool copyRefs) {
   // Mach-O symbol table does have size in it, so need to scan ahead
@@ -61,7 +82,7 @@
   uint64_t offset = sym.value - section.address;
   uint64_t size = nextSymbolAddress(normalizedFile, sym) - sym.value;
   ArrayRef<uint8_t> atomContent = section.content.slice(offset, size);
-  file.addDefinedAtom(sym.name, atomContent, copyRefs);
+  file.addDefinedAtom(sym.name, atomContent, atomScope(sym.scope), copyRefs);
 }
 
 static ErrorOr<std::unique_ptr<lld::File>>
@@ -73,8 +94,10 @@
     processSymbol(normalizedFile, *file, sym, copyRefs);
   }
 
-  assert(normalizedFile.localSymbols.empty() &&
-         "local symbols not supported yet!");
+  for (const Symbol &sym : normalizedFile.localSymbols) {
+    processSymbol(normalizedFile, *file, sym, copyRefs);
+  }
+
   assert(normalizedFile.undefinedSymbols.empty() &&
          "undefined symbols not supported yet!");