[cfe-dev] Converting pointers to fat pointers

David Chisnall csdavec at swan.ac.uk
Sat May 26 05:17:24 PDT 2012


On 15 May 2012, at 04:04, John Criswell wrote:

> On 5/14/12 9:57 PM, Sai Charan wrote:
>> In the interest of time & effort, I am leaning on working at the LLVM IR level. 
>> 
>> The code listing in section 3.1 of the SoftBound paper is precisely what I am looking to do. However, the listing is at the C source level, while section 6 says that the implementation has been done on the LLVM IR; I don't see how I can figure out pointer de-references in LLVM IR. Every alloca/load/store is via <ty>*.
>> 
>> In summary, how do I figure out pointer de-references in LLVM IR.
> 
> Ignoring intrinsic functions, the only LLVM IR instructions that dereference pointers are load and store.

While true, this only tells half of the story.  You also need to be careful of pointer arithmetic, which can be done either via GEPs or via int-to-pointer casts.  If your fat pointers contain, for example, bounds information then you will need to track all of these.

We (cl.cam.ac.uk) are currently in the process of adding LLVM support for a custom MIPS-based processor that has hardware support for capabilities, meaning that we have 64-bit and 256-bit pointers in the system.  64-bit pointers are just numbers, but 256-bit (capability) pointers include start, bounds, and a set of permissions.  Both can be dereferenced, although via different instructions (64-bit pointers are implicitly checked against a specific capability register, depending on how they are used).

We're hitting a few issues in that LLVM IR assumes that you only have one pointer size and so, for example, does things like fold a 64-bit pointer to int to 256-bit pointer sequence into a bitcast, and assumptions in the back end that pointers are integers.  

David





More information about the cfe-dev mailing list