From ce5aefa74b1014990c91f75ae8bbfb9a8192cca0 Mon Sep 17 00:00:00 2001 From: Lukacs Berki Date: Wed, 17 Aug 2016 12:17:55 +0000 Subject: 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 --- .../build/lib/rules/cpp/CppLinkActionBuilder.java | 54 +++++++++++++--------- 1 file 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 libOpts = new LinkedHashSet<>(); - // List of command line parameters to link input files (either directly or using -l). - List linkerInputParameters = new ArrayList<>(); - // List of command line parameters that need to be placed *outside* of // --whole-archive ... --no-whole-archive. List noWholeArchiveInputs = new ArrayList<>(); @@ -1365,6 +1371,9 @@ public class CppLinkActionBuilder { } } + List wholeArchiveInputParams = new ArrayList<>(); + List 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 optionsList = needWholeArchive ? noWholeArchiveInputs : linkerInputParameters; + List 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 wholeArchiveInputParams = ImmutableList.builder(); - ImmutableList.Builder 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 options, @Nullable Map ltoMap) { + LinkerInput input, List wholeArchiveOptions, List standardOptions, + @Nullable Map 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 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 options = inputNeedsWholeArchive(input) + ? wholeArchiveOptions : standardOptions; // For anything else, add the input directly. Artifact inputArtifact = input.getArtifact(); -- cgit v1.2.3