diff options
author | hlopko <hlopko@google.com> | 2018-03-01 13:17:23 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-01 13:19:47 -0800 |
commit | dad2276e54f504b4e9ee0107e845b838d0a9b956 (patch) | |
tree | 997caeaede0460026d2b3279133197cd3f157928 /src/main/java | |
parent | 4b6c0ec4b54e258763ce22e1a7f529d293aff026 (diff) |
Introduce a specific action_config for linking nodeps dynamic libraries
With this cl toolchain author can specify different flags for linking shared
library produced by cc_library and a shared library produced by cc_binary.
This is what is needed to remove linking_mode_flags - MOSTLY_STATIC_LIBRARIES
from the crosstool. What this linking mode was used for was to separate when we
link transitive shared library from cc_binary and when we link this
little-and-not-really-useful-outside-of-bazel nodeps shared library in cc_library.
RELNOTES: CcToolchain: Introduced action_config for "c++-link-transitive-dynamic-library"
PiperOrigin-RevId: 187523334
Diffstat (limited to 'src/main/java')
7 files changed, 73 insertions, 20 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index ac9abc2321..b69bd74300 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -125,6 +125,7 @@ public final class CcCommon { // differently named outputs. Link.LinkTargetType.PIC_STATIC_LIBRARY.getActionName(), Link.LinkTargetType.INTERFACE_DYNAMIC_LIBRARY.getActionName(), + Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName(), Link.LinkTargetType.DYNAMIC_LIBRARY.getActionName(), Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY.getActionName(), Link.LinkTargetType.ALWAYS_LINK_PIC_STATIC_LIBRARY.getActionName(), diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index 644feb2558..3463012abd 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -211,8 +211,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { if (!createDynamicLibrary && !supportsDynamicLinker) { ImmutableList.Builder<Artifact> dynamicLibraries = ImmutableList.builder(); dynamicLibraries.add( - CppHelper.getLinuxLinkedArtifact( - ruleContext, ruleContext.getConfiguration(), LinkTargetType.DYNAMIC_LIBRARY)); + CppHelper.getLinuxLinkedArtifact( + ruleContext, ruleContext.getConfiguration(), LinkTargetType.NODEPS_DYNAMIC_LIBRARY)); if (CppHelper.useInterfaceSharedObjects(ccToolchain.getCppConfiguration(), ccToolchain)) { dynamicLibraries.add( CppHelper.getLinuxLinkedArtifact( @@ -229,8 +229,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { // a "no generating action for this artifact" error. ImmutableList.Builder<Artifact> dynamicLibraries = ImmutableList.builder(); dynamicLibraries.add( - CppHelper.getLinuxLinkedArtifact( - ruleContext, ruleContext.getConfiguration(), LinkTargetType.DYNAMIC_LIBRARY)); + CppHelper.getLinuxLinkedArtifact( + ruleContext, ruleContext.getConfiguration(), LinkTargetType.NODEPS_DYNAMIC_LIBRARY)); if (CppHelper.useInterfaceSharedObjects(ccToolchain.getCppConfiguration(), ccToolchain)) { dynamicLibraries.add( CppHelper.getLinuxLinkedArtifact( diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index 24a8c5c69f..c9356c80f8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java @@ -587,7 +587,7 @@ public final class CcLinkingHelper { CppHelper.getLinuxLinkedArtifact( ruleContext, configuration, - Link.LinkTargetType.DYNAMIC_LIBRARY, + Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY, linkedArtifactNameSuffix)); if (CppHelper.useInterfaceSharedObjects(ccToolchain.getCppConfiguration(), ccToolchain) @@ -819,7 +819,7 @@ public final class CcLinkingHelper { if (dynamicLibrary == null) { // If the crosstool is configured to select an output artifact, we use that selection. // Otherwise, we use linux defaults. - soImpl = getLinkedArtifact(LinkTargetType.DYNAMIC_LIBRARY); + soImpl = getLinkedArtifact(LinkTargetType.NODEPS_DYNAMIC_LIBRARY); mainLibraryIdentifier = libraryIdentifier; } else { // This branch is only used for vestigial Google-internal rules where the name of the output @@ -857,7 +857,7 @@ public final class CcLinkingHelper { .addObjectFiles(ccOutputs.getObjectFiles(usePicForSharedLibs)) .addNonCodeInputs(ccOutputs.getHeaderTokenFiles()) .addLtoBitcodeFiles(ccOutputs.getLtoBitcodeFiles()) - .setLinkType(LinkTargetType.DYNAMIC_LIBRARY) + .setLinkType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY) .setLinkStaticness(LinkStaticness.DYNAMIC) .addActionInputs(linkActionInputs) .setLibraryIdentifier(mainLibraryIdentifier) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java index 0ed940b78b..dd39fe24c3 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java @@ -49,6 +49,7 @@ public class CppActionConfigs { + " name: 'dynamic_library_linker_tool'" + " flag_set {" + " action: 'c++-link-dynamic-library'" + + " action: 'c++-link-nodeps-dynamic-library'" + " flag_group {" + " flag: '" + cppLinkDynamicLibraryToolPath @@ -370,6 +371,7 @@ public class CppActionConfigs { " action: 'c++-compile'", " action: 'c++-link-interface-dynamic-library'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-executable'", " flag_group {", " flag: '-fprofile-generate=%{fdo_instrument_path}'", @@ -444,6 +446,29 @@ public class CppActionConfigs { " implies: 'sysroot'", "}", "action_config {", + " config_name: 'c++-link-nodeps-dynamic-library'", + " action_name: 'c++-link-nodeps-dynamic-library'", + " tool {", + " tool_path: '" + gccToolPath + "'", + " }", + ifTrue( + supportsInterfaceSharedLibraries, + "implies: 'build_interface_libraries'", + "implies: 'dynamic_library_linker_tool'"), + " implies: 'symbol_counts'", + " implies: 'strip_debug_symbols'", + " implies: 'shared_flag'", + " implies: 'linkstamps'", + " implies: 'output_execpath_flags'", + " implies: 'runtime_library_search_directories'", + " implies: 'library_search_directories'", + " implies: 'libraries_to_link'", + " implies: 'legacy_link_flags'", + " implies: 'linker_param_file'", + " implies: 'fission_support'", + " implies: 'sysroot'", + "}", + "action_config {", " config_name: 'c++-link-dynamic-library'", " action_name: 'c++-link-dynamic-library'", " tool {", @@ -509,6 +534,7 @@ public class CppActionConfigs { " flag_set {", " expand_if_all_available: 'generate_interface_library'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " flag: '%{generate_interface_library}'", " flag: '%{interface_library_builder_path}'", @@ -528,6 +554,7 @@ public class CppActionConfigs { " expand_if_all_available: 'symbol_counts_output'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " flag: '-Wl,--print-symbol-counts=%{symbol_counts_output}'", " }", @@ -539,6 +566,7 @@ public class CppActionConfigs { " name: 'shared_flag'", " flag_set {", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " flag: '-shared'", " }", @@ -551,6 +579,7 @@ public class CppActionConfigs { " flag_set {", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " expand_if_all_available: 'linkstamp_paths'", " flag_group {", " iterate_over: 'linkstamp_paths'", @@ -565,6 +594,7 @@ public class CppActionConfigs { " flag_set {", " expand_if_all_available: 'output_execpath'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-executable'", " flag_group {", " flag: '-o'", @@ -580,6 +610,7 @@ public class CppActionConfigs { " expand_if_all_available: 'runtime_library_search_directories'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " iterate_over: 'runtime_library_search_directories'", " flag_group {", @@ -611,6 +642,7 @@ public class CppActionConfigs { " expand_if_all_available: 'library_search_directories'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " iterate_over: 'library_search_directories'", " flag: '-L%{library_search_directories}'", @@ -671,6 +703,7 @@ public class CppActionConfigs { " expand_if_all_available: 'libraries_to_link'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " iterate_over: 'libraries_to_link'", " flag_group {", @@ -840,6 +873,7 @@ public class CppActionConfigs { " expand_if_all_available: 'legacy_link_flags'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " iterate_over: 'legacy_link_flags'", " flag: '%{legacy_link_flags}'", @@ -853,6 +887,7 @@ public class CppActionConfigs { " flag_set {", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-interface-dynamic-library'", " flag_group {", " expand_if_all_available: 'is_using_fission'", @@ -867,6 +902,7 @@ public class CppActionConfigs { " flag_set {", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-interface-dynamic-library'", " flag_group {", " expand_if_all_available: 'strip_debug_symbols'", @@ -897,6 +933,7 @@ public class CppActionConfigs { " flag_set {", " action: 'c++-link-interface-dynamic-library'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-executable'", " action: 'objc-executable'", " action: 'objc++-executable'", @@ -929,6 +966,7 @@ public class CppActionConfigs { " flag_set {", " action: 'c++-link-interface-dynamic-library'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'c++-link-executable'", " flag_group {", " flag: '-lgcov'", @@ -1026,6 +1064,7 @@ public class CppActionConfigs { " action: 'c++-module-compile'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " action: 'clif-match'", " action: 'lto-backend'", " flag_group {", @@ -1070,6 +1109,7 @@ public class CppActionConfigs { " expand_if_all_available: 'linker_param_file'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", + " action: 'c++-link-nodeps-dynamic-library'", " flag_group {", " flag: '-Wl,@%{linker_param_file}'", " }", 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 6a0ce57f52..79edac28a8 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 @@ -715,6 +715,7 @@ public class CppLinkActionBuilder { // That was probably an unintended side effect of the change that introduced interface // outputs. // On Windows, We can always split the command line when building DLL. + case NODEPS_DYNAMIC_LIBRARY: case DYNAMIC_LIBRARY: return (interfaceOutput == null || featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)); @@ -801,7 +802,7 @@ public class CppLinkActionBuilder { final ImmutableMap<Linkstamp, Artifact> linkstampMap = mapLinkstampsToOutputs(linkstamps, ruleContext, configuration, output, linkArtifactFactory); - if (interfaceOutput != null && (fake || linkType != LinkTargetType.DYNAMIC_LIBRARY)) { + if (interfaceOutput != null && (fake || !linkType.isDynamicLibrary())) { throw new RuntimeException( "Interface output can only be used " + "with non-fake DYNAMIC_LIBRARY targets"); } @@ -1022,7 +1023,7 @@ public class CppLinkActionBuilder { Preconditions.checkArgument( linkType != LinkTargetType.INTERFACE_DYNAMIC_LIBRARY, "you can't link an interface dynamic library directly"); - if (linkType != LinkTargetType.DYNAMIC_LIBRARY) { + if (!linkType.isDynamicLibrary()) { Preconditions.checkArgument( interfaceOutput == null, "interface output may only be non-null for dynamic library links"); @@ -1219,7 +1220,7 @@ public class CppLinkActionBuilder { CppHelper.getFdoBuildStamp(ruleContext, fdoSupport.getFdoSupport()), featureConfiguration, cppConfiguration.forcePic() - || (linkType == LinkTargetType.DYNAMIC_LIBRARY + || (linkType.isDynamicLibrary() && toolchain.toolchainNeedsPic()), Matcher.quoteReplacement( isNativeDeps && cppConfiguration.shareNativeDeps() @@ -1260,7 +1261,7 @@ public class CppLinkActionBuilder { } private boolean shouldUseLinkDynamicLibraryTool() { - return linkType.equals(LinkTargetType.DYNAMIC_LIBRARY) + return linkType.isDynamicLibrary() && toolchain.supportsInterfaceSharedObjects() && !featureConfiguration.hasConfiguredLinkerPathInActionConfig(); } @@ -1275,9 +1276,7 @@ public class CppLinkActionBuilder { boolean fullyStatic = (staticness == LinkStaticness.FULLY_STATIC); boolean mostlyStatic = (staticness == LinkStaticness.MOSTLY_STATIC); boolean sharedLinkopts = - type == LinkTargetType.DYNAMIC_LIBRARY - || linkopts.contains("-shared") - || cppConfig.hasSharedLinkOption(); + type.isDynamicLibrary() || linkopts.contains("-shared") || cppConfig.hasSharedLinkOption(); return (isNativeDeps || cppConfig.legacyWholeArchive()) && (fullyStatic || mostlyStatic) && sharedLinkopts; @@ -1393,10 +1392,10 @@ public class CppLinkActionBuilder { } return this; } - + /** * Sets the interface output of the link. A non-null argument can only be provided if the link - * type is {@code DYNAMIC_LIBRARY} and fake is false. + * type is {@code NODEPS_DYNAMIC_LIBRARY} and fake is false. */ public CppLinkActionBuilder setInterfaceOutput(Artifact interfaceOutput) { this.interfaceOutput = interfaceOutput; @@ -1906,7 +1905,7 @@ public class CppLinkActionBuilder { String runtimeSolibName = runtimeSolibDir != null ? runtimeSolibDir.getBaseName() : null; boolean runtimeRpath = runtimeSolibDir != null - && (linkType == LinkTargetType.DYNAMIC_LIBRARY + && (linkType.isDynamicLibrary() || (linkType == LinkTargetType.EXECUTABLE && linkStaticness == LinkStaticness.DYNAMIC)); 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 d159b7db13..852e28e8b5 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 @@ -166,12 +166,20 @@ public abstract class Link { ArtifactCategory.INTERFACE_LIBRARY, Executable.NOT_EXECUTABLE), - /** A dynamic library. */ + /** A dynamic library built from cc_library srcs. */ + NODEPS_DYNAMIC_LIBRARY( + ".so", + Staticness.DYNAMIC, + "c++-link-nodeps-dynamic-library", + Picness.NOPIC, // Actually PIC but it's not indicated in the file name + ArtifactCategory.DYNAMIC_LIBRARY, + Executable.NOT_EXECUTABLE), + /** A transitive dynamic library used for distribution. */ DYNAMIC_LIBRARY( ".so", Staticness.DYNAMIC, "c++-link-dynamic-library", - Picness.NOPIC, // Actually PIC but it's not indicated in the file name + Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.DYNAMIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -256,6 +264,11 @@ public abstract class Link { public boolean isExecutable() { return (executable == Executable.EXECUTABLE); } + + /** Returns true iff this link type is a dynamic library or transitive dynamic library */ + public boolean isDynamicLibrary() { + return this == NODEPS_DYNAMIC_LIBRARY || this == DYNAMIC_LIBRARY; + } } /** 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 389176cf0e..005c212084 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 @@ -350,7 +350,7 @@ public final class LinkCommandLine extends CommandLine { } } } - + /** * Returns a raw link command for the given link invocation, including both command and arguments * (argv). The version that uses the expander is preferred, but that one can't be used during |