Skip to content

Skip the CPU detection on MinGW like MSVC for amd64 - #22

Open
illwieckz wants to merge 13 commits into
masterfrom
illwieckz/mingw-2
Open

illwieckz wants to merge 13 commits into
masterfrom
illwieckz/mingw-2

Conversation

The only known working implementation is for i686 MSVC.

- detection was already disabled and marked at not working with amd64 MSVC,
- detection was already disabled on amd64 MinGW because amd64 Windows was tested, not just amd64 MSVC,
- there is no MinGW implementation in the code,
- this disables detection on MinGW explicitely whatever the architecture.
@illwieckz illwieckz added the enhancement New feature or request label Jun 22, 2026
@illwieckz
illwieckz force-pushed the illwieckz/mingw-2 branch from 275fad6 to 8edc038 Compare July 3, 2026 00:20
@illwieckz
illwieckz force-pushed the illwieckz/mingw-2 branch from 8edc038 to 2265238 Compare July 13, 2026 07:07
@slipher

slipher commented Jul 18, 2026

Copy link
Copy Markdown
Member

Microsoft longjmp documentation warns:

  • Don't use longjmp to transfer control out of an interrupt-handling routine unless the interrupt is caused by a floating-point exception. In this case, a program may return from an interrupt handler via longjmp if it first reinitializes the floating-point math package by calling _fpreset.

  • Don't use longjmp to transfer control from a callback routine invoked directly or indirectly by Windows code.

Anyway as discussed elsewhere, since 32-bit Windows is obsolete it's probably not worth trying to port this to MinGW.

@illwieckz

Copy link
Copy Markdown
Member Author

Actually the code is already entirely skipped on amd64 with MSVC:

#if defined(NACL_WINDOWS_MSC_64)
static int CheckCPUFeatureDetection(NaClCPUFeaturesX86 *cpuf) {
  /* Unfortunately the asm_ tests will not work on 64-bit Windows */
  return 0;
}
#else

So actually my second commit was adding with MinGW something that was even not implemented with MSVC (on amd64).

So we can just decide to just always skip the code on MinGW, which is my first commit.

@illwieckz
illwieckz force-pushed the illwieckz/mingw-2 branch from 2265238 to 229f874 Compare July 18, 2026 11:02
@illwieckz

Copy link
Copy Markdown
Member Author

So I removed the second commit. MinGW now does like MSVC amd64: skip the tests.

We already know we can skip the tests since MSVC does it in all cases with amd64.

@illwieckz illwieckz changed the title CPU detection for MinGW Skip the CPU detection on MinGW like MSVC for amd64 Jul 18, 2026
@illwieckz

illwieckz commented Jul 18, 2026 •

Copy link
Copy Markdown
Member Author

It happened that it was already skipped on MinGW amd64 too because it was just testing for windows-amd64, but now this also skips on MinGW i686. Skipping a code that is known to be skippable is good enough maintenance for an obsolete platform.

@illwieckz
illwieckz force-pushed the illwieckz/mingw-2 branch from 229f874 to b67a76b Compare July 18, 2026 11:12
@illwieckz

illwieckz commented Jul 18, 2026 •

Copy link
Copy Markdown
Member Author

To quote the remaining commit message:

win32: skip some CPU detection on Windows with MinGW like amd64 MSVC

The only known working implementation is for i686 MSVC.

- detection was already disabled and marked at not working with amd64 MSVC,
- detection was already disabled on amd64 MinGW because amd64 Windows was tested, not just amd64 MSVC,
- there is no MinGW implementation in the code,
- this disables MinGW detection explicitely whatever the architecture.

@illwieckz
illwieckz force-pushed the illwieckz/mingw-2 branch from b67a76b to 0f62129 Compare July 18, 2026 11:16
@illwieckz

Copy link
Copy Markdown
Member Author

@slipher I need this to get the i686 MinGW build working.

@illwieckz

Copy link
Copy Markdown
Member Author

I added a patch to silence a warning.

@slipher

slipher commented Oct 6, 2026

Copy link
Copy Markdown
Member

@slipher I need this to get the i686 MinGW build working.

I thought you gave up on using MinGW for now since the ones in Debian are too old to build it (needs GCC 16; also may depend on the right TLS flavor being configured).

In view of Unvanquished/Unvanquished#3572 maybe we will never need to build an x86 MinGW version.

@illwieckz

Copy link
Copy Markdown
Member Author

The Windows MinGW we use in CI cannot build for i686?

Move the Windows alignment attribute after the struct keyword so
GCC accepts the declaration without triggering -Werror=attributes.
@slipher

slipher commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

The Windows MinGW we use in CI cannot build for i686?

I used a toolchain there downloaded from a Github release, which can build for i686 (if downloading a different variant), yes, but only on a Windows host! No doubt Linux binaries can be found somewhere, but you have been saying that you prefer to have separately pre-built MSVC binaries instead of having to obtain the needed MinGW toolchain for a deps build.

Enable SSE2 for x86-32 Windows builds so GCC can compile SSE
intrinsics such as _mm_sfence() without a target-specific option
mismatch.
Add the GCC compiler check to the existing __builtin_unreachable()
workaround so GCC recognizes that NaClSwitch does not return.
Add GCC-compatible inline assembly for accessing Windows segment
registers and the stack pointer while preserving the existing MSVC
implementation.

I used an LLM to convert the syntax.
@illwieckz

illwieckz commented Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

The Windows MinGW we use in CI cannot build for i686?

My question was meaningless, I probably misread something at the time.

I used a toolchain there downloaded from a Github release, which can build for i686 (if downloading a different variant), yes, but only on a Windows host!

Yes of course they also provide some MinGW that can build i686 exe, except it requires some extra fixes in the test code.

No doubt Linux binaries can be found somewhere

I wasn't looking for some Linux MinGW.

but you have been saying that you prefer to have separately pre-built MSVC binaries instead of having to obtain the needed MinGW toolchain for a deps build.

Actually I want pre-build Windows binaries yes, but I would prefer to be able to build them myself with MinGW if possible.

Cast the stack frame address through uintptr_t to avoid an integer-to-pointer
size warning when building the 32-bit Windows test with GCC.
Add a tls_edit_i686 build option that makes the native tls_edit
host tool use the x86-32 build environment, reusing the existing
32-bit MinGW toolchain instead of requiring a separate x86-64 MinGW
toolchain.

Supposedly an amd64 Windows machine can run a native i686 host tool,
so we don't need to cross-compile the host tools.

The option requires mingw=1 and a 32-bit target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants