From f32955474bb4428e2b2704846740d516103872c8 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Mon, 31 Jul 2023 11:03:13 -0700 Subject: [PATCH] Enable -dead_strip by default for opt builds This change makes `-dead_strip` always be enabled for `opt` builds, regardless of `--objc_enable_binary_stripping`. This should be the right default for everyone, if not we can look at adding a way to disable it. This also allows passing `--features=dead_strip` to enable `-dead_strip` in other configurations, which previously wasn't supported if you weren't using `opt`. --- crosstool/cc_toolchain_config.bzl | 12 ++++---- test/linking_tests.bzl | 48 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/crosstool/cc_toolchain_config.bzl b/crosstool/cc_toolchain_config.bzl index d01c81d..ccb997f 100644 --- a/crosstool/cc_toolchain_config.bzl +++ b/crosstool/cc_toolchain_config.bzl @@ -979,6 +979,11 @@ def _impl(ctx): ), ], ), + flag_set( + actions = _DYNAMIC_LINK_ACTIONS, + flag_groups = [flag_group(flags = ["-dead_strip"])], + with_features = [with_feature_set(features = ["opt"])], + ), ], ) @@ -1990,14 +1995,9 @@ def _impl(ctx): flag_sets = [ flag_set( actions = _DYNAMIC_LINK_ACTIONS, - flag_groups = [ - flag_group( - flags = ["-dead_strip"], - ), - ], + flag_groups = [flag_group(flags = ["-dead_strip"])], ), ], - requires = [feature_set(features = ["opt"])], ) oso_prefix_feature = feature( diff --git a/test/linking_tests.bzl b/test/linking_tests.bzl index 801c857..7644703 100644 --- a/test/linking_tests.bzl +++ b/test/linking_tests.bzl @@ -7,6 +7,21 @@ load( default_test = make_action_command_line_test_rule() +opt_test = make_action_command_line_test_rule( + config_settings = { + "//command_line_option:compilation_mode": "opt", + }, +) + +dead_strip_requested_test = make_action_command_line_test_rule( + config_settings = { + "//command_line_option:compilation_mode": "fastbuild", + "//command_line_option:features": [ + "dead_strip", + ], + }, +) + disable_objc_test = make_action_command_line_test_rule( config_settings = { "//command_line_option:features": [ @@ -26,6 +41,39 @@ def linking_test_suite(name): "2", "-ObjC", ], + not_expected_argv = [ + "-dead_strip", + ], + mnemonic = "ObjcLink", + target_under_test = "//test/test_data:apple_binary", + ) + + opt_test( + name = "{}_opt_link_test".format(name), + tags = [name], + expected_argv = [ + "-Xlinker", + "-objc_abi_version", + "-Xlinker", + "2", + "-ObjC", + "-dead_strip", + ], + mnemonic = "ObjcLink", + target_under_test = "//test/test_data:apple_binary", + ) + + dead_strip_requested_test( + name = "{}_dead_strip_requested_test".format(name), + tags = [name], + expected_argv = [ + "-Xlinker", + "-objc_abi_version", + "-Xlinker", + "2", + "-ObjC", + "-dead_strip", + ], mnemonic = "ObjcLink", target_under_test = "//test/test_data:apple_binary", )