Sign in to follow this  
Alundra

GCC -malign-double

Recommended Posts

As I understand it this flag doesn't really do much on most x86_64 ABI's since long longs and doubles are already aligned on a two-word boundary. However if that is not the case then you must be very careful what you apply that flag to, because if any non-PhysX structure declarations (in library/system headers and so on) get affected by that flag and their layout suddenly differs from the layout expected by their implementation, which does not expect malign-double, there's no telling what might happen, but it will almost certainly end with stack corruption, an eventual segmentation fault of your program, and lots of tears.

 

I would recommend controlling the usage of this compiler flag as strictly as possible, in other words limiting it to the PhysX headers (or wherever they are needed) and nothing else.

Share this post


Link to post
Share on other sites

As Bacterius alluded to..this flag can turn out to be very viral. I had the same issue with PhysX too and it wasn't until after using 3.3.1. My guess is either they screwed up the build or they changed the way the libraries are being built.

Share this post


Link to post
Share on other sites

Seconding -- or thirding, I guess -- the earlier comments.

 

Setting the flag globally is likely to cause issues unless you are compiling all libraries from scratch and all libraries are written to cope with the unexpected packing requirements.

 

Far better to just set alignment flags on the specific structures that need it.

Share this post


Link to post
Share on other sites

The problem is the error is in a physx file called PxPreprocessor.h not only on the compilation of PhysX.

The only way is to enable a flag before include and disable after include ?

How do that correctly if it's the only way ?

Edited by Alundra

Share this post


Link to post
Share on other sites
They make the source code available.

Add it to your source tree, add the source to your build chain. If you need to modify something that doesn't exactly meet your needs -- such as that header file -- then modify the file and comment the reason for the change.

Share this post


Link to post
Share on other sites

Here the part of PhysX code which gives the error :

// Ensure that the application hasn't tweaked the pack value to less than 8, which would break
// matching between the API headers and the binaries
// This assert works on win32/win64/360/ps3, but may need further specialization on other platforms.
// Some GCC compilers need the compiler flag -malign-double to be set.
// Apparently the apple-clang-llvm compiler doesn't support malign-double.

struct PxPackValidation { char _; long long a; };

#if !defined(PX_APPLE)
PX_COMPILE_TIME_ASSERT(PX_OFFSET_OF(PxPackValidation, a) == 8);
#endif

PX_OFFSET_OF is defined like that before :

#if defined(PX_GNUC)
#define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
#else
#define PX_OFFSET_OF(X, Y) offsetof(X, Y)
#endif

PX_COMPILE_TIME_ASSERT :

// static assert
#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))  
#define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1] __attribute__((unused))
#else 
#define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
#endif

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this