https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102992
--- Comment #29 from Iain Sandoe <iains at gcc dot gnu.org> --- (In reply to Francois-Xavier Coudert from comment #28) > > Well, unless there's a good reason to have it in a DTOR, it makes for a more > > robust solution to call it directly (there are various other differences > > that could occur in mixed code bases esp. c++ + fortran even without the > > Darwin21.1 bug). > > Mixed code is in fact the reason why it's in a DTOR and not called at the > end of Fortran main program. We need this clean-up routine to run even when > the main code is not in Fortran, and but Fortran routines are called by > other means (Fortran object files linked, or Fortran-based library loaded at > run-time). I've posted a fix for this (it is the fix for darwin21 DTORs in general) however CAVEAT : there is No guarantee given by the GCC DTOR machinery about the relative ordering of DTORs between different TUs, my fix will not solve that.