-
-
Notifications
You must be signed in to change notification settings - Fork 268
Fix tests/codegen/mangling.d
on x86
#4661
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
Conversation
I very much doubt we want to change the low-level calling convention, not matching up with the frontend CC. And definitely not for working around a test failure (where the the test might need adjustments, but I don't want to verify myself right now). |
Yes, I was hesitant to go further with touching |
AFAICT, DMD doesn't automagically fix up anything either, or change the calling convention - it doesn't fixup the |
Well, there seems to be plenty of segfaults in the 32bit tests so I think we can safely rule out changing the calling convention
Yes, dmd doesn't do anything special to naked functions, nor does ldc2. They both keep the default calling convention for the architecture, which is C for dmd and stdcall for ldc2. I don't have a problem with this. My only issues was that, while calling conventions can mostly be ignored, you can't do that with naked assembly functions and I didn't want to have the same code that works with dmd be completely broken with ldc2, though we are talking about naked assembly so maybe I'm making a bigger deal then it needs to be. Either way, given the test failures I think it would be better to just change the test file to make it pass and live with the differences between ldc2 and dmd when it comes to naked assembly functions on x86. |
Nope, only for 32-bit x86, there's a D-specific ABI/CC, where LDC follows DMD (except for NOT reversing the args IIRC, but not 100% sure), which is very similar to stdcall, except that it tries to use one register: https://dlang.org/spec/abi.html#function_calling_conventions |
See e.g. here, required for DMD too: https://github.com/dlang/phobos/blob/master/std/internal/math/biguintx86.d#L623 |
Neat! Having a formal document describing the spec seems to make it easier to understand as opposed to looking at the code and working my way backwards. |
Hah! :D - Well I do it that way most of the time too, not trusting potentially outdated docs/specs. ;) Edit: E.g., the spec mentions that this is the CC for Windows x86. In reality, it's the one for all 32-bit x86 targets. Well, not really, Android is different, of course... |
@@ -46,6 +46,8 @@ version(AsmX86) | |||
else | |||
static assert(naked_cppFunc.mangleof == "_ZN15cpp_naked_funcs13naked_cppFuncEd"); | |||
|
|||
import ldc.attributes : callingConvention; | |||
@callingConvention("ccc") | |||
int naked_dFunc(double a) { asm { naked; ret; } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest changing the param to a 32-bit integer, which is passed in a register on 32-bit x86, and so the plain ret
should still work.
Avoid issues on x86 with the calling convention by having an int argument, which can be passed through a register, therefore, lifting the burden of cleaning the stack, instead of a double. Signed-off-by: Andrei Horodniceanu <[email protected]>
tests/codegen/mangling.d
on x86
I've looked over this again with a rested mind and I think I finally understand what you mean. First of all, ldc is consistent with dmd when it comes to the calling convention of naked assembly functions on x86 (like you told me), on most operating system that being the one described in the spec. What threw my off was:
All in all, I just wanted to thank you for being patient with me and taking the time to explain it. |
Oh, you're very welcome, thank you for cleaning up this stuff showing up when running the tests on non-CI-tested platforms, investigating and fixing it all yourself! 👍
Oh okay, I was expecting it'd segfault too. No wonder this caused a bit of confusion. |
The test
codegen/mangling.d
has been failing for me on x86 with a segmentation fault because of stack corruption due to the function:ldc/tests/codegen/inputs/mangling_definitions.d
Line 49 in 93afbfa
not respecting the stdcall convention which is set as the default for functions with D linkage on x86.
I've tried to fix this by changing the default calling convention for naked assembly functions on x86 and adding an attribute in the
mangling.d
file to specify the C calling convention.I'm not sure how this test has been passing on windows x86.