Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PIC level in program compilation?

I'm taking a look at LLVM libraries and I figured out that Clang emits the LLVM IR modules adding this metadata:

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"PIC Level", i32 2}
!1 = !{!"Apple LLVM version 7.3.0 (clang-703.0.31)"}

Then I found out that calling the method setPICLevel() on a module gets a similar result:

!0 = !{i32 1, !"PIC Level", i32 0}

So the whole metadata !0 is about the PIC level.

I've been searching for it on the internet but I've found nothing. What's this PIC level and what does it indicate?

like image 786
NoImaginationGuy Avatar asked Jun 12 '16 17:06

NoImaginationGuy


1 Answers

It is a flag that only applies to PowerPC and is ignored otherwise. It sets the model for position-independent code to either a small or large model. Other architectures of course can have PIC, but this flag representing the size if the model is not applicable elsewhere.

You could see the commit where it was first added to LLVM: http://comments.gmane.org/gmane.comp.compilers.llvm.cvs/205216

More info:

https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/dynamic_code.html

https://en.m.wikipedia.org/wiki/Position-independent_code

like image 100
bodangly Avatar answered Oct 23 '22 03:10

bodangly