Skip to content

Normalise LLVM target triple for Apple platforms (aarch64 -> arm64)#156

Merged
angerman merged 1 commit into
stable-ghc-9.14from
normalise-llvm-target-triple
Feb 28, 2026
Merged

Normalise LLVM target triple for Apple platforms (aarch64 -> arm64)#156
angerman merged 1 commit into
stable-ghc-9.14from
normalise-llvm-target-triple

Conversation

@angerman
Copy link
Copy Markdown

Summary

  • Add normaliseLlvmTarget to ghc-toolchain that rewrites aarch64-apple-* to arm64-apple-* in LLVM target triples
  • GNU config.sub normalises to aarch64-apple-darwin, but Apple's LLVM toolchain and nix's cc-wrapper expect arm64-apple-darwin
  • Without this fix, GHC passes --target=aarch64-apple-darwin to clang, triggering a cc-wrapper warning that pollutes stderr and causes ~5400/10775 testsuite failures on aarch64-darwin

Split out from #149 (the HADRIAN_SETTINGS removal was already merged separately).

Test plan

  • CI passes on x86_64-linux (no regression)
  • aarch64-darwin builds should no longer produce cc-wrapper --target mismatch warnings

Apple's LLVM toolchain uses `arm64` as the canonical architecture name
for AArch64 on Apple platforms, while GNU config.sub normalises to
`aarch64`. This mismatch causes `--target=aarch64-apple-darwin` to be
passed to clang, which conflicts with toolchain wrappers (e.g. nix
cc-wrapper) that expect `arm64-apple-darwin`.

The result is thousands of test failures on aarch64-darwin because the
cc-wrapper warning pollutes compiler output and the target flag
interaction breaks compilation.

Fix by adding normaliseLlvmTarget that rewrites `aarch64-apple-*` to
`arm64-apple-*` for the LLVM target triple, matching Apple conventions
and the existing llvm-targets file which already uses arm64-apple-darwin.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds LLVM-target triple normalization in ghc-toolchain to avoid Apple toolchain / wrapper mismatches (notably nix cc-wrapper) by rewriting aarch64-apple-* to arm64-apple-*.

Changes:

  • Export normaliseLlvmTarget from GHC.Toolchain.NormaliseTriple and implement aarch64-apple-*arm64-apple-* rewriting.
  • Apply normaliseLlvmTarget when computing tgtLlvmTarget in ghc-toolchain’s mkTarget.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
utils/ghc-toolchain/src/GHC/Toolchain/NormaliseTriple.hs Adds and exports normaliseLlvmTarget to rewrite Apple AArch64 LLVM triples.
utils/ghc-toolchain/exe/Main.hs Uses normaliseLlvmTarget when generating the persisted “LLVM target” setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

-- See also: the @llvm-targets@ file uses @arm64-apple-darwin@.
normaliseLlvmTarget :: String -> String
normaliseLlvmTarget triple
| "aarch64-apple-" `isPrefixOf` triple
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normaliseLlvmTarget currently rewrites any aarch64-apple-* triple to arm64-apple-*. This will change aarch64-apple-ios into arm64-apple-ios, but the shipped llvm-targets file contains an aarch64-apple-ios entry and no arm64-apple-ios entry, so GHC's LLVM backend will fail to look up a data layout for iOS targets (panic in the lookup target (llvmTargets ...) path). Consider narrowing this rewrite to the Darwin host triples that actually trigger the cc-wrapper warning (e.g. aarch64-apple-darwin*), or alternatively add matching arm64-apple-* aliases to llvm-targets as part of this change.

Suggested change
| "aarch64-apple-" `isPrefixOf` triple
| "aarch64-apple-darwin" `isPrefixOf` triple

Copilot uses AI. Check for mistakes.
Comment on lines +443 to +445
-- Use Llvm target if specified, otherwise use triple as llvm target.
-- Normalise for platform conventions (e.g. aarch64-apple-* -> arm64-apple-*).
let tgtLlvmTarget = normaliseLlvmTarget $ fromMaybe normalised_triple (optLlvmTriple opts)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tgtLlvmTarget is persisted into the generated settings file as "LLVM target" and is later used by the LLVM backend to look up a data layout in llvm-targets. Applying normaliseLlvmTarget unconditionally here can therefore make the settings contain a triple that isn't present in llvm-targets (e.g. arm64-apple-ios). Please ensure the normalisation only produces triples that exist in llvm-targets (either by narrowing the rewrite to darwin, or by adding the corresponding aliases to llvm-targets).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@angerman angerman requested a review from Copilot February 28, 2026 01:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +32
| "aarch64-apple-" `isPrefixOf` triple
= "arm64-" ++ drop (length "aarch64-") triple
| otherwise
= triple
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard checks the prefix "aarch64-apple-" but the rewrite drops only "aarch64-". This works today, but it’s easy to accidentally break if the guard/prefix changes later. Prefer rewriting based on a single shared prefix (e.g., strip the exact matched prefix and prepend the corresponding replacement prefix) to keep the condition and transformation coupled.

Suggested change
| "aarch64-apple-" `isPrefixOf` triple
= "arm64-" ++ drop (length "aarch64-") triple
| otherwise
= triple
| srcPrefix `isPrefixOf` triple
= dstPrefix ++ drop (length srcPrefix) triple
| otherwise
= triple
where
srcPrefix = "aarch64-apple-"
dstPrefix = "arm64-apple-"

Copilot uses AI. Check for mistakes.
Comment on lines +443 to +445
-- Use Llvm target if specified, otherwise use triple as llvm target.
-- Normalise for platform conventions (e.g. aarch64-apple-* -> arm64-apple-*).
let tgtLlvmTarget = normaliseLlvmTarget $ fromMaybe normalised_triple (optLlvmTriple opts)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Llvm”/“llvm” in the comment is inconsistent with the standard acronym “LLVM”. Consider updating the comment to use “LLVM” consistently (and, if desired, “LLVM target triple” for clarity).

Copilot uses AI. Check for mistakes.
@angerman angerman merged commit b931ed7 into stable-ghc-9.14 Feb 28, 2026
37 of 45 checks passed
@angerman angerman deleted the normalise-llvm-target-triple branch February 28, 2026 12:29
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.

2 participants