Skip to content

Pass fission flags to ThinLTO backend actions - #837

Open
akonradi wants to merge 2 commits into
bazelbuild:mainfrom
akonradi:abakon/fission-flags-for-lto-backend
Open

Pass fission flags to ThinLTO backend actions#837
akonradi wants to merge 2 commits into
bazelbuild:mainfrom
akonradi:abakon/fission-flags-for-lto-backend

Conversation

@akonradi

@akonradi akonradi commented Aug 3, 2026

Copy link
Copy Markdown

Fix interaction between --fission and --features=thin_lto. Without this, every LTO backend action fails:

ERROR: output 'prog.lto/bazel-out/k8-opt/bin/_objs/prog/a.dwo' was not created
ERROR: LTO Backend Compile prog.lto/bazel-out/k8-opt/bin/_objs/prog/a.o failed:
       not all outputs were created or valid

Fixed by adding ACTION_NAMES.lto_backend to the per_object_debug_info flag_set in
cc/private/toolchain/unix_cc_toolchain_config.bzl and cc/private/toolchain_config/legacy_features.bzl.

Adds a test that uses the real Linux cc_toolchain_config since that wasn't covered by the existing test, and was broken.

@google-cla

google-cla Bot commented Aug 3, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@trybka

trybka commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

I think you need to complete the Google CLA, but otherwise I think this looks good.

With --fission enabled, a .dwo output is declared for every LTO backend
action, but the default Unix toolchain config never passes -gsplit-dwarf
to that action, so the output can never be written and --fission
combined with --features=thin_lto fails at execution time with

  output '<target>.lto/.../foo.dwo' was not created

This test documents the current behaviour: it asserts that the .dwo is
declared and that -gsplit-dwarf is absent. The following commit fixes
the toolchain configs and flips the assertion.

The existing ThinLTO fission coverage in
tests/cc/common/cc_binary_thin_lto_tests.bzl cannot catch this, because
the test toolchain in tests/cc/testutil/toolchains defines its own
fission_flags_for_lto_backend feature covering ACTION_NAMES.lto_backend.
Toolchains built on unix_cc_toolchain_config.bzl have no such feature,
so the gap can only be seen by testing against that config -- hence a
new linux toolchain registration in tests/default_unix_toolchain, which
so far registered only a macOS toolchain.

The "dwp" tool_paths entry is required: without it, cc_binary analysis
under --fission fails with a NoneType error out of
create_debug_packager_actions before any flag can be inspected.
cc/private/link/lto_backends.bzl declares <object>.dwo as an output of
each LTO backend action and binds both per_object_debug_info_file and
is_using_fission for it, but neither production toolchain config puts
-gsplit-dwarf on ACTION_NAMES.lto_backend. The declared output is
therefore never written and the action always fails:

  ERROR: output 'prog.lto/.../a.dwo' was not created
  ERROR: LTO Backend Compile prog.lto/.../a.o failed:
         not all outputs were created or valid

so --fission cannot be combined with --features=thin_lto at all.

Add ACTION_NAMES.lto_backend to the per_object_debug_info flag_set in
unix_cc_toolchain_config.bzl and legacy_features.bzl, and flip the
assertion added by the previous commit. The build variable the
flag_group gates on is already bound for that action, so no further
plumbing is needed.

Verified end to end outside the test suite with bazel 8.7.0 and clang
22.1.8 on a two-file cc_binary, --features=thin_lto --fission=yes
--features=per_object_debug_info and no --ltobackendopt: before, the
build fails as above; after, it succeeds and writes non-empty .dwo
files that llvm-dwp packs into a valid .dwp.
@akonradi
akonradi force-pushed the abakon/fission-flags-for-lto-backend branch from c43da3e to c033aba Compare August 3, 2026 16:00
@akonradi

akonradi commented Aug 3, 2026

Copy link
Copy Markdown
Author

Ha, it was the Claude co-author attribution. Removed and force-pushed, same contents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants