<div class="gmail_quote">Thanks, Eli. It was my fault that the stack wasn't 16-byte aligned. Since I was compiling<br>a OS kernel with clang, I had to set  rsp myself. I made a mistake in one of the assembly <br>code. Now, it has been fixed and everything is fine. <br>

<br><br>BTW, it seems clang can't handle the "=rm" inline assembly code as in the following:<br>static inline struct pcpu_gs *percpu ()<br>{<br>        struct pcpu_gs         *gs;<br><br>        asm volatile ("movq %%gs:gs_self, %0" : "=rm" (gs));<br>

        return gs;<br>}<br><br>clang will generate code like: <br><br>movq %gs:gs_self, -8(%rbp)<br><br>leading gas to complain: Error: too many memory references for `movq'<br><br><br>--Zhi<br><br>On Thu, Aug 13, 2009 at 5:39 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Thu, Aug 13, 2009 at 1:26 PM, Zhi Wang<<a href="mailto:beiyuw@gmail.com">beiyuw@gmail.com</a>> wrote:<br>


> It seems clang will generate code to handle variable length arguments<br>
> no matter whether<br>
> va_xxx (va_start, va_end) is used or not. (gcc will only generate code<br>
> to handle varible<br>
> length arguments when va_start is used).<br>
<br>
</div>I suppose that's a quality-of-implementation issue; it's really more<br>
of a backend issue, though, so I'd suggest asking on llvmdev.<br>
<div class="im"><br>
> My biggest issue with this code is that movaps is used. According to<br>
> Intel's manual,<br>
> if the destination memory isn't 16-byte aligned, a GP# (General<br>
> Protection fault) will occur.<br>
> It seems that using movaps is wrong unless we can guarantee that ebp<br>
> is always 16byte aligned.<br>
> This may not be true. I manually edited the binary of generated code<br>
> to use the movups<br>
> (the same instruction as movups except that it will not check the<br>
> alignment). instruction<br>
> and everything is fine.<br>
<br>
</div>The stack is supposed to be 16-byte aligned on x86-64; if it isn't,<br>
there's probably a bug somewhere.  But again, better to discuss on<br>
llvmdev.<br>
<font color="#888888"><br>
-Eli<br>
</font></blockquote></div><br>