This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: local variable alignment on Solaris/SPARC, with gcc 4.x


Hi Amruth,

I just took a look at the SPARC ABI ... 

+ Although the architecture requires only word alignment, software convention and the operating system require every stack frame to be doubleword aligned.

+ Every stack frame must have a 16-word save area for the in and local registers, in case of window overflow or underflow.  This save area always must exist at %sp+0.

Also of interest in the SPARC ABI (but irrelevant to your problem) is the use of var-args, which may result in misaligned data for (say) a double that straddles the wrong two words.

So it would seem to me that even a leaf-function should have a double-word aligned stack.

But that does not mean that a char foo[10]; local (stack) variable will be word or double-word aligned.  The compiler's optimizer is at liberty to perform deep voodoo optimization that may result in the foo being at a non-word boundary.  :-(

For GCC 4.1.0, I'd turn on the -O2 optimization and use the -fverbose-asm switch and -S to view the flags that are enabled by -O2, and then disable them a batch at a time (divide and conquer) until you isolate a flag that you can use to disable the behavior.

As it so happens, though, -O2 also enables optimizations that do not have a tweakable knob to explicitly disable.  And if the optimization is one of those, you may be in dire straights.

I'd also upgrade to GCC 4.1.2 or GCC 4.2.1, if possible.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]