diff options
author | 2016-12-22 08:48:05 +0000 | |
---|---|---|
committer | 2016-12-22 09:58:12 +0000 | |
commit | 5b6302405b2039f74e2259fa1829cdf7eee7f6ac (patch) | |
tree | 4588f4aa69da75fca3bb2598373a16e123d6af4d /src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java | |
parent | 5374d4fd8ee670b96fe39fe47b04b641c3587342 (diff) |
Move hardcoded toolchain linker flags to CROSSTOOL
This cl introduces another build variable: toolchain_flags and updates all the
affected crosstools (those which started using action_configs, because the
defaults from CppLinkActionConfigs are not applied then). This build variable
is a requirement for follow-up refactoring exposing param_files build variable.
With toolchain_flags and param_files we will have full control over flags
placement on the link command line.
--
PiperOrigin-RevId: 142741060
MOS_MIGRATED_REVID=142741060
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index 145088e321..6b5a6ec296 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -308,7 +308,7 @@ public final class LinkCommandLine extends CommandLine { } } - private void addToolchainFlags(List<String> argv) { + private ImmutableList<String> getToolchainFlags() { boolean fullyStatic = (linkStaticness == LinkStaticness.FULLY_STATIC); boolean mostlyStatic = (linkStaticness == LinkStaticness.MOSTLY_STATIC); boolean sharedLinkopts = @@ -316,6 +316,8 @@ public final class LinkCommandLine extends CommandLine { || linkopts.contains("-shared") || cppConfiguration.getLinkOptions().contains("-shared"); + List<String> toolchainFlags = new ArrayList<>(); + /* * For backwards compatibility, linkopts come _after_ inputFiles. * This is needed to allow linkopts to contain libraries and @@ -328,22 +330,22 @@ public final class LinkCommandLine extends CommandLine { * (global defaults, per-target linkopts, and command-line linkopts), * we have no idea what the right order should be, or if anyone cares. */ - argv.addAll(linkopts); + toolchainFlags.addAll(linkopts); // Extra toolchain link options based on the output's link staticness. if (fullyStatic) { - argv.addAll(cppConfiguration.getFullyStaticLinkOptions(features, sharedLinkopts)); + toolchainFlags.addAll(cppConfiguration.getFullyStaticLinkOptions(features, sharedLinkopts)); } else if (mostlyStatic) { - argv.addAll(cppConfiguration.getMostlyStaticLinkOptions(features, sharedLinkopts)); + toolchainFlags.addAll(cppConfiguration.getMostlyStaticLinkOptions(features, sharedLinkopts)); } else { - argv.addAll(cppConfiguration.getDynamicLinkOptions(features, sharedLinkopts)); + toolchainFlags.addAll(cppConfiguration.getDynamicLinkOptions(features, sharedLinkopts)); } // Extra test-specific link options. if (useTestOnlyFlags) { - argv.addAll(cppConfiguration.getTestOnlyLinkOptions()); + toolchainFlags.addAll(cppConfiguration.getTestOnlyLinkOptions()); } - argv.addAll(cppConfiguration.getLinkOptions()); + toolchainFlags.addAll(cppConfiguration.getLinkOptions()); // -pie is not compatible with shared and should be // removed when the latter is part of the link command. Should we need to further @@ -351,13 +353,15 @@ public final class LinkCommandLine extends CommandLine { // command line / CROSSTOOL flags that distinguish them. But as long as this is // the only relevant use case we're just special-casing it here. if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY) { - Iterables.removeIf(argv, Predicates.equalTo("-pie")); + Iterables.removeIf(toolchainFlags, Predicates.equalTo("-pie")); } // Fission mode: debug info is in .dwo files instead of .o files. Inform the linker of this. if (linkTargetType.staticness() == Staticness.DYNAMIC && cppConfiguration.useFission()) { - argv.add("-Wl,--gdb-index"); + toolchainFlags.add("-Wl,--gdb-index"); } + + return ImmutableList.copyOf(toolchainFlags); } /** @@ -375,14 +379,26 @@ public final class LinkCommandLine extends CommandLine { switch (linkTargetType) { case EXECUTABLE: argv.add(cppConfiguration.getCppExecutable().getPathString()); - argv.addAll(featureConfiguration.getCommandLine(actionName, variables)); - addToolchainFlags(argv); + argv.addAll( + featureConfiguration.getCommandLine( + actionName, + new Variables.Builder() + .addAll(variables) + .addStringSequenceVariable( + CppLinkActionBuilder.TOOLCHAIN_FLAGS_VARIABLE, getToolchainFlags()) + .build())); break; case DYNAMIC_LIBRARY: argv.add(toolPath); - argv.addAll(featureConfiguration.getCommandLine(actionName, variables)); - addToolchainFlags(argv); + argv.addAll( + featureConfiguration.getCommandLine( + actionName, + new Variables.Builder() + .addAll(variables) + .addStringSequenceVariable( + CppLinkActionBuilder.TOOLCHAIN_FLAGS_VARIABLE, getToolchainFlags()) + .build())); break; case STATIC_LIBRARY: |