[Issue 22170] interface thunk doesn't set EBX to GOT
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 2 22:58:46 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22170
--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject.org> ---
It looks like what DMD is doing is loading the GOT into EBX before every
function call.
i.e: Abridged version of objdump
---
push %ebp
mov %esp,%ebp
sub $0x28,%esp
mov %ebx,-0x28(%ebp)
mov %esi,-0x24(%ebp)
mov -0x1c(%ebp),%ebx
call 147c8 <_D5mydll10multiply10FiZi at plt>
mov -0x1c(%ebp),%ebx
call *%esi
mov -0x1c(%ebp),%ebx
call 145b0 <_D5mydll1S3addMFiZi at plt>
mov -0x1c(%ebp),%ebx
call 145b0 <_D5mydll1S3addMFiZi at plt>
mov -0x1c(%ebp),%ebx
call 14560 <_D5mydll1I6createFZCQs1C at plt>
mov -0x1c(%ebp),%ebx
mov (%eax),%ecx
call *0x4(%ecx)
xor %eax,%eax
mov -0x28(%ebp),%ebx
mov -0x24(%ebp),%esi
leave
ret
---
Surely it'd be more efficient to load GOT in the prologue, then restore the
previous in the epilogue.
i.e: The above rewritten:
---
push %ebp
mov %esp,%ebp
sub $0x28,%esp
mov %ebx,-0x28(%ebp) # <- looks like a save (better push %ebx?)
mov %esi,-0x24(%ebp)
mov -0x1c(%ebp),%ebx # <- Added load GOT here
call 147c8 <_D5mydll10multiply10FiZi at plt>
call *%esi
call 145b0 <_D5mydll1S3addMFiZi at plt>
call 145b0 <_D5mydll1S3addMFiZi at plt>
call 14560 <_D5mydll1I6createFZCQs1C at plt>
mov (%eax),%ecx
call *0x4(%ecx)
xor %eax,%eax
mov -0x28(%ebp),%ebx # <- looks like a restore (better pop %ebx?)
mov -0x24(%ebp),%esi
leave
ret
---
So it seems that the save/restore is already being done for normal functions,
but this isn't being done for thunks.
--
More information about the Digitalmars-d-bugs
mailing list