tags:

views:

350

answers:

2

In gcc there is a directive called .align that allows me to align things at boundaries that need to be a power of two. However, on my Intel Core Duo machine I want to align some code (not data) at addresses that are NOT powers of two. Is there any straightforward way to do that?

Because obviously, .align 3 gives me the error: Error: alignment not a power of two.

+1  A: 

Assuming you're using GCC, you can used packed structures and manual padding:

struct very_slow_t
{
   int a;
   char padding;
   int b; /* b is now padded to byte 5 */
} __attribute__((__packed__));

But why would you possibly want to do that? I mean, it would make your program much slower.

DrJokepu
Thanks, but more looking for code alignment, sorry for not specifically mentioning that!
+2  A: 

Align to a power of two, and then pad with the appropriate number of assembler NOPs before the code you want to be misaligned. (I'm presuming you know how to do in-line assembler in gcc here; comment if you don't.)

Curt Sampson
Yes, I know how to do that. I am aware of this option, however, it would be easier if I could "hard" align it! Thanks
It would be easier, yes, except it may be a bit much to ask the "align" command to unalign things!
Curt Sampson