[lld] r259739 - Default to an unknown OS instead of MacOSX.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 17:58:00 PST 2016


Author: pete
Date: Wed Feb  3 19:57:59 2016
New Revision: 259739

URL: http://llvm.org/viewvc/llvm-project?rev=259739&view=rev
Log:
Default to an unknown OS instead of MacOSX.

Defaulting to unknown matches ld64, but it also makes sure that all
of our code can handle not knowing the platform.  For example, a later
commit will add support for version min load commands with an unknown
platform, which is a feature supported by ld64.

No test case here.  The next commit will have one with the version min
code that needed this patch.

Modified:
    lld/trunk/lib/Driver/DarwinLdDriver.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=259739&r1=259738&r2=259739&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed Feb  3 19:57:59 2016
@@ -352,7 +352,7 @@ bool DarwinLdDriver::parse(llvm::ArrayRe
   }
 
   // Handle -macosx_version_min or -ios_version_min
-  MachOLinkingContext::OS os = MachOLinkingContext::OS::macOSX;
+  MachOLinkingContext::OS os = MachOLinkingContext::OS::unknown;
   uint32_t minOSVersion = 0;
   if (llvm::opt::Arg *minOS =
           parsedArgs.getLastArg(OPT_macosx_version_min, OPT_ios_version_min,

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=259739&r1=259738&r2=259739&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed Feb  3 19:57:59 2016
@@ -163,22 +163,27 @@ void MachOLinkingContext::configure(Head
   _osMinVersion = minOSVersion;
 
   // If min OS not specified on command line, use reasonable defaults.
-  if (minOSVersion == 0) {
-    switch (_arch) {
-    case arch_x86_64:
-    case arch_x86:
-      parsePackedVersion("10.8", _osMinVersion);
-      _os = MachOLinkingContext::OS::macOSX;
-      break;
-    case arch_armv6:
-    case arch_armv7:
-    case arch_armv7s:
-    case arch_arm64:
-      parsePackedVersion("7.0", _osMinVersion);
-      _os = MachOLinkingContext::OS::iOS;
-      break;
-    default:
-      break;
+  // Note that we only do sensible defaults when emitting something other than
+  // object and preload.
+  if (_outputMachOType != llvm::MachO::MH_OBJECT &&
+      _outputMachOType != llvm::MachO::MH_PRELOAD) {
+    if (minOSVersion == 0) {
+      switch (_arch) {
+      case arch_x86_64:
+      case arch_x86:
+        parsePackedVersion("10.8", _osMinVersion);
+        _os = MachOLinkingContext::OS::macOSX;
+        break;
+      case arch_armv6:
+      case arch_armv7:
+      case arch_armv7s:
+      case arch_arm64:
+        parsePackedVersion("7.0", _osMinVersion);
+        _os = MachOLinkingContext::OS::iOS;
+        break;
+      default:
+        break;
+      }
     }
   }
 
@@ -376,9 +381,10 @@ bool MachOLinkingContext::minOS(StringRe
       return false;
     return _osMinVersion >= parsedVersion;
   case OS::unknown:
-    break;
+    // If we don't know the target, then assume that we don't meet the min OS.
+    // This matches the ld64 behaviour
+    return false;
   }
-  llvm_unreachable("target not configured for iOS or MacOSX");
 }
 
 bool MachOLinkingContext::addEntryPointLoadCommand() const {




More information about the llvm-commits mailing list