5
2
Fork
You've already forked lightening
2

Support Windows and Microsoft x64 ABI #1

Open
h-c-mueller wants to merge 1 commit from h-c-mueller/lightening:fix-windows into main
pull from: h-c-mueller/lightening:fix-windows
merge into: guile:main
guile:main
guile:reinterpret
guile:callr-fix3
First-time contributor
Copy link

This patch fixes compilation and linking issues for Windows (MinGW)
and Cygwin. It ensures that JIT symbols are correctly exported in DLL
builds and provides a fallback for the missing ffs() function in the
Windows C runtime.

  • lightening.h (JIT_API): Do not use the hidden visibility attribute
    on Windows or Cygwin. The PE/COFF format used on these platforms
    requires standard visibility for symbols to be correctly exported
    when building Guile as a DLL.

  • lightening/x86-cpu.c (__ffs): New static function. Fallback
    implementation using __builtin_ffs() as the standard POSIX ffs()
    is unavailable in MSVCRT/UCRT.
    (ffsw): Use the internal __ffs wrapper for bit-scan operations to
    ensure consistency across all Windows toolchains.

Note: an identical patch has been provided as guile/guile@71d21b9ae6 in guile/guile#68.

This patch fixes compilation and linking issues for Windows (MinGW) and Cygwin. It ensures that JIT symbols are correctly exported in DLL builds and provides a fallback for the missing ffs() function in the Windows C runtime. * lightening.h (JIT_API): Do not use the hidden visibility attribute on Windows or Cygwin. The PE/COFF format used on these platforms requires standard visibility for symbols to be correctly exported when building Guile as a DLL. * lightening/x86-cpu.c (__ffs): New static function. Fallback implementation using __builtin_ffs() as the standard POSIX ffs() is unavailable in MSVCRT/UCRT. (ffsw): Use the internal __ffs wrapper for bit-scan operations to ensure consistency across all Windows toolchains. Note: an identical patch has been provided as https://codeberg.org/guile/guile/commit/71d21b9ae6 in https://codeberg.org/guile/guile/pulls/68.
Collaborator
Copy link

@h-c-mueller how do you build this for testing?
I'd merge but I want to test it first.

Thank you for the pr

@h-c-mueller how do you build this for testing? I'd merge but I want to test it first. Thank you for the pr
Author
First-time contributor
Copy link

I updated the patch, which now includes a full test suite update. (Note: This update incorporates changes across three PR iterations to ensure a clean final state).

The command make -C tests test-native now runs successfully on MSYS2 for MSYS (a Cygwin clone), MINGW32, MINGW64, and UCRT64. The command make -C tests CC=clang test-native passed on CLANG64. Verification on Linux x64 also passed without warning.

I removed the inclusion of <sys/mman.h> from lightening/lightening.c as it appears to be no longer required by the core logic. While I am confident in this change, I was unable to verify it on the following architectures: aarch64, arm, mips, ppc, riscv, and s390. I recommend a brief cross-check on these platforms to ensure no indirect dependencies were broken.

I updated the patch, which now includes a full test suite update. (Note: This update incorporates changes across three PR iterations to ensure a clean final state). The command `make -C tests test-native` now runs successfully on MSYS2 for MSYS (a Cygwin clone), MINGW32, MINGW64, and UCRT64. The command `make -C tests CC=clang test-native` passed on CLANG64. Verification on Linux x64 also passed without warning. I removed the inclusion of `<sys/mman.h>` from `lightening/lightening.c` as it appears to be no longer required by the core logic. While I am confident in this change, I was unable to verify it on the following architectures: aarch64, arm, mips, ppc, riscv, and s390. I recommend a brief cross-check on these platforms to ensure no indirect dependencies were broken.
h-c-mueller changed title from (削除) Fix Windows/Cygwin build visibility and missing ffs() function (削除ここまで) to Support Windows and Microsoft x64 ABI 2026年01月15日 11:53:30 +01:00
Author
First-time contributor
Copy link

I needed more pushes to get it nice, now I have it done. I also found an issue but the fix comes in a separate PR.

Support Windows and Microsoft x64 ABI
The command `make -C tests test-native' now runs successfully on
MSYS2 for MSYS (a Cygwin clone), MINGW32, MINGW64, and UCRT64.
The command `make -C tests CC=clang test-native' passed on CLANG64.
Finally, the command:
'make -C tests check TARGETS="native ia32 aarch64" \
 CC_IA32=i686-linux-gnu-gcc \
 CC_AARCH64=aarch64-linux-gnu-gcc'
passes on Linux x86_64. All without warnings.
Patch regarding __ffs is based on ideas from Michael Gran.
* lightening.h (JIT_API): Update copyright year. Disable visibility
 attributes on Cygwin and Windows, as they are not supported the
 same way as on ELF platforms.
* lightening/aarch64.c: Update copyright year. Add `maybe_unused'
 attributes to instruction helpers generated by the
 `DEFINE_PATCHABLE_INSTRUCTION' macro to suppress warnings.
* lightening/lightening.c: Update copyright year. Remove
 inclusion of `<sys/mman.h>' since it is no longer required. Fix
 warnings from -Wundef.
* lightening/lightening.c (jit_address): Cast ternary operator results
 to `(jit_pointer_t)' and wrap in parentheses to avoid pointer type
 mismatch warnings in Clang.
* lightening/x86-cpu.c (__ffs): Update copyright year. New static
 helper to wrap `__builtin_ffs' on Windows/MinGW where the standard
 `ffs' function is missing.
* lightening/x86-cpu.c (ffsw): Use the new `__ffs' helper.
* lightening/x86.c (reset_abi_arg_iterator): Update copyright year.
 Simplify Cygwin 64-bit and Windows 64-bit detection logic without
 changing any code path.
* tests/Makefile: Add `EXEEXT' support for Windows. Update `PROGS' and
 `clean' rules. Refactor test targets to correctly use dependencies
 with extensions. Update Debian package installation instructions and
 dependencies. Add -Wundef since related warnings have been found.
* tests/call_10_2.c (run_test_double): Adjust register usage for the
 Microsoft x64 ABI. Only use `JIT_F0' through `JIT_F4' as scratch
 registers to comply with the MS ABI.
* tests/test.h (main_helper): Use `uint8_t *' for arena_base instead of
 `char *'. Implement Windows-specific JIT memory allocation using
 `CreateFileMapping' and `MapViewOfFile'. Add proper cleanup using
 `UnmapViewOfFile' and `CloseHandle'.
I needed more pushes to get it nice, now I have it done. I also found an issue but the fix comes in a separate PR. ``` Support Windows and Microsoft x64 ABI The command `make -C tests test-native' now runs successfully on MSYS2 for MSYS (a Cygwin clone), MINGW32, MINGW64, and UCRT64. The command `make -C tests CC=clang test-native' passed on CLANG64. Finally, the command: 'make -C tests check TARGETS="native ia32 aarch64" \ CC_IA32=i686-linux-gnu-gcc \ CC_AARCH64=aarch64-linux-gnu-gcc' passes on Linux x86_64. All without warnings. Patch regarding __ffs is based on ideas from Michael Gran. * lightening.h (JIT_API): Update copyright year. Disable visibility attributes on Cygwin and Windows, as they are not supported the same way as on ELF platforms. * lightening/aarch64.c: Update copyright year. Add `maybe_unused' attributes to instruction helpers generated by the `DEFINE_PATCHABLE_INSTRUCTION' macro to suppress warnings. * lightening/lightening.c: Update copyright year. Remove inclusion of `<sys/mman.h>' since it is no longer required. Fix warnings from -Wundef. * lightening/lightening.c (jit_address): Cast ternary operator results to `(jit_pointer_t)' and wrap in parentheses to avoid pointer type mismatch warnings in Clang. * lightening/x86-cpu.c (__ffs): Update copyright year. New static helper to wrap `__builtin_ffs' on Windows/MinGW where the standard `ffs' function is missing. * lightening/x86-cpu.c (ffsw): Use the new `__ffs' helper. * lightening/x86.c (reset_abi_arg_iterator): Update copyright year. Simplify Cygwin 64-bit and Windows 64-bit detection logic without changing any code path. * tests/Makefile: Add `EXEEXT' support for Windows. Update `PROGS' and `clean' rules. Refactor test targets to correctly use dependencies with extensions. Update Debian package installation instructions and dependencies. Add -Wundef since related warnings have been found. * tests/call_10_2.c (run_test_double): Adjust register usage for the Microsoft x64 ABI. Only use `JIT_F0' through `JIT_F4' as scratch registers to comply with the MS ABI. * tests/test.h (main_helper): Use `uint8_t *' for arena_base instead of `char *'. Implement Windows-specific JIT memory allocation using `CreateFileMapping' and `MapViewOfFile'. Add proper cleanup using `UnmapViewOfFile' and `CloseHandle'. ```
hahnjo left a comment
Copy link

In principle the changes in lightening/ look OK to me. I didn't check a build in LilyPond, I can do that if wanted.

I would prefer to have separate commits, they make it easier to associate commit message and explanation with the actual code changes, but I'm not a maintainer 🤷

In principle the changes in `lightening/` look OK to me. I didn't check a build in LilyPond, I can do that if wanted. I would prefer to have separate commits, they make it easier to associate commit message and explanation with the actual code changes, but I'm not a maintainer 🤷
@ -318,3 +318,3 @@
iter->argc = argc;
iter->args = args;
#if (defined(__CYGWIN__) || defined(_WIN64)) && __X64
#if (defined(__CYGWIN__) && defined(__x86_64__)) || defined(_WIN64)
First-time contributor
Copy link

To be honest, I found the previous conditions easier to read: "Is it targeting Windows and 64-bit?" Now it's "Is it Cygwin and 64-bit, or is it _WIN64 which implicitly means 64-bit?

To be honest, I found the previous conditions easier to read: "Is it targeting Windows and 64-bit?" Now it's "Is it Cygwin and 64-bit, or is it `_WIN64` which implicitly means 64-bit?
This pull request has changes conflicting with the target branch.
  • tests/Makefile
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix-windows:h-c-mueller-fix-windows
git switch h-c-mueller-fix-windows

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff h-c-mueller-fix-windows
git switch h-c-mueller-fix-windows
git rebase main
git switch main
git merge --ff-only h-c-mueller-fix-windows
git switch h-c-mueller-fix-windows
git rebase main
git switch main
git merge --no-ff h-c-mueller-fix-windows
git switch main
git merge --squash h-c-mueller-fix-windows
git switch main
git merge --ff-only h-c-mueller-fix-windows
git switch main
git merge h-c-mueller-fix-windows
git push origin main
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
guile/lightening!1
Reference in a new issue
guile/lightening
No description provided.
Delete branch "h-c-mueller/lightening:fix-windows"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?