aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-08-17 12:17:55 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-08-18 08:29:24 +0000
commitce5aefa74b1014990c91f75ae8bbfb9a8192cca0 (patch)
tree548b866b179b5b5d4b5fb14b3f604873b768326f
parent7415065fef78317ad294731b8636b6ed7d97f27f (diff)
Remove the awkward logic that used to look at the string form at a command line option to determine if it should be a whole archive one and use the artifact category in LinkerInput to make that decision instead.
-- MOS_MIGRATED_REVID=130508699
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java54
1 files changed, 31 insertions, 23 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 f5ae6fc6a1..15bde7883e 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
@@ -1250,6 +1250,15 @@ public class CppLinkActionBuilder {
return isNativeDeps && cppConfiguration.shareNativeDeps();
}
+ private boolean inputNeedsWholeArchive(LinkerInput input) {
+ if (Link.useStartEndLib(input, cppConfiguration.archiveType())) {
+ return false;
+ }
+
+ return input.getArtifactCategory() == ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY
+ && !wholeArchive && !needWholeArchive;
+ }
+
/**
* When linking a shared library fully or mostly static then we need to link in *all* dependent
* files, not just what the shared library needs for its own code. This is done by wrapping all
@@ -1264,9 +1273,6 @@ public class CppLinkActionBuilder {
// Used to collect -L and -Wl,-rpath options, ensuring that each used only once.
Set<String> libOpts = new LinkedHashSet<>();
- // List of command line parameters to link input files (either directly or using -l).
- List<String> linkerInputParameters = new ArrayList<>();
-
// List of command line parameters that need to be placed *outside* of
// --whole-archive ... --no-whole-archive.
List<String> noWholeArchiveInputs = new ArrayList<>();
@@ -1365,6 +1371,9 @@ public class CppLinkActionBuilder {
}
}
+ List<String> wholeArchiveInputParams = new ArrayList<>();
+ List<String> standardArchiveInputParams = new ArrayList<>();
+
for (LinkerInput input : linkerInputs) {
if (input.getArtifactCategory() == ArtifactCategory.DYNAMIC_LIBRARY) {
PathFragment libDir = input.getArtifact().getExecPath().getParentDirectory();
@@ -1376,16 +1385,19 @@ public class CppLinkActionBuilder {
if (libDir.equals(solibDir)) {
includeSolibDir = true;
}
- addDynamicInputLinkOptions(input, linkerInputParameters, libOpts, solibDir, rpathRoot);
+ addDynamicInputLinkOptions(
+ input, standardArchiveInputParams, libOpts, solibDir, rpathRoot);
} else {
- addStaticInputLinkOptions(input, linkerInputParameters, ltoMap);
+ addStaticInputLinkOptions(
+ input, wholeArchiveInputParams, standardArchiveInputParams, ltoMap);
}
}
boolean includeRuntimeSolibDir = false;
for (LinkerInput input : runtimeLinkerInputs) {
- List<String> optionsList = needWholeArchive ? noWholeArchiveInputs : linkerInputParameters;
+ List<String> optionsList = needWholeArchive
+ ? noWholeArchiveInputs : standardArchiveInputParams;
if (input.getArtifactCategory() == ArtifactCategory.DYNAMIC_LIBRARY) {
PathFragment libDir = input.getArtifact().getExecPath().getParentDirectory();
@@ -1397,7 +1409,10 @@ public class CppLinkActionBuilder {
includeRuntimeSolibDir = true;
addDynamicInputLinkOptions(input, optionsList, libOpts, solibDir, rpathRoot);
} else {
- addStaticInputLinkOptions(input, optionsList, ltoMap);
+ addStaticInputLinkOptions(input,
+ needWholeArchive ? noWholeArchiveInputs : wholeArchiveInputParams,
+ needWholeArchive ? noWholeArchiveInputs : standardArchiveInputParams,
+ ltoMap);
}
}
@@ -1411,18 +1426,8 @@ public class CppLinkActionBuilder {
linkArgCollector.setLibopts(libOpts);
- ImmutableList.Builder<String> wholeArchiveInputParams = ImmutableList.builder();
- ImmutableList.Builder<String> standardArchiveInputParams = ImmutableList.builder();
- for (String param : linkerInputParameters) {
- if (!wholeArchive && Link.LINK_LIBRARY_FILETYPES.matches(param) && !needWholeArchive) {
- wholeArchiveInputParams.add(param);
- } else {
- standardArchiveInputParams.add(param);
- }
- }
-
- linkArgCollector.setLinkerInputParams(standardArchiveInputParams.build());
- linkArgCollector.setWholeArchiveLinkerInputParams(wholeArchiveInputParams.build());
+ linkArgCollector.setLinkerInputParams(standardArchiveInputParams);
+ linkArgCollector.setWholeArchiveLinkerInputParams(wholeArchiveInputParams);
linkArgCollector.setNoWholeArchiveInputs(noWholeArchiveInputs);
if (ltoMap != null) {
@@ -1477,14 +1482,15 @@ public class CppLinkActionBuilder {
* be supplied for LTO final links.
*/
private void addStaticInputLinkOptions(
- LinkerInput input, List<String> options, @Nullable Map<Artifact, Artifact> ltoMap) {
+ LinkerInput input, List<String> wholeArchiveOptions, List<String> standardOptions,
+ @Nullable Map<Artifact, Artifact> ltoMap) {
Preconditions.checkState(!(input.getArtifactCategory() == ArtifactCategory.DYNAMIC_LIBRARY));
// start-lib/end-lib library: adds its input object files.
if (Link.useStartEndLib(input, cppConfiguration.archiveType())) {
Iterable<Artifact> archiveMembers = input.getObjectFiles();
if (!Iterables.isEmpty(archiveMembers)) {
- options.add("-Wl,--start-lib");
+ standardOptions.add("-Wl,--start-lib");
for (Artifact member : archiveMembers) {
if (ltoMap != null) {
Artifact backend = ltoMap.remove(member);
@@ -1497,11 +1503,13 @@ public class CppLinkActionBuilder {
}
}
- options.add(member.getExecPathString());
+ standardOptions.add(member.getExecPathString());
}
- options.add("-Wl,--end-lib");
+ standardOptions.add("-Wl,--end-lib");
}
} else {
+ List<String> options = inputNeedsWholeArchive(input)
+ ? wholeArchiveOptions : standardOptions;
// For anything else, add the input directly.
Artifact inputArtifact = input.getArtifact();