[cfe-dev] clang x86 code generation/binary compatibility with GCC

Evan Cheng evan.cheng at apple.com
Fri Oct 12 09:11:21 PDT 2012


I believe LLVM is C ABI compliant. I don't know where it is documented but LLVM's assumption is caller must extend arguments to at least 32-bit.

See discussion here:

http://llvm.org/bugs/show_bug.cgi?id=12207
and
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46942

Looks like gcc does sign / zero extend its call arguments so there shouldn't any compatibility issue mixing llvm and gcc code.

Evan

On Oct 12, 2012, at 7:55 AM, "Richtarsky, Martin" <martin.richtarsky at sap.com> wrote:

> Hi,
> 
> I have this code:
> 
> void conv(long *pa, signed char b)
> {
>  *pa = static_cast<long>(b);
> }
> 
> 
> GCC 4.3.4 on SLES11, aswell as a recent GCC 4.7.1 compile this to:
> 
>  .cfi_startproc
>  movsbq  %sil, %rsi
>  movq    %rsi, (%rdi)
>  ret
>  .cfi_endproc
> 
> So the "signed char b" in sil is sign-extended to a 64 bit register.
> 
> clang emits this:
> 
> # BB#0:                                 # %entry
>  movslq  %esi, %rax
>  movq    %rax, (%rdi)
>  ret
> 
> clang is already passing char arguments in 32-bit registers sign-extended, and the generated code of this function relies on that. I have a case where this causes problems with jitted code that is calling such functions, and the assumption made by clang that the char has already been extended to 32 bit fails there.S
> 
> Anyone can shine some light on this? 
> 
> Thanks and best regards,
> Martin
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list