<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57589>57589</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Shared library compiled with -ffast-math modifies FPU state of thread
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          simonbyrne
      </td>
    </tr>
</table>

<pre>
    On linux:
```
touch foo.c
clang -Ofast -fpic -shared foo.c -o foo.so
objdump --disassemble foo.so
```
gives:
```
Disassembly of section .text:

00000000000004f0 <set_fast_math>:
 4f0:   0f ae 5c 24 fc          stmxcsr -0x4(%rsp)
 4f5:   81 4c 24 fc 40 80 00    orl    $0x8040,-0x4(%rsp)
 4fc:   00
 4fd:   0f ae 54 24 fc          ldmxcsr -0x4(%rsp)
 502:   c3                      retq
 503:   66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
 50a:   00 00 00
 50d:   0f 1f 00                nopl   (%rax)
```

This means that any thread which later loads the library will then set the flush subnormals to zero (FTZ) and subnormals are zero (DAZ) flags (even if the executable itself was not compiled with `-ffast-math`).

# Related discussion
- ["Someone’s Been Messing With My Subnormals!"](https://moyix.blogspot.com/2022/09/someones-been-messing-with-my-subnormals.html) by Brendan Dolan-Gavitt (@moyix)
- ["Beware of fast-math"](https://simonbyrne.github.io/notes/fastmath/#flushing_subnormals_to_zero) by me (@simonbyrne)
- [GCC issue #55522](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VUuPozgQ_jXkUgI55jFw4NDdmcxpNKvtWa00l8gYAx4ZnMWmk8yv37KdkO7enrUQweWvqr56OY1uL_W3CZSclnOUPkRkF5GHqCDXx2-tXvgAndYJDwKu2NRD_K1jxkLcHSWH2AxsFm1AQaz9h9EBr5u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