-
Notifications
You must be signed in to change notification settings - Fork 164
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
Functions that have inline assembly that refer to local variables or parameters will refer to them by EBP, but function prologue does not set up EBP stack frame #805
Comments
This only seems to be a major problem with the 32-bit C/C++ compiler. |
Thank you for your bug report. |
The CG appears to use indirect settings to generate a caller stack frame when the __asm block is used. |
Now it generates correct code.
|
CG should be extended to propagate usage of C caller auto variable flag from in-line code back to caller to decide to use standard stack frame in C caller with [e]bp pointer to C auto variables |
Take this contrived example from DOSLIB for example:
Output according to WDIS
Values going into and out of the inline assembly are wrong because it reads and writes through EBP, but the function prologue/epilogue never did the usual PUSH EBP, MOV EBP, ESP and LEAVE routine. Stack frame checking is disabled when compiling this code. So when the inline asm writes to what it thinks is a local variable, it's writing to whatever stack location the parent function happened to leave EBP set to.
A considerable amount of code in DOSLIB uses functions with inline assembly and those functions are causing stack corruption and malfunctioning because of this bug.
I found this while tracking down why the various test programs in DOSLIB were crashing when compiled with recent Open Watcom code. I found this when tracking down why the Sound Blaster test program crashed shortly after probing the DMA controller, why the crash had something to do with the CPU detection code blanking a 32-bit word well above it's own stack frame that caused SNDSB test.c to crash when main() returned, and so on.
The text was updated successfully, but these errors were encountered: