Skip to content

32-bit Phase 4c: run the test suite as i686 programs (TSLANG_TEST_X86) - #339

Merged
ASDAlexander77 merged 10 commits into
mainfrom
phase4c-suite-i686
Sep 21, 2026
Merged

ASDAlexander77 merged 10 commits into
mainfrom
phase4c-suite-i686

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Summary

Phase 4c of 32-bit support: the test suite now runs as 32-bit programs (i686-pc-windows-msvc) and passes. The 32-bit test set is off by default. With the option off, the registered tests, their names and the x64 runner scripts are unchanged. The plan is in docs/superpowers/plans/2026-09-22-32-bit-phase-4c-suite.md.

How to run it

prepare_3rdParty.bat <cfg> x86
scripts\build_tslang_runtime_<cfg>_x86.bat
cmake -DTSLANG_TEST_X86=ON <build dir>
ctest -C Release -L x86

If an x86 library (gc, runtime, libcmt, kernel32, libucrt) is missing, configure stops with an error that names it.

What's in it

  • test-runner -x86: compiles for the i686 triple, uses the _X86 library paths, links with /machine:x86, and refuses -jit.
  • TSLANG_TEST_X86 (CMake option, default OFF): the tslang_add_test wrapper registers a test-x86-* twin of every non-JIT test, labelled x86. tslang/test/tester/x86-exclusions.cmake disables three tests: internals under gc, rc and none. It uses inline_asm<i64> with an =r constraint, and 32-bit x86 has no 64-bit register.
  • mask-ir.sh now also masks the numeric IDs in tsrelcb_ / tsretcb_ names, which differ from run to run.

Compiler behaviour changes

  1. Importing a DLL for a foreign target. When the target's architecture or OS differs from the host's, the compiler reads the exported __decls string from the PE file (Dump::readExportedCString) instead of loading the DLL. Previously it loaded an x86 DLL into the x64 compiler, which failed with 0xC1. Imports on the host architecture are unchanged. For a foreign target, importing a file that isn't a PE DLL, or a DLL built for a different CPU, is now a clear compile error. Two new default-suite tests cover this path: test-compile-foreign-target-import-read and test-compile-foreign-target-import-errors.
  2. An asInvoker manifest in every Windows x86 --emit=exe. Windows' installer detection won't start an unmanifested 32-bit exe whose name contains patch, setup, install or update without admin rights. That was the cause of the last three x86 failures ("dispatch"). The compiler builds the RT_MANIFEST object in-process, so rc.exe isn't needed. x64 output and DLLs are unchanged.

Coverage

  • 1398 x86 twins are registered: 1395 pass, and the 3 internals tests are disabled.
  • No twins for:
    • the 1357 JIT tests, because the JIT can't run 32-bit code inside the 64-bit compiler;
    • 14 tests that run as CMake scripts rather than through the test runner.
  • Every corpus file is compiled at least once as 32-bit, except 02funcs_vararg.ts, which only has JIT tests.

Not in this PR

These are recorded in the spec's open issues.

  • The x86 default library is deferred. It has to be built in the separate TypeScriptCompilerDefaultLib repository, and the compiler's default-library folder lookup needs an x86 segment. The suite runs with --no-default-lib, as on x64.
  • Found, not fixed: in multi-file tests, per-test flags such as -mm=rc never reach the entry file. For example, test-compile-rc-shared-* actually builds a gc exe against an rc DLL. It behaves the same way on x64.
  • CI doesn't run the x86 set, because it's opt-in and needs the x86 libraries.

Test plan

  • ctest -C Release -L x86 with -DTSLANG_TEST_X86=ON: 1395/1395 pass, 3 disabled.
  • Default suite ctest -j 16 -C Release: 2771/2771. That's the previous 2769 plus the two new foreign-target import tests.
  • With TSLANG_TEST_X86=OFF, CTestTestfile.cmake is identical to main's apart from the two new tests, and the x64 runner scripts are byte-identical.
  • An x86 exe contains exactly one RT_MANIFEST, and no temporary files are left behind.
  • check-x86-libs.sh, check-x86-run.sh and check-x86-eh.sh all ok.
  • compare-ir.sh on x64 --emit=llvm: unchanged apart from the known nondeterministic files.
  • Linux CI. Not run locally. The x86 set is Windows-only and off by default.

🤖 Generated with Claude Code

ASDAlexander77 and others added 10 commits September 21, 2026 22:25
test-runner gains -x86. It compiles every file with
-mtriple=i686-pc-windows-msvc and links with /machine:x86 against the
x86 VC, SDK, UCRT, gc and runtime libraries, which CMake now bakes in as
TEST_*_X86 defines. The shared-library scripts copy the 32-bit gc.dll,
which sits beside its import library in lib/x86. The cached scripts get
an "x86" suffix so an x86 run never reuses an x64 one, and a reconfigure
removes them. -jit with -x86 is refused, since the JIT runs in the x64
compiler process.

Without -x86 the scripts are the same as before.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
With -DTSLANG_TEST_X86=ON, each test-runner registration that does not
pass -jit also gets a twin, test-x86-<name without "test-">, that runs
`test-runner -x86` with the same arguments and is labelled x86. So
`ctest -C Release -L x86` runs the suite as i686 programs. The option
is off by default, and then the tests and their names are unchanged.

- tslang_add_test replaces add_test for the test-runner registrations,
  1203 of them, the two corpus-loop ones included. It sets
  TSLANG_X86_TWIN in the caller, so the corpus loop disables a broken
  file's twin along with the file.
- The cmake-script tests (rc debug info, collector linkage, the
  default-library collector tests, the ownership verifier) keep plain
  add_test and have no twin.
- With the option on, configure checks that the x86 gc.lib, the shared
  gc.lib and gc.dll, and the runtime library exist. A missing one is a
  FATAL_ERROR that names the script that builds it.
- x86-exclusions.cmake lists the twins that cannot run at 32 bits, each
  with a reason. They are registered DISABLED, and an entry that
  names no twin is a configure error. For now the only entries are
  the three internals.ts registrations: an inline_asm<i64> with an
  "=r" constraint does not fit one i686 register.

1398 twins, 1357 -jit registrations skipped. First run: 131 failures,
all -shared, all "Can't open: Unknown error (0xC1)" from loading an
x86 DLL in the compiler.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An x64 tslang cannot load an i686 DLL, so importing one failed with
"Can't open: Unknown error (0xC1)" before any declaration was read.

When the target's arch or OS differs from the host's
(targetInfo.supportsInProcessJit is false), mlirGenImportSharedLib no
longer loads the library. It reads each exported __decls pointer
variable from the PE file instead, using the new
Dump::readExportedCString. That function takes the export RVA, reads
the 4- or 8-byte pointer there (the string's address at the preferred
image base, as the linker wrote it; the base relocation only matters
once loaded), subtracts the image base, and reads the NUL-terminated
string from the section's data in the file. A symbol the library does
not export still gets the existing warning. A symbol it does export but
whose string can't be read is an error.

The memory-model and gctors markers and the collector check already
read the file, so they work for i686 unchanged. The global constructor
that loads the library at run time stays, because it runs inside the
32-bit program. The host path is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Windows installer detection asks for elevation before starting a 32-bit
exe that has no requestedExecutionLevel manifest and whose name contains
"setup", "install", "update" or "patch"; unelevated, CreateProcess
refuses it. The x86 twins of export-import-class-abstract-virtual-dispatch
never started ("dispatch" holds "patch"). x64 exes are exempt.

tslang --emit=exe now links an RT_MANIFEST resource object (asInvoker)
into every Windows x86 program, built in-process with LLVM's
WindowsResource writer. Not -manifest:embed: the driver uses MSVC's
link.exe when Visual Studio is installed, and link.exe then runs rc.exe,
which is on PATH only in a developer prompt (LNK1158). x64 output and
DLLs are unchanged. test-runner -x86 passes lld-link /manifest:embed and
/manifestuac for exes, not DLLs. check-x86-run.sh builds hello as
my_setup_patch.exe and runs it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
They vary between runs of the same compiler, like td_, tsrel_ and
tsret_, and showed up as compare-ir noise.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Phases 1-4 implemented except the x86 default library. The 4c bullet
says how to run the suite (-DTSLANG_TEST_X86=ON, ctest -L x86), the 1398
twins and 1357 JIT registrations without one, the three internals
exclusions, and the installer-detection manifest finding. Closes the
"Importing an x86 DLL" issue; opens the deferred x86 default library and
the per-test flags that miss a multi-file test's entry file.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
For a target whose arch or OS differs from the host's, the declarations
of an imported DLL are read from the file, so only a PE image can serve.
A file that is not one now fails with "cannot read declarations from
'<file>': for a target other than the host, only PE DLLs can be
imported". A DLL built for another machine than the target's (an x64
DLL imported into an i686 program) is refused with both machines named.
The machine names come from Dump::coffMachineName, moved out of exe.cpp
so both places use one mapping.

Dump::getSymbols now consumes the error of a failed createBinary and of
a failed createDumper. Left unconsumed, either aborts a Debug build.

writeAsInvokerManifestObj removes its temporary object when writing it
fails. Before, the caller never learned the path, so the file leaked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
test-compile-foreign-target-import-read builds shared.ts as an x64 DLL
and compiles use_shared.ts for x86_64 Linux against it. That target
takes the read-from-file path (PE32+) with no x86 libraries. The test
checks that the program compiles with no missing-declarations warning,
and that its IR looks up test1, test2 and val_str. Only the DLL's
declarations declare those names.

test-compile-foreign-target-import-errors checks the two refusals: a
non-PE foo.dll imported for a foreign target, and an x64 DLL imported
into an x86 program.

Also, with TSLANG_TEST_X86 on, configure now checks that the MSVC and
Windows SDK x86 libraries (libcmt, kernel32, libucrt) are installed.
tslang_add_test checks the test- prefix whether the option is on or
not. A comment notes that test-jit-00-array-conditional-access has no
-jit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The twin rule is "every test-runner registration without -jit". Only
02funcs_vararg.ts is JIT-only at the file level. The cmake-script tests
without twins are listed: rc-debug-info, gc-shared-auto, the two
default-library collector tests, the 8 ownership-verifier shards and
the two new foreign-target import tests. The DLL file is read when the
target's arch or OS differs from the host's (supportsInProcessJit), not
the arch alone. The spec now names the default-suite tests that cover
that path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit b277622 into main Sep 21, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the phase4c-suite-i686 branch September 21, 2026 23:55
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