From 8a8d8afa3df40e9f122d2b826f1a825a66f6908d Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 1 Apr 2009 03:17:40 +0000 Subject: [PATCH] Tweak/cleanup darwin::Link a bit, add several FIXMES, and improve test case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68182 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 83 +++++++++++++++++++++-------------------- test/Driver/darwin-ld.c | 14 +++++++ 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index e0dfdd1b86..4392f4f670 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1050,11 +1050,6 @@ static bool isMacosxVersionLT(unsigned (&A)[3], return isMacosxVersionLT(A, B); } -static bool isMacosxVersionGTE(unsigned(&A)[3], - unsigned V0, unsigned V1=0, unsigned V2=0) { - return !isMacosxVersionLT(A, V0, V1, V2); -} - const toolchains::Darwin_X86 &darwin::Link::getDarwinToolChain() const { return reinterpret_cast(getToolChain()); } @@ -1280,15 +1275,17 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, // Derived from startfile spec. if (Args.hasArg(options::OPT_dynamiclib)) { // Derived from darwin_dylib1 spec. - if (Args.hasArg(options::OPT_miphoneos_version_min_EQ) || - isMacosxVersionLT(MacosxVersion, 10, 5)) + if (isMacosxVersionLT(MacosxVersion, 10, 5)) CmdArgs.push_back("-ldylib1.o"); - else + else if (isMacosxVersionLT(MacosxVersion, 10, 6)) CmdArgs.push_back("-ldylib1.10.5.o"); } else { if (Args.hasArg(options::OPT_bundle)) { - if (!Args.hasArg(options::OPT_static)) - CmdArgs.push_back("-lbundle1.o"); + if (!Args.hasArg(options::OPT_static)) { + // Derived from darwin_bundle1 spec. + if (isMacosxVersionLT(MacosxVersion, 10, 6)) + CmdArgs.push_back("-lbundle1.o"); + } } else { if (Args.hasArg(options::OPT_pg)) { if (Args.hasArg(options::OPT_static) || @@ -1307,14 +1304,14 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lcrt0.o"); } else { // Derived from darwin_crt1 spec. - if (Args.hasArg(options::OPT_miphoneos_version_min_EQ) || - isMacosxVersionLT(MacosxVersion, 10, 5)) { + if (isMacosxVersionLT(MacosxVersion, 10, 5)) CmdArgs.push_back("-lcrt1.o"); - } else { + else if (isMacosxVersionLT(MacosxVersion, 10, 6)) CmdArgs.push_back("-lcrt1.10.5.o"); - - // darwin_crt2 spec is empty. - } + else + CmdArgs.push_back("-lcrt1.10.6.o"); + + // darwin_crt2 spec is empty. } } } @@ -1383,36 +1380,40 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA, !Args.hasArg(options::OPT_nodefaultlibs)) { // link_ssp spec is empty. - // Derived from libgcc spec. + // Derived from libgcc and lib specs but refactored. if (Args.hasArg(options::OPT_static)) { CmdArgs.push_back("-lgcc_static"); - } else if (Args.hasArg(options::OPT_static_libgcc)) { - CmdArgs.push_back("-lgcc_eh"); - CmdArgs.push_back("-lgcc"); - } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { - // Derived from darwin_iphoneos_libgcc spec. - CmdArgs.push_back("-lgcc_s.10.5"); - CmdArgs.push_back("-lgcc"); - } else if (Args.hasArg(options::OPT_shared_libgcc) || - Args.hasArg(options::OPT_fexceptions) || - Args.hasArg(options::OPT_fgnu_runtime)) { - if (isMacosxVersionLT(MacosxVersion, 10, 5)) - CmdArgs.push_back("-lgcc_s.10.4"); - else - CmdArgs.push_back("-lgcc_s.10.5"); - CmdArgs.push_back("-lgcc"); } else { - if (isMacosxVersionLT(MacosxVersion, 10, 5) && - isMacosxVersionGTE(MacosxVersion, 10, 3, 9)) - CmdArgs.push_back("-lgcc_s.10.4"); - if (isMacosxVersionGTE(MacosxVersion, 10, 5)) + if (Args.hasArg(options::OPT_static_libgcc)) { + CmdArgs.push_back("-lgcc_eh"); + } else if (Args.hasArg(options::OPT_miphoneos_version_min_EQ)) { + // Derived from darwin_iphoneos_libgcc spec. CmdArgs.push_back("-lgcc_s.10.5"); - CmdArgs.push_back("-lgcc"); - } + } else if (Args.hasArg(options::OPT_shared_libgcc) || + Args.hasArg(options::OPT_fexceptions) || + Args.hasArg(options::OPT_fgnu_runtime)) { + // FIXME: This is probably broken on 10.3? + if (isMacosxVersionLT(MacosxVersion, 10, 5)) + CmdArgs.push_back("-lgcc_s.10.4"); + else if (isMacosxVersionLT(MacosxVersion, 10, 6)) + CmdArgs.push_back("-lgcc_s.10.5"); + } else { + if (isMacosxVersionLT(MacosxVersion, 10, 3, 9)) + ; // Do nothing. + else if (isMacosxVersionLT(MacosxVersion, 10, 5)) + CmdArgs.push_back("-lgcc_s.10.4"); + else if (isMacosxVersionLT(MacosxVersion, 10, 6)) + CmdArgs.push_back("-lgcc_s.10.5"); + } - // Derived from lib spec. - if (!Args.hasArg(options::OPT_static)) - CmdArgs.push_back("-lSystem"); + if (isMacosxVersionLT(MacosxVersion, 10, 6)) { + CmdArgs.push_back("-lgcc"); + CmdArgs.push_back("-lSystem"); + } else { + CmdArgs.push_back("-lSystem"); + CmdArgs.push_back("-lgcc"); + } + } } if (!Args.hasArg(options::OPT_A) && diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 5469b2bfe2..e5ccb17959 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -3,6 +3,20 @@ // RUN: clang -ccc-host-triple i386-apple-darwin9 -arch i386 -arch x86_64 %s -### -o foo 2> %t.log && // RUN: grep '".*collect2" .*"-arch_multiple" "-final_output" "foo"' %t.log && +// RUN: clang -ccc-host-triple i386-apple-darwin9 -### -filelist FOO -static 2> %t.log && +// RUN: grep '"-lcrt0.o" .*"-lgcc_static"' %t.log && +// RUN: grep '"-lgcc"' %t.log | count 0 && +// RUN: clang -ccc-host-triple i386-apple-darwin7 -### -filelist FOO 2> %t.log && +// RUN: grep '"-lcrt1.o" .*"-lgcc" "-lSystem"' %t.log && +// RUN: grep '"-lgcc_s"' %t.log | count 0 && +// RUN: clang -ccc-host-triple i386-apple-darwin8 -### -filelist FOO 2> %t.log && +// RUN: grep '"-lcrt1.o" .*"-lgcc_s.10.4" "-lgcc" "-lSystem"' %t.log && +// RUN: clang -ccc-host-triple i386-apple-darwin9 -### -filelist FOO 2> %t.log && +// RUN: grep '"-lcrt1.10.5.o" .*"-lgcc_s.10.5" "-lgcc" "-lSystem"' %t.log && +// RUN: clang -ccc-host-triple i386-apple-darwin10 -### -filelist FOO 2> %t.log && +// RUN: grep '"-lcrt1.10.6.o" .*"-lSystem" "-lgcc"' %t.log && +// RUN: grep '"-lgcc_s"' %t.log | count 0 && + // Splatter test case. This is gross, but it works for now. For the // driver, just getting coverage of the tool code and checking the // output options is nearly good enough. The main thing we are -- 2.40.0