Changeset c4049e6 in mainline for uspace/lib/c/generic/libc.c


Ignore:
Timestamp:
2018-07-05T21:41:20Z (7 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9283830
Parents:
9396c52
git-author:
Dzejrou <dzejrou@…> (2018-03-15 10:40:53)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:20)
Message:

c+cpp: added support for global static constructors destructors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/libc.c

    r9396c52 rc4049e6  
    6161#endif
    6262
     63static bool env_setup = false;
    6364
    64 static bool env_setup = false;
     65/**
     66 * Used for C++ constructors/destructors
     67 * and the GCC constructor/destructor extension.
     68 */
     69typedef void (*init_array_entry_t)();
     70extern init_array_entry_t __init_array_start[];
     71extern init_array_entry_t __init_array_end[];
     72typedef void (*fini_array_entry_t)();
     73extern fini_array_entry_t __fini_array_start[];
     74extern fini_array_entry_t __fini_array_end[];
    6575
    6676void __libc_main(void *pcb_ptr)
     
    115125
    116126        /*
     127         * C++ Static constructor calls.
     128         */
     129        ptrdiff_t init_array_entries = (__init_array_end - __init_array_start);
     130
     131        for (int i = init_array_entries - 1; i > 0; --i)
     132                __init_array_start[i]();
     133
     134        /*
    117135         * Run main() and set task return value
    118136         * according the result
     
    124142void __libc_exit(int status)
    125143{
     144        /*
     145         * GCC extension __attribute__((destructor)),
     146         * C++ destructors are added to __cxa_finalize call
     147         * when the respective constructor is called.
     148         */
     149        ptrdiff_t fini_array_entries = (__fini_array_end - __fini_array_start);
     150
     151        for (int i = 0; i < fini_array_entries; ++i)
     152                __fini_array_start[i]();
     153
    126154        if (env_setup) {
    127155                __stdio_done();
Note: See TracChangeset for help on using the changeset viewer.