aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-04-30 14:41:48 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-30 14:43:48 -0700
commit3fbe733bf72659e9de30fb099a65e87b1a402a18 (patch)
tree48da16e749f0ef9fbe2eac1f9eecaebf407e3c47 /src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java
parentc1fa95a7b7f854c584974ec89475d0ee2b1e579a (diff)
Consolidating start/end lib archive expansion Take 2
Different places in the link logic were in charge of expanding start/end lib archives, causing discrepancies. This CL gets rid of the special iteration in Link.java and makes LibrariesToLinkCollecter solely responsible for mapping static libraries to their object files on the link command l... RELNOTES: Fixing start/end lib expansion for linking. There were many cases where archive files were still being used with toolchains that support start/end lib. This change consolidates the places that make that decision so they can be more consistent. PiperOrigin-RevId: 194847987
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java126
1 files changed, 0 insertions, 126 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java
index 74142be962..30cdbbe7dd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java
@@ -14,13 +14,7 @@
package com.google.devtools.build.lib.rules.cpp;
-import com.google.common.collect.AbstractIterator;
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.collect.CollectionUtils;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
import com.google.devtools.build.lib.util.FileTypeSet;
-import java.util.Iterator;
/**
* Utility types and methods for generating command lines for the linker, given
@@ -295,124 +289,4 @@ public abstract class Link {
|| linkerInput.getArtifactCategory() == ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY)
&& linkerInput.containsObjectFiles();
}
-
- /**
- * Replace always used archives with its members. This is used to build the linker cmd line.
- */
- public static Iterable<LinkerInput> mergeInputsCmdLine(NestedSet<LibraryToLink> inputs,
- boolean globalNeedWholeArchive, ArchiveType archiveType) {
- return new FilterMembersForLinkIterable(inputs, globalNeedWholeArchive, archiveType, false);
- }
-
- /**
- * Add in any object files which are implicitly named as inputs by the linker.
- */
- public static Iterable<LinkerInput> mergeInputsDependencies(NestedSet<LibraryToLink> inputs,
- boolean globalNeedWholeArchive, ArchiveType archiveType) {
- return new FilterMembersForLinkIterable(inputs, globalNeedWholeArchive, archiveType, true);
- }
-
- /**
- * On the fly implementation to filter the members.
- */
- private static final class FilterMembersForLinkIterable implements Iterable<LinkerInput> {
- private final boolean globalNeedWholeArchive;
- private final ArchiveType archiveType;
- private final boolean deps;
-
- private final Iterable<LibraryToLink> inputs;
-
- private FilterMembersForLinkIterable(Iterable<LibraryToLink> inputs,
- boolean globalNeedWholeArchive, ArchiveType archiveType, boolean deps) {
- this.globalNeedWholeArchive = globalNeedWholeArchive;
- this.archiveType = archiveType;
- this.deps = deps;
- this.inputs = CollectionUtils.makeImmutable(inputs);
- }
-
- @Override
- public Iterator<LinkerInput> iterator() {
- return new FilterMembersForLinkIterator(inputs.iterator(), globalNeedWholeArchive,
- archiveType, deps);
- }
- }
-
- /**
- * On the fly implementation to filter the members.
- */
- private static final class FilterMembersForLinkIterator extends AbstractIterator<LinkerInput> {
- private final boolean globalNeedWholeArchive;
- private final ArchiveType archiveType;
- private final boolean deps;
-
- private final Iterator<LibraryToLink> inputs;
- private Iterator<LinkerInput> delayList = ImmutableList.<LinkerInput>of().iterator();
-
- private FilterMembersForLinkIterator(Iterator<LibraryToLink> inputs,
- boolean globalNeedWholeArchive, ArchiveType archiveType, boolean deps) {
- this.globalNeedWholeArchive = globalNeedWholeArchive;
- this.archiveType = archiveType;
- this.deps = deps;
- this.inputs = inputs;
- }
-
- @Override
- protected LinkerInput computeNext() {
- if (delayList.hasNext()) {
- return delayList.next();
- }
-
- while (inputs.hasNext()) {
- LibraryToLink inputLibrary = inputs.next();
-
- // True if the linker might use the members of this file, i.e., if the file is a thin or
- // start_end_lib archive (aka static library). Also check if the library contains object
- // files - otherwise getObjectFiles returns null, which would lead to an NPE in
- // simpleLinkerInputs.
- boolean needMembersForLink = archiveType != ArchiveType.REGULAR
- && (inputLibrary.getArtifactCategory() == ArtifactCategory.STATIC_LIBRARY
- || inputLibrary.getArtifactCategory() == ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY)
- && inputLibrary.containsObjectFiles();
-
- // True if we will pass the members instead of the original archive.
- boolean passMembersToLinkCmd = needMembersForLink && (globalNeedWholeArchive
- || inputLibrary.getArtifactCategory() == ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY);
-
- // If deps is false (when computing the inputs to be passed on the command line), then it's
- // an if-then-else, i.e., the passMembersToLinkCmd flag decides whether to pass the object
- // files or the archive itself. This flag in turn is based on whether the archives are fat
- // or not (thin archives or start_end_lib) - we never expand fat archives, but we do expand
- // non-fat archives if we need whole-archives for the entire link, or for the specific
- // library (i.e., if alwayslink=1).
- //
- // If deps is true (when computing the inputs to be passed to the action as inputs), then it
- // becomes more complicated. We always need to pass the members for thin and start_end_lib
- // archives (needMembersForLink). And we _also_ need to pass the archive file itself unless
- // it's a start_end_lib archive (unless it's an alwayslink library).
-
- // A note about ordering: the order in which the object files and the library are returned
- // does not currently matter - this code results in the library returned first, and the
- // object files returned after, but only if both are returned, which can only happen if
- // deps is true, in which case this code only computes the list of inputs for the link
- // action (so the order isn't critical).
- if (passMembersToLinkCmd || (deps && needMembersForLink)) {
- delayList =
- LinkerInputs.simpleLinkerInputs(
- inputLibrary.getObjectFiles(),
- ArtifactCategory.OBJECT_FILE,
- /* disableWholeArchive= */ false)
- .iterator();
- }
-
- if (!(passMembersToLinkCmd || (deps && useStartEndLib(inputLibrary, archiveType)))) {
- return inputLibrary;
- }
-
- if (delayList.hasNext()) {
- return delayList.next();
- }
- }
- return endOfData();
- }
- }
}