Repository navigation
Conversation
|
|
||
| define nt_host | ||
| $(call set_autoconf_var,NT,y) | ||
| $(call set_kernel_config,INIT_STACK_ALL_ZERO,n) |
There was a problem hiding this comment.
It's used to make my old Cygwin GCC 11 happy. We can remove it if we maintain our own newer Cygwin cross compiler.
There was a problem hiding this comment.
It was only needed for the old Cygwin GCC 11 (Kconfig probes the MinGW gcc, which supports -ftrivial-auto-var-init, while the kernel was built with GCC 11, which doesn't). With a current Cygwin GCC it builds fine, so it's removed.
|
Just to make the LKL run under vanilla 64-bit Win32 environment instaed of Cygwin. |
|
@xdqi thanks for the patchset and sorry for the late response (resulting required to rebase your branch..). one quick question: do you think it's better to have a separate test matrix other than current |
|
@xdqi read through the patches briefly. I'd like to test this new platform over gh actions (or any CI) during any commits, because it's very hard to track down which commits break this feature, especially the platform is non-Linux one. It would be nice to include a test update in this patchset if possible. |
|
@thehajime |
On Win64 (MinGW-w64) long is 32 bit (LLP64) while the LKL kernel is built for LP64, where long is 64 bit. Using long in the host interface breaks syscall parameters, UAPI struct layouts and pointer casts between the application and the kernel. Add lkl_long_t / lkl_ulong_t (arch/lkl/include/uapi/asm/lkl_long.h), which are long long on LLP64 hosts and long everywhere else, so nothing changes for the existing hosts. headers_install.py replaces long with lkl_long_t in the installed UAPI headers and adds the lkl_long.h include. The host library and the tests use lkl_long_t for syscall parameters, ioctl pointer casts and return values, and print them with %lld. Also fix the case of the Windows header names in virtio_net_wintap.c so it builds on case sensitive file systems. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
CONFIG_LKL_HOST_MEMCPY/MEMSET/MEMMOVE are enabled in the kernel config, so the kernel expects these lkl_host_ops to be set. Without them the kernel does not start on Win64. Wrap the libc routines so that the lkl_ulong_t signature matches. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
On Win64 longjmp() unwinds the stack with RtlUnwindEx(), which fails when LKL jumps between the stacks of different threads. Define __USE_MINGW_SETJMP_NON_SEH so that setjmp() does not record a frame; longjmp() then only restores the registers. The Win64 jmp_buf also holds xmm registers and must be 16 bytes aligned, so align it inside struct lkl_jmp_buf. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
The kernel has to be built for LP64, but MinGW-w64 compilers are LLP64. Add a compiler shim, tools/lkl/scripts/win64-cc.sh, linked as x86_64-w64-mingw32-gcc from tools/lkl/bin, which is in PATH for the kernel build. It compiles the kernel with x86_64-pc-cygwin-gcc, which produces PE/COFF objects using the same MS x64 calling convention as MinGW, but with a 64 bit long. User space code is still compiled with the real MinGW-w64 gcc and talks to the kernel through lkl_long_t. The kernel link needs binutils with the NT weak externals fixes, see tools/lkl/scripts/binutils-build.sh. Build with: make -C tools/lkl CROSS_COMPILE=x86_64-w64-mingw32- Also skip <sys/resource.h> in disk-vfio-pci.c, MinGW does not have it. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
Linking LKL for Windows needs binutils with fixes for PE/COFF NT weak externals that are not upstream: - relocate the weak external aux entries in ld -r output (Octavian Purdila) - convert NT weak externals to local symbols in objcopy -G (Octavian Purdila) - resolve the weak externals by name instead of the stale tag index left by ld -r, which made objcopy -G resolve some of them to the wrong symbol (Sheldon Qi) binutils 2.47 implements linking NT weak externals natively, so the older "Fix linker error when using NT weak externals" patch is no longer needed. Instead of committing more prebuilt binaries, add binutils-build.sh, which downloads binutils 2.47, applies the patches from binutils-patches/ and installs the tools in $BINUTILS_PREFIX. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
Add a win64 job that cross compiles LKL on Linux and runs the tests with wine. win64-toolchain.sh installs x86_64-pc-cygwin-gcc and the MinGW-w64 gcc from the msys2-cross release packages (https://github.com/xdqi/msys-cross) and builds binutils with binutils-build.sh. Under wine the tap and wintap backends are not usable, so skip the tap test on Windows hosts and the wintap test when netsh is missing. Signed-off-by: Sheldon Qi <3365420+xdqi@users.noreply.github.com>
|
Thanks @tavip @thehajime, and sorry for the long delay. I rebased on the current master and reworked the series around your comments: No more committed binaries (@tavip): this PR no longer touches any binary. CI (@thehajime): there's a new Makefile.autoconf: the Other changes:
Native Linux boot/disk/net tests still pass. checkpatch's only remaining complaint is "do not add new typedefs" for |
| #endif | ||
|
|
||
| void *thread_stack(unsigned long *size) | ||
| void *thread_stack(lkl_ulong_t *size) |
There was a problem hiding this comment.
Switching to lkl_ulong_t int this files is not strictly required, but I agree it is more consistent changing it as well.
| #!/bin/sh | ||
| # SPDX-License-Identifier: GPL-2.0 | ||
| # | ||
| # Build GNU binutils with the PE/COFF NT weak externals fixes needed to |
There was a problem hiding this comment.
Awesome, thank you very much for cleaning this up!
lkl: Win64 (x86_64-w64-mingw32) support
Summary
This PR lets LKL run in a plain 64-bit Windows (MinGW-w64) environment instead of Cygwin/MSYS. Win64 uses the LLP64 data model (
longis 32 bit), while the LKL kernel is LP64 (longis 64 bit). The series bridges the two with an LKL-specific long type, builds the kernel with an LP64 compiler that uses the same calling convention as MinGW, and adds CI that runs the tests under wine.Changes
lkl_long_t/lkl_ulong_t(arch/lkl/include/uapi/asm/lkl_long.h):long longon LLP64 hosts andlongeverywhere else, so nothing changes for existing hosts.headers_install.pyreplaceslongwith these types in the installed UAPI headers. The host library and the tests use them for syscall parameters, pointer casts and return values.memcpy/memset/memmovehost ops.RtlUnwindEx(), which fails when LKL jumps between thread stacks.tools/lkl/scripts/win64-cc.sh, linked astools/lkl/bin/x86_64-w64-mingw32-gcc): compiles the kernel withx86_64-pc-cygwin-gcc, which emits PE/COFF with the MS x64 calling convention but is LP64. User space is compiled with the real MinGW-w64 gcc.tools/lkl/scripts/binutils-build.sh: builds binutils 2.47 with the NT weak externals patches LKL needs (tools/lkl/scripts/binutils-patches/), instead of committing prebuilt binaries.win64job that cross compiles on Ubuntu and runs the tests under wine.tools/lkl/scripts/win64-toolchain.shsets up the toolchain.Building
Toolchain:
x86_64-pc-cygwin-gcc(kernel, LP64)x86_64-w64-mingw32-gcc(user space, LLP64)tools/lkl/scripts/binutils-build.shTesting
Under wine: 100 tests, 89 ok, 0 failed, 11 skipped (lklfuse, hijack and vfio don't apply to Windows), including boot and the ext4/btrfs/vfat/xfs disk tests. Native Linux tests are unchanged.
Disclaimer
This pull request is mostly done by Claude Code, but I audited every line of code :).