x86 code emitter ebp and esp conflicts

Hi,

I recently ran into a case, where x86 fails to run correctly.

Checking into the emitted code, it seems that the local memory anchored at ebp has conflict with stack memory anchored at esp prepared for function calls.

For example, let us say:

foo()
{

call bar();
}

There is some local data for foo() at ebp-170h. while preparing the call to bar, some data is written to esp+17h. The problem is that esp+17h and ebp-170h point to the same address, and therefore the data is corrupted.

Has anyone seen this problem before? and is there any fix or work around for that?

Thanks!

-Peng

Can you provide real code?

Joerg

Has anyone seen this problem before? and is there any fix or work around
for that?

Please provide a testcase and fill LLVM problem report into bugzilla.

Thanks!

Bug is reported with test cases. see http://llvm.org/bugs/show_bug.cgi?id=15124 .

Thanks,
-Peng

A correction:

After reading the assembly code, the problem is when stack memory allocation is happening between the stack subtraction and the actual function call.

For example, the correct call to sin is:

sub esp, 8
move [esp], xmm0 ; line 1
call sin
add esp, 8

While the generated code adds some stack allocation after line 1 as follows:

sub esp, 8
move [esp], xmm0
move eax, 10h
call chkstk ; allocate more stack
mov esi,esp
mov eax,dword ptr [ebp-278h]
mov dword ptr [esi+8],eax
mov eax,dword ptr [ebp-274h]
mov dword ptr [esi+4],eax
mov eax,dword ptr [ebp-26Ch]
mov dword ptr [esi],eax
call sin
add esp, 8

This causes the stack pointer is pointing to the some user data, i.e., 8 bytes above the true stack top.

Does any one have any idea to prevent the above stack allocation?

Thanks,
-Peng