asharif tools <asharif.to...@gmail.com> writes:

> On Wed, Jun 8, 2011 at 10:32 PM, Ian Lance Taylor <i...@google.com> wrote:
>> asharif tools <asharif.to...@gmail.com> writes:
>>
>>> function:
>>>       call    __i686.get_pc_thunk.bx
>>>       addl    $_GLOBAL_OFFSET_TABLE_, %ebx
>>>       movl    %gs:20, %eax # Stack-guard init
>>>       movl    %eax, -12(%ebp) # Stack-guard init
>>
>>> Now, what I want to do is move stack guard initialization part
>>> (consisting of the two instructions I have commented as "Stack-guard
>>> init" into get_pc_thunk.bx for those functions that have both the
>>> stack guard and a call to get_pc_thunk.bx. The compiler should
>>> generate a "stack_guarded_get_pc_thunk.bx" that will do move the
>>> %gs:20 value to the correction location on the stack instead of
>>> executing nops. In this way some useful work can be done instead of
>>> nops.
>>
>> I don't understand how you can do that.  The offset from %ebp will be
>> different in different functions.  When optimizing, it is likely to be
>> an offset from %esp instead.  The scratch register used may also be
>> different; consider functions with __attribute__ ((regparm (2))), or the
>> use of -mregparm=2.
>
> I see.
>
> Would it be possible for the caller of stack_protected_get_pc_thunk to
> pass in this offset from gs in the return register (ebx in this case)
> in all the cases you described?

You mean the offset from %esp or %ebp.  This would require an leal
instruction, so now you are only saving one instruction.  And that by
itself would not be enough, because __stack_protected_get_pc_thunk would
not know which register it could use to move the value.  But you could
have different variants of the function, or it could preserve the
register.  With those conditions, yes, I think it would be possible.
But the savings seems fairly minimal to me, and it only matters on the
Atom.  Not that I want to stop you if you are interested.

Ian

Reply via email to