Thursday, March 31, 2011

Running Cocoa app under otest causes dyld_misaligned_stack_error in Release mode

Hello,

I have a problem which I have been struggling with for a while.

I have a Cocoa library which acts as a wrapper for a C++ library. C++ library is tested using a set of BOOST unit tests. The tests run normally under both debug and release modes.

In order to test the Cocoa wrapper I am using otest. Here is the strange part, the tests run normally in debug mode but fail in release mode. To make sure its not something in the code I've taken the tests content and compiled them as a separate Cocoa app which uses the wrapper code. This runs normally both under release and debug.

When otest fails I get a stack trace which makes little sense and ends with dyld_misaligned_stack_error.

Another strange thing that I've noticed is that when starting otest from a command line rather than from XCode if I point DYLD_LIBRARY_PATH and DYLD_FRAMEWORK_PATH to the Debug version of C++ library the tests pass. I have confirmed though that all my test code is being compiled with Release flags.

Any help would be greatly appreciated!

Thank you

From stackoverflow
  • Try adding flag "-mstackrealign" in C flags in the release version.

    -mstackrealign

    Realign the stack at entry. On the Intel x86, the -mstackrealign option will generate an alternate prologue/epilogue that realigns the runtime stack. This supports mixing legacy codes that keep a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility.

    See GCC's man page for reference.

    Alex : Thanks for the answer. However this does not seem to be the reason in this case, although it helped to discover a fix. For some reason removing NDEBUG from C flags in Release mode fixed the problem even without -mstackrealign option. I do not understand why though.
    Alex : Nevermind :) I forgot to add this flag to release version of my C++ libraries. Thanks a lot, your answer helped find the problem.

0 comments:

Post a Comment