Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cc/private/link/cc_linking_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,12 @@ def _maybe_do_lto_indexing(*, link_type, linking_mode, compilation_outputs, libr
has_lto_bitcode_inputs = lto_compilation_context.lto_bitcode_inputs

# TODO(b/338618120): deduplicate prefer_static_lib, prefer_pic_libs computed in finalize_link_action as well
prefer_static_libs = linking_mode == LINKING_MODE.STATIC or \
not feature_configuration.is_enabled("supports_dynamic_linker")
# supports_dynamic_library_deps is the intended feature for controlling
# whether dynamic libraries can be consumed as deps. Fall back to
# supports_dynamic_linker for toolchains that haven't adopted the new feature.
supports_dynamic_deps = feature_configuration.is_enabled("supports_dynamic_library_deps") or \
feature_configuration.is_enabled("supports_dynamic_linker")
prefer_static_libs = linking_mode == LINKING_MODE.STATIC or not supports_dynamic_deps
prefer_pic_libs = is_dynamic_library(link_type)

static_libraries_to_link = []
Expand Down
8 changes: 6 additions & 2 deletions cc/private/link/finalize_link_action.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ def finalize_link_action(
feature_configuration.is_enabled("supports_start_end_lib"))

# TODO(b/338618120): deduplicate prefer_static_lib, prefer_pic_libs
prefer_static_libs = linking_mode == LINKING_MODE.STATIC or \
not feature_configuration.is_enabled("supports_dynamic_linker")
# supports_dynamic_library_deps is the intended feature for controlling
# whether dynamic libraries can be consumed as deps. Fall back to
# supports_dynamic_linker for toolchains that haven't adopted the new feature.
supports_dynamic_deps = feature_configuration.is_enabled("supports_dynamic_library_deps") or \
feature_configuration.is_enabled("supports_dynamic_linker")
prefer_static_libs = linking_mode == LINKING_MODE.STATIC or not supports_dynamic_deps

# TODO(b/412540147): We select PIC libraries iff creating a dynamic library. Match PIC flags.
prefer_pic_libs = is_dynamic_library(link_type)
Expand Down
3 changes: 3 additions & 0 deletions cc/private/toolchain/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ def _impl(ctx):
)

supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
supports_dynamic_library_deps_feature = feature(name = "supports_dynamic_library_deps", enabled = True)

user_compile_flags_feature = feature(
name = "user_compile_flags",
Expand Down Expand Up @@ -1885,6 +1886,7 @@ def _impl(ctx):
static_libgcc_feature,
fdo_optimize_feature,
supports_dynamic_linker_feature,
supports_dynamic_library_deps_feature,
fastbuild_feature,
dbg_feature,
opt_feature,
Expand Down Expand Up @@ -1947,6 +1949,7 @@ def _impl(ctx):
unfiltered_compile_flags_feature,
treat_warnings_as_errors_feature,
archive_param_file_feature,
supports_dynamic_library_deps_feature,
generate_linkmap_feature,
no_dotd_file_feature,
] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = True)
Expand Down
4 changes: 4 additions & 0 deletions cc/toolchains/capabilities/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ cc_tool_capability(
name = "supports_dynamic_linker",
)

cc_tool_capability(
name = "supports_dynamic_library_deps",
)

cc_tool_capability(
name = "supports_pic",
)
6 changes: 6 additions & 0 deletions tests/cc/testutil/toolchains/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ _supports_dynamic_linker_feature = feature(
enabled = True,
)

_supports_dynamic_library_deps_feature = feature(
name = FEATURE_NAMES.supports_dynamic_library_deps,
enabled = True,
)

_shorten_virtual_includes_feature = feature(
name = FEATURE_NAMES.shorten_virtual_includes,
enabled = True,
Expand Down Expand Up @@ -1290,6 +1295,7 @@ _feature_name_to_feature = {
FEATURE_NAMES.no_legacy_features: _no_legacy_features_feature,
FEATURE_NAMES.do_not_split_linking_cmdline: _do_not_split_linking_cmdline_feature,
FEATURE_NAMES.supports_dynamic_linker: _supports_dynamic_linker_feature,
FEATURE_NAMES.supports_dynamic_library_deps: _supports_dynamic_library_deps_feature,
FEATURE_NAMES.supports_interface_shared_libraries: _supports_interface_shared_libraries_feature,
FEATURE_NAMES.pic: _pic_feature,
FEATURE_NAMES.define_with_space: _define_with_space,
Expand Down
1 change: 1 addition & 0 deletions tests/cc/testutil/toolchains/features.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FEATURE_NAMES = struct(
no_legacy_features = "no_legacy_features",
do_not_split_linking_cmdline = "do_not_split_linking_cmdline",
supports_dynamic_linker = "supports_dynamic_linker",
supports_dynamic_library_deps = "supports_dynamic_library_deps",
supports_interface_shared_libraries = "supports_interface_shared_libraries",
pic = "pic",
define_with_space = "define_with_space",
Expand Down