Driver/Darwin: Simplify target version checks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index f07ce34..9e64c86 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -241,8 +241,7 @@
void DarwinGCC::AddLinkRuntimeLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
- unsigned MacosxVersionMin[3];
- getMacosxVersionMin(Args, MacosxVersionMin);
+ // Note that this routine is only used for targetting OS X.
// Derived from libgcc and lib specs but refactored.
if (Args.hasArg(options::OPT_static)) {
@@ -262,20 +261,20 @@
options::OPT_fno_exceptions) ||
Args.hasArg(options::OPT_fgnu_runtime)) {
// FIXME: This is probably broken on 10.3?
- if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
+ if (isMacosxVersionLT(10, 5))
CmdArgs.push_back("-lgcc_s.10.4");
- else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
+ else if (isMacosxVersionLT(10, 6))
CmdArgs.push_back("-lgcc_s.10.5");
} else {
- if (isMacosxVersionLT(MacosxVersionMin, 10, 3, 9))
+ if (isMacosxVersionLT(10, 3, 9))
; // Do nothing.
- else if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
+ else if (isMacosxVersionLT(10, 5))
CmdArgs.push_back("-lgcc_s.10.4");
- else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
+ else if (isMacosxVersionLT(10, 6))
CmdArgs.push_back("-lgcc_s.10.5");
}
- if (isTargetIPhoneOS() || isMacosxVersionLT(MacosxVersionMin, 10, 6)) {
+ if (isTargetIPhoneOS() || isMacosxVersionLT(10, 6)) {
CmdArgs.push_back("-lgcc");
CmdArgs.push_back("-lSystem");
} else {
@@ -328,20 +327,17 @@
if (getDarwinArchName(Args) == "armv6")
DarwinStaticLib = "libclang_rt.armv6.a";
} else {
- unsigned MacosxVersionMin[3];
- getMacosxVersionMin(Args, MacosxVersionMin);
-
// The dynamic runtime library was merged with libSystem for 10.6 and
// beyond; only 10.4 and 10.5 need an additional runtime library.
- if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
+ if (isMacosxVersionLT(10, 5))
CmdArgs.push_back("-lgcc_s.10.4");
- else if (isMacosxVersionLT(MacosxVersionMin, 10, 6))
+ else if (isMacosxVersionLT(10, 6))
CmdArgs.push_back("-lgcc_s.10.5");
// For OS X, we only need a static runtime library when targetting 10.4, to
// provide versions of the static functions which were omitted from
// 10.4.dylib.
- if (isMacosxVersionLT(MacosxVersionMin, 10, 5))
+ if (isMacosxVersionLT(10, 5))
DarwinStaticLib = "libclang_rt.10.4.a";
}
@@ -362,21 +358,6 @@
}
}
-void Darwin::getMacosxVersionMin(const ArgList &Args,
- unsigned (&Res)[3]) const {
- if (Arg *A = Args.getLastArg(options::OPT_mmacosx_version_min_EQ)) {
- bool HadExtra;
- if (!Driver::GetReleaseVersion(A->getValue(Args), Res[0], Res[1], Res[2],
- HadExtra) ||
- HadExtra) {
- const Driver &D = getDriver();
- D.Diag(clang::diag::err_drv_invalid_version_number)
- << A->getAsString(Args);
- }
- } else
- return getMacosxVersion(Res);
-}
-
DerivedArgList *Darwin::TranslateArgs(InputArgList &Args,
const char *BoundArch) const {
DerivedArgList *DAL = new DerivedArgList(Args, false);
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index 71de8b7..e17546c 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -112,22 +112,12 @@
Res[2] = DarwinVersion[2];
}
- void getMacosxVersion(unsigned (&Res)[3]) const {
- Res[0] = 10;
- Res[1] = DarwinVersion[0] - 4;
- Res[2] = DarwinVersion[1];
- }
-
/// getDarwinArchName - Get the "Darwin" arch name for a particular compiler
/// invocation. For example, Darwin treats different ARM variations as
/// distinct architectures.
llvm::StringRef getDarwinArchName(const ArgList &Args) const;
- /// getMacosxVersionMin - Get the effective -mmacosx-version-min, which is
- /// either the -mmacosx-version-min, or the current version if unspecified.
- void getMacosxVersionMin(const ArgList &Args, unsigned (&Res)[3]) const;
-
- static bool isMacosxVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
+ static bool isVersionLT(unsigned (&A)[3], unsigned (&B)[3]) {
for (unsigned i=0; i < 3; ++i) {
if (A[i] > B[i]) return false;
if (A[i] < B[i]) return true;
@@ -135,16 +125,16 @@
return false;
}
- static bool isMacosxVersionLT(unsigned (&A)[3],
- unsigned V0, unsigned V1=0, unsigned V2=0) {
- unsigned B[3] = { V0, V1, V2 };
- return isMacosxVersionLT(A, B);
- }
-
bool isIPhoneOSVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
assert(isTargetIPhoneOS() && "Unexpected call for OS X target!");
unsigned B[3] = { V0, V1, V2 };
- return isMacosxVersionLT(TargetVersion, B);
+ return isVersionLT(TargetVersion, B);
+ }
+
+ bool isMacosxVersionLT(unsigned V0, unsigned V1=0, unsigned V2=0) const {
+ assert(!isTargetIPhoneOS() && "Unexpected call for iPhoneOS target!");
+ unsigned B[3] = { V0, V1, V2 };
+ return isVersionLT(TargetVersion, B);
}
/// AddLinkSearchPathArgs - Add the linker search paths to \arg CmdArgs.
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index e75e12c..92507d2 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2029,10 +2029,6 @@
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
-
- unsigned MacosxVersionMin[3];
- getDarwinToolChain().getMacosxVersionMin(Args, MacosxVersionMin);
-
if (!Args.hasArg(options::OPT_A) &&
!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nostartfiles)) {
@@ -2043,9 +2039,9 @@
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
CmdArgs.push_back("-ldylib1.o");
} else {
- if (getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin, 10, 5))
+ if (getDarwinToolChain().isMacosxVersionLT(10, 5))
CmdArgs.push_back("-ldylib1.o");
- else if (getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin, 10,6))
+ else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
CmdArgs.push_back("-ldylib1.10.5.o");
}
} else {
@@ -2056,7 +2052,7 @@
if (getDarwinToolChain().isIPhoneOSVersionLT(3, 1))
CmdArgs.push_back("-lbundle1.o");
} else {
- if (getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin, 10, 6))
+ if (getDarwinToolChain().isMacosxVersionLT(10, 6))
CmdArgs.push_back("-lbundle1.o");
}
}
@@ -2083,24 +2079,24 @@
CmdArgs.push_back("-lcrt1.o");
else
CmdArgs.push_back("-lcrt1.3.1.o");
- } else if (getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin,
- 10, 5))
- CmdArgs.push_back("-lcrt1.o");
- else if (getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin,
- 10, 6))
- CmdArgs.push_back("-lcrt1.10.5.o");
- else
- CmdArgs.push_back("-lcrt1.10.6.o");
+ } else {
+ if (getDarwinToolChain().isMacosxVersionLT(10, 5))
+ CmdArgs.push_back("-lcrt1.o");
+ else if (getDarwinToolChain().isMacosxVersionLT(10, 6))
+ CmdArgs.push_back("-lcrt1.10.5.o");
+ else
+ CmdArgs.push_back("-lcrt1.10.6.o");
- // darwin_crt2 spec is empty.
+ // darwin_crt2 spec is empty.
+ }
}
}
}
}
- if (Args.hasArg(options::OPT_shared_libgcc) &&
- !Args.hasArg(options::OPT_miphoneos_version_min_EQ) &&
- getDarwinToolChain().isMacosxVersionLT(MacosxVersionMin, 10, 5)) {
+ if (!getDarwinToolChain().isTargetIPhoneOS() &&
+ Args.hasArg(options::OPT_shared_libgcc) &&
+ getDarwinToolChain().isMacosxVersionLT(10, 5)) {
const char *Str =
Args.MakeArgString(getToolChain().GetFilePath(C, "crt3.o"));
CmdArgs.push_back(Str);