<div dir="ltr"><div>gcc will try really hard to find a free register from which to address your stack variables, starting with esp, and then falling back to any free register.  If you clobber every register except for ebp *and* require stack realignment, it errors out.</div>
<div><br></div><div>If you remove any clobber from the following example, it will compile.</div><div><br></div><div>$ cat realign_inline_asm.c</div><div>int foo(int a) {</div><div>  __attribute__((aligned(16))) int r = -1;</div>
<div>  asm volatile ("push %%edi\n\t"</div><div>                "xor %%eax, %%eax\n\t"</div><div>                "xor %%ebx, %%ebx\n\t"</div><div>                "xor %%ecx, %%ecx\n\t"</div>
<div>                "xor %%edx, %%edx\n\t"</div><div>                "xor %%esi, %%esi\n\t"</div><div>                "mov %0, %%eax\n\t"</div><div>                "pop %%edi\n\t"</div>
<div>                "xor %%edi, %%edi\n\t"</div><div>                : "=m"(r) /* out */</div><div>                : /* in */</div><div>                : "eax", "ebx", "ecx", "edx", "esi", "edi", "esp");</div>
<div>  return r;</div><div>}</div><div><br></div><div>$ gcc -m32 -c realign_inline_asm.c -S -o -  -mstackrealign<br></div><div>        .file   "realign_inline_asm.c"</div><div>realign_inline_asm.c: In function ‘foo’:</div>
<div>realign_inline_asm.c:3:3: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’</div><div><br></div><div>For now, at least, it would be nice to report a fatal error when we want to use esi for the BP, but we have inline asm that clobbers it.  We already have the clobber list with that info.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 8, 2013 at 7:39 AM, Chad Rosier <span dir="ltr"><<a href="mailto:chad.rosier@gmail.com" target="_blank">chad.rosier@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote">On Wed, Aug 7, 2013 at 8:38 PM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank">stoklund@2pi.dk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Aug 7, 2013, at 5:17 PM, Reid Kleckner <<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>> wrote:<br>
<br>
> Wouldn't it be much better to use ebp for the base pointer and put the pre-alignment SP into a local that could be spilled or register allocated as necessary?  Is that just a matter of work?<br>
<br>
</div>I think stack unwinders would expect to find the frame pointer in %ebp.<br>
<span><font color="#888888"><br>
/jakob</font></span></blockquote></div><br></div></div>Unfortunately, I can't think of a simple solution here.  How does gcc 
handle this case?  IIRC, gcc was the original motivating factor for 
forcing the use of the FP?<span class="HOEnZb"><font color="#888888"><br>
<br>
 Chad<br>
</font></span></blockquote></div><br></div>