Skip to content

fix(cmake): don't pass -fno-fat-lto-objects on Apple GCC - #6114

Merged
rwgk merged 1 commit into
pybind:masterfrom
henryiii:fix/lto-macos-gcc
Jul 27, 2026
Merged

fix(cmake): don't pass -fno-fat-lto-objects on Apple GCC#6114
rwgk merged 1 commit into
pybind:masterfrom
henryiii:fix/lto-macos-gcc

Conversation

@henryiii

@henryiii henryiii commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

See #6112.

🤖 AI text below 🤖

Description

GCC on macOS has no linker plugin. -fno-fat-lto-objects needs one, so cc1plus fails with "-fno-fat-lto-objects are supported only with linker plugin". Because the LTO probe always adds this flag for non-MinGW GNU compilers, every probe (-flto=auto, -flto) fails and LTO is silently disabled, although plain -flto=auto works.

This change skips the flag when APPLE is set.

Verified with Homebrew g++-16 on macOS: before, HAS_FLTO_AUTO and HAS_FLTO both fail and pybind11::lto is disabled; after, HAS_FLTO_AUTO succeeds and pybind11::lto is enabled. The Apple Clang path is unchanged.

Fixes #6060

Suggested changelog entry:

  • Do not pass -fno-fat-lto-objects to GCC on macOS, which made all LTO probes fail and silently disabled LTO.

https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3

GCC on macOS has no linker plugin, so `-fno-fat-lto-objects` makes every
LTO probe fail and LTO is silently disabled. Plain `-flto=auto` works.

Fixes pybind#6060

Assisted-by: ClaudeCode:claude-opus-5
Claude-Session: https://claude.ai/code/session_013JABmnjt9oAh29p1pytAB3
@henryiii
henryiii marked this pull request as ready for review July 26, 2026 03:03
@rwgk
rwgk merged commit f4d31b7 into pybind:master Jul 27, 2026
98 checks passed
@rwgk
rwgk deleted the fix/lto-macos-gcc branch July 27, 2026 04:26
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Jul 27, 2026
@barracuda156

Copy link
Copy Markdown

@henryiii Thank you!

@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Aug 3, 2026
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.

[BUG]: Invalid flag unnecessarily forces FLTO test to fail with gcc on macOS

3 participants