www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - llvm 3.6 and x86 (32-bit) varargs bad stack adjust

reply Dan Olson <gorox comcast.net> writes:
I haven't been paying attention, so perhaps this is old news.  D varargs
is broken with LDC 0.15.2 and LLVM 3.6 releases.  It looks like an
incorrect stack adjust is being added by backend after the function
call.  I noticed when I ran unittests and std.outbuffer plus other
unittests segv.

I tried LLVM 3.6.0, 3.6.1, and latest version on release_36 branch.  All
fail same way.  LLVM 3.5 seems ok.

Is there an Issue on this yet?
--
Dan
Jul 12 2015
parent reply "Kai Nacke" <kai redstar.de> writes:
On Sunday, 12 July 2015 at 07:09:33 UTC, Dan Olson wrote:
 I haven't been paying attention, so perhaps this is old news.  
 D varargs is broken with LDC 0.15.2 and LLVM 3.6 releases.  It 
 looks like an incorrect stack adjust is being added by backend 
 after the function call.  I noticed when I ran unittests and 
 std.outbuffer plus other unittests segv.

 I tried LLVM 3.6.0, 3.6.1, and latest version on release_36 
 branch.  All fail same way.  LLVM 3.5 seems ok.

 Is there an Issue on this yet?
 --
 Dan
Hi Dan! There is no ldc issue yet. Did you check with LLVM 3.7? If we can produce a LLVM bug report then we could try to set this as a release blocker. Branching for the 3.7 release is tomorrow. Regards, Kai
Jul 12 2015
next sibling parent Dan Olson <gorox comcast.net> writes:
https://github.com/ldc-developers/ldc/issues/1000

Do I win something for Issue 1000?
Jul 13 2015
prev sibling next sibling parent reply Dan Olson <gorox comcast.net> writes:
"Kai Nacke" <kai redstar.de> writes:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we can
 produce a LLVM bug report then we could try to set this as a release
 blocker. Branching for the 3.7 release is tomorrow.
No, I have not tried 3.7 and I won't have time for a couple days. I don't understand the history of why LDC uses X86_StdCall for Posix. It says in LLVM docs that it is mostly used by Win32. Perhaps it is not well tested outside Windows. I don't think this new Issue is a problem on Windows.
Jul 13 2015
next sibling parent "David Nadlinger" <code klickverbot.at> writes:
On Monday, 13 July 2015 at 17:04:55 UTC, Dan Olson wrote:
 I don't understand the history of why LDC uses X86_StdCall for 
 Posix.
The reasons are indeed mainly historic in so far as this is what DMD does, and we want to match DMD's calling convention as closely as possible for naked inline assembly. — David
Jul 13 2015
prev sibling next sibling parent Dan Olson <gorox comcast.net> writes:
Dan Olson <gorox comcast.net> writes:

 "Kai Nacke" <kai redstar.de> writes:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we can
 produce a LLVM bug report then we could try to set this as a release
 blocker. Branching for the 3.7 release is tomorrow.
No, I have not tried 3.7 and I won't have time for a couple days.
Same problem with LLVM master 3.7.0svn.
Jul 13 2015
prev sibling parent reply "Kai Nacke" <kai redstar.de> writes:
On Monday, 13 July 2015 at 17:04:55 UTC, Dan Olson wrote:
 "Kai Nacke" <kai redstar.de> writes:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we 
 can produce a LLVM bug report then we could try to set this as 
 a release blocker. Branching for the 3.7 release is tomorrow.
No, I have not tried 3.7 and I won't have time for a couple days. I don't understand the history of why LDC uses X86_StdCall for Posix. It says in LLVM docs that it is mostly used by Win32. Perhaps it is not well tested outside Windows. I don't think this new Issue is a problem on Windows.
stdcall conventions does not support variadic arguments. Or am I wrong? Regards, Kai
Jul 14 2015
parent reply Dan Olson <gorox comcast.net> writes:
"Kai Nacke" <kai redstar.de> writes:

 On Monday, 13 July 2015 at 17:04:55 UTC, Dan Olson wrote:
 "Kai Nacke" <kai redstar.de> writes:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we can
 produce a LLVM bug report then we could try to set this as a
 release blocker. Branching for the 3.7 release is tomorrow.
No, I have not tried 3.7 and I won't have time for a couple days. I don't understand the history of why LDC uses X86_StdCall for Posix. It says in LLVM docs that it is mostly used by Win32. Perhaps it is not well tested outside Windows. I don't think this new Issue is a problem on Windows.
stdcall conventions does not support variadic arguments. Or am I wrong? Regards, Kai
Yeah, I read that too. That is why I was curious about the history of using X86_StdCall. Didn't D-style variadics changed in 0.15.2 from a pointer to varags to a true variadic call. Could that be related? I decided to start looks at diffs in LLVM source from 3.5 to 3.6 to see what might have happened there too. Maybe LDC is just using X86_StdCall in a "non-Std" way.
Jul 14 2015
parent "Kai Nacke" <kai redstar.de> writes:
On Wednesday, 15 July 2015 at 06:32:32 UTC, Dan Olson wrote:
 "Kai Nacke" <kai redstar.de> writes:

 On Monday, 13 July 2015 at 17:04:55 UTC, Dan Olson wrote:
 "Kai Nacke" <kai redstar.de> writes:
 There is no ldc issue yet. Did you check with LLVM 3.7? If 
 we can produce a LLVM bug report then we could try to set 
 this as a release blocker. Branching for the 3.7 release is 
 tomorrow.
No, I have not tried 3.7 and I won't have time for a couple days. I don't understand the history of why LDC uses X86_StdCall for Posix. It says in LLVM docs that it is mostly used by Win32. Perhaps it is not well tested outside Windows. I don't think this new Issue is a problem on Windows.
stdcall conventions does not support variadic arguments. Or am I wrong? Regards, Kai
Yeah, I read that too. That is why I was curious about the history of using X86_StdCall. Didn't D-style variadics changed in 0.15.2 from a pointer to varags to a true variadic call. Could that be related? I decided to start looks at diffs in LLVM source from 3.5 to 3.6 to see what might have happened there too. Maybe LDC is just using X86_StdCall in a "non-Std" way.
Yes, that is the difference. With 0.15.1 there is no variadic call. I think we must change calling convention to cdecl for variadic D functions. Regards, Kai
Jul 15 2015
prev sibling parent reply "David Nadlinger" <code klickverbot.at> writes:
On Monday, 13 July 2015 at 04:34:00 UTC, Kai Nacke wrote:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we 
 can produce a LLVM bug report then we could try to set this as 
 a release blocker. Branching for the 3.7 release is tomorrow.
So if this is really an LLVM bug that we cannot work around easily, what is our plan for the next LDC release(s)? — David
Jul 14 2015
parent reply "Kai Nacke" <kai redstar.de> writes:
On Tuesday, 14 July 2015 at 12:04:57 UTC, David Nadlinger wrote:
 On Monday, 13 July 2015 at 04:34:00 UTC, Kai Nacke wrote:
 There is no ldc issue yet. Did you check with LLVM 3.7? If we 
 can produce a LLVM bug report then we could try to set this as 
 a release blocker. Branching for the 3.7 release is tomorrow.
So if this is really an LLVM bug that we cannot work around easily, what is our plan for the next LDC release(s)? — David
I think now that it is not an LLVM bug because stdcall does not support variadic arguments. Solution is to use the C calling convention. DMD seems to do something similar. Regards, Kai
Jul 15 2015
parent Dan Olson <gorox comcast.net> writes:
"Kai Nacke" <kai redstar.de> writes:
 I think now that it is not an LLVM bug because stdcall does not
 support variadic arguments. Solution is to use the C calling
 convention. DMD seems to do something similar.
It is odd though that LLVM doesn't complain when varargs is used with CallingConv::X86_StdCall. With ARM when I upgraded to 0.15.2, it specifically told me: [ 5%] Generating src/core/demangle_arm64.o Calling convention does not support varargs or perfect forwarding! i32 (i8*, i64, i8*, ...)* snprintf LLVM ERROR: Broken module found, compilation aborted! make[3]: *** [runtime/src/core/demangle_arm64.o] Error 1 Then I knew to switch from Fast to C! -- Dan
Jul 16 2015