build: three device-free executables do not build with the documented clang-cl route #3867

Open
opened 2026-12-02 15:43:48 +00:00 by triggered02 · 2 comments
triggered02 commented 2026-12-02 15:43:48 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-02T15:43:48Z.


Summary. docs/non-windows-hosts.md says the clang-cl + xwin route builds "the eight startup stand-ins (xmem_shim, d3d12_xs_shim and the six startup_stub_* targets) and the device-free test executables ... from a clean checkout". I built the whole tree that way on current main and three device-free executables do not build. One is a plain clang/MSVC divergence with a one-line fix (PR below); the other two I am reporting without a fix.

Environment: Debian, clang-cl 19.1.1 + lld-link, xwin splat of SDK 10.0.26100, Release, the toolchain file from that doc section. Tree: main at 0939575e, clean checkout.

cmake --build out/build/clang -j 8 -- -k 0
FAILED: CMakeFiles/startup_gameinput_trace.dir/tests/startup_gameinput_trace.cpp.obj
FAILED: CMakeFiles/xmem_commit_protection_check.dir/tests/xmem_commit_protection_check.cpp.obj
FAILED: startup_host_cpu_probe.exe
FAILED: xapu.dll xapu.lib

xapu is the known gap (no MSVC m.lib on this host, already documented). The other three are below.

1. startup_gameinput_trace — const-cast idiom, fixed in #3866. vtbl is const void* const*, and four calls do reinterpret_cast<Fn>(vtbl[n]), which drops const:

tests/startup_gameinput_trace.cpp(41,43): error: reinterpret_cast from 'const void *' to 'Fn'
  (aka 'unsigned long long (*)(...IGameInputReading *)') casts away qualifiers
(and .cpp(46,16), (55,43), (60,16))

MSVC accepts this, clang does not. Casting through const_cast<void*> first is accepted by both and changes nothing at runtime. With that one change the target links.

2. xmem_commit_protection_check — the compiler crashes.

clang-cl: error: clang frontend command failed with exit code 139 (use -v to see invocation)

139 is SIGSEGV in the frontend, not a diagnostic. It may be a clang 19.1.1 bug rather than anything this repo does, but it means the target cannot be built on this route at all. I have not reduced it; -v and a reduced preprocessed source would be the next step, and I do not know whether it reproduces on other clang versions.

3. startup_host_cpu_probe — intrinsics unresolved at link.

lld-link: error: undefined symbol: __rdtscp
lld-link: error: undefined symbol: _mm_loadu_si128
lld-link: error: undefined symbol: _mm_set_epi32
lld-link: error: undefined symbol: _mm_add_epi32

The source uses intrinsics that MSVC's headers declare __forceinline from <intrin.h>; with this layout they arrive as external calls instead. Likely a missing #include <intrin.h> or an architecture flag (/arch:SSE2/-msse2) on this route. I have not confirmed which.

What I am not claiming. None of this affects the Windows build or CI — MSVC remains the reference and Windows CI is green. It only narrows what "builds on Linux with clang-cl" actually covers, and two of the three gaps look like documentation overstatement rather than code defects worth changing for their own sake.

I am fixing (1) in a PR because it is small, verifiable here, and inside the route the doc already promises. Say if you would rather the doc name the narrower set of targets that currently build and I will do that instead.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6748737413 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3867). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-02T15:43:48Z. --- **Summary.** `docs/non-windows-hosts.md` says the clang-cl + xwin route builds "the eight startup stand-ins (`xmem_shim`, `d3d12_xs_shim` and the six `startup_stub_*` targets) and the device-free test executables ... from a clean checkout". I built the whole tree that way on current `main` and three device-free executables do not build. One is a plain clang/MSVC divergence with a one-line fix (PR below); the other two I am reporting without a fix. **Environment:** Debian, clang-cl 19.1.1 + lld-link, `xwin splat` of SDK 10.0.26100, Release, the toolchain file from that doc section. Tree: `main` at `0939575e`, clean checkout. ``` cmake --build out/build/clang -j 8 -- -k 0 FAILED: CMakeFiles/startup_gameinput_trace.dir/tests/startup_gameinput_trace.cpp.obj FAILED: CMakeFiles/xmem_commit_protection_check.dir/tests/xmem_commit_protection_check.cpp.obj FAILED: startup_host_cpu_probe.exe FAILED: xapu.dll xapu.lib ``` `xapu` is the known gap (no MSVC `m.lib` on this host, already documented). The other three are below. **1. `startup_gameinput_trace` — const-cast idiom, fixed in #3866.** `vtbl` is `const void* const*`, and four calls do `reinterpret_cast<Fn>(vtbl[n])`, which drops `const`: ``` tests/startup_gameinput_trace.cpp(41,43): error: reinterpret_cast from 'const void *' to 'Fn' (aka 'unsigned long long (*)(...IGameInputReading *)') casts away qualifiers (and .cpp(46,16), (55,43), (60,16)) ``` MSVC accepts this, clang does not. Casting through `const_cast<void*>` first is accepted by both and changes nothing at runtime. With that one change the target links. **2. `xmem_commit_protection_check` — the compiler crashes.** ``` clang-cl: error: clang frontend command failed with exit code 139 (use -v to see invocation) ``` 139 is SIGSEGV in the frontend, not a diagnostic. It may be a clang 19.1.1 bug rather than anything this repo does, but it means the target cannot be built on this route at all. I have not reduced it; `-v` and a reduced preprocessed source would be the next step, and I do not know whether it reproduces on other clang versions. **3. `startup_host_cpu_probe` — intrinsics unresolved at link.** ``` lld-link: error: undefined symbol: __rdtscp lld-link: error: undefined symbol: _mm_loadu_si128 lld-link: error: undefined symbol: _mm_set_epi32 lld-link: error: undefined symbol: _mm_add_epi32 ``` The source uses intrinsics that MSVC's headers declare `__forceinline` from `<intrin.h>`; with this layout they arrive as external calls instead. Likely a missing `#include <intrin.h>` or an architecture flag (`/arch:SSE2`/`-msse2`) on this route. I have not confirmed which. **What I am not claiming.** None of this affects the Windows build or CI — MSVC remains the reference and Windows CI is green. It only narrows what "builds on Linux with clang-cl" actually covers, and two of the three gaps look like documentation overstatement rather than code defects worth changing for their own sake. I am fixing (1) in a PR because it is small, verifiable here, and inside the route the doc already promises. Say if you would rather the doc name the narrower set of targets that currently build and I will do that instead.
triggered02 commented 2026-12-02 15:46:48 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-02T15:46:48Z.


Progress on two of the three, plus a root cause for the third.

2. xmem_commit_protection_check — reduced, fixed in #3869, and it is an upstream clang bug. The crash is in GenerateSEHFilterFunction → EmitCapturedLocals → recoverAddrOfEscapedLocal. Trigger, reduced to ~20 lines:

__except filter Result
capture_fault(GetExceptionInformation(), &info) crashes
capture_fault(plain_ep(), &info) builds
capture_fault(GetExceptionInformation()) — no captured local builds

So clang 19.1.1 cannot recover an escaped local inside an outlined SEH filter when that filter also references the exception record. The workaround in #3869 records through a thread_local sink so the filter captures nothing; semantics and MSVC output are unchanged.

3. startup_host_cpu_probe — root cause identified, not fixed. It is not a missing <intrin.h> (the file already includes <immintrin.h> and <intrin.h>). The build picks up xwin's MSVC CRT headers, not clang's:

Note: including file: /home/triggered/.xwin/crt/include/immintrin.h

MSVC's headers declare these intrinsics and rely on #pragma intrinsic; under clang-cl those declarations are not turned into clang builtins, so _mm_loadu_si128, __rdtscp, _mm_set_epi32, _mm_add_epi32 are emitted as calls and stay undefined at link:

$ llvm-nm ifull.obj | grep ' U '
           U __rdtscp
           U __security_check_cookie
           U __security_cookie
           U _mm_loadu_si128

__SSE2__ is defined and the target is x86-64, so this is not an architecture-flag problem — it is header precedence: the /imsvc xwin paths are searched before clang's -internal-isystem resource headers. The fix therefore belongs in the toolchain file or the CMake warning/feature block, not in the test source, and I would rather you decide which side owns it than have me move header precedence around in a file other contributors copy into their own toolchains. Options I see: give clang's resource include priority over the xwin CRT for <*.h> intrinsics, or add #if defined(__clang__) builtin mappings in the one test that needs them.

1. startup_gameinput_trace — fixed in #3868.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7350905005 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3867#issuecomment-7350905005). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-02T15:46:48Z. --- Progress on two of the three, plus a root cause for the third. **2. `xmem_commit_protection_check` — reduced, fixed in #3869, and it is an upstream clang bug.** The crash is in `GenerateSEHFilterFunction` → `EmitCapturedLocals` → `recoverAddrOfEscapedLocal`. Trigger, reduced to ~20 lines: | `__except` filter | Result | |---|---| | `capture_fault(GetExceptionInformation(), &info)` | **crashes** | | `capture_fault(plain_ep(), &info)` | builds | | `capture_fault(GetExceptionInformation())` — no captured local | builds | So clang 19.1.1 cannot recover an escaped local inside an outlined SEH filter when that filter also references the exception record. The workaround in #3869 records through a `thread_local` sink so the filter captures nothing; semantics and MSVC output are unchanged. **3. `startup_host_cpu_probe` — root cause identified, not fixed.** It is not a missing `<intrin.h>` (the file already includes `<immintrin.h>` and `<intrin.h>`). The build picks up **xwin's MSVC CRT headers**, not clang's: ``` Note: including file: /home/triggered/.xwin/crt/include/immintrin.h ``` MSVC's headers declare these intrinsics and rely on `#pragma intrinsic`; under clang-cl those declarations are not turned into clang builtins, so `_mm_loadu_si128`, `__rdtscp`, `_mm_set_epi32`, `_mm_add_epi32` are emitted as **calls** and stay undefined at link: ``` $ llvm-nm ifull.obj | grep ' U ' U __rdtscp U __security_check_cookie U __security_cookie U _mm_loadu_si128 ``` `__SSE2__` is defined and the target is x86-64, so this is not an architecture-flag problem — it is header precedence: the `/imsvc` xwin paths are searched before clang's `-internal-isystem` resource headers. The fix therefore belongs in the toolchain file or the CMake warning/feature block, not in the test source, and I would rather you decide which side owns it than have me move header precedence around in a file other contributors copy into their own toolchains. Options I see: give clang's resource include priority over the xwin CRT for `<*.h>` intrinsics, or add `#if defined(__clang__)` builtin mappings in the one test that needs them. **1. `startup_gameinput_trace`** — fixed in #3868.
triggered02 commented 2026-12-02 16:05:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-02T16:05:26Z.


Correction on item 3 — that one is my host, not the repository. Please disregard the header-precedence theory; I found the actual cause and it is a broken toolchain install on my side.

$ clang-cl --target=x86_64-pc-windows-msvc -print-resource-dir
/home/triggered/.local/llvm/root/usr/lib/llvm-19/lib/clang/19
$ ls .../lib/clang/19/include
(no such directory)

My unpacked Ubuntu llvm-19 archive has no clang resource headers at all — lib/clang/19/include does not exist. So clang-cl has no intrinsic headers of its own, picks up the MSVC <immintrin.h> from the xwin CRT, and MSVC's declarations stay unresolved because clang does not honour #pragma intrinsic for them. _mm_loadu_si128 etc. therefore become calls, exactly as llvm-nm showed.

On a toolchain that ships libclang-common-19-dev (or any complete clang install) the resource headers are present, clang's own <immintrin.h> defines those intrinsics as builtins, and this link failure should not occur. So item 3 is not evidence against the documented route and needs no repository change. I have not verified that on a complete install — I am telling you what the missing directory implies, not claiming a clean build I did not run.

For completeness, I also tested the fix that would have followed from my wrong theory: putting clang's resource include first in the /imsvc list changes nothing here, because the directory is empty. That experiment is void.

Status of the three gaps, corrected:

  1. startup_gameinput_trace — repository bug, fixed in #3868 (approved).
  2. xmem_commit_protection_check — upstream clang bug, reduced, worked around in #3869 (merged into main as 6e3a181b).
  3. startup_host_cpu_probe — my host's incomplete LLVM install, not a repository issue. Withdraw.

I would still like to know whether the doc's sentence holds on a complete clang install, but that is your call to spend time on — from here the only honest next step I could take is installing the missing headers and re-running, which does not test the repository at all.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7351419511 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3867#issuecomment-7351419511). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-02T16:05:26Z. --- **Correction on item 3 — that one is my host, not the repository.** Please disregard the header-precedence theory; I found the actual cause and it is a broken toolchain install on my side. ``` $ clang-cl --target=x86_64-pc-windows-msvc -print-resource-dir /home/triggered/.local/llvm/root/usr/lib/llvm-19/lib/clang/19 $ ls .../lib/clang/19/include (no such directory) ``` My unpacked Ubuntu `llvm-19` archive has **no clang resource headers at all** — `lib/clang/19/include` does not exist. So clang-cl has no intrinsic headers of its own, picks up the MSVC `<immintrin.h>` from the xwin CRT, and MSVC's declarations stay unresolved because clang does not honour `#pragma intrinsic` for them. `_mm_loadu_si128` etc. therefore become calls, exactly as `llvm-nm` showed. On a toolchain that ships `libclang-common-19-dev` (or any complete clang install) the resource headers are present, clang's own `<immintrin.h>` defines those intrinsics as builtins, and this link failure should not occur. **So item 3 is not evidence against the documented route and needs no repository change.** I have not verified that on a complete install — I am telling you what the missing directory implies, not claiming a clean build I did not run. For completeness, I also tested the fix that would have followed from my wrong theory: putting clang's resource include first in the `/imsvc` list changes nothing here, because the directory is empty. That experiment is void. **Status of the three gaps, corrected:** 1. `startup_gameinput_trace` — **repository bug**, fixed in #3868 (approved). 2. `xmem_commit_protection_check` — **upstream clang bug**, reduced, worked around in #3869 (merged into `main` as `6e3a181b`). 3. `startup_host_cpu_probe` — **my host's incomplete LLVM install**, not a repository issue. Withdraw. I would still like to know whether the doc's sentence holds on a complete clang install, but that is your call to spend time on — from here the only honest next step I could take is installing the missing headers and re-running, which does not test the repository at all.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#3867
No description provided.