diff options
author | Googler <noreply@google.com> | 2017-01-20 17:01:21 +0000 |
---|---|---|
committer | Laszlo Csomor <laszlocsomor@google.com> | 2017-01-23 09:52:34 +0000 |
commit | efb2f17075a3dbc3d5875699252db7e35a28c8d7 (patch) | |
tree | 68f5b9335c5160217c762c471e33c80f1f235813 /src/main | |
parent | 1ba41a8c4fa6d21c48145ef3e91cd0315ccac574 (diff) |
Description redacted.
--
PiperOrigin-RevId: 145091484
MOS_MIGRATED_REVID=145091484
Diffstat (limited to 'src/main')
7 files changed, 128 insertions, 32 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 b21536e797..6d8f41ce88 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 @@ -275,15 +275,21 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { // Store immutable context for use in other *_binary rules that are implemented by // linking the interpreter (Java, Python, etc.) together with native deps. CppLinkAction.Context linkContext = new CppLinkAction.Context(linkActionBuilder); + Iterable<LTOBackendArtifacts> ltoBackendArtifacts = ImmutableList.of(); + boolean usePic = CppHelper.usePic(ruleContext, !isLinkShared(ruleContext)); if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) { linkActionBuilder.setLTOIndexing(true); CppLinkAction indexAction = linkActionBuilder.build(); ruleContext.registerAction(indexAction); - for (LTOBackendArtifacts ltoArtifacts : indexAction.getAllLTOBackendArtifacts()) { - boolean usePic = CppHelper.usePic(ruleContext, !isLinkShared(ruleContext)); - ltoArtifacts.scheduleLTOBackendAction(ruleContext, featureConfiguration, usePic); + ltoBackendArtifacts = indexAction.getAllLTOBackendArtifacts(); + for (LTOBackendArtifacts ltoArtifacts : ltoBackendArtifacts) { + ltoArtifacts.scheduleLTOBackendAction( + ruleContext, + featureConfiguration, + usePic, + /*generateDwo=*/ cppConfiguration.useFission()); } linkActionBuilder.setLTOIndexing(false); @@ -317,7 +323,13 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CppHelper.createStripAction(ruleContext, cppConfiguration, executable, strippedFile); DwoArtifactsCollector dwoArtifacts = - collectTransitiveDwoArtifacts(ruleContext, ccCompilationOutputs, linkStaticness); + collectTransitiveDwoArtifacts( + ruleContext, + ccCompilationOutputs, + linkStaticness, + cppConfiguration.useFission(), + usePic, + ltoBackendArtifacts); Artifact dwpFile = ruleContext.getImplicitOutputArtifact(CppRuleClasses.CC_BINARY_DEBUG_PACKAGE); createDebugPackagerActions(ruleContext, cppConfiguration, dwpFile, dwoArtifacts); @@ -514,16 +526,23 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { * Collects .dwo artifacts either transitively or directly, depending on the link type. * * <p>For a cc_binary, we only include the .dwo files corresponding to the .o files that are - * passed into the link. For static linking, this includes all transitive dependencies. But - * for dynamic linking, dependencies are separately linked into their own shared libraries, - * so we don't need them here. + * passed into the link. For static linking, this includes all transitive dependencies. But for + * dynamic linking, dependencies are separately linked into their own shared libraries, so we + * don't need them here. */ - private static DwoArtifactsCollector collectTransitiveDwoArtifacts(RuleContext context, - CcCompilationOutputs compilationOutputs, LinkStaticness linkStaticness) { + private static DwoArtifactsCollector collectTransitiveDwoArtifacts( + RuleContext context, + CcCompilationOutputs compilationOutputs, + LinkStaticness linkStaticness, + boolean generateDwo, + boolean ltoBackendArtifactsUsePic, + Iterable<LTOBackendArtifacts> ltoBackendArtifacts) { if (linkStaticness == LinkStaticness.DYNAMIC) { - return DwoArtifactsCollector.directCollector(compilationOutputs); + return DwoArtifactsCollector.directCollector( + context, compilationOutputs, generateDwo, ltoBackendArtifactsUsePic, ltoBackendArtifacts); } else { - return CcCommon.collectTransitiveDwoArtifacts(context, compilationOutputs); + return CcCommon.collectTransitiveDwoArtifacts( + context, compilationOutputs, generateDwo, ltoBackendArtifactsUsePic, ltoBackendArtifacts); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index c1128f773a..7cc659e1b5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -162,12 +162,13 @@ public final class CcCommon { return ruleContext.attributes().has(name, type); } - /** - * Collects all .dwo artifacts in this target's transitive closure. - */ + /** Collects all .dwo artifacts in this target's transitive closure. */ public static DwoArtifactsCollector collectTransitiveDwoArtifacts( RuleContext ruleContext, - CcCompilationOutputs compilationOutputs) { + CcCompilationOutputs compilationOutputs, + boolean generateDwo, + boolean ltoBackendArtifactsUsePic, + Iterable<LTOBackendArtifacts> ltoBackendArtifacts) { ImmutableList.Builder<TransitiveInfoCollection> deps = ImmutableList.<TransitiveInfoCollection>builder(); @@ -177,9 +178,15 @@ public final class CcCommon { deps.add(CppHelper.mallocForTarget(ruleContext)); } - return compilationOutputs == null // Possible in LIPO collection mode (see initializationHook). + return compilationOutputs == null // Possible in LIPO collection mode (see initializationHook). ? DwoArtifactsCollector.emptyCollector() - : DwoArtifactsCollector.transitiveCollector(compilationOutputs, deps.build()); + : DwoArtifactsCollector.transitiveCollector( + ruleContext, + compilationOutputs, + deps.build(), + generateDwo, + ltoBackendArtifactsUsePic, + ltoBackendArtifacts); } public TransitiveLipoInfoProvider collectTransitiveLipoLabels(CcCompilationOutputs outputs) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java index a172f805da..4a5692014d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java @@ -926,7 +926,13 @@ public final class CcLibraryHelper { } DwoArtifactsCollector dwoArtifacts = - DwoArtifactsCollector.transitiveCollector(ccOutputs, deps); + DwoArtifactsCollector.transitiveCollector( + ruleContext, + ccOutputs, + deps, /*generateDwo=*/ + false, /*ltoBackendArtifactsUsePic=*/ + false, /*ltoBackendArtifacts=*/ + ImmutableList.of()); Runfiles cppStaticRunfiles = collectCppRunfiles(ccLinkingOutputs, true); Runfiles cppSharedRunfiles = collectCppRunfiles(ccLinkingOutputs, false); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index ec1ef1e3b8..64f1db9375 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -829,6 +829,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment { + " action: 'c++-compile'" + " action: 'assemble'" + " action: 'preprocess-assemble'" + + " action: 'lto-backend'" + " expand_if_all_available: 'per_object_debug_info_file'" + " flag_group {" + " flag: '-gsplit-dwarf'" diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java index c3dee0b557..4c134a512d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java @@ -508,6 +508,9 @@ public final class CppModel { } else if (CppFileTypes.CLIF_INPUT_PROTO.matches(source.getSource().getExecPath())) { createClifMatchAction(outputName, result, env, builder); } else { + boolean bitcodeOutput = + featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO) + && CppFileTypes.LTO_SOURCE.matches(sourceArtifact.getFilename()); createSourceAction( outputName, result, @@ -517,7 +520,10 @@ public final class CppModel { ArtifactCategory.OBJECT_FILE, /*addObject=*/ true, isCodeCoverageEnabled(), - /*generateDwo=*/ cppConfiguration.useFission(), + // The source action does not generate dwo when it has bitcode + // output (since it isn't generating a native object with debug + // info). In that case the LTOBackendAction will generate the dwo. + /*generateDwo=*/ cppConfiguration.useFission() && !bitcodeOutput, CppFileTypes.mustProduceDotdFile(sourceArtifact.getFilename()), source.getBuildVariables()); } @@ -966,7 +972,15 @@ public final class CppModel { for (LTOBackendArtifacts ltoArtifacts : indexAction.getAllLTOBackendArtifacts()) { ltoArtifacts.scheduleLTOBackendAction( - ruleContext, featureConfiguration, usePicForSharedLibs); + ruleContext, + featureConfiguration, + usePicForSharedLibs, + // If support is ever added for generating a dwp file for shared + // library targets (e.g. when linkstatic=0), then this should change + // to generate dwo files when cppConfiguration.useFission(), + // and the dwp generating action for the shared library should + // include all of the resulting dwo files. + /*generateDwo=*/ false); } linkActionBuilder.setLTOIndexing(false); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java index c097198c7f..5745d35d0c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.cpp; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -38,11 +39,14 @@ public class DwoArtifactsCollector { */ private final NestedSet<Artifact> picDwoArtifacts; - /** - * Instantiates a "real" collector on meaningful data. - */ - private DwoArtifactsCollector(CcCompilationOutputs compilationOutputs, - Iterable<TransitiveInfoCollection> deps) { + /** Instantiates a "real" collector on meaningful data. */ + private DwoArtifactsCollector( + RuleContext ruleContext, + CcCompilationOutputs compilationOutputs, + Iterable<TransitiveInfoCollection> deps, + boolean generateDwo, + boolean ltoBackendArtifactsUsePic, + Iterable<LTOBackendArtifacts> ltoBackendArtifacts) { Preconditions.checkNotNull(compilationOutputs); Preconditions.checkNotNull(deps); @@ -56,6 +60,19 @@ public class DwoArtifactsCollector { dwoBuilder.addAll(compilationOutputs.getDwoFiles()); picDwoBuilder.addAll(compilationOutputs.getPicDwoFiles()); + // If we are generating .dwo, add any generated for LTOBackendArtifacts. + if (generateDwo) { + for (LTOBackendArtifacts ltoBackendArtifact : ltoBackendArtifacts) { + Artifact objectFile = ltoBackendArtifact.getObjectFile(); + if (ltoBackendArtifactsUsePic) { + picDwoBuilder.add( + ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".dwo")); + } else { + dwoBuilder.add(ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".dwo")); + } + } + } + for (TransitiveInfoCollection info : deps) { CppDebugFileProvider provider = info.getProvider(CppDebugFileProvider.class); if (provider != null) { @@ -82,9 +99,20 @@ public class DwoArtifactsCollector { * @param compilationOutputs the output compilation context for the owning target * @param deps which of the target's transitive info collections should be visited */ - public static DwoArtifactsCollector transitiveCollector(CcCompilationOutputs compilationOutputs, - Iterable<TransitiveInfoCollection> deps) { - return new DwoArtifactsCollector(compilationOutputs, deps); + public static DwoArtifactsCollector transitiveCollector( + RuleContext ruleContext, + CcCompilationOutputs compilationOutputs, + Iterable<TransitiveInfoCollection> deps, + boolean generateDwo, + boolean ltoBackendArtifactsUsePic, + Iterable<LTOBackendArtifacts> ltoBackendArtifacts) { + return new DwoArtifactsCollector( + ruleContext, + compilationOutputs, + deps, + generateDwo, + ltoBackendArtifactsUsePic, + ltoBackendArtifacts); } /** @@ -92,9 +120,19 @@ public class DwoArtifactsCollector { * * @param compilationOutputs the output compilation context for the owning target */ - public static DwoArtifactsCollector directCollector(CcCompilationOutputs compilationOutputs) { - return new DwoArtifactsCollector( - compilationOutputs, ImmutableList.<TransitiveInfoCollection>of()); + public static DwoArtifactsCollector directCollector( + RuleContext ruleContext, + CcCompilationOutputs compilationOutputs, + boolean generateDwo, + boolean ltoBackendArtifactsUsePic, + Iterable<LTOBackendArtifacts> ltoBackendArtifacts) { + return new DwoArtifactsCollector( + ruleContext, + compilationOutputs, + ImmutableList.<TransitiveInfoCollection>of(), + generateDwo, + ltoBackendArtifactsUsePic, + ltoBackendArtifacts); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java index 1d2a25c9af..b509bf9007 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java @@ -106,7 +106,10 @@ public final class LTOBackendArtifacts { } public void scheduleLTOBackendAction( - RuleContext ruleContext, FeatureConfiguration featureConfiguration, boolean usePic) { + RuleContext ruleContext, + FeatureConfiguration featureConfiguration, + boolean usePic, + boolean generateDwo) { LTOBackendAction.Builder builder = new LTOBackendAction.Builder(); builder.addImportsInfo(bitcodeFiles, imports); @@ -139,6 +142,14 @@ public final class LTOBackendArtifacts { if (autoFdoProfile != null) { builder.addInput(autoFdoProfile); } + + if (generateDwo) { + Artifact dwoFile = ruleContext.getRelatedArtifact(objectFile.getRootRelativePath(), ".dwo"); + builder.addOutput(dwoFile); + buildVariablesBuilder.addStringVariable( + "per_object_debug_info_file", dwoFile.getExecPathString()); + } + Variables buildVariables = buildVariablesBuilder.build(); List<String> execArgs = new ArrayList<>(); execArgs.addAll(featureConfiguration.getCommandLine("lto-backend", buildVariables)); |