Add macOS ThinLTO arguments#748
Open
dzbarsky wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
thin_ltofeature 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_ltotreats a ThinLTO path as a directory and generates0.<arch>.lto.o; rules_cc requiresthinlto_merged_object_fileto be an exact declared output consumed by the final link.This PR is based directly on
main. It overlaps thecc_featuregolden-test helper and the ThinLTOselectstructure 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.