* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
@ 2020-04-27 22:32 ` redi at gcc dot gnu.org
2020-04-27 23:41 ` gcasper42 at gmail dot com
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-27 22:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Why can't you just use a global object with a constructor and destructor? That
would get correctly ordered with respect to the std::ios_base::Init object that
needs to be created before std::cout can be used.
The constructor and destructor attributes not necessary in C++, and are
documented as having an unspecified order relative to global objects (like the
std::ios_base::Init one).
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
2020-04-27 22:32 ` [Bug libstdc++/94810] " redi at gcc dot gnu.org
@ 2020-04-27 23:41 ` gcasper42 at gmail dot com
2020-04-28 8:51 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gcasper42 at gmail dot com @ 2020-04-27 23:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #2 from Geoffrey Casper <gcasper42 at gmail dot com> ---
I suppose that's a workaround, but there shouldn't be a seg fault in a
libstdc++ header file.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
2020-04-27 22:32 ` [Bug libstdc++/94810] " redi at gcc dot gnu.org
2020-04-27 23:41 ` gcasper42 at gmail dot com
@ 2020-04-28 8:51 ` redi at gcc dot gnu.org
2020-04-28 13:16 ` gcasper42 at gmail dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-28 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There isn't, there's a segfault in your program. That is caused by assuming
that the global streams have been constructed already, when it is clearly
documented that the construction order is unspecified.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (2 preceding siblings ...)
2020-04-28 8:51 ` redi at gcc dot gnu.org
@ 2020-04-28 13:16 ` gcasper42 at gmail dot com
2020-04-28 16:07 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gcasper42 at gmail dot com @ 2020-04-28 13:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #4 from Geoffrey Casper <gcasper42 at gmail dot com> ---
Wouldn't it make more sense to initialize global objects on a per need basis?
So the constructors of unused global objects would never be called and there is
no ambiguity of when constructors are called. I'd gladly work on implementing
this, but I'd need some more information on the brod design of GCC.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (3 preceding siblings ...)
2020-04-28 13:16 ` gcasper42 at gmail dot com
@ 2020-04-28 16:07 ` redi at gcc dot gnu.org
2020-04-28 16:09 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-28 16:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't see how that could conform to the standard's requirements.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (4 preceding siblings ...)
2020-04-28 16:07 ` redi at gcc dot gnu.org
@ 2020-04-28 16:09 ` redi at gcc dot gnu.org
2020-04-28 17:39 ` gcasper42 at gmail dot com
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-28 16:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe you misunderstood comment 3, the construction order is only unspecified
when you use __attribute__((constructor)). If you just create normal global
objects using normal C++ the order within a single translation unit is
completely specified, and your program would work as expected.
So again, why can't you just use standard C++ instead of attributes that aren't
needed in C++, and proposing non-conforming changes to the compiler?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (5 preceding siblings ...)
2020-04-28 16:09 ` redi at gcc dot gnu.org
@ 2020-04-28 17:39 ` gcasper42 at gmail dot com
2020-04-28 20:52 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gcasper42 at gmail dot com @ 2020-04-28 17:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #7 from Geoffrey Casper <gcasper42 at gmail dot com> ---
I believe I did misunderstand comment 3. Thanks for your clarification. Do all
global objects get marked with the constructor attribute, which leads to the
ambiguity?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (6 preceding siblings ...)
2020-04-28 17:39 ` gcasper42 at gmail dot com
@ 2020-04-28 20:52 ` redi at gcc dot gnu.org
2023-02-03 19:29 ` murugesandins at gmail dot com
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-28 20:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
No. The ambiguity only happens if you use the attribute explicitly, as you are
doing.
Just create a global object with a constructor and a destructor, instead of
using functions with __attribute__((constructor)) and
__attribute__((destructor)).
#include <iostream>
struct X {
X() {
std::cout << "Starting" << std::endl;
}
~X() {
std::cout << "Finishing" << std::endl;
}
};
int main() {
std::cout << "Hello, World!" << std::endl;
}
I'm closing this as invalid, since the attribute is documented to have
unspecified construction order relative to normal globals, which means your
original example is not expected to work.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (7 preceding siblings ...)
2020-04-28 20:52 ` redi at gcc dot gnu.org
@ 2023-02-03 19:29 ` murugesandins at gmail dot com
2023-02-03 19:47 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: murugesandins at gmail dot com @ 2023-02-03 19:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #9 from Murugesan Nagarajan <murugesandins at gmail dot com> ---
I'll update my comment today(Sat 04-Feb-2023 IST) after 09:00 AM IST. Right now
I'm facing network issue due to travelling.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (8 preceding siblings ...)
2023-02-03 19:29 ` murugesandins at gmail dot com
@ 2023-02-03 19:47 ` pinskia at gcc dot gnu.org
2023-02-03 22:04 ` murugesandins at gmail dot com
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-03 19:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=39796,
| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=98108,
| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=44952
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note in GCC 13+, this should work now after r13-3707-g4e4e3ffd10f53e .
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (9 preceding siblings ...)
2023-02-03 19:47 ` pinskia at gcc dot gnu.org
@ 2023-02-03 22:04 ` murugesandins at gmail dot com
2023-02-04 3:22 ` murugesandins at gmail dot com
2023-02-06 4:41 ` murugesandins at gmail dot com
12 siblings, 0 replies; 14+ messages in thread
From: murugesandins at gmail dot com @ 2023-02-03 22:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #11 from Murugesan Nagarajan <murugesandins at gmail dot com> ---
Hi Andrew,
Thank you for your comment. I'll check this after 09:00 AM.
Regards,
N.Murugesan
Google:
murugesan openssl
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (10 preceding siblings ...)
2023-02-03 22:04 ` murugesandins at gmail dot com
@ 2023-02-04 3:22 ` murugesandins at gmail dot com
2023-02-06 4:41 ` murugesandins at gmail dot com
12 siblings, 0 replies; 14+ messages in thread
From: murugesandins at gmail dot com @ 2023-02-04 3:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #12 from Murugesan Nagarajan <murugesandins at gmail dot com> ---
Thank you for sharing comment at:
>> https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=4e4e3ffd10f53e
Move stream initialization into compiled library
I am facing my issue to have my proper environment:
01. My laptop has gone before 6 months(it was having RHEL and ubuntu) at
vmplayer iso files.
02. Current acer system do not have any .iso files.
03. My working place not providing sudo access at Linux.
I have verified at cygwin using g++.exe which is working fine.
:)
$ g++.exe --version 2>&1 | grep GCC
g++ (GCC) 11.3.0
However I can verify your g++ related changes and I will update this page(in
future) when I have related OS using relative admin privileges.
Have a nice weekend.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
2020-04-27 21:44 [Bug libstdc++/94810] New: std::cout segmentation fault in __attribute__((constructor)) function gcasper42 at gmail dot com
` (11 preceding siblings ...)
2023-02-04 3:22 ` murugesandins at gmail dot com
@ 2023-02-06 4:41 ` murugesandins at gmail dot com
12 siblings, 0 replies; 14+ messages in thread
From: murugesandins at gmail dot com @ 2023-02-06 4:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
--- Comment #13 from Murugesan Nagarajan <murugesandins at gmail dot com> ---
@Andrew,
Thank you for updating current bug id: 94810
Old bug reported:
On: Mon 27-Apr-2020 09:44:52 PM UTC
Old Bug URL:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810
Old Status: RESOLVED INVALID
@Andrew's comment on 2023-02-03 07:47:43 PM UTC
Related linked bug/url:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=4e4e3ffd10f53e
Updated bug on: Sun 06-Nov-2022 04:16:00 PM UTC
Updated status: Bug fix completed using "__attribute__" and new
bug using "__has_attribute".
^ permalink raw reply [flat|nested] 14+ messages in thread