On Sat, 16 Aug 2025, Pali Rohár wrote:

Rename __do_global_ctors to __mingw_do_global_ctors and __do_global_dtors
to __mingw_do_global_dtors to make it explicit that these two functions
are internal for mingw-w64 runtime and not supposed to be used or called by
anything else.

Explicitly call __mingw_do_global_ctors() in mingw-w64 startup sequence
instead of the __main() function, and make gcc's __main() function
completely empty, as it is not needed anymore. Function __main() is
inserted into every function main() by gcc, so the symbol for function
__main() has to exist in mingw-w64 runtime even if it does nothing.

Move atexit(__mingw_do_global_dtors) call from __mingw_do_global_ctors() to
mingw-w64 shutdown sequence. For exe builds use _crt_atexit() registration
and for dll builds call __mingw_do_global_dtors() function from the
_CRT_INIT(DLL_PROCESS_DETACH) function.
---

I feel uneasy about this change. It changes a lot, without presenting a compelling argument about why.

The interface around "__main" can be entrenched in many places, and code expecting to e.g. override the entry point and just call "__main" no longer will have working C++ constructors.

The code now uses _crt_atexit() instead of atexit(). Perhaps it is ok, I would need to study those interfaces and review that as a change on its own. An explanation of why might help as well. If there is a reason to do that, it would be easier to handle review wise if it is split to a separate commit as well, with separate arguments.

{
-  unsigned long nptrs = (unsigned long) (ptrdiff_t) __CTOR_LIST__[0];
+  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];
  unsigned long i;

This change, to remove the intermediate cast, looks unrelated to the rest of the changes. Is there a good reason for why we should do that? In that case it could be a separate change. It is also possible that removing it may reintroduce warnings in some build configuration.

// Martin

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to