aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-02-12 16:35:47 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-12 16:37:42 -0800
commit26761d7258f0751c9a5f69a1fe7b889a54333652 (patch)
tree9c5b2d4ad73310dce7f631ec6f51cef6b7c2c0bc /src
parentffb8a98a99cccbeaa397e7dc6eb04ee36f86b048 (diff)
Blaze: let a LinkerInput declare that it needs debug info in the executable
RELNOTES: None. PiperOrigin-RevId: 185455486
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java23
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInput.java5
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java50
3 files changed, 68 insertions, 10 deletions
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 e0cd9a44d9..46c9d92a81 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
@@ -209,6 +209,7 @@ public class CppLinkActionBuilder {
private boolean isNativeDeps;
private boolean useTestOnlyFlags;
private boolean wholeArchive;
+ private boolean mustKeepDebug = false;
private LinkArtifactFactory linkArtifactFactory = CppLinkAction.DEFAULT_ARTIFACT_FACTORY;
private boolean isLtoIndexing = false;
@@ -929,7 +930,8 @@ public class CppLinkActionBuilder {
// If we reached here, then allowLtoIndexing must be true (checked above).
/* allowLtoIndexing= */ true,
/* interfaceLibraryBuilder= */ null,
- /* interfaceLibraryOutput= */ null)
+ /* interfaceLibraryOutput= */ null,
+ mustKeepDebug)
: new CppLinkVariablesExtension(
configuration,
needWholeArchive,
@@ -943,7 +945,8 @@ public class CppLinkActionBuilder {
/* ltoOutputRootPrefix= */ PathFragment.EMPTY_FRAGMENT,
allowLtoIndexing,
toolchain.getInterfaceSoBuilder(),
- interfaceOutput);
+ interfaceOutput,
+ mustKeepDebug);
variablesExtension.addVariables(buildVariablesBuilder);
for (VariablesExtension extraVariablesExtension : variablesExtensions) {
extraVariablesExtension.addVariables(buildVariablesBuilder);
@@ -1314,6 +1317,9 @@ public class CppLinkActionBuilder {
Preconditions.checkArgument(
input.getArtifact().isTreeArtifact() || Link.OBJECT_FILETYPES.matches(name), name);
this.objectFiles.add(input);
+ if (input.isMustKeepDebug()) {
+ this.mustKeepDebug = true;
+ }
}
/**
@@ -1383,6 +1389,9 @@ public class CppLinkActionBuilder {
public CppLinkActionBuilder addLibrary(LibraryToLink input) {
checkLibrary(input);
libraries.add(input);
+ if (input.isMustKeepDebug()) {
+ mustKeepDebug = true;
+ }
return this;
}
@@ -1393,6 +1402,9 @@ public class CppLinkActionBuilder {
public CppLinkActionBuilder addLibraries(NestedSet<LibraryToLink> inputs) {
for (LibraryToLink input : inputs) {
checkLibrary(input);
+ if (input.isMustKeepDebug()) {
+ mustKeepDebug = true;
+ }
}
this.libraries.addTransitive(inputs);
return this;
@@ -1613,6 +1625,7 @@ public class CppLinkActionBuilder {
private final Artifact thinltoMergedObjectFile;
private final PathFragment ltoOutputRootPrefix;
private final boolean allowLtoIndexing;
+ private final boolean mustKeepDebug;
private final LinkArgCollector linkArgCollector = new LinkArgCollector();
@@ -1629,7 +1642,8 @@ public class CppLinkActionBuilder {
PathFragment ltoOutputRootPrefix,
boolean allowLtoIndexing,
Artifact interfaceLibraryBuilder,
- Artifact interfaceLibraryOutput) {
+ Artifact interfaceLibraryOutput,
+ boolean mustKeepDebug) {
this.configuration = configuration;
this.needWholeArchive = needWholeArchive;
this.linkerInputs = linkerInputs;
@@ -1643,6 +1657,7 @@ public class CppLinkActionBuilder {
this.thinltoMergedObjectFile = thinltoMergedObjectFile;
this.ltoOutputRootPrefix = ltoOutputRootPrefix;
this.allowLtoIndexing = allowLtoIndexing;
+ this.mustKeepDebug = mustKeepDebug;
addInputFileLinkOptions(linkArgCollector);
}
@@ -1661,7 +1676,7 @@ public class CppLinkActionBuilder {
buildVariables.addStringVariable(FORCE_PIC_VARIABLE, "");
}
- if (cppConfiguration.shouldStripBinaries()) {
+ if (!mustKeepDebug && cppConfiguration.shouldStripBinaries()) {
buildVariables.addStringVariable(STRIP_DEBUG_SYMBOLS_VARIABLE, "");
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInput.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInput.java
index dacc11275c..3d07e1b89c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInput.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInput.java
@@ -54,4 +54,9 @@ public interface LinkerInput {
* legal to call this only when {@link #containsObjectFiles()} returns true.
*/
Iterable<Artifact> getObjectFiles();
+
+ /**
+ * Returns whether we must keep debug symbols for this input.
+ */
+ boolean isMustKeepDebug();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
index 70ab54de4f..808db7be7d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkerInputs.java
@@ -117,6 +117,11 @@ public abstract class LinkerInputs {
public String toString() {
return "SimpleLinkerInput(" + artifact + ")";
}
+
+ @Override
+ public boolean isMustKeepDebug() {
+ return false;
+ }
}
/**
@@ -262,6 +267,11 @@ public abstract class LinkerInputs {
public int hashCode() {
return solibSymlinkArtifact.hashCode();
}
+
+ @Override
+ public boolean isMustKeepDebug() {
+ return false;
+ }
}
/** This class represents a library that may contain object files. */
@@ -278,6 +288,7 @@ public abstract class LinkerInputs {
private final Iterable<Artifact> objectFiles;
private final ImmutableMap<Artifact, Artifact> ltoBitcodeFiles;
private final ImmutableMap<Artifact, LtoBackendArtifacts> sharedNonLtoBackends;
+ private final boolean mustKeepDebug;
@AutoCodec.Instantiator
@VisibleForSerialization
@@ -287,13 +298,15 @@ public abstract class LinkerInputs {
String libraryIdentifier,
Iterable<Artifact> objectFiles,
ImmutableMap<Artifact, Artifact> ltoBitcodeFiles,
- ImmutableMap<Artifact, LtoBackendArtifacts> sharedNonLtoBackends) {
+ ImmutableMap<Artifact, LtoBackendArtifacts> sharedNonLtoBackends,
+ boolean mustKeepDebug) {
this.libraryArtifact = libraryArtifact;
this.category = category;
this.libraryIdentifier = libraryIdentifier;
this.objectFiles = objectFiles;
this.ltoBitcodeFiles = ltoBitcodeFiles;
this.sharedNonLtoBackends = sharedNonLtoBackends;
+ this.mustKeepDebug = mustKeepDebug;
}
private CompoundLibraryToLink(
@@ -303,7 +316,8 @@ public abstract class LinkerInputs {
Iterable<Artifact> objectFiles,
ImmutableMap<Artifact, Artifact> ltoBitcodeFiles,
ImmutableMap<Artifact, LtoBackendArtifacts> sharedNonLtoBackends,
- boolean allowArchiveTypeInAlwayslink) {
+ boolean allowArchiveTypeInAlwayslink,
+ boolean mustKeepDebug) {
String basename = libraryArtifact.getFilename();
switch (category) {
case ALWAYSLINK_STATIC_LIBRARY:
@@ -332,6 +346,7 @@ public abstract class LinkerInputs {
this.ltoBitcodeFiles =
(ltoBitcodeFiles == null) ? ImmutableMap.<Artifact, Artifact>of() : ltoBitcodeFiles;
this.sharedNonLtoBackends = sharedNonLtoBackends;
+ this.mustKeepDebug = mustKeepDebug;
}
@Override
@@ -402,6 +417,11 @@ public abstract class LinkerInputs {
public int hashCode() {
return libraryArtifact.hashCode();
}
+
+ @Override
+ public boolean isMustKeepDebug() {
+ return this.mustKeepDebug;
+ }
}
//////////////////////////////////////////////////////////////////////////////////////
@@ -467,7 +487,8 @@ public abstract class LinkerInputs {
/* objectFiles= */ null,
/* ltoBitcodeFiles= */ null,
/* sharedNonLtoBackends= */ null,
- /* allowArchiveTypeInAlwayslink= */ false);
+ /* allowArchiveTypeInAlwayslink= */ false,
+ /* mustKeepDebug= */ false);
}
public static LibraryToLink opaqueLibraryToLink(
@@ -479,7 +500,8 @@ public abstract class LinkerInputs {
/* objectFiles= */ null,
/* ltoBitcodeFiles= */ null,
/* sharedNonLtoBackends= */ null,
- /* allowArchiveTypeInAlwayslink= */ false);
+ /* allowArchiveTypeInAlwayslink= */ false,
+ /* mustKeepDebug= */ false);
}
public static LibraryToLink opaqueLibraryToLink(
@@ -488,7 +510,22 @@ public abstract class LinkerInputs {
String libraryIdentifier,
boolean allowArchiveTypeInAlwayslink) {
return new CompoundLibraryToLink(
- artifact, category, libraryIdentifier, null, null, null, allowArchiveTypeInAlwayslink);
+ artifact, category, libraryIdentifier, null, null, null, allowArchiveTypeInAlwayslink,
+ /* mustKeepDebug= */ false);
+ }
+
+ public static LibraryToLink opaqueLibraryToLink(
+ Artifact artifact, ArtifactCategory category, String libraryIdentifier,
+ CppConfiguration.StripMode stripMode) {
+ return new CompoundLibraryToLink(
+ artifact,
+ category,
+ libraryIdentifier,
+ /* objectFiles= */ null,
+ /* ltoBitcodeFiles= */ null,
+ /* sharedNonLtoBackends= */ null,
+ /* allowArchiveTypeInAlwayslink= */ false,
+ /* mustKeepDebug= */ stripMode == CppConfiguration.StripMode.NEVER);
}
/** Creates a library to link with the specified object files. */
@@ -501,7 +538,8 @@ public abstract class LinkerInputs {
ImmutableMap<Artifact, LtoBackendArtifacts> sharedNonLtoBackends) {
return new CompoundLibraryToLink(
library, category, libraryIdentifier, objectFiles, ltoBitcodeFiles, sharedNonLtoBackends,
- /* allowArchiveTypeInAlwayslink= */ false);
+ /* allowArchiveTypeInAlwayslink= */ false,
+ /* mustKeepDebug= */ false);
}
public static Iterable<Artifact> toNonSolibArtifacts(Iterable<LibraryToLink> libraries) {