[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #13 from Murugesan Nagarajan --- @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".
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #12 from Murugesan Nagarajan --- 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.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #11 from Murugesan Nagarajan --- Hi Andrew, Thank you for your comment. I'll check this after 09:00 AM. Regards, N.Murugesan Google: murugesan openssl
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 Andrew Pinski 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 --- Note in GCC 13+, this should work now after r13-3707-g4e4e3ffd10f53e .
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #9 from Murugesan Nagarajan --- 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.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #8 from Jonathan Wakely --- 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 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.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #7 from Geoffrey Casper --- 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?
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #6 from Jonathan Wakely --- 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?
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #5 from Jonathan Wakely --- I don't see how that could conform to the standard's requirements.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #4 from Geoffrey Casper --- 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.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #3 from Jonathan Wakely --- 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.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #2 from Geoffrey Casper --- I suppose that's a workaround, but there shouldn't be a seg fault in a libstdc++ header file.
[Bug libstdc++/94810] std::cout segmentation fault in __attribute__((constructor)) function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810 --- Comment #1 from Jonathan Wakely --- 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).