-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
start code: implement __init_array_start, __init_array_end #20852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I would suggest also splitting up the calls to |
@Rexicon226 how are we feeling about |
hmmm I don't know about that. I like it better when the process just ends. The OS cleans up all the memory and open handles, and any resource not cleaned up by the OS is a bug because the process could have been terminated abnormally. Not implementing those destructors forces people to code correctly. |
It's needed for correctness in some cases though. If I build some C code that uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest also splitting up the calls to
callMainWithArgs()
andstd.posix.exit()
here, and calling the function pointers stored between__fini_array_start
/__fini_array_end
.hmmm I don't know about that. I like it better when the process just ends. The OS cleans up all the memory and open handles, and any resource not cleaned up by the OS is a bug because the process could have been terminated abnormally. Not implementing those destructors forces people to code correctly.
I'd argue that "not running destructors" should be the behavior of std.process.cleanExit
in release modes, not the default. In fact, if handling is added between callMainWithArgs
and std.posix.exit
as was suggested, this would already be the case since cleanExit
calls exit
itself in release modes, instead of returning from main
.
As for there being no use case for destructors, the first one that occurs to me is flushing compiler instrumentation data to disk for non-fuzzing use cases. In this case, it may be desirable to not write misleading profiling data when the process exits abnormally, maybe because you just got the command line syntax wrong the first time.
That said, I don't think there should be explicit language/std support for defining destructors in Zig, that use case seems questionable and the friction should remain with creating them from Zig.
For that use case specifically, you would expect the executable to |
Yeah I forgot that calling |
That seems reasonable. It's enough friction to satisfy me. |
Tested by observing
__sanitizer_cov_8bit_counters_init
and__sanitizer_cov_pcs_init
being called in a libc-less build.