What is the difference between __cxa_atexit () and atexit ()

In GCC docs, I found a parameter -fuse-cxa-atexit, and it says the following:

This option is required for fully standardized processing of static destructors.

So what is the difference between the two? In the docs for __cxa_atexitI found the following:

The __cxa_atexit () function is used to implement atexit ()

I do statics in functions (don't ask why), and I was wondering which of the 2 to use to call the destructor.

And I suppose I only have atexit()MSVC? This is problem?

Is it possible to simply use atexit()everywhere and be sure that it will behave the same way as real static objects in functions?

+4
source share
1 answer

__cxa_atexit()defined in Italium C ++ ABI. The document explains the motivation for this function :

The C ++ standard requires that destructors be called for global objects when a program exits in the opposite order of construction. Most implementations did this by calling the C library routine atexitto register destructors. This is problematic because the 1999 C standard only requires an implementation to support 32 registered functions, although most implementations support many others. More importantly, it generally does not have the ability in most implementations to remove [Dynamic shared objects] from the executable image of the program, calling it dlclosebefore the program terminates.

API, , , atexit - - DSO (, dlclose).

:

  • __cxa_atexit() 32 .
  • __cxa_atexit() , .

-fuse-cxa-atexit, , libc (, glibc, musl). , gcc, , ( , , libc ).

, __cxa_atexit : , / (__dso_handle).

... __cxa_atexit, atexit DSO.


MSVC, -, atexit()- . dlclose MSVC dlclose().

+4

Source: https://habr.com/ru/post/1672750/


All Articles