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. > As far as I understand, the stack guard part is done in function.c > (called by cfgexpand.c) which adds the prologue and epilogue to the > protected functions. At this point, we are still target-independent. > > The get_pc_thunk.bx is generated by the target-specific > config/i386/i386.c part (ix86_file_end). > > How should I go about creating such a patch that should: > > 1. Check if a function has both stack guard as well as access to a > global (which would result in having the get_pc_thunk call). > 2. Remove the stack guard prologue instructions. > 3. Replace calls to get_pc_thunk.bx in that function to > stack_guarded_get_pc_thunk. > > Specifically, what phase should this be done in? If you can do this, do it at final, in the expansion for the stack_set and set_got insns. Ian