aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-09-11 23:03:52 +0200
committerGravatar Philipp Wollermann <philwo@google.com>2017-09-12 14:05:56 +0200
commit52d718c11b73af6c5b278710dfce26434b2e0380 (patch)
treea22d669abd37ba4aa74c21c5778e98fc41b7ae54 /src/main/java/com/google/devtools/build
parentbb50580a7f3eb3f4e7c5fba8e92d20e931591a70 (diff)
Don't attempt LTO indexing of cc_binary if there are no bitcode inputs to link.
The problem is that the linker will not produce the expected .params file output if there are no inputs, and there is no need for this step in that case. This required adding a method to check if there are any bitcode inputs to the link either directly or indirectly via a library. This is the same walk done by createLtoArtifacts once we decide to do an LTO indexing step. RELNOTES: NONE PiperOrigin-RevId: 168281516
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index c613ff0ec6..8c91d6be80 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -288,7 +288,8 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
Iterable<LtoBackendArtifacts> ltoBackendArtifacts = ImmutableList.of();
boolean usePic = CppHelper.usePic(ruleContext, !isLinkShared(ruleContext));
- if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) {
+ if (linkActionBuilder.hasLtoBitcodeInputs()
+ && featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) {
linkActionBuilder.setLtoIndexing(true);
linkActionBuilder.setUsePicForLtoBackendActions(usePic);
CppLinkAction indexAction = linkActionBuilder.build();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index d2a03172d5..d4f3e4e515 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -498,6 +498,22 @@ public class CppLinkActionBuilder {
return uniqueLibrariesBuilder.build();
}
+ /**
+ * Returns true if there are any LTO bitcode inputs to this link, either directly transitively via
+ * library inputs.
+ */
+ boolean hasLtoBitcodeInputs() {
+ if (!ltoBitcodeFiles.isEmpty()) {
+ return true;
+ }
+ for (LibraryToLink lib : libraries.build()) {
+ if (!lib.getLtoBitcodeFiles().isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private Iterable<LtoBackendArtifacts> createLtoArtifacts(
PathFragment ltoOutputRootPrefix, NestedSet<LibraryToLink> uniqueLibraries) {
Set<Artifact> compiled = new LinkedHashSet<>();