diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index b3cef73e5269..41efccfb93a7 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2907,6 +2907,17 @@ void darwin::Link::AddLinkArgs(Compilation &C, CmdArgs.push_back("-demangle"); } + // If we are using LTO, then automatically create a temporary file path for + // the linker to use, so that it's lifetime will extend past a possible + // dsymutil step. + if (Version[0] >= 100 && D.IsUsingLTO(Args)) { + const char *TmpPath = C.getArgs().MakeArgString( + D.GetTemporaryPath(types::getTypeTempSuffix(types::TY_Object))); + C.addTempFile(TmpPath); + CmdArgs.push_back("-object_path_lto"); + CmdArgs.push_back(TmpPath); + } + // Derived from the "link" spec. Args.AddAllArgs(CmdArgs, options::OPT_static); if (!Args.hasArg(options::OPT_static)) diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c index f6ea829570cb..a87de540360e 100644 --- a/clang/test/Driver/darwin-ld.c +++ b/clang/test/Driver/darwin-ld.c @@ -92,3 +92,11 @@ // LINK_OLDER_NODEMANGLE: {{ld(.exe)?"}} // LINK_OLDER_NODEMANGLE-NOT: "-demangle" // LINK_OLDER_NODEMANGLE: "-lSystem" + +// RUN: %clang -ccc-host-triple x86_64-apple-darwin10 -### %t.o \ +// RUN: -mlinker-version=101 -flto 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=LINK_OBJECT_LTO_PATH %s < %t.log +// +// LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}} +// LINK_OBJECT_LTO_PATH: "-object_path_lto"