Repository navigation
32-bit Phase 4c: run the test suite as i686 programs (TSLANG_TEST_X86) - #339
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 indocs/superpowers/plans/2026-09-22-32-bit-phase-4c-suite.md.How to run it
If an x86 library (gc, runtime,
libcmt,kernel32,libucrt) is missing, configure stops with an error that names it.What's in it
-x86: compiles for the i686 triple, uses the_X86library paths, links with/machine:x86, and refuses-jit.TSLANG_TEST_X86(CMake option, default OFF): thetslang_add_testwrapper registers atest-x86-*twin of every non-JIT test, labelledx86.tslang/test/tester/x86-exclusions.cmakedisables three tests:internalsunder gc, rc and none. It usesinline_asm<i64>with an=rconstraint, and 32-bit x86 has no 64-bit register.mask-ir.shnow also masks the numeric IDs intsrelcb_/tsretcb_names, which differ from run to run.Compiler behaviour changes
__declsstring 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-readandtest-compile-foreign-target-import-errors.asInvokermanifest 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 theRT_MANIFESTobject in-process, sorc.exeisn't needed. x64 output and DLLs are unchanged.Coverage
internalstests are disabled.02funcs_vararg.ts, which only has JIT tests.Not in this PR
These are recorded in the spec's open issues.
TypeScriptCompilerDefaultLibrepository, and the compiler's default-library folder lookup needs an x86 segment. The suite runs with--no-default-lib, as on x64.-mm=rcnever 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.Test plan
ctest -C Release -L x86with-DTSLANG_TEST_X86=ON: 1395/1395 pass, 3 disabled.ctest -j 16 -C Release: 2771/2771. That's the previous 2769 plus the two new foreign-target import tests.TSLANG_TEST_X86=OFF,CTestTestfile.cmakeis identical to main's apart from the two new tests, and the x64 runner scripts are byte-identical.RT_MANIFEST, and no temporary files are left behind.check-x86-libs.sh,check-x86-run.shandcheck-x86-eh.shall ok.compare-ir.shon x64--emit=llvm: unchanged apart from the known nondeterministic files.🤖 Generated with Claude Code