Can somebody explain me how the following code works?
# if   defined(__ELF__)
#  define __SECTION_FLAGS   ", \"aw\" , @progbits"
    /* writable flag needed for ld ".[cd]tors" sections bug workaround) */
# elif defined(__COFF__)
#  define __SECTION_FLAGS   ", \"dr\""
    /* untested, may be writable flag needed */
# endif
asm
(
    ".section .ctors" __SECTION_FLAGS "\n"
    ".globl __ctors_begin__\n"
    "__ctors_begin__:\n"
    ".previous\n"
);
asm /* ld ".[cd]tors" sections bug workaround */
(
    ".section .ctors0" __SECTION_FLAGS "\n"
    ".globl __ctors0_begin__\n"
    "__ctors0_begin__:\n"
    ".previous\n"
);
Similarly we are getting __ctors_end__ , __ctors0_end__  and destructors location is also obtained this way. After some ld bug workarounds all functions pointed by pointers from   __ctors_begin__ to __ctors_end__ are executed. I don't know assembler and this code is impossible for me to interpret.
BTW: I know that invoking C++ contructors/destructors from C is not a task to be considered safe or easy.