Skip to content

Conversation

@maleadt
Copy link
Member

@maleadt maleadt commented Nov 16, 2020

The implementation of fesetenv cannot be portable, as the value of
FE_DFL_ENV differs between platforms. On FreeBSD, it is a actual
environment. With glibc however, it's a sentinel -1 handled in the
implementation of its floating point functions.

https://github.com/freebsd/freebsd/blob/a41d904f70e8e9e3c3062952b52f0845af0af738/lib/msun/x86/fenv.h#L97-L99

https://github.com/bminor/glibc/blob/acdcca72940e060270e4e54d9c0457398110f409/sysdeps/x86/fpu/bits/fenv.h#L96-L97

With openlibm based on FreeBSD's libm, it assumes FE_DFL_ENV to be an
actual environment. That assumption breaks using code that was compiled
against glibc, e.g., libcuda:

Thread 1 "julia-debug" received signal SIGSEGV, Segmentation fault.
0x00007ffff7b855d0 in fesetenv () from /home/tim/Julia/julia/build/release/usr/bin/../lib/libopenlibm.so
(gdb) bt

This reverts commit 5a27b4c.

Fixes JuliaLang/julia#38427.

The implementation of `fesetenv` cannot be portable, as the value of
`FE_DFL_ENV` differs between platforms. On FreeBSD, it is a actual
environment. With glibc however, it's a sentinel -1 handled in the
implementation of its floating point functions.

With openlibm based on FreeBSD's libm, it assumes `FE_DFL_ENV` to be an
actual environment. That assumption breaks using code that was compiled
against glibc, e.g., `libcuda`:

```
Thread 1 "julia-debug" received signal SIGSEGV, Segmentation fault.
0x00007ffff7b855d0 in fesetenv () from /home/tim/Julia/julia/build/release/usr/bin/../lib/libopenlibm.so
(gdb) bt
```

This reverts commit 5a27b4c.

Fixes JuliaLang/julia#38427.
@ararslan ararslan requested a review from staticfloat November 16, 2020 17:50
@staticfloat staticfloat merged commit c856101 into JuliaMath:master Nov 16, 2020
@staticfloat
Copy link
Contributor

If I can't remember why I did this, it can't be that important. Go ahead and do a run on the buildbots with this and let's see if it all compiles properly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openlibm fenv changes broke CUDA

2 participants