mirror of https://github.com/ARMmbed/mbed-os.git
Override exit and atexit functions from newlib.
This change simplify the exit and initialization process. It also reduce the number of hidden memory allocation made by atexit.pull/2745/head
parent
ce23ec3120
commit
f4f8b491d1
|
@ -629,7 +629,7 @@ extern "C" void exit(int return_code) {
|
||||||
} //namespace std
|
} //namespace std
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TOOLCHAIN_ARM)
|
#if defined(TOOLCHAIN_ARM) || defined(TOOLCHAIN_GCC)
|
||||||
|
|
||||||
// This series of function disable the registration of global destructors
|
// This series of function disable the registration of global destructors
|
||||||
// in a dynamic table which will be called when the application exit.
|
// in a dynamic table which will be called when the application exit.
|
||||||
|
@ -650,6 +650,39 @@ void __cxa_finalize(void *handle) {
|
||||||
|
|
||||||
} // end of extern "C"
|
} // end of extern "C"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(TOOLCHAIN_GCC)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Depending on how newlib is configured, it is often not enough to define
|
||||||
|
* __aeabi_atexit, __cxa_atexit and __cxa_finalize in order to override the
|
||||||
|
* behavior regarding the registration of handlers with atexit.
|
||||||
|
*
|
||||||
|
* To overcome this limitation, exit and atexit are overriden here.
|
||||||
|
*/
|
||||||
|
extern "C"{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retarget of exit for GCC.
|
||||||
|
* @details Unlike the standard version, this function doesn't call any function
|
||||||
|
* registered with atexit before calling _exit.
|
||||||
|
*/
|
||||||
|
void __wrap_exit(int return_code) {
|
||||||
|
_exit(return_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retarget atexit from GCC.
|
||||||
|
* @details This function will always fail and never register any handler to be
|
||||||
|
* called at exit.
|
||||||
|
*/
|
||||||
|
int __wrap_atexit(void (*func)()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ class GCC(mbedToolchain):
|
||||||
'c': ["-std=gnu99"],
|
'c': ["-std=gnu99"],
|
||||||
'cxx': ["-std=gnu++98", "-fno-rtti", "-Wvla"],
|
'cxx': ["-std=gnu++98", "-fno-rtti", "-Wvla"],
|
||||||
'ld': ["-Wl,--gc-sections", "-Wl,--wrap,main",
|
'ld': ["-Wl,--gc-sections", "-Wl,--wrap,main",
|
||||||
"-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_calloc_r"],
|
"-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r", "-Wl,--wrap,_calloc_r",
|
||||||
|
"-Wl,--wrap,exit", "-Wl,--wrap,atexit"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False):
|
def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False):
|
||||||
|
|
Loading…
Reference in New Issue