diff options
| author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2015-10-02 15:10:33 +0000 |
|---|---|---|
| committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2015-10-02 15:10:33 +0000 |
| commit | a5efe3a66b9655a7f3ae6fa8d308455af3f50daa (patch) | |
| tree | 68f9b9b367e5ace0683c26dbf090ae3c38f17c79 /clang | |
| parent | f9989b04bf13c16f98e30d785596ff836a7a915f (diff) | |
| download | bcm5719-llvm-a5efe3a66b9655a7f3ae6fa8d308455af3f50daa.tar.gz bcm5719-llvm-a5efe3a66b9655a7f3ae6fa8d308455af3f50daa.zip | |
[DarwinDriver] Reapply: Use -lto_library to specify the path for libLTO.dylib
Reapply r248935.
Usually, when using LTO with a clang installation newer than the
system's one, there's a libLTO.dylib version mismatch and LTO fails. One
solution to this is to make ld point to the right libLTO.dylib by
changing DYLD_LIBRARY_PATH.
However, ld64 supports specifying the complete path to the desired
libLTO.dylib through the -lto_library option. This commit adds support
for the clang driver to use this option whenever it's capable of finding
a libLTO.dylib in clang's installed library directory. This way, we
don't need to rely on DYLD_LIBRARY_PATH nor get caught by version
mismatches.
Differential Revision: http://reviews.llvm.org/D13117
rdar://problem/7363476
llvm-svn: 249143
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticGroups.td | 1 | ||||
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 37 | ||||
| -rw-r--r-- | clang/test/Driver/darwin-ld-lto.c | 25 |
4 files changed, 56 insertions, 9 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index f7f09da4ea6..c54d58a87a4 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -117,6 +117,8 @@ def err_drv_optimization_remark_pattern : Error< def err_drv_no_neon_modifier : Error<"[no]neon is not accepted as modifier, please use [no]simd instead">; def warn_O4_is_O3 : Warning<"-O4 is equivalent to -O3">, InGroup<Deprecated>; +def warn_drv_lto_libpath : Warning<"libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead">, + InGroup<LibLTO>; def warn_drv_optimization_value : Warning<"optimization level '%0' is not supported; using '%1%2' instead">, InGroup<InvalidCommandLineArgument>; def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not supported">, diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index a185b22519a..bf655cc3aa5 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -96,6 +96,7 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedDeclarations, DeprecatedWritableStr]>, DiagCategory<"Deprecations">; +def LibLTO : DiagGroup<"liblto">; def : DiagGroup<"disabled-optimization">; def : DiagGroup<"discard-qual">; def : DiagGroup<"div-by-zero">; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 1b741ee8505..932122236b5 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -6502,15 +6502,34 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args, options::OPT_fno_application_extension, false)) CmdArgs.push_back("-application_extension"); - // 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] >= 116 && D.IsUsingLTO(Args) && NeedsTempPath(Inputs)) { - const char *TmpPath = C.getArgs().MakeArgString( - D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object))); - C.addTempFile(TmpPath); - CmdArgs.push_back("-object_path_lto"); - CmdArgs.push_back(TmpPath); + if (D.IsUsingLTO(Args)) { + // 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] >= 116 && NeedsTempPath(Inputs)) { + const char *TmpPath = C.getArgs().MakeArgString( + D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object))); + C.addTempFile(TmpPath); + CmdArgs.push_back("-object_path_lto"); + CmdArgs.push_back(TmpPath); + } + + // Use -lto_library option to specify the libLTO.dylib path. Try to find + // it in clang installed libraries. If not found, the option is not used + // and 'ld' will use its default mechanism to search for libLTO.dylib. + if (Version[0] >= 133) { + // Search for libLTO in <InstalledDir>/../lib/libLTO.dylib + StringRef P = llvm::sys::path::parent_path(D.getInstalledDir()); + SmallString<128> LibLTOPath(P); + llvm::sys::path::append(LibLTOPath, "lib"); + llvm::sys::path::append(LibLTOPath, "libLTO.dylib"); + if (llvm::sys::fs::exists(LibLTOPath)) { + CmdArgs.push_back("-lto_library"); + CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath)); + } else { + D.Diag(diag::warn_drv_lto_libpath); + } + } } // Derived from the "link" spec. diff --git a/clang/test/Driver/darwin-ld-lto.c b/clang/test/Driver/darwin-ld-lto.c new file mode 100644 index 00000000000..23e006a0185 --- /dev/null +++ b/clang/test/Driver/darwin-ld-lto.c @@ -0,0 +1,25 @@ +// REQUIRES: system-darwin + +// Check that ld gets "-lto_library" and warnings about libLTO.dylib path. + +// RUN: %clang -target x86_64-apple-darwin10 -### %s \ +// RUN: -mlinker-version=133 -flto 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s < %t.log +// +// LINK_LTOLIB_PATH: {{ld(.exe)?"}} +// LINK_LTOLIB_PATH: "-lto_library" + +// RUN: %clang -target x86_64-apple-darwin10 -### %s \ +// RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 -flto 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_WRN %s < %t.log +// +// LINK_LTOLIB_PATH_WRN: warning: libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead + +// RUN: %clang -target x86_64-apple-darwin10 -### %s \ +// RUN: -ccc-install-dir %S/dummytestdir -mlinker-version=133 -Wno-liblto -flto 2> %t.log +// RUN: cat %t.log +// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_NOWRN %s < %t.log +// +// LINK_LTOLIB_PATH_NOWRN-NOT: warning: libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead |

