Odd behavior in fiber unittest - printf stops optimization crash
Kevin Brogan via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sat Feb 28 16:30:01 PST 2015
msvc 64 bit build.
Trying to figure out why the unit test for core.thread is failing
for release but not for debug.
First I wanted to figure out which tests were causing the crash.
Turns out that only the fiber related tests are crashing. All
thread related unit tests are fine.
Thoughts are that it would be an optimization problem, since
release is crashing but not debug.
I switch out the -O3 flag in build scripts for core.thread with
-02. No more crash.
So that's confirmed... but what line of code is causing the
crash? Switch back to -O3 and disable all of the fibre unit tests
except for what looked to be the simplest one.
unittest
{
int x = 0;
(new Fiber({
x++;
})).call();
assert( x == 1 );
}
Using printf statements I determine that the crash is happening
inside of a naked assembly function called fiber_switchContext.
There's almost zero comments so I don't understand exactly why
it's doing what it's doing. Seems to be saving the win64 abi
non-volatile registers as well as something to do with thread
local storage using the GS register which is completely
undocumented on msdn from what I can tell.
I have questions about the function. Why is RBX pushed after the
XMM registers. (xmm alignment i guess?) Why are RDI and RSI not
saved, as they are non-volatile as well according to
https://msdn.microsoft.com/en-us/library/9z1stfyw.aspx.
So while I'm writing this I realize I haven't tested what happens
if I modify the context switch to save RDI and RSI as well...
unit test is working now!!! next!
Earlier I had figured out that placing a printf on either side of
the call to fiber_switchContext would eliminate the crash. I
guess it changed the optimized code...
On to the next failing fiber related unit test!
More information about the digitalmars-d-ldc
mailing list