From: Daniel Dunbar Date: Fri, 20 Mar 2009 16:06:39 +0000 (+0000) Subject: Driver: Add and use darwin::Assemble tool. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8cac5f7e1ce63dd77ee0fb4ef68f9fa804f41ea6;p=clang Driver: Add and use darwin::Assemble tool. - Based on patch from Pieter de Bie; thanks! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67379 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 3941726c2e..3165a8f395 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -44,7 +44,7 @@ Tool &Darwin_X86::SelectTool(const Compilation &C, case Action::CompileJobClass: T = new tools::gcc::Compile(*this); break; case Action::AssembleJobClass: - T = new tools::gcc::Assemble(*this); break; + T = new tools::darwin::Assemble(*this); break; case Action::LinkJobClass: T = new tools::gcc::Link(*this); break; case Action::LipoJobClass: diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 9ac20f9c95..9a3930c5be 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -438,10 +438,56 @@ void gcc::Link::RenderExtraToolArgs(ArgStringList &CmdArgs) const { // The types are (hopefully) good enough. } +void darwin::Assemble::ConstructJob(Compilation &C, const JobAction &JA, + Job &Dest, const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + assert(Inputs.size() == 1 && "Unexpected number of inputs."); + const InputInfo &Input = Inputs[0]; + + // Bit of a hack, this is only used for original inputs. + if (Input.isFilename() && + strcmp(Input.getFilename(), Input.getBaseInput()) == 0 && + Args.hasArg(options::OPT_g_Group)) + CmdArgs.push_back("--gstabs"); + + // Derived from asm spec. + CmdArgs.push_back("-arch"); + CmdArgs.push_back(getToolChain().getArchName().c_str()); + + CmdArgs.push_back("-force_cpusubtype_ALL"); + if ((Args.hasArg(options::OPT_mkernel) || + Args.hasArg(options::OPT_static) || + Args.hasArg(options::OPT_fapple_kext)) && + !Args.hasArg(options::OPT_dynamic)) + CmdArgs.push_back("-static"); + + Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, + options::OPT_Xassembler); + + assert(Output.isFilename() && "Unexpected lipo output."); + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + + if (Input.isPipe()) { + CmdArgs.push_back("-"); + } else { + assert(Input.isFilename() && "Invalid input."); + CmdArgs.push_back(Input.getFilename()); + } + + // asm_final spec is empty. + + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath(C, "as").c_str()); + Dest.addCommand(new Command(Exec, CmdArgs)); +} void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, - Job &Dest, - const InputInfo &Output, + Job &Dest, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index 40aa2084da..672096e391 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -111,9 +111,25 @@ namespace gcc { } // end namespace gcc namespace darwin { + class VISIBILITY_HIDDEN Assemble : public Tool { + public: + Assemble(const ToolChain &TC) : Tool("darwin::Assemble", TC) {} + + virtual bool acceptsPipedInput() const { return true; } + virtual bool canPipeOutput() const { return false; } + virtual bool hasIntegratedCPP() const { return false; } + + virtual void ConstructJob(Compilation &C, const JobAction &JA, + Job &Dest, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &TCArgs, + const char *LinkingOutput) const; + }; + class VISIBILITY_HIDDEN Lipo : public Tool { public: - Lipo(const ToolChain &TC) : Tool("gcc::Link", TC) {} + Lipo(const ToolChain &TC) : Tool("darwin::Lipo", TC) {} virtual bool acceptsPipedInput() const { return false; } virtual bool canPipeOutput() const { return false; } diff --git a/test/Driver/bindings.c b/test/Driver/bindings.c index 01382a198d..2b4633ffb5 100644 --- a/test/Driver/bindings.c +++ b/test/Driver/bindings.c @@ -1,43 +1,49 @@ // Basic binding. -// RUN: clang-driver -ccc-print-bindings %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings %s &> %t && // RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: ".*\.s"' %t && // RUN: grep 'bind - "gcc::Assemble", inputs: \[".*\.s"\], output: ".*\.o"' %t && // RUN: grep 'bind - "gcc::Link", inputs: \[".*\.o"\], output: "a.out"' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang %s &> %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: ".*\.s"' %t && // RUN: grep 'bind - "gcc::Assemble", inputs: \[".*\.s"\], output: ".*\.o"' %t && // RUN: grep 'bind - "gcc::Link", inputs: \[".*\.o"\], output: "a.out"' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang -no-integrated-cpp %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang -no-integrated-cpp %s &> %t && // RUN: grep 'bind - "gcc::Preprocess", inputs: \[".*bindings.c"\], output: ".*\.i"' %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[".*\.i"\], output: ".*\.s"' %t && // RUN: grep 'bind - "gcc::Assemble", inputs: \[".*\.s"\], output: ".*\.o"' %t && // RUN: grep 'bind - "gcc::Link", inputs: \[".*\.o"\], output: "a.out"' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang -no-integrated-cpp -pipe %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang -no-integrated-cpp -pipe %s &> %t && // RUN: grep 'bind - "gcc::Preprocess", inputs: \[".*bindings.c"\], output: (pipe)' %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[(pipe)\], output: (pipe)' %t && // RUN: grep 'bind - "gcc::Assemble", inputs: \[(pipe)\], output: ".*\.o"' %t && // RUN: grep 'bind - "gcc::Link", inputs: \[".*\.o"\], output: "a.out"' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang -x c-header %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang -x c-header %s &> %t && // RUN: grep 'bind - "gcc::Precompile", inputs: \[".*bindings.c"\], output: ".*bindings.c.gch' %t && // Clang control options -// RUN: clang-driver -ccc-print-bindings -fsyntax-only %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -fsyntax-only %s &> %t && // RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: (nothing)' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang -fsyntax-only %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang -fsyntax-only %s &> %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: (nothing)' %t && -// RUN: clang-driver -ccc-print-bindings -ccc-no-clang-cxx -fsyntax-only -x c++ %s &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-bindings -ccc-no-clang-cxx -fsyntax-only -x c++ %s &> %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: (nothing)' %t && // RUN: clang-driver -ccc-print-bindings -ccc-no-clang-cpp -fsyntax-only -no-integrated-cpp -x c++ %s &> %t && // RUN: grep 'bind - "gcc::Preprocess", inputs: \[".*bindings.c"\], output: ".*\.ii"' %t && // RUN: grep 'bind - "clang", inputs: \[".*\.ii"\], output: (nothing)' %t && -// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc &> %t && // RUN: grep 'bind - "gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && -// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs ppc %s -S -arch ppc &> %t && +// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs ppc %s -S -arch ppc &> %t && // RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && +// Darwin bindings +// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings %s &> %t && +// RUN: grep 'bind - "clang", inputs: \[".*bindings.c"\], output: ".*\.s"' %t && +// RUN: grep 'bind - "darwin::Assemble", inputs: \[".*\.s"\], output: ".*\.o"' %t && +// RUN: grep 'bind - "gcc::Link", inputs: \[".*\.o"\], output: "a.out"' %t && + // RUN: true