[LLVMdev] PIC documentation ?

Dale Johannesen dalej at apple.com
Tue Jun 16 14:53:08 PDT 2009

>> 2. ABI docs for Darwin (x86, x86_64, ppc, ppc64) you might find
>> somewhere @apple.com. There you can have all 3 types of PIC code:
>> static (no pic at all), DynamicNoPIC and full PIC.
> Okay. We need documentation, what is the difference between  
> DynamicNoPIC and
> full PIC ?

The best way to figure this out is to run  a small program through and  
look at the output I think.  It's not considered part of the ABI, as  
it doesn't affect the callee or the codegen for variable  
definitions....note that the code sequences for function calls also  
varied in compilers earlier than gcc-4.2, and OS's earlier than  
Leopard.  Look for getDarwinVers in the X86 and PPC back ends and look  
around for "stubs" if you want to support Tiger.

int x;
void foo() {
   return x;

Results on x86-32 with -fomit-frame-pointer (which is not the default):
result of -fPIC (equivalent to -fpic on Darwin):
         call    L3
         popl    %ecx                   << gets value of PC into %ecx  
(other registers can be used)
         movl    L_x$non_lazy_ptr-"L00000000001$pb"(%ecx), %eax     <<  
gets &x; PC relative
         movl    (%eax), %eax       << gets x; indirect
.comm _x,4,2
         .section __IMPORT,__pointers,non_lazy_symbol_pointers
         .indirect_symbol _x   << magic cookie for indirect  
references, must be in this magic section
         .long   0

Result of -mdynamic-no-pic:
         movl    L_x$non_lazy_ptr, %eax       << &x, not PC relative
         movl    (%eax), %eax              << gets x; indirect
.comm _x,4,2
         .section __IMPORT,__pointers,non_lazy_symbol_pointers
         .indirect_symbol _x
         .long   0

Result of -static:
         movl    _x, %eax      << direct reference
.comm _x,4,2

More information about the llvm-dev mailing list