how to add padding to globals?

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.

Gry

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