Skip to content

winsup: AArch64 enablement for aarch64-pc-cygwin - #356

Open
aswin-mcw wants to merge 8 commits into
msys2:msys2-3.6.10from
Multicorewareinc:aarch64-minimal
Open

aswin-mcw wants to merge 8 commits into
msys2:msys2-3.6.10from
Multicorewareinc:aarch64-minimal

Conversation

@aswin-mcw

@aswin-mcw aswin-mcw commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Adds the msys2-runtime pieces needed to build and run the runtime on AArch64
(Windows on ARM64), targeting aarch64-pc-cygwin. All new build steps are
gated behind compiler probes or arch conditionals, so x86/x86_64 are unaffected.

Changes

Build / configury

  • getprocaddrarm64 — probe for aarch64-w64-mingw32-gcc, build under a new
    HAVE_MINGWARM64_CC. Never errors when absent.
  • configure: allow skipping cygserver and utils--disable-cygserver /
    --disable-utils for stage-1 bootstrap. Both default to enabled.
  • console-helper(arm64)--enable-mingw-utils builds only the
    utils/mingw host tools. Defaults off.

Runtime (winsup/cygwin)

  • AArch64 fast_cwd — adds winsup/cygwin/aarch64/fastcwd.cc.
  • uname — report "aarch64" for PROCESSOR_ARCHITECTURE_ARM64 (was
    "unknown").
  • exit_process — narrow the stale TODO to the missing ARMNT case.
  • fix argv corruption in quoted()strcpy (cmd, cmd + 1) overlaps;
    AArch64's SIMD strcpy duplicates bytes and mangles command lines from a
    native parent such as cmd.exe. Use memmove.

Diagnostics

  • strace(arm64) — crash reporter to localise the ARM64 segfault (#20).

The aarch64-pc-cygwin toolchain

Built and validated with a full cross toolchain targeting aarch64-pc-cygwin,
built on an x86_64-pc-msys host and installable via pacman: binutils, a
two-stage GCC (C, C++, libstdc++, libgomp, libatomic, libquadmath), and the
MSYS2 runtime itself (msys-2.0.dll), bootstrapped with stage-1 GCC and
rebuilt with stage-2.

AArch64 support in Cygwin/newlib this builds on

MSYS2-runtime is a friendly fork of Cygwin and rebases onto upstream Cygwin
releases, so the bulk of the AArch64 enablement lives in Cygwin/newlib
itself
. The changes in this PR only build and run on top of that work — they
are not usable without it.

That AArch64 port has been a sustained effort since early 2025 (first
patches landed in March 2025), and a large share of the commits below were
authored by our team, with several still under review. The remainder is other
upstream AArch64 work we build on. Full per-commit authorship is in the Git
history.

Merged upstream

64 commits (click to expand)

Under review (cygwin-patches)

Notes for reviewers

  • Targets msys2-3.6.10.
  • winsup/configure is not yet regenerated in this PR; the configure.ac
    change needs autoreconf to take effect. I can add the regenerated
    configure if you would prefer it in-tree.

Add winsup/cygwin/aarch64/fastcwd.cc, the AArch64 counterpart to the
x86_64 fast current-working-directory probing used by path_conv.

(cherry picked from commit 61007db)

@dscho dscho left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

The *-*-msys change (and maybe also the __MSYS__ change) should be addressed differently, though, as the MSYS2 runtime build process now uses *-pc-cygwin as host triplet. (see #303).

Comment thread newlib/libc/include/malloc.h Outdated

extern void *malloc (size_t);
#ifdef __CYGWIN__
#if defined(__CYGWIN__) || defined(__MSYS__)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit curious that this is needed for ARM64, but not for x64?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right — it's only needed because our aarch64 build defines MSYS (triple aarch64-pc-msys); x64 builds as *-pc-cygwin so CYGWIN already covers it. Once we retarget the toolchain to aarch64-pc-cygwin, this change isn't needed and we'll drop it.

Comment thread newlib/configure.host Outdated
# Don't use for these since they provide their own setjmp.
case ${host} in
*-*-sco* | *-*-cygwin*)
*-*-sco* | *-*-cygwin* | *-*-msys*)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to revert #303. Would you be able to adjust the aarch64-* toolchain to recapitulate the change from x86_64-pc-msys to x86_64-pc-cygwin?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed — this was unintentionally reverting #303 (we'd missed that it had landed). We'll recapitulate the x86_64-pc-msys → x86_64-pc-cygwin change for aarch64-* instead of re-adding --msys*, so this hunk goes away.

@aswin-mcw

Copy link
Copy Markdown
Author

Very nice!

The *-*-msys change (and maybe also the __MSYS__ change) should be addressed differently, though, as the MSYS2 runtime build process now uses *-pc-cygwin as host triplet. (see #303).

Thanks for catching this! You're right — #303 was merged fairly recently and we hadn't noticed it, so we didn't realize these changes were re-introducing the --msys* triple that #303 had deliberately removed. That explains the MSYS/--msys* bits — they only exist because our aarch64 toolchain still targets aarch64-pc-msys, whereas x64 now builds as *-pc-cygwin.

We'll retarget our aarch64 toolchain to aarch64-pc-cygwin (mirroring the x86_64-pc-msys → x86_64-pc-cygwin change) and then drop both the --msys* change in configure.host/configure.ac and the MSYS guard in malloc.h. The remaining aarch64 runtime commits (fast_cwd, uname, exit_process, getprocaddrarm64) stand on their own. I'll push the updated series once the toolchain is rebuilt.

mayankag-qti and others added 6 commits September 9, 2026 16:28
uname() and uname_x() returned "unknown" as the machine name on ARM64
Windows.  Map PROCESSOR_ARCHITECTURE_ARM64 to "aarch64".

(cherry picked from commit 5bc1d33)
getprocaddrarm64.exe is now provided, so the "provide exes for these"
TODO only applies to the 32-bit ARM (ARMNT) helper.  Reword the comment
accordingly.

(cherry picked from commit 345e368)
…sent

Native ARM64 (PID_NOTCYGWIN) processes should be terminated gently via a
console helper instead of TerminateProcess.  Probe for aarch64-w64-mingw32-gcc
in winsup/configure.ac and build getprocaddrarm64 under the HAVE_MINGWARM64_CC
conditional.

The probe is done unconditionally (outside the with_cross_bootstrap /
mingw-progs block) and never errors when the compiler is absent, so the helper
builds on Windows-on-ARM cross setups (e.g. --with-cross-bootstrap) without
requiring the x86 MinGW compilers, and x86 hosts are unaffected.

Note: winsup/configure is generated; run autoreconf so the new
AC_CHECK_PROGS/AM_CONDITIONAL take effect.

Co-authored-by: chandru-mcw <chandru.kumaresan@multicorewareinc.com>
(cherry picked from commit 4b38982)
This patch adds configure options allowing to disable build of cygserver
and Cygwin utilities. This is useful when one needs to build only
cygwin1.dll and crt0.o with stage1 compiler that is not yet capable of
linking executables as it is missing cygwin1.dll and crt0.o.

Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
The ARM64 runtime shipped zero winsup utils because it configures
--disable-utils --without-mingw-progs --with-cross-bootstrap, which skips the
entire utils/ tree (including the utils/mingw/ MinGW host tools). This adds a
scoped opt-in so the cross build produces the MinGW host tools through automake,
exactly as the native x86_64 build does -- no hand-written compile line -- while
the ~26 cygwin-linked utils in utils/ stay deferred.

winsup/configure.ac:
  - new --enable-mingw-utils (default off) => AM_CONDITIONAL(BUILD_MINGW_UTILS)
  - enter the MinGW probe block when --enable-mingw-utils is given even under
    --without-mingw-progs, so @MINGW_CXX@ resolves (the PKGBUILD overrides it to
    aarch64-w64-mingw32-g++)
  - the i686/x86_64 MinGW compilers become optional under the opt-in (they are
    absent on the ARM64 box); add HAVE_MINGW32_CC / HAVE_MINGW64_CC, mirroring
    the existing HAVE_MINGWARM64_CC

winsup/Makefile.am: enter utils/ under BUILD_MINGW_UTILS as well as BUILD_UTILS.

winsup/utils/Makefile.am: build the cygwin-linked bin_PROGRAMS only under
  BUILD_UTILS (unchanged for x86_64); descend into mingw/ under CROSS_BOOTSTRAP
  or BUILD_MINGW_UTILS.

winsup/utils/mingw/Makefile.am: in mingw-utils-only mode build just
  cygwin-console-helper and ldh; build getprocaddr32/64/arm64 each only when its
  compiler is present.

Default off => a strict no-op for every existing configuration.
strace.exe segfaults on aarch64-pc-msys when tracing a process (issue
#20).  The only signal today is the shell's bare "Segmentation fault"
line; the fault reproduces only on the ARM64 box, so root-causing it
needs a fault address we currently don't have.

Install a vectored exception handler plus a last-resort unhandled-filter
in main2() that, on a genuine fault, print the exception code, the
faulting instruction address, and -- decisively -- the module + offset
that address resolves to (via GetModuleHandleExW FROM_ADDRESS), so we
can tell immediately whether the PC is in strace.exe's own logic or
inside msys-2.0.dll.  A few registers are dumped from the CONTEXT record
(ARM64 and x86_64 branches).  GCC-SEH pseudo-exceptions, breakpoints and
the SetThreadName marker are skipped so only real crashes are reported;
the trace file is flushed first so no captured lines are lost.

Inert unless a fault occurs, pure win32/ntdll (no cygwin runtime
dependency), so it is safe in this -lntdll util and stays permanently.
Compile-checked for both aarch64-w64-mingw32 and x86_64 with -Wall
-Wextra.
@aswin-mcw
aswin-mcw force-pushed the aarch64-minimal branch 2 times, most recently from 87b5d73 to a6e58e7 Compare September 9, 2026 11:09
quoted() deletes an in-place quote with strcpy (cmd, cmd + 1), where source
and destination overlap.  That is undefined, and only works by accident on
implementations that copy a byte at a time.

The AArch64 SIMD strcpy rounds the source pointer down to a 16-byte boundary
and loads that entire block, so storing it back one byte lower duplicates
bytes inside the block while keeping the string length.  Command lines from a
native parent such as cmd.exe therefore arrived mangled, with the damage
depending on where the string happened to sit in memory.

Use memmove, which is defined for overlapping buffers, in both places.
@aswin-mcw aswin-mcw changed the title winsup/newlib: AArch64 enablement for the aarch64-pc-msys target winsup: AArch64 enablement for aarch64-pc-cygwin Sep 9, 2026
@aswin-mcw

Copy link
Copy Markdown
Author

@dscho The retarget to aarch64-pc-cygwin is done and this branch is
updated accordingly. The two commits that only existed for the
aarch64-pc-msys triple are dropped, so the PR no longer touches newlib
and has no remaining *-*-msys* references (9 commits → 8).

@dscho

dscho commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@aswin-mcw this is great! I am currently quite busy preparing for a new Git for Windows release, which is complicated by the fact that we have to migrate away from MINGW64. So I cannot have a look at this right now. But I'm really excited about this and hope to be able to assist soon!

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.

5 participants