svn commit: r253802 - head/contrib/llvm/tools/clang/lib/Headers

Jilles Tjoelker jilles at stack.nl
Wed Aug 7 20:57:07 UTC 2013


On Tue, Jul 30, 2013 at 04:16:58PM +0200, Dimitry Andric wrote:
> Upstream gcc checks this with:

> #if defined(__i386__) && defined(__PIC__)
> ...
> #elif defined(__x86_64__) && (defined(__code_model_medium__) || defined(__code_model_large__)) && defined(__PIC__)
> ...

> and it exchanges ebx or rbx with %k1 or %q1, respectively, instead of
> push/pop.  That might be a little more efficient.

> I guess the defined(__PIC__) should be enough for us, in most cases.
> The code_model stuff is for x32 support, which we do not have yet.

The code_model stuff is not for x32 support but for PIC/PIE code where
code+data exceed 2GB so relative addressing cannot always be used. The
ABI then prescribes that %r15 be loaded with the GOT pointer when
invoking a large model (code>2GB) PLT entry; otherwise (medium model or
no PLT entry used), much like i386, any register can be used for the GOT
pointer.

In x32, relative addressing can always be used and there is no need for
a PIC register.

I don't really understand why special tricks are needed for %ebx/%rbx.
With the "b" constraint or "%ebx" clobber, adequate information is
provided to the compiler that %ebx/%rbx will have to be saved somewhere
around the asm. And in fact this appears to work fine with clang; only
gcc (4.2.1 and 4.4.3; I have not tested newer versions) needs special
trickery to access %ebx.

-- 
Jilles Tjoelker


More information about the svn-src-all mailing list