Skip to content

Commit

Permalink
Enable -dead_strip by default for opt builds
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
keith committed Jul 31, 2023
1 parent 9bfe15e commit f329554
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"])],
),
],
)

Expand Down Expand Up @@ -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(
Expand Down
48 changes: 48 additions & 0 deletions test/linking_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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",
)
Expand Down

0 comments on commit f329554

Please sign in to comment.