Skip to content

Build win-arm64 libClangSharp with clang-cl to match the LLVM release ABI#807

Open
tannergooding wants to merge 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-investigate-arm64-ci-failure-pr-805
Open

Build win-arm64 libClangSharp with clang-cl to match the LLVM release ABI#807
tannergooding wants to merge 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-investigate-arm64-ci-failure-pr-805

Conversation

@tannergooding

Copy link
Copy Markdown
Member

What

Builds the win-arm64 libClangSharp shim with the LLVM release's own clang-cl (via -G Ninja) instead of MSVC, so the shim's C++ record layouts match the clang-built LLVM binaries it links against.

Why

The official LLVM release binaries are clang-built. On Arm64, clang and MSVC disagree on the record layout of over-aligned non-POD base classes — e.g. clang::TemplateSpecializationType (TypeWithKeyword + FoldingSetNode, where the Type base is alignas(16)):

  • clang rounds the over-aligned base up to a full slot → later base at offset 32, Template at 40.
  • MSVC-Arm64 packs the next base into the over-aligned base's tail padding → later base at 24, Template at 32.

So an MSVC-built shim reads members of clang-built types at the wrong offset and returns garbage — clangsharp_Type_getTemplateName yields CX_TNK_Invalid, which surfaces as the windows-arm64 CI failures on TemplateNameTest / DependentTemplateBaseTest. This is a long-standing MSVC-vs-clang ABI disagreement specific to the aarch64-pc-windows-msvc triple (reproduces across every MSVC Arm64 and clang version tested); win-x64 layouts agree, so only win-arm64 needs the change.

Changes

  • scripts/build.ps1 — route win-arm64 libClangSharp through Ninja + the release's clang-cl (imports the VS dev environment via vcvarsall, puts the LLVM bin on PATH). win-x64 keeps using MSVC.
  • sources/libClangSharp/CMakeLists.txt — generalize the diaguids.lib repoint (which works around the absolute path LLVM bakes into LLVMExports.cmake) to also apply under Ninja + clang-cl, sourcing the VS root/arch from VSINSTALLDIR and the compiler arch id when the VS-generator variables are absent.
  • README.md — document the win-arm64 clang-cl special-casing.

The interim skip guards for TemplateNameTest / DependentTemplateBaseTest (issue #806) stay until the native package is regenerated and republished with this fix.

Validation

Built the shim locally on an Arm64 box via the real scripts/build.ps1 -regeneratenative path (fresh build dir, simulated the LLVM build-machine diaguids path to confirm the repoint), binplaced the result, and ran both previously-failing tests: TemplateNameTest passes and DependentTemplateBaseTest is 8 passed / 0 failed (was 8× Debug.Fail).

tannergooding and others added 3 commits July 16, 2026 12:08
These tests exercise native libClangSharp shims that are broken in the
win-arm64 22.1.8.2 prebuilt, causing Debug.Fail / NRE when the native
lib returns CX_TNK_Invalid for template names. The existing DeclTest
guard already covers other shim-dependent tests; extend the same pattern
to TypeTest and the baseline generator tests.

See dotnet#806.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… ABI

The official LLVM release binaries are clang-built. On Arm64, clang and MSVC
disagree on the record layout of over-aligned non-POD base classes such as
clang::TemplateSpecializationType (clang rounds the over-aligned base up to a
full slot; MSVC-Arm64 packs the next base into its tail padding), so an
MSVC-built shim reads members of clang-built types at the wrong offset and
returns garbage (e.g. getTemplateName yielding CX_TNK_Invalid). win-x64 layouts
agree between the two compilers, so only win-arm64 is affected.

Build the win-arm64 shim with the release's own clang-cl (via Ninja) so its
layouts match the libs it links against. Generalize the diaguids.lib repoint in
libClangSharp/CMakeLists.txt to also apply under Ninja + clang-cl, sourcing the
Visual Studio root and target arch from VSINSTALLDIR and the compiler arch id
when the VS-generator variables are absent.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…m64 rebuild

The win-arm64 shim is now compiled with clang-cl, so the native package needs a
new revision to republish. Bump the five runtime nuspecs, the meta nuspec, and
runtime.json from 22.1.8.2 to 22.1.8.3. The managed libClangSharp pin in
Directory.Packages.props stays at .2 until .3 is published, matching how prior
native republishes were sequenced.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

1 participant