Darwin: Pass -iphoneos-version-min to ld when building for ARM.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81019 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/HostInfo.cpp b/lib/Driver/HostInfo.cpp
index 89a3f8f..305c7cc 100644
--- a/lib/Driver/HostInfo.cpp
+++ b/lib/Driver/HostInfo.cpp
@@ -155,11 +155,18 @@
   if (!TC) {
     llvm::Triple TCTriple(getTriple());
     TCTriple.setArchName(ArchName);
-                          
+
     if (strcmp(ArchName, "i386") == 0 || strcmp(ArchName, "x86_64") == 0)
       TC = new toolchains::Darwin(*this, TCTriple,
                                   DarwinVersion,
-                                  GCCVersion);
+                                  GCCVersion,
+                                  false);
+    else if (strncmp(ArchName, "arm", 3) == 0 ||
+             strncmp(ArchName, "thumb", 5) == 0)
+      TC = new toolchains::Darwin(*this, TCTriple,
+                                  DarwinVersion,
+                                  GCCVersion,
+                                  true);
     else
       TC = new toolchains::Darwin_GCC(*this, TCTriple);
   }
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 63b629f..d6067af 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -29,7 +29,8 @@
 
 Darwin::Darwin(const HostInfo &Host, const llvm::Triple& Triple,
                const unsigned (&_DarwinVersion)[3],
-               const unsigned (&_GCCVersion)[3])
+               const unsigned (&_GCCVersion)[3],
+               bool _IsIPhone)
   : ToolChain(Host, Triple) {
   DarwinVersion[0] = _DarwinVersion[0];
   DarwinVersion[1] = _DarwinVersion[1];
@@ -37,10 +38,14 @@
   GCCVersion[0] = _GCCVersion[0];
   GCCVersion[1] = _GCCVersion[1];
   GCCVersion[2] = _GCCVersion[2];
+  IsIPhone = _IsIPhone;
 
   llvm::raw_string_ostream(MacosxVersionMin)
     << "10." << DarwinVersion[0] - 4 << '.' << DarwinVersion[1];
 
+  // FIXME: Lift default up.
+  IPhoneOSVersionMin = "3.0";
+
   ToolChainDir = "i686-apple-darwin";
   ToolChainDir += llvm::utostr(DarwinVersion[0]);
   ToolChainDir += "/";
@@ -150,15 +155,21 @@
   } else if (!OSXVersion && !iPhoneVersion) {
     // Chose the default version based on the arch.
     //
-    // FIXME: This will need to be fixed when we merge in arm support.
+    // FIXME: Are there iPhone overrides for this?
 
-    // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
-    // from the host.
-    const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
-    if (!Version)
-      Version = MacosxVersionMin.c_str();
-    const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
-    DAL->append(DAL->MakeJoinedArg(0, O, Version));
+    if (!isIPhone()) {
+      // Look for MACOSX_DEPLOYMENT_TARGET, otherwise use the version
+      // from the host.
+      const char *Version = ::getenv("MACOSX_DEPLOYMENT_TARGET");
+      if (!Version)
+        Version = MacosxVersionMin.c_str();
+      const Option *O = Opts.getOption(options::OPT_mmacosx_version_min_EQ);
+      DAL->append(DAL->MakeJoinedArg(0, O, Version));
+    } else {
+      const char *Version = IPhoneOSVersionMin.c_str();
+      const Option *O = Opts.getOption(options::OPT_miphoneos_version_min_EQ);
+      DAL->append(DAL->MakeJoinedArg(0, O, Version));
+    }
   }
   
   for (ArgList::iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) {
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index 3d8632e..b0cc9cb 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -53,6 +53,9 @@
   /// GCC version to use.
   unsigned GCCVersion[3];
 
+  /// Whether this is this an iPhone toolchain.
+  bool IsIPhone;
+
   /// The directory suffix for this tool chain.
   std::string ToolChainDir;
 
@@ -60,12 +63,16 @@
   /// initialized.
   mutable std::string MacosxVersionMin;
 
+  /// The default iphoneos-version-min of this tool chain.
+  std::string IPhoneOSVersionMin;
+
   const char *getMacosxVersionMin() const;
 
 public:
   Darwin(const HostInfo &Host, const llvm::Triple& Triple, 
-             const unsigned (&DarwinVersion)[3],
-             const unsigned (&GCCVersion)[3]);
+         const unsigned (&DarwinVersion)[3],
+         const unsigned (&GCCVersion)[3],
+         bool IsIPhone);
   ~Darwin();
 
   void getDarwinVersion(unsigned (&Res)[3]) const {
@@ -84,10 +91,16 @@
     return MacosxVersionMin.c_str();
   }
 
+  const char *getIPhoneOSVersionStr() const {
+    return IPhoneOSVersionMin.c_str();
+  }
+
   const std::string &getToolChainDir() const { 
     return ToolChainDir;
   }
 
+  bool isIPhone() const { return IsIPhone; }
+
   virtual DerivedArgList *TranslateArgs(InputArgList &Args) const;
 
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index b72d562..27b34c7 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1457,22 +1457,22 @@
   Args.AddAllArgs(CmdArgs, options::OPT_image__base);
   Args.AddAllArgs(CmdArgs, options::OPT_init);
 
-  if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ)) {
-    if (!Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
-      // FIXME: I don't understand what is going on here. This is
-      // supposed to come from darwin_ld_minversion, but gcc doesn't
-      // seem to be following that; it must be getting overridden
-      // somewhere.
+  if (!Args.hasArg(options::OPT_mmacosx_version_min_EQ) &&
+      !Args.hasArg(options::OPT_miphoneos_version_min_EQ)) {
+    // Add default version min.
+    if (!getDarwinToolChain().isIPhone()) {
       CmdArgs.push_back("-macosx_version_min");
       CmdArgs.push_back(getDarwinToolChain().getMacosxVersionStr());
+    } else {
+      CmdArgs.push_back("-iphoneos_version_min");
+      CmdArgs.push_back(getDarwinToolChain().getIPhoneOSVersionStr());
     }
-  } else {
-    // Adding all arguments doesn't make sense here but this is what
-    // gcc does.
-    Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ,
-                              "-macosx_version_min");
   }
 
+  // Adding all arguments doesn't make sense here but this is what
+  // gcc does.
+  Args.AddAllArgsTranslated(CmdArgs, options::OPT_mmacosx_version_min_EQ,
+                              "-macosx_version_min");
   Args.AddAllArgsTranslated(CmdArgs, options::OPT_miphoneos_version_min_EQ,
                             "-iphoneos_version_min");
   Args.AddLastArg(CmdArgs, options::OPT_nomultidefs);