-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segfaults with 128-bit integers on Windows #45
Comments
Do you know if your version of mingw supports the |
Yes, in a container running from the Docker image, I can successfully compile and run a
|
If it helps - using an older 4.08.0 installation, also using fdopen's opam distribution, I don't get a segfault. On 4.10.0 I do get it. |
Tried compiling the above test C progs with -O3 and they compiled/ran without error. My prior test w/ an ifdef check also worked. |
I should mention that the error started happening after we upgraded GCC (specifically: mingw) to version 9. We were previously on version 7 and there was no trouble. |
This gdb output seems to be saying that GCC optimized out the variable |
I found perl folks wrap code with a lot of guards to protect it from new GCC... perl11/cperl@c0b59c8 (this was a failed(?) commit to add even more |
@rseymour do you think we should such guards as well? |
We didn't end up going with them as the other fix worked, but I feel like it's the "right" way to do it until GCC fixes itself. |
Just coming back to this issue after a long while... Are we positive that this is a GCC bug? I can't tell from the previous discussion what the "misbehavior" might be. The fact that we observe the issue at O2 and above doesn't necessarily reflect a GCC issue; it could be that the bindings code does something illegal per the C standard, and that GCC only becomes "smart" at O2. Maybe the issue is this: when HAVE_INT128 is absent, some unspecified issue observable only at -O2 and above causes a segfault. Then there are two fixes:
Is this an accurate summary? Would you be open to the first fix? FYI, we're still running our entire infrastructure with the workaround outlined in this bug: we compile the test program, see if it segfaults, and if it does, recompile ocaml-stdint with -O0 to prevent the error from happening. Thanks! Jonathan |
I just discovered I was being bitten by this too - making A brief glance suggests this should work (a very brief glance suggests mingw-w64 doesn't provide the macro at all): diff --git a/lib/int128.h b/lib/int128.h
index 194e1ae..1db352d 100644
--- a/lib/int128.h
+++ b/lib/int128.h
@@ -1,7 +1,7 @@
#ifndef OCAML_INT128_H
#define OCAML_INT128_H
-#if defined(__SIZEOF_INT128__)
+#if defined(__SIZEOF_INT128__) || defined(__MINGW32__)
#define HAVE_INT128
typedef __int128_t int128;
#else
diff --git a/lib/uint128.h b/lib/uint128.h
index 3f97dab..864ea40 100644
--- a/lib/uint128.h
+++ b/lib/uint128.h
@@ -1,7 +1,7 @@
#ifndef OCAML_UINT128_H
#define OCAML_UINT128_H
-#if defined(__SIZEOF_INT128__)
+#if defined(__SIZEOF_INT128__) || defined(__MINGW32__)
#define HAVE_UINT128
typedef __uint128_t uint128;
#else |
This and forcing |
Your solution seems fine to me @dra27 -- do I understand you correctly that we need both Thanks for chiming in! Delightful to see you jump in on a Windows-only obscure optimization-related bug ;-). |
I haven't tested if A glorious coincidence to have jumped in within hours of you - I just happen to be hacking cap'n proto on mingw-w64 at the moment! 🙂 |
May I suggest adding a reference to this issue in a comment in the patch itself? I think actual comments are better than relying on the commit message in instances like these. |
I should have had a more in-depth glance, |
OK, I've dug a bit further. The problem is alignment, and it's not Windows-specific, I expect it's just not been seen on Linux or elsewhere yet. Here's the relevant assembly snippet for
however, this assumes that Unfortunately, this cast is invalid: #define Int128_val(v) (*((int128 *)Data_custom_val(v))) For whatever reason, in 4.07.1 it appears that the allocator much more readily allocated 16-byte aligned custom values (I think this is simply an image layout coincidence). |
With my colleague @msprotz, we observed segfaults related to 128-bit integers in some Windows OCaml programs using ocaml-stdint.
It turns out that even the test executable produced by
make test/stdint_test
segfaults, with no test running, as we show below.We are working on Windows 10 version 1909 (10.0.18363.720) with Cygwin 3.1.4-1, mingw64-x86_64-gcc 9.2.0, and OCaml 4.09.0 installed via OCaml and OPaM for Windows. If you want to quickly reproduce our config, you can pull a complete Docker image pulling the latest ocaml-stdint
master
(0785788) and building ocaml-stdint and its test suite. You can also rebuild the Docker image yourself using this Dockerfile.txt.Then, below is what we are observing:
As a workaround, my colleague @msprotz proposed to recompile ocaml-stdint with gcc optimizations disabled, which we did in tahina-pro/ocaml-stdint@99ac1fa, and there we no longer observe these segfaults.
The text was updated successfully, but these errors were encountered: