Skip to content

Fix Xcode PCH redefinition warnings for clang's libc++ hardening mode#1076

Open
SRSaunders wants to merge 3 commits intoRobertBeckebans:masterfrom
SRSaunders:clang-hardening-fix
Open

Fix Xcode PCH redefinition warnings for clang's libc++ hardening mode#1076
SRSaunders wants to merge 3 commits intoRobertBeckebans:masterfrom
SRSaunders:clang-hardening-fix

Conversation

@SRSaunders
Copy link
Copy Markdown

@SRSaunders SRSaunders commented Feb 10, 2026

This fixes #1075 for llvm's libc++ hardening mode starting with llvm 18.

Although the fix is designed to avoid PCH redefinition errors on Apple Xcode builds with AppleClang 17+, the solution is general in that other platforms and build types can take advantage of the improvement.

The solution defines new CLANG_CXX_FLAGS_<build-type> cmake variables (default empty) that are appended to the existing CMAKE_CXX_FLAGS_<build-type> variables and passed to both PCH and regular build components. For Xcode builds using AppleClang 17+ (containing llvm 19+), these new variables are automatically set to match Xcode's defaults for the hardening defines. However, they can be manually set on any build type or platform for non-MSVC compilers.

For example, a linux (or macOS) release build could add the following to their cmake-<platform>-release.sh script to enable _LIBCPP_HARDENING_MODE_FAST:

-DCLANG_CXX_FLAGS_RELEASE="-U_LIBCPP_HARDENING_MODE -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST"

This PR also fixes a small PCH cleanup issue for rbdmap when using non-MSVC IDE builds (tested with Xcode).

Tested on macOS Sequoia with Xcode 26.2 builds as well as command line builds (debug and release variants). Also tested on Linux Manjaro + clang 21 with _LIBCPP_HARDENING_MODE_FAST override on command line release build.

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.

AppleClang 17+ emits PCH redefinition warnings for llvm's libc++ hardening mode

1 participant