public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
@ 2012-11-29  0:52 luto at mit dot edu
  2012-11-29  1:49 ` [Bug c++/55522] " luto at mit dot edu
                   ` (40 more replies)
  0 siblings, 41 replies; 42+ messages in thread
From: luto at mit dot edu @ 2012-11-29  0:52 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522

             Bug #: 55522
           Summary: -funsafe-math-optimizations is unexpectedly harmful,
                    especially w/ -shared
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: luto@mit.edu


The docs for -funsafe-math-optimizations say:

When used at link-time, it may include libraries or startup files that change
the default FPU control word or other similar optimizations. 

This is, IMO, really bad.  One might naively assume (if you haven't thought
about that) that -ffast-math and -funsafe-math-optimizations merely affect code
generation.  This is true if you *compile* with -ffast-math, but if you *link*
with it, then you end up breaking IEEE758 semantics program-wide.  This causes
real-life problems.

Please consider some combination of:

1. Making -funsafe-math-optimizations illegal when combined with -shared.

2. Splitting the inclusion of crtfastmath.o into its own option
(-funsafe-math-mode-at-startup, perhaps) and make -ffast-math (and -Ofast) not
set that one.

3. Mention in the docs just how bad this is in shared libraries.


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug c++/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
@ 2012-11-29  1:49 ` luto at mit dot edu
  2012-11-29  8:57 ` [Bug target/55522] " rguenth at gcc dot gnu.org
                   ` (39 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: luto at mit dot edu @ 2012-11-29  1:49 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522

--- Comment #1 from Andy Lutomirski <luto at mit dot edu> 2012-11-29 01:48:53 UTC ---
I mean IEEE754, of course.


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
  2012-11-29  1:49 ` [Bug c++/55522] " luto at mit dot edu
@ 2012-11-29  8:57 ` rguenth at gcc dot gnu.org
  2012-11-30  1:41 ` luto at mit dot edu
                   ` (38 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-11-29  8:57 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*, i?86-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-29
          Component|middle-end                  |target
            Version|unknown                     |4.6.3
     Ever Confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> 2012-11-29 08:57:15 UTC ---
I think crtfastmath.o should not be used when linking with -shared.


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
  2012-11-29  1:49 ` [Bug c++/55522] " luto at mit dot edu
  2012-11-29  8:57 ` [Bug target/55522] " rguenth at gcc dot gnu.org
@ 2012-11-30  1:41 ` luto at mit dot edu
  2015-04-28 18:23 ` orion at cora dot nwra.com
                   ` (37 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: luto at mit dot edu @ 2012-11-30  1:41 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55522

--- Comment #3 from Andy Lutomirski <luto at mit dot edu> 2012-11-30 01:41:14 UTC ---
I'm still unconvinced that it makes sense as part of
-funsafe-math-optimizations at all.  It's not an "optimization" in the sense
that people usually think of when looking at compiler flags.


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (2 preceding siblings ...)
  2012-11-30  1:41 ` luto at mit dot edu
@ 2015-04-28 18:23 ` orion at cora dot nwra.com
  2021-10-06  1:15 ` ilya.konstantinov at gmail dot com
                   ` (36 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: orion at cora dot nwra.com @ 2015-04-28 18:23 UTC (permalink / raw)
  To: gcc-bugs

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

Orion Poplawski <orion at cora dot nwra.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |orion at cora dot nwra.com

--- Comment #4 from Orion Poplawski <orion at cora dot nwra.com> ---
A recent issue triggered by this:
https://bugzilla.redhat.com/show_bug.cgi?id=1127544


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (3 preceding siblings ...)
  2015-04-28 18:23 ` orion at cora dot nwra.com
@ 2021-10-06  1:15 ` ilya.konstantinov at gmail dot com
  2022-09-06 22:40 ` foom at fuhm dot net
                   ` (35 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: ilya.konstantinov at gmail dot com @ 2021-10-06  1:15 UTC (permalink / raw)
  To: gcc-bugs

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

Ilya Konstantinov <ilya.konstantinov at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ilya.konstantinov at gmail dot com

--- Comment #11 from Ilya Konstantinov <ilya.konstantinov at gmail dot com> ---
Another manifestation of 'crtfastmath.o considered harmful':
https://github.com/gevent/gevent/pull/1820

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (4 preceding siblings ...)
  2021-10-06  1:15 ` ilya.konstantinov at gmail dot com
@ 2022-09-06 22:40 ` foom at fuhm dot net
  2022-09-06 22:55 ` pinskia at gcc dot gnu.org
                   ` (34 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: foom at fuhm dot net @ 2022-09-06 22:40 UTC (permalink / raw)
  To: gcc-bugs

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

James Y Knight <foom at fuhm dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |foom at fuhm dot net

--- Comment #12 from James Y Knight <foom at fuhm dot net> ---
https://github.com/llvm/llvm-project/issues/57589 was just filed, requesting to
fix this behavior in Clang, as well.

Since Clang is effectively only doing it in the first place to match GCC's
behavior, my feeling is that it'd be better not to make such a change in Clang
only.

However, I'd just like to give my support to changing this in GCC (either to
stop automatically linking against crtfastmath.o altogether, or to at least
stop doing so with -shared). And, if there is a change here, would certainly
then propose to match the new behavior in Clang.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (5 preceding siblings ...)
  2022-09-06 22:40 ` foom at fuhm dot net
@ 2022-09-06 22:55 ` pinskia at gcc dot gnu.org
  2022-09-06 22:57 ` sam at gentoo dot org
                   ` (33 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-06 22:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patient: Doctor it hurts when I do this.
Doctor: then don't do that and if you read the instructions I gave you I told
you I would hurt this way.

Note I think it was a mistake that gcc had -ffast-math option at all now.

But that ship has sailed over 18 years ago. And people abuse optimizations that
are documented this way and will still continue to abuse others similarly
really.
Plus always will abuse c/c++ semantics too.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (6 preceding siblings ...)
  2022-09-06 22:55 ` pinskia at gcc dot gnu.org
@ 2022-09-06 22:57 ` sam at gentoo dot org
  2022-09-07 10:06 ` egallager at gcc dot gnu.org
                   ` (32 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: sam at gentoo dot org @ 2022-09-06 22:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from Sam James <sam at gentoo dot org> ---
(In reply to Andrew Pinski from comment #13)
> Patient: Doctor it hurts when I do this.
> Doctor: then don't do that and if you read the instructions I gave you I
> told you I would hurt this way.
> 

This response could be applied to any bug asking for a change in behaviour of a
command line option. But I accept it's been a long time.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (7 preceding siblings ...)
  2022-09-06 22:57 ` sam at gentoo dot org
@ 2022-09-07 10:06 ` egallager at gcc dot gnu.org
  2022-09-08 17:09 ` luto at kernel dot org
                   ` (31 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-09-07 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #15 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #13)
> Patient: Doctor it hurts when I do this.
> Doctor: then don't do that and if you read the instructions I gave you I
> told you I would hurt this way.
> 

The problem I see with this analogy, is who exactly is the doctor in this
situation? It seems that currently the doctor is the GCC devs, but I think the
situation could be improved by having GCC itself be the doctor, by implementing
a -Wfast-math warning flag or something to make the issues with -ffast-math
more known. Having it documented in the instructions is just one place; it
should be mentioned in all the relevant places that a user might check.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (8 preceding siblings ...)
  2022-09-07 10:06 ` egallager at gcc dot gnu.org
@ 2022-09-08 17:09 ` luto at kernel dot org
  2022-09-09 10:32 ` rguenth at gcc dot gnu.org
                   ` (30 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: luto at kernel dot org @ 2022-09-08 17:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #16 from Andy Lutomirski <luto at kernel dot org> ---
(In reply to Andrew Pinski from comment #13)
> Patient: Doctor it hurts when I do this.
> Doctor: then don't do that and if you read the instructions I gave you I
> told you I would hurt this way.

I think this analogy is off.  Maybe for most questionable optimization or
codegen options it would apply, but -ffast-math is more like:

Patient: Doctor, it hurts me when my neighbor does this.
Doctor: Then tell your neighbor not to read that and to read the fine print on
the box.

If nitroglycerin pills have side effects and patients need to read the label,
maybe fine.  But if they start exploding and breaking other peoples' windows,
that's a whole different problem.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (9 preceding siblings ...)
  2022-09-08 17:09 ` luto at kernel dot org
@ 2022-09-09 10:32 ` rguenth at gcc dot gnu.org
  2022-09-09 10:50 ` rguenth at gcc dot gnu.org
                   ` (29 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-09 10:32 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org

--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note that when a shared library wants -ffast-math like behavior (FTZ, etc.)
_not_ linking crtfastmath.o will cause its behavior to depend on the process
loading
it and whether that sets the appropriate flags or not.  That might also cause
highly surprising effects.

That said, a "true fix" would redesign how these things work and make
FTZ part of the instruction encoding.

I suppose setting/restoring the control word around all public API of a
translation unit (and with LTO a bit more optimized) would be prohibitly
expensive.

Short of dropping the feature or re-implementing it, for example in the
dynamic loader via some ELF annotations with documented behavior on
"mismatch", I don't see any fix for this bug besides asking users to
conciously not link with -ffast-math when building shared libraries - unless
that's intended.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (10 preceding siblings ...)
  2022-09-09 10:32 ` rguenth at gcc dot gnu.org
@ 2022-09-09 10:50 ` rguenth at gcc dot gnu.org
  2022-09-11 15:46 ` brendandg at nyu dot edu
                   ` (28 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-09 10:50 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|x86_64-*-*, i?86-*-*        |x86_64-*-*, i?86-*-*,
                   |                            |aarch64, alpha, arm, ia64,
                   |                            |loongarch, mips, sparc
           Keywords|                            |documentation

--- Comment #18 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'll note that I can't find any documentation for this link-time behavior which
triggers for -Ofast, -ffast-math and -funsafe-math-optimizations but also
with -ffast-math -fno-unsafe-math-optimizations.

I've adjusted the list of affected targets.  What their crtfastmath.o actually
does would need to be determined, but it for sure will have the same spreading
effect.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (11 preceding siblings ...)
  2022-09-09 10:50 ` rguenth at gcc dot gnu.org
@ 2022-09-11 15:46 ` brendandg at nyu dot edu
  2022-09-12  7:01 ` rguenth at gcc dot gnu.org
                   ` (27 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: brendandg at nyu dot edu @ 2022-09-11 15:46 UTC (permalink / raw)
  To: gcc-bugs

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

Brendan Dolan-Gavitt <brendandg at nyu dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |brendandg at nyu dot edu

--- Comment #19 from Brendan Dolan-Gavitt <brendandg at nyu dot edu> ---
I read through the crtfastmath.c implementations for the other affected targets
and confirmed that they do all set flush-to-zero in this thread:

https://threadreaderapp.com/thread/1567612053363347461.html

I agree that there should be a way for a shared library to link crtfastmath.o
if it wants that behavior. But is there a reason -l:crtfastmath.o isn't
sufficient in that case? Why does it need to be enabled automatically when
-Ofast/-ffast-math/-funsafe-math optimizations are turned on?

The other note I would add is that in multi-threaded applications,
crtfastmath.o is already not behaving as intended: FTZ/DAZ will only be set in
the CPU state of the thread that loaded the shared library; it's hard to
imagine a case where a user wants individual threads to have different FTZ/DAZ
(unless they explicitly manage that by hand). Example:

$ cat baz.c
#include <stdio.h>
#include <unistd.h>
#include <dlfcn.h>
#include <pthread.h>

void loadlib() {
    void *handle = dlopen("./gofast.so", RTLD_LAZY);
    if (!handle) {
        fprintf(stderr, "dlopen: %s\n", dlerror());
    }
}

#define MXCSR_DAZ (1 << 6)  /* Enable denormals are zero mode */
#define MXCSR_FTZ (1 << 15) /* Enable flush to zero mode */
void printftz(int i) {
    unsigned int mxcsr = __builtin_ia32_stmxcsr ();
    printf("[%d] mxcsr.FTZ = %d, mxcsr.DAZ = %d\n", i, !!(mxcsr & MXCSR_FTZ),
!!(mxcsr & MXCSR_DAZ));
    return;
}

void *thread(void *arg) {
    // Print thread id
    int i = *(int *)arg;
    if (i == 0) loadlib();
    sleep(1);
    printftz(i);
}

int main(int argc, char **argv) {
    // Create 4 threads
    pthread_t threads[4];
    int tids[4];
    for (int i = 0; i < 4; i++) {
        tids[i] = i;
        pthread_create(&threads[i], NULL, thread, &tids[i]);
    }
    // Wait for all threads to finish
    for (int i = 0; i < 4; i++) {
        pthread_join(threads[i], NULL);
    }
    return 0;
}

$ touch gofast.c
$ gcc -Ofast -fpic -shared gofast.c -o gofast.so
$ gcc -pthread baz.c -o baz -ldl

$ ./baz
[3] mxcsr.FTZ = 0, mxcsr.DAZ = 0
[0] mxcsr.FTZ = 1, mxcsr.DAZ = 1
[2] mxcsr.FTZ = 0, mxcsr.DAZ = 0
[1] mxcsr.FTZ = 0, mxcsr.DAZ = 0

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (12 preceding siblings ...)
  2022-09-11 15:46 ` brendandg at nyu dot edu
@ 2022-09-12  7:01 ` rguenth at gcc dot gnu.org
  2022-09-12  9:47 ` fw at gcc dot gnu.org
                   ` (26 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-12  7:01 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com

--- Comment #20 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Brendan Dolan-Gavitt from comment #19)
> I read through the crtfastmath.c implementations for the other affected
> targets and confirmed that they do all set flush-to-zero in this thread:
> 
> https://threadreaderapp.com/thread/1567612053363347461.html
> 
> I agree that there should be a way for a shared library to link
> crtfastmath.o if it wants that behavior. But is there a reason
> -l:crtfastmath.o isn't sufficient in that case? Why does it need to be
> enabled automatically when -Ofast/-ffast-math/-funsafe-math optimizations
> are turned on?

The reasons for most of the "globbing" into -ffast-math/-Ofast are the
rules for SPEC CPU 2006 base flags which IIRC limited the number of flags
allowed (that's no longer a requirement for SPEC CPU 2017).  And of course
that users will not know of the flags but are likely not interested in
denormals when using -ffast-math.

> The other note I would add is that in multi-threaded applications,
> crtfastmath.o is already not behaving as intended: FTZ/DAZ will only be set
> in the CPU state of the thread that loaded the shared library; it's hard to
> imagine a case where a user wants individual threads to have different
> FTZ/DAZ (unless they explicitly manage that by hand). Example:

[...]

Yeah.  Not sure how often dynamic objects are opened from within threads
though.  That said, a possibility to enforce "consistency" at least would
be to save/restore the FP state around dlopen() so that shared objects
loaded not at program startup would not affect FP state at all?
The same could be done for shared objects loaded at program startup of
course.

The other way around would eventually be to make the CTOR __tls, that
should eventually force all threads to change their FP state(?).

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (13 preceding siblings ...)
  2022-09-12  7:01 ` rguenth at gcc dot gnu.org
@ 2022-09-12  9:47 ` fw at gcc dot gnu.org
  2022-09-14 17:03 ` brendandg at nyu dot edu
                   ` (25 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: fw at gcc dot gnu.org @ 2022-09-12  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

Florian Weimer <fw at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fw at gcc dot gnu.org

--- Comment #21 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #20)
> Yeah.  Not sure how often dynamic objects are opened from within threads
> though.

We know that some shared objects call pthread_create from ELF constructors,
which is enough to potentially expose the issue if the ELF constructors are
ordered in certain ways.

> That said, a possibility to enforce "consistency" at least would
> be to save/restore the FP state around dlopen() so that shared objects
> loaded not at program startup would not affect FP state at all?
> The same could be done for shared objects loaded at program startup of
> course.

I think GCC should not automatically link crtfastmath.o with -shared. That will
fix this particular issue for new shared objects, where the
action-at-a-distance issue is most prominent and least desirable I think.

> The other way around would eventually be to make the CTOR __tls, that
> should eventually force all threads to change their FP state(?).

No, all current TLS constructors run lazily when some language construct is
used. There is no way to run TLS constructors at dlopen time. We can in theory
change CPU state using glibc's SETXID broadcast, but it will impact legitimate
uses of the control register (e.g., changes to the FP control word around a
block of code that is executed in a non-default mode).

These days, we'd probably use GNU property notes for something like this
(although we'd likely not make it a global property in the first place, not for
this).

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (14 preceding siblings ...)
  2022-09-12  9:47 ` fw at gcc dot gnu.org
@ 2022-09-14 17:03 ` brendandg at nyu dot edu
  2022-10-07  9:27 ` aph at gcc dot gnu.org
                   ` (24 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: brendandg at nyu dot edu @ 2022-09-14 17:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #22 from Brendan Dolan-Gavitt <brendandg at nyu dot edu> ---
I think loading shared libraries from within threads is actually pretty common
when shared libs are used as plugins for some GUI app. I made a graph of the
reverse dependencies of Debian packages that contain shared libraries linking
to crtfastmath.o, and you can see that most of them are related to A/V plugins
(e.g. the largest cluster is from gstreamer-plugins-bad):

https://moyix.net/~moyix/ffast_debian.pdf

Granted, I think you could argue in this case that only affecting the thread
that loaded the plugin is the *intended* behavior.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (15 preceding siblings ...)
  2022-09-14 17:03 ` brendandg at nyu dot edu
@ 2022-10-07  9:27 ` aph at gcc dot gnu.org
  2022-10-07 17:00 ` hjl.tools at gmail dot com
                   ` (23 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: aph at gcc dot gnu.org @ 2022-10-07  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #23 from Andrew Haley <aph at gcc dot gnu.org> ---
This bug has pernicious effects in many more places:

https://moyix.blogspot.com/2022/09/someones-been-messing-with-my-subnormals.html

Florian is right: at least, GCC should not automatically link crtfastmath.o
with -shared. Better, separate fiddling with the FP control register from
-ffast-math entirely.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (16 preceding siblings ...)
  2022-10-07  9:27 ` aph at gcc dot gnu.org
@ 2022-10-07 17:00 ` hjl.tools at gmail dot com
  2022-10-10  9:17 ` fw at gcc dot gnu.org
                   ` (22 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: hjl.tools at gmail dot com @ 2022-10-07 17:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #24 from H.J. Lu <hjl.tools at gmail dot com> ---
Dropping crtfastmath.o with -shared makes sense.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (17 preceding siblings ...)
  2022-10-07 17:00 ` hjl.tools at gmail dot com
@ 2022-10-10  9:17 ` fw at gcc dot gnu.org
  2022-10-10 16:45 ` hjl.tools at gmail dot com
                   ` (21 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: fw at gcc dot gnu.org @ 2022-10-10  9:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #25 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #24)
> Dropping crtfastmath.o with -shared makes sense.

Are you going to send a patch? I can give it a try as well (although I'm not
familiar with the GCC specs language).

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (18 preceding siblings ...)
  2022-10-10  9:17 ` fw at gcc dot gnu.org
@ 2022-10-10 16:45 ` hjl.tools at gmail dot com
  2022-10-10 16:46 ` hjl.tools at gmail dot com
                   ` (20 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: hjl.tools at gmail dot com @ 2022-10-10 16:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #26 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 53686
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53686&action=edit
A patch not to add crtfastmath.o for -shared on x86

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (19 preceding siblings ...)
  2022-10-10 16:45 ` hjl.tools at gmail dot com
@ 2022-10-10 16:46 ` hjl.tools at gmail dot com
  2022-10-10 19:33 ` brendandg at nyu dot edu
                   ` (19 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: hjl.tools at gmail dot com @ 2022-10-10 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #27 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Florian Weimer from comment #25)
> (In reply to H.J. Lu from comment #24)
> > Dropping crtfastmath.o with -shared makes sense.
> 
> Are you going to send a patch? I can give it a try as well (although I'm not
> familiar with the GCC specs language).

Please give the patch at comment #26 a try.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (20 preceding siblings ...)
  2022-10-10 16:46 ` hjl.tools at gmail dot com
@ 2022-10-10 19:33 ` brendandg at nyu dot edu
  2022-12-19 10:36 ` cvs-commit at gcc dot gnu.org
                   ` (18 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: brendandg at nyu dot edu @ 2022-10-10 19:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #28 from Brendan Dolan-Gavitt <brendandg at nyu dot edu> ---
(In reply to H.J. Lu from comment #27)
> (In reply to Florian Weimer from comment #25)
> > (In reply to H.J. Lu from comment #24)
> > > Dropping crtfastmath.o with -shared makes sense.
> > 
> > Are you going to send a patch? I can give it a try as well (although I'm not
> > familiar with the GCC specs language).
> 
> Please give the patch at comment #26 a try.

It may be worth expanding this patch to other architectures that currently have
crtfastmath.o, since they similarly use global FPU state. The ones I have
confirmed are: ia64, loongarch, aarch64, alpha, mips, arm, and sparc.

(Details in this Twitter thread, unfortunately didn't write it up elsewhere:
https://threadreaderapp.com/thread/1567612053363347461.html ).

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (21 preceding siblings ...)
  2022-10-10 19:33 ` brendandg at nyu dot edu
@ 2022-12-19 10:36 ` cvs-commit at gcc dot gnu.org
  2022-12-26  1:12 ` cvs-commit at gcc dot gnu.org
                   ` (17 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-19 10:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #29 from Florian Weimer <fw at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #26)
> Created attachment 53686 [details]
> A patch not to add crtfastmath.o for -shared on x86

-  "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \
+  "%{Ofast|ffast-math|funsafe-math-optimizations:%{!shared:crtfastmath.o%s}} \

Works for me. It's also the change I would have mde.

--- Comment #30 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:88b531d0323fc1fc4173f1975d6a4f408a096f8b

commit r13-4769-g88b531d0323fc1fc4173f1975d6a4f408a096f8b
Author: liuhongt <hongtao.liu@intel.com>
Date:   Thu Dec 15 09:38:08 2022 +0800

    x86: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid changing the MXCSR register
    when loading a shared library.  crtfastmath.o will be used only when
    building executables.

            PR target/55522
            * config/i386/gnu-user-common.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Don't add crtfastmath.o for -shared.
            * doc/invoke.texi (-shared): Add related documentation.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (22 preceding siblings ...)
  2022-12-19 10:36 ` cvs-commit at gcc dot gnu.org
@ 2022-12-26  1:12 ` cvs-commit at gcc dot gnu.org
  2023-01-12 13:46 ` rguenth at gcc dot gnu.org
                   ` (16 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-26  1:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #31 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:e54375d85d4aa5889869c2672158083b2106b623

commit r13-4891-ge54375d85d4aa5889869c2672158083b2106b623
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Dec 12 15:43:58 2022 +0800

    x86: Add a new option -mdaz-ftz to enable FTZ and DAZ flags in MXCSR.

    if (mdaz-ftz)
      link crtfastmath.o
    else if ((Ofast || ffast-math || funsafe-math-optimizations)
             && !shared && !mno-daz-ftz)
      link crtfastmath.o
    else
      Don't link crtfastmath.o

    gcc/ChangeLog:

            PR target/55522
            PR target/36821
            * config/i386/gnu-user-common.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Link crtfastmath.o whenever -mdaz-ftz is specified. Don't link
            crtfastmath.o when -share or -mno-daz-ftz is specified.
            * config/i386/i386.opt (mdaz-ftz): New option.
            * doc/invoke.texi (x86 options): Document mftz-daz.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (23 preceding siblings ...)
  2022-12-26  1:12 ` cvs-commit at gcc dot gnu.org
@ 2023-01-12 13:46 ` rguenth at gcc dot gnu.org
  2023-01-13  3:35 ` sam at gentoo dot org
                   ` (15 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-12 13:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|x86_64-*-*, i?86-*-*,       |x86_64-*-*, i?86-*-*,
                   |aarch64, alpha, arm, ia64,  |aarch64, alpha, arm, ia64,
                   |loongarch, mips, sparc      |loongarch, mips, sparc,
                   |                            |*-solaris2*

--- Comment #32 from Richard Biener <rguenth at gcc dot gnu.org> ---
Do other targets want to follow suite for GCC 13 here?

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (24 preceding siblings ...)
  2023-01-12 13:46 ` rguenth at gcc dot gnu.org
@ 2023-01-13  3:35 ` sam at gentoo dot org
  2023-01-13  7:47 ` rguenth at gcc dot gnu.org
                   ` (14 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: sam at gentoo dot org @ 2023-01-13  3:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #33 from Sam James <sam at gentoo dot org> ---
(In reply to Richard Biener from comment #32)
> Do other targets want to follow suite for GCC 13 here?

I think the deviation for x86 and !x86 as-is will lead to further confusion.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (25 preceding siblings ...)
  2023-01-13  3:35 ` sam at gentoo dot org
@ 2023-01-13  7:47 ` rguenth at gcc dot gnu.org
  2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
                   ` (13 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-13  7:47 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #34 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm going to post a series of changes.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (26 preceding siblings ...)
  2023-01-13  7:47 ` rguenth at gcc dot gnu.org
@ 2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
  2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
                   ` (12 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-13 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #35 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:0bf7131e539de4ca66b3c0eb72aa0afbd8f006dc

commit r13-5140-g0bf7131e539de4ca66b3c0eb72aa0afbd8f006dc
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:47:59 2023 +0100

    aarch64: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/aarch64/aarch64-elf-raw.h (ENDFILE_SPEC): Don't add
            crtfastmath.o for -shared.
            * config/aarch64/aarch64-freebsd.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Likewise.
            * config/aarch64/aarch64-linux.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Likewise.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (27 preceding siblings ...)
  2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
@ 2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
  2023-01-16 13:31 ` cvs-commit at gcc dot gnu.org
                   ` (11 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-13 11:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #36 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:426a9f5570d74040176f81e7cf6806b36ebc907f

commit r13-5141-g426a9f5570d74040176f81e7cf6806b36ebc907f
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:51:10 2023 +0100

    arm: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/arm/linux-eabi.h (ENDFILE_SPEC): Don't add
            crtfastmath.o for -shared.
            * config/arm/unknown-elf.h (STARTFILE_SPEC): Likewise.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (28 preceding siblings ...)
  2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
@ 2023-01-16 13:31 ` cvs-commit at gcc dot gnu.org
  2023-01-18  2:46 ` cvs-commit at gcc dot gnu.org
                   ` (10 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-16 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #37 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:6347bbec3efb625dfc8592fbb3099dc0364c5317

commit r13-5201-g6347bbec3efb625dfc8592fbb3099dc0364c5317
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:56:28 2023 +0100

    solaris2: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/sol2.h (ENDFILE_SPEC): Don't add crtfastmath.o for
-shared.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (29 preceding siblings ...)
  2023-01-16 13:31 ` cvs-commit at gcc dot gnu.org
@ 2023-01-18  2:46 ` cvs-commit at gcc dot gnu.org
  2023-01-23 12:34 ` cvs-commit at gcc dot gnu.org
                   ` (9 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-18  2:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #38 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:159b0f41adc4c8ead45e12a523470381ce716ff2

commit r13-5235-g159b0f41adc4c8ead45e12a523470381ce716ff2
Author: liuhongt <hongtao.liu@intel.com>
Date:   Fri Jan 13 16:19:47 2023 +0800

    Don't add crtfastmath.o for -shared.

    Patches [1] and [2] fixed PR55522 for x86-linux but left all other x86
    targets unfixed (x86-cygwin, x86-darwin and x86-mingw32).
    This patch applies a similar change to other specs using crtfastmath.o.

    [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608528.html
    [2] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608529.html

    gcc/ChangeLog:

            PR target/55522
            * config/i386/cygwin.h (ENDFILE_SPEC): Link crtfastmath.o
            whenever -mdaz-ftz is specified. Don't link crtfastmath.o when
            -share or -mno-daz-ftz is specified.
            * config/i386/darwin.h (ENDFILE_SPEC): Ditto.
            * config/i386/mingw32.h (ENDFILE_SPEC): Ditto.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (30 preceding siblings ...)
  2023-01-18  2:46 ` cvs-commit at gcc dot gnu.org
@ 2023-01-23 12:34 ` cvs-commit at gcc dot gnu.org
  2023-01-27  3:26 ` cvs-commit at gcc dot gnu.org
                   ` (8 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-23 12:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #39 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:054e407b7f68f714c024d8a9c983fdd53ceead2b

commit r13-5305-g054e407b7f68f714c024d8a9c983fdd53ceead2b
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:54:33 2023 +0100

    sparc: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/sparc/freebsd.h (ENDFILE_SPEC): Don't add crtfastmath.o
            for -shared.
            * config/sparc/linux.h (ENDFILE_SPEC): Likewise.
            * config/sparc/linux64.h (ENDFILE_SPEC): Likewise.
            * config/sparc/sp-elf.h (ENDFILE_SPEC): Likewise.
            * config/sparc/sp64-elf.h (ENDFILE_SPEC): Likewise.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (31 preceding siblings ...)
  2023-01-23 12:34 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27  3:26 ` cvs-commit at gcc dot gnu.org
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-27  3:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #40 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Chenghua Xu <paulhua@gcc.gnu.org>:

https://gcc.gnu.org/g:476efe839e069e556b4b03cf6ec8c18870867960

commit r13-5424-g476efe839e069e556b4b03cf6ec8c18870867960
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 09:01:12 2023 +0100

    LoongArch: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/loongarch/gnu-user.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Don't add crtfastmath.o for -shared.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (32 preceding siblings ...)
  2023-01-27  3:26 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-27 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #41 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:31949fba1222692548b501e4dfa4ddcf7b7fc7c6

commit r13-5450-g31949fba1222692548b501e4dfa4ddcf7b7fc7c6
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:50:14 2023 +0100

    alpha: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/alpha/linux.h (ENDFILE_SPEC): Don't add
            crtfastmath.o for -shared.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (33 preceding siblings ...)
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-27 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #42 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:ed0a765ef9b7be420fc4cf6e653fc7350f84981c

commit r13-5451-ged0a765ef9b7be420fc4cf6e653fc7350f84981c
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:52:07 2023 +0100

    ia64: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/ia64/linux.h (ENDFILE_SPEC): Don't add crtfastmath.o
            for -shared.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (34 preceding siblings ...)
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-27 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #43 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:6cdb4d4bcd52c95cb6d367b93a82eb599d4e26f0

commit r13-5452-g6cdb4d4bcd52c95cb6d367b93a82eb599d4e26f0
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:53:44 2023 +0100

    mips: Don't add crtfastmath.o for -shared

    Don't add crtfastmath.o for -shared to avoid altering the FP
    environment when loading a shared library.

            PR target/55522
            * config/mips/gnu-user.h (GNU_USER_TARGET_MATHFILE_SPEC):
            Don't add crtfastmath.o for -shared.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (35 preceding siblings ...)
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
  2023-01-27 14:47 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-27 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #44 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:b799acef461bcb78d77819dd27c8e4806177d841

commit r13-5453-gb799acef461bcb78d77819dd27c8e4806177d841
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jan 13 08:57:12 2023 +0100

    Clarify -shared effect on crtfastmath.o

    This rewords the note to not specifically mention crtfastmath.o
    but FP environment altering by -ffast-math or -Ofast.

            PR target/55522
            * doc/invoke.texi (-shared): Clarify effect on -ffast-math
            and -Ofast FP environment side-effects.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (36 preceding siblings ...)
  2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
@ 2023-01-27 14:47 ` rguenth at gcc dot gnu.org
  2023-04-30  3:58 ` arthur200126 at gmail dot com
                   ` (2 subsequent siblings)
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-27 14:47 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
      Known to fail|                            |12.2.1
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #45 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for GCC 13.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (37 preceding siblings ...)
  2023-01-27 14:47 ` rguenth at gcc dot gnu.org
@ 2023-04-30  3:58 ` arthur200126 at gmail dot com
  2023-10-16 15:36 ` o.hlinka at gmail dot com
  2023-10-17  7:08 ` rguenth at gcc dot gnu.org
  40 siblings, 0 replies; 42+ messages in thread
From: arthur200126 at gmail dot com @ 2023-04-30  3:58 UTC (permalink / raw)
  To: gcc-bugs

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

Mingye Wang <arthur200126 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arthur200126 at gmail dot com

--- Comment #46 from Mingye Wang <arthur200126 at gmail dot com> ---
Uh, should there be some sort of -mdaz-ftz for the other arches too?

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (38 preceding siblings ...)
  2023-04-30  3:58 ` arthur200126 at gmail dot com
@ 2023-10-16 15:36 ` o.hlinka at gmail dot com
  2023-10-17  7:08 ` rguenth at gcc dot gnu.org
  40 siblings, 0 replies; 42+ messages in thread
From: o.hlinka at gmail dot com @ 2023-10-16 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

OH <o.hlinka at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |o.hlinka at gmail dot com

--- Comment #47 from OH <o.hlinka at gmail dot com> ---
Will/Could this be back-ported to the 12.x or lower versions? (Wasn't clear to
me from previous comments if this would be the case).

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [Bug target/55522] -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared
  2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
                   ` (39 preceding siblings ...)
  2023-10-16 15:36 ` o.hlinka at gmail dot com
@ 2023-10-17  7:08 ` rguenth at gcc dot gnu.org
  40 siblings, 0 replies; 42+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-17  7:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #48 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to OH from comment #47)
> Will/Could this be back-ported to the 12.x or lower versions? (Wasn't clear
> to me from previous comments if this would be the case).

Changing the behavior mid-release is not a good idea, so no.

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2023-10-17  7:08 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-29  0:52 [Bug c++/55522] New: -funsafe-math-optimizations is unexpectedly harmful, especially w/ -shared luto at mit dot edu
2012-11-29  1:49 ` [Bug c++/55522] " luto at mit dot edu
2012-11-29  8:57 ` [Bug target/55522] " rguenth at gcc dot gnu.org
2012-11-30  1:41 ` luto at mit dot edu
2015-04-28 18:23 ` orion at cora dot nwra.com
2021-10-06  1:15 ` ilya.konstantinov at gmail dot com
2022-09-06 22:40 ` foom at fuhm dot net
2022-09-06 22:55 ` pinskia at gcc dot gnu.org
2022-09-06 22:57 ` sam at gentoo dot org
2022-09-07 10:06 ` egallager at gcc dot gnu.org
2022-09-08 17:09 ` luto at kernel dot org
2022-09-09 10:32 ` rguenth at gcc dot gnu.org
2022-09-09 10:50 ` rguenth at gcc dot gnu.org
2022-09-11 15:46 ` brendandg at nyu dot edu
2022-09-12  7:01 ` rguenth at gcc dot gnu.org
2022-09-12  9:47 ` fw at gcc dot gnu.org
2022-09-14 17:03 ` brendandg at nyu dot edu
2022-10-07  9:27 ` aph at gcc dot gnu.org
2022-10-07 17:00 ` hjl.tools at gmail dot com
2022-10-10  9:17 ` fw at gcc dot gnu.org
2022-10-10 16:45 ` hjl.tools at gmail dot com
2022-10-10 16:46 ` hjl.tools at gmail dot com
2022-10-10 19:33 ` brendandg at nyu dot edu
2022-12-19 10:36 ` cvs-commit at gcc dot gnu.org
2022-12-26  1:12 ` cvs-commit at gcc dot gnu.org
2023-01-12 13:46 ` rguenth at gcc dot gnu.org
2023-01-13  3:35 ` sam at gentoo dot org
2023-01-13  7:47 ` rguenth at gcc dot gnu.org
2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
2023-01-13 11:14 ` cvs-commit at gcc dot gnu.org
2023-01-16 13:31 ` cvs-commit at gcc dot gnu.org
2023-01-18  2:46 ` cvs-commit at gcc dot gnu.org
2023-01-23 12:34 ` cvs-commit at gcc dot gnu.org
2023-01-27  3:26 ` cvs-commit at gcc dot gnu.org
2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
2023-01-27 14:47 ` cvs-commit at gcc dot gnu.org
2023-01-27 14:47 ` rguenth at gcc dot gnu.org
2023-04-30  3:58 ` arthur200126 at gmail dot com
2023-10-16 15:36 ` o.hlinka at gmail dot com
2023-10-17  7:08 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).