From ec5553352f2f661d39ac4cf665dd9b3c779e614c Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 15 Jan 2021 07:16:11 -0800 Subject: [PATCH] Remove support for "nodeps" dynamic libraries on Apple platforms. Any such usage was only accidentally working due to -undefined dynamic_lookup. That flag only works on Darwin (macOS) at all. But even there, TLS can cause undefined symbols with these "nodeps" libraries. Fundamentally, Mach-O's two-level namespacing makes this infeasible. https://github.com/bazelbuild/bazel/issues/4341 Closes #4341. PiperOrigin-RevId: 352002776 --- src/test/shell/bazel/cc_integration_test.sh | 8 ++++++++ .../bazel/tags_propagation_native_test.sh | 18 ++++++++++-------- .../shell/integration/configured_query_test.sh | 2 ++ tools/cpp/cc_toolchain_config.bzl | 1 - tools/osx/crosstool/cc_toolchain_config.bzl | 3 --- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/test/shell/bazel/cc_integration_test.sh b/src/test/shell/bazel/cc_integration_test.sh index 7b9756ae423d2c..f08a91b58ff9e7 100755 --- a/src/test/shell/bazel/cc_integration_test.sh +++ b/src/test/shell/bazel/cc_integration_test.sh @@ -660,6 +660,10 @@ EOF } function test_aspect_accessing_args_link_action_with_tree_artifact() { + # This test assumes the presence of "nodeps" dynamic libraries, which do not + # function on Apple platforms. + [ "$PLATFORM" != "darwin" ] || return 0 + local package="${FUNCNAME[0]}" mkdir -p "${package}" cat > "${package}/makes_tree_artifacts.sh" < output1 2> $TEST_log \ - || fail "should have generated output successfully" - - assert_contains "ExecutionInfo: {" output1 - assert_contains "local:" output1 - assert_contains "no-cache:" output1 - assert_contains "no-remote:" output1 + if [ "${PLATFORM}" != "darwin" ]; then + # Darwin does not support implicit "nodeps" shared libraries. + bazel aquery --experimental_allow_tags_propagation 'mnemonic("CppLink", outputs(".*/libtest.so", //test:test))' > output1 2> $TEST_log \ + || fail "should have generated output successfully" + + assert_contains "ExecutionInfo: {" output1 + assert_contains "local:" output1 + assert_contains "no-cache:" output1 + assert_contains "no-remote:" output1 + fi } function test_cc_binary_tags_propagated() { diff --git a/src/test/shell/integration/configured_query_test.sh b/src/test/shell/integration/configured_query_test.sh index 128a270097609b..7c716d6d461c29 100755 --- a/src/test/shell/integration/configured_query_test.sh +++ b/src/test/shell/integration/configured_query_test.sh @@ -1122,6 +1122,8 @@ EOF if "$is_windows"; then assert_contains "cclib.lib" output + elif is_darwin; then + assert_contains "libcclib.a" output else assert_contains "libcclib.a" output assert_contains "libcclib.so" output diff --git a/tools/cpp/cc_toolchain_config.bzl b/tools/cpp/cc_toolchain_config.bzl index f4748365fd3c0a..807e769ae8dafc 100644 --- a/tools/cpp/cc_toolchain_config.bzl +++ b/tools/cpp/cc_toolchain_config.bzl @@ -1159,7 +1159,6 @@ def _impl(ctx): features = [ default_compile_flags_feature, default_link_flags_feature, - supports_dynamic_linker_feature, supports_pic_feature, objcopy_embed_flags_feature, dbg_feature, diff --git a/tools/osx/crosstool/cc_toolchain_config.bzl b/tools/osx/crosstool/cc_toolchain_config.bzl index 21eac5aa09ac4a..79616b2062522e 100644 --- a/tools/osx/crosstool/cc_toolchain_config.bzl +++ b/tools/osx/crosstool/cc_toolchain_config.bzl @@ -4734,8 +4734,6 @@ def _impl(ctx): ], ) - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - objc_actions_feature = feature( name = "objc_actions", implies = [ @@ -6243,7 +6241,6 @@ def _impl(ctx): linker_param_file_feature, compiler_input_flags_feature, compiler_output_flags_feature, - supports_dynamic_linker_feature, objcopy_embed_flags_feature, dynamic_linking_mode_feature, set_install_name,