How to get 16-byte stack alignment in leaf functions
Dave Allured - NOAA Affiliate
dave.allured@noaa.gov
Tue Sep 10 00:21:00 GMT 2013
Hello, I am trying to create a dynamic library for
x86_64-apple-darwin12 (Mac OS) with gcc 4.8.1. My source code
includes some simple functions that I think are being identified as
leaf functions. This works fine when compiling to a static library.
However, when compiling to dynamic library (-dynamiclib etc.), seg
fault results immediately on call from one of these leaf-like
functions to another. GDB tells me that the stack becomes misaligned
in the calling function, and the actual seg fault happens within a
dynamic loader stub function. The simplified message from GDB is:
misaligned_stack_error_entering_dyld_stub_binder
And indeed, the stack pointer which was aligned to xxxx0 in previous
functions, is now xxxx8 just before the fatal call to the dynamic
loader.
I read that the Mac ABI requires 16-byte stack alignment. So, this
seems to be a case where leaf functions are no longer leaf functions
when compiling for dynamic library. However I can not seem to obtain
16 byte alignment by default, or with the obvious controls such as
-mpreferred-stack-boundary=4. There are a few kludges that force
alignment, such as adding a fprintf call in the called function.
Is there a straightforward way to obtain 16-byte stack alignment for
all function calls, regardless of their status as leaf?
I will gladly supply a short test case if this is insufficient
information. Thanks for any insights.
--Dave
More information about the Gcc-help
mailing list