[llvm-dev] Any way to disable the alignment of functions?

Rahman Lavaee Mashhadi via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 30 00:02:05 PST 2015


Dear Mats and David,
Sorry for my late response.
David is right. The problem only appears in C++ code.

> On Dec 28, 2015, at 7:02 AM, David Chisnall <David.Chisnall at cl.cam.ac.uk> wrote:
> 
> On 28 Dec 2015, at 00:24, mats petersson via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> 
>> On 27 December 2015 at 21:23, Rahman Lavaee Mashhadi via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>>> but on a few programs, it produces a segfault-generating executable. So my guess is that for some functions, alignment is necessary for soundness, not just performance.
>> 
>> 
>> That seems rather odd. On x86, I'm not aware of any instruction sequence that REQUIRES alignment of the instruction itself.
> 
> I would definitely expect it to break most C++ programs, because the C++ ABI uses the low bit to distinguish between function pointers and pointers to members.  Other code may also assume that functions start on an n>1 byte boundary and reuse the low bits for other things.  If a valid function pointer has its low bit set, then you may end up masking it off in some other code and then jumping to one byte into the first instruction.  This being x86, that may still be a valid instruction sequence, but it’s almost certainly not a sensible one.
> 
> David
> 



More information about the llvm-dev mailing list