Skip to content

clang multiarch is broken with pch (at least on macOS) #114626

@alecazam

Description

@alecazam

So macOS clang seems to have left out multiarch support for precompiled headers. So I split out our arch specifications as such, and compiled each pch for each arch. I've left the trailing backslash off on the examples below just because they don't carry over without using a double-backslash.

Given that Win/Android/Linux now has arm64 and x64, this would be good to fix if this is pervasive across other platforms.

clang --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin24.1.0
Thread model: posix

CXXARCH := -arch x86_64 -mavx2 -mf16c -mfma
-arch arm64

The problem is now I need to pass the pch to the compiles. This requires use of -include-pch like so.

PRECOMPILED_CXXFLAGS +=
-include-pch $(PRECOMPILED_PCH_ARM)
-include-pch $(PRECOMPILED_PCH_X64)

But that doesn't work since it tries to link the x64 pch to the .o. So then I try -Xarch

PRECOMPILED_CXXFLAGS +=
-Xarch_arm64 -include-pch $(PRECOMPILED_PCH_ARM)
-Xarch_x86_64 -include-pch $(PRECOMPILED_PCH_X64)

That generates the following failure:
invalid Xarch argument: '-Xarch_arm64 -include-pch', options requiring arguments are unsupported

I also tried this to workaround the single argument limit of -Xarch, but then get a complaint about using -o with multiple arch. But I don't get that if I just leave the pch out, and it builds the universal lib/exe just fine. The -o is still on the command line.

PRECOMPILED_CXXFLAGS +=
-include-pch -Xarch_arm64$(PRECOMPILED_PCH_ARM)
-Xarch_x86_64 $(PRECOMPILED_PCH_X64)

clang++:1:1 cannot specify -o when generating multiple output files

Trying to turn it into a single arg, clang seems to think this is a -include directive, and tries to prepend the AST (.pch) with the filename -pch=... which is also not correct parsing and hangs the parser.

PRECOMPILED_CXXFLAGS +=
-Xarch_arm64 -include-pch=$(PRECOMPILED_PCH_ARM)
-Xarch_x86_64 -include-pch=$(PRECOMPILED_PCH_X64)\

So I have no idea how to fix multiarch and pch. I can build multiarch without pch. I can build each arch separately. The -Xarch limitation is very limiting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions