diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2021-11-04 09:37:14 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2021-11-15 19:48:56 +0000 |
commit | fabe8cc41e9b01913e2016861237d1d99d7567bf (patch) | |
tree | 355d2b664bee14493cfe409407adb9d965446b45 /gcc/doc/tm.texi | |
parent | d3cc82dc9cc2d4f1021fc5d4c1463c3a14fc6795 (diff) | |
download | gcc-fabe8cc41e9b01913e2016861237d1d99d7567bf.zip gcc-fabe8cc41e9b01913e2016861237d1d99d7567bf.tar.gz gcc-fabe8cc41e9b01913e2016861237d1d99d7567bf.tar.bz2 |
IPA: Provide a mechanism to register static DTORs via cxa_atexit.
For at least one target (Darwin) the platform convention is to
register static destructors (i.e. __attribute__((destructor)))
with __cxa_atexit rather than placing them into a list that is
run by some other mechanism.
This patch provides a target hook that allows a target to opt
into this and handling for the process in ipa_cdtor_merge ().
When the mode is enabled (dtors_from_cxa_atexit is set) we:
* Generate new CTORs to register static destructors with
__cxa_atexit and add them to the existing list of CTORs;
we then process the revised CTORs list.
* We sort the DTORs into priority and then TU order, this
means that they are registered in that order with
__cxa_atexit () and therefore will be run in the reverse
order.
* Likewise, CTORs are sorted into priority and then TU order,
which means that they will run in that order.
This matches the behavior of using init/fini (or
mod_init_func/mod_term_func) sections.
This also fixes a bug where Fortran needs a DTOR to be run to
close IO.
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
PR fortran/102992
gcc/ChangeLog:
* config/darwin.h (TARGET_DTORS_FROM_CXA_ATEXIT): New.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in: Add TARGET_DTORS_FROM_CXA_ATEXIT hook.
* ipa.c (cgraph_build_static_cdtor_1): Return the built
function decl.
(build_cxa_atexit_decl): New.
(build_dso_handle_decl): New.
(build_cxa_dtor_registrations): New.
(compare_cdtor_tu_order): New.
(build_cxa_atexit_fns): New.
(ipa_cdtor_merge): If dtors_from_cxa_atexit is set,
process the DTORs/CTORs accordingly.
(pass_ipa_cdtor_merge::gate): Also run if
dtors_from_cxa_atexit is set.
* target.def (dtors_from_cxa_atexit): New hook.
Diffstat (limited to 'gcc/doc/tm.texi')
-rw-r--r-- | gcc/doc/tm.texi | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 78a1af1..6ec1d50 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -9210,6 +9210,14 @@ collecting constructors and destructors to be run at startup and exit. It is false if we must use @command{collect2}. @end deftypevr +@deftypevr {Target Hook} bool TARGET_DTORS_FROM_CXA_ATEXIT +This value is true if the target wants destructors to be queued to be +run from __cxa_atexit. If this is the case then, for each priority level, +a new constructor will be entered that registers the destructors for that +level with __cxa_atexit (and there will be no destructors emitted). +It is false the method implied by @code{have_ctors_dtors} is used. +@end deftypevr + @deftypefn {Target Hook} void TARGET_ASM_CONSTRUCTOR (rtx @var{symbol}, int @var{priority}) If defined, a function that outputs assembler code to arrange to call the function referenced by @var{symbol} at initialization time. |