using option -fno-register-global-dtors-with-atexit i want the clang compiler to not emit any calls to __cxa_atexit or atexit
I assume this option will disable the calls because compiler manual says:
clang --help | grep "atexit"
-fno-register-global-dtors-with-atexit
Don't use atexit to register global destructors
-fno-register-global-dtors-with-cxa-atexit
Don't use __cxa_atexit to register global destructors
-fno-use-cxa-atexit
Alias for -fno-register-global-dtors-with-cxa-atexit
-fregister-global-dtors-with-atexit
Use atexit or __cxa_atexit to register global destructors
Because GCC does not have -fno-register-global-dtors-with-atexit option
it will produce construction and destruction symbols for all objects in the TU without the calls to runtime procedures
remove mention of _cxa_atexit for -fregister-global-dtors-with-atexit and -fno-register-global-dtors-with-atexit options such that
clang --help | grep "atexit"
will produce
-fno-register-global-dtors-with-atexit
Don't use atexit or __cxa_atexit to register global destructors
-fno-use-cxa-atexit Don't use __cxa_atexit for calling to register global destructors
-fregister-global-dtors-with-atexit
Use atexit or __cxa_atexit to register global destructors instead of __cxa_atexit
add -fno-register-global-dtors-with-cxa-atexit option as alias for existing -fno-use-cxa-atexit
add -fno-use-atexit option as alias for existing -fno-register-global-dtors-with-atexit
make codegen emit separated procedures for construct and destruct global objects in the translation unit if options
-fno-use-atexit and -fno-use-cxa-atexit are specified
Final output for
clang --help | grep "atexit"
-fno-register-global-dtors-with-atexit
Don't use atexit to register global destructors
-fno-register-global-dtors-with-cxa-atexit
Don't use __cxa_atexit to register global destructors
-fno-use-atexit
Alias for -fno-register-global-dtors-with-atexit
-fno-use-cxa-atexit
Alias for -fno-register-global-dtors-with-cxa-atexit
-fregister-global-dtors-with-atexit
Use atexit to register global destructors instead of __cxa_atexit
Issue
I have an example of code with static object initialization
using option
-fno-register-global-dtors-with-atexit
i want the clang compiler to not emit any calls to __cxa_atexit or atexitI assume this option will disable the calls because compiler manual says:
However the command
where DSO_Life.cc contains:
will generate x86_64 assembly code with call to __cxa_atexit anyway
LLVM IR also contains call to __cxa_atexit
Related behavior
option
-fno-use-cxa-atexit
will replace call to __cxa_atexit with call to atexitNote: DSO_Life.cc changed to
It also will extract dtor for each global object like that:
(it can be usefull for reflection, i am gonna use that if it's legal)
Compiler Explorer
GCC behavior
Note: DSO_Life.cc changed to
GCC 13.2.1 also have option
-fno-use-cxa-atexit
Command:
Because GCC does not have -fno-register-global-dtors-with-atexit option it will produce construction and destruction symbols for all objects in the TU without the calls to runtime procedures
Proposal
-fregister-global-dtors-with-atexit
and-fno-register-global-dtors-with-atexit
options such thatwill produce
-fno-register-global-dtors-with-cxa-atexit
option as alias for existing-fno-use-cxa-atexit
-fno-use-atexit
option as alias for existing-fno-register-global-dtors-with-atexit
-fno-use-atexit
and-fno-use-cxa-atexit
are specifiedFinal output for
Thank You