PIC documentation ?

Is there any overview or detailed socumentation on LLVM PIC ?

Many thanks in advance,

Aaron

Hello, Aaron

Is there any overview or detailed socumentation on LLVM PIC ?

Did you mean Position Independent Code? If so - there is nothing
special here, LLVM just implements (when this is implemented) what is
defined in platform ABI.

Anton,

Sorry I have not replied earlier.

Can I ask what platform ABI’s are documented other than Itanium ?

I need to get to understand PIC on x86, x86_64 and PowerPC for the COFF and MachO backends.

Thanks,

Aaron

2009/6/15 Anton Korobeynikov <anton@korobeynikov.info>

Hello, Aaron

Can I ask what platform ABI's are documented other than Itanium ?

I'd bet all platform ABI are more or less documented.

I need to get to understand PIC on x86, x86_64 and PowerPC for the COFF and MachO backends.

ABI is normally induced by platform, not by architecture or object
file format (however they can influence on it).

1. Windows is PIC by design. Google for PE file format and for
'relocs' section. This corresponds to LLVM's DynamicNoPIC
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.
3. COFF is usually not used on PPC at all (maybe on some old AIX'es?).

PS: Since you did not mention ELF, I assume you already found ABI docs
for it (for all platforms).

Hello, Aaron

Can I ask what platform ABI's are documented other than Itanium ?

I'd bet all platform ABI are more or less documented.

I need to get to understand PIC on x86, x86_64 and PowerPC for the COFF and MachO backends.

ABI is normally induced by platform, not by architecture or object
file format (however they can influence on it).

1. Windows is PIC by design. Google for PE file format and for
'relocs' section. This corresponds to LLVM's DynamicNoPIC
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.

The Apple ABI document is here, but doesn't really talk about PIC:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/000-Introduction/introduction.html

Anton,

Can I ask what platform ABI's are documented other than Itanium ?

I'd bet all platform ABI are more or less documented.

Right.

Maybe we should collect references and do some LLVM PIC documentation and put it on LLVM website ?

I need to get to understand PIC on x86, x86_64 and PowerPC for the COFF and MachO backends.

ABI is normally induced by platform, not by architecture or object
file format (however they can influence on it).

Yes.

1. Windows is PIC by design. Google for PE file format and for
'relocs' section. This corresponds to LLVM's DynamicNoPIC

Okay I have this documentation.

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 ?

3. COFF is usually not used on PPC at all (maybe on some old AIX'es?).

Yes.

Since you did not mention ELF, I assume you already found ABI docs
for it (for all platforms).

I am not working on the ELF backend, but could not understand the PIC code in the ELF documentation.

Thanks,

Aaron

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.

The Apple ABI document is here, but doesn't really talk about PIC:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/000-Introduction/introduction.html

Thanks Dale,

Aaron

Aaron,

Maybe we should collect references and do some LLVM PIC documentation and
put it on LLVM website ?

What you mean as "LLVM PIC documentation"? What should be included there?

Okay. We need documentation, what is the difference between DynamicNoPIC and
full PIC ?
From TargetMachine.cpp (actually this is show in llc --help):

  cl::values(
    clEnumValN(Reloc::Default, "default",
               "Target default relocation model"),
    clEnumValN(Reloc::Static, "static",
               "Non-relocatable code"),
    clEnumValN(Reloc::PIC_, "pic",
               "Fully relocatable, position independent code"),
    clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
               "Relocatable external references, non-relocatable code"),
    clEnumValEnd));

Maybe we should collect references and do some LLVM PIC documentation and
put it on LLVM website ?

What you mean as "LLVM PIC documentation"? What should be included there?

Good question, if I had a proper overview of LLVM PIC implmentation then I would know :slight_smile:

Okay. We need documentation, what is the difference between DynamicNoPIC and
full PIC ?
From TargetMachine.cpp (actually this is show in llc --help):

cl::values(
   clEnumValN(Reloc::Default, "default",
              "Target default relocation model"),
   clEnumValN(Reloc::Static, "static",
              "Non-relocatable code"),
   clEnumValN(Reloc::PIC_, "pic",
              "Fully relocatable, position independent code"),
   clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
              "Relocatable external references, non-relocatable code"),
   clEnumValEnd));

This tells me a bit but very little.

Okay I will have to study the code, I was hoping not to have to do that.

Aaron

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):
_foo:
         call L3
"L00000000001$pb":
         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
         ret
.comm _x,4,2
         .section __IMPORT,__pointers,non_lazy_symbol_pointers
L_x$non_lazy_ptr:
         .indirect_symbol _x << magic cookie for indirect references, must be in this magic section
         .long 0

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

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

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.

Great thats the way to do it, very obvious solution !

Thanks for the hints Dale,

Aaron