Skip to content

Commit

Permalink
Driver/Darwin: When invoking the linker, automatically pass -object_p…
Browse files Browse the repository at this point in the history
…ath_lto so

that the linker has a place to put the temporary object file and can leave it
around (for the driver to clean up). This is important so that the object file
references in the debug info are preserved for possible use by dsymutil.
 - <rdar://problem/8294279> executable has no debug symbols when compiled with LTO

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133543 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
ddunbar committed Jun 21, 2011
1 parent ed79895 commit 5bfa656
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Driver/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions test/Driver/darwin-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5bfa656

Please sign in to comment.