This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Inline ASM and stack/base pointer


kevin diggs <diggskevin38@gmail.com> writes:

> On Thu, Jun 9, 2011 at 12:49 PM, Ian Lance Taylor <iant@google.com> wrote:
>> Daniel Mierswa <impulze@impulze.org> writes:
>>
>>> I was wondering how to overcome the issue that evolves when parameters
>>> (inputs) to the inline assembly are passed relative to ebp/esp and
>>> modifying those pointers in the inline assembly. Basically
>>> __asm__("push %ecx\nmov %0, %edx\n"::"m"(variable)); could set '%0' to
>>> 4(%esp) or similar which would no longer represent the same location
>>> once I use push/pop in my asm. Is it possible to explicitly state that
>>> GCC passes those relative to esp _or_ ebp so I can safely modify at
>>> least one pointer (i.e. reserve stack space)? Or are there any other
>>> ways to overcome this issue? Thanks in advance.
>>
>> Add "%esp" to your clobber list. ÂThat should force the compiler to pass
>> any stack variables using an offset from %ebp.
>>
>> Ian
>>
>
> What happens if you use -fomit-frame-pointer?

Doesn't matter, -fomit-frame-pointer doesn't mean never use a frame
pointer, it means only use one if you need one.  If an asm clobbers
%esp, then the function needs a frame pointer.

> If you muck with esp, do you have to put it back? In other words if
> you include "%esp" in your clobber, does the compiler back up and
> restore it?

You do have to keep it the same.  The compiler will not preserve it for
you.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]