qizhrj / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

Do not link with -ffast-math #488

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Linking shared libraries with -ffast-math is dangerous.  It causes the SSE 
mxcsr flags to be set on library *load*, which can cause various issues for 
programs the unsuspectingly load such a library.  See:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522
https://bugzilla.redhat.com/show_bug.cgi?id=1127544

for some discussion, examples.

Unfortunately, CMAKE_C_FLAGS are also used during link, so the current:

   # Do not use ffast-math for all build, it would produce incorrect results,
only set for release:
   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")

triggers this.

According to http://public.kitware.com/pipermail/cmake/2015-April/060479.html 
the preferred solution would be something like:

target_compile_options(openjpeg PRIVATE
  $<$<CONFIG:Release>:-ffast-math>)

The attached patches appears to achieve this (for 1.5.1 and trunk).

Another wrinkle on this is that -DCMAKE_BUILD_TYPE=RelWithDebInfo or MinSizeRel 
will also cause -ffast-math not to be used at all.  Not sure if that is an 
issue or not. 

Original issue reported on code.google.com by or...@cora.nwra.com on 28 Apr 2015 at 9:43

Attachments: