Skip to content

Conversation

@JinShil
Copy link
Contributor

@JinShil JinShil commented May 31, 2025

See #95257 and #7740 and the various issue reports related to them.

@JinShil JinShil requested a review from MichalStrehovsky as a code owner May 31, 2025 04:52
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label May 31, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member

Is there an example of a standard library (glibc, Rust stdlib, etc.) that prints to stderr if it fails to initialize? Trying to figure out if this is standard practice. Both good and bad things can happen from this.

@JinShil
Copy link
Contributor Author

JinShil commented Jun 4, 2025

I think libc calls terminate, and users add a termination handler, but it's been a decade or two since I looked at the C runtime code. Is ASSERT_MSG or ASSERT preferred?

@JinShil
Copy link
Contributor Author

JinShil commented Jun 4, 2025

Is ASSERT_MSG or ASSERT preferred?

It appears that would be pointless for release builds.

@JinShil
Copy link
Contributor Author

JinShil commented Jun 4, 2025

This is the best I could think of to mimic a runtime initialization failure in C++:

#include <stdexcept>

struct Global 
{
    Global() 
    { 
        throw std::runtime_error("Init failure"); 
    }
};

Global g;

int main() 
{ 
    return 0;
}

That results in the following printed to stderr:

terminate called after throwing an instance of 'std::runtime_error'
  what():  Init failure
Aborted

Default Termination Handler:
https://github.com/gcc-mirror/gcc/blob/f7df645956459c559f254d622090d4dd09159890/libstdc%2B%2B-v3/libsupc%2B%2B/eh_term_handler.h#L35
https://github.com/gcc-mirror/gcc/blob/f7df645956459c559f254d622090d4dd09159890/libstdc%2B%2B-v3/libsupc%2B%2B/vterminate.cc#L44

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do the same in front of other PalPrintFatalError, so this change is just going with the flow.

If we wanted to do something else, we should revisit all PalPrintFatalError+RhFailFast calls.

@MichalStrehovsky MichalStrehovsky merged commit 09cb359 into dotnet:main Jun 4, 2025
94 checks passed
@JinShil JinShil deleted the patch-1 branch June 4, 2025 22:17
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants