-
Notifications
You must be signed in to change notification settings - Fork 22
Description
The hermetic C++ toolchain is currently using wrapper/clang for linking instead of the dedicated wrapper/ld script. As a result, all linker-related configuration in the toolchain is effectively ignored.
The root cause seems to be that action_configs are created but never passed to cc_common.create_cc_toolchain_config_info here:
rules_ml_toolchain/third_party/rules_cc_toolchain/toolchain_config.bzl
Lines 106 to 143 in aa27dbc
| def _cc_toolchain_config_impl(ctx): | |
| action_configs = [action_config( | |
| action_name = action, | |
| enabled = True, | |
| tools = [ | |
| tool(ctx.attr.tool_paths["ld"]), | |
| ], | |
| implies = [ | |
| ], | |
| ) for action in ACTION_NAME_GROUPS.all_cc_link_actions] | |
| return cc_common.create_cc_toolchain_config_info( | |
| ctx = ctx, | |
| host_system_name = "local", | |
| target_system_name = ctx.attr.target_system_name, | |
| target_cpu = ctx.attr.target_cpu, | |
| target_libc = ctx.attr.target_libc, | |
| artifact_name_patterns = _create_artifact_name_patterns(ctx), | |
| toolchain_identifier = "aarch64_linux_clang_id", | |
| compiler = "clang", | |
| abi_version = "unknown", | |
| abi_libc_version = "unknown", | |
| tool_paths = [ | |
| tool_path(name = name, path = path) | |
| for name, path in ctx.attr.tool_paths.items() | |
| ], | |
| features = [ | |
| label[FeatureInfo] | |
| for label in ctx.attr.compiler_features | |
| ] + [_label_to_tool_path_feature({ | |
| "gcc": ctx.file.c_compiler, | |
| "cpp": ctx.file.cc_compiler, | |
| "ld": ctx.file.linker, | |
| "ar": ctx.file.archiver, | |
| "strip": ctx.file.strip_tool, | |
| "in": ctx.file.install_name, | |
| })], | |
| ) |
Because action_configs are omitted from the create_cc_toolchain_config_info call, Bazel ends up invoking wrapper/clang for linking instead of wrapper/ld. This is why the toolchain currently needs the feature:
"//third_party/rules_cc_toolchain/features:use_lld",in order to get the expected linker behavior.
I tried wiring action_configs through to create_cc_toolchain_config_info locally, but then hit linker errors like undefined reference to _main in binaries where main is definitely defined. I did not track that regression down further.
This behavior also makes it harder to switch to a different linker (for example, mold) while keeping the rest of the toolchain the same.
If omitting action_configs in create_cc_toolchain_config_info was intentional, a short comment in the code would be very helpful. It would have saved me a significant amount of debugging time and will likely help others too.