From 00d3d8e9028e4937121cb8b76254bcac3d6477fc Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Tue, 29 Jun 2010 16:38:33 +0000 Subject: [PATCH] Driver/Darwin: Only run dsymutil when we are also compiling/assembling as part of the compilation. - clang is always invoking dsymutil llvm-svn: 107149 --- clang/lib/Driver/Driver.cpp | 24 +++++++++++++++++++----- clang/test/Driver/darwin-dsymutil.c | 7 +++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 0dbe39c28212..200e43842cae 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -39,9 +39,6 @@ using namespace clang::driver; using namespace clang; -// Used to set values for "production" clang, for releases. -// #define USE_PRODUCTION_CLANG - Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir, llvm::StringRef _DefaultHostTriple, llvm::StringRef _DefaultImageName, @@ -510,6 +507,19 @@ void Driver::PrintActions(const Compilation &C) const { PrintActions1(C, *it, Ids); } +/// \brief Check whether the given input tree contains any compilation (or +/// assembly) actions. +static bool ContainsCompileAction(const Action *A) { + if (isa(A) || isa(A)) + return true; + + for (Action::const_iterator it = A->begin(), ie = A->end(); it != ie; ++it) + if (ContainsCompileAction(*it)) + return true; + + return false; +} + void Driver::BuildUniversalActions(const ArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building universal build actions"); @@ -586,11 +596,15 @@ void Driver::BuildUniversalActions(const ArgList &Args, else Actions.push_back(new LipoJobAction(Inputs, Act->getType())); - // Add a 'dsymutil' step if necessary. + // Add a 'dsymutil' step if necessary, when debug info is enabled and we + // have a compile input. We need to run 'dsymutil' ourselves in such cases + // because the debug info will refer to a temporary object file which is + // will be removed at the end of the compilation process. if (Act->getType() == types::TY_Image) { Arg *A = Args.getLastArg(options::OPT_g_Group); if (A && !A->getOption().matches(options::OPT_g0) && - !A->getOption().matches(options::OPT_gstabs)) { + !A->getOption().matches(options::OPT_gstabs) && + ContainsCompileAction(Actions.back())) { ActionList Inputs; Inputs.push_back(Actions.back()); Actions.pop_back(); diff --git a/clang/test/Driver/darwin-dsymutil.c b/clang/test/Driver/darwin-dsymutil.c index fd236dd60c28..752afae3bf75 100644 --- a/clang/test/Driver/darwin-dsymutil.c +++ b/clang/test/Driver/darwin-dsymutil.c @@ -29,3 +29,10 @@ // // CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Link", inputs: [{{.*}}], output: "foo" // CHECK-OUTPUT-NAME: "x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["foo"], output: "foo.dSYM" + +// Check that we only use dsymutil when needed. +// +// RUN: touch %t.o +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -ccc-print-bindings \ +// RUN: -o foo %t.o -g 2> %t +// RUN: grep "Dsymutil" %t | count 0