-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
32-bit x86: Alignment issues for LL byval params #1356
Comments
Today's LLVM is able to happily compile all modules (incl. unittests) with all alignment attributes enabled, for both 32-bit and 64-bit MSVC.
|
I don't think the MS ABI really works with aligned byval arguments.
Clang generates:
|
MSVC won't compile my example. Instead, it will issue error C2719:
|
I was afraid it was that kind of limitation. We could work around that by copying the original argument at the caller's site and passing a pointer to that aligned copy (that's what we do when passing value types > 64bit by value on Win64), at least for |
Would |
Thanks for the hint, that could work (as long as the argument stack base is appropriately aligned too). Is there a reason why LLVM doesn't directly support aligned byval params for MSVC targets (32-bit at least)? I thought LLVM tries to be quite ABI-agnostic and that it's the front-end's responsibility to control the ABI... e.g., we manually implement the System V ABI (partially) for non-Windows x86_64 targets. |
As for regular args due to LDC issue ldc-developers#1356. This fixes runnable/ldc_cabi1 and so dmd-testsuite passes again.
As for regular args due to LDC issue ldc-developers#1356. This fixes runnable/ldc_cabi1 and so dmd-testsuite passes again.
As for regular args due to LDC issue ldc-developers#1356. This fixes runnable/ldc_cabi1 and so dmd-testsuite passes again.
As for regular args due to LDC issue ldc-developers#1356. This fixes runnable/ldc_cabi1 and so dmd-testsuite passes again.
@kinke What happens with GDC/DMD with the following:
I'd guess the following happens:
|
While I could figure that out (another time, just passing by before going to bed), let me first say that we're not trying to mimic the ABI of other compilers in all aspects. What you described is what I would expect from LLVM, regardless of the actual target (nit-picking: I'd expect 31 bytes of padding inbetween the single-byte bool and the struct). If the bool was passed in a register, I'd simply expect an aligned function arguments stack base/incoming stack pointer. |
This fixes the debug unittests. See ldc-developers/ldc#1356.
druntime module |
Is there a need to workaround this in intel-intrinsics? What should I avoid? |
This fixes the debug unittests. See #1356.
CI tests fail on Ubuntu with LDC 1.30.0 for the compiled 32-bit binaries. And the culprit is the Cent alignment. The problem is not reproducible with the older LDC 1.20.1 Looks like all this alignment stuff is rather fragile: https://issues.dlang.org/show_bug.cgi?id=22980 ldc-developers/ldc#1356 (comment) The 16 byte alignment is not necessary in principle. Except for maybe some C library bindings, which require compatibility with the '__int128' type. C compilers don't support '__int128' for 32-bit code though. For now just use the default struct alignment for Cent. This problem can be investigated later and the 16 byte alignment may possibly return at least for the 64-bit binaries.
CI tests fail on Ubuntu with LDC 1.30.0 for the compiled 32-bit binaries. And the culprit is the Cent alignment. The problem is not reproducible with the older LDC 1.20.1 Looks like all this alignment stuff is rather fragile: https://issues.dlang.org/show_bug.cgi?id=22980 ldc-developers/ldc#1356 (comment) The 16 byte alignment is not necessary in principle. Except for maybe some C library bindings, which require compatibility with the '__int128' type. C compilers don't support '__int128' for 32-bit code though. For now just use the default struct alignment for Cent. This problem can be investigated later and the 16 byte alignment may possibly return at least for the 64-bit binaries.
User code may crash when decorating certain function parameters with an LLVM
align
attribute for MSVC targets.It may lead to LLVM assertions in the inliner too, I don't remember exactly.For 64-bit MSVC, the issue occurs for the specialNot an issue anymore with recent LLVM.sret
parameter. We currently work around it by not specifying the alignment for the pointer parameter, but still use the alignment whenalloca
ting the result.For 32-bit MSVC,
byval
pointer parameters arealsoaffected (we don't usebyval
at all for the Win64 ABI). The resulting user code crashes (when enabling thealign
attribute) seem to indicate that LLVM isn't aligning the function parameters stack correctly.Linux and OSX don't have these issues.
Pinging @majnemer. :)
The text was updated successfully, but these errors were encountered: