Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not link with -ffast-math #488

Closed
gcode-importer opened this issue Apr 28, 2015 · 6 comments
Closed

Do not link with -ffast-math #488

gcode-importer opened this issue Apr 28, 2015 · 6 comments
Assignees
Milestone

Comments

@gcode-importer
Copy link

Originally reported on Google Code with ID 488

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.

Reported by orion@cora.nwra.com on 2015-04-28 21:43:08


- _Attachment: [openjpeg-fast-math.patch](https://storage.googleapis.com/google-code-attachments/openjpeg/issue-488/comment-0/openjpeg-fast-math.patch)_ - _Attachment: [openjpeg2-fast-math.patch](https://storage.googleapis.com/google-code-attachments/openjpeg/issue-488/comment-0/openjpeg2-fast-math.patch)_
@rdieter
Copy link
Contributor

rdieter commented Jul 30, 2015

I can take care of importing the proposed patches

@rdieter
Copy link
Contributor

rdieter commented Jul 30, 2015

Hrm, apparently I don't have commit access yet :(

@mayeut
Copy link
Collaborator

mayeut commented Jul 30, 2015

Done on master

@mayeut
Copy link
Collaborator

mayeut commented Aug 27, 2015

This requires CMake 2.8.12
Minimum CMake version was 2.8.2 until now.
Either disable -ffast-math before 2.8.12 or bump minimum CMake version to 2.8.12 ?

@mayeut mayeut added this to the OPJ v2.1.1 milestone Aug 27, 2015
mayeut added a commit to mayeut/openjpeg that referenced this issue Sep 1, 2015
@mayeut
Copy link
Collaborator

mayeut commented Sep 4, 2015

@detonin,

Feel free to close if the implemented solution is OK.

disable -ffast-math before 2.8.12

@detonin
Copy link
Contributor

detonin commented Jan 23, 2016

Implemented solution is ok. Thanks. Closing.
Master will be merged in 2.1 branch so #553 shall be closed too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants