Add support for the source_version cmdline option.

This is of the form A.B.C.D.E and to match ld64's behaviour, is
always output to files, even when the version is 0.

rdar://problem/24472630

llvm-svn: 259746
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
index 0eb2b11..4e303dd 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
@@ -467,6 +467,10 @@
     ++count;
   }
 
+  // Add LC_SOURCE_VERSION
+  size += sizeof(source_version_command);
+  ++count;
+
   // If main executable add LC_MAIN
   if (_file.fileType == llvm::MachO::MH_EXECUTE) {
     size += sizeof(entry_point_command);
@@ -915,6 +919,17 @@
     // LC_VERSION_MIN_TVOS
     writeVersionMinLoadCommand(_file, _swap, lc);
 
+    // Add LC_SOURCE_VERSION
+    {
+      source_version_command* sv = reinterpret_cast<source_version_command*>(lc);
+      sv->cmd       = LC_SOURCE_VERSION;
+      sv->cmdsize   = sizeof(source_version_command);
+      sv->version   = _file.sourceVersion;
+      if (_swap)
+        swapStruct(*sv);
+      lc += sizeof(source_version_command);
+    }
+
     // If main executable, add LC_MAIN.
     if (_file.fileType == llvm::MachO::MH_EXECUTE) {
       // Build LC_MAIN load command.