[Issue 10462] interface thunk doesn't preserve EBX

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 19 14:50:14 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10462



--- Comment #6 from Martin Nowak <code at dawg.eu> 2013-07-19 14:50:12 PDT ---
The fix seems to work but I found another corner case.
Calling an interface thunk through a delegate still crashes.

----
cat > bug.d << CODE
void call(int delegate() dg)
{
    assert(dg() == 7);
}

interface I { int opCall(); }
class C : I { int opCall() { return 7; } }

void test()
{
    I i = new C;
    call(&i.opCall);
}
CODE

cat > main.d << CODE
import bug;
void main() { bug.test(); }
CODE

${DMD} -g -m32 -fPIC -shared bug.d -oflibbug.so
${DMD} -g -m32 main.d -L-L. -L-lbug -L-rpath=.
./main
----

The code generated to call the delegate trashes EBX.

<_D3bug4callFDFZiZv>:
...
mov    0x8(%ebp),%eax   // loads context ptr
mov    -0x4(%ebp),%ebx  // correctly loads GOT into EBX
mov    0xc(%ebp),%edx   // loads function ptr
mov    0x8(%ebp),%ebx   // overwrites EBX with context ptr ???
call   *%edx

The interface thunk call through call *%edx needs a correct EBX.

<_TMP3>:
sub    $0x8,%eax
jmp    d3e0 <_D3bug1C6opCallMFZi at plt>

So the problematic instruction is the additional load into EBX.
This works correctly with optimized builds btw.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list