Merge pull request #2745 from pan-/disable_global_objects_destruction

Disable global objects destruction
pull/2586/head
Sam Grove 2016-09-22 00:48:08 -05:00 committed by GitHub
commit 0c0455bf3f
4 changed files with 61 additions and 3 deletions

View File

@ -629,6 +629,64 @@ extern "C" void exit(int return_code) {
} //namespace std
#endif
#if defined(TOOLCHAIN_ARM) || defined(TOOLCHAIN_GCC)
// This series of function disable the registration of global destructors
// in a dynamic table which will be called when the application exit.
// In mbed, program never exit properly, it dies.
// More informations about this topic for ARMCC here:
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/6449.html
extern "C" {
int __aeabi_atexit(void *object, void (*dtor)(void* /*this*/), void *handle) {
return 1;
}
int __cxa_atexit(void (*dtor)(void* /*this*/), void *object, void *handle) {
return 1;
}
void __cxa_finalize(void *handle) {
}
} // 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
namespace mbed {

View File

@ -796,7 +796,6 @@ void pre_main(void) {
singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex));
malloc_mutex_id = osMutexCreate(osMutex(malloc_mutex));
env_mutex_id = osMutexCreate(osMutex(env_mutex));
atexit(__libc_fini_array);
__libc_init_array();
main(0, NULL);
}

View File

@ -42,7 +42,8 @@ class GCC(mbedToolchain):
'c': ["-std=gnu99"],
'cxx': ["-std=gnu++98", "-fno-rtti", "-Wvla"],
'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):

View File

@ -43,7 +43,7 @@ class IAR(mbedToolchain):
"--diag_suppress=Pa050,Pa084,Pa093,Pa082"],
'asm': [],
'c': ["--vla"],
'cxx': ["--guard_calls"],
'cxx': ["--guard_calls", "--no_static_destruction"],
'ld': ["--skip_dynamic_initialization", "--threaded_lib"],
}