]> granicus.if.org Git - clang/commitdiff
darwin: Unconditionally pass -lto_library, remove -Wliblto warning.
authorNico Weber <nicolasweber@gmx.de>
Tue, 22 Nov 2016 19:38:07 +0000 (19:38 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 22 Nov 2016 19:38:07 +0000 (19:38 +0000)
https://reviews.llvm.org/D25932 made it so that clang always checks if
libLTO.dylib is present on disk, even if -flto is not being used. The
motivation for that change was that if a dependency happens to contain bitcode,
ld64 will try to load libLTO without -flto explicitly being enabled. However,
the change had the undesirable side effect of warning if libLTO.dylib doesn't
exist even if it isn't needed.

Change things so that -lto_library is always passes, independent of if it
exists or not. ld64 only looks at this flag if it uses LTO. If the dylib
exists, all is well. If it doesn't, and LTO is not being used, all is well too.
If ld64 does end up using LTO and the dylib does not exist, ld64 will print
something like

    ld: could not process llvm bitcode object file, because foo/libLTO.dylib could not be loaded file 'test.o' for architecture x86_64

https://reviews.llvm.org/D26984

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287685 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticDriverKinds.td
lib/Driver/Tools.cpp
test/Driver/darwin-ld-lto.c

index c28c92e7a78d69ded3ae362f0170bf3060736e8f..3d0bfe6c049bc29d57ebea3f9ee054bc0f844b84 100644 (file)
@@ -168,8 +168,6 @@ def err_drv_bitcode_unsupported_on_toolchain : Error<
   "-fembed-bitcode is not supported on versions of iOS prior to 6.0">;
 
 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">,
index 038f682f62905ea10cf4c7b37801137ea41535c8..8760b85e4fb57290f63733e140088f8def9aa103 100644 (file)
@@ -8221,20 +8221,20 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
   }
 
   // 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.
+  // it in clang installed libraries. ld64 will only look at this argument
+  // when it actually uses LTO, so libLTO.dylib only needs to exist at link
+  // time if ld64 decides that it needs to use LTO.
+  // Since this is passed unconditionally, ld64 will never look for libLTO.dylib
+  // next to it. That's ok since ld64 using a libLTO.dylib not matching the
+  // clang version won't work anyways.
   if (Version[0] >= 133) {
     // Search for libLTO in <InstalledDir>/../lib/libLTO.dylib
     StringRef P = llvm::sys::path::parent_path(D.Dir);
     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);
-    }
+    CmdArgs.push_back("-lto_library");
+    CmdArgs.push_back(C.getArgs().MakeArgString(LibLTOPath));
   }
 
   // ld64 version 262 and above run the deduplicate pass by default.
index dcdeebb44004b884f19ea3063db432ff2e92fbb8..21c2214b771f40d54df5f57b7f27ffb2b9e7f9da 100644 (file)
@@ -1,6 +1,6 @@
 // REQUIRES: system-darwin
 
-// Check that ld gets "-lto_library" and warnings about libLTO.dylib path.
+// Check that ld gets "-lto_library".
 
 // RUN: mkdir -p %T/bin
 // RUN: mkdir -p %T/lib
 // LINK_LTOLIB_PATH: {{ld(.exe)?"}}
 // LINK_LTOLIB_PATH: "-lto_library"
 
+// Also pass -lto_library even if the file doesn't exist; if it's needed at
+// link time, ld will complain instead.
 // RUN: %clang -target x86_64-apple-darwin10 -### %s \
 // RUN:   -ccc-install-dir %S/dummytestdir -mlinker-version=133 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_WRN %s -input-file %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 2> %t.log
-// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH_NOWRN %s -input-file %t.log
-//
-// LINK_LTOLIB_PATH_NOWRN-NOT: warning: libLTO.dylib relative to clang installed dir not found; using 'ld' default search path instead
+// RUN: FileCheck -check-prefix=LINK_LTOLIB_PATH %s -input-file %t.log