Bug 22172 – GOT address is stored to EBX before every function call

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2021-08-03T06:41:05Z
Last change time
2024-12-13T19:17:50Z
Keywords
backend, performance
Assigned to
No Owner
Creator
Iain Buclaw
Moved to GitHub: dmd#18049 →

Comments

Comment #0 by ibuclaw — 2021-08-03T06:41:05Z
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 %ebx,-0x28(%ebp) # <- looks like a save (better push %ebx?) mov %esi,-0x24(%ebp) mov -0x1c(%ebp),%ebx # store GOT call 147c8 <_D5mydll10multiply10FiZi@plt> mov -0x1c(%ebp),%ebx # store GOT call *%esi mov -0x1c(%ebp),%ebx # store GOT call 145b0 <_D5mydll1S3addMFiZi@plt> mov -0x1c(%ebp),%ebx # store GOT call 145b0 <_D5mydll1S3addMFiZi@plt> mov -0x1c(%ebp),%ebx # store GOT call 14560 <_D5mydll1I6createFZCQs1C@plt> mov -0x1c(%ebp),%ebx # store GOT 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 --- 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) # <- save previous GOT mov %esi,-0x24(%ebp) mov -0x1c(%ebp),%ebx # <- store GOT 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 -0x28(%ebp),%ebx # <- restore previous GOT mov -0x24(%ebp),%esi leave ret ---
Comment #1 by robert.schadek — 2024-12-13T19:17:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18049 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB