Hi
Recently HSE pointed out a problem with a piece of code that doesn’t work on
64 bit but only when imported from a
library. Intrigued I looked into the disassembly and found a discrepancy when exactly the same code was assembled directly into the application or it was linked from a static library. To reduce the complexity I build a testbed and fortunately could reproduce this behaviour.
While inspecting the compiled code with ObjConv, I found that the homing area was not reserved (missing sub rsp, …) but at the end of the proc releasing the stack was done, however the incorrect amount.
The correct code should be:
00007FF604B91001 48 89 4C 24 08 mov qword ptr [rsp+8],rcx
00007FF604B91006 48 83 EC 28 sub rsp,28h
00007FF604B9100A 48 8B 4C 24 30 mov rcx,qword ptr [rsp+30h]
00007FF604B9100F 48 C7 C1 7B 00 00 00 mov rcx,7Bh
00007FF604B91016 E8 E5 FF FF FF call 00007FF604B91000
00007FF604B9101B 48 83 C4 28 add rsp,28h
00007FF604B9101F C3 ret
But the code from the library is:
00007FF78A601021 48 89 4C 24 08 mov qword ptr [rsp+8],rcx
00007FF78A601026 48 8B 4C 24 28 mov rcx,qword ptr [rsp+28h]
00007FF78A60102B 48 C7 C1 7B 00 00 00 mov rcx,7Bh
00007FF78A601032 E8 E9 FF FF FF call 00007FF78A601020
00007FF78A601037 48 83 C4 20 add rsp,20h
00007FF78A60103B C3 ret Both were compiled with exactly the same switches.
Experimenting a bit, I found that commenting out the later WinTest_Done procedure, the error is gone…

I post the complete testbed. Paths must be adjusted for your setup.
I hope you can find the problem soon.
Biterider