www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22172] New: GOT address is stored to EBX before every

https://issues.dlang.org/show_bug.cgi?id=22172

          Issue ID: 22172
           Summary: GOT address is stored to EBX before every function
                    call
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

It looks like DMD is loading the GOT into EBX before every function call.

i.e: Abridged version of objdump of a program (from issue 22170)
---
push   %ebp
mov    %esp,%ebp
sub    $0x28,%esp

mov    %esi,-0x24(%ebp)


call   147c8 <_D5mydll10multiply10FiZi plt>

call   *%esi

call   145b0 <_D5mydll1S3addMFiZi plt>

call   145b0 <_D5mydll1S3addMFiZi plt>

call   14560 <_D5mydll1I6createFZCQs1C plt>

mov    (%eax),%ecx
call   *0x4(%ecx)

xor    %eax,%eax

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    %esi,-0x24(%ebp)


call   147c8 <_D5mydll10multiply10FiZi plt>
call   *%esi
call   145b0 <_D5mydll1S3addMFiZi plt>
call   145b0 <_D5mydll1S3addMFiZi plt>
call   14560 <_D5mydll1I6createFZCQs1C plt>
mov    (%eax),%ecx
call   *0x4(%ecx)

xor    %eax,%eax

mov    -0x24(%ebp),%esi
leave
ret
---

--
Aug 02 2021