[llvm-dev] how to add padding to globals?

John Criswell via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 21 06:31:15 PST 2015


On 12/20/15 7:24 PM, Gry Gunvor via llvm-dev wrote:
> I want LLVM to add padding at the top of my globals.  I also want
> expressions that evaluate globals to use a base address that skips
> over the padding.  I'm looking for any suggestions as to where to
> change the size of a global and where to change the pointer value used
> when it occurs in an expression.

SAFECode has code which does this at the LLVM IR level.  You can find it 
at 
http://llvm.org/viewvc/llvm-project/safecode/branches/release_32/lib/BaggyBoundsChecks/BaggyBoundsChecks.cpp?revision=177641&view=markup 
(though you will need to update it to use the newer LLVM API).

The pass essentially looks for globals to align and pad.  To pad the 
objects, it create a new global of structure type: the first structure 
element is the global's original type, and the second is an array of 
bytes that adds the padding.  Uses of the original global are then 
replaced with a constant GEP expression that generates a pointer to the 
first element of the new global.

Regards,

John Criswell

>
> Gry
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell



More information about the llvm-dev mailing list