public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114357] New: C++: Support the no_destroy attribute
@ 2024-03-15 21:48 i at maskray dot me
  2024-03-15 21:59 ` [Bug c++/114357] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: i at maskray dot me @ 2024-03-15 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114357
           Summary: C++: Support the no_destroy attribute
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: i at maskray dot me
  Target Milestone: ---

Clang supports [[clang::no_destroy]] (alternative form:
`__attribute__((no_destroy))`) to disable exit-time destructors of variables of
static or thread local storage duration.

* July 2018 discussion:
https://discourse.llvm.org/t/rfc-suppress-c-static-destructor-registration/49128
* Patch: https://reviews.llvm.org/D50994 with follow-up
https://reviews.llvm.org/D54344
* Current documentation:
https://clang.llvm.org/docs/AttributeReference.html#no-destroy
* https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1247r0.html (seems
not presented to EWG yet)

[[clang::always_destroy]] enables exit-time destructors for specific objects
(when -fno-c++-static-destructors disables exit-time destructors globally).

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

* [Bug c++/114357] C++: Support the no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
@ 2024-03-15 21:59 ` pinskia at gcc dot gnu.org
  2024-03-15 22:02 ` [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's " pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15 21:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This sounds like a very dangerous attribute to have. It changes behavior and
even could cause memory leaks if abused.

Plus I think it is also designed to get around folks not programming well
defined C++ code.

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
  2024-03-15 21:59 ` [Bug c++/114357] " pinskia at gcc dot gnu.org
@ 2024-03-15 22:02 ` pinskia at gcc dot gnu.org
  2024-03-15 22:08 ` jfb at chromium dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15 22:02 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
            Summary|C++: Support the no_destroy |Add a way to not call
                   |attribute                   |deconstructors for non-auto
                   |                            |decls, like clang's
                   |                            |no_destroy attribute

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Really having this attribute to work around broken C++ code is just asking for
more troubles. There was a request recently for asking to remove the store for
the vtable in trivial deconstructors to work around broken C++ code and it was
obvious that the developer didn't know how it was broken and just wanted to
this attribute to workaround their broken code.

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
  2024-03-15 21:59 ` [Bug c++/114357] " pinskia at gcc dot gnu.org
  2024-03-15 22:02 ` [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's " pinskia at gcc dot gnu.org
@ 2024-03-15 22:08 ` jfb at chromium dot org
  2024-03-15 22:09 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jfb at chromium dot org @ 2024-03-15 22:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from JF Bastien <jfb at chromium dot org> ---
The LLVM feature was added for XNU, because the kernel never runs its own
global C++ destructors (but the compiler can't know this). It saved a
non-trivial amount of code generation.

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
                   ` (2 preceding siblings ...)
  2024-03-15 22:08 ` jfb at chromium dot org
@ 2024-03-15 22:09 ` pinskia at gcc dot gnu.org
  2024-03-15 22:25 ` jfb at chromium dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to JF Bastien from comment #3)
> The LLVM feature was added for XNU, because the kernel never runs its own
> global C++ destructors (but the compiler can't know this). It saved a
> non-trivial amount of code generation.

Yes and that is broken ....

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
                   ` (3 preceding siblings ...)
  2024-03-15 22:09 ` pinskia at gcc dot gnu.org
@ 2024-03-15 22:25 ` jfb at chromium dot org
  2024-03-15 22:26 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jfb at chromium dot org @ 2024-03-15 22:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from JF Bastien <jfb at chromium dot org> ---
(In reply to Andrew Pinski from comment #4)
> (In reply to JF Bastien from comment #3)
> > The LLVM feature was added for XNU, because the kernel never runs its own
> > global C++ destructors (but the compiler can't know this). It saved a
> > non-trivial amount of code generation.
> 
> Yes and that is broken ....

Please substantiate your assertion with evidence. What, specifically, is broken
and why?

It's totally normal for kernels to not run destructors. It's totally normal for
classes to have destructors and do work in them. It's totally normal to use
these classes as globals and not need the destructor behavior in these global
circumstances (yet need it when used on the stack or heap). It's totally normal
for the compiler to not know this unless told.

Look you can do what you want with a non-standard feature in GCC. You're just
not being constructive (being destructive?) in this request. People have used
this for good reasons in my opinion, and more people would want this
standardized so I'll revive that standardization effort. If you have actual
good reasons to be against I'd like to hear them. I haven't heard those reasons
from you. But again, do what you want and feel free to ignore, I'm not going to
engage further if you want to just close the bug as "won't fix".

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
                   ` (4 preceding siblings ...)
  2024-03-15 22:25 ` jfb at chromium dot org
@ 2024-03-15 22:26 ` pinskia at gcc dot gnu.org
  2024-03-15 23:46 ` redi at gcc dot gnu.org
  2024-03-16 10:35 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-15 22:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=19661

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There are better ways of optimizing out atexit calls. PR 19661 has existed for
years but nobody has decided to fix it since it has been a low hanging fruit
and such.

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
                   ` (5 preceding siblings ...)
  2024-03-15 22:26 ` pinskia at gcc dot gnu.org
@ 2024-03-15 23:46 ` redi at gcc dot gnu.org
  2024-03-16 10:35 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-15 23:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Libstdc++ has to use some sneaky hacks to avoid destroying globals, we would
definitely use no_destroy if we had it.

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

* [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's no_destroy attribute
  2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
                   ` (6 preceding siblings ...)
  2024-03-15 23:46 ` redi at gcc dot gnu.org
@ 2024-03-16 10:35 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-03-16 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-16
             Status|UNCONFIRMED                 |NEW

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
e.g. PR 107500 where a bare metal system wastes space for a no-op destructor.
It would be a lot simpler if we could just mark immortal objects as
[[no_destroy]] and not have to dance around what the standard allows (or not)
about lifetimes and triviality for objects with static storage duration. It
would also be better to not rely on DCE being able to figure out what we're
trying to do with unions and empty destructors.

There are valid use cases in a kernel or language runtime for ensuring that
some objects do not end their lifetime while other code is still running.

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

end of thread, other threads:[~2024-03-16 10:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-15 21:48 [Bug c++/114357] New: C++: Support the no_destroy attribute i at maskray dot me
2024-03-15 21:59 ` [Bug c++/114357] " pinskia at gcc dot gnu.org
2024-03-15 22:02 ` [Bug c++/114357] Add a way to not call deconstructors for non-auto decls, like clang's " pinskia at gcc dot gnu.org
2024-03-15 22:08 ` jfb at chromium dot org
2024-03-15 22:09 ` pinskia at gcc dot gnu.org
2024-03-15 22:25 ` jfb at chromium dot org
2024-03-15 22:26 ` pinskia at gcc dot gnu.org
2024-03-15 23:46 ` redi at gcc dot gnu.org
2024-03-16 10:35 ` redi 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).