diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -2033,13 +2033,17 @@ Arg *A = Args.getLastArg(options::OPT_g_Group); bool enablesDebugInfo = A && !A->getOption().matches(options::OPT_g0) && !A->getOption().matches(options::OPT_gstabs); + bool isGeneratingTemporaryObject = + ContainsCompileOrAssembleAction(Actions.back()) || LTOMode != LTOK_None; if ((enablesDebugInfo || willEmitRemarks(Args)) && - ContainsCompileOrAssembleAction(Actions.back())) { + isGeneratingTemporaryObject) { // 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 - // will be removed at the end of the compilation process. + // are linking a temporary object. This occurs when we have a compiler + // or assmbler input or if LTO is enabled. We need to run 'dsymutil' + // ourselves in such cases because the debug info will refer to the + // temporary object file which will be removed at the end of the + // compilation process. if (Act->getType() == types::TY_Image) { ActionList Inputs; Inputs.push_back(Actions.back()); diff --git a/clang/test/Driver/darwin-dsymutil.c b/clang/test/Driver/darwin-dsymutil.c --- a/clang/test/Driver/darwin-dsymutil.c +++ b/clang/test/Driver/darwin-dsymutil.c @@ -47,3 +47,11 @@ // Check that we don't crash when translating arguments for dsymutil. // RUN: %clang -m32 -arch x86_64 -g %s -### + +// Check that we run dsymutil when -flto is specified and no source is provided +// RUN: touch %t.o +// RUN: %clang -target x86_64-apple-darwin10 -ccc-print-bindings \ +// RUN: -arch x86_64 %t.o -g -flto 2> %t +// RUN: FileCheck -check-prefix=CHECK-DSYMUTIL-LTO < %t %s + +// CHECK-DSYMUTIL-LTO: x86_64-apple-darwin10" - "darwin::Dsymutil", inputs: ["a.out"], output: "a.out.dSYM"