Skip to content

Add macOS ThinLTO arguments#748

Open
dzbarsky wants to merge 1 commit into
bazelbuild:mainfrom
dzbarsky:codex/macos-thinlto
Open

Add macOS ThinLTO arguments#748
dzbarsky wants to merge 1 commit into
bazelbuild:mainfrom
dzbarsky:codex/macos-thinlto

Conversation

@dzbarsky

Copy link
Copy Markdown
Contributor

The thin_lto feature currently sends GNU plugin options to every non-Windows linker. Mach-O LLD implements distributed ThinLTO with direct --thinlto-* options instead, so macOS indexing actions fail when they inherit the ELF spellings. This selects Mach-O LLD's direct indexing, imports, prefix replacement, suffix replacement, and merged-object options on macOS while preserving the existing arguments on other platforms.

The merged regular LTO object uses --lto-obj-path, which is proposed in llvm/llvm-project#203365. Mach-O LLD's existing -object_path_lto treats a ThinLTO path as a directory and generates 0.<arch>.lto.o; rules_cc requires thinlto_merged_object_file to be an exact declared output consumed by the final link.

This PR is based directly on main. It overlaps the cc_feature golden-test helper and the ThinLTO select structure in #747; whichever PR lands second will need a mechanical rebase.

Validation: bazel test //tests/rule_based_toolchain/legacy_features_as_args:thin_lto_macos_test --test_output=errors.

Mach-O LLD exposes distributed ThinLTO through direct --thinlto options
rather than the GNU plugin options used by ELF linkers. Select the
Mach-O LLD options for macOS indexing actions, including
--lto-obj-path for the declared regular LTO object output.

Add a macOS golden test for the complete thin_lto feature and extend the
legacy feature test helper to compare cc_feature targets.
dzbarsky added a commit to hermeticbuild/hermetic-llvm that referenced this pull request Jun 11, 2026
This adds distributed ThinLTO for macOS targets after #615. The existing
`windows-thin-lto.patch` remains unchanged, and the macOS rules_cc
changes are isolated in `macos-thin-lto.patch`, which is applied after
`windows-thin-lto.patch`. The macOS patch corresponds to
bazelbuild/rules_cc#748 and only adds Mach-O LLD's direct distributed
ThinLTO arguments.

The LLVM source patch adds the exact-file `--lto-obj-path` contract
proposed upstream in llvm/llvm-project#203365. The exact-file contract
lets the indexing action produce rules_cc's declared
`thinlto_merged_object_file` without reproducing Mach-O LLD's
`0.<arch>.lto.o` directory naming.

`is_windows_capable_of_thinlto_feature` and
`is_macos_capable_of_thinlto_feature` default to false and independently
control whether the toolchain exposes the rules_cc `thin_lto` feature on
Windows and macOS. `windows_capable_of_thinlto_feature` and
`macos_capable_of_thinlto_feature` combine the corresponding build
setting with the target OS constraint. `--config=prebuilt` enables both
build settings. `is_windows_capable_of_thinlto_feature` can be removed
after a rules_cc release contains Windows distributed ThinLTO support.
`is_macos_capable_of_thinlto_feature` can be removed after rules_cc and
LLVM releases contain macOS distributed ThinLTO support. The previous
macOS `-flto=thin` fallback is removed because rules_cc now creates
separate indexing and backend actions.

Validation:

- Applied `windows-thin-lto.patch` followed by `macos-thin-lto.patch` to
a clean rules_cc checkout and compared the resulting ThinLTO feature
with the rules_cc source.
- `bazel test
//tests/rule_based_toolchain/legacy_features_as_args:thin_lto_macos_test
--test_output=errors` in rules_cc.
- `bazel build --config=prebuilt --config=remote --config=bootstrap
//prebuilt/llvm:for_windows_amd64 //prebuilt/llvm:for_windows_arm64
//prebuilt/llvm:for_macos_amd64 //prebuilt/llvm:for_macos_arm64`.
- BuildBuddy invocation:
https://app.buildbuddy.io/invocation/ff484673-abb8-41c9-ba4c-a19410241625
@dzbarsky dzbarsky changed the title [codex] Add macOS ThinLTO arguments Add macOS ThinLTO arguments Jun 11, 2026
@dzbarsky dzbarsky marked this pull request as ready for review June 11, 2026 20:05
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.

1 participant